diff options
Diffstat (limited to 'src/ats/plugin_ats_ril.c')
-rw-r--r-- | src/ats/plugin_ats_ril.c | 2134 |
1 files changed, 1071 insertions, 1063 deletions
diff --git a/src/ats/plugin_ats_ril.c b/src/ats/plugin_ats_ril.c index 9f78450c2..abf265f19 100644 --- a/src/ats/plugin_ats_ril.c +++ b/src/ats/plugin_ats_ril.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2011-2014 GNUnet e.V. | 3 | Copyright (C) 2011-2014 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -32,17 +32,17 @@ | |||
32 | 32 | ||
33 | 33 | ||
34 | 34 | ||
35 | #define LOG(kind,...) GNUNET_log_from (kind, "ats-ril",__VA_ARGS__) | 35 | #define LOG(kind, ...) GNUNET_log_from(kind, "ats-ril", __VA_ARGS__) |
36 | 36 | ||
37 | #define RIL_MIN_BW (5 * ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__)) | 37 | #define RIL_MIN_BW (5 * ntohl(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__)) |
38 | #define RIL_MAX_BW GNUNET_ATS_MaxBandwidth | 38 | #define RIL_MAX_BW GNUNET_ATS_MaxBandwidth |
39 | 39 | ||
40 | #define RIL_ACTION_INVALID -1 | 40 | #define RIL_ACTION_INVALID -1 |
41 | #define RIL_INTERVAL_EXPONENT 10 | 41 | #define RIL_INTERVAL_EXPONENT 10 |
42 | #define RIL_UTILITY_DELAY_MAX 1000 | 42 | #define RIL_UTILITY_DELAY_MAX 1000 |
43 | 43 | ||
44 | #define RIL_DEFAULT_STEP_TIME_MIN GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 200) | 44 | #define RIL_DEFAULT_STEP_TIME_MIN GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 200) |
45 | #define RIL_DEFAULT_STEP_TIME_MAX GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 2000) | 45 | #define RIL_DEFAULT_STEP_TIME_MAX GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 2000) |
46 | #define RIL_DEFAULT_ALGORITHM RIL_ALGO_SARSA | 46 | #define RIL_DEFAULT_ALGORITHM RIL_ALGO_SARSA |
47 | #define RIL_DEFAULT_SELECT RIL_SELECT_SOFTMAX | 47 | #define RIL_DEFAULT_SELECT RIL_SELECT_SOFTMAX |
48 | #define RIL_DEFAULT_WELFARE RIL_WELFARE_NASH | 48 | #define RIL_DEFAULT_WELFARE RIL_WELFARE_NASH |
@@ -71,8 +71,7 @@ | |||
71 | * to a particular address. The action of switching to address with index i is depicted by the | 71 | * to a particular address. The action of switching to address with index i is depicted by the |
72 | * number (RIL_ACTION_TYPE_NUM + i). | 72 | * number (RIL_ACTION_TYPE_NUM + i). |
73 | */ | 73 | */ |
74 | enum RIL_Action_Type | 74 | enum RIL_Action_Type { |
75 | { | ||
76 | RIL_ACTION_NOTHING = 0, | 75 | RIL_ACTION_NOTHING = 0, |
77 | RIL_ACTION_BW_IN_DBL = -2, //TODO? Potentially add more actions | 76 | RIL_ACTION_BW_IN_DBL = -2, //TODO? Potentially add more actions |
78 | RIL_ACTION_BW_IN_HLV = -3, | 77 | RIL_ACTION_BW_IN_HLV = -3, |
@@ -85,26 +84,22 @@ enum RIL_Action_Type | |||
85 | RIL_ACTION_TYPE_NUM = 5 | 84 | RIL_ACTION_TYPE_NUM = 5 |
86 | }; | 85 | }; |
87 | 86 | ||
88 | enum RIL_Algorithm | 87 | enum RIL_Algorithm { |
89 | { | ||
90 | RIL_ALGO_SARSA = 0, | 88 | RIL_ALGO_SARSA = 0, |
91 | RIL_ALGO_Q = 1 | 89 | RIL_ALGO_Q = 1 |
92 | }; | 90 | }; |
93 | 91 | ||
94 | enum RIL_Select | 92 | enum RIL_Select { |
95 | { | ||
96 | RIL_SELECT_SOFTMAX = 0, | 93 | RIL_SELECT_SOFTMAX = 0, |
97 | RIL_SELECT_EGREEDY = 1 | 94 | RIL_SELECT_EGREEDY = 1 |
98 | }; | 95 | }; |
99 | 96 | ||
100 | enum RIL_Welfare | 97 | enum RIL_Welfare { |
101 | { | ||
102 | RIL_WELFARE_NASH, | 98 | RIL_WELFARE_NASH, |
103 | RIL_WELFARE_EGALITARIAN | 99 | RIL_WELFARE_EGALITARIAN |
104 | }; | 100 | }; |
105 | 101 | ||
106 | enum RIL_E_Modification | 102 | enum RIL_E_Modification { |
107 | { | ||
108 | RIL_E_DECAY, | 103 | RIL_E_DECAY, |
109 | RIL_E_ZERO, | 104 | RIL_E_ZERO, |
110 | RIL_E_ACCUMULATE, | 105 | RIL_E_ACCUMULATE, |
@@ -114,8 +109,7 @@ enum RIL_E_Modification | |||
114 | /** | 109 | /** |
115 | * Global learning parameters | 110 | * Global learning parameters |
116 | */ | 111 | */ |
117 | struct RIL_Learning_Parameters | 112 | struct RIL_Learning_Parameters { |
118 | { | ||
119 | /** | 113 | /** |
120 | * The TD-algorithm to use | 114 | * The TD-algorithm to use |
121 | */ | 115 | */ |
@@ -205,8 +199,7 @@ struct RIL_Learning_Parameters | |||
205 | /** | 199 | /** |
206 | * Wrapper for addresses to store them in agent's linked list | 200 | * Wrapper for addresses to store them in agent's linked list |
207 | */ | 201 | */ |
208 | struct RIL_Address_Wrapped | 202 | struct RIL_Address_Wrapped { |
209 | { | ||
210 | /** | 203 | /** |
211 | * Next in DLL | 204 | * Next in DLL |
212 | */ | 205 | */ |
@@ -224,8 +217,7 @@ struct RIL_Address_Wrapped | |||
224 | }; | 217 | }; |
225 | 218 | ||
226 | 219 | ||
227 | struct RIL_Peer_Agent | 220 | struct RIL_Peer_Agent { |
228 | { | ||
229 | /** | 221 | /** |
230 | * Next agent in solver's linked list | 222 | * Next agent in solver's linked list |
231 | */ | 223 | */ |
@@ -337,8 +329,7 @@ struct RIL_Peer_Agent | |||
337 | double nop_bonus; | 329 | double nop_bonus; |
338 | }; | 330 | }; |
339 | 331 | ||
340 | struct RIL_Scope | 332 | struct RIL_Scope { |
341 | { | ||
342 | /** | 333 | /** |
343 | * ATS network type | 334 | * ATS network type |
344 | */ | 335 | */ |
@@ -388,8 +379,7 @@ struct RIL_Scope | |||
388 | /** | 379 | /** |
389 | * A handle for the reinforcement learning solver | 380 | * A handle for the reinforcement learning solver |
390 | */ | 381 | */ |
391 | struct GAS_RIL_Handle | 382 | struct GAS_RIL_Handle { |
392 | { | ||
393 | /** | 383 | /** |
394 | * The solver-plugin environment of the solver-plugin API | 384 | * The solver-plugin environment of the solver-plugin API |
395 | */ | 385 | */ |
@@ -476,9 +466,9 @@ struct GAS_RIL_Handle | |||
476 | * @return estimation value | 466 | * @return estimation value |
477 | */ | 467 | */ |
478 | static double | 468 | static double |
479 | agent_q (struct RIL_Peer_Agent *agent, | 469 | agent_q(struct RIL_Peer_Agent *agent, |
480 | const double *state, | 470 | const double *state, |
481 | int action) | 471 | int action) |
482 | { | 472 | { |
483 | unsigned int i; | 473 | unsigned int i; |
484 | double result = 0.0; | 474 | double result = 0.0; |
@@ -488,7 +478,7 @@ agent_q (struct RIL_Peer_Agent *agent, | |||
488 | 478 | ||
489 | /* prevent crashes if learning diverges */ | 479 | /* prevent crashes if learning diverges */ |
490 | if (isnan(result)) | 480 | if (isnan(result)) |
491 | return isnan(result) * UINT32_MAX; | 481 | return isnan(result) * UINT32_MAX; |
492 | if (isinf(result)) | 482 | if (isinf(result)) |
493 | return isinf(result) * UINT32_MAX; | 483 | return isinf(result) * UINT32_MAX; |
494 | return result; | 484 | return result; |
@@ -503,18 +493,18 @@ agent_q (struct RIL_Peer_Agent *agent, | |||
503 | * @return the index, starting with zero | 493 | * @return the index, starting with zero |
504 | */ | 494 | */ |
505 | static int | 495 | static int |
506 | agent_address_get_index (struct RIL_Peer_Agent *agent, struct ATS_Address *address) | 496 | agent_address_get_index(struct RIL_Peer_Agent *agent, struct ATS_Address *address) |
507 | { | 497 | { |
508 | int i; | 498 | int i; |
509 | struct RIL_Address_Wrapped *cur; | 499 | struct RIL_Address_Wrapped *cur; |
510 | 500 | ||
511 | i = -1; | 501 | i = -1; |
512 | for (cur = agent->addresses_head; NULL != cur; cur = cur->next) | 502 | for (cur = agent->addresses_head; NULL != cur; cur = cur->next) |
513 | { | 503 | { |
514 | i++; | 504 | i++; |
515 | if (cur->address_naked == address) | 505 | if (cur->address_naked == address) |
516 | return i; | 506 | return i; |
517 | } | 507 | } |
518 | return i; | 508 | return i; |
519 | } | 509 | } |
520 | 510 | ||
@@ -527,7 +517,7 @@ agent_address_get_index (struct RIL_Peer_Agent *agent, struct ATS_Address *addre | |||
527 | * @return wrapped address | 517 | * @return wrapped address |
528 | */ | 518 | */ |
529 | static struct RIL_Address_Wrapped * | 519 | static struct RIL_Address_Wrapped * |
530 | agent_address_get_wrapped (struct RIL_Peer_Agent *agent, struct ATS_Address *address) | 520 | agent_address_get_wrapped(struct RIL_Peer_Agent *agent, struct ATS_Address *address) |
531 | { | 521 | { |
532 | struct RIL_Address_Wrapped *cur; | 522 | struct RIL_Address_Wrapped *cur; |
533 | 523 | ||
@@ -539,62 +529,67 @@ agent_address_get_wrapped (struct RIL_Peer_Agent *agent, struct ATS_Address *add | |||
539 | 529 | ||
540 | 530 | ||
541 | static int | 531 | static int |
542 | agent_action_is_possible (struct RIL_Peer_Agent *agent, int action) | 532 | agent_action_is_possible(struct RIL_Peer_Agent *agent, int action) |
543 | { | 533 | { |
544 | int address_index; | 534 | int address_index; |
545 | 535 | ||
546 | switch (action) | 536 | switch (action) |
547 | { | ||
548 | case RIL_ACTION_NOTHING: | ||
549 | return GNUNET_YES; | ||
550 | break; | ||
551 | case RIL_ACTION_BW_IN_INC: | ||
552 | case RIL_ACTION_BW_IN_DBL: | ||
553 | if (agent->bw_in >= RIL_MAX_BW) | ||
554 | return GNUNET_NO; | ||
555 | else | ||
556 | return GNUNET_YES; | ||
557 | break; | ||
558 | case RIL_ACTION_BW_IN_DEC: | ||
559 | case RIL_ACTION_BW_IN_HLV: | ||
560 | if (agent->bw_in <= 0) | ||
561 | return GNUNET_NO; | ||
562 | else | ||
563 | return GNUNET_YES; | ||
564 | break; | ||
565 | case RIL_ACTION_BW_OUT_INC: | ||
566 | case RIL_ACTION_BW_OUT_DBL: | ||
567 | if (agent->bw_out >= RIL_MAX_BW) | ||
568 | return GNUNET_NO; | ||
569 | else | ||
570 | return GNUNET_YES; | ||
571 | break; | ||
572 | case RIL_ACTION_BW_OUT_DEC: | ||
573 | case RIL_ACTION_BW_OUT_HLV: | ||
574 | if (agent->bw_out <= 0) | ||
575 | return GNUNET_NO; | ||
576 | else | ||
577 | return GNUNET_YES; | ||
578 | break; | ||
579 | default: | ||
580 | if ((action >= RIL_ACTION_TYPE_NUM) && (action < agent->n)) //switch address action | ||
581 | { | 537 | { |
582 | address_index = action - RIL_ACTION_TYPE_NUM; | 538 | case RIL_ACTION_NOTHING: |
539 | return GNUNET_YES; | ||
540 | break; | ||
541 | |||
542 | case RIL_ACTION_BW_IN_INC: | ||
543 | case RIL_ACTION_BW_IN_DBL: | ||
544 | if (agent->bw_in >= RIL_MAX_BW) | ||
545 | return GNUNET_NO; | ||
546 | else | ||
547 | return GNUNET_YES; | ||
548 | break; | ||
583 | 549 | ||
584 | GNUNET_assert(address_index >= 0); | 550 | case RIL_ACTION_BW_IN_DEC: |
585 | GNUNET_assert( | 551 | case RIL_ACTION_BW_IN_HLV: |
586 | address_index <= agent_address_get_index (agent, agent->addresses_tail->address_naked)); | 552 | if (agent->bw_in <= 0) |
553 | return GNUNET_NO; | ||
554 | else | ||
555 | return GNUNET_YES; | ||
556 | break; | ||
557 | |||
558 | case RIL_ACTION_BW_OUT_INC: | ||
559 | case RIL_ACTION_BW_OUT_DBL: | ||
560 | if (agent->bw_out >= RIL_MAX_BW) | ||
561 | return GNUNET_NO; | ||
562 | else | ||
563 | return GNUNET_YES; | ||
564 | break; | ||
587 | 565 | ||
588 | if ((agent_address_get_index(agent, agent->address_inuse) == address_index) || | 566 | case RIL_ACTION_BW_OUT_DEC: |
589 | agent->address_inuse->active) | 567 | case RIL_ACTION_BW_OUT_HLV: |
568 | if (agent->bw_out <= 0) | ||
590 | return GNUNET_NO; | 569 | return GNUNET_NO; |
591 | else | 570 | else |
592 | return GNUNET_YES; | 571 | return GNUNET_YES; |
593 | break; | 572 | break; |
573 | |||
574 | default: | ||
575 | if ((action >= RIL_ACTION_TYPE_NUM) && (action < agent->n)) //switch address action | ||
576 | { | ||
577 | address_index = action - RIL_ACTION_TYPE_NUM; | ||
578 | |||
579 | GNUNET_assert(address_index >= 0); | ||
580 | GNUNET_assert( | ||
581 | address_index <= agent_address_get_index(agent, agent->addresses_tail->address_naked)); | ||
582 | |||
583 | if ((agent_address_get_index(agent, agent->address_inuse) == address_index) || | ||
584 | agent->address_inuse->active) | ||
585 | return GNUNET_NO; | ||
586 | else | ||
587 | return GNUNET_YES; | ||
588 | break; | ||
589 | } | ||
590 | // error - action does not exist | ||
591 | GNUNET_assert(GNUNET_NO); | ||
594 | } | 592 | } |
595 | // error - action does not exist | ||
596 | GNUNET_assert(GNUNET_NO); | ||
597 | } | ||
598 | } | 593 | } |
599 | 594 | ||
600 | 595 | ||
@@ -607,7 +602,7 @@ agent_action_is_possible (struct RIL_Peer_Agent *agent, int action) | |||
607 | * @return the action promising most future reward | 602 | * @return the action promising most future reward |
608 | */ | 603 | */ |
609 | static int | 604 | static int |
610 | agent_get_action_max (struct RIL_Peer_Agent *agent, double *state) | 605 | agent_get_action_max(struct RIL_Peer_Agent *agent, double *state) |
611 | { | 606 | { |
612 | int i; | 607 | int i; |
613 | int max_i = RIL_ACTION_INVALID; | 608 | int max_i = RIL_ACTION_INVALID; |
@@ -615,17 +610,17 @@ agent_get_action_max (struct RIL_Peer_Agent *agent, double *state) | |||
615 | double max_q = -DBL_MAX; | 610 | double max_q = -DBL_MAX; |
616 | 611 | ||
617 | for (i = 0; i < agent->n; i++) | 612 | for (i = 0; i < agent->n; i++) |
618 | { | ||
619 | if (agent_action_is_possible(agent, i)) | ||
620 | { | 613 | { |
621 | cur_q = agent_q (agent, state, i); | 614 | if (agent_action_is_possible(agent, i)) |
622 | if (cur_q > max_q) | 615 | { |
623 | { | 616 | cur_q = agent_q(agent, state, i); |
624 | max_q = cur_q; | 617 | if (cur_q > max_q) |
625 | max_i = i; | 618 | { |
626 | } | 619 | max_q = cur_q; |
620 | max_i = i; | ||
621 | } | ||
622 | } | ||
627 | } | 623 | } |
628 | } | ||
629 | 624 | ||
630 | GNUNET_assert(RIL_ACTION_INVALID != max_i); | 625 | GNUNET_assert(RIL_ACTION_INVALID != max_i); |
631 | 626 | ||
@@ -639,38 +634,38 @@ agent_get_action_max (struct RIL_Peer_Agent *agent, double *state) | |||
639 | * @return the action index | 634 | * @return the action index |
640 | */ | 635 | */ |
641 | static int | 636 | static int |
642 | agent_get_action_random (struct RIL_Peer_Agent *agent) | 637 | agent_get_action_random(struct RIL_Peer_Agent *agent) |
643 | { | 638 | { |
644 | int i; | 639 | int i; |
645 | int is_possible[agent->n]; | 640 | int is_possible[agent->n]; |
646 | int sum = 0; | 641 | int sum = 0; |
647 | int r; | 642 | int r; |
648 | 643 | ||
649 | for (i = 0; i<agent->n; i++) | 644 | for (i = 0; i < agent->n; i++) |
650 | { | ||
651 | if (agent_action_is_possible(agent, i)) | ||
652 | { | ||
653 | is_possible[i] = GNUNET_YES; | ||
654 | sum++; | ||
655 | } | ||
656 | else | ||
657 | { | 645 | { |
658 | is_possible[i] = GNUNET_NO; | 646 | if (agent_action_is_possible(agent, i)) |
647 | { | ||
648 | is_possible[i] = GNUNET_YES; | ||
649 | sum++; | ||
650 | } | ||
651 | else | ||
652 | { | ||
653 | is_possible[i] = GNUNET_NO; | ||
654 | } | ||
659 | } | 655 | } |
660 | } | ||
661 | 656 | ||
662 | r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, sum); | 657 | r = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, sum); |
663 | 658 | ||
664 | sum = -1; | 659 | sum = -1; |
665 | for (i = 0; i<agent->n; i++) | 660 | for (i = 0; i < agent->n; i++) |
666 | { | ||
667 | if (is_possible[i]) | ||
668 | { | 661 | { |
669 | sum++; | 662 | if (is_possible[i]) |
670 | if (sum == r) | 663 | { |
671 | return i; | 664 | sum++; |
665 | if (sum == r) | ||
666 | return i; | ||
667 | } | ||
672 | } | 668 | } |
673 | } | ||
674 | 669 | ||
675 | GNUNET_assert(GNUNET_NO); | 670 | GNUNET_assert(GNUNET_NO); |
676 | return RIL_ACTION_INVALID; | 671 | return RIL_ACTION_INVALID; |
@@ -686,7 +681,7 @@ agent_get_action_random (struct RIL_Peer_Agent *agent) | |||
686 | * @param a_prime the new | 681 | * @param a_prime the new |
687 | */ | 682 | */ |
688 | static void | 683 | static void |
689 | agent_update (struct RIL_Peer_Agent *agent, double reward, double *s_next, int a_prime) | 684 | agent_update(struct RIL_Peer_Agent *agent, double reward, double *s_next, int a_prime) |
690 | { | 685 | { |
691 | int i; | 686 | int i; |
692 | int k; | 687 | int k; |
@@ -694,8 +689,8 @@ agent_update (struct RIL_Peer_Agent *agent, double reward, double *s_next, int a | |||
694 | double **theta = agent->W; | 689 | double **theta = agent->W; |
695 | 690 | ||
696 | delta = agent->envi->global_discount_integrated * reward; //reward | 691 | delta = agent->envi->global_discount_integrated * reward; //reward |
697 | delta += agent->envi->global_discount_variable * agent_q (agent, s_next, a_prime); //discounted future value | 692 | delta += agent->envi->global_discount_variable * agent_q(agent, s_next, a_prime); //discounted future value |
698 | delta -= agent_q (agent, agent->s_old, agent->a_old); //one step | 693 | delta -= agent_q(agent, agent->s_old, agent->a_old); //one step |
699 | 694 | ||
700 | // LOG(GNUNET_ERROR_TYPE_INFO, "update() Step# %llu Q(s,a): %f a: %f r: %f y: %f Q(s+1,a+1) = %f delta: %f\n", | 695 | // LOG(GNUNET_ERROR_TYPE_INFO, "update() Step# %llu Q(s,a): %f a: %f r: %f y: %f Q(s+1,a+1) = %f delta: %f\n", |
701 | // agent->step_count, | 696 | // agent->step_count, |
@@ -707,17 +702,17 @@ agent_update (struct RIL_Peer_Agent *agent, double reward, double *s_next, int a | |||
707 | // delta); | 702 | // delta); |
708 | 703 | ||
709 | for (k = 0; k < agent->n; k++) | 704 | for (k = 0; k < agent->n; k++) |
710 | { | ||
711 | for (i = 0; i < agent->m; i++) | ||
712 | { | 705 | { |
713 | // LOG(GNUNET_ERROR_TYPE_INFO, "alpha = %f delta = %f e[%d] = %f\n", | 706 | for (i = 0; i < agent->m; i++) |
714 | // agent->envi->parameters.alpha, | 707 | { |
715 | // delta, | 708 | // LOG(GNUNET_ERROR_TYPE_INFO, "alpha = %f delta = %f e[%d] = %f\n", |
716 | // i, | 709 | // agent->envi->parameters.alpha, |
717 | // agent->e[i]); | 710 | // delta, |
718 | theta[k][i] += agent->envi->parameters.alpha * delta * agent->E[k][i]; | 711 | // i, |
712 | // agent->e[i]); | ||
713 | theta[k][i] += agent->envi->parameters.alpha * delta * agent->E[k][i]; | ||
714 | } | ||
719 | } | 715 | } |
720 | } | ||
721 | } | 716 | } |
722 | 717 | ||
723 | 718 | ||
@@ -734,38 +729,41 @@ agent_update (struct RIL_Peer_Agent *agent, double reward, double *s_next, int a | |||
734 | * @param action the action to take | 729 | * @param action the action to take |
735 | */ | 730 | */ |
736 | static void | 731 | static void |
737 | agent_modify_eligibility (struct RIL_Peer_Agent *agent, | 732 | agent_modify_eligibility(struct RIL_Peer_Agent *agent, |
738 | enum RIL_E_Modification mod, | 733 | enum RIL_E_Modification mod, |
739 | double *feature, | 734 | double *feature, |
740 | int action) | 735 | int action) |
741 | { | 736 | { |
742 | int i; | 737 | int i; |
743 | int k; | 738 | int k; |
744 | 739 | ||
745 | for (i = 0; i < agent->m; i++) | 740 | for (i = 0; i < agent->m; i++) |
746 | { | ||
747 | switch (mod) | ||
748 | { | 741 | { |
749 | case RIL_E_ACCUMULATE: | 742 | switch (mod) |
750 | agent->E[action][i] += feature[i]; | 743 | { |
751 | break; | 744 | case RIL_E_ACCUMULATE: |
752 | case RIL_E_REPLACE: | 745 | agent->E[action][i] += feature[i]; |
753 | agent->E[action][i] = agent->E[action][i] > feature[i] ? agent->E[action][i] : feature[i]; | 746 | break; |
754 | break; | 747 | |
755 | case RIL_E_DECAY: | 748 | case RIL_E_REPLACE: |
756 | for (k = 0; k < agent->n; k++) | 749 | agent->E[action][i] = agent->E[action][i] > feature[i] ? agent->E[action][i] : feature[i]; |
757 | { | 750 | break; |
758 | agent->E[k][i] *= agent->envi->global_discount_variable * agent->envi->parameters.lambda; | 751 | |
759 | } | 752 | case RIL_E_DECAY: |
760 | break; | 753 | for (k = 0; k < agent->n; k++) |
761 | case RIL_E_ZERO: | 754 | { |
762 | for (k = 0; k < agent->n; k++) | 755 | agent->E[k][i] *= agent->envi->global_discount_variable * agent->envi->parameters.lambda; |
763 | { | 756 | } |
764 | agent->E[k][i] = 0; | 757 | break; |
765 | } | 758 | |
766 | break; | 759 | case RIL_E_ZERO: |
760 | for (k = 0; k < agent->n; k++) | ||
761 | { | ||
762 | agent->E[k][i] = 0; | ||
763 | } | ||
764 | break; | ||
765 | } | ||
767 | } | 766 | } |
768 | } | ||
769 | } | 767 | } |
770 | 768 | ||
771 | /** | 769 | /** |
@@ -776,14 +774,14 @@ agent_modify_eligibility (struct RIL_Peer_Agent *agent, | |||
776 | * @param stat | 774 | * @param stat |
777 | */ | 775 | */ |
778 | static void | 776 | static void |
779 | ril_inform (struct GAS_RIL_Handle *solver, | 777 | ril_inform(struct GAS_RIL_Handle *solver, |
780 | enum GAS_Solver_Operation op, | 778 | enum GAS_Solver_Operation op, |
781 | enum GAS_Solver_Status stat) | 779 | enum GAS_Solver_Status stat) |
782 | { | 780 | { |
783 | solver->env->info_cb (solver->env->cls, | 781 | solver->env->info_cb(solver->env->cls, |
784 | op, | 782 | op, |
785 | stat, | 783 | stat, |
786 | GAS_INFO_NONE); | 784 | GAS_INFO_NONE); |
787 | } | 785 | } |
788 | 786 | ||
789 | /** | 787 | /** |
@@ -792,7 +790,7 @@ ril_inform (struct GAS_RIL_Handle *solver, | |||
792 | * @param net | 790 | * @param net |
793 | */ | 791 | */ |
794 | static unsigned long long | 792 | static unsigned long long |
795 | ril_get_max_bw (struct RIL_Scope *net) | 793 | ril_get_max_bw(struct RIL_Scope *net) |
796 | { | 794 | { |
797 | return GNUNET_MIN(2 * GNUNET_MAX(net->bw_in_available, net->bw_out_available), GNUNET_ATS_MaxBandwidth); | 795 | return GNUNET_MIN(2 * GNUNET_MAX(net->bw_in_available, net->bw_out_available), GNUNET_ATS_MaxBandwidth); |
798 | } | 796 | } |
@@ -809,82 +807,82 @@ ril_get_max_bw (struct RIL_Scope *net) | |||
809 | * @param silent disables invocation of the bw_changed callback, if #GNUNET_YES | 807 | * @param silent disables invocation of the bw_changed callback, if #GNUNET_YES |
810 | */ | 808 | */ |
811 | static void | 809 | static void |
812 | envi_set_active_suggestion (struct GAS_RIL_Handle *solver, | 810 | envi_set_active_suggestion(struct GAS_RIL_Handle *solver, |
813 | struct RIL_Peer_Agent *agent, | 811 | struct RIL_Peer_Agent *agent, |
814 | struct ATS_Address *new_address, | 812 | struct ATS_Address *new_address, |
815 | unsigned long long new_bw_in, | 813 | unsigned long long new_bw_in, |
816 | unsigned long long new_bw_out, | 814 | unsigned long long new_bw_out, |
817 | int silent) | 815 | int silent) |
818 | { | 816 | { |
819 | int notify = GNUNET_NO; | 817 | int notify = GNUNET_NO; |
820 | 818 | ||
821 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 819 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
822 | " set_active_suggestion() for peer '%s'\n", | 820 | " set_active_suggestion() for peer '%s'\n", |
823 | GNUNET_i2s (&agent->peer)); | 821 | GNUNET_i2s(&agent->peer)); |
824 | 822 | ||
825 | //address change | 823 | //address change |
826 | if (agent->address_inuse != new_address) | 824 | if (agent->address_inuse != new_address) |
827 | { | ||
828 | if (NULL != agent->address_inuse) | ||
829 | { | 825 | { |
830 | agent->address_inuse->active = GNUNET_NO; | 826 | if (NULL != agent->address_inuse) |
831 | agent->address_inuse->assigned_bw_in = 0; | 827 | { |
832 | agent->address_inuse->assigned_bw_out = 0; | 828 | agent->address_inuse->active = GNUNET_NO; |
833 | } | 829 | agent->address_inuse->assigned_bw_in = 0; |
834 | if (NULL != new_address) | 830 | agent->address_inuse->assigned_bw_out = 0; |
835 | { | 831 | } |
836 | LOG(GNUNET_ERROR_TYPE_DEBUG, " set address active: %s\n", agent->is_active ? "yes" : "no"); | 832 | if (NULL != new_address) |
837 | new_address->active = agent->is_active; | 833 | { |
838 | new_address->assigned_bw_in = agent->bw_in; | 834 | LOG(GNUNET_ERROR_TYPE_DEBUG, " set address active: %s\n", agent->is_active ? "yes" : "no"); |
839 | new_address->assigned_bw_out = agent->bw_out; | 835 | new_address->active = agent->is_active; |
840 | } | 836 | new_address->assigned_bw_in = agent->bw_in; |
841 | notify |= GNUNET_YES; | 837 | new_address->assigned_bw_out = agent->bw_out; |
842 | } | 838 | } |
843 | |||
844 | if (new_address) | ||
845 | { | ||
846 | //activity change | ||
847 | if (new_address->active != agent->is_active) | ||
848 | { | ||
849 | new_address->active = agent->is_active; | ||
850 | notify |= GNUNET_YES; | 839 | notify |= GNUNET_YES; |
851 | } | 840 | } |
852 | 841 | ||
853 | //bw change | 842 | if (new_address) |
854 | if (agent->bw_in != new_bw_in) | ||
855 | { | ||
856 | agent->bw_in = new_bw_in; | ||
857 | new_address->assigned_bw_in = new_bw_in; | ||
858 | notify |= GNUNET_YES; | ||
859 | } | ||
860 | if (agent->bw_out != new_bw_out) | ||
861 | { | 843 | { |
862 | agent->bw_out = new_bw_out; | 844 | //activity change |
863 | new_address->assigned_bw_out = new_bw_out; | 845 | if (new_address->active != agent->is_active) |
864 | notify |= GNUNET_YES; | 846 | { |
847 | new_address->active = agent->is_active; | ||
848 | notify |= GNUNET_YES; | ||
849 | } | ||
850 | |||
851 | //bw change | ||
852 | if (agent->bw_in != new_bw_in) | ||
853 | { | ||
854 | agent->bw_in = new_bw_in; | ||
855 | new_address->assigned_bw_in = new_bw_in; | ||
856 | notify |= GNUNET_YES; | ||
857 | } | ||
858 | if (agent->bw_out != new_bw_out) | ||
859 | { | ||
860 | agent->bw_out = new_bw_out; | ||
861 | new_address->assigned_bw_out = new_bw_out; | ||
862 | notify |= GNUNET_YES; | ||
863 | } | ||
865 | } | 864 | } |
866 | } | ||
867 | 865 | ||
868 | if (notify && agent->is_active && (GNUNET_NO == silent)) | 866 | if (notify && agent->is_active && (GNUNET_NO == silent)) |
869 | { | ||
870 | if (new_address) | ||
871 | { | ||
872 | LOG(GNUNET_ERROR_TYPE_DEBUG, " envi_set_active_suggestion() notify\n"); | ||
873 | agent->suggestion_issue = GNUNET_YES; | ||
874 | agent->suggestion_address = new_address; | ||
875 | } | ||
876 | else if (agent->address_inuse) | ||
877 | { | 867 | { |
878 | /* disconnect case, no new address */ | 868 | if (new_address) |
879 | GNUNET_assert(0 == agent->address_inuse->assigned_bw_in); | 869 | { |
880 | GNUNET_assert(0 == agent->address_inuse->assigned_bw_out); | 870 | LOG(GNUNET_ERROR_TYPE_DEBUG, " envi_set_active_suggestion() notify\n"); |
881 | agent->bw_in = 0; | 871 | agent->suggestion_issue = GNUNET_YES; |
882 | agent->bw_out = 0; | 872 | agent->suggestion_address = new_address; |
883 | 873 | } | |
884 | agent->suggestion_issue = GNUNET_YES; | 874 | else if (agent->address_inuse) |
885 | agent->suggestion_address = agent->address_inuse; | 875 | { |
876 | /* disconnect case, no new address */ | ||
877 | GNUNET_assert(0 == agent->address_inuse->assigned_bw_in); | ||
878 | GNUNET_assert(0 == agent->address_inuse->assigned_bw_out); | ||
879 | agent->bw_in = 0; | ||
880 | agent->bw_out = 0; | ||
881 | |||
882 | agent->suggestion_issue = GNUNET_YES; | ||
883 | agent->suggestion_address = agent->address_inuse; | ||
884 | } | ||
886 | } | 885 | } |
887 | } | ||
888 | agent->address_inuse = new_address; | 886 | agent->address_inuse = new_address; |
889 | } | 887 | } |
890 | 888 | ||
@@ -896,7 +894,7 @@ envi_set_active_suggestion (struct GAS_RIL_Handle *solver, | |||
896 | * @return pointer to the state vector | 894 | * @return pointer to the state vector |
897 | */ | 895 | */ |
898 | static double * | 896 | static double * |
899 | envi_get_state (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | 897 | envi_get_state(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) |
900 | { | 898 | { |
901 | double *state; | 899 | double *state; |
902 | double y[2]; | 900 | double y[2]; |
@@ -909,27 +907,27 @@ envi_get_state (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | |||
909 | int k; | 907 | int k; |
910 | unsigned long long max_bw; | 908 | unsigned long long max_bw; |
911 | 909 | ||
912 | state = GNUNET_malloc (sizeof(double) * agent->m); | 910 | state = GNUNET_malloc(sizeof(double) * agent->m); |
913 | 911 | ||
914 | max_bw = ril_get_max_bw((struct RIL_Scope *) agent->address_inuse->solver_information); | 912 | max_bw = ril_get_max_bw((struct RIL_Scope *)agent->address_inuse->solver_information); |
915 | 913 | ||
916 | y[0] = (double) agent->bw_out; | 914 | y[0] = (double)agent->bw_out; |
917 | y[1] = (double) agent->bw_in; | 915 | y[1] = (double)agent->bw_in; |
918 | 916 | ||
919 | m = agent_address_get_index (agent, agent->address_inuse) * (solver->parameters.rbf_divisor+1) * (solver->parameters.rbf_divisor+1); | 917 | m = agent_address_get_index(agent, agent->address_inuse) * (solver->parameters.rbf_divisor + 1) * (solver->parameters.rbf_divisor + 1); |
920 | for (i = 0; i <= solver->parameters.rbf_divisor; i++) | 918 | for (i = 0; i <= solver->parameters.rbf_divisor; i++) |
921 | { | ||
922 | for (k = 0; k <= solver->parameters.rbf_divisor; k++) | ||
923 | { | 919 | { |
924 | x[0] = (double) i * (double) max_bw / (double) solver->parameters.rbf_divisor; | 920 | for (k = 0; k <= solver->parameters.rbf_divisor; k++) |
925 | x[1] = (double) k * (double) max_bw / (double) solver->parameters.rbf_divisor; | 921 | { |
926 | d[0] = x[0]-y[0]; | 922 | x[0] = (double)i * (double)max_bw / (double)solver->parameters.rbf_divisor; |
927 | d[1] = x[1]-y[1]; | 923 | x[1] = (double)k * (double)max_bw / (double)solver->parameters.rbf_divisor; |
928 | sigma = (((double) max_bw / ((double) solver->parameters.rbf_divisor + 1)) * 0.5); | 924 | d[0] = x[0] - y[0]; |
929 | f = exp(-((d[0]*d[0] + d[1]*d[1]) / (2 * sigma * sigma))); | 925 | d[1] = x[1] - y[1]; |
930 | state[m++] = f; | 926 | sigma = (((double)max_bw / ((double)solver->parameters.rbf_divisor + 1)) * 0.5); |
927 | f = exp(-((d[0] * d[0] + d[1] * d[1]) / (2 * sigma * sigma))); | ||
928 | state[m++] = f; | ||
929 | } | ||
931 | } | 930 | } |
932 | } | ||
933 | 931 | ||
934 | return state; | 932 | return state; |
935 | } | 933 | } |
@@ -942,22 +940,22 @@ envi_get_state (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | |||
942 | * @return the utility value | 940 | * @return the utility value |
943 | */ | 941 | */ |
944 | static double | 942 | static double |
945 | agent_get_utility (struct RIL_Peer_Agent *agent) | 943 | agent_get_utility(struct RIL_Peer_Agent *agent) |
946 | { | 944 | { |
947 | const double *preferences; | 945 | const double *preferences; |
948 | double delay_atsi; | 946 | double delay_atsi; |
949 | double delay_norm; | 947 | double delay_norm; |
950 | double pref_match; | 948 | double pref_match; |
951 | 949 | ||
952 | preferences = agent->envi->env->get_preferences (agent->envi->env->cls, | 950 | preferences = agent->envi->env->get_preferences(agent->envi->env->cls, |
953 | &agent->peer); | 951 | &agent->peer); |
954 | 952 | ||
955 | delay_atsi = agent->address_inuse->norm_delay.norm; | 953 | delay_atsi = agent->address_inuse->norm_delay.norm; |
956 | delay_norm = RIL_UTILITY_DELAY_MAX*exp(-delay_atsi*0.00001); | 954 | delay_norm = RIL_UTILITY_DELAY_MAX * exp(-delay_atsi * 0.00001); |
957 | 955 | ||
958 | pref_match = preferences[GNUNET_ATS_PREFERENCE_LATENCY] * delay_norm; | 956 | pref_match = preferences[GNUNET_ATS_PREFERENCE_LATENCY] * delay_norm; |
959 | pref_match += preferences[GNUNET_ATS_PREFERENCE_BANDWIDTH] * | 957 | pref_match += preferences[GNUNET_ATS_PREFERENCE_BANDWIDTH] * |
960 | sqrt((double) (agent->bw_in/RIL_MIN_BW) * (double) (agent->bw_out/RIL_MIN_BW)); | 958 | sqrt((double)(agent->bw_in / RIL_MIN_BW) * (double)(agent->bw_out / RIL_MIN_BW)); |
961 | return pref_match; | 959 | return pref_match; |
962 | } | 960 | } |
963 | 961 | ||
@@ -970,41 +968,41 @@ agent_get_utility (struct RIL_Peer_Agent *agent) | |||
970 | * @return the social welfare value | 968 | * @return the social welfare value |
971 | */ | 969 | */ |
972 | static double | 970 | static double |
973 | ril_network_get_social_welfare (struct GAS_RIL_Handle *solver, struct RIL_Scope *scope) | 971 | ril_network_get_social_welfare(struct GAS_RIL_Handle *solver, struct RIL_Scope *scope) |
974 | { | 972 | { |
975 | struct RIL_Peer_Agent *cur; | 973 | struct RIL_Peer_Agent *cur; |
976 | double result; | 974 | double result; |
977 | 975 | ||
978 | switch (solver->parameters.social_welfare) | 976 | switch (solver->parameters.social_welfare) |
979 | { | ||
980 | case RIL_WELFARE_EGALITARIAN: | ||
981 | result = DBL_MAX; | ||
982 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) | ||
983 | { | ||
984 | if (cur->is_active && cur->address_inuse && (cur->address_inuse->solver_information == scope)) | ||
985 | { | ||
986 | result = GNUNET_MIN(result, agent_get_utility(cur)); | ||
987 | } | ||
988 | } | ||
989 | return result; | ||
990 | |||
991 | case RIL_WELFARE_NASH: | ||
992 | result = 0; | ||
993 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) | ||
994 | { | 977 | { |
995 | if (cur->is_active && cur->address_inuse && (cur->address_inuse->solver_information == scope)) | 978 | case RIL_WELFARE_EGALITARIAN: |
996 | { | 979 | result = DBL_MAX; |
997 | result *= pow(agent_get_utility(cur), 1.0 / (double) scope->active_agent_count); | 980 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) |
998 | } | 981 | { |
982 | if (cur->is_active && cur->address_inuse && (cur->address_inuse->solver_information == scope)) | ||
983 | { | ||
984 | result = GNUNET_MIN(result, agent_get_utility(cur)); | ||
985 | } | ||
986 | } | ||
987 | return result; | ||
988 | |||
989 | case RIL_WELFARE_NASH: | ||
990 | result = 0; | ||
991 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) | ||
992 | { | ||
993 | if (cur->is_active && cur->address_inuse && (cur->address_inuse->solver_information == scope)) | ||
994 | { | ||
995 | result *= pow(agent_get_utility(cur), 1.0 / (double)scope->active_agent_count); | ||
996 | } | ||
997 | } | ||
998 | return result; | ||
999 | } | 999 | } |
1000 | return result; | ||
1001 | } | ||
1002 | GNUNET_assert(GNUNET_NO); | 1000 | GNUNET_assert(GNUNET_NO); |
1003 | return 1; | 1001 | return 1; |
1004 | } | 1002 | } |
1005 | 1003 | ||
1006 | static double | 1004 | static double |
1007 | envi_get_penalty (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | 1005 | envi_get_penalty(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) |
1008 | { | 1006 | { |
1009 | struct RIL_Scope *net; | 1007 | struct RIL_Scope *net; |
1010 | unsigned long long over_max; | 1008 | unsigned long long over_max; |
@@ -1014,26 +1012,26 @@ envi_get_penalty (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | |||
1014 | net = agent->address_inuse->solver_information; | 1012 | net = agent->address_inuse->solver_information; |
1015 | 1013 | ||
1016 | if (net->bw_in_utilized > net->bw_in_available) | 1014 | if (net->bw_in_utilized > net->bw_in_available) |
1017 | { | ||
1018 | over_in = net->bw_in_utilized - net->bw_in_available; | ||
1019 | if (RIL_ACTION_BW_IN_INC == agent->a_old) | ||
1020 | { | 1015 | { |
1021 | /* increase quadratically */ | 1016 | over_in = net->bw_in_utilized - net->bw_in_available; |
1022 | over_in *= over_in; | 1017 | if (RIL_ACTION_BW_IN_INC == agent->a_old) |
1018 | { | ||
1019 | /* increase quadratically */ | ||
1020 | over_in *= over_in; | ||
1021 | } | ||
1023 | } | 1022 | } |
1024 | } | ||
1025 | if (net->bw_out_utilized > net->bw_out_available) | 1023 | if (net->bw_out_utilized > net->bw_out_available) |
1026 | { | ||
1027 | over_out = net->bw_out_utilized - net->bw_out_available; | ||
1028 | if (RIL_ACTION_BW_OUT_INC == agent->a_old) | ||
1029 | { | 1024 | { |
1030 | /* increase quadratically */ | 1025 | over_out = net->bw_out_utilized - net->bw_out_available; |
1031 | over_out *= over_out; | 1026 | if (RIL_ACTION_BW_OUT_INC == agent->a_old) |
1027 | { | ||
1028 | /* increase quadratically */ | ||
1029 | over_out *= over_out; | ||
1030 | } | ||
1032 | } | 1031 | } |
1033 | } | ||
1034 | over_max = (over_in + over_out) / (RIL_MIN_BW * RIL_MIN_BW); | 1032 | over_max = (over_in + over_out) / (RIL_MIN_BW * RIL_MIN_BW); |
1035 | 1033 | ||
1036 | return -1.0 * (double) over_max; | 1034 | return -1.0 * (double)over_max; |
1037 | } | 1035 | } |
1038 | 1036 | ||
1039 | /** | 1037 | /** |
@@ -1046,7 +1044,7 @@ envi_get_penalty (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | |||
1046 | * @return the reward | 1044 | * @return the reward |
1047 | */ | 1045 | */ |
1048 | static double | 1046 | static double |
1049 | envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | 1047 | envi_get_reward(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) |
1050 | { | 1048 | { |
1051 | struct RIL_Scope *net; | 1049 | struct RIL_Scope *net; |
1052 | double objective; | 1050 | double objective; |
@@ -1058,18 +1056,18 @@ envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | |||
1058 | net = agent->address_inuse->solver_information; | 1056 | net = agent->address_inuse->solver_information; |
1059 | 1057 | ||
1060 | penalty = envi_get_penalty(solver, agent); | 1058 | penalty = envi_get_penalty(solver, agent); |
1061 | objective = (agent_get_utility (agent) + net->social_welfare) / 2; | 1059 | objective = (agent_get_utility(agent) + net->social_welfare) / 2; |
1062 | delta = objective - agent->objective_old; | 1060 | delta = objective - agent->objective_old; |
1063 | agent->objective_old = objective; | 1061 | agent->objective_old = objective; |
1064 | 1062 | ||
1065 | if (delta != 0 && penalty == 0) | 1063 | if (delta != 0 && penalty == 0) |
1066 | { | 1064 | { |
1067 | agent->nop_bonus = delta * RIL_NOP_DECAY; | 1065 | agent->nop_bonus = delta * RIL_NOP_DECAY; |
1068 | } | 1066 | } |
1069 | else | 1067 | else |
1070 | { | 1068 | { |
1071 | agent->nop_bonus *= RIL_NOP_DECAY; | 1069 | agent->nop_bonus *= RIL_NOP_DECAY; |
1072 | } | 1070 | } |
1073 | 1071 | ||
1074 | steady = (RIL_ACTION_NOTHING == agent->a_old) ? agent->nop_bonus : 0; | 1072 | steady = (RIL_ACTION_NOTHING == agent->a_old) ? agent->nop_bonus : 0; |
1075 | 1073 | ||
@@ -1085,31 +1083,31 @@ envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | |||
1085 | * @param direction_in if GNUNET_YES, change inbound bandwidth, otherwise the outbound bandwidth | 1083 | * @param direction_in if GNUNET_YES, change inbound bandwidth, otherwise the outbound bandwidth |
1086 | */ | 1084 | */ |
1087 | static void | 1085 | static void |
1088 | envi_action_bw_double (struct GAS_RIL_Handle *solver, | 1086 | envi_action_bw_double(struct GAS_RIL_Handle *solver, |
1089 | struct RIL_Peer_Agent *agent, | 1087 | struct RIL_Peer_Agent *agent, |
1090 | int direction_in) | 1088 | int direction_in) |
1091 | { | 1089 | { |
1092 | unsigned long long new_bw; | 1090 | unsigned long long new_bw; |
1093 | unsigned long long max_bw; | 1091 | unsigned long long max_bw; |
1094 | 1092 | ||
1095 | max_bw = ril_get_max_bw((struct RIL_Scope *) agent->address_inuse->solver_information); | 1093 | max_bw = ril_get_max_bw((struct RIL_Scope *)agent->address_inuse->solver_information); |
1096 | 1094 | ||
1097 | if (direction_in) | 1095 | if (direction_in) |
1098 | { | 1096 | { |
1099 | new_bw = agent->bw_in * 2; | 1097 | new_bw = agent->bw_in * 2; |
1100 | if (new_bw < agent->bw_in || new_bw > max_bw) | 1098 | if (new_bw < agent->bw_in || new_bw > max_bw) |
1101 | new_bw = max_bw; | 1099 | new_bw = max_bw; |
1102 | envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw, | 1100 | envi_set_active_suggestion(solver, agent, agent->address_inuse, new_bw, |
1103 | agent->bw_out, GNUNET_NO); | 1101 | agent->bw_out, GNUNET_NO); |
1104 | } | 1102 | } |
1105 | else | 1103 | else |
1106 | { | 1104 | { |
1107 | new_bw = agent->bw_out * 2; | 1105 | new_bw = agent->bw_out * 2; |
1108 | if (new_bw < agent->bw_out || new_bw > max_bw) | 1106 | if (new_bw < agent->bw_out || new_bw > max_bw) |
1109 | new_bw = max_bw; | 1107 | new_bw = max_bw; |
1110 | envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, | 1108 | envi_set_active_suggestion(solver, agent, agent->address_inuse, agent->bw_in, |
1111 | new_bw, GNUNET_NO); | 1109 | new_bw, GNUNET_NO); |
1112 | } | 1110 | } |
1113 | } | 1111 | } |
1114 | 1112 | ||
1115 | /** | 1113 | /** |
@@ -1122,28 +1120,28 @@ envi_action_bw_double (struct GAS_RIL_Handle *solver, | |||
1122 | * bandwidth | 1120 | * bandwidth |
1123 | */ | 1121 | */ |
1124 | static void | 1122 | static void |
1125 | envi_action_bw_halven (struct GAS_RIL_Handle *solver, | 1123 | envi_action_bw_halven(struct GAS_RIL_Handle *solver, |
1126 | struct RIL_Peer_Agent *agent, | 1124 | struct RIL_Peer_Agent *agent, |
1127 | int direction_in) | 1125 | int direction_in) |
1128 | { | 1126 | { |
1129 | unsigned long long new_bw; | 1127 | unsigned long long new_bw; |
1130 | 1128 | ||
1131 | if (direction_in) | 1129 | if (direction_in) |
1132 | { | 1130 | { |
1133 | new_bw = agent->bw_in / 2; | 1131 | new_bw = agent->bw_in / 2; |
1134 | if (new_bw <= 0 || new_bw > agent->bw_in) | 1132 | if (new_bw <= 0 || new_bw > agent->bw_in) |
1135 | new_bw = 0; | 1133 | new_bw = 0; |
1136 | envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw, agent->bw_out, | 1134 | envi_set_active_suggestion(solver, agent, agent->address_inuse, new_bw, agent->bw_out, |
1137 | GNUNET_NO); | 1135 | GNUNET_NO); |
1138 | } | 1136 | } |
1139 | else | 1137 | else |
1140 | { | 1138 | { |
1141 | new_bw = agent->bw_out / 2; | 1139 | new_bw = agent->bw_out / 2; |
1142 | if (new_bw <= 0 || new_bw > agent->bw_out) | 1140 | if (new_bw <= 0 || new_bw > agent->bw_out) |
1143 | new_bw = 0; | 1141 | new_bw = 0; |
1144 | envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, new_bw, | 1142 | envi_set_active_suggestion(solver, agent, agent->address_inuse, agent->bw_in, new_bw, |
1145 | GNUNET_NO); | 1143 | GNUNET_NO); |
1146 | } | 1144 | } |
1147 | } | 1145 | } |
1148 | 1146 | ||
1149 | /** | 1147 | /** |
@@ -1155,29 +1153,29 @@ envi_action_bw_halven (struct GAS_RIL_Handle *solver, | |||
1155 | * bandwidth | 1153 | * bandwidth |
1156 | */ | 1154 | */ |
1157 | static void | 1155 | static void |
1158 | envi_action_bw_inc (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in) | 1156 | envi_action_bw_inc(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in) |
1159 | { | 1157 | { |
1160 | unsigned long long new_bw; | 1158 | unsigned long long new_bw; |
1161 | unsigned long long max_bw; | 1159 | unsigned long long max_bw; |
1162 | 1160 | ||
1163 | max_bw = ril_get_max_bw((struct RIL_Scope *) agent->address_inuse->solver_information); | 1161 | max_bw = ril_get_max_bw((struct RIL_Scope *)agent->address_inuse->solver_information); |
1164 | 1162 | ||
1165 | if (direction_in) | 1163 | if (direction_in) |
1166 | { | 1164 | { |
1167 | new_bw = agent->bw_in + (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW); | 1165 | new_bw = agent->bw_in + (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW); |
1168 | if (new_bw < agent->bw_in || new_bw > max_bw) | 1166 | if (new_bw < agent->bw_in || new_bw > max_bw) |
1169 | new_bw = max_bw; | 1167 | new_bw = max_bw; |
1170 | envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw, | 1168 | envi_set_active_suggestion(solver, agent, agent->address_inuse, new_bw, |
1171 | agent->bw_out, GNUNET_NO); | 1169 | agent->bw_out, GNUNET_NO); |
1172 | } | 1170 | } |
1173 | else | 1171 | else |
1174 | { | 1172 | { |
1175 | new_bw = agent->bw_out + (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW); | 1173 | new_bw = agent->bw_out + (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW); |
1176 | if (new_bw < agent->bw_out || new_bw > max_bw) | 1174 | if (new_bw < agent->bw_out || new_bw > max_bw) |
1177 | new_bw = max_bw; | 1175 | new_bw = max_bw; |
1178 | envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, | 1176 | envi_set_active_suggestion(solver, agent, agent->address_inuse, agent->bw_in, |
1179 | new_bw, GNUNET_NO); | 1177 | new_bw, GNUNET_NO); |
1180 | } | 1178 | } |
1181 | } | 1179 | } |
1182 | 1180 | ||
1183 | /** | 1181 | /** |
@@ -1190,26 +1188,26 @@ envi_action_bw_inc (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, | |||
1190 | * bandwidth | 1188 | * bandwidth |
1191 | */ | 1189 | */ |
1192 | static void | 1190 | static void |
1193 | envi_action_bw_dec (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in) | 1191 | envi_action_bw_dec(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in) |
1194 | { | 1192 | { |
1195 | unsigned long long new_bw; | 1193 | unsigned long long new_bw; |
1196 | 1194 | ||
1197 | if (direction_in) | 1195 | if (direction_in) |
1198 | { | 1196 | { |
1199 | new_bw = agent->bw_in - (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW); | 1197 | new_bw = agent->bw_in - (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW); |
1200 | if (new_bw <= 0 || new_bw > agent->bw_in) | 1198 | if (new_bw <= 0 || new_bw > agent->bw_in) |
1201 | new_bw = 0; | 1199 | new_bw = 0; |
1202 | envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw, agent->bw_out, | 1200 | envi_set_active_suggestion(solver, agent, agent->address_inuse, new_bw, agent->bw_out, |
1203 | GNUNET_NO); | 1201 | GNUNET_NO); |
1204 | } | 1202 | } |
1205 | else | 1203 | else |
1206 | { | 1204 | { |
1207 | new_bw = agent->bw_out - (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW); | 1205 | new_bw = agent->bw_out - (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW); |
1208 | if (new_bw <= 0 || new_bw > agent->bw_out) | 1206 | if (new_bw <= 0 || new_bw > agent->bw_out) |
1209 | new_bw = 0; | 1207 | new_bw = 0; |
1210 | envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, new_bw, | 1208 | envi_set_active_suggestion(solver, agent, agent->address_inuse, agent->bw_in, new_bw, |
1211 | GNUNET_NO); | 1209 | GNUNET_NO); |
1212 | } | 1210 | } |
1213 | } | 1211 | } |
1214 | 1212 | ||
1215 | /** | 1213 | /** |
@@ -1220,9 +1218,9 @@ envi_action_bw_dec (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, | |||
1220 | * @param address_index index of the address as it is saved in the agent's list, starting with zero | 1218 | * @param address_index index of the address as it is saved in the agent's list, starting with zero |
1221 | */ | 1219 | */ |
1222 | static void | 1220 | static void |
1223 | envi_action_address_switch (struct GAS_RIL_Handle *solver, | 1221 | envi_action_address_switch(struct GAS_RIL_Handle *solver, |
1224 | struct RIL_Peer_Agent *agent, | 1222 | struct RIL_Peer_Agent *agent, |
1225 | unsigned int address_index) | 1223 | unsigned int address_index) |
1226 | { | 1224 | { |
1227 | struct RIL_Address_Wrapped *cur; | 1225 | struct RIL_Address_Wrapped *cur; |
1228 | int i = 0; | 1226 | int i = 0; |
@@ -1230,17 +1228,17 @@ envi_action_address_switch (struct GAS_RIL_Handle *solver, | |||
1230 | //cur = agent_address_get_wrapped(agent, agent->address_inuse); | 1228 | //cur = agent_address_get_wrapped(agent, agent->address_inuse); |
1231 | 1229 | ||
1232 | for (cur = agent->addresses_head; NULL != cur; cur = cur->next) | 1230 | for (cur = agent->addresses_head; NULL != cur; cur = cur->next) |
1233 | { | ||
1234 | if (i == address_index) | ||
1235 | { | 1231 | { |
1236 | envi_set_active_suggestion (solver, agent, cur->address_naked, agent->bw_in, agent->bw_out, | 1232 | if (i == address_index) |
1237 | GNUNET_NO); | 1233 | { |
1238 | return; | 1234 | envi_set_active_suggestion(solver, agent, cur->address_naked, agent->bw_in, agent->bw_out, |
1235 | GNUNET_NO); | ||
1236 | return; | ||
1237 | } | ||
1238 | |||
1239 | i++; | ||
1239 | } | 1240 | } |
1240 | 1241 | ||
1241 | i++; | ||
1242 | } | ||
1243 | |||
1244 | //no address with address_index exists, in this case this action should not be callable | 1242 | //no address with address_index exists, in this case this action should not be callable |
1245 | GNUNET_assert(GNUNET_NO); | 1243 | GNUNET_assert(GNUNET_NO); |
1246 | } | 1244 | } |
@@ -1253,53 +1251,62 @@ envi_action_address_switch (struct GAS_RIL_Handle *solver, | |||
1253 | * @param action the action to perform by the solver | 1251 | * @param action the action to perform by the solver |
1254 | */ | 1252 | */ |
1255 | static void | 1253 | static void |
1256 | envi_do_action (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int action) | 1254 | envi_do_action(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int action) |
1257 | { | 1255 | { |
1258 | int address_index; | 1256 | int address_index; |
1259 | 1257 | ||
1260 | switch (action) | 1258 | switch (action) |
1261 | { | 1259 | { |
1262 | case RIL_ACTION_NOTHING: | 1260 | case RIL_ACTION_NOTHING: |
1263 | break; | 1261 | break; |
1264 | case RIL_ACTION_BW_IN_DBL: | 1262 | |
1265 | envi_action_bw_double (solver, agent, GNUNET_YES); | 1263 | case RIL_ACTION_BW_IN_DBL: |
1266 | break; | 1264 | envi_action_bw_double(solver, agent, GNUNET_YES); |
1267 | case RIL_ACTION_BW_IN_HLV: | 1265 | break; |
1268 | envi_action_bw_halven (solver, agent, GNUNET_YES); | 1266 | |
1269 | break; | 1267 | case RIL_ACTION_BW_IN_HLV: |
1270 | case RIL_ACTION_BW_IN_INC: | 1268 | envi_action_bw_halven(solver, agent, GNUNET_YES); |
1271 | envi_action_bw_inc (solver, agent, GNUNET_YES); | 1269 | break; |
1272 | break; | 1270 | |
1273 | case RIL_ACTION_BW_IN_DEC: | 1271 | case RIL_ACTION_BW_IN_INC: |
1274 | envi_action_bw_dec (solver, agent, GNUNET_YES); | 1272 | envi_action_bw_inc(solver, agent, GNUNET_YES); |
1275 | break; | 1273 | break; |
1276 | case RIL_ACTION_BW_OUT_DBL: | 1274 | |
1277 | envi_action_bw_double (solver, agent, GNUNET_NO); | 1275 | case RIL_ACTION_BW_IN_DEC: |
1278 | break; | 1276 | envi_action_bw_dec(solver, agent, GNUNET_YES); |
1279 | case RIL_ACTION_BW_OUT_HLV: | 1277 | break; |
1280 | envi_action_bw_halven (solver, agent, GNUNET_NO); | 1278 | |
1281 | break; | 1279 | case RIL_ACTION_BW_OUT_DBL: |
1282 | case RIL_ACTION_BW_OUT_INC: | 1280 | envi_action_bw_double(solver, agent, GNUNET_NO); |
1283 | envi_action_bw_inc (solver, agent, GNUNET_NO); | 1281 | break; |
1284 | break; | 1282 | |
1285 | case RIL_ACTION_BW_OUT_DEC: | 1283 | case RIL_ACTION_BW_OUT_HLV: |
1286 | envi_action_bw_dec (solver, agent, GNUNET_NO); | 1284 | envi_action_bw_halven(solver, agent, GNUNET_NO); |
1287 | break; | ||
1288 | default: | ||
1289 | if ((action >= RIL_ACTION_TYPE_NUM) && (action < agent->n)) //switch address action | ||
1290 | { | ||
1291 | address_index = action - RIL_ACTION_TYPE_NUM; | ||
1292 | |||
1293 | GNUNET_assert(address_index >= 0); | ||
1294 | GNUNET_assert( | ||
1295 | address_index <= agent_address_get_index (agent, agent->addresses_tail->address_naked)); | ||
1296 | |||
1297 | envi_action_address_switch (solver, agent, address_index); | ||
1298 | break; | 1285 | break; |
1286 | |||
1287 | case RIL_ACTION_BW_OUT_INC: | ||
1288 | envi_action_bw_inc(solver, agent, GNUNET_NO); | ||
1289 | break; | ||
1290 | |||
1291 | case RIL_ACTION_BW_OUT_DEC: | ||
1292 | envi_action_bw_dec(solver, agent, GNUNET_NO); | ||
1293 | break; | ||
1294 | |||
1295 | default: | ||
1296 | if ((action >= RIL_ACTION_TYPE_NUM) && (action < agent->n)) //switch address action | ||
1297 | { | ||
1298 | address_index = action - RIL_ACTION_TYPE_NUM; | ||
1299 | |||
1300 | GNUNET_assert(address_index >= 0); | ||
1301 | GNUNET_assert( | ||
1302 | address_index <= agent_address_get_index(agent, agent->addresses_tail->address_naked)); | ||
1303 | |||
1304 | envi_action_address_switch(solver, agent, address_index); | ||
1305 | break; | ||
1306 | } | ||
1307 | // error - action does not exist | ||
1308 | GNUNET_assert(GNUNET_NO); | ||
1299 | } | 1309 | } |
1300 | // error - action does not exist | ||
1301 | GNUNET_assert(GNUNET_NO); | ||
1302 | } | ||
1303 | } | 1310 | } |
1304 | 1311 | ||
1305 | /** | 1312 | /** |
@@ -1314,27 +1321,27 @@ envi_do_action (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int | |||
1314 | * @return the action index | 1321 | * @return the action index |
1315 | */ | 1322 | */ |
1316 | static int | 1323 | static int |
1317 | agent_select_egreedy (struct RIL_Peer_Agent *agent, double *state) | 1324 | agent_select_egreedy(struct RIL_Peer_Agent *agent, double *state) |
1318 | { | 1325 | { |
1319 | int action; | 1326 | int action; |
1320 | double r = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 1327 | double r = (double)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
1321 | UINT32_MAX) / (double) UINT32_MAX; | 1328 | UINT32_MAX) / (double)UINT32_MAX; |
1322 | 1329 | ||
1323 | if (r < agent->envi->parameters.epsilon) //explore | 1330 | if (r < agent->envi->parameters.epsilon) //explore |
1324 | { | ||
1325 | action = agent_get_action_random(agent); | ||
1326 | if (RIL_ALGO_Q == agent->envi->parameters.algorithm) | ||
1327 | { | 1331 | { |
1328 | agent->eligibility_reset = GNUNET_YES; | 1332 | action = agent_get_action_random(agent); |
1333 | if (RIL_ALGO_Q == agent->envi->parameters.algorithm) | ||
1334 | { | ||
1335 | agent->eligibility_reset = GNUNET_YES; | ||
1336 | } | ||
1337 | agent->envi->parameters.epsilon *= agent->envi->parameters.epsilon_decay; | ||
1338 | return action; | ||
1329 | } | 1339 | } |
1330 | agent->envi->parameters.epsilon *= agent->envi->parameters.epsilon_decay; | ||
1331 | return action; | ||
1332 | } | ||
1333 | else //exploit | 1340 | else //exploit |
1334 | { | 1341 | { |
1335 | action = agent_get_action_max(agent, state); | 1342 | action = agent_get_action_max(agent, state); |
1336 | return action; | 1343 | return action; |
1337 | } | 1344 | } |
1338 | } | 1345 | } |
1339 | 1346 | ||
1340 | /** | 1347 | /** |
@@ -1348,7 +1355,7 @@ agent_select_egreedy (struct RIL_Peer_Agent *agent, double *state) | |||
1348 | * @return | 1355 | * @return |
1349 | */ | 1356 | */ |
1350 | static int | 1357 | static int |
1351 | agent_select_softmax (struct RIL_Peer_Agent *agent, double *state) | 1358 | agent_select_softmax(struct RIL_Peer_Agent *agent, double *state) |
1352 | { | 1359 | { |
1353 | int i; | 1360 | int i; |
1354 | int a_max; | 1361 | int a_max; |
@@ -1359,44 +1366,44 @@ agent_select_softmax (struct RIL_Peer_Agent *agent, double *state) | |||
1359 | 1366 | ||
1360 | a_max = agent_get_action_max(agent, state); | 1367 | a_max = agent_get_action_max(agent, state); |
1361 | 1368 | ||
1362 | for (i=0; i<agent->n; i++) | 1369 | for (i = 0; i < agent->n; i++) |
1363 | { | ||
1364 | if (agent_action_is_possible(agent, i)) | ||
1365 | { | ||
1366 | eqt[i] = exp(agent_q(agent,state,i) / agent->envi->parameters.temperature); | ||
1367 | if (isinf (eqt[i])) | ||
1368 | eqt[i] = isinf(eqt[i]) * UINT32_MAX; | ||
1369 | sum += eqt[i]; | ||
1370 | } | ||
1371 | } | ||
1372 | for (i=0; i<agent->n; i++) | ||
1373 | { | ||
1374 | if (agent_action_is_possible(agent, i)) | ||
1375 | { | 1370 | { |
1376 | p[i] = eqt[i]/sum; | 1371 | if (agent_action_is_possible(agent, i)) |
1372 | { | ||
1373 | eqt[i] = exp(agent_q(agent, state, i) / agent->envi->parameters.temperature); | ||
1374 | if (isinf(eqt[i])) | ||
1375 | eqt[i] = isinf(eqt[i]) * UINT32_MAX; | ||
1376 | sum += eqt[i]; | ||
1377 | } | ||
1377 | } | 1378 | } |
1378 | else | 1379 | for (i = 0; i < agent->n; i++) |
1379 | { | 1380 | { |
1380 | p[i] = 0; | 1381 | if (agent_action_is_possible(agent, i)) |
1382 | { | ||
1383 | p[i] = eqt[i] / sum; | ||
1384 | } | ||
1385 | else | ||
1386 | { | ||
1387 | p[i] = 0; | ||
1388 | } | ||
1381 | } | 1389 | } |
1382 | } | 1390 | r = (double)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
1383 | r = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 1391 | UINT32_MAX) / (double)UINT32_MAX; |
1384 | UINT32_MAX) / (double) UINT32_MAX; | ||
1385 | sum = 0; | 1392 | sum = 0; |
1386 | for (i=0; i<agent->n; i++) | 1393 | for (i = 0; i < agent->n; i++) |
1387 | { | ||
1388 | if (sum + p[i] > r) | ||
1389 | { | 1394 | { |
1390 | if (i != a_max) | 1395 | if (sum + p[i] > r) |
1391 | { | 1396 | { |
1392 | if (RIL_ALGO_Q == agent->envi->parameters.algorithm) | 1397 | if (i != a_max) |
1393 | agent->eligibility_reset = GNUNET_YES; | 1398 | { |
1394 | agent->envi->parameters.temperature *= agent->envi->parameters.temperature_decay; | 1399 | if (RIL_ALGO_Q == agent->envi->parameters.algorithm) |
1395 | } | 1400 | agent->eligibility_reset = GNUNET_YES; |
1396 | return i; | 1401 | agent->envi->parameters.temperature *= agent->envi->parameters.temperature_decay; |
1402 | } | ||
1403 | return i; | ||
1404 | } | ||
1405 | sum += p[i]; | ||
1397 | } | 1406 | } |
1398 | sum += p[i]; | ||
1399 | } | ||
1400 | GNUNET_assert(GNUNET_NO); | 1407 | GNUNET_assert(GNUNET_NO); |
1401 | return RIL_ACTION_INVALID; | 1408 | return RIL_ACTION_INVALID; |
1402 | } | 1409 | } |
@@ -1410,16 +1417,16 @@ agent_select_softmax (struct RIL_Peer_Agent *agent, double *state) | |||
1410 | * @return the action index | 1417 | * @return the action index |
1411 | */ | 1418 | */ |
1412 | static int | 1419 | static int |
1413 | agent_select_action (struct RIL_Peer_Agent *agent, double *state) | 1420 | agent_select_action(struct RIL_Peer_Agent *agent, double *state) |
1414 | { | 1421 | { |
1415 | if (agent->envi->parameters.select == RIL_SELECT_EGREEDY) | 1422 | if (agent->envi->parameters.select == RIL_SELECT_EGREEDY) |
1416 | { | 1423 | { |
1417 | return agent_select_egreedy(agent, state); | 1424 | return agent_select_egreedy(agent, state); |
1418 | } | 1425 | } |
1419 | else | 1426 | else |
1420 | { | 1427 | { |
1421 | return agent_select_softmax(agent, state); | 1428 | return agent_select_softmax(agent, state); |
1422 | } | 1429 | } |
1423 | } | 1430 | } |
1424 | 1431 | ||
1425 | /** | 1432 | /** |
@@ -1431,7 +1438,7 @@ agent_select_action (struct RIL_Peer_Agent *agent, double *state) | |||
1431 | * @param agent the agent performing the step | 1438 | * @param agent the agent performing the step |
1432 | */ | 1439 | */ |
1433 | static void | 1440 | static void |
1434 | agent_step (struct RIL_Peer_Agent *agent) | 1441 | agent_step(struct RIL_Peer_Agent *agent) |
1435 | { | 1442 | { |
1436 | int a_next = RIL_ACTION_INVALID; | 1443 | int a_next = RIL_ACTION_INVALID; |
1437 | int a_max; | 1444 | int a_max; |
@@ -1439,58 +1446,58 @@ agent_step (struct RIL_Peer_Agent *agent) | |||
1439 | double reward; | 1446 | double reward; |
1440 | 1447 | ||
1441 | LOG(GNUNET_ERROR_TYPE_DEBUG, " agent_step() Peer '%s', algorithm %s\n", | 1448 | LOG(GNUNET_ERROR_TYPE_DEBUG, " agent_step() Peer '%s', algorithm %s\n", |
1442 | GNUNET_i2s (&agent->peer), | 1449 | GNUNET_i2s(&agent->peer), |
1443 | agent->envi->parameters.algorithm ? "Q" : "SARSA"); | 1450 | agent->envi->parameters.algorithm ? "Q" : "SARSA"); |
1444 | 1451 | ||
1445 | s_next = envi_get_state (agent->envi, agent); | 1452 | s_next = envi_get_state(agent->envi, agent); |
1446 | reward = envi_get_reward (agent->envi, agent); | 1453 | reward = envi_get_reward(agent->envi, agent); |
1447 | 1454 | ||
1448 | if (agent->eligibility_reset) | 1455 | if (agent->eligibility_reset) |
1449 | { | 1456 | { |
1450 | agent_modify_eligibility(agent, RIL_E_ZERO, NULL, -1); | 1457 | agent_modify_eligibility(agent, RIL_E_ZERO, NULL, -1); |
1451 | agent->eligibility_reset = GNUNET_NO; | 1458 | agent->eligibility_reset = GNUNET_NO; |
1452 | } | 1459 | } |
1453 | else | 1460 | else |
1454 | { | 1461 | { |
1455 | agent_modify_eligibility (agent, RIL_E_DECAY, NULL, -1); | 1462 | agent_modify_eligibility(agent, RIL_E_DECAY, NULL, -1); |
1456 | } | 1463 | } |
1457 | if (RIL_ACTION_INVALID != agent->a_old) | 1464 | if (RIL_ACTION_INVALID != agent->a_old) |
1458 | { | ||
1459 | agent_modify_eligibility (agent, agent->envi->parameters.eligibility_trace_mode, agent->s_old, agent->a_old); | ||
1460 | } | ||
1461 | |||
1462 | switch (agent->envi->parameters.algorithm) | ||
1463 | { | ||
1464 | case RIL_ALGO_SARSA: | ||
1465 | a_next = agent_select_action (agent, s_next); | ||
1466 | if (RIL_ACTION_INVALID != agent->a_old) | ||
1467 | { | 1465 | { |
1468 | //updates weights with selected action (on-policy), if not first step | 1466 | agent_modify_eligibility(agent, agent->envi->parameters.eligibility_trace_mode, agent->s_old, agent->a_old); |
1469 | agent_update (agent, reward, s_next, a_next); | ||
1470 | } | 1467 | } |
1471 | break; | ||
1472 | 1468 | ||
1473 | case RIL_ALGO_Q: | 1469 | switch (agent->envi->parameters.algorithm) |
1474 | a_max = agent_get_action_max (agent, s_next); | ||
1475 | if (RIL_ACTION_INVALID != agent->a_old) | ||
1476 | { | 1470 | { |
1477 | //updates weights with best action, disregarding actually selected action (off-policy), if not first step | 1471 | case RIL_ALGO_SARSA: |
1478 | agent_update (agent, reward, s_next, a_max); | 1472 | a_next = agent_select_action(agent, s_next); |
1473 | if (RIL_ACTION_INVALID != agent->a_old) | ||
1474 | { | ||
1475 | //updates weights with selected action (on-policy), if not first step | ||
1476 | agent_update(agent, reward, s_next, a_next); | ||
1477 | } | ||
1478 | break; | ||
1479 | |||
1480 | case RIL_ALGO_Q: | ||
1481 | a_max = agent_get_action_max(agent, s_next); | ||
1482 | if (RIL_ACTION_INVALID != agent->a_old) | ||
1483 | { | ||
1484 | //updates weights with best action, disregarding actually selected action (off-policy), if not first step | ||
1485 | agent_update(agent, reward, s_next, a_max); | ||
1486 | } | ||
1487 | a_next = agent_select_action(agent, s_next); | ||
1488 | break; | ||
1479 | } | 1489 | } |
1480 | a_next = agent_select_action (agent, s_next); | ||
1481 | break; | ||
1482 | } | ||
1483 | 1490 | ||
1484 | GNUNET_assert(RIL_ACTION_INVALID != a_next); | 1491 | GNUNET_assert(RIL_ACTION_INVALID != a_next); |
1485 | 1492 | ||
1486 | LOG (GNUNET_ERROR_TYPE_DEBUG, "step() Step# %llu R: %f IN %llu OUT %llu A: %d\n", | 1493 | LOG(GNUNET_ERROR_TYPE_DEBUG, "step() Step# %llu R: %f IN %llu OUT %llu A: %d\n", |
1487 | agent->step_count, | 1494 | agent->step_count, |
1488 | reward, | 1495 | reward, |
1489 | agent->bw_in/1024, | 1496 | agent->bw_in / 1024, |
1490 | agent->bw_out/1024, | 1497 | agent->bw_out / 1024, |
1491 | a_next); | 1498 | a_next); |
1492 | 1499 | ||
1493 | envi_do_action (agent->envi, agent, a_next); | 1500 | envi_do_action(agent->envi, agent, a_next); |
1494 | 1501 | ||
1495 | GNUNET_free(agent->s_old); | 1502 | GNUNET_free(agent->s_old); |
1496 | agent->s_old = s_next; | 1503 | agent->s_old = s_next; |
@@ -1505,7 +1512,7 @@ agent_step (struct RIL_Peer_Agent *agent) | |||
1505 | * @param solver the solver handle | 1512 | * @param solver the solver handle |
1506 | */ | 1513 | */ |
1507 | static void | 1514 | static void |
1508 | ril_step (struct GAS_RIL_Handle *solver); | 1515 | ril_step(struct GAS_RIL_Handle *solver); |
1509 | 1516 | ||
1510 | 1517 | ||
1511 | /** | 1518 | /** |
@@ -1515,12 +1522,12 @@ ril_step (struct GAS_RIL_Handle *solver); | |||
1515 | * @param cls the solver handle | 1522 | * @param cls the solver handle |
1516 | */ | 1523 | */ |
1517 | static void | 1524 | static void |
1518 | ril_step_scheduler_task (void *cls) | 1525 | ril_step_scheduler_task(void *cls) |
1519 | { | 1526 | { |
1520 | struct GAS_RIL_Handle *solver = cls; | 1527 | struct GAS_RIL_Handle *solver = cls; |
1521 | 1528 | ||
1522 | solver->step_next_task_id = NULL; | 1529 | solver->step_next_task_id = NULL; |
1523 | ril_step (solver); | 1530 | ril_step(solver); |
1524 | } | 1531 | } |
1525 | 1532 | ||
1526 | /** | 1533 | /** |
@@ -1532,7 +1539,7 @@ ril_step_scheduler_task (void *cls) | |||
1532 | * @return the ratio | 1539 | * @return the ratio |
1533 | */ | 1540 | */ |
1534 | static double | 1541 | static double |
1535 | ril_get_used_resource_ratio (struct GAS_RIL_Handle *solver) | 1542 | ril_get_used_resource_ratio(struct GAS_RIL_Handle *solver) |
1536 | { | 1543 | { |
1537 | int i; | 1544 | int i; |
1538 | struct RIL_Scope net; | 1545 | struct RIL_Scope net; |
@@ -1541,24 +1548,24 @@ ril_get_used_resource_ratio (struct GAS_RIL_Handle *solver) | |||
1541 | double ratio; | 1548 | double ratio; |
1542 | 1549 | ||
1543 | for (i = 0; i < solver->networks_count; i++) | 1550 | for (i = 0; i < solver->networks_count; i++) |
1544 | { | ||
1545 | net = solver->network_entries[i]; | ||
1546 | if (net.bw_in_assigned > 0) //only consider scopes where an address is actually active | ||
1547 | { | 1551 | { |
1548 | sum_assigned += net.bw_in_utilized; | 1552 | net = solver->network_entries[i]; |
1549 | sum_assigned += net.bw_out_utilized; | 1553 | if (net.bw_in_assigned > 0) //only consider scopes where an address is actually active |
1550 | sum_available += net.bw_in_available; | 1554 | { |
1551 | sum_available += net.bw_out_available; | 1555 | sum_assigned += net.bw_in_utilized; |
1556 | sum_assigned += net.bw_out_utilized; | ||
1557 | sum_available += net.bw_in_available; | ||
1558 | sum_available += net.bw_out_available; | ||
1559 | } | ||
1552 | } | 1560 | } |
1553 | } | ||
1554 | if (sum_available > 0) | 1561 | if (sum_available > 0) |
1555 | { | 1562 | { |
1556 | ratio = ((double) sum_assigned) / ((double) sum_available); | 1563 | ratio = ((double)sum_assigned) / ((double)sum_available); |
1557 | } | 1564 | } |
1558 | else | 1565 | else |
1559 | { | 1566 | { |
1560 | ratio = 0; | 1567 | ratio = 0; |
1561 | } | 1568 | } |
1562 | 1569 | ||
1563 | return ratio > 1 ? 1 : ratio; //overutilization is possible, cap at 1 | 1570 | return ratio > 1 ? 1 : ratio; //overutilization is possible, cap at 1 |
1564 | } | 1571 | } |
@@ -1571,18 +1578,18 @@ ril_get_used_resource_ratio (struct GAS_RIL_Handle *solver) | |||
1571 | * @return the network struct | 1578 | * @return the network struct |
1572 | */ | 1579 | */ |
1573 | static struct RIL_Scope * | 1580 | static struct RIL_Scope * |
1574 | ril_get_network (struct GAS_RIL_Handle *s, uint32_t type) | 1581 | ril_get_network(struct GAS_RIL_Handle *s, uint32_t type) |
1575 | { | 1582 | { |
1576 | int i; | 1583 | int i; |
1577 | 1584 | ||
1578 | for (i = 0; i < s->networks_count; i++) | 1585 | for (i = 0; i < s->networks_count; i++) |
1579 | { | ||
1580 | if (s->network_entries[i].type == type) | ||
1581 | { | 1586 | { |
1582 | return &s->network_entries[i]; | 1587 | if (s->network_entries[i].type == type) |
1588 | { | ||
1589 | return &s->network_entries[i]; | ||
1590 | } | ||
1583 | } | 1591 | } |
1584 | } | 1592 | return NULL; |
1585 | return NULL ; | ||
1586 | } | 1593 | } |
1587 | 1594 | ||
1588 | /** | 1595 | /** |
@@ -1595,25 +1602,25 @@ ril_get_network (struct GAS_RIL_Handle *s, uint32_t type) | |||
1595 | * @return GNUNET_YES if there are theoretically enough resources left | 1602 | * @return GNUNET_YES if there are theoretically enough resources left |
1596 | */ | 1603 | */ |
1597 | static int | 1604 | static int |
1598 | ril_network_is_not_full (struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType network) | 1605 | ril_network_is_not_full(struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType network) |
1599 | { | 1606 | { |
1600 | struct RIL_Scope *net; | 1607 | struct RIL_Scope *net; |
1601 | struct RIL_Peer_Agent *agent; | 1608 | struct RIL_Peer_Agent *agent; |
1602 | unsigned long long address_count = 0; | 1609 | unsigned long long address_count = 0; |
1603 | 1610 | ||
1604 | for (agent = solver->agents_head; NULL != agent; agent = agent->next) | 1611 | for (agent = solver->agents_head; NULL != agent; agent = agent->next) |
1605 | { | ||
1606 | if (agent->address_inuse && agent->is_active) | ||
1607 | { | 1612 | { |
1608 | net = agent->address_inuse->solver_information; | 1613 | if (agent->address_inuse && agent->is_active) |
1609 | if (net->type == network) | 1614 | { |
1610 | { | 1615 | net = agent->address_inuse->solver_information; |
1611 | address_count++; | 1616 | if (net->type == network) |
1612 | } | 1617 | { |
1618 | address_count++; | ||
1619 | } | ||
1620 | } | ||
1613 | } | 1621 | } |
1614 | } | ||
1615 | 1622 | ||
1616 | net = ril_get_network (solver, network); | 1623 | net = ril_get_network(solver, network); |
1617 | return (net->bw_in_available > RIL_MIN_BW * address_count) && (net->bw_out_available > RIL_MIN_BW * address_count); | 1624 | return (net->bw_in_available > RIL_MIN_BW * address_count) && (net->bw_out_available > RIL_MIN_BW * address_count); |
1618 | } | 1625 | } |
1619 | 1626 | ||
@@ -1628,7 +1635,7 @@ ril_network_is_not_full (struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType | |||
1628 | * @param silent | 1635 | * @param silent |
1629 | */ | 1636 | */ |
1630 | static void | 1637 | static void |
1631 | ril_try_unblock_agent (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int silent) | 1638 | ril_try_unblock_agent(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int silent) |
1632 | { | 1639 | { |
1633 | struct RIL_Address_Wrapped *addr_wrap; | 1640 | struct RIL_Address_Wrapped *addr_wrap; |
1634 | struct RIL_Scope *net; | 1641 | struct RIL_Scope *net; |
@@ -1636,19 +1643,19 @@ ril_try_unblock_agent (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *age | |||
1636 | unsigned long long start_out; | 1643 | unsigned long long start_out; |
1637 | 1644 | ||
1638 | for (addr_wrap = agent->addresses_head; NULL != addr_wrap; addr_wrap = addr_wrap->next) | 1645 | for (addr_wrap = agent->addresses_head; NULL != addr_wrap; addr_wrap = addr_wrap->next) |
1639 | { | 1646 | { |
1640 | net = addr_wrap->address_naked->solver_information; | 1647 | net = addr_wrap->address_naked->solver_information; |
1641 | if (ril_network_is_not_full(solver, net->type)) | 1648 | if (ril_network_is_not_full(solver, net->type)) |
1642 | { | 1649 | { |
1643 | if (NULL == agent->address_inuse) | 1650 | if (NULL == agent->address_inuse) |
1644 | { | 1651 | { |
1645 | start_in = net->bw_in_available < net->bw_in_utilized ? (net->bw_in_available - net->bw_in_utilized) / 2 : RIL_MIN_BW; | 1652 | start_in = net->bw_in_available < net->bw_in_utilized ? (net->bw_in_available - net->bw_in_utilized) / 2 : RIL_MIN_BW; |
1646 | start_out = net->bw_out_available < net->bw_out_utilized ? (net->bw_out_available - net->bw_out_utilized) / 2 : RIL_MIN_BW; | 1653 | start_out = net->bw_out_available < net->bw_out_utilized ? (net->bw_out_available - net->bw_out_utilized) / 2 : RIL_MIN_BW; |
1647 | envi_set_active_suggestion (solver, agent, addr_wrap->address_naked, start_in, start_out, silent); | 1654 | envi_set_active_suggestion(solver, agent, addr_wrap->address_naked, start_in, start_out, silent); |
1648 | } | 1655 | } |
1649 | return; | 1656 | return; |
1657 | } | ||
1650 | } | 1658 | } |
1651 | } | ||
1652 | agent->address_inuse = NULL; | 1659 | agent->address_inuse = NULL; |
1653 | } | 1660 | } |
1654 | 1661 | ||
@@ -1659,7 +1666,7 @@ ril_try_unblock_agent (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *age | |||
1659 | * @param solver the solver handle | 1666 | * @param solver the solver handle |
1660 | */ | 1667 | */ |
1661 | static void | 1668 | static void |
1662 | ril_calculate_discount (struct GAS_RIL_Handle *solver) | 1669 | ril_calculate_discount(struct GAS_RIL_Handle *solver) |
1663 | { | 1670 | { |
1664 | struct GNUNET_TIME_Absolute time_now; | 1671 | struct GNUNET_TIME_Absolute time_now; |
1665 | struct GNUNET_TIME_Relative time_delta; | 1672 | struct GNUNET_TIME_Relative time_delta; |
@@ -1667,25 +1674,25 @@ ril_calculate_discount (struct GAS_RIL_Handle *solver) | |||
1667 | 1674 | ||
1668 | // MDP case only for debugging purposes | 1675 | // MDP case only for debugging purposes |
1669 | if (solver->simulate) | 1676 | if (solver->simulate) |
1670 | { | 1677 | { |
1671 | solver->global_discount_variable = solver->parameters.gamma; | 1678 | solver->global_discount_variable = solver->parameters.gamma; |
1672 | solver->global_discount_integrated = 1; | 1679 | solver->global_discount_integrated = 1; |
1673 | return; | 1680 | return; |
1674 | } | 1681 | } |
1675 | 1682 | ||
1676 | // semi-MDP case | 1683 | // semi-MDP case |
1677 | 1684 | ||
1678 | //calculate tau, i.e. how many real valued time units have passed, one time unit is one minimum time step | 1685 | //calculate tau, i.e. how many real valued time units have passed, one time unit is one minimum time step |
1679 | time_now = GNUNET_TIME_absolute_get (); | 1686 | time_now = GNUNET_TIME_absolute_get(); |
1680 | time_delta = GNUNET_TIME_absolute_get_difference (solver->step_time_last, time_now); | 1687 | time_delta = GNUNET_TIME_absolute_get_difference(solver->step_time_last, time_now); |
1681 | solver->step_time_last = time_now; | 1688 | solver->step_time_last = time_now; |
1682 | tau = (double) time_delta.rel_value_us | 1689 | tau = (double)time_delta.rel_value_us |
1683 | / (double) solver->parameters.step_time_min.rel_value_us; | 1690 | / (double)solver->parameters.step_time_min.rel_value_us; |
1684 | 1691 | ||
1685 | //calculate reward discounts (once per step for all agents) | 1692 | //calculate reward discounts (once per step for all agents) |
1686 | solver->global_discount_variable = pow (M_E, ((-1.0) * ((double) solver->parameters.beta) * tau)); | 1693 | solver->global_discount_variable = pow(M_E, ((-1.0) * ((double)solver->parameters.beta) * tau)); |
1687 | solver->global_discount_integrated = (1.0 - solver->global_discount_variable) | 1694 | solver->global_discount_integrated = (1.0 - solver->global_discount_variable) |
1688 | / (double) solver->parameters.beta; | 1695 | / (double)solver->parameters.beta; |
1689 | } | 1696 | } |
1690 | 1697 | ||
1691 | /** | 1698 | /** |
@@ -1696,18 +1703,18 @@ ril_calculate_discount (struct GAS_RIL_Handle *solver) | |||
1696 | * @return the number of allocated connections | 1703 | * @return the number of allocated connections |
1697 | */ | 1704 | */ |
1698 | static int | 1705 | static int |
1699 | ril_network_count_active_agents (struct GAS_RIL_Handle *solver, struct RIL_Scope *scope) | 1706 | ril_network_count_active_agents(struct GAS_RIL_Handle *solver, struct RIL_Scope *scope) |
1700 | { | 1707 | { |
1701 | int c = 0; | 1708 | int c = 0; |
1702 | struct RIL_Peer_Agent *cur_agent; | 1709 | struct RIL_Peer_Agent *cur_agent; |
1703 | 1710 | ||
1704 | for (cur_agent = solver->agents_head; NULL != cur_agent; cur_agent = cur_agent->next) | 1711 | for (cur_agent = solver->agents_head; NULL != cur_agent; cur_agent = cur_agent->next) |
1705 | { | ||
1706 | if (cur_agent->is_active && cur_agent->address_inuse && (cur_agent->address_inuse->solver_information == scope)) | ||
1707 | { | 1712 | { |
1708 | c++; | 1713 | if (cur_agent->is_active && cur_agent->address_inuse && (cur_agent->address_inuse->solver_information == scope)) |
1714 | { | ||
1715 | c++; | ||
1716 | } | ||
1709 | } | 1717 | } |
1710 | } | ||
1711 | return c; | 1718 | return c; |
1712 | } | 1719 | } |
1713 | 1720 | ||
@@ -1722,26 +1729,26 @@ ril_network_count_active_agents (struct GAS_RIL_Handle *solver, struct RIL_Scope | |||
1722 | * @return the sum of the assigned bandwidths | 1729 | * @return the sum of the assigned bandwidths |
1723 | */ | 1730 | */ |
1724 | static unsigned long long | 1731 | static unsigned long long |
1725 | ril_network_get_assigned (struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType type, int direction_in) | 1732 | ril_network_get_assigned(struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType type, int direction_in) |
1726 | { | 1733 | { |
1727 | struct RIL_Peer_Agent *cur; | 1734 | struct RIL_Peer_Agent *cur; |
1728 | struct RIL_Scope *net; | 1735 | struct RIL_Scope *net; |
1729 | unsigned long long sum = 0; | 1736 | unsigned long long sum = 0; |
1730 | 1737 | ||
1731 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) | 1738 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) |
1732 | { | ||
1733 | if (cur->is_active && cur->address_inuse) | ||
1734 | { | 1739 | { |
1735 | net = cur->address_inuse->solver_information; | 1740 | if (cur->is_active && cur->address_inuse) |
1736 | if (net->type == type) | 1741 | { |
1737 | { | 1742 | net = cur->address_inuse->solver_information; |
1738 | if (direction_in) | 1743 | if (net->type == type) |
1739 | sum += cur->bw_in; | 1744 | { |
1740 | else | 1745 | if (direction_in) |
1741 | sum += cur->bw_out; | 1746 | sum += cur->bw_in; |
1742 | } | 1747 | else |
1748 | sum += cur->bw_out; | ||
1749 | } | ||
1750 | } | ||
1743 | } | 1751 | } |
1744 | } | ||
1745 | 1752 | ||
1746 | return sum; | 1753 | return sum; |
1747 | } | 1754 | } |
@@ -1757,26 +1764,26 @@ ril_network_get_assigned (struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType | |||
1757 | * @return the sum of the utilized bandwidths (in bytes/second) | 1764 | * @return the sum of the utilized bandwidths (in bytes/second) |
1758 | */ | 1765 | */ |
1759 | static unsigned long long | 1766 | static unsigned long long |
1760 | ril_network_get_utilized (struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType type, int direction_in) | 1767 | ril_network_get_utilized(struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType type, int direction_in) |
1761 | { | 1768 | { |
1762 | struct RIL_Peer_Agent *cur; | 1769 | struct RIL_Peer_Agent *cur; |
1763 | struct RIL_Scope *net; | 1770 | struct RIL_Scope *net; |
1764 | unsigned long long sum = 0; | 1771 | unsigned long long sum = 0; |
1765 | 1772 | ||
1766 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) | 1773 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) |
1767 | { | ||
1768 | if (cur->is_active && cur->address_inuse) | ||
1769 | { | 1774 | { |
1770 | net = cur->address_inuse->solver_information; | 1775 | if (cur->is_active && cur->address_inuse) |
1771 | if (net->type == type) | 1776 | { |
1772 | { | 1777 | net = cur->address_inuse->solver_information; |
1773 | if (direction_in) | 1778 | if (net->type == type) |
1774 | sum += cur->address_inuse->norm_utilization_in.norm; | 1779 | { |
1775 | else | 1780 | if (direction_in) |
1776 | sum += cur->address_inuse->norm_utilization_out.norm; | 1781 | sum += cur->address_inuse->norm_utilization_in.norm; |
1777 | } | 1782 | else |
1783 | sum += cur->address_inuse->norm_utilization_out.norm; | ||
1784 | } | ||
1785 | } | ||
1778 | } | 1786 | } |
1779 | } | ||
1780 | 1787 | ||
1781 | return sum; | 1788 | return sum; |
1782 | } | 1789 | } |
@@ -1788,21 +1795,21 @@ ril_network_get_utilized (struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType | |||
1788 | * @param solver the solver handle | 1795 | * @param solver the solver handle |
1789 | */ | 1796 | */ |
1790 | static void | 1797 | static void |
1791 | ril_networks_update_state (struct GAS_RIL_Handle *solver) | 1798 | ril_networks_update_state(struct GAS_RIL_Handle *solver) |
1792 | { | 1799 | { |
1793 | int c; | 1800 | int c; |
1794 | struct RIL_Scope *net; | 1801 | struct RIL_Scope *net; |
1795 | 1802 | ||
1796 | for (c = 0; c < solver->networks_count; c++) | 1803 | for (c = 0; c < solver->networks_count; c++) |
1797 | { | 1804 | { |
1798 | net = &solver->network_entries[c]; | 1805 | net = &solver->network_entries[c]; |
1799 | net->bw_in_assigned = ril_network_get_assigned(solver, net->type, GNUNET_YES); | 1806 | net->bw_in_assigned = ril_network_get_assigned(solver, net->type, GNUNET_YES); |
1800 | net->bw_in_utilized = ril_network_get_utilized(solver, net->type, GNUNET_YES); | 1807 | net->bw_in_utilized = ril_network_get_utilized(solver, net->type, GNUNET_YES); |
1801 | net->bw_out_assigned = ril_network_get_assigned(solver, net->type, GNUNET_NO); | 1808 | net->bw_out_assigned = ril_network_get_assigned(solver, net->type, GNUNET_NO); |
1802 | net->bw_out_utilized = ril_network_get_utilized(solver, net->type, GNUNET_NO); | 1809 | net->bw_out_utilized = ril_network_get_utilized(solver, net->type, GNUNET_NO); |
1803 | net->active_agent_count = ril_network_count_active_agents(solver, net); | 1810 | net->active_agent_count = ril_network_count_active_agents(solver, net); |
1804 | net->social_welfare = ril_network_get_social_welfare(solver, net); | 1811 | net->social_welfare = ril_network_get_social_welfare(solver, net); |
1805 | } | 1812 | } |
1806 | } | 1813 | } |
1807 | 1814 | ||
1808 | /** | 1815 | /** |
@@ -1813,7 +1820,7 @@ ril_networks_update_state (struct GAS_RIL_Handle *solver) | |||
1813 | * @param solver the solver handle | 1820 | * @param solver the solver handle |
1814 | */ | 1821 | */ |
1815 | static void | 1822 | static void |
1816 | ril_step_schedule_next (struct GAS_RIL_Handle *solver) | 1823 | ril_step_schedule_next(struct GAS_RIL_Handle *solver) |
1817 | { | 1824 | { |
1818 | double used_ratio; | 1825 | double used_ratio; |
1819 | double factor; | 1826 | double factor; |
@@ -1821,21 +1828,21 @@ ril_step_schedule_next (struct GAS_RIL_Handle *solver) | |||
1821 | double offset; | 1828 | double offset; |
1822 | struct GNUNET_TIME_Relative time_next; | 1829 | struct GNUNET_TIME_Relative time_next; |
1823 | 1830 | ||
1824 | used_ratio = ril_get_used_resource_ratio (solver); | 1831 | used_ratio = ril_get_used_resource_ratio(solver); |
1825 | 1832 | ||
1826 | GNUNET_assert( | 1833 | GNUNET_assert( |
1827 | solver->parameters.step_time_min.rel_value_us | 1834 | solver->parameters.step_time_min.rel_value_us |
1828 | <= solver->parameters.step_time_max.rel_value_us); | 1835 | <= solver->parameters.step_time_max.rel_value_us); |
1829 | 1836 | ||
1830 | factor = (double) GNUNET_TIME_relative_subtract (solver->parameters.step_time_max, | 1837 | factor = (double)GNUNET_TIME_relative_subtract(solver->parameters.step_time_max, |
1831 | solver->parameters.step_time_min).rel_value_us; | 1838 | solver->parameters.step_time_min).rel_value_us; |
1832 | offset = (double) solver->parameters.step_time_min.rel_value_us; | 1839 | offset = (double)solver->parameters.step_time_min.rel_value_us; |
1833 | y = factor * pow (used_ratio, RIL_INTERVAL_EXPONENT) + offset; | 1840 | y = factor * pow(used_ratio, RIL_INTERVAL_EXPONENT) + offset; |
1834 | 1841 | ||
1835 | GNUNET_assert(y <= (double) solver->parameters.step_time_max.rel_value_us); | 1842 | GNUNET_assert(y <= (double)solver->parameters.step_time_max.rel_value_us); |
1836 | GNUNET_assert(y >= (double) solver->parameters.step_time_min.rel_value_us); | 1843 | GNUNET_assert(y >= (double)solver->parameters.step_time_min.rel_value_us); |
1837 | 1844 | ||
1838 | time_next = GNUNET_TIME_relative_saturating_multiply (GNUNET_TIME_UNIT_MICROSECONDS, (unsigned long long) y); | 1845 | time_next = GNUNET_TIME_relative_saturating_multiply(GNUNET_TIME_UNIT_MICROSECONDS, (unsigned long long)y); |
1839 | 1846 | ||
1840 | // LOG (GNUNET_ERROR_TYPE_INFO, "ratio: %f, factor: %f, offset: %f, y: %f\n", | 1847 | // LOG (GNUNET_ERROR_TYPE_INFO, "ratio: %f, factor: %f, offset: %f, y: %f\n", |
1841 | // used_ratio, | 1848 | // used_ratio, |
@@ -1844,15 +1851,15 @@ ril_step_schedule_next (struct GAS_RIL_Handle *solver) | |||
1844 | // y); | 1851 | // y); |
1845 | 1852 | ||
1846 | if (solver->simulate) | 1853 | if (solver->simulate) |
1847 | { | 1854 | { |
1848 | time_next = GNUNET_TIME_UNIT_ZERO; | 1855 | time_next = GNUNET_TIME_UNIT_ZERO; |
1849 | } | 1856 | } |
1850 | 1857 | ||
1851 | if ((NULL == solver->step_next_task_id) && (GNUNET_NO == solver->done)) | 1858 | if ((NULL == solver->step_next_task_id) && (GNUNET_NO == solver->done)) |
1852 | { | 1859 | { |
1853 | solver->step_next_task_id = GNUNET_SCHEDULER_add_delayed (time_next, &ril_step_scheduler_task, | 1860 | solver->step_next_task_id = GNUNET_SCHEDULER_add_delayed(time_next, &ril_step_scheduler_task, |
1854 | solver); | 1861 | solver); |
1855 | } | 1862 | } |
1856 | } | 1863 | } |
1857 | 1864 | ||
1858 | /** | 1865 | /** |
@@ -1861,61 +1868,62 @@ ril_step_schedule_next (struct GAS_RIL_Handle *solver) | |||
1861 | * @param solver | 1868 | * @param solver |
1862 | */ | 1869 | */ |
1863 | static void | 1870 | static void |
1864 | ril_step (struct GAS_RIL_Handle *solver) | 1871 | ril_step(struct GAS_RIL_Handle *solver) |
1865 | { | 1872 | { |
1866 | struct RIL_Peer_Agent *cur; | 1873 | struct RIL_Peer_Agent *cur; |
1867 | 1874 | ||
1868 | if (GNUNET_YES == solver->bulk_lock) | 1875 | if (GNUNET_YES == solver->bulk_lock) |
1869 | { | 1876 | { |
1870 | solver->bulk_changes++; | 1877 | solver->bulk_changes++; |
1871 | return; | 1878 | return; |
1872 | } | 1879 | } |
1873 | 1880 | ||
1874 | ril_inform (solver, GAS_OP_SOLVE_START, GAS_STAT_SUCCESS); | 1881 | ril_inform(solver, GAS_OP_SOLVE_START, GAS_STAT_SUCCESS); |
1875 | 1882 | ||
1876 | LOG(GNUNET_ERROR_TYPE_DEBUG, " RIL step number %d\n", solver->step_count); | 1883 | LOG(GNUNET_ERROR_TYPE_DEBUG, " RIL step number %d\n", solver->step_count); |
1877 | 1884 | ||
1878 | if (0 == solver->step_count) | 1885 | if (0 == solver->step_count) |
1879 | { | 1886 | { |
1880 | solver->step_time_last = GNUNET_TIME_absolute_get (); | 1887 | solver->step_time_last = GNUNET_TIME_absolute_get(); |
1881 | } | 1888 | } |
1882 | 1889 | ||
1883 | ril_calculate_discount (solver); | 1890 | ril_calculate_discount(solver); |
1884 | ril_networks_update_state (solver); | 1891 | ril_networks_update_state(solver); |
1885 | 1892 | ||
1886 | //trigger one step per active, unblocked agent | 1893 | //trigger one step per active, unblocked agent |
1887 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) | 1894 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) |
1888 | { | ||
1889 | if (cur->is_active) | ||
1890 | { | 1895 | { |
1891 | if (NULL == cur->address_inuse) | 1896 | if (cur->is_active) |
1892 | { | 1897 | { |
1893 | ril_try_unblock_agent(solver, cur, GNUNET_NO); | 1898 | if (NULL == cur->address_inuse) |
1894 | } | 1899 | { |
1895 | if (cur->address_inuse) | 1900 | ril_try_unblock_agent(solver, cur, GNUNET_NO); |
1896 | { | 1901 | } |
1897 | agent_step (cur); | 1902 | if (cur->address_inuse) |
1898 | } | 1903 | { |
1904 | agent_step(cur); | ||
1905 | } | ||
1906 | } | ||
1899 | } | 1907 | } |
1900 | } | ||
1901 | 1908 | ||
1902 | ril_networks_update_state (solver); | 1909 | ril_networks_update_state(solver); |
1903 | 1910 | ||
1904 | solver->step_count++; | 1911 | solver->step_count++; |
1905 | ril_step_schedule_next (solver); | 1912 | ril_step_schedule_next(solver); |
1906 | 1913 | ||
1907 | ril_inform (solver, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS); | 1914 | ril_inform(solver, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS); |
1908 | 1915 | ||
1909 | ril_inform (solver, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, GAS_STAT_SUCCESS); | 1916 | ril_inform(solver, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, GAS_STAT_SUCCESS); |
1910 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) | 1917 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) |
1911 | { | 1918 | { |
1912 | if (cur->suggestion_issue) { | 1919 | if (cur->suggestion_issue) |
1913 | solver->env->bandwidth_changed_cb (solver->env->cls, | 1920 | { |
1914 | cur->suggestion_address); | 1921 | solver->env->bandwidth_changed_cb(solver->env->cls, |
1915 | cur->suggestion_issue = GNUNET_NO; | 1922 | cur->suggestion_address); |
1916 | } | 1923 | cur->suggestion_issue = GNUNET_NO; |
1917 | } | 1924 | } |
1918 | ril_inform (solver, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, GAS_STAT_SUCCESS); | 1925 | } |
1926 | ril_inform(solver, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, GAS_STAT_SUCCESS); | ||
1919 | } | 1927 | } |
1920 | 1928 | ||
1921 | /** | 1929 | /** |
@@ -1924,18 +1932,18 @@ ril_step (struct GAS_RIL_Handle *solver) | |||
1924 | * @param agent The respective agent | 1932 | * @param agent The respective agent |
1925 | */ | 1933 | */ |
1926 | static void | 1934 | static void |
1927 | agent_w_init (struct RIL_Peer_Agent *agent) | 1935 | agent_w_init(struct RIL_Peer_Agent *agent) |
1928 | { | 1936 | { |
1929 | int i; | 1937 | int i; |
1930 | int k; | 1938 | int k; |
1931 | 1939 | ||
1932 | for (i = 0; i < agent->n; i++) | 1940 | for (i = 0; i < agent->n; i++) |
1933 | { | ||
1934 | for (k = 0; k < agent->m; k++) | ||
1935 | { | 1941 | { |
1936 | agent->W[i][k] = agent->envi->parameters.alpha * (1.0 - 2.0 * ((double) GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX)/(double) UINT32_MAX)); | 1942 | for (k = 0; k < agent->m; k++) |
1943 | { | ||
1944 | agent->W[i][k] = agent->envi->parameters.alpha * (1.0 - 2.0 * ((double)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX) / (double)UINT32_MAX)); | ||
1945 | } | ||
1937 | } | 1946 | } |
1938 | } | ||
1939 | } | 1947 | } |
1940 | 1948 | ||
1941 | /** | 1949 | /** |
@@ -1946,11 +1954,11 @@ agent_w_init (struct RIL_Peer_Agent *agent) | |||
1946 | * @return handle to the new agent | 1954 | * @return handle to the new agent |
1947 | */ | 1955 | */ |
1948 | static struct RIL_Peer_Agent * | 1956 | static struct RIL_Peer_Agent * |
1949 | agent_init (void *s, const struct GNUNET_PeerIdentity *peer) | 1957 | agent_init(void *s, const struct GNUNET_PeerIdentity *peer) |
1950 | { | 1958 | { |
1951 | int i; | 1959 | int i; |
1952 | struct GAS_RIL_Handle * solver = s; | 1960 | struct GAS_RIL_Handle * solver = s; |
1953 | struct RIL_Peer_Agent * agent = GNUNET_new (struct RIL_Peer_Agent); | 1961 | struct RIL_Peer_Agent * agent = GNUNET_new(struct RIL_Peer_Agent); |
1954 | 1962 | ||
1955 | agent->envi = solver; | 1963 | agent->envi = solver; |
1956 | agent->peer = *peer; | 1964 | agent->peer = *peer; |
@@ -1961,17 +1969,17 @@ agent_init (void *s, const struct GNUNET_PeerIdentity *peer) | |||
1961 | agent->suggestion_issue = GNUNET_NO; | 1969 | agent->suggestion_issue = GNUNET_NO; |
1962 | agent->n = RIL_ACTION_TYPE_NUM; | 1970 | agent->n = RIL_ACTION_TYPE_NUM; |
1963 | agent->m = 0; | 1971 | agent->m = 0; |
1964 | agent->W = (double **) GNUNET_malloc (sizeof (double *) * agent->n); | 1972 | agent->W = (double **)GNUNET_malloc(sizeof(double *) * agent->n); |
1965 | agent->E = (double **) GNUNET_malloc (sizeof (double *) * agent->n); | 1973 | agent->E = (double **)GNUNET_malloc(sizeof(double *) * agent->n); |
1966 | for (i = 0; i < agent->n; i++) | 1974 | for (i = 0; i < agent->n; i++) |
1967 | { | 1975 | { |
1968 | agent->W[i] = (double *) GNUNET_malloc (sizeof (double) * agent->m); | 1976 | agent->W[i] = (double *)GNUNET_malloc(sizeof(double) * agent->m); |
1969 | agent->E[i] = (double *) GNUNET_malloc (sizeof (double) * agent->m); | 1977 | agent->E[i] = (double *)GNUNET_malloc(sizeof(double) * agent->m); |
1970 | } | 1978 | } |
1971 | agent_w_init(agent); | 1979 | agent_w_init(agent); |
1972 | agent->eligibility_reset = GNUNET_NO; | 1980 | agent->eligibility_reset = GNUNET_NO; |
1973 | agent->a_old = RIL_ACTION_INVALID; | 1981 | agent->a_old = RIL_ACTION_INVALID; |
1974 | agent->s_old = GNUNET_malloc (sizeof (double) * agent->m); | 1982 | agent->s_old = GNUNET_malloc(sizeof(double) * agent->m); |
1975 | agent->address_inuse = NULL; | 1983 | agent->address_inuse = NULL; |
1976 | agent->objective_old = 0; | 1984 | agent->objective_old = 0; |
1977 | agent->nop_bonus = 0; | 1985 | agent->nop_bonus = 0; |
@@ -1986,15 +1994,15 @@ agent_init (void *s, const struct GNUNET_PeerIdentity *peer) | |||
1986 | * @param agent the agent to retire | 1994 | * @param agent the agent to retire |
1987 | */ | 1995 | */ |
1988 | static void | 1996 | static void |
1989 | agent_die (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | 1997 | agent_die(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) |
1990 | { | 1998 | { |
1991 | int i; | 1999 | int i; |
1992 | 2000 | ||
1993 | for (i = 0; i < agent->n; i++) | 2001 | for (i = 0; i < agent->n; i++) |
1994 | { | 2002 | { |
1995 | GNUNET_free_non_null(agent->W[i]); | 2003 | GNUNET_free_non_null(agent->W[i]); |
1996 | GNUNET_free_non_null(agent->E[i]); | 2004 | GNUNET_free_non_null(agent->E[i]); |
1997 | } | 2005 | } |
1998 | GNUNET_free_non_null(agent->W); | 2006 | GNUNET_free_non_null(agent->W); |
1999 | GNUNET_free_non_null(agent->E); | 2007 | GNUNET_free_non_null(agent->E); |
2000 | GNUNET_free_non_null(agent->s_old); | 2008 | GNUNET_free_non_null(agent->s_old); |
@@ -2010,25 +2018,25 @@ agent_die (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | |||
2010 | * @return the agent | 2018 | * @return the agent |
2011 | */ | 2019 | */ |
2012 | static struct RIL_Peer_Agent * | 2020 | static struct RIL_Peer_Agent * |
2013 | ril_get_agent (struct GAS_RIL_Handle *solver, const struct GNUNET_PeerIdentity *peer, int create) | 2021 | ril_get_agent(struct GAS_RIL_Handle *solver, const struct GNUNET_PeerIdentity *peer, int create) |
2014 | { | 2022 | { |
2015 | struct RIL_Peer_Agent *cur; | 2023 | struct RIL_Peer_Agent *cur; |
2016 | 2024 | ||
2017 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) | 2025 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) |
2018 | { | ||
2019 | if (0 == GNUNET_memcmp (peer, &cur->peer)) | ||
2020 | { | 2026 | { |
2021 | return cur; | 2027 | if (0 == GNUNET_memcmp(peer, &cur->peer)) |
2028 | { | ||
2029 | return cur; | ||
2030 | } | ||
2022 | } | 2031 | } |
2023 | } | ||
2024 | 2032 | ||
2025 | if (create) | 2033 | if (create) |
2026 | { | 2034 | { |
2027 | cur = agent_init (solver, peer); | 2035 | cur = agent_init(solver, peer); |
2028 | GNUNET_CONTAINER_DLL_insert_tail(solver->agents_head, solver->agents_tail, cur); | 2036 | GNUNET_CONTAINER_DLL_insert_tail(solver->agents_head, solver->agents_tail, cur); |
2029 | return cur; | 2037 | return cur; |
2030 | } | 2038 | } |
2031 | return NULL ; | 2039 | return NULL; |
2032 | } | 2040 | } |
2033 | 2041 | ||
2034 | /** | 2042 | /** |
@@ -2040,11 +2048,11 @@ ril_get_agent (struct GAS_RIL_Handle *solver, const struct GNUNET_PeerIdentity * | |||
2040 | * @return whether or not the network is considered active | 2048 | * @return whether or not the network is considered active |
2041 | */ | 2049 | */ |
2042 | static int | 2050 | static int |
2043 | ril_network_is_active (struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType network) | 2051 | ril_network_is_active(struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType network) |
2044 | { | 2052 | { |
2045 | struct RIL_Scope *net; | 2053 | struct RIL_Scope *net; |
2046 | 2054 | ||
2047 | net = ril_get_network (solver, network); | 2055 | net = ril_get_network(solver, network); |
2048 | return net->bw_out_available >= RIL_MIN_BW; | 2056 | return net->bw_out_available >= RIL_MIN_BW; |
2049 | } | 2057 | } |
2050 | 2058 | ||
@@ -2060,14 +2068,14 @@ ril_network_is_active (struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType ne | |||
2060 | * @param old_length the length of the old vector | 2068 | * @param old_length the length of the old vector |
2061 | */ | 2069 | */ |
2062 | static void | 2070 | static void |
2063 | ril_cut_from_vector (void **old, | 2071 | ril_cut_from_vector(void **old, |
2064 | size_t element_size, | 2072 | size_t element_size, |
2065 | unsigned int hole_start, | 2073 | unsigned int hole_start, |
2066 | unsigned int hole_length, | 2074 | unsigned int hole_length, |
2067 | unsigned int old_length) | 2075 | unsigned int old_length) |
2068 | { | 2076 | { |
2069 | char *tmpptr; | 2077 | char *tmpptr; |
2070 | char *oldptr = (char *) *old; | 2078 | char *oldptr = (char *)*old; |
2071 | size_t size; | 2079 | size_t size; |
2072 | unsigned int bytes_before; | 2080 | unsigned int bytes_before; |
2073 | unsigned int bytes_hole; | 2081 | unsigned int bytes_hole; |
@@ -2083,20 +2091,20 @@ ril_cut_from_vector (void **old, | |||
2083 | bytes_after = element_size * (old_length - hole_start - hole_length); | 2091 | bytes_after = element_size * (old_length - hole_start - hole_length); |
2084 | 2092 | ||
2085 | if (0 == size) | 2093 | if (0 == size) |
2086 | { | 2094 | { |
2087 | tmpptr = NULL; | 2095 | tmpptr = NULL; |
2088 | } | 2096 | } |
2089 | else | 2097 | else |
2090 | { | 2098 | { |
2091 | tmpptr = GNUNET_malloc (size); | 2099 | tmpptr = GNUNET_malloc(size); |
2092 | GNUNET_memcpy (tmpptr, oldptr, bytes_before); | 2100 | GNUNET_memcpy(tmpptr, oldptr, bytes_before); |
2093 | GNUNET_memcpy (tmpptr + bytes_before, oldptr + (bytes_before + bytes_hole), bytes_after); | 2101 | GNUNET_memcpy(tmpptr + bytes_before, oldptr + (bytes_before + bytes_hole), bytes_after); |
2094 | } | 2102 | } |
2095 | if (NULL != *old) | 2103 | if (NULL != *old) |
2096 | { | 2104 | { |
2097 | GNUNET_free(*old); | 2105 | GNUNET_free(*old); |
2098 | } | 2106 | } |
2099 | *old = (void *) tmpptr; | 2107 | *old = (void *)tmpptr; |
2100 | } | 2108 | } |
2101 | 2109 | ||
2102 | /* | 2110 | /* |
@@ -2113,20 +2121,20 @@ ril_cut_from_vector (void **old, | |||
2113 | * @param pref_rel the normalized preference value for this kind over all clients | 2121 | * @param pref_rel the normalized preference value for this kind over all clients |
2114 | */ | 2122 | */ |
2115 | static void | 2123 | static void |
2116 | GAS_ril_address_change_preference (void *solver, | 2124 | GAS_ril_address_change_preference(void *solver, |
2117 | const struct GNUNET_PeerIdentity *peer, | 2125 | const struct GNUNET_PeerIdentity *peer, |
2118 | enum GNUNET_ATS_PreferenceKind kind, | 2126 | enum GNUNET_ATS_PreferenceKind kind, |
2119 | double pref_rel) | 2127 | double pref_rel) |
2120 | { | 2128 | { |
2121 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2129 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2122 | "API_address_change_preference() Preference '%s' for peer '%s' changed to %.2f \n", | 2130 | "API_address_change_preference() Preference '%s' for peer '%s' changed to %.2f \n", |
2123 | GNUNET_ATS_print_preference_type (kind), GNUNET_i2s (peer), pref_rel); | 2131 | GNUNET_ATS_print_preference_type(kind), GNUNET_i2s(peer), pref_rel); |
2124 | 2132 | ||
2125 | struct GAS_RIL_Handle *s = solver; | 2133 | struct GAS_RIL_Handle *s = solver; |
2126 | 2134 | ||
2127 | s->parameters.temperature = s->parameters.temperature_init; | 2135 | s->parameters.temperature = s->parameters.temperature_init; |
2128 | s->parameters.epsilon = s->parameters.epsilon_init; | 2136 | s->parameters.epsilon = s->parameters.epsilon_init; |
2129 | ril_step (s); | 2137 | ril_step(s); |
2130 | } | 2138 | } |
2131 | 2139 | ||
2132 | 2140 | ||
@@ -2140,9 +2148,9 @@ GAS_ril_address_change_preference (void *solver, | |||
2140 | * @param network network type of this address | 2148 | * @param network network type of this address |
2141 | */ | 2149 | */ |
2142 | static void | 2150 | static void |
2143 | GAS_ril_address_add (void *solver, | 2151 | GAS_ril_address_add(void *solver, |
2144 | struct ATS_Address *address, | 2152 | struct ATS_Address *address, |
2145 | uint32_t network) | 2153 | uint32_t network) |
2146 | { | 2154 | { |
2147 | struct GAS_RIL_Handle *s = solver; | 2155 | struct GAS_RIL_Handle *s = solver; |
2148 | struct RIL_Peer_Agent *agent; | 2156 | struct RIL_Peer_Agent *agent; |
@@ -2155,32 +2163,32 @@ GAS_ril_address_add (void *solver, | |||
2155 | int i; | 2163 | int i; |
2156 | unsigned int zero; | 2164 | unsigned int zero; |
2157 | 2165 | ||
2158 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2166 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2159 | "API_address_add()\n"); | 2167 | "API_address_add()\n"); |
2160 | 2168 | ||
2161 | net = ril_get_network (s, network); | 2169 | net = ril_get_network(s, network); |
2162 | address->solver_information = net; | 2170 | address->solver_information = net; |
2163 | 2171 | ||
2164 | if (!ril_network_is_active (s, network)) | 2172 | if (!ril_network_is_active(s, network)) |
2165 | { | 2173 | { |
2166 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2174 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2167 | "API_address_add() Did not add %s address %s for peer '%s', network does not have enough bandwidth\n", | 2175 | "API_address_add() Did not add %s address %s for peer '%s', network does not have enough bandwidth\n", |
2168 | address->plugin, address->addr, GNUNET_i2s (&address->peer)); | 2176 | address->plugin, address->addr, GNUNET_i2s(&address->peer)); |
2169 | return; | 2177 | return; |
2170 | } | 2178 | } |
2171 | 2179 | ||
2172 | s->parameters.temperature = s->parameters.temperature_init; | 2180 | s->parameters.temperature = s->parameters.temperature_init; |
2173 | s->parameters.epsilon = s->parameters.epsilon_init; | 2181 | s->parameters.epsilon = s->parameters.epsilon_init; |
2174 | 2182 | ||
2175 | agent = ril_get_agent (s, &address->peer, GNUNET_YES); | 2183 | agent = ril_get_agent(s, &address->peer, GNUNET_YES); |
2176 | 2184 | ||
2177 | //add address | 2185 | //add address |
2178 | address_wrapped = GNUNET_new (struct RIL_Address_Wrapped); | 2186 | address_wrapped = GNUNET_new(struct RIL_Address_Wrapped); |
2179 | address_wrapped->address_naked = address; | 2187 | address_wrapped->address_naked = address; |
2180 | GNUNET_CONTAINER_DLL_insert_tail(agent->addresses_head, agent->addresses_tail, address_wrapped); | 2188 | GNUNET_CONTAINER_DLL_insert_tail(agent->addresses_head, agent->addresses_tail, address_wrapped); |
2181 | 2189 | ||
2182 | //increase size of W | 2190 | //increase size of W |
2183 | m_new = agent->m + ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)); | 2191 | m_new = agent->m + ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)); |
2184 | m_old = agent->m; | 2192 | m_old = agent->m; |
2185 | n_new = agent->n + 1; | 2193 | n_new = agent->n + 1; |
2186 | n_old = agent->n; | 2194 | n_old = agent->n; |
@@ -2189,22 +2197,22 @@ GAS_ril_address_add (void *solver, | |||
2189 | agent->n = n_old; | 2197 | agent->n = n_old; |
2190 | GNUNET_array_grow(agent->E, agent->n, n_new); | 2198 | GNUNET_array_grow(agent->E, agent->n, n_new); |
2191 | for (i = 0; i < n_new; i++) | 2199 | for (i = 0; i < n_new; i++) |
2192 | { | ||
2193 | if (i < n_old) | ||
2194 | { | ||
2195 | agent->m = m_old; | ||
2196 | GNUNET_array_grow(agent->W[i], agent->m, m_new); | ||
2197 | agent->m = m_old; | ||
2198 | GNUNET_array_grow(agent->E[i], agent->m, m_new); | ||
2199 | } | ||
2200 | else | ||
2201 | { | 2200 | { |
2202 | zero = 0; | 2201 | if (i < n_old) |
2203 | GNUNET_array_grow(agent->W[i], zero, m_new); | 2202 | { |
2204 | zero = 0; | 2203 | agent->m = m_old; |
2205 | GNUNET_array_grow(agent->E[i], zero, m_new); | 2204 | GNUNET_array_grow(agent->W[i], agent->m, m_new); |
2205 | agent->m = m_old; | ||
2206 | GNUNET_array_grow(agent->E[i], agent->m, m_new); | ||
2207 | } | ||
2208 | else | ||
2209 | { | ||
2210 | zero = 0; | ||
2211 | GNUNET_array_grow(agent->W[i], zero, m_new); | ||
2212 | zero = 0; | ||
2213 | GNUNET_array_grow(agent->E[i], zero, m_new); | ||
2214 | } | ||
2206 | } | 2215 | } |
2207 | } | ||
2208 | 2216 | ||
2209 | //increase size of old state vector | 2217 | //increase size of old state vector |
2210 | agent->m = m_old; | 2218 | agent->m = m_old; |
@@ -2212,11 +2220,11 @@ GAS_ril_address_add (void *solver, | |||
2212 | 2220 | ||
2213 | ril_try_unblock_agent(s, agent, GNUNET_NO); | 2221 | ril_try_unblock_agent(s, agent, GNUNET_NO); |
2214 | 2222 | ||
2215 | ril_step (s); | 2223 | ril_step(s); |
2216 | 2224 | ||
2217 | LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_add() Added %s %s address %s for peer '%s'\n", | 2225 | LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_add() Added %s %s address %s for peer '%s'\n", |
2218 | address->active ? "active" : "inactive", address->plugin, address->addr, | 2226 | address->active ? "active" : "inactive", address->plugin, address->addr, |
2219 | GNUNET_i2s (&address->peer)); | 2227 | GNUNET_i2s(&address->peer)); |
2220 | } | 2228 | } |
2221 | 2229 | ||
2222 | /** | 2230 | /** |
@@ -2228,8 +2236,8 @@ GAS_ril_address_add (void *solver, | |||
2228 | * @param address the address to remove | 2236 | * @param address the address to remove |
2229 | */ | 2237 | */ |
2230 | static void | 2238 | static void |
2231 | GAS_ril_address_delete (void *solver, | 2239 | GAS_ril_address_delete(void *solver, |
2232 | struct ATS_Address *address) | 2240 | struct ATS_Address *address) |
2233 | { | 2241 | { |
2234 | struct GAS_RIL_Handle *s = solver; | 2242 | struct GAS_RIL_Handle *s = solver; |
2235 | struct RIL_Peer_Agent *agent; | 2243 | struct RIL_Peer_Agent *agent; |
@@ -2240,103 +2248,103 @@ GAS_ril_address_delete (void *solver, | |||
2240 | int i; | 2248 | int i; |
2241 | struct RIL_Scope *net; | 2249 | struct RIL_Scope *net; |
2242 | 2250 | ||
2243 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2251 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2244 | "API_address_delete() Delete %s %s address %s for peer '%s'\n", | 2252 | "API_address_delete() Delete %s %s address %s for peer '%s'\n", |
2245 | address->active ? "active" : "inactive", | 2253 | address->active ? "active" : "inactive", |
2246 | address->plugin, | 2254 | address->plugin, |
2247 | address->addr, | 2255 | address->addr, |
2248 | GNUNET_i2s (&address->peer)); | 2256 | GNUNET_i2s(&address->peer)); |
2249 | 2257 | ||
2250 | agent = ril_get_agent (s, &address->peer, GNUNET_NO); | 2258 | agent = ril_get_agent(s, &address->peer, GNUNET_NO); |
2251 | if (NULL == agent) | 2259 | if (NULL == agent) |
2252 | { | 2260 | { |
2253 | net = address->solver_information; | 2261 | net = address->solver_information; |
2254 | GNUNET_assert(! ril_network_is_active (s, net->type)); | 2262 | GNUNET_assert(!ril_network_is_active(s, net->type)); |
2255 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2263 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2256 | "No agent allocated for peer yet, since address was in inactive network\n"); | 2264 | "No agent allocated for peer yet, since address was in inactive network\n"); |
2257 | return; | 2265 | return; |
2258 | } | 2266 | } |
2259 | 2267 | ||
2260 | s->parameters.temperature = s->parameters.temperature_init; | 2268 | s->parameters.temperature = s->parameters.temperature_init; |
2261 | s->parameters.epsilon = s->parameters.epsilon_init; | 2269 | s->parameters.epsilon = s->parameters.epsilon_init; |
2262 | 2270 | ||
2263 | address_index = agent_address_get_index (agent, address); | 2271 | address_index = agent_address_get_index(agent, address); |
2264 | address_wrapped = agent_address_get_wrapped (agent, address); | 2272 | address_wrapped = agent_address_get_wrapped(agent, address); |
2265 | 2273 | ||
2266 | if (NULL == address_wrapped) | 2274 | if (NULL == address_wrapped) |
2267 | { | 2275 | { |
2268 | net = address->solver_information; | 2276 | net = address->solver_information; |
2269 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2277 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2270 | "Address not considered by agent, address was in inactive network\n"); | 2278 | "Address not considered by agent, address was in inactive network\n"); |
2271 | return; | 2279 | return; |
2272 | } | 2280 | } |
2273 | GNUNET_CONTAINER_DLL_remove (agent->addresses_head, | 2281 | GNUNET_CONTAINER_DLL_remove(agent->addresses_head, |
2274 | agent->addresses_tail, | 2282 | agent->addresses_tail, |
2275 | address_wrapped); | 2283 | address_wrapped); |
2276 | GNUNET_free (address_wrapped); | 2284 | GNUNET_free(address_wrapped); |
2277 | 2285 | ||
2278 | //decrease W | 2286 | //decrease W |
2279 | m_new = agent->m - ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)); | 2287 | m_new = agent->m - ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)); |
2280 | n_new = agent->n - 1; | 2288 | n_new = agent->n - 1; |
2281 | 2289 | ||
2282 | for (i = 0; i < agent->n; i++) | 2290 | for (i = 0; i < agent->n; i++) |
2283 | { | 2291 | { |
2284 | ril_cut_from_vector ((void **) &agent->W[i], sizeof(double), | 2292 | ril_cut_from_vector((void **)&agent->W[i], sizeof(double), |
2285 | address_index * ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), | 2293 | address_index * ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)), |
2286 | ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), agent->m); | 2294 | ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)), agent->m); |
2287 | ril_cut_from_vector ((void **) &agent->E[i], sizeof(double), | 2295 | ril_cut_from_vector((void **)&agent->E[i], sizeof(double), |
2288 | address_index * ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), | 2296 | address_index * ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)), |
2289 | ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), agent->m); | 2297 | ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)), agent->m); |
2290 | } | 2298 | } |
2291 | GNUNET_free_non_null(agent->W[RIL_ACTION_TYPE_NUM + address_index]); | 2299 | GNUNET_free_non_null(agent->W[RIL_ACTION_TYPE_NUM + address_index]); |
2292 | GNUNET_free_non_null(agent->E[RIL_ACTION_TYPE_NUM + address_index]); | 2300 | GNUNET_free_non_null(agent->E[RIL_ACTION_TYPE_NUM + address_index]); |
2293 | ril_cut_from_vector ((void **) &agent->W, sizeof(double *), RIL_ACTION_TYPE_NUM + address_index, | 2301 | ril_cut_from_vector((void **)&agent->W, sizeof(double *), RIL_ACTION_TYPE_NUM + address_index, |
2294 | 1, agent->n); | 2302 | 1, agent->n); |
2295 | ril_cut_from_vector ((void **) &agent->E, sizeof(double *), RIL_ACTION_TYPE_NUM + address_index, | 2303 | ril_cut_from_vector((void **)&agent->E, sizeof(double *), RIL_ACTION_TYPE_NUM + address_index, |
2296 | 1, agent->n); | 2304 | 1, agent->n); |
2297 | //correct last action | 2305 | //correct last action |
2298 | if (agent->a_old > (RIL_ACTION_TYPE_NUM + address_index)) | 2306 | if (agent->a_old > (RIL_ACTION_TYPE_NUM + address_index)) |
2299 | { | 2307 | { |
2300 | agent->a_old -= 1; | 2308 | agent->a_old -= 1; |
2301 | } | 2309 | } |
2302 | else if (agent->a_old == (RIL_ACTION_TYPE_NUM + address_index)) | 2310 | else if (agent->a_old == (RIL_ACTION_TYPE_NUM + address_index)) |
2303 | { | 2311 | { |
2304 | agent->a_old = RIL_ACTION_INVALID; | 2312 | agent->a_old = RIL_ACTION_INVALID; |
2305 | } | 2313 | } |
2306 | //decrease old state vector | 2314 | //decrease old state vector |
2307 | ril_cut_from_vector ((void **) &agent->s_old, sizeof(double), | 2315 | ril_cut_from_vector((void **)&agent->s_old, sizeof(double), |
2308 | address_index * ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), | 2316 | address_index * ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)), |
2309 | ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), agent->m); | 2317 | ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)), agent->m); |
2310 | agent->m = m_new; | 2318 | agent->m = m_new; |
2311 | agent->n = n_new; | 2319 | agent->n = n_new; |
2312 | 2320 | ||
2313 | if (agent->address_inuse == address) | 2321 | if (agent->address_inuse == address) |
2314 | { | 2322 | { |
2315 | if (NULL != agent->addresses_head) //if peer has an address left, use it | 2323 | if (NULL != agent->addresses_head) //if peer has an address left, use it |
2316 | { | 2324 | { |
2317 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2325 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2318 | "Active address died, suggesting alternative!\n"); | 2326 | "Active address died, suggesting alternative!\n"); |
2319 | envi_set_active_suggestion (s, | 2327 | envi_set_active_suggestion(s, |
2320 | agent, | 2328 | agent, |
2321 | agent->addresses_head->address_naked, | 2329 | agent->addresses_head->address_naked, |
2322 | agent->bw_in, | 2330 | agent->bw_in, |
2323 | agent->bw_out, | 2331 | agent->bw_out, |
2324 | GNUNET_YES); | 2332 | GNUNET_YES); |
2325 | } | 2333 | } |
2326 | else | 2334 | else |
2327 | { | 2335 | { |
2328 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2336 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2329 | "Active address died, suggesting disconnect!\n"); | 2337 | "Active address died, suggesting disconnect!\n"); |
2330 | envi_set_active_suggestion (s, agent, NULL, 0, 0, GNUNET_NO); | 2338 | envi_set_active_suggestion(s, agent, NULL, 0, 0, GNUNET_NO); |
2331 | } | 2339 | } |
2332 | } | 2340 | } |
2333 | ril_step (solver); | 2341 | ril_step(solver); |
2334 | if (agent->suggestion_address == address) | 2342 | if (agent->suggestion_address == address) |
2335 | { | 2343 | { |
2336 | agent->suggestion_issue = GNUNET_NO; | 2344 | agent->suggestion_issue = GNUNET_NO; |
2337 | agent->suggestion_address = NULL; | 2345 | agent->suggestion_address = NULL; |
2338 | } | 2346 | } |
2339 | GNUNET_assert (agent->address_inuse != address); | 2347 | GNUNET_assert(agent->address_inuse != address); |
2340 | } | 2348 | } |
2341 | 2349 | ||
2342 | 2350 | ||
@@ -2347,17 +2355,17 @@ GAS_ril_address_delete (void *solver, | |||
2347 | * @param address the address | 2355 | * @param address the address |
2348 | */ | 2356 | */ |
2349 | static void | 2357 | static void |
2350 | GAS_ril_address_property_changed (void *solver, | 2358 | GAS_ril_address_property_changed(void *solver, |
2351 | struct ATS_Address *address) | 2359 | struct ATS_Address *address) |
2352 | { | 2360 | { |
2353 | struct GAS_RIL_Handle *s = solver; | 2361 | struct GAS_RIL_Handle *s = solver; |
2354 | 2362 | ||
2355 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2363 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2356 | "Properties for peer '%s' address changed\n", | 2364 | "Properties for peer '%s' address changed\n", |
2357 | GNUNET_i2s (&address->peer)); | 2365 | GNUNET_i2s(&address->peer)); |
2358 | s->parameters.temperature = s->parameters.temperature_init; | 2366 | s->parameters.temperature = s->parameters.temperature_init; |
2359 | s->parameters.epsilon = s->parameters.epsilon_init; | 2367 | s->parameters.epsilon = s->parameters.epsilon_init; |
2360 | ril_step (s); | 2368 | ril_step(s); |
2361 | } | 2369 | } |
2362 | 2370 | ||
2363 | 2371 | ||
@@ -2372,20 +2380,20 @@ GAS_ril_address_property_changed (void *solver, | |||
2372 | * @param score the score | 2380 | * @param score the score |
2373 | */ | 2381 | */ |
2374 | static void | 2382 | static void |
2375 | GAS_ril_address_preference_feedback (void *solver, | 2383 | GAS_ril_address_preference_feedback(void *solver, |
2376 | struct GNUNET_SERVICE_Client *application, | 2384 | struct GNUNET_SERVICE_Client *application, |
2377 | const struct GNUNET_PeerIdentity *peer, | 2385 | const struct GNUNET_PeerIdentity *peer, |
2378 | const struct GNUNET_TIME_Relative scope, | 2386 | const struct GNUNET_TIME_Relative scope, |
2379 | enum GNUNET_ATS_PreferenceKind kind, | 2387 | enum GNUNET_ATS_PreferenceKind kind, |
2380 | double score) | 2388 | double score) |
2381 | { | 2389 | { |
2382 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2390 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2383 | "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f from application %s for " | 2391 | "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f from application %s for " |
2384 | "preference %s for %d seconds\n", | 2392 | "preference %s for %d seconds\n", |
2385 | GNUNET_i2s (peer), | 2393 | GNUNET_i2s(peer), |
2386 | "UNKNOWN", | 2394 | "UNKNOWN", |
2387 | GNUNET_ATS_print_preference_type (kind), | 2395 | GNUNET_ATS_print_preference_type(kind), |
2388 | scope.rel_value_us / 1000000); | 2396 | scope.rel_value_us / 1000000); |
2389 | } | 2397 | } |
2390 | 2398 | ||
2391 | 2399 | ||
@@ -2395,12 +2403,12 @@ GAS_ril_address_preference_feedback (void *solver, | |||
2395 | * @param solver the solver | 2403 | * @param solver the solver |
2396 | */ | 2404 | */ |
2397 | static void | 2405 | static void |
2398 | GAS_ril_bulk_start (void *solver) | 2406 | GAS_ril_bulk_start(void *solver) |
2399 | { | 2407 | { |
2400 | struct GAS_RIL_Handle *s = solver; | 2408 | struct GAS_RIL_Handle *s = solver; |
2401 | 2409 | ||
2402 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2410 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2403 | "API_bulk_start() lock: %d\n", s->bulk_lock+1); | 2411 | "API_bulk_start() lock: %d\n", s->bulk_lock + 1); |
2404 | 2412 | ||
2405 | s->bulk_lock++; | 2413 | s->bulk_lock++; |
2406 | } | 2414 | } |
@@ -2412,7 +2420,7 @@ GAS_ril_bulk_start (void *solver) | |||
2412 | * @param solver the solver handle | 2420 | * @param solver the solver handle |
2413 | */ | 2421 | */ |
2414 | static void | 2422 | static void |
2415 | GAS_ril_bulk_stop (void *solver) | 2423 | GAS_ril_bulk_stop(void *solver) |
2416 | { | 2424 | { |
2417 | struct GAS_RIL_Handle *s = solver; | 2425 | struct GAS_RIL_Handle *s = solver; |
2418 | 2426 | ||
@@ -2421,17 +2429,17 @@ GAS_ril_bulk_stop (void *solver) | |||
2421 | s->bulk_lock - 1); | 2429 | s->bulk_lock - 1); |
2422 | 2430 | ||
2423 | if (s->bulk_lock < 1) | 2431 | if (s->bulk_lock < 1) |
2424 | { | 2432 | { |
2425 | GNUNET_break(0); | 2433 | GNUNET_break(0); |
2426 | return; | 2434 | return; |
2427 | } | 2435 | } |
2428 | s->bulk_lock--; | 2436 | s->bulk_lock--; |
2429 | 2437 | ||
2430 | if (0 < s->bulk_changes) | 2438 | if (0 < s->bulk_changes) |
2431 | { | 2439 | { |
2432 | ril_step (solver); | 2440 | ril_step(solver); |
2433 | s->bulk_changes = 0; | 2441 | s->bulk_changes = 0; |
2434 | } | 2442 | } |
2435 | } | 2443 | } |
2436 | 2444 | ||
2437 | 2445 | ||
@@ -2446,38 +2454,38 @@ GAS_ril_bulk_stop (void *solver) | |||
2446 | * @param peer the identity of the peer | 2454 | * @param peer the identity of the peer |
2447 | */ | 2455 | */ |
2448 | static void | 2456 | static void |
2449 | GAS_ril_get_preferred_address (void *solver, | 2457 | GAS_ril_get_preferred_address(void *solver, |
2450 | const struct GNUNET_PeerIdentity *peer) | 2458 | const struct GNUNET_PeerIdentity *peer) |
2451 | { | 2459 | { |
2452 | struct GAS_RIL_Handle *s = solver; | 2460 | struct GAS_RIL_Handle *s = solver; |
2453 | struct RIL_Peer_Agent *agent; | 2461 | struct RIL_Peer_Agent *agent; |
2454 | 2462 | ||
2455 | LOG(GNUNET_ERROR_TYPE_DEBUG, "API_get_preferred_address()\n"); | 2463 | LOG(GNUNET_ERROR_TYPE_DEBUG, "API_get_preferred_address()\n"); |
2456 | 2464 | ||
2457 | agent = ril_get_agent (s, peer, GNUNET_YES); | 2465 | agent = ril_get_agent(s, peer, GNUNET_YES); |
2458 | 2466 | ||
2459 | agent->is_active = GNUNET_YES; | 2467 | agent->is_active = GNUNET_YES; |
2460 | envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, agent->bw_out, GNUNET_YES); | 2468 | envi_set_active_suggestion(solver, agent, agent->address_inuse, agent->bw_in, agent->bw_out, GNUNET_YES); |
2461 | 2469 | ||
2462 | ril_try_unblock_agent(solver, agent, GNUNET_YES); | 2470 | ril_try_unblock_agent(solver, agent, GNUNET_YES); |
2463 | 2471 | ||
2464 | if (agent->address_inuse) | 2472 | if (agent->address_inuse) |
2465 | { | 2473 | { |
2466 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2474 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2467 | "API_get_preferred_address() Activated agent for peer '%s' with %s address %s\n", | 2475 | "API_get_preferred_address() Activated agent for peer '%s' with %s address %s\n", |
2468 | GNUNET_i2s (peer), agent->address_inuse->plugin, agent->address_inuse->addr); | 2476 | GNUNET_i2s(peer), agent->address_inuse->plugin, agent->address_inuse->addr); |
2469 | } | 2477 | } |
2470 | else | 2478 | else |
2471 | { | 2479 | { |
2472 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2480 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2473 | "API_get_preferred_address() Activated agent for peer '%s', but no address available\n", | 2481 | "API_get_preferred_address() Activated agent for peer '%s', but no address available\n", |
2474 | GNUNET_i2s (peer)); | 2482 | GNUNET_i2s(peer)); |
2475 | s->parameters.temperature = s->parameters.temperature_init; | 2483 | s->parameters.temperature = s->parameters.temperature_init; |
2476 | s->parameters.epsilon = s->parameters.epsilon_init; | 2484 | s->parameters.epsilon = s->parameters.epsilon_init; |
2477 | } | 2485 | } |
2478 | if (NULL != agent->address_inuse) | 2486 | if (NULL != agent->address_inuse) |
2479 | s->env->bandwidth_changed_cb (s->env->cls, | 2487 | s->env->bandwidth_changed_cb(s->env->cls, |
2480 | agent->address_inuse); | 2488 | agent->address_inuse); |
2481 | } | 2489 | } |
2482 | 2490 | ||
2483 | 2491 | ||
@@ -2491,41 +2499,41 @@ GAS_ril_get_preferred_address (void *solver, | |||
2491 | * @param peer the peer | 2499 | * @param peer the peer |
2492 | */ | 2500 | */ |
2493 | static void | 2501 | static void |
2494 | GAS_ril_stop_get_preferred_address (void *solver, | 2502 | GAS_ril_stop_get_preferred_address(void *solver, |
2495 | const struct GNUNET_PeerIdentity *peer) | 2503 | const struct GNUNET_PeerIdentity *peer) |
2496 | { | 2504 | { |
2497 | struct GAS_RIL_Handle *s = solver; | 2505 | struct GAS_RIL_Handle *s = solver; |
2498 | struct RIL_Peer_Agent *agent; | 2506 | struct RIL_Peer_Agent *agent; |
2499 | 2507 | ||
2500 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2508 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2501 | "API_stop_get_preferred_address()"); | 2509 | "API_stop_get_preferred_address()"); |
2502 | 2510 | ||
2503 | agent = ril_get_agent (s, peer, GNUNET_NO); | 2511 | agent = ril_get_agent(s, peer, GNUNET_NO); |
2504 | 2512 | ||
2505 | if (NULL == agent) | 2513 | if (NULL == agent) |
2506 | { | 2514 | { |
2507 | GNUNET_break(0); | 2515 | GNUNET_break(0); |
2508 | return; | 2516 | return; |
2509 | } | 2517 | } |
2510 | if (GNUNET_NO == agent->is_active) | 2518 | if (GNUNET_NO == agent->is_active) |
2511 | { | 2519 | { |
2512 | GNUNET_break(0); | 2520 | GNUNET_break(0); |
2513 | return; | 2521 | return; |
2514 | } | 2522 | } |
2515 | 2523 | ||
2516 | s->parameters.temperature = s->parameters.temperature_init; | 2524 | s->parameters.temperature = s->parameters.temperature_init; |
2517 | s->parameters.epsilon = s->parameters.epsilon_init; | 2525 | s->parameters.epsilon = s->parameters.epsilon_init; |
2518 | 2526 | ||
2519 | agent->is_active = GNUNET_NO; | 2527 | agent->is_active = GNUNET_NO; |
2520 | 2528 | ||
2521 | envi_set_active_suggestion (s, agent, agent->address_inuse, agent->bw_in, agent->bw_out, | 2529 | envi_set_active_suggestion(s, agent, agent->address_inuse, agent->bw_in, agent->bw_out, |
2522 | GNUNET_YES); | 2530 | GNUNET_YES); |
2523 | 2531 | ||
2524 | ril_step (s); | 2532 | ril_step(s); |
2525 | 2533 | ||
2526 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2534 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2527 | "API_stop_get_preferred_address() Paused agent for peer '%s'\n", | 2535 | "API_stop_get_preferred_address() Paused agent for peer '%s'\n", |
2528 | GNUNET_i2s (peer)); | 2536 | GNUNET_i2s(peer)); |
2529 | } | 2537 | } |
2530 | 2538 | ||
2531 | 2539 | ||
@@ -2535,233 +2543,233 @@ GAS_ril_stop_get_preferred_address (void *solver, | |||
2535 | * @param cls pointer to the 'struct GNUNET_ATS_PluginEnvironment' | 2543 | * @param cls pointer to the 'struct GNUNET_ATS_PluginEnvironment' |
2536 | */ | 2544 | */ |
2537 | void * | 2545 | void * |
2538 | libgnunet_plugin_ats_ril_init (void *cls) | 2546 | libgnunet_plugin_ats_ril_init(void *cls) |
2539 | { | 2547 | { |
2540 | static struct GNUNET_ATS_SolverFunctions sf; | 2548 | static struct GNUNET_ATS_SolverFunctions sf; |
2541 | struct GNUNET_ATS_PluginEnvironment *env = cls; | 2549 | struct GNUNET_ATS_PluginEnvironment *env = cls; |
2542 | struct GAS_RIL_Handle *solver = GNUNET_new (struct GAS_RIL_Handle); | 2550 | struct GAS_RIL_Handle *solver = GNUNET_new(struct GAS_RIL_Handle); |
2543 | struct RIL_Scope * cur; | 2551 | struct RIL_Scope * cur; |
2544 | int c; | 2552 | int c; |
2545 | char *string; | 2553 | char *string; |
2546 | float f_tmp; | 2554 | float f_tmp; |
2547 | 2555 | ||
2548 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2556 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2549 | "API_init() Initializing RIL solver\n"); | 2557 | "API_init() Initializing RIL solver\n"); |
2550 | 2558 | ||
2551 | GNUNET_assert (NULL != env); | 2559 | GNUNET_assert(NULL != env); |
2552 | GNUNET_assert (NULL != env->cfg); | 2560 | GNUNET_assert(NULL != env->cfg); |
2553 | GNUNET_assert (NULL != env->stats); | 2561 | GNUNET_assert(NULL != env->stats); |
2554 | GNUNET_assert (NULL != env->bandwidth_changed_cb); | 2562 | GNUNET_assert(NULL != env->bandwidth_changed_cb); |
2555 | GNUNET_assert (NULL != env->get_preferences); | 2563 | GNUNET_assert(NULL != env->get_preferences); |
2556 | 2564 | ||
2557 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, "ats", "RIL_RBF_DIVISOR", &solver->parameters.rbf_divisor)) | 2565 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, "ats", "RIL_RBF_DIVISOR", &solver->parameters.rbf_divisor)) |
2558 | { | 2566 | { |
2559 | solver->parameters.rbf_divisor = RIL_DEFAULT_RBF_DIVISOR; | 2567 | solver->parameters.rbf_divisor = RIL_DEFAULT_RBF_DIVISOR; |
2560 | } | 2568 | } |
2561 | 2569 | ||
2562 | if (GNUNET_OK | 2570 | if (GNUNET_OK |
2563 | != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats", "RIL_STEP_TIME_MIN", | 2571 | != GNUNET_CONFIGURATION_get_value_time(env->cfg, "ats", "RIL_STEP_TIME_MIN", |
2564 | &solver->parameters.step_time_min)) | 2572 | &solver->parameters.step_time_min)) |
2565 | { | 2573 | { |
2566 | solver->parameters.step_time_min = RIL_DEFAULT_STEP_TIME_MIN; | 2574 | solver->parameters.step_time_min = RIL_DEFAULT_STEP_TIME_MIN; |
2567 | } | 2575 | } |
2568 | 2576 | ||
2569 | if (GNUNET_OK | 2577 | if (GNUNET_OK |
2570 | != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats", "RIL_STEP_TIME_MAX", | 2578 | != GNUNET_CONFIGURATION_get_value_time(env->cfg, "ats", "RIL_STEP_TIME_MAX", |
2571 | &solver->parameters.step_time_max)) | 2579 | &solver->parameters.step_time_max)) |
2572 | { | 2580 | { |
2573 | solver->parameters.step_time_max = RIL_DEFAULT_STEP_TIME_MAX; | 2581 | solver->parameters.step_time_max = RIL_DEFAULT_STEP_TIME_MAX; |
2574 | } | 2582 | } |
2575 | 2583 | ||
2576 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_ALGORITHM", &string)) | 2584 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(env->cfg, "ats", "RIL_ALGORITHM", &string)) |
2577 | { | ||
2578 | GNUNET_STRINGS_utf8_toupper (string, string); | ||
2579 | if (0 == strcmp (string, "SARSA")) | ||
2580 | { | 2585 | { |
2581 | solver->parameters.algorithm = RIL_ALGO_SARSA; | 2586 | GNUNET_STRINGS_utf8_toupper(string, string); |
2587 | if (0 == strcmp(string, "SARSA")) | ||
2588 | { | ||
2589 | solver->parameters.algorithm = RIL_ALGO_SARSA; | ||
2590 | } | ||
2591 | if (0 == strcmp(string, "Q-LEARNING")) | ||
2592 | { | ||
2593 | solver->parameters.algorithm = RIL_ALGO_Q; | ||
2594 | } | ||
2595 | |||
2596 | GNUNET_free(string); | ||
2582 | } | 2597 | } |
2583 | if (0 == strcmp (string, "Q-LEARNING")) | 2598 | else |
2584 | { | 2599 | { |
2585 | solver->parameters.algorithm = RIL_ALGO_Q; | 2600 | solver->parameters.algorithm = RIL_DEFAULT_ALGORITHM; |
2586 | } | 2601 | } |
2587 | 2602 | ||
2588 | GNUNET_free (string); | 2603 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(env->cfg, "ats", "RIL_SELECT", &string)) |
2589 | } | 2604 | { |
2590 | else | 2605 | solver->parameters.select = !strcmp(string, "EGREEDY") ? RIL_SELECT_EGREEDY : RIL_SELECT_SOFTMAX; |
2591 | { | 2606 | GNUNET_free(string); |
2592 | solver->parameters.algorithm = RIL_DEFAULT_ALGORITHM; | 2607 | } |
2593 | } | ||
2594 | |||
2595 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_SELECT", &string)) | ||
2596 | { | ||
2597 | solver->parameters.select = !strcmp (string, "EGREEDY") ? RIL_SELECT_EGREEDY : RIL_SELECT_SOFTMAX; | ||
2598 | GNUNET_free (string); | ||
2599 | } | ||
2600 | else | 2608 | else |
2601 | { | 2609 | { |
2602 | solver->parameters.select = RIL_DEFAULT_SELECT; | 2610 | solver->parameters.select = RIL_DEFAULT_SELECT; |
2603 | } | 2611 | } |
2604 | 2612 | ||
2605 | 2613 | ||
2606 | solver->parameters.beta = RIL_DEFAULT_DISCOUNT_BETA; | 2614 | solver->parameters.beta = RIL_DEFAULT_DISCOUNT_BETA; |
2607 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | 2615 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", |
2608 | "RIL_DISCOUNT_BETA", &f_tmp)) | 2616 | "RIL_DISCOUNT_BETA", &f_tmp)) |
2609 | { | ||
2610 | if (f_tmp < 0.0) | ||
2611 | { | ||
2612 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2613 | "RIL_DISCOUNT_BETA", f_tmp); | ||
2614 | } | ||
2615 | else | ||
2616 | { | 2617 | { |
2617 | solver->parameters.beta = f_tmp; | 2618 | if (f_tmp < 0.0) |
2618 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | 2619 | { |
2619 | "RIL_DISCOUNT_BETA", f_tmp); | 2620 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), |
2621 | "RIL_DISCOUNT_BETA", f_tmp); | ||
2622 | } | ||
2623 | else | ||
2624 | { | ||
2625 | solver->parameters.beta = f_tmp; | ||
2626 | LOG(GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2627 | "RIL_DISCOUNT_BETA", f_tmp); | ||
2628 | } | ||
2620 | } | 2629 | } |
2621 | } | ||
2622 | 2630 | ||
2623 | solver->parameters.gamma = RIL_DEFAULT_DISCOUNT_GAMMA; | 2631 | solver->parameters.gamma = RIL_DEFAULT_DISCOUNT_GAMMA; |
2624 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | 2632 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", |
2625 | "RIL_DISCOUNT_GAMMA", &f_tmp)) | 2633 | "RIL_DISCOUNT_GAMMA", &f_tmp)) |
2626 | { | ||
2627 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) | ||
2628 | { | 2634 | { |
2629 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | 2635 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) |
2630 | "RIL_DISCOUNT_GAMMA", f_tmp); | 2636 | { |
2631 | } | 2637 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), |
2632 | else | 2638 | "RIL_DISCOUNT_GAMMA", f_tmp); |
2633 | { | 2639 | } |
2634 | solver->parameters.gamma = f_tmp; | 2640 | else |
2635 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | 2641 | { |
2636 | "RIL_DISCOUNT_GAMMA", f_tmp); | 2642 | solver->parameters.gamma = f_tmp; |
2643 | LOG(GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2644 | "RIL_DISCOUNT_GAMMA", f_tmp); | ||
2645 | } | ||
2637 | } | 2646 | } |
2638 | } | ||
2639 | 2647 | ||
2640 | solver->parameters.alpha = RIL_DEFAULT_GRADIENT_STEP_SIZE; | 2648 | solver->parameters.alpha = RIL_DEFAULT_GRADIENT_STEP_SIZE; |
2641 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | 2649 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", |
2642 | "RIL_GRADIENT_STEP_SIZE", &f_tmp)) | 2650 | "RIL_GRADIENT_STEP_SIZE", &f_tmp)) |
2643 | { | ||
2644 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) | ||
2645 | { | 2651 | { |
2646 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | 2652 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) |
2647 | "RIL_GRADIENT_STEP_SIZE", f_tmp); | 2653 | { |
2648 | } | 2654 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), |
2649 | else | 2655 | "RIL_GRADIENT_STEP_SIZE", f_tmp); |
2650 | { | 2656 | } |
2651 | solver->parameters.alpha = f_tmp; | 2657 | else |
2652 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | 2658 | { |
2653 | "RIL_GRADIENT_STEP_SIZE", f_tmp); | 2659 | solver->parameters.alpha = f_tmp; |
2660 | LOG(GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2661 | "RIL_GRADIENT_STEP_SIZE", f_tmp); | ||
2662 | } | ||
2654 | } | 2663 | } |
2655 | } | ||
2656 | 2664 | ||
2657 | solver->parameters.lambda = RIL_DEFAULT_TRACE_DECAY; | 2665 | solver->parameters.lambda = RIL_DEFAULT_TRACE_DECAY; |
2658 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | 2666 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", |
2659 | "RIL_TRACE_DECAY", &f_tmp)) | 2667 | "RIL_TRACE_DECAY", &f_tmp)) |
2660 | { | ||
2661 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) | ||
2662 | { | ||
2663 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2664 | "RIL_TRACE_DECAY", f_tmp); | ||
2665 | } | ||
2666 | else | ||
2667 | { | 2668 | { |
2668 | solver->parameters.lambda = f_tmp; | 2669 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) |
2669 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | 2670 | { |
2670 | "RIL_TRACE_DECAY", f_tmp); | 2671 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), |
2672 | "RIL_TRACE_DECAY", f_tmp); | ||
2673 | } | ||
2674 | else | ||
2675 | { | ||
2676 | solver->parameters.lambda = f_tmp; | ||
2677 | LOG(GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2678 | "RIL_TRACE_DECAY", f_tmp); | ||
2679 | } | ||
2671 | } | 2680 | } |
2672 | } | ||
2673 | 2681 | ||
2674 | solver->parameters.epsilon_init = RIL_DEFAULT_EXPLORE_RATIO; | 2682 | solver->parameters.epsilon_init = RIL_DEFAULT_EXPLORE_RATIO; |
2675 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | 2683 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", |
2676 | "RIL_EXPLORE_RATIO", &f_tmp)) | 2684 | "RIL_EXPLORE_RATIO", &f_tmp)) |
2677 | { | ||
2678 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) | ||
2679 | { | ||
2680 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2681 | "RIL_EXPLORE_RATIO", f_tmp); | ||
2682 | } | ||
2683 | else | ||
2684 | { | 2685 | { |
2685 | solver->parameters.epsilon_init = f_tmp; | 2686 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) |
2686 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | 2687 | { |
2687 | "RIL_EXPLORE_RATIO", f_tmp); | 2688 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), |
2689 | "RIL_EXPLORE_RATIO", f_tmp); | ||
2690 | } | ||
2691 | else | ||
2692 | { | ||
2693 | solver->parameters.epsilon_init = f_tmp; | ||
2694 | LOG(GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2695 | "RIL_EXPLORE_RATIO", f_tmp); | ||
2696 | } | ||
2688 | } | 2697 | } |
2689 | } | ||
2690 | 2698 | ||
2691 | solver->parameters.epsilon_decay = RIL_DEFAULT_EXPLORE_DECAY; | 2699 | solver->parameters.epsilon_decay = RIL_DEFAULT_EXPLORE_DECAY; |
2692 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | 2700 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", |
2693 | "RIL_EXPLORE_DECAY", &f_tmp)) | 2701 | "RIL_EXPLORE_DECAY", &f_tmp)) |
2694 | { | ||
2695 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) | ||
2696 | { | 2702 | { |
2697 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | 2703 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) |
2698 | "RIL_EXPLORE_DECAY", f_tmp); | 2704 | { |
2699 | } | 2705 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), |
2700 | else | 2706 | "RIL_EXPLORE_DECAY", f_tmp); |
2701 | { | 2707 | } |
2702 | solver->parameters.epsilon_decay = f_tmp; | 2708 | else |
2703 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | 2709 | { |
2704 | "RIL_EXPLORE_DECAY", f_tmp); | 2710 | solver->parameters.epsilon_decay = f_tmp; |
2711 | LOG(GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2712 | "RIL_EXPLORE_DECAY", f_tmp); | ||
2713 | } | ||
2705 | } | 2714 | } |
2706 | } | ||
2707 | 2715 | ||
2708 | solver->parameters.temperature_init = RIL_DEFAULT_TEMPERATURE; | 2716 | solver->parameters.temperature_init = RIL_DEFAULT_TEMPERATURE; |
2709 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | 2717 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", |
2710 | "RIL_TEMPERATURE", &f_tmp)) | 2718 | "RIL_TEMPERATURE", &f_tmp)) |
2711 | { | ||
2712 | if (f_tmp <= 0.0) | ||
2713 | { | ||
2714 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2715 | "RIL_TEMPERATURE", f_tmp); | ||
2716 | } | ||
2717 | else | ||
2718 | { | 2719 | { |
2719 | solver->parameters.temperature_init = f_tmp; | 2720 | if (f_tmp <= 0.0) |
2720 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | 2721 | { |
2721 | "RIL_TEMPERATURE", f_tmp); | 2722 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), |
2723 | "RIL_TEMPERATURE", f_tmp); | ||
2724 | } | ||
2725 | else | ||
2726 | { | ||
2727 | solver->parameters.temperature_init = f_tmp; | ||
2728 | LOG(GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2729 | "RIL_TEMPERATURE", f_tmp); | ||
2730 | } | ||
2722 | } | 2731 | } |
2723 | } | ||
2724 | 2732 | ||
2725 | solver->parameters.temperature_decay = RIL_DEFAULT_TEMPERATURE_DECAY; | 2733 | solver->parameters.temperature_decay = RIL_DEFAULT_TEMPERATURE_DECAY; |
2726 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | 2734 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", |
2727 | "RIL_TEMPERATURE_DECAY", &f_tmp)) | 2735 | "RIL_TEMPERATURE_DECAY", &f_tmp)) |
2728 | { | ||
2729 | if ((f_tmp <= 0.0) || solver->parameters.temperature_decay > 1) | ||
2730 | { | 2736 | { |
2731 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | 2737 | if ((f_tmp <= 0.0) || solver->parameters.temperature_decay > 1) |
2732 | "RIL_TEMPERATURE_DECAY", f_tmp); | 2738 | { |
2739 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2740 | "RIL_TEMPERATURE_DECAY", f_tmp); | ||
2741 | } | ||
2742 | else | ||
2743 | { | ||
2744 | solver->parameters.temperature_decay = f_tmp; | ||
2745 | LOG(GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2746 | "RIL_TEMPERATURE_DECAY", f_tmp); | ||
2747 | } | ||
2733 | } | 2748 | } |
2734 | else | 2749 | |
2750 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, "ats", "RIL_SIMULATE", &solver->simulate)) | ||
2735 | { | 2751 | { |
2736 | solver->parameters.temperature_decay = f_tmp; | 2752 | solver->simulate = GNUNET_NO; |
2737 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2738 | "RIL_TEMPERATURE_DECAY", f_tmp); | ||
2739 | } | 2753 | } |
2740 | } | ||
2741 | |||
2742 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, "ats", "RIL_SIMULATE", &solver->simulate)) | ||
2743 | { | ||
2744 | solver->simulate = GNUNET_NO; | ||
2745 | } | ||
2746 | 2754 | ||
2747 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(env->cfg, "ats", "RIL_REPLACE_TRACES")) | 2755 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(env->cfg, "ats", "RIL_REPLACE_TRACES")) |
2748 | { | 2756 | { |
2749 | solver->parameters.eligibility_trace_mode = RIL_E_REPLACE; | 2757 | solver->parameters.eligibility_trace_mode = RIL_E_REPLACE; |
2750 | } | 2758 | } |
2751 | else | 2759 | else |
2752 | { | 2760 | { |
2753 | solver->parameters.eligibility_trace_mode = RIL_E_ACCUMULATE; | 2761 | solver->parameters.eligibility_trace_mode = RIL_E_ACCUMULATE; |
2754 | } | 2762 | } |
2755 | 2763 | ||
2756 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_SOCIAL_WELFARE", &string)) | 2764 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(env->cfg, "ats", "RIL_SOCIAL_WELFARE", &string)) |
2757 | { | 2765 | { |
2758 | solver->parameters.social_welfare = !strcmp (string, "NASH") ? RIL_WELFARE_NASH : RIL_WELFARE_EGALITARIAN; | 2766 | solver->parameters.social_welfare = !strcmp(string, "NASH") ? RIL_WELFARE_NASH : RIL_WELFARE_EGALITARIAN; |
2759 | GNUNET_free (string); | 2767 | GNUNET_free(string); |
2760 | } | 2768 | } |
2761 | else | 2769 | else |
2762 | { | 2770 | { |
2763 | solver->parameters.social_welfare = RIL_DEFAULT_WELFARE; | 2771 | solver->parameters.social_welfare = RIL_DEFAULT_WELFARE; |
2764 | } | 2772 | } |
2765 | 2773 | ||
2766 | solver->env = env; | 2774 | solver->env = env; |
2767 | sf.cls = solver; | 2775 | sf.cls = solver; |
@@ -2776,22 +2784,22 @@ libgnunet_plugin_ats_ril_init (void *cls) | |||
2776 | sf.s_bulk_stop = &GAS_ril_bulk_stop; | 2784 | sf.s_bulk_stop = &GAS_ril_bulk_stop; |
2777 | 2785 | ||
2778 | solver->networks_count = env->network_count; | 2786 | solver->networks_count = env->network_count; |
2779 | solver->network_entries = GNUNET_malloc (env->network_count * sizeof (struct RIL_Scope)); | 2787 | solver->network_entries = GNUNET_malloc(env->network_count * sizeof(struct RIL_Scope)); |
2780 | solver->step_count = 0; | 2788 | solver->step_count = 0; |
2781 | solver->done = GNUNET_NO; | 2789 | solver->done = GNUNET_NO; |
2782 | 2790 | ||
2783 | for (c = 0; c < env->network_count; c++) | 2791 | for (c = 0; c < env->network_count; c++) |
2784 | { | 2792 | { |
2785 | cur = &solver->network_entries[c]; | 2793 | cur = &solver->network_entries[c]; |
2786 | cur->type = c; | 2794 | cur->type = c; |
2787 | cur->bw_in_available = env->in_quota[c]; | 2795 | cur->bw_in_available = env->in_quota[c]; |
2788 | cur->bw_out_available = env->out_quota[c]; | 2796 | cur->bw_out_available = env->out_quota[c]; |
2789 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2797 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2790 | "init() Quotas for %s network: IN %llu - OUT %llu\n", | 2798 | "init() Quotas for %s network: IN %llu - OUT %llu\n", |
2791 | GNUNET_NT_to_string(cur->type), | 2799 | GNUNET_NT_to_string(cur->type), |
2792 | cur->bw_in_available/1024, | 2800 | cur->bw_in_available / 1024, |
2793 | cur->bw_out_available/1024); | 2801 | cur->bw_out_available / 1024); |
2794 | } | 2802 | } |
2795 | 2803 | ||
2796 | LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Parameters:\n"); | 2804 | LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Parameters:\n"); |
2797 | LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Algorithm = %s, alpha = %f, beta = %f, lambda = %f\n", | 2805 | LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Algorithm = %s, alpha = %f, beta = %f, lambda = %f\n", |
@@ -2816,7 +2824,7 @@ libgnunet_plugin_ats_ril_init (void *cls) | |||
2816 | * @param cls the solver handle | 2824 | * @param cls the solver handle |
2817 | */ | 2825 | */ |
2818 | void * | 2826 | void * |
2819 | libgnunet_plugin_ats_ril_done (void *cls) | 2827 | libgnunet_plugin_ats_ril_done(void *cls) |
2820 | { | 2828 | { |
2821 | struct GNUNET_ATS_SolverFunctions *sf = cls; | 2829 | struct GNUNET_ATS_SolverFunctions *sf = cls; |
2822 | struct GAS_RIL_Handle *s = sf->cls; | 2830 | struct GAS_RIL_Handle *s = sf->cls; |
@@ -2829,17 +2837,17 @@ libgnunet_plugin_ats_ril_done (void *cls) | |||
2829 | 2837 | ||
2830 | cur_agent = s->agents_head; | 2838 | cur_agent = s->agents_head; |
2831 | while (NULL != cur_agent) | 2839 | while (NULL != cur_agent) |
2832 | { | 2840 | { |
2833 | next_agent = cur_agent->next; | 2841 | next_agent = cur_agent->next; |
2834 | GNUNET_CONTAINER_DLL_remove(s->agents_head, s->agents_tail, cur_agent); | 2842 | GNUNET_CONTAINER_DLL_remove(s->agents_head, s->agents_tail, cur_agent); |
2835 | agent_die (s, cur_agent); | 2843 | agent_die(s, cur_agent); |
2836 | cur_agent = next_agent; | 2844 | cur_agent = next_agent; |
2837 | } | 2845 | } |
2838 | 2846 | ||
2839 | if (NULL != s->step_next_task_id) | 2847 | if (NULL != s->step_next_task_id) |
2840 | { | 2848 | { |
2841 | GNUNET_SCHEDULER_cancel (s->step_next_task_id); | 2849 | GNUNET_SCHEDULER_cancel(s->step_next_task_id); |
2842 | } | 2850 | } |
2843 | GNUNET_free(s->network_entries); | 2851 | GNUNET_free(s->network_entries); |
2844 | GNUNET_free(s); | 2852 | GNUNET_free(s); |
2845 | 2853 | ||