aboutsummaryrefslogtreecommitdiff
path: root/src/ats/gnunet-service-ats-solver_ril.c
diff options
context:
space:
mode:
authorFabian Oehlmann <oehlmann@in.tum.de>2013-10-08 15:43:03 +0000
committerFabian Oehlmann <oehlmann@in.tum.de>2013-10-08 15:43:03 +0000
commite6c06a3f18b4c3a5a3cae2aa572c927d737ce532 (patch)
tree0d4c3d4553609122e99dca250ead4e36bd3fc819 /src/ats/gnunet-service-ats-solver_ril.c
parent9549f5de3b28e061a9997a9966ac4d9013033472 (diff)
downloadgnunet-e6c06a3f18b4c3a5a3cae2aa572c927d737ce532.tar.gz
gnunet-e6c06a3f18b4c3a5a3cae2aa572c927d737ce532.zip
ats_ril: -fixed property indexing
-comment cleanup
Diffstat (limited to 'src/ats/gnunet-service-ats-solver_ril.c')
-rwxr-xr-xsrc/ats/gnunet-service-ats-solver_ril.c48
1 files changed, 37 insertions, 11 deletions
diff --git a/src/ats/gnunet-service-ats-solver_ril.c b/src/ats/gnunet-service-ats-solver_ril.c
index 2320f295e..e0ba317bb 100755
--- a/src/ats/gnunet-service-ats-solver_ril.c
+++ b/src/ats/gnunet-service-ats-solver_ril.c
@@ -49,6 +49,12 @@
49 * General description 49 * General description
50 */ 50 */
51 51
52/**
53 * The actions, how an agent can manipulate the current assignment. I.e. how the bandwidth can be
54 * changed for the currently chosen address. Not depicted in the enum are the actions of switching
55 * to a particular address. The action of switching to address with index i is depicted by the
56 * number (RIL_ACTION_TYPE_NUM + i).
57 */
52enum RIL_Action_Type 58enum RIL_Action_Type
53{ 59{
54 RIL_ACTION_NOTHING = 0, 60 RIL_ACTION_NOTHING = 0,
@@ -149,7 +155,7 @@ struct RIL_Peer_Agent
149 /** 155 /**
150 * Whether the agent is active or not 156 * Whether the agent is active or not
151 */ 157 */
152 int active; //TODO? rename into "requested", since it rather depicts whether there is a request pending for it 158 int active; //TODO? rename into something better. It reflects the state whether get_preferred_address() has been called for the according peer or not
153 159
154 /** 160 /**
155 * Number of performed time-steps 161 * Number of performed time-steps
@@ -309,12 +315,12 @@ struct GAS_RIL_Handle
309 unsigned long long step_count; 315 unsigned long long step_count;
310 316
311 /** 317 /**
312 * Interval time between steps in milliseconds //TODO? put in agent 318 * Interval time between steps in milliseconds //TODO? Future Work: Heterogeneous stepping among agents
313 */ 319 */
314 struct GNUNET_TIME_Relative step_time; 320 struct GNUNET_TIME_Relative step_time;
315 321
316 /** 322 /**
317 * Task identifier of the next time-step to be executed //TODO? put in agent 323 * Task identifier of the next time-step to be executed
318 */ 324 */
319 GNUNET_SCHEDULER_TaskIdentifier next_step; 325 GNUNET_SCHEDULER_TaskIdentifier next_step;
320 326
@@ -375,10 +381,14 @@ agent_estimate_q (struct RIL_Peer_Agent *agent, double *state, int action)
375static int 381static int
376agent_decide_exploration (struct RIL_Peer_Agent *agent) 382agent_decide_exploration (struct RIL_Peer_Agent *agent)
377{ 383{
384 //TODO? Future Work: Improve exploration/exploitation trade-off by different mechanisms than e-greedy
385 /*
386 * An e-greedy replacement could be based on the accuracy of the prediction of the Q-value
387 */
378 double r = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 388 double r = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
379 UINT32_MAX) / (double) UINT32_MAX; 389 UINT32_MAX) / (double) UINT32_MAX;
380 390
381if (r < RIL_EXPLORE_RATIO) 391 if (r < RIL_EXPLORE_RATIO)
382 { 392 {
383 return GNUNET_YES; 393 return GNUNET_YES;
384 } 394 }
@@ -471,6 +481,7 @@ agent_get_action_best (struct RIL_Peer_Agent *agent, double *state)
471static int 481static int
472agent_get_action_explore (struct RIL_Peer_Agent *agent, double *state) 482agent_get_action_explore (struct RIL_Peer_Agent *agent, double *state)
473{ 483{
484 // TODO?: Future Work: Choose the action for exploration, which has been explored the least in this state
474 return GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, agent->n); 485 return GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, agent->n);
475} 486}
476 487
@@ -697,6 +708,22 @@ ril_get_max_bw(struct RIL_Peer_Agent *agent, int direction_in)
697} 708}
698 709
699/** 710/**
711 * Get the index of the quality-property in question
712 * @param type the quality property type
713 * @return the index
714 */
715static int
716ril_find_property_index (uint32_t type)
717{
718 int existing_types[] = GNUNET_ATS_QualityProperties;
719 int c;
720 for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++)
721 if (existing_types[c] == type)
722 return c;
723 return GNUNET_SYSERR;
724}
725
726/**
700 * Gets the reward of the last performed step 727 * Gets the reward of the last performed step
701 * @param solver solver handle 728 * @param solver solver handle
702 * @return the reward 729 * @return the reward
@@ -712,11 +739,13 @@ envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
712 double pref_match = 0; 739 double pref_match = 0;
713 double bw_norm; 740 double bw_norm;
714 struct RIL_Network *net; 741 struct RIL_Network *net;
742 int prop_index;
715 743
716 preferences = solver->callbacks->get_preferences (solver->callbacks->get_preferences_cls, &agent->peer); 744 preferences = solver->callbacks->get_preferences (solver->callbacks->get_preferences_cls, &agent->peer);
717 properties = solver->callbacks->get_properties (solver->callbacks->get_properties_cls, 745 properties = solver->callbacks->get_properties (solver->callbacks->get_properties_cls,
718 agent->address_inuse); 746 agent->address_inuse);
719 pref_match += preferences[GNUNET_ATS_PREFERENCE_LATENCY] * properties[GNUNET_ATS_QUALITY_NET_DELAY]; 747 prop_index = ril_find_property_index(GNUNET_ATS_QUALITY_NET_DELAY);
748 pref_match += preferences[GNUNET_ATS_PREFERENCE_LATENCY] * properties[prop_index];
720 bw_norm = GNUNET_MAX(2, ((( 749 bw_norm = GNUNET_MAX(2, (((
721 ((double) agent->bw_in / (double) ril_get_max_bw(agent, GNUNET_YES)) + 750 ((double) agent->bw_in / (double) ril_get_max_bw(agent, GNUNET_YES)) +
722 ((double) agent->bw_out / (double) ril_get_max_bw(agent, GNUNET_NO)) 751 ((double) agent->bw_out / (double) ril_get_max_bw(agent, GNUNET_NO))
@@ -1171,7 +1200,6 @@ ril_cut_from_vector (void **old,
1171 unsigned int bytes_hole; 1200 unsigned int bytes_hole;
1172 unsigned int bytes_after; 1201 unsigned int bytes_after;
1173 1202
1174
1175 GNUNET_assert(old_length > hole_length); 1203 GNUNET_assert(old_length > hole_length);
1176 GNUNET_assert(old_length >= (hole_start + hole_length)); 1204 GNUNET_assert(old_length >= (hole_start + hole_length));
1177 1205
@@ -1446,7 +1474,7 @@ GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network
1446 1474
1447 //increase size of old state vector 1475 //increase size of old state vector
1448 agent->m = m_old; 1476 agent->m = m_old;
1449 GNUNET_array_grow(agent->s_old, agent->m, m_new); //TODO initialize new state features? 1477 GNUNET_array_grow(agent->s_old, agent->m, m_new); //TODO random instead of zero-initialization of state features
1450 1478
1451 agent->m = m_old; 1479 agent->m = m_old;
1452 GNUNET_array_grow(agent->e, agent->m, m_new); 1480 GNUNET_array_grow(agent->e, agent->m, m_new);
@@ -1473,7 +1501,6 @@ GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network
1473void 1501void
1474GAS_ril_address_delete (void *solver, struct ATS_Address *address, int session_only) 1502GAS_ril_address_delete (void *solver, struct ATS_Address *address, int session_only)
1475{ 1503{
1476 //TODO? use session as feature
1477 struct GAS_RIL_Handle *s = solver; 1504 struct GAS_RIL_Handle *s = solver;
1478 struct RIL_Peer_Agent *agent; 1505 struct RIL_Peer_Agent *agent;
1479 struct RIL_Address_Wrapped *address_wrapped; 1506 struct RIL_Address_Wrapped *address_wrapped;
@@ -1612,9 +1639,8 @@ GAS_ril_address_session_changed (void *solver,
1612 uint32_t cur_session, 1639 uint32_t cur_session,
1613 uint32_t new_session) 1640 uint32_t new_session)
1614{ 1641{
1615 //TODO? consider session change in solver behaviour
1616 /* 1642 /*
1617 * Potentially add session activity as a feature in state vector 1643 * TODO? Future Work: Potentially add session activity as a feature in state vector
1618 */ 1644 */
1619 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_session_changed()\n"); 1645 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_session_changed()\n");
1620} 1646}
@@ -1706,7 +1732,7 @@ GAS_ril_address_preference_feedback (void *solver,
1706 enum GNUNET_ATS_PreferenceKind kind, 1732 enum GNUNET_ATS_PreferenceKind kind,
1707 double score) 1733 double score)
1708{ 1734{
1709 //TODO! talk to Matthias about feedback 1735 //TODO! collect feedback
1710 LOG(GNUNET_ERROR_TYPE_DEBUG, 1736 LOG(GNUNET_ERROR_TYPE_DEBUG,
1711 "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f from application %s for " 1737 "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f from application %s for "
1712 "preference %s for %d seconds\n", GNUNET_i2s (peer), "UNKNOWN", 1738 "preference %s for %d seconds\n", GNUNET_i2s (peer), "UNKNOWN",