diff options
author | Fabian Oehlmann <oehlmann@in.tum.de> | 2013-09-26 10:20:16 +0000 |
---|---|---|
committer | Fabian Oehlmann <oehlmann@in.tum.de> | 2013-09-26 10:20:16 +0000 |
commit | 7627b7c93947204620a2995f3fed2aca3c668a16 (patch) | |
tree | c61b34f55a22869eafc1f8f3292b2c1e14679222 /src | |
parent | 0c71268773cfca7d1d5c7411a7b31d9d09ea800e (diff) | |
download | gnunet-7627b7c93947204620a2995f3fed2aca3c668a16.tar.gz gnunet-7627b7c93947204620a2995f3fed2aca3c668a16.zip |
ats_ril: added inc and dec actions
Diffstat (limited to 'src')
-rwxr-xr-x | src/ats/gnunet-service-ats-solver_ril.c | 156 |
1 files changed, 114 insertions, 42 deletions
diff --git a/src/ats/gnunet-service-ats-solver_ril.c b/src/ats/gnunet-service-ats-solver_ril.c index 806a278b7..9aecd1747 100755 --- a/src/ats/gnunet-service-ats-solver_ril.c +++ b/src/ats/gnunet-service-ats-solver_ril.c | |||
@@ -45,18 +45,22 @@ | |||
45 | 45 | ||
46 | enum RIL_Action_Type | 46 | enum RIL_Action_Type |
47 | { | 47 | { |
48 | RIL_ACTION_BW_IN_DBL = 0, | 48 | RIL_ACTION_NOTHING = 0, |
49 | RIL_ACTION_BW_OUT_DBL = 1, | 49 | RIL_ACTION_BW_IN_DBL = 1, |
50 | RIL_ACTION_BW_IN_HLV = 2, | 50 | RIL_ACTION_BW_IN_HLV = 2, |
51 | RIL_ACTION_BW_OUT_HLV = 3, | 51 | RIL_ACTION_BW_IN_INC = 3, |
52 | RIL_ACTION_TYPE_NUM = 4 | 52 | RIL_ACTION_BW_IN_DEC = 4, |
53 | RIL_ACTION_BW_OUT_DBL = 5, | ||
54 | RIL_ACTION_BW_OUT_HLV = 6, | ||
55 | RIL_ACTION_BW_OUT_INC = 7, | ||
56 | RIL_ACTION_BW_OUT_DEC = 8, | ||
57 | RIL_ACTION_TYPE_NUM = 9 | ||
53 | }; | 58 | }; |
54 | //TODO! add the rest of the actions | 59 | //TODO! add the rest of the actions |
55 | 60 | ||
56 | enum RIL_Algorithm | 61 | enum RIL_Algorithm |
57 | { | 62 | { |
58 | RIL_ALGO_SARSA = 0, | 63 | RIL_ALGO_SARSA = 0, RIL_ALGO_Q = 1 |
59 | RIL_ALGO_Q = 1 | ||
60 | }; | 64 | }; |
61 | 65 | ||
62 | enum RIL_E_Modification | 66 | enum RIL_E_Modification |
@@ -477,11 +481,10 @@ envi_change_active_address (struct GAS_RIL_Handle *solver, | |||
477 | notify |= GNUNET_YES; | 481 | notify |= GNUNET_YES; |
478 | } | 482 | } |
479 | 483 | ||
480 | |||
481 | if (notify) | 484 | if (notify) |
482 | { | 485 | { |
483 | solver->callbacks->bw_changed (solver->callbacks->bw_changed_cls, | 486 | solver->callbacks->bw_changed (solver->callbacks->bw_changed_cls, |
484 | agent->address); | 487 | agent->address); |
485 | } | 488 | } |
486 | } | 489 | } |
487 | 490 | ||
@@ -500,10 +503,10 @@ envi_get_state (struct GAS_RIL_Handle *solver) | |||
500 | for (i = 0; i < solver->networks_count; i++) | 503 | for (i = 0; i < solver->networks_count; i++) |
501 | { | 504 | { |
502 | net = &solver->network_entries[i]; | 505 | net = &solver->network_entries[i]; |
503 | state[i*4 + 0] = (double) net->bw_in_assigned; | 506 | state[i * 4 + 0] = (double) net->bw_in_assigned; |
504 | state[i*4 + 1] = (double) net->bw_in_available; | 507 | state[i * 4 + 1] = (double) net->bw_in_available; |
505 | state[i*4 + 2] = (double) net->bw_out_assigned; | 508 | state[i * 4 + 2] = (double) net->bw_out_assigned; |
506 | state[i*4 + 3] = (double) net->bw_out_available; | 509 | state[i * 4 + 3] = (double) net->bw_out_available; |
507 | } | 510 | } |
508 | 511 | ||
509 | return state; | 512 | return state; |
@@ -530,11 +533,13 @@ envi_action_bw_double (struct GAS_RIL_Handle *solver, | |||
530 | { | 533 | { |
531 | if (direction_in) | 534 | if (direction_in) |
532 | { | 535 | { |
533 | envi_change_active_address(solver, agent, agent->address, agent->bw_in * 2, agent->bw_out); | 536 | envi_change_active_address (solver, agent, agent->address, agent->bw_in * 2, |
537 | agent->bw_out); | ||
534 | } | 538 | } |
535 | else | 539 | else |
536 | { | 540 | { |
537 | envi_change_active_address(solver, agent, agent->address, agent->bw_in, agent->bw_out * 2); | 541 | envi_change_active_address (solver, agent, agent->address, agent->bw_in, |
542 | agent->bw_out * 2); | ||
538 | } | 543 | } |
539 | } | 544 | } |
540 | 545 | ||
@@ -551,14 +556,61 @@ envi_action_bw_halven (struct GAS_RIL_Handle *solver, | |||
551 | new_bw = agent->bw_in / 2; | 556 | new_bw = agent->bw_in / 2; |
552 | if (new_bw < min_bw) | 557 | if (new_bw < min_bw) |
553 | new_bw = min_bw; | 558 | new_bw = min_bw; |
554 | envi_change_active_address(solver, agent, agent->address, new_bw, agent->bw_out); | 559 | envi_change_active_address (solver, agent, agent->address, new_bw, |
560 | agent->bw_out); | ||
555 | } | 561 | } |
556 | else | 562 | else |
557 | { | 563 | { |
558 | new_bw = agent->bw_out / 2; | 564 | new_bw = agent->bw_out / 2; |
559 | if (new_bw < min_bw) | 565 | if (new_bw < min_bw) |
560 | new_bw = min_bw; | 566 | new_bw = min_bw; |
561 | envi_change_active_address(solver, agent, agent->address, agent->bw_in, new_bw); | 567 | envi_change_active_address (solver, agent, agent->address, agent->bw_in, |
568 | new_bw); | ||
569 | } | ||
570 | } | ||
571 | |||
572 | static void | ||
573 | envi_action_bw_inc (struct GAS_RIL_Handle *solver, | ||
574 | struct RIL_Peer_Agent *agent, | ||
575 | int direction_in) | ||
576 | { | ||
577 | uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); | ||
578 | |||
579 | if (direction_in) | ||
580 | { | ||
581 | envi_change_active_address (solver, agent, agent->address, | ||
582 | agent->bw_in + (5 * min_bw), agent->bw_out); | ||
583 | } | ||
584 | else | ||
585 | { | ||
586 | envi_change_active_address (solver, agent, agent->address, agent->bw_in, | ||
587 | agent->bw_out + (5 * min_bw)); | ||
588 | } | ||
589 | } | ||
590 | |||
591 | static void | ||
592 | envi_action_bw_dec (struct GAS_RIL_Handle *solver, | ||
593 | struct RIL_Peer_Agent *agent, | ||
594 | int direction_in) | ||
595 | { | ||
596 | uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); | ||
597 | unsigned long long new_bw; | ||
598 | |||
599 | if (direction_in) | ||
600 | { | ||
601 | new_bw = agent->bw_in - (5 * min_bw); | ||
602 | if (new_bw < min_bw) | ||
603 | new_bw = min_bw; | ||
604 | envi_change_active_address (solver, agent, agent->address, new_bw, | ||
605 | agent->bw_out); | ||
606 | } | ||
607 | else | ||
608 | { | ||
609 | new_bw = agent->bw_out - (5 * min_bw); | ||
610 | if (new_bw < min_bw) | ||
611 | new_bw = min_bw; | ||
612 | envi_change_active_address (solver, agent, agent->address, agent->bw_in, | ||
613 | new_bw); | ||
562 | } | 614 | } |
563 | } | 615 | } |
564 | 616 | ||
@@ -574,18 +626,35 @@ envi_do_action (struct GAS_RIL_Handle *solver, | |||
574 | { | 626 | { |
575 | switch (action) | 627 | switch (action) |
576 | { | 628 | { |
629 | case RIL_ACTION_NOTHING: | ||
630 | break; | ||
577 | case RIL_ACTION_BW_IN_DBL: | 631 | case RIL_ACTION_BW_IN_DBL: |
578 | envi_action_bw_double (solver, agent, GNUNET_YES); | 632 | envi_action_bw_double (solver, agent, GNUNET_YES); |
579 | break; | 633 | break; |
580 | case RIL_ACTION_BW_IN_HLV: | 634 | case RIL_ACTION_BW_IN_HLV: |
581 | envi_action_bw_halven (solver, agent, GNUNET_YES); | 635 | envi_action_bw_halven (solver, agent, GNUNET_YES); |
582 | break; | 636 | break; |
637 | case RIL_ACTION_BW_IN_INC: | ||
638 | envi_action_bw_inc (solver, agent, GNUNET_YES); | ||
639 | break; | ||
640 | case RIL_ACTION_BW_IN_DEC: | ||
641 | envi_action_bw_dec (solver, agent, GNUNET_YES); | ||
642 | break; | ||
583 | case RIL_ACTION_BW_OUT_DBL: | 643 | case RIL_ACTION_BW_OUT_DBL: |
584 | envi_action_bw_double (solver, agent, GNUNET_NO); | 644 | envi_action_bw_double (solver, agent, GNUNET_NO); |
585 | break; | 645 | break; |
586 | case RIL_ACTION_BW_OUT_HLV: | 646 | case RIL_ACTION_BW_OUT_HLV: |
587 | envi_action_bw_halven (solver, agent, GNUNET_NO); | 647 | envi_action_bw_halven (solver, agent, GNUNET_NO); |
588 | break; | 648 | break; |
649 | case RIL_ACTION_BW_OUT_INC: | ||
650 | envi_action_bw_inc (solver, agent, GNUNET_NO); | ||
651 | break; | ||
652 | case RIL_ACTION_BW_OUT_DEC: | ||
653 | envi_action_bw_dec (solver, agent, GNUNET_NO); | ||
654 | break; | ||
655 | default: | ||
656 | // error - action does not exist | ||
657 | GNUNET_assert(GNUNET_NO); | ||
589 | } | 658 | } |
590 | } | 659 | } |
591 | 660 | ||
@@ -606,7 +675,7 @@ agent_step (struct RIL_Peer_Agent *agent) | |||
606 | s_next = envi_get_state (agent->envi); | 675 | s_next = envi_get_state (agent->envi); |
607 | reward = envi_get_reward (agent->envi, agent); | 676 | reward = envi_get_reward (agent->envi, agent); |
608 | 677 | ||
609 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "agent_step() with algorithm %s\n", | 678 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "agent_step() with algorithm %s\n", |
610 | agent->envi->parameters.algorithm ? "Q" : "SARSA"); | 679 | agent->envi->parameters.algorithm ? "Q" : "SARSA"); |
611 | 680 | ||
612 | switch (agent->envi->parameters.algorithm) | 681 | switch (agent->envi->parameters.algorithm) |
@@ -782,8 +851,6 @@ ril_remove_agent (struct GAS_RIL_Handle *s, struct RIL_Peer_Agent *agent) | |||
782 | // return c; | 851 | // return c; |
783 | //} | 852 | //} |
784 | 853 | ||
785 | |||
786 | |||
787 | /** | 854 | /** |
788 | * Returns the agent for a peer | 855 | * Returns the agent for a peer |
789 | * @param s solver handle | 856 | * @param s solver handle |
@@ -808,7 +875,7 @@ ril_get_agent (struct GAS_RIL_Handle *solver, | |||
808 | 875 | ||
809 | if (create) | 876 | if (create) |
810 | return agent_init (solver, peer); | 877 | return agent_init (solver, peer); |
811 | return NULL; | 878 | return NULL ; |
812 | } | 879 | } |
813 | 880 | ||
814 | static int | 881 | static int |
@@ -837,7 +904,7 @@ ril_init_agents_it (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
837 | struct RIL_Peer_Agent *agent = NULL; | 904 | struct RIL_Peer_Agent *agent = NULL; |
838 | uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); | 905 | uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); |
839 | 906 | ||
840 | if (ril_network_is_active(address->solver_information)) | 907 | if (ril_network_is_active (address->solver_information)) |
841 | { | 908 | { |
842 | agent = ril_get_agent (solver, &address->peer, GNUNET_YES); | 909 | agent = ril_get_agent (solver, &address->peer, GNUNET_YES); |
843 | 910 | ||
@@ -857,7 +924,8 @@ ril_init_agents_it (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
857 | } | 924 | } |
858 | 925 | ||
859 | static void | 926 | static void |
860 | ril_get_new_address_or_delete (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | 927 | ril_get_new_address_or_delete (struct GAS_RIL_Handle *solver, |
928 | struct RIL_Peer_Agent *agent) | ||
861 | { | 929 | { |
862 | uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); | 930 | uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); |
863 | //get new address for agent or delete agent | 931 | //get new address for agent or delete agent |
@@ -869,11 +937,11 @@ ril_get_new_address_or_delete (struct GAS_RIL_Handle *solver, struct RIL_Peer_Ag | |||
869 | if (NULL == agent->address) //no other address available | 937 | if (NULL == agent->address) //no other address available |
870 | { | 938 | { |
871 | agent->active = GNUNET_NO; | 939 | agent->active = GNUNET_NO; |
872 | ril_remove_agent(solver, agent); | 940 | ril_remove_agent (solver, agent); |
873 | } | 941 | } |
874 | else | 942 | else |
875 | { | 943 | { |
876 | envi_change_active_address(solver, agent, agent->address, min_bw, min_bw); | 944 | envi_change_active_address (solver, agent, agent->address, min_bw, min_bw); |
877 | } | 945 | } |
878 | } | 946 | } |
879 | 947 | ||
@@ -891,11 +959,12 @@ ril_get_network (struct GAS_RIL_Handle *s, uint32_t type) | |||
891 | 959 | ||
892 | for (i = 0; i < s->networks_count; i++) | 960 | for (i = 0; i < s->networks_count; i++) |
893 | { | 961 | { |
894 | if (s->network_entries[i].type == type) { | 962 | if (s->network_entries[i].type == type) |
963 | { | ||
895 | return &s->network_entries[i]; | 964 | return &s->network_entries[i]; |
896 | } | 965 | } |
897 | } | 966 | } |
898 | return NULL; | 967 | return NULL ; |
899 | } | 968 | } |
900 | 969 | ||
901 | /** | 970 | /** |
@@ -1115,7 +1184,7 @@ GAS_ril_address_add (void *solver, | |||
1115 | * and action vector | 1184 | * and action vector |
1116 | */ | 1185 | */ |
1117 | 1186 | ||
1118 | address->solver_information = ril_get_network(s, network); | 1187 | address->solver_information = ril_get_network (s, network); |
1119 | 1188 | ||
1120 | /* | 1189 | /* |
1121 | * reiterate all addresses, create new agent if necessary and give the agent the address | 1190 | * reiterate all addresses, create new agent if necessary and give the agent the address |
@@ -1154,23 +1223,24 @@ GAS_ril_address_delete (void *solver, | |||
1154 | struct GAS_RIL_Handle *s = solver; | 1223 | struct GAS_RIL_Handle *s = solver; |
1155 | struct RIL_Peer_Agent *agent; | 1224 | struct RIL_Peer_Agent *agent; |
1156 | 1225 | ||
1157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "API_address_delete() deleting %s address %p for peer '%s'\n", | 1226 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1158 | address->active ? "active" : "inactive", | 1227 | "API_address_delete() deleting %s address %p for peer '%s'\n", |
1159 | address, | 1228 | address->active ? "active" : "inactive", address, |
1160 | GNUNET_i2s(&address->peer)); | 1229 | GNUNET_i2s (&address->peer)); |
1161 | 1230 | ||
1162 | agent = ril_get_agent (s, &address->peer, GNUNET_NO); | 1231 | agent = ril_get_agent (s, &address->peer, GNUNET_NO); |
1163 | 1232 | ||
1164 | if (NULL == agent) | 1233 | if (NULL == agent) |
1165 | { | 1234 | { |
1166 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "API_address_delete() deleting address for unallocated agent\n"); | 1235 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1236 | "API_address_delete() deleting address for unallocated agent\n"); | ||
1167 | return; | 1237 | return; |
1168 | } | 1238 | } |
1169 | 1239 | ||
1170 | if (address == agent->address) //if used address deleted | 1240 | if (address == agent->address) //if used address deleted |
1171 | { | 1241 | { |
1172 | address->active = GNUNET_NO; | 1242 | address->active = GNUNET_NO; |
1173 | ril_get_new_address_or_delete(s, agent); | 1243 | ril_get_new_address_or_delete (s, agent); |
1174 | } | 1244 | } |
1175 | 1245 | ||
1176 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1246 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
@@ -1279,18 +1349,18 @@ GAS_ril_address_change_network (void *solver, | |||
1279 | GNUNET_ATS_print_network_type (current_network), | 1349 | GNUNET_ATS_print_network_type (current_network), |
1280 | GNUNET_ATS_print_network_type (new_network)); | 1350 | GNUNET_ATS_print_network_type (new_network)); |
1281 | 1351 | ||
1282 | address->solver_information = ril_get_network(solver, new_network); | 1352 | address->solver_information = ril_get_network (solver, new_network); |
1283 | 1353 | ||
1284 | if (address->active) | 1354 | if (address->active) |
1285 | { | 1355 | { |
1286 | agent = ril_get_agent(solver, &address->peer, GNUNET_NO); | 1356 | agent = ril_get_agent (solver, &address->peer, GNUNET_NO); |
1287 | 1357 | ||
1288 | //remove from old network | 1358 | //remove from old network |
1289 | net = ril_get_network (s, current_network); | 1359 | net = ril_get_network (s, current_network); |
1290 | net->bw_in_assigned -= agent->bw_in; | 1360 | net->bw_in_assigned -= agent->bw_in; |
1291 | net->bw_out_assigned -= agent->bw_out; | 1361 | net->bw_out_assigned -= agent->bw_out; |
1292 | 1362 | ||
1293 | if (ril_network_is_active(ril_get_network(s, new_network))) | 1363 | if (ril_network_is_active (ril_get_network (s, new_network))) |
1294 | { | 1364 | { |
1295 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New network is active\n"); | 1365 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New network is active\n"); |
1296 | //add to new network | 1366 | //add to new network |
@@ -1307,13 +1377,15 @@ GAS_ril_address_change_network (void *solver, | |||
1307 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New network is not active\n"); | 1377 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New network is not active\n"); |
1308 | 1378 | ||
1309 | net = agent->address->solver_information; | 1379 | net = agent->address->solver_information; |
1310 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Before: active address %p is %s\n", agent->address, GNUNET_ATS_print_network_type(net->type)); | 1380 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Before: active address %p is %s\n", |
1381 | agent->address, GNUNET_ATS_print_network_type (net->type)); | ||
1311 | 1382 | ||
1312 | address->active = GNUNET_NO; | 1383 | address->active = GNUNET_NO; |
1313 | ril_get_new_address_or_delete(s, agent); | 1384 | ril_get_new_address_or_delete (s, agent); |
1314 | 1385 | ||
1315 | net = agent->address->solver_information; | 1386 | net = agent->address->solver_information; |
1316 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "After: active address %p is %s\n", agent->address, GNUNET_ATS_print_network_type(net->type)); | 1387 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "After: active address %p is %s\n", |
1388 | agent->address, GNUNET_ATS_print_network_type (net->type)); | ||
1317 | } | 1389 | } |
1318 | } | 1390 | } |
1319 | } | 1391 | } |
@@ -1396,9 +1468,9 @@ GAS_ril_get_preferred_address (void *solver, | |||
1396 | if (NULL == agent) | 1468 | if (NULL == agent) |
1397 | { | 1469 | { |
1398 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1470 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1399 | "API_get_preferred_address() No agent for peer '%s' do not suggest address\n", | 1471 | "API_get_preferred_address() No agent for peer '%s' do not suggest address\n", |
1400 | GNUNET_i2s (peer)); | 1472 | GNUNET_i2s (peer)); |
1401 | return NULL; | 1473 | return NULL ; |
1402 | } | 1474 | } |
1403 | 1475 | ||
1404 | agent->active = GNUNET_YES; | 1476 | agent->active = GNUNET_YES; |