aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorFabian Oehlmann <oehlmann@in.tum.de>2013-11-19 17:38:27 +0000
committerFabian Oehlmann <oehlmann@in.tum.de>2013-11-19 17:38:27 +0000
commit332160659373044ac0c2a15a799a55cf7d113ee9 (patch)
treeff6506c86b1931478397a779aab1d4274b262345 /src/ats
parent0f14ef81c789128be63bc3654bff1a6cb7df2953 (diff)
downloadgnunet-332160659373044ac0c2a15a799a55cf7d113ee9.tar.gz
gnunet-332160659373044ac0c2a15a799a55cf7d113ee9.zip
globalized networks state
Diffstat (limited to 'src/ats')
-rwxr-xr-xsrc/ats/libgnunet_plugin_ats_ril.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/ats/libgnunet_plugin_ats_ril.c b/src/ats/libgnunet_plugin_ats_ril.c
index 599241e34..cf8bb0ade 100755
--- a/src/ats/libgnunet_plugin_ats_ril.c
+++ b/src/ats/libgnunet_plugin_ats_ril.c
@@ -305,6 +305,11 @@ struct GAS_RIL_Handle
305 double discount_integrated; 305 double discount_integrated;
306 306
307 /** 307 /**
308 * State vector for networks for the current step
309 */
310 double *state_networks;
311
312 /**
308 * Lock for bulk operations 313 * Lock for bulk operations
309 */ 314 */
310 int bulk_lock; 315 int bulk_lock;
@@ -661,6 +666,22 @@ ril_network_get_assigned (struct GAS_RIL_Handle *solver, enum GNUNET_ATS_Network
661 return sum; 666 return sum;
662} 667}
663 668
669static void
670envi_state_networks (struct GAS_RIL_Handle *solver)
671{
672 int i;
673 struct RIL_Network net;
674
675 for (i = 0; i < solver->networks_count; i++)
676 {
677 net = solver->network_entries[i];
678 solver->state_networks[i * RIL_FEATURES_NETWORK_COUNT + 0] = (double) ril_network_get_assigned(solver, net.type, GNUNET_YES);
679 solver->state_networks[i * RIL_FEATURES_NETWORK_COUNT + 1] = (double) net.bw_in_available;
680 solver->state_networks[i * RIL_FEATURES_NETWORK_COUNT + 2] = (double) ril_network_get_assigned(solver, net.type, GNUNET_NO);
681 solver->state_networks[i * RIL_FEATURES_NETWORK_COUNT + 3] = (double) net.bw_out_available;
682 }
683}
684
664/** 685/**
665 * Allocates a state vector and fills it with the features present 686 * Allocates a state vector and fills it with the features present
666 * @param solver the solver handle 687 * @param solver the solver handle
@@ -672,18 +693,17 @@ envi_get_state (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
672{ 693{
673 int i; 694 int i;
674 int k; 695 int k;
675 struct RIL_Network net;
676 double *state = GNUNET_malloc (sizeof (double) * agent->m); 696 double *state = GNUNET_malloc (sizeof (double) * agent->m);
677 struct RIL_Address_Wrapped *cur_address; 697 struct RIL_Address_Wrapped *cur_address;
678 const double *properties; 698 const double *properties;
679 699
700 //copy global networks state
680 for (i = 0; i < solver->networks_count; i++) 701 for (i = 0; i < solver->networks_count; i++)
681 { 702 {
682 net = solver->network_entries[i]; 703 state[i * RIL_FEATURES_NETWORK_COUNT + 0] = solver->state_networks[i * RIL_FEATURES_NETWORK_COUNT + 0];
683 state[i * RIL_FEATURES_NETWORK_COUNT + 0] = (double) ril_network_get_assigned(solver, net.type, GNUNET_YES); 704 state[i * RIL_FEATURES_NETWORK_COUNT + 1] = solver->state_networks[i * RIL_FEATURES_NETWORK_COUNT + 1];
684 state[i * RIL_FEATURES_NETWORK_COUNT + 1] = (double) net.bw_in_available; 705 state[i * RIL_FEATURES_NETWORK_COUNT + 2] = solver->state_networks[i * RIL_FEATURES_NETWORK_COUNT + 2];
685 state[i * RIL_FEATURES_NETWORK_COUNT + 2] = (double) ril_network_get_assigned(solver, net.type, GNUNET_NO); 706 state[i * RIL_FEATURES_NETWORK_COUNT + 3] = solver->state_networks[i * RIL_FEATURES_NETWORK_COUNT + 3];
686 state[i * RIL_FEATURES_NETWORK_COUNT + 3] = (double) net.bw_out_available;
687 } 707 }
688 708
689 i = i * RIL_FEATURES_NETWORK_COUNT; //first address feature 709 i = i * RIL_FEATURES_NETWORK_COUNT; //first address feature
@@ -1292,6 +1312,9 @@ ril_step (struct GAS_RIL_Handle *solver)
1292 solver->discount_integrated = (1 - solver->discount_variable) 1312 solver->discount_integrated = (1 - solver->discount_variable)
1293 / ((double) solver->parameters.beta); 1313 / ((double) solver->parameters.beta);
1294 1314
1315 //calculate network state vector
1316 envi_state_networks(solver);
1317
1295 //trigger one step per active agent 1318 //trigger one step per active agent
1296 for (cur = solver->agents_head; NULL != cur; cur = cur->next) 1319 for (cur = solver->agents_head; NULL != cur; cur = cur->next)
1297 { 1320 {
@@ -1665,6 +1688,7 @@ libgnunet_plugin_ats_ril_init (void *cls)
1665 solver->networks_count = env->network_count; 1688 solver->networks_count = env->network_count;
1666 solver->network_entries = GNUNET_malloc (env->network_count * sizeof (struct RIL_Network)); 1689 solver->network_entries = GNUNET_malloc (env->network_count * sizeof (struct RIL_Network));
1667 solver->step_count = 0; 1690 solver->step_count = 0;
1691 solver->state_networks = GNUNET_malloc (solver->networks_count * RIL_FEATURES_NETWORK_COUNT * sizeof (double));
1668 1692
1669 for (c = 0; c < env->network_count; c++) 1693 for (c = 0; c < env->network_count; c++)
1670 { 1694 {
@@ -1710,6 +1734,7 @@ libgnunet_plugin_ats_ril_done (void *cls)
1710 GNUNET_SCHEDULER_cancel (s->step_next_task_id); 1734 GNUNET_SCHEDULER_cancel (s->step_next_task_id);
1711 } 1735 }
1712 GNUNET_free(s->network_entries); 1736 GNUNET_free(s->network_entries);
1737 GNUNET_free(s->state_networks);
1713 GNUNET_free(s); 1738 GNUNET_free(s);
1714 1739
1715 return NULL ; 1740 return NULL ;