diff options
author | Fabian Oehlmann <oehlmann@in.tum.de> | 2013-11-22 18:03:25 +0000 |
---|---|---|
committer | Fabian Oehlmann <oehlmann@in.tum.de> | 2013-11-22 18:03:25 +0000 |
commit | ccf016b4b6e47bf0f37e3d2b00b046784253f003 (patch) | |
tree | e9df2cde9c0559ee7a1c1d7fd1731d9a48c72006 /src/ats | |
parent | f2970b4525aae963e03b7d0c9a079473b20451b4 (diff) | |
download | gnunet-ccf016b4b6e47bf0f37e3d2b00b046784253f003.tar.gz gnunet-ccf016b4b6e47bf0f37e3d2b00b046784253f003.zip |
removed task_pending attribute
testing reward function changes
Diffstat (limited to 'src/ats')
-rwxr-xr-x | src/ats/libgnunet_plugin_ats_ril.c | 60 |
1 files changed, 29 insertions, 31 deletions
diff --git a/src/ats/libgnunet_plugin_ats_ril.c b/src/ats/libgnunet_plugin_ats_ril.c index b2e90e77c..f3f958177 100755 --- a/src/ats/libgnunet_plugin_ats_ril.c +++ b/src/ats/libgnunet_plugin_ats_ril.c | |||
@@ -108,7 +108,7 @@ struct RIL_Learning_Parameters | |||
108 | double lambda; | 108 | double lambda; |
109 | 109 | ||
110 | /** | 110 | /** |
111 | * Ratio, whith what probability an agent should explore in the e-greed policy | 111 | * Ratio, with what probability an agent should explore in the e-greed policy |
112 | */ | 112 | */ |
113 | double explore_ratio; | 113 | double explore_ratio; |
114 | 114 | ||
@@ -296,11 +296,6 @@ struct GAS_RIL_Handle | |||
296 | GNUNET_SCHEDULER_TaskIdentifier step_next_task_id; | 296 | GNUNET_SCHEDULER_TaskIdentifier step_next_task_id; |
297 | 297 | ||
298 | /** | 298 | /** |
299 | * Whether a step is already scheduled | ||
300 | */ | ||
301 | int step_task_pending; | ||
302 | |||
303 | /** | ||
304 | * Variable discount factor, dependent on time between steps | 299 | * Variable discount factor, dependent on time between steps |
305 | */ | 300 | */ |
306 | double global_discount_variable; | 301 | double global_discount_variable; |
@@ -345,6 +340,11 @@ struct GAS_RIL_Handle | |||
345 | */ | 340 | */ |
346 | struct RIL_Peer_Agent * agents_head; | 341 | struct RIL_Peer_Agent * agents_head; |
347 | struct RIL_Peer_Agent * agents_tail; | 342 | struct RIL_Peer_Agent * agents_tail; |
343 | |||
344 | /** | ||
345 | * Shutdown | ||
346 | */ | ||
347 | int done; | ||
348 | }; | 348 | }; |
349 | 349 | ||
350 | /* | 350 | /* |
@@ -926,14 +926,14 @@ envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | |||
926 | } | 926 | } |
927 | if (overutilized > 0) | 927 | if (overutilized > 0) |
928 | { | 928 | { |
929 | //return -1. * (double) overutilized; | 929 | return -1. * (double) overutilized / 1024; |
930 | return -1; | 930 | return -1; |
931 | } | 931 | } |
932 | 932 | ||
933 | reward += envi_reward_global (solver) * (solver->parameters.reward_global_share); | 933 | reward += envi_reward_global (solver) * (solver->parameters.reward_global_share); |
934 | reward += envi_reward_local (solver, agent) * (1 - solver->parameters.reward_global_share); | 934 | reward += envi_reward_local (solver, agent) * (1 - solver->parameters.reward_global_share); |
935 | 935 | ||
936 | return reward; | 936 | return (reward - 1.) * 100; |
937 | } | 937 | } |
938 | 938 | ||
939 | /** | 939 | /** |
@@ -1237,7 +1237,7 @@ agent_step (struct RIL_Peer_Agent *agent) | |||
1237 | agent->step_count += 1; | 1237 | agent->step_count += 1; |
1238 | } | 1238 | } |
1239 | 1239 | ||
1240 | static int | 1240 | static void |
1241 | ril_step (struct GAS_RIL_Handle *solver); | 1241 | ril_step (struct GAS_RIL_Handle *solver); |
1242 | 1242 | ||
1243 | /** | 1243 | /** |
@@ -1252,7 +1252,7 @@ ril_step_scheduler_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *t | |||
1252 | { | 1252 | { |
1253 | struct GAS_RIL_Handle *solver = cls; | 1253 | struct GAS_RIL_Handle *solver = cls; |
1254 | 1254 | ||
1255 | solver->step_task_pending = GNUNET_NO; | 1255 | solver->step_next_task_id = GNUNET_SCHEDULER_NO_TASK; |
1256 | ril_step (solver); | 1256 | ril_step (solver); |
1257 | } | 1257 | } |
1258 | 1258 | ||
@@ -1370,11 +1370,6 @@ ril_step_schedule_next (struct GAS_RIL_Handle *solver) | |||
1370 | double offset; | 1370 | double offset; |
1371 | struct GNUNET_TIME_Relative time_next; | 1371 | struct GNUNET_TIME_Relative time_next; |
1372 | 1372 | ||
1373 | if (solver->step_task_pending) | ||
1374 | { | ||
1375 | GNUNET_SCHEDULER_cancel (solver->step_next_task_id); | ||
1376 | } | ||
1377 | |||
1378 | used_ratio = ril_get_used_resource_ratio (solver); | 1373 | used_ratio = ril_get_used_resource_ratio (solver); |
1379 | 1374 | ||
1380 | GNUNET_assert( | 1375 | GNUNET_assert( |
@@ -1389,18 +1384,20 @@ ril_step_schedule_next (struct GAS_RIL_Handle *solver) | |||
1389 | GNUNET_assert(y <= (double ) solver->parameters.step_time_max.rel_value_us); | 1384 | GNUNET_assert(y <= (double ) solver->parameters.step_time_max.rel_value_us); |
1390 | GNUNET_assert(y >= (double ) solver->parameters.step_time_min.rel_value_us); | 1385 | GNUNET_assert(y >= (double ) solver->parameters.step_time_min.rel_value_us); |
1391 | 1386 | ||
1392 | time_next = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, (unsigned int) y); | 1387 | time_next = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, (unsigned long long) y); |
1393 | 1388 | ||
1394 | solver->step_next_task_id = GNUNET_SCHEDULER_add_delayed (time_next, &ril_step_scheduler_task, | 1389 | if ((GNUNET_SCHEDULER_NO_TASK == solver->step_next_task_id) && (GNUNET_NO == solver->done)) |
1395 | solver); | 1390 | { |
1396 | solver->step_task_pending = GNUNET_YES; | 1391 | solver->step_next_task_id = GNUNET_SCHEDULER_add_delayed (time_next, &ril_step_scheduler_task, |
1392 | solver); | ||
1393 | } | ||
1397 | } | 1394 | } |
1398 | 1395 | ||
1399 | /** | 1396 | /** |
1400 | * Triggers one step per agent | 1397 | * Triggers one step per agent |
1401 | * @param solver | 1398 | * @param solver |
1402 | */ | 1399 | */ |
1403 | static int | 1400 | static void |
1404 | ril_step (struct GAS_RIL_Handle *solver) | 1401 | ril_step (struct GAS_RIL_Handle *solver) |
1405 | { | 1402 | { |
1406 | struct RIL_Peer_Agent *cur; | 1403 | struct RIL_Peer_Agent *cur; |
@@ -1411,7 +1408,7 @@ ril_step (struct GAS_RIL_Handle *solver) | |||
1411 | if (GNUNET_YES == solver->bulk_lock) | 1408 | if (GNUNET_YES == solver->bulk_lock) |
1412 | { | 1409 | { |
1413 | solver->bulk_changes++; | 1410 | solver->bulk_changes++; |
1414 | return GNUNET_NO; | 1411 | return; |
1415 | } | 1412 | } |
1416 | 1413 | ||
1417 | ril_inform (solver, GAS_OP_SOLVE_START, GAS_STAT_SUCCESS); | 1414 | ril_inform (solver, GAS_OP_SOLVE_START, GAS_STAT_SUCCESS); |
@@ -1426,9 +1423,9 @@ ril_step (struct GAS_RIL_Handle *solver) | |||
1426 | //calculate tau, i.e. how many real valued time units have passed, one time unit is one minimum time step | 1423 | //calculate tau, i.e. how many real valued time units have passed, one time unit is one minimum time step |
1427 | time_now = GNUNET_TIME_absolute_get (); | 1424 | time_now = GNUNET_TIME_absolute_get (); |
1428 | time_delta = GNUNET_TIME_absolute_get_difference (solver->step_time_last, time_now); | 1425 | time_delta = GNUNET_TIME_absolute_get_difference (solver->step_time_last, time_now); |
1426 | solver->step_time_last = time_now; | ||
1429 | tau = ((double) time_delta.rel_value_us) | 1427 | tau = ((double) time_delta.rel_value_us) |
1430 | / ((double) solver->parameters.step_time_min.rel_value_us); | 1428 | / ((double) solver->parameters.step_time_min.rel_value_us); |
1431 | solver->step_time_last = time_now; | ||
1432 | 1429 | ||
1433 | //calculate reward discounts (once per step for all agents) | 1430 | //calculate reward discounts (once per step for all agents) |
1434 | solver->global_discount_variable = pow (M_E, ((-1.) * ((double) solver->parameters.beta) * tau)); | 1431 | solver->global_discount_variable = pow (M_E, ((-1.) * ((double) solver->parameters.beta) * tau)); |
@@ -1468,8 +1465,6 @@ ril_step (struct GAS_RIL_Handle *solver) | |||
1468 | } | 1465 | } |
1469 | } | 1466 | } |
1470 | ril_inform (solver, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, GAS_STAT_SUCCESS); | 1467 | ril_inform (solver, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, GAS_STAT_SUCCESS); |
1471 | |||
1472 | return GNUNET_YES; | ||
1473 | } | 1468 | } |
1474 | 1469 | ||
1475 | static int | 1470 | static int |
@@ -1532,7 +1527,7 @@ agent_init (void *s, const struct GNUNET_PeerIdentity *peer) | |||
1532 | agent->peer = *peer; | 1527 | agent->peer = *peer; |
1533 | agent->step_count = 0; | 1528 | agent->step_count = 0; |
1534 | agent->is_active = GNUNET_NO; | 1529 | agent->is_active = GNUNET_NO; |
1535 | agent->bw_in = 1024; | 1530 | agent->bw_in = 1024; //TODO? put min_bw |
1536 | agent->bw_out = 1024; | 1531 | agent->bw_out = 1024; |
1537 | agent->suggestion_issue = GNUNET_NO; | 1532 | agent->suggestion_issue = GNUNET_NO; |
1538 | agent->n = RIL_ACTION_TYPE_NUM; | 1533 | agent->n = RIL_ACTION_TYPE_NUM; |
@@ -1806,6 +1801,7 @@ libgnunet_plugin_ats_ril_init (void *cls) | |||
1806 | solver->network_entries = GNUNET_malloc (env->network_count * sizeof (struct RIL_Network)); | 1801 | solver->network_entries = GNUNET_malloc (env->network_count * sizeof (struct RIL_Network)); |
1807 | solver->step_count = 0; | 1802 | solver->step_count = 0; |
1808 | solver->global_state_networks = GNUNET_malloc (solver->networks_count * RIL_FEATURES_NETWORK_COUNT * sizeof (double)); | 1803 | solver->global_state_networks = GNUNET_malloc (solver->networks_count * RIL_FEATURES_NETWORK_COUNT * sizeof (double)); |
1804 | solver->done = GNUNET_NO; | ||
1809 | 1805 | ||
1810 | for (c = 0; c < env->network_count; c++) | 1806 | for (c = 0; c < env->network_count; c++) |
1811 | { | 1807 | { |
@@ -1816,10 +1812,10 @@ libgnunet_plugin_ats_ril_init (void *cls) | |||
1816 | LOG(GNUNET_ERROR_TYPE_INFO, "Quotas for %s network: IN %llu - OUT %llu\n", GNUNET_ATS_print_network_type(cur->type), cur->bw_in_available/1024, cur->bw_out_available/1024); | 1812 | LOG(GNUNET_ERROR_TYPE_INFO, "Quotas for %s network: IN %llu - OUT %llu\n", GNUNET_ATS_print_network_type(cur->type), cur->bw_in_available/1024, cur->bw_out_available/1024); |
1817 | } | 1813 | } |
1818 | 1814 | ||
1819 | solver->step_next_task_id = GNUNET_SCHEDULER_add_delayed ( | 1815 | // solver->step_next_task_id = GNUNET_SCHEDULER_add_delayed ( |
1820 | GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_get_millisecond_ (), 1000), | 1816 | // GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_get_millisecond_ (), 1000), |
1821 | &ril_step_scheduler_task, solver); | 1817 | // &ril_step_scheduler_task, solver); |
1822 | solver->step_task_pending = GNUNET_YES; | 1818 | // solver->step_next_task_id = GNUNET_SCHEDULER_add_now(&ril_step_scheduler_task, solver); |
1823 | 1819 | ||
1824 | LOG(GNUNET_ERROR_TYPE_INFO, "Parameters:\n"); | 1820 | LOG(GNUNET_ERROR_TYPE_INFO, "Parameters:\n"); |
1825 | LOG(GNUNET_ERROR_TYPE_INFO, "Algorithm = %s, alpha = %f, beta = %f, lambda = %f\n", | 1821 | LOG(GNUNET_ERROR_TYPE_INFO, "Algorithm = %s, alpha = %f, beta = %f, lambda = %f\n", |
@@ -1848,6 +1844,8 @@ libgnunet_plugin_ats_ril_done (void *cls) | |||
1848 | 1844 | ||
1849 | LOG(GNUNET_ERROR_TYPE_DEBUG, "API_done() Shutting down RIL solver\n"); | 1845 | LOG(GNUNET_ERROR_TYPE_DEBUG, "API_done() Shutting down RIL solver\n"); |
1850 | 1846 | ||
1847 | s->done = GNUNET_YES; | ||
1848 | |||
1851 | cur_agent = s->agents_head; | 1849 | cur_agent = s->agents_head; |
1852 | while (NULL != cur_agent) | 1850 | while (NULL != cur_agent) |
1853 | { | 1851 | { |
@@ -1857,7 +1855,7 @@ libgnunet_plugin_ats_ril_done (void *cls) | |||
1857 | cur_agent = next_agent; | 1855 | cur_agent = next_agent; |
1858 | } | 1856 | } |
1859 | 1857 | ||
1860 | if (s->step_task_pending) | 1858 | if (GNUNET_SCHEDULER_NO_TASK != s->step_next_task_id) |
1861 | { | 1859 | { |
1862 | GNUNET_SCHEDULER_cancel (s->step_next_task_id); | 1860 | GNUNET_SCHEDULER_cancel (s->step_next_task_id); |
1863 | } | 1861 | } |
@@ -1865,7 +1863,7 @@ libgnunet_plugin_ats_ril_done (void *cls) | |||
1865 | GNUNET_free(s->global_state_networks); | 1863 | GNUNET_free(s->global_state_networks); |
1866 | GNUNET_free(s); | 1864 | GNUNET_free(s); |
1867 | 1865 | ||
1868 | return NULL ; | 1866 | return NULL; |
1869 | } | 1867 | } |
1870 | 1868 | ||
1871 | /** | 1869 | /** |