diff options
author | Fabian Oehlmann <oehlmann@in.tum.de> | 2013-10-18 12:45:47 +0000 |
---|---|---|
committer | Fabian Oehlmann <oehlmann@in.tum.de> | 2013-10-18 12:45:47 +0000 |
commit | f370ea1429d3caa2d31a0ed146ba403cbb3a090f (patch) | |
tree | 7f8ac1b98c37a334dc7bd27d3c1ad5af03d92f44 /src | |
parent | 18642e4b759b39aa644d8a232c31c2a755d707bb (diff) | |
download | gnunet-f370ea1429d3caa2d31a0ed146ba403cbb3a090f.tar.gz gnunet-f370ea1429d3caa2d31a0ed146ba403cbb3a090f.zip |
split reward calculation
Diffstat (limited to 'src')
-rwxr-xr-x | src/ats/libgnunet_plugin_ats_ril.c | 99 |
1 files changed, 68 insertions, 31 deletions
diff --git a/src/ats/libgnunet_plugin_ats_ril.c b/src/ats/libgnunet_plugin_ats_ril.c index 2a35007f3..641ed5266 100755 --- a/src/ats/libgnunet_plugin_ats_ril.c +++ b/src/ats/libgnunet_plugin_ats_ril.c | |||
@@ -151,7 +151,7 @@ struct RIL_Peer_Agent | |||
151 | /** | 151 | /** |
152 | * Whether the agent is active or not | 152 | * Whether the agent is active or not |
153 | */ | 153 | */ |
154 | int active; | 154 | int is_active; |
155 | 155 | ||
156 | /** | 156 | /** |
157 | * Number of performed time-steps | 157 | * Number of performed time-steps |
@@ -534,8 +534,8 @@ envi_set_active_suggestion (struct GAS_RIL_Handle *solver, | |||
534 | } | 534 | } |
535 | if (NULL != new_address) | 535 | if (NULL != new_address) |
536 | { | 536 | { |
537 | LOG(GNUNET_ERROR_TYPE_DEBUG, "set address active: %s\n", agent->active ? "yes" : "no"); | 537 | LOG(GNUNET_ERROR_TYPE_DEBUG, "set address active: %s\n", agent->is_active ? "yes" : "no"); |
538 | new_address->active = agent->active; | 538 | new_address->active = agent->is_active; |
539 | new_address->assigned_bw_in.value__ = htonl (agent->bw_in); | 539 | new_address->assigned_bw_in.value__ = htonl (agent->bw_in); |
540 | new_address->assigned_bw_out.value__ = htonl (agent->bw_out); | 540 | new_address->assigned_bw_out.value__ = htonl (agent->bw_out); |
541 | } | 541 | } |
@@ -545,9 +545,9 @@ envi_set_active_suggestion (struct GAS_RIL_Handle *solver, | |||
545 | if (new_address) | 545 | if (new_address) |
546 | { | 546 | { |
547 | //activity change | 547 | //activity change |
548 | if (new_address->active != agent->active) | 548 | if (new_address->active != agent->is_active) |
549 | { | 549 | { |
550 | new_address->active = agent->active; | 550 | new_address->active = agent->is_active; |
551 | } | 551 | } |
552 | 552 | ||
553 | //bw change | 553 | //bw change |
@@ -565,7 +565,7 @@ envi_set_active_suggestion (struct GAS_RIL_Handle *solver, | |||
565 | } | 565 | } |
566 | } | 566 | } |
567 | 567 | ||
568 | if (notify && agent->active && (GNUNET_NO == silent)) | 568 | if (notify && agent->is_active && (GNUNET_NO == silent)) |
569 | { | 569 | { |
570 | if (new_address) | 570 | if (new_address) |
571 | { | 571 | { |
@@ -686,46 +686,83 @@ ril_find_property_index (uint32_t type) | |||
686 | return GNUNET_SYSERR; | 686 | return GNUNET_SYSERR; |
687 | } | 687 | } |
688 | 688 | ||
689 | /** | ||
690 | * Gets the reward for the last performed step | ||
691 | * | ||
692 | * @param solver solver handle | ||
693 | * @return the reward | ||
694 | */ | ||
695 | static double | 689 | static double |
696 | envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | 690 | envi_reward_global (struct GAS_RIL_Handle *solver) |
691 | { | ||
692 | int i; | ||
693 | unsigned int in_available = 0; | ||
694 | unsigned int out_available = 0; | ||
695 | unsigned int in_assigned = 0; | ||
696 | unsigned int out_assigned = 0; | ||
697 | double ratio_in; | ||
698 | double ratio_out; | ||
699 | |||
700 | for (i = 0; i < solver->networks_count; i++) | ||
701 | { | ||
702 | in_available += solver->network_entries[i].bw_in_available; | ||
703 | in_assigned += solver->network_entries[i].bw_in_assigned; | ||
704 | out_available += solver->network_entries[i].bw_out_available; | ||
705 | out_assigned += solver->network_entries[i].bw_out_assigned; | ||
706 | } | ||
707 | |||
708 | ratio_in = ((double) in_assigned) / ((double) in_available); | ||
709 | ratio_out = ((double) out_assigned) / ((double) out_available); | ||
710 | |||
711 | return ((ratio_in + ratio_out) * 0.5) + 1; | ||
712 | } | ||
713 | |||
714 | static double | ||
715 | envi_reward_local (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | ||
697 | { | 716 | { |
698 | /* | ||
699 | * - Match the preferences of the peer with the current assignment | ||
700 | * - Validity of the solution | ||
701 | */ | ||
702 | const double *preferences; | 717 | const double *preferences; |
703 | const double *properties; | 718 | const double *properties; |
719 | int prop_index; | ||
704 | double pref_match = 0; | 720 | double pref_match = 0; |
705 | double bw_norm; | 721 | double bw_norm; |
706 | struct RIL_Network *net; | ||
707 | int prop_index; | ||
708 | 722 | ||
709 | preferences = solver->plugin_envi->get_preferences (solver->plugin_envi->get_preference_cls, | 723 | preferences = solver->plugin_envi->get_preferences (solver->plugin_envi->get_preference_cls, |
710 | &agent->peer); | 724 | &agent->peer); |
711 | properties = solver->plugin_envi->get_property (solver->plugin_envi->get_property_cls, | 725 | properties = solver->plugin_envi->get_property (solver->plugin_envi->get_property_cls, |
712 | agent->address_inuse); | 726 | agent->address_inuse); |
727 | |||
728 | //preference matching from latency and bandwidth | ||
713 | prop_index = ril_find_property_index (GNUNET_ATS_QUALITY_NET_DELAY); | 729 | prop_index = ril_find_property_index (GNUNET_ATS_QUALITY_NET_DELAY); |
714 | pref_match += preferences[GNUNET_ATS_PREFERENCE_LATENCY] * (3 - properties[prop_index]); //invert property as we want to maximize for lower latencies | 730 | pref_match += 1 - (preferences[GNUNET_ATS_PREFERENCE_LATENCY] * (3 - properties[prop_index])); //invert property as we want to maximize for lower latencies |
715 | bw_norm = GNUNET_MAX(2, ((( | 731 | bw_norm = GNUNET_MAX(2, ((( |
716 | ((double) agent->bw_in / (double) ril_get_max_bw(agent, GNUNET_YES)) + | 732 | ((double) agent->bw_in / (double) ril_get_max_bw(agent, GNUNET_YES)) + |
717 | ((double) agent->bw_out / (double) ril_get_max_bw(agent, GNUNET_NO)) | 733 | ((double) agent->bw_out / (double) ril_get_max_bw(agent, GNUNET_NO)) |
718 | ) / 2 | 734 | ) / 2 |
719 | ) + 1)); | 735 | ) + 1)); |
720 | pref_match += preferences[GNUNET_ATS_PREFERENCE_BANDWIDTH] * bw_norm; | 736 | |
737 | pref_match += 1 - (preferences[GNUNET_ATS_PREFERENCE_BANDWIDTH] * bw_norm); | ||
738 | |||
739 | return pref_match * 0.5; | ||
740 | } | ||
741 | |||
742 | /** | ||
743 | * Gets the reward for the last performed step, which is calculated in equal | ||
744 | * parts from the local (the peer specific) and the global (for all peers | ||
745 | * identical) reward. | ||
746 | * | ||
747 | * @param solver solver handle | ||
748 | * @return the reward | ||
749 | */ | ||
750 | static double | ||
751 | envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | ||
752 | { | ||
753 | struct RIL_Network *net; | ||
754 | double reward = 0; | ||
721 | 755 | ||
756 | //punish overutilization | ||
722 | net = agent->address_inuse->solver_information; | 757 | net = agent->address_inuse->solver_information; |
723 | if ((net->bw_in_assigned > net->bw_in_available) || (net->bw_out_assigned > net->bw_out_available)) | 758 | if ((net->bw_in_assigned > net->bw_in_available) || (net->bw_out_assigned > net->bw_out_available)) |
724 | { | 759 | { |
725 | return -1; | 760 | return -1; |
726 | } | 761 | } |
727 | 762 | ||
728 | return pref_match; | 763 | reward += envi_reward_global (solver); |
764 | reward += envi_reward_local (solver, agent); | ||
765 | return reward * 0.5; | ||
729 | } | 766 | } |
730 | 767 | ||
731 | /** | 768 | /** |
@@ -1021,7 +1058,7 @@ ril_periodic_step (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1021 | 1058 | ||
1022 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) | 1059 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) |
1023 | { | 1060 | { |
1024 | if (cur->active && cur->address_inuse) | 1061 | if (cur->is_active && cur->address_inuse) |
1025 | { | 1062 | { |
1026 | agent_step (cur); | 1063 | agent_step (cur); |
1027 | } | 1064 | } |
@@ -1048,7 +1085,7 @@ agent_init (void *s, const struct GNUNET_PeerIdentity *peer) | |||
1048 | agent->envi = solver; | 1085 | agent->envi = solver; |
1049 | agent->peer = *peer; | 1086 | agent->peer = *peer; |
1050 | agent->step_count = 0; | 1087 | agent->step_count = 0; |
1051 | agent->active = GNUNET_NO; | 1088 | agent->is_active = GNUNET_NO; |
1052 | agent->n = RIL_ACTION_TYPE_NUM; | 1089 | agent->n = RIL_ACTION_TYPE_NUM; |
1053 | agent->m = solver->networks_count * RIL_FEATURES_NETWORK_COUNT; | 1090 | agent->m = solver->networks_count * RIL_FEATURES_NETWORK_COUNT; |
1054 | agent->W = (double **) GNUNET_malloc (sizeof (double *) * agent->n); | 1091 | agent->W = (double **) GNUNET_malloc (sizeof (double *) * agent->n); |
@@ -1754,7 +1791,7 @@ GAS_ril_get_preferred_address (void *solver, const struct GNUNET_PeerIdentity *p | |||
1754 | 1791 | ||
1755 | agent = ril_get_agent (s, peer, GNUNET_YES); | 1792 | agent = ril_get_agent (s, peer, GNUNET_YES); |
1756 | 1793 | ||
1757 | agent->active = GNUNET_YES; | 1794 | agent->is_active = GNUNET_YES; |
1758 | 1795 | ||
1759 | if (agent->address_inuse) | 1796 | if (agent->address_inuse) |
1760 | { | 1797 | { |
@@ -1804,13 +1841,13 @@ GAS_ril_stop_get_preferred_address (void *solver, const struct GNUNET_PeerIdenti | |||
1804 | GNUNET_break(0); | 1841 | GNUNET_break(0); |
1805 | return; | 1842 | return; |
1806 | } | 1843 | } |
1807 | if (GNUNET_NO == agent->active) | 1844 | if (GNUNET_NO == agent->is_active) |
1808 | { | 1845 | { |
1809 | GNUNET_break(0); | 1846 | GNUNET_break(0); |
1810 | return; | 1847 | return; |
1811 | } | 1848 | } |
1812 | 1849 | ||
1813 | agent->active = GNUNET_NO; | 1850 | agent->is_active = GNUNET_NO; |
1814 | if (agent->address_inuse) | 1851 | if (agent->address_inuse) |
1815 | { | 1852 | { |
1816 | net = agent->address_inuse->solver_information; | 1853 | net = agent->address_inuse->solver_information; |