aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorFabian Oehlmann <oehlmann@in.tum.de>2013-11-18 15:04:09 +0000
committerFabian Oehlmann <oehlmann@in.tum.de>2013-11-18 15:04:09 +0000
commitd4c9e4621784624454b2d871cc66dc659929d986 (patch)
tree6aa0bf82216392ea9db20da434cb0bf3bcb308dc /src/ats
parent6171f40b8cb690ae18e0967628b42abd537f84ce (diff)
downloadgnunet-d4c9e4621784624454b2d871cc66dc659929d986.tar.gz
gnunet-d4c9e4621784624454b2d871cc66dc659929d986.zip
added utilization
Diffstat (limited to 'src/ats')
-rwxr-xr-xsrc/ats/libgnunet_plugin_ats_ril.c47
1 files changed, 32 insertions, 15 deletions
diff --git a/src/ats/libgnunet_plugin_ats_ril.c b/src/ats/libgnunet_plugin_ats_ril.c
index 7dcc29efd..22535413e 100755
--- a/src/ats/libgnunet_plugin_ats_ril.c
+++ b/src/ats/libgnunet_plugin_ats_ril.c
@@ -37,8 +37,8 @@
37#define RIL_DEFAULT_STEP_TIME_MAX GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 3000) 37#define RIL_DEFAULT_STEP_TIME_MAX GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 3000)
38#define RIL_DEFAULT_ALGORITHM RIL_ALGO_SARSA 38#define RIL_DEFAULT_ALGORITHM RIL_ALGO_SARSA
39#define RIL_DEFAULT_DISCOUNT_BETA 0.7 39#define RIL_DEFAULT_DISCOUNT_BETA 0.7
40#define RIL_DEFAULT_GRADIENT_STEP_SIZE 0.4 40#define RIL_DEFAULT_GRADIENT_STEP_SIZE 0.3
41#define RIL_DEFAULT_TRACE_DECAY 0.6 41#define RIL_DEFAULT_TRACE_DECAY 0.5
42#define RIL_DEFAULT_EXPLORE_RATIO 0.1 42#define RIL_DEFAULT_EXPLORE_RATIO 0.1
43 43
44/** 44/**
@@ -732,6 +732,23 @@ ril_find_property_index (uint32_t type)
732 return GNUNET_SYSERR; 732 return GNUNET_SYSERR;
733} 733}
734 734
735static int
736ril_get_atsi (struct ATS_Address *address, uint32_t type)
737{
738 int c1;
739 GNUNET_assert(NULL != address);
740
741 if ((NULL == address->atsi) || (0 == address->atsi_count))
742 return 0;
743
744 for (c1 = 0; c1 < address->atsi_count; c1++)
745 {
746 if (ntohl (address->atsi[c1].type) == type)
747 return ntohl (address->atsi[c1].value);
748 }
749 return 0;
750}
751
735static double 752static double
736envi_reward_global (struct GAS_RIL_Handle *solver) 753envi_reward_global (struct GAS_RIL_Handle *solver)
737{ 754{
@@ -754,37 +771,37 @@ envi_reward_global (struct GAS_RIL_Handle *solver)
754 ratio_in = ((double) in_assigned) / ((double) in_available); 771 ratio_in = ((double) in_assigned) / ((double) in_available);
755 ratio_out = ((double) out_assigned) / ((double) out_available); 772 ratio_out = ((double) out_assigned) / ((double) out_available);
756 773
757 return ((ratio_in + ratio_out) * 0.5) + 1; 774 return ((ratio_in + ratio_out) / 2) + 1;
758} 775}
759 776
760static double 777static double
761envi_reward_local (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) 778envi_reward_local (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
762{ 779{
763 //TODO! add utilization
764
765 const double *preferences; 780 const double *preferences;
766 const double *properties; 781 const double *properties;
767 int prop_index; 782 int prop_index;
768 double pref_match = 0; 783 double pref_match = 0;
769 double bw_norm; 784 double bw_norm;
785 double dl_norm;
770 786
771 preferences = solver->plugin_envi->get_preferences (solver->plugin_envi->get_preference_cls, 787 preferences = solver->plugin_envi->get_preferences (solver->plugin_envi->get_preference_cls,
772 &agent->peer); 788 &agent->peer);
773 properties = solver->plugin_envi->get_property (solver->plugin_envi->get_property_cls, 789 properties = solver->plugin_envi->get_property (solver->plugin_envi->get_property_cls,
774 agent->address_inuse); 790 agent->address_inuse);
775 791
776 //preference matching from latency and bandwidth 792 //preference matching from latency
777 prop_index = ril_find_property_index (GNUNET_ATS_QUALITY_NET_DELAY); 793 prop_index = ril_find_property_index (GNUNET_ATS_QUALITY_NET_DELAY);
778 pref_match += 1 - (preferences[GNUNET_ATS_PREFERENCE_LATENCY] * (3 - properties[prop_index])); //invert property as we want to maximize for lower latencies 794 dl_norm = 2 - properties[prop_index]; //invert property as we want to maximize for lower latencies
779 bw_norm = GNUNET_MAX(2, ((( 795
780 ((double) agent->bw_in / (double) ril_get_max_bw(agent, GNUNET_YES)) + 796 bw_norm = ((ril_get_atsi (agent->address_inuse, GNUNET_ATS_UTILIZATION_IN)
781 ((double) agent->bw_out / (double) ril_get_max_bw(agent, GNUNET_NO)) 797 / ril_get_max_bw (agent, GNUNET_YES))
782 ) / 2 798 + (ril_get_atsi (agent->address_inuse, GNUNET_ATS_UTILIZATION_OUT)
783 ) + 1)); 799 / ril_get_max_bw (agent, GNUNET_NO))) / 2;
784 800
785 pref_match += 1 - (preferences[GNUNET_ATS_PREFERENCE_BANDWIDTH] * bw_norm); 801 pref_match += (preferences[GNUNET_ATS_PREFERENCE_LATENCY] * dl_norm);
802 pref_match += (preferences[GNUNET_ATS_PREFERENCE_BANDWIDTH] * bw_norm);
786 803
787 return pref_match * 0.5; 804 return (pref_match / 4) +1;
788} 805}
789 806
790/** 807/**
@@ -807,7 +824,7 @@ envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
807 if ((net->bw_in_assigned > net->bw_in_available) 824 if ((net->bw_in_assigned > net->bw_in_available)
808 || (net->bw_out_assigned > net->bw_out_available)) 825 || (net->bw_out_assigned > net->bw_out_available))
809 { 826 {
810 return -1; 827 return 0;
811 } 828 }
812 829
813 reward += envi_reward_global (solver); 830 reward += envi_reward_global (solver);