aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Oehlmann <oehlmann@in.tum.de>2014-01-09 17:56:41 +0000
committerFabian Oehlmann <oehlmann@in.tum.de>2014-01-09 17:56:41 +0000
commit03f90c3e7c5d6e4bcabef18de9f6b4e5d7e77e45 (patch)
tree36f94b91023dc0e3ed93662423d267f31987a523
parentdd6d52c21761cdcc8ffc5a8896f8244b34238094 (diff)
downloadgnunet-03f90c3e7c5d6e4bcabef18de9f6b4e5d7e77e45.tar.gz
gnunet-03f90c3e7c5d6e4bcabef18de9f6b4e5d7e77e45.zip
keep addresses inuse
-rwxr-xr-xsrc/ats/plugin_ats_ril.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/ats/plugin_ats_ril.c b/src/ats/plugin_ats_ril.c
index e452ca30a..da974dd72 100755
--- a/src/ats/plugin_ats_ril.c
+++ b/src/ats/plugin_ats_ril.c
@@ -495,11 +495,14 @@ static int
495agent_get_action_max (struct RIL_Peer_Agent *agent, double *state) 495agent_get_action_max (struct RIL_Peer_Agent *agent, double *state)
496{ 496{
497 int i; 497 int i;
498 int num_actions;
498 int max_i = RIL_ACTION_INVALID; 499 int max_i = RIL_ACTION_INVALID;
499 double cur_q; 500 double cur_q;
500 double max_q = -DBL_MAX; 501 double max_q = -DBL_MAX;
501 502
502 for (i = 0; i < agent->n; i++) 503 num_actions = agent->address_inuse->used ? RIL_ACTION_TYPE_NUM : agent->n;
504
505 for (i = 0; i < num_actions; i++)
503 { 506 {
504 cur_q = agent_estimate_q (agent, state, i); 507 cur_q = agent_estimate_q (agent, state, i);
505 if (cur_q > max_q) 508 if (cur_q > max_q)
@@ -1170,19 +1173,22 @@ static int
1170agent_select_egreedy (struct RIL_Peer_Agent *agent, double *state) 1173agent_select_egreedy (struct RIL_Peer_Agent *agent, double *state)
1171{ 1174{
1172 int action; 1175 int action;
1176 int num_actions;
1173 double r = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1177 double r = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1174 UINT32_MAX) / (double) UINT32_MAX; 1178 UINT32_MAX) / (double) UINT32_MAX;
1175 1179
1176 if (r < agent->envi->parameters.explore_ratio) 1180 num_actions = agent->address_inuse->used ? RIL_ACTION_TYPE_NUM : agent->n;
1181
1182 if (r < agent->envi->parameters.explore_ratio) //explore
1177 { 1183 {
1178 action = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, agent->n); 1184 action = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, num_actions);
1179 if (RIL_ALGO_Q == agent->envi->parameters.algorithm) 1185 if (RIL_ALGO_Q == agent->envi->parameters.algorithm)
1180 { 1186 {
1181 agent_modify_eligibility(agent, RIL_E_ZERO, NULL, action); 1187 agent_modify_eligibility(agent, RIL_E_ZERO, NULL, action);
1182 } 1188 }
1183 return action; 1189 return action;
1184 } 1190 }
1185 else 1191 else //exploit
1186 { 1192 {
1187 action = agent_get_action_max(agent, state); 1193 action = agent_get_action_max(agent, state);
1188 if (RIL_ALGO_Q == agent->envi->parameters.algorithm) 1194 if (RIL_ALGO_Q == agent->envi->parameters.algorithm)
@@ -1208,26 +1214,29 @@ agent_select_softmax (struct RIL_Peer_Agent *agent, double *state)
1208{ 1214{
1209 int i; 1215 int i;
1210 int a_max; 1216 int a_max;
1217 int num_actions;
1211 double eqt[agent->n]; 1218 double eqt[agent->n];
1212 double p[agent->n]; 1219 double p[agent->n];
1213 double sum = 0; 1220 double sum = 0;
1214 double r; 1221 double r;
1215 1222
1223 num_actions = agent->address_inuse->used ? RIL_ACTION_TYPE_NUM : agent->n;
1224
1216 a_max = agent_get_action_max(agent, state); 1225 a_max = agent_get_action_max(agent, state);
1217 1226
1218 for (i=0; i<agent->n; i++) 1227 for (i=0; i<num_actions; i++)
1219 { 1228 {
1220 eqt[i] = exp(agent_estimate_q(agent,state,i) / agent->envi->parameters.temperature); 1229 eqt[i] = exp(agent_estimate_q(agent,state,i) / agent->envi->parameters.temperature);
1221 sum += eqt[i]; 1230 sum += eqt[i];
1222 } 1231 }
1223 for (i=0; i<agent->n; i++) 1232 for (i=0; i<num_actions; i++)
1224 { 1233 {
1225 p[i] = eqt[i]/sum; 1234 p[i] = eqt[i]/sum;
1226 } 1235 }
1227 r = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1236 r = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1228 UINT32_MAX) / (double) UINT32_MAX; 1237 UINT32_MAX) / (double) UINT32_MAX;
1229 sum = 0; 1238 sum = 0;
1230 for (i=0; i<agent->n; i++) 1239 for (i=0; i<num_actions; i++)
1231 { 1240 {
1232 if (sum + p[i] > r) 1241 if (sum + p[i] > r)
1233 { 1242 {
@@ -2292,9 +2301,6 @@ GAS_ril_address_session_changed (void *solver,
2292 uint32_t cur_session, 2301 uint32_t cur_session,
2293 uint32_t new_session) 2302 uint32_t new_session)
2294{ 2303{
2295 /*
2296 * TODO? Future Work: Potentially add session activity as a feature in state vector
2297 */
2298 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_session_changed()\n"); 2304 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_session_changed()\n");
2299} 2305}
2300 2306
@@ -2311,9 +2317,6 @@ GAS_ril_address_session_changed (void *solver,
2311void 2317void
2312GAS_ril_address_inuse_changed (void *solver, struct ATS_Address *address, int in_use) 2318GAS_ril_address_inuse_changed (void *solver, struct ATS_Address *address, int in_use)
2313{ 2319{
2314 /*
2315 * TODO? Future Work: Potentially add usage variable to state vector
2316 */
2317 LOG(GNUNET_ERROR_TYPE_DEBUG, 2320 LOG(GNUNET_ERROR_TYPE_DEBUG,
2318 "API_address_inuse_changed() Usage for %s address of peer '%s' changed to %s\n", 2321 "API_address_inuse_changed() Usage for %s address of peer '%s' changed to %s\n",
2319 address->plugin, GNUNET_i2s (&address->peer), (GNUNET_YES == in_use) ? "USED" : "UNUSED"); 2322 address->plugin, GNUNET_i2s (&address->peer), (GNUNET_YES == in_use) ? "USED" : "UNUSED");