aboutsummaryrefslogtreecommitdiff
path: root/src/ats/plugin_ats_ril.c
diff options
context:
space:
mode:
authorFabian Oehlmann <oehlmann@in.tum.de>2014-01-22 16:35:34 +0000
committerFabian Oehlmann <oehlmann@in.tum.de>2014-01-22 16:35:34 +0000
commit268c09f21fda66a4b2657007c1dfa47eb9eb9e4f (patch)
treefad4280c372ac02ffac302076e4f3767a30771dc /src/ats/plugin_ats_ril.c
parent0c7aa062cb988866f9d859a7c67836707cf1041c (diff)
downloadgnunet-268c09f21fda66a4b2657007c1dfa47eb9eb9e4f.tar.gz
gnunet-268c09f21fda66a4b2657007c1dfa47eb9eb9e4f.zip
reward function made differentiable
Diffstat (limited to 'src/ats/plugin_ats_ril.c')
-rwxr-xr-xsrc/ats/plugin_ats_ril.c65
1 files changed, 46 insertions, 19 deletions
diff --git a/src/ats/plugin_ats_ril.c b/src/ats/plugin_ats_ril.c
index 27628ec70..91f290afc 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 1024 * 250 //GNUNET_ATS_MaxBandwidth 32#define RIL_MAX_BW GNUNET_ATS_MaxBandwidth
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
@@ -511,7 +511,7 @@ agent_address_get_index (struct RIL_Peer_Agent *agent, struct ATS_Address *addre
511 * @return wrapped address 511 * @return wrapped address
512 */ 512 */
513static struct RIL_Address_Wrapped * 513static struct RIL_Address_Wrapped *
514agent_address_get (struct RIL_Peer_Agent *agent, struct ATS_Address *address) 514agent_address_get_wrapped (struct RIL_Peer_Agent *agent, struct ATS_Address *address)
515{ 515{
516 struct RIL_Address_Wrapped *cur; 516 struct RIL_Address_Wrapped *cur;
517 517
@@ -1006,21 +1006,40 @@ static double
1006envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) 1006envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
1007{ 1007{
1008 struct RIL_Scope *net; 1008 struct RIL_Scope *net;
1009 unsigned long long overutilization; 1009 unsigned long long over_max;
1010 unsigned long long over_in = 0; 1010 unsigned long long over_in = 0;
1011 unsigned long long over_out = 0; 1011 unsigned long long over_out = 0;
1012 double objective; 1012 double objective;
1013 double delta; 1013 double delta;
1014 double steady; 1014 double steady;
1015 double util_ratio_in;
1016 double util_ratio_out;
1017 double util_ratio_max;
1018 double sigmoid_x;
1019 double obj;
1020 double over;
1021 double obj_share;
1015 1022
1016 net = agent->address_inuse->solver_information; 1023 net = agent->address_inuse->solver_information;
1017 1024
1018 //TODO make sure in tests to have utilization property updated 1025 //TODO make sure in tests to have utilization property updated
1019 if (net->bw_in_assigned > net->bw_in_available) 1026 if (net->bw_in_utilized > net->bw_in_available)
1020 over_in = net->bw_in_assigned - net->bw_in_available; 1027 {
1021 if (net->bw_out_assigned > net->bw_out_available) 1028 over_in = net->bw_in_utilized - net->bw_in_available;
1022 over_out = net->bw_out_assigned - net->bw_out_available; 1029 if (RIL_ACTION_BW_IN_INC == agent->a_old)
1023 overutilization = GNUNET_MAX(over_in, over_out) / RIL_MIN_BW; 1030 {
1031 over_in *= 2;
1032 }
1033 }
1034 if (net->bw_out_utilized > net->bw_out_available)
1035 {
1036 over_out = net->bw_out_utilized - net->bw_out_available;
1037 if (RIL_ACTION_BW_OUT_INC == agent->a_old)
1038 {
1039 over_out *= 2;
1040 }
1041 }
1042 over_max = GNUNET_MAX (over_in , over_out) / RIL_MIN_BW;
1024 1043
1025 objective = (agent_get_utility (agent) + net->social_welfare) / 2; 1044 objective = (agent_get_utility (agent) + net->social_welfare) / 2;
1026 delta = objective - agent->objective_old; 1045 delta = objective - agent->objective_old;
@@ -1035,14 +1054,15 @@ envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
1035 1054
1036 steady = (RIL_ACTION_NOTHING == agent->a_old) ? agent->nop_bonus : 0; 1055 steady = (RIL_ACTION_NOTHING == agent->a_old) ? agent->nop_bonus : 0;
1037 1056
1038 if (0 != overutilization) 1057 util_ratio_in = (double) net->bw_in_utilized / (double) net->bw_in_available;
1039 { 1058 util_ratio_out = (double) net->bw_out_utilized / (double) net->bw_out_available;
1040 return -1.0 * (double) overutilization; 1059 util_ratio_max = GNUNET_MAX (util_ratio_in, util_ratio_out);
1041 } 1060 sigmoid_x = util_ratio_max - 1;
1042 else 1061 obj_share = 1 / (1 + exp(1 * sigmoid_x));
1043 { 1062
1044 return delta + steady; 1063 over = -1.0 * (double) over_max;
1045 } 1064 obj = delta + steady;
1065 return (obj_share * obj) + ((1 - obj_share) * over);
1046} 1066}
1047 1067
1048/** 1068/**
@@ -1781,11 +1801,17 @@ ril_step_schedule_next (struct GAS_RIL_Handle *solver)
1781 offset = (double) solver->parameters.step_time_min.rel_value_us; 1801 offset = (double) solver->parameters.step_time_min.rel_value_us;
1782 y = factor * pow (used_ratio, RIL_INTERVAL_EXPONENT) + offset; 1802 y = factor * pow (used_ratio, RIL_INTERVAL_EXPONENT) + offset;
1783 1803
1784 GNUNET_assert(y <= (double ) solver->parameters.step_time_max.rel_value_us); 1804 GNUNET_assert(y <= (double) solver->parameters.step_time_max.rel_value_us);
1785 GNUNET_assert(y >= (double ) solver->parameters.step_time_min.rel_value_us); 1805 GNUNET_assert(y >= (double) solver->parameters.step_time_min.rel_value_us);
1786 1806
1787 time_next = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, (unsigned long long) y); 1807 time_next = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, (unsigned long long) y);
1788 1808
1809 LOG (GNUNET_ERROR_TYPE_INFO, "ratio: %f, factor: %f, offset: %f, y: %f\n",
1810 used_ratio,
1811 factor,
1812 offset,
1813 y);
1814
1789 if (solver->simulate) 1815 if (solver->simulate)
1790 { 1816 {
1791 time_next = GNUNET_TIME_UNIT_ZERO; 1817 time_next = GNUNET_TIME_UNIT_ZERO;
@@ -1916,6 +1942,7 @@ agent_init (void *s, const struct GNUNET_PeerIdentity *peer)
1916 agent->s_old = GNUNET_malloc (sizeof (double) * agent->m); 1942 agent->s_old = GNUNET_malloc (sizeof (double) * agent->m);
1917 agent->address_inuse = NULL; 1943 agent->address_inuse = NULL;
1918 agent->objective_old = 0; 1944 agent->objective_old = 0;
1945 agent->nop_bonus = 0;
1919 1946
1920 return agent; 1947 return agent;
1921} 1948}
@@ -2444,7 +2471,7 @@ GAS_ril_address_delete (void *solver, struct ATS_Address *address, int session_o
2444 } 2471 }
2445 2472
2446 address_index = agent_address_get_index (agent, address); 2473 address_index = agent_address_get_index (agent, address);
2447 address_wrapped = agent_address_get (agent, address); 2474 address_wrapped = agent_address_get_wrapped (agent, address);
2448 2475
2449 if (NULL == address_wrapped) 2476 if (NULL == address_wrapped)
2450 { 2477 {