summaryrefslogtreecommitdiff
path: root/src/ats/plugin_ats_ril.c
diff options
context:
space:
mode:
authorFabian Oehlmann <oehlmann@in.tum.de>2014-01-23 17:02:37 +0000
committerFabian Oehlmann <oehlmann@in.tum.de>2014-01-23 17:02:37 +0000
commitea54b7b85309be7d6e1faf0388509ce377f65adc (patch)
tree4dc698c90cb2328f8c7c132343d922d9b43a0c0e /src/ats/plugin_ats_ril.c
parent46430c183d3997aca16602c40ac8f0b4280d9966 (diff)
downloadgnunet-ea54b7b85309be7d6e1faf0388509ce377f65adc.tar.gz
gnunet-ea54b7b85309be7d6e1faf0388509ce377f65adc.zip
refactoring
Diffstat (limited to 'src/ats/plugin_ats_ril.c')
-rwxr-xr-xsrc/ats/plugin_ats_ril.c101
1 files changed, 68 insertions, 33 deletions
diff --git a/src/ats/plugin_ats_ril.c b/src/ats/plugin_ats_ril.c
index 91f290afc..944e4a5fe 100755
--- a/src/ats/plugin_ats_ril.c
+++ b/src/ats/plugin_ats_ril.c
@@ -29,7 +29,7 @@
29#define LOG(kind,...) GNUNET_log_from (kind, "ats-ril",__VA_ARGS__) 29#define LOG(kind,...) GNUNET_log_from (kind, "ats-ril",__VA_ARGS__)
30 30
31#define RIL_MIN_BW ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__) 31#define RIL_MIN_BW ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__)
32#define RIL_MAX_BW GNUNET_ATS_MaxBandwidth 32#define RIL_MAX_BW 1024 * 1000//GNUNET_ATS_MaxBandwidth TODO! revert
33 33
34#define RIL_ACTION_INVALID -1 34#define RIL_ACTION_INVALID -1
35#define RIL_INTERVAL_EXPONENT 10 35#define RIL_INTERVAL_EXPONENT 10
@@ -199,6 +199,17 @@ struct RIL_Address_Wrapped
199 * The address 199 * The address
200 */ 200 */
201 struct ATS_Address *address_naked; 201 struct ATS_Address *address_naked;
202
203 /**
204 * Last inbound bandwidth used
205 */
206 unsigned long long bw_in;
207
208 /**
209 * Last outbound bandwidth used
210 */
211 unsigned long long bw_out;
212
202}; 213};
203 214
204struct RIL_Peer_Agent 215struct RIL_Peer_Agent
@@ -984,41 +995,40 @@ ril_network_get_social_welfare (struct GAS_RIL_Handle *solver, struct RIL_Scope
984 { 995 {
985 if (cur->is_active && cur->address_inuse && (cur->address_inuse->solver_information == scope)) 996 if (cur->is_active && cur->address_inuse && (cur->address_inuse->solver_information == scope))
986 { 997 {
987 result *= agent_get_utility(cur); 998 result *= pow(agent_get_utility(cur), 1.0 / (double) scope->agent_count);
988 } 999 }
989 } 1000 }
990 return pow(result, 1.0 / (double) scope->agent_count); 1001 return result;
991 } 1002 }
992 GNUNET_assert(GNUNET_NO); 1003 GNUNET_assert(GNUNET_NO);
993 return 1; 1004 return 1;
994} 1005}
995 1006
996/**
997 * Gets the reward for the last performed step, which is calculated in equal
998 * parts from the local (the peer specific) and the global (for all peers
999 * identical) reward.
1000 *
1001 * @param solver the solver handle
1002 * @param agent the agent handle
1003 * @return the reward
1004 */
1005static double 1007static double
1006envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) 1008envi_penalty_share (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
1007{ 1009{
1008 struct RIL_Scope *net; 1010 struct RIL_Scope *net;
1009 unsigned long long over_max;
1010 unsigned long long over_in = 0;
1011 unsigned long long over_out = 0;
1012 double objective;
1013 double delta;
1014 double steady;
1015 double util_ratio_in; 1011 double util_ratio_in;
1016 double util_ratio_out; 1012 double util_ratio_out;
1017 double util_ratio_max; 1013 double util_ratio_max;
1018 double sigmoid_x; 1014 double sigmoid_x;
1019 double obj; 1015
1020 double over; 1016 net = agent->address_inuse->solver_information;
1021 double obj_share; 1017
1018 util_ratio_in = (double) net->bw_in_utilized / (double) net->bw_in_available;
1019 util_ratio_out = (double) net->bw_out_utilized / (double) net->bw_out_available;
1020 util_ratio_max = GNUNET_MAX (util_ratio_in, util_ratio_out);
1021 sigmoid_x = util_ratio_max - 1;
1022 return 1 - (1 / (1 + exp(5 * sigmoid_x)));
1023}
1024
1025static double
1026envi_get_penalty (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
1027{
1028 struct RIL_Scope *net;
1029 unsigned long long over_max;
1030 unsigned long long over_in = 0;
1031 unsigned long long over_out = 0;
1022 1032
1023 net = agent->address_inuse->solver_information; 1033 net = agent->address_inuse->solver_information;
1024 1034
@@ -1041,6 +1051,31 @@ envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
1041 } 1051 }
1042 over_max = GNUNET_MAX (over_in , over_out) / RIL_MIN_BW; 1052 over_max = GNUNET_MAX (over_in , over_out) / RIL_MIN_BW;
1043 1053
1054 return -1.0 * (double) over_max;
1055}
1056
1057/**
1058 * Gets the reward for the last performed step, which is calculated in equal
1059 * parts from the local (the peer specific) and the global (for all peers
1060 * identical) reward.
1061 *
1062 * @param solver the solver handle
1063 * @param agent the agent handle
1064 * @return the reward
1065 */
1066static double
1067envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
1068{
1069 struct RIL_Scope *net;
1070 double objective;
1071 double delta;
1072 double steady;
1073 double pen_share;
1074 double penalty;
1075 double reward;
1076
1077 net = agent->address_inuse->solver_information;
1078
1044 objective = (agent_get_utility (agent) + net->social_welfare) / 2; 1079 objective = (agent_get_utility (agent) + net->social_welfare) / 2;
1045 delta = objective - agent->objective_old; 1080 delta = objective - agent->objective_old;
1046 agent->objective_old = objective; 1081 agent->objective_old = objective;
@@ -1050,19 +1085,13 @@ envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
1050 agent->nop_bonus = delta * 0.5; 1085 agent->nop_bonus = delta * 0.5;
1051 } 1086 }
1052 1087
1053 LOG(GNUNET_ERROR_TYPE_DEBUG, "agent->nop_bonus: %f\n", agent->nop_bonus);
1054
1055 steady = (RIL_ACTION_NOTHING == agent->a_old) ? agent->nop_bonus : 0; 1088 steady = (RIL_ACTION_NOTHING == agent->a_old) ? agent->nop_bonus : 0;
1056 1089
1057 util_ratio_in = (double) net->bw_in_utilized / (double) net->bw_in_available; 1090 pen_share = envi_penalty_share(solver, agent);
1058 util_ratio_out = (double) net->bw_out_utilized / (double) net->bw_out_available; 1091 penalty = envi_get_penalty(solver, agent);
1059 util_ratio_max = GNUNET_MAX (util_ratio_in, util_ratio_out);
1060 sigmoid_x = util_ratio_max - 1;
1061 obj_share = 1 / (1 + exp(1 * sigmoid_x));
1062 1092
1063 over = -1.0 * (double) over_max; 1093 reward = delta + steady;
1064 obj = delta + steady; 1094 return ((1 - pen_share) * reward) + (pen_share * penalty);
1065 return (obj_share * obj) + ((1 - obj_share) * over);
1066} 1095}
1067 1096
1068/** 1097/**
@@ -1209,11 +1238,15 @@ envi_action_address_switch (struct GAS_RIL_Handle *solver,
1209 struct RIL_Address_Wrapped *cur; 1238 struct RIL_Address_Wrapped *cur;
1210 int i = 0; 1239 int i = 0;
1211 1240
1241 cur = agent_address_get_wrapped(agent, agent->address_inuse);
1242 cur->bw_in = agent->bw_in;
1243 cur->bw_out = agent->bw_out;
1244
1212 for (cur = agent->addresses_head; NULL != cur; cur = cur->next) 1245 for (cur = agent->addresses_head; NULL != cur; cur = cur->next)
1213 { 1246 {
1214 if (i == address_index) 1247 if (i == address_index)
1215 { 1248 {
1216 envi_set_active_suggestion (solver, agent, cur->address_naked, agent->bw_in, agent->bw_out, 1249 envi_set_active_suggestion (solver, agent, cur->address_naked, cur->bw_in, cur->bw_out,
1217 GNUNET_NO); 1250 GNUNET_NO);
1218 return; 1251 return;
1219 } 1252 }
@@ -2392,6 +2425,8 @@ GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network
2392 //add address 2425 //add address
2393 address_wrapped = GNUNET_new (struct RIL_Address_Wrapped); 2426 address_wrapped = GNUNET_new (struct RIL_Address_Wrapped);
2394 address_wrapped->address_naked = address; 2427 address_wrapped->address_naked = address;
2428 address_wrapped->bw_in = RIL_MIN_BW;
2429 address_wrapped->bw_out = RIL_MIN_BW;
2395 GNUNET_CONTAINER_DLL_insert_tail(agent->addresses_head, agent->addresses_tail, address_wrapped); 2430 GNUNET_CONTAINER_DLL_insert_tail(agent->addresses_head, agent->addresses_tail, address_wrapped);
2396 2431
2397 //increase size of W 2432 //increase size of W