aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorFabian Oehlmann <oehlmann@in.tum.de>2013-11-20 16:56:06 +0000
committerFabian Oehlmann <oehlmann@in.tum.de>2013-11-20 16:56:06 +0000
commit5e551fe9e4d182dc6c699d43a30d37f3b6f3a2de (patch)
treec2bbb8f9777dae98676812286ea95b3b10af4dc5 /src/ats
parent225260a0a885e09a417395a5c9de7b6da549f290 (diff)
downloadgnunet-5e551fe9e4d182dc6c699d43a30d37f3b6f3a2de.tar.gz
gnunet-5e551fe9e4d182dc6c699d43a30d37f3b6f3a2de.zip
- variables renamed
- no suggestion if not at least min_bw bandwidth is theoretically available
Diffstat (limited to 'src/ats')
-rwxr-xr-xsrc/ats/libgnunet_plugin_ats_ril.c167
1 files changed, 106 insertions, 61 deletions
diff --git a/src/ats/libgnunet_plugin_ats_ril.c b/src/ats/libgnunet_plugin_ats_ril.c
index 336efede1..6e7ef45e9 100755
--- a/src/ats/libgnunet_plugin_ats_ril.c
+++ b/src/ats/libgnunet_plugin_ats_ril.c
@@ -298,22 +298,22 @@ struct GAS_RIL_Handle
298 /** 298 /**
299 * Whether a step is already scheduled 299 * Whether a step is already scheduled
300 */ 300 */
301 int task_pending; 301 int step_task_pending;
302 302
303 /** 303 /**
304 * Variable discount factor, dependent on time between steps 304 * Variable discount factor, dependent on time between steps
305 */ 305 */
306 double discount_variable; 306 double global_discount_variable;
307 307
308 /** 308 /**
309 * Integrated variable discount factor, dependent on time between steps 309 * Integrated variable discount factor, dependent on time between steps
310 */ 310 */
311 double discount_integrated; 311 double global_discount_integrated;
312 312
313 /** 313 /**
314 * State vector for networks for the current step 314 * State vector for networks for the current step
315 */ 315 */
316 double *state_networks; 316 double *global_state_networks;
317 317
318 /** 318 /**
319 * Lock for bulk operations 319 * Lock for bulk operations
@@ -504,8 +504,8 @@ agent_update_weights (struct RIL_Peer_Agent *agent, double reward, double *s_nex
504 double delta; 504 double delta;
505 double *theta = agent->W[agent->a_old]; 505 double *theta = agent->W[agent->a_old];
506 506
507 delta = agent->envi->discount_integrated * reward; //reward 507 delta = agent->envi->global_discount_integrated * reward; //reward
508 delta += agent->envi->discount_variable * agent_estimate_q (agent, s_next, a_prime); //discounted future value 508 delta += agent->envi->global_discount_variable * agent_estimate_q (agent, s_next, a_prime); //discounted future value
509 delta -= agent_estimate_q (agent, agent->s_old, agent->a_old); //one step 509 delta -= agent_estimate_q (agent, agent->s_old, agent->a_old); //one step
510 for (i = 0; i < agent->m; i++) 510 for (i = 0; i < agent->m; i++)
511 { 511 {
@@ -540,7 +540,7 @@ agent_modify_eligibility (struct RIL_Peer_Agent *agent, enum RIL_E_Modification
540 e[i] = 1; 540 e[i] = 1;
541 break; 541 break;
542 case RIL_E_SET: 542 case RIL_E_SET:
543 e[i] *= agent->envi->discount_variable * agent->envi->parameters.lambda; 543 e[i] *= agent->envi->global_discount_variable * agent->envi->parameters.lambda;
544 break; 544 break;
545 case RIL_E_ZERO: 545 case RIL_E_ZERO:
546 e[i] = 0; 546 e[i] = 0;
@@ -681,10 +681,10 @@ envi_state_networks (struct GAS_RIL_Handle *solver)
681 for (i = 0; i < solver->networks_count; i++) 681 for (i = 0; i < solver->networks_count; i++)
682 { 682 {
683 net = solver->network_entries[i]; 683 net = solver->network_entries[i];
684 solver->state_networks[i * RIL_FEATURES_NETWORK_COUNT + 0] = (double) ril_network_get_assigned(solver, net.type, GNUNET_YES); 684 solver->global_state_networks[i * RIL_FEATURES_NETWORK_COUNT + 0] = (double) ril_network_get_assigned(solver, net.type, GNUNET_YES);
685 solver->state_networks[i * RIL_FEATURES_NETWORK_COUNT + 1] = (double) net.bw_in_available; 685 solver->global_state_networks[i * RIL_FEATURES_NETWORK_COUNT + 1] = (double) net.bw_in_available;
686 solver->state_networks[i * RIL_FEATURES_NETWORK_COUNT + 2] = (double) ril_network_get_assigned(solver, net.type, GNUNET_NO); 686 solver->global_state_networks[i * RIL_FEATURES_NETWORK_COUNT + 2] = (double) ril_network_get_assigned(solver, net.type, GNUNET_NO);
687 solver->state_networks[i * RIL_FEATURES_NETWORK_COUNT + 3] = (double) net.bw_out_available; 687 solver->global_state_networks[i * RIL_FEATURES_NETWORK_COUNT + 3] = (double) net.bw_out_available;
688 } 688 }
689} 689}
690 690
@@ -707,10 +707,10 @@ envi_get_state (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
707 //copy global networks state 707 //copy global networks state
708 for (i = 0; i < solver->networks_count; i++) 708 for (i = 0; i < solver->networks_count; i++)
709 { 709 {
710 state[i * RIL_FEATURES_NETWORK_COUNT + 0] = solver->state_networks[i * RIL_FEATURES_NETWORK_COUNT + 0]; 710 state[i * RIL_FEATURES_NETWORK_COUNT + 0] = solver->global_state_networks[i * RIL_FEATURES_NETWORK_COUNT + 0];
711 state[i * RIL_FEATURES_NETWORK_COUNT + 1] = solver->state_networks[i * RIL_FEATURES_NETWORK_COUNT + 1]; 711 state[i * RIL_FEATURES_NETWORK_COUNT + 1] = solver->global_state_networks[i * RIL_FEATURES_NETWORK_COUNT + 1];
712 state[i * RIL_FEATURES_NETWORK_COUNT + 2] = solver->state_networks[i * RIL_FEATURES_NETWORK_COUNT + 2]; 712 state[i * RIL_FEATURES_NETWORK_COUNT + 2] = solver->global_state_networks[i * RIL_FEATURES_NETWORK_COUNT + 2];
713 state[i * RIL_FEATURES_NETWORK_COUNT + 3] = solver->state_networks[i * RIL_FEATURES_NETWORK_COUNT + 3]; 713 state[i * RIL_FEATURES_NETWORK_COUNT + 3] = solver->global_state_networks[i * RIL_FEATURES_NETWORK_COUNT + 3];
714 } 714 }
715 715
716 //get peer features 716 //get peer features
@@ -1212,7 +1212,7 @@ ril_step_scheduler_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *t
1212{ 1212{
1213 struct GAS_RIL_Handle *solver = cls; 1213 struct GAS_RIL_Handle *solver = cls;
1214 1214
1215 solver->task_pending = GNUNET_NO; 1215 solver->step_task_pending = GNUNET_NO;
1216 ril_step (solver); 1216 ril_step (solver);
1217} 1217}
1218 1218
@@ -1249,6 +1249,72 @@ ril_get_used_resource_ratio (struct GAS_RIL_Handle *solver)
1249} 1249}
1250 1250
1251/** 1251/**
1252 * Lookup network struct by type
1253 *
1254 * @param s the solver handle
1255 * @param type the network type
1256 * @return the network struct
1257 */
1258static struct RIL_Network *
1259ril_get_network (struct GAS_RIL_Handle *s, uint32_t type)
1260{
1261 int i;
1262
1263 for (i = 0; i < s->networks_count; i++)
1264 {
1265 if (s->network_entries[i].type == type)
1266 {
1267 return &s->network_entries[i];
1268 }
1269 }
1270 return NULL ;
1271}
1272
1273static int
1274ril_network_is_not_full (struct GAS_RIL_Handle *solver, enum GNUNET_ATS_Network_Type network)
1275{
1276 struct RIL_Network *net;
1277 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
1278 struct RIL_Peer_Agent *agent;
1279 unsigned long long address_count = 0;
1280
1281 for (agent = solver->agents_head; NULL != agent; agent = agent->next)
1282 {
1283 if (agent->address_inuse && agent->is_active)
1284 {
1285 net = agent->address_inuse->solver_information;
1286 if (net->type == network)
1287 {
1288 address_count++;
1289 }
1290 }
1291 }
1292
1293 net = ril_get_network (solver, network);
1294 return (net->bw_in_available > min_bw * address_count) && (net->bw_out_available > min_bw * address_count);
1295}
1296
1297static void
1298ril_try_unblock_agent (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int silent)
1299{
1300 struct RIL_Address_Wrapped *addr_wrap;
1301 struct RIL_Network *net;
1302 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
1303
1304 for (addr_wrap = agent->addresses_head; NULL != addr_wrap; addr_wrap = addr_wrap->next)
1305 {
1306 net = addr_wrap->address_naked->solver_information;
1307 if (ril_network_is_not_full(solver, net->type))
1308 {
1309 if (NULL == agent->address_inuse)
1310 envi_set_active_suggestion (solver, agent, addr_wrap->address_naked, min_bw, min_bw, silent);
1311 return;
1312 }
1313 }
1314 agent->address_inuse = NULL;
1315}
1316
1317/**
1252 * Schedules the next global step in an adaptive way. The more resources are 1318 * Schedules the next global step in an adaptive way. The more resources are
1253 * left, the earlier the next step is scheduled. This serves the reactivity of 1319 * left, the earlier the next step is scheduled. This serves the reactivity of
1254 * the solver to changed inputs. 1320 * the solver to changed inputs.
@@ -1264,7 +1330,7 @@ ril_step_schedule_next (struct GAS_RIL_Handle *solver)
1264 double offset; 1330 double offset;
1265 struct GNUNET_TIME_Relative time_next; 1331 struct GNUNET_TIME_Relative time_next;
1266 1332
1267 if (solver->task_pending) 1333 if (solver->step_task_pending)
1268 { 1334 {
1269 GNUNET_SCHEDULER_cancel (solver->step_next_task_id); 1335 GNUNET_SCHEDULER_cancel (solver->step_next_task_id);
1270 } 1336 }
@@ -1287,7 +1353,7 @@ ril_step_schedule_next (struct GAS_RIL_Handle *solver)
1287 1353
1288 solver->step_next_task_id = GNUNET_SCHEDULER_add_delayed (time_next, &ril_step_scheduler_task, 1354 solver->step_next_task_id = GNUNET_SCHEDULER_add_delayed (time_next, &ril_step_scheduler_task,
1289 solver); 1355 solver);
1290 solver->task_pending = GNUNET_YES; 1356 solver->step_task_pending = GNUNET_YES;
1291} 1357}
1292 1358
1293/** 1359/**
@@ -1325,8 +1391,8 @@ ril_step (struct GAS_RIL_Handle *solver)
1325 solver->step_time_last = time_now; 1391 solver->step_time_last = time_now;
1326 1392
1327 //calculate reward discounts (once per step for all agents) 1393 //calculate reward discounts (once per step for all agents)
1328 solver->discount_variable = pow (M_E, ((-1.) * ((double) solver->parameters.beta) * tau)); 1394 solver->global_discount_variable = pow (M_E, ((-1.) * ((double) solver->parameters.beta) * tau));
1329 solver->discount_integrated = (1 - solver->discount_variable) 1395 solver->global_discount_integrated = (1 - solver->global_discount_variable)
1330 / ((double) solver->parameters.beta); 1396 / ((double) solver->parameters.beta);
1331 1397
1332 //calculate network state vector 1398 //calculate network state vector
@@ -1335,9 +1401,16 @@ ril_step (struct GAS_RIL_Handle *solver)
1335 //trigger one step per active agent 1401 //trigger one step per active agent
1336 for (cur = solver->agents_head; NULL != cur; cur = cur->next) 1402 for (cur = solver->agents_head; NULL != cur; cur = cur->next)
1337 { 1403 {
1338 if (cur->is_active && cur->address_inuse) 1404 if (cur->is_active)
1339 { 1405 {
1340 agent_step (cur); 1406 if (NULL == cur->address_inuse)
1407 {
1408 ril_try_unblock_agent(solver, cur, GNUNET_NO);
1409 }
1410 if (cur->address_inuse)
1411 {
1412 agent_step (cur);
1413 }
1341 } 1414 }
1342 } 1415 }
1343 1416
@@ -1431,8 +1504,6 @@ agent_init (void *s, const struct GNUNET_PeerIdentity *peer)
1431 agent->e = (double *) GNUNET_malloc (sizeof (double) * agent->m); 1504 agent->e = (double *) GNUNET_malloc (sizeof (double) * agent->m);
1432 agent_modify_eligibility (agent, RIL_E_ZERO); 1505 agent_modify_eligibility (agent, RIL_E_ZERO);
1433 1506
1434 GNUNET_CONTAINER_DLL_insert_tail(solver->agents_head, solver->agents_tail, agent);
1435
1436 return agent; 1507 return agent;
1437} 1508}
1438 1509
@@ -1480,29 +1551,9 @@ ril_get_agent (struct GAS_RIL_Handle *solver, const struct GNUNET_PeerIdentity *
1480 1551
1481 if (create) 1552 if (create)
1482 { 1553 {
1483 return agent_init (solver, peer); 1554 cur = agent_init (solver, peer);
1484 } 1555 GNUNET_CONTAINER_DLL_insert_tail(solver->agents_head, solver->agents_tail, cur);
1485 return NULL ; 1556 return cur;
1486}
1487
1488/**
1489 * Lookup network struct by type
1490 *
1491 * @param s the solver handle
1492 * @param type the network type
1493 * @return the network struct
1494 */
1495static struct RIL_Network *
1496ril_get_network (struct GAS_RIL_Handle *s, uint32_t type)
1497{
1498 int i;
1499
1500 for (i = 0; i < s->networks_count; i++)
1501 {
1502 if (s->network_entries[i].type == type)
1503 {
1504 return &s->network_entries[i];
1505 }
1506 } 1557 }
1507 return NULL ; 1558 return NULL ;
1508} 1559}
@@ -1522,9 +1573,7 @@ ril_network_is_active (struct GAS_RIL_Handle *solver, enum GNUNET_ATS_Network_Ty
1522 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); 1573 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
1523 1574
1524 net = ril_get_network (solver, network); 1575 net = ril_get_network (solver, network);
1525 if (net->bw_out_available < min_bw) 1576 return net->bw_out_available >= min_bw;
1526 return GNUNET_NO;
1527 return GNUNET_YES;
1528} 1577}
1529 1578
1530/** 1579/**
@@ -1712,7 +1761,7 @@ libgnunet_plugin_ats_ril_init (void *cls)
1712 solver->networks_count = env->network_count; 1761 solver->networks_count = env->network_count;
1713 solver->network_entries = GNUNET_malloc (env->network_count * sizeof (struct RIL_Network)); 1762 solver->network_entries = GNUNET_malloc (env->network_count * sizeof (struct RIL_Network));
1714 solver->step_count = 0; 1763 solver->step_count = 0;
1715 solver->state_networks = GNUNET_malloc (solver->networks_count * RIL_FEATURES_NETWORK_COUNT * sizeof (double)); 1764 solver->global_state_networks = GNUNET_malloc (solver->networks_count * RIL_FEATURES_NETWORK_COUNT * sizeof (double));
1716 1765
1717 for (c = 0; c < env->network_count; c++) 1766 for (c = 0; c < env->network_count; c++)
1718 { 1767 {
@@ -1725,7 +1774,7 @@ libgnunet_plugin_ats_ril_init (void *cls)
1725 solver->step_next_task_id = GNUNET_SCHEDULER_add_delayed ( 1774 solver->step_next_task_id = GNUNET_SCHEDULER_add_delayed (
1726 GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_get_millisecond_ (), 1000), 1775 GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_get_millisecond_ (), 1000),
1727 &ril_step_scheduler_task, solver); 1776 &ril_step_scheduler_task, solver);
1728 solver->task_pending = GNUNET_YES; 1777 solver->step_task_pending = GNUNET_YES;
1729 1778
1730 return solver; 1779 return solver;
1731} 1780}
@@ -1753,12 +1802,12 @@ libgnunet_plugin_ats_ril_done (void *cls)
1753 cur_agent = next_agent; 1802 cur_agent = next_agent;
1754 } 1803 }
1755 1804
1756 if (s->task_pending) 1805 if (s->step_task_pending)
1757 { 1806 {
1758 GNUNET_SCHEDULER_cancel (s->step_next_task_id); 1807 GNUNET_SCHEDULER_cancel (s->step_next_task_id);
1759 } 1808 }
1760 GNUNET_free(s->network_entries); 1809 GNUNET_free(s->network_entries);
1761 GNUNET_free(s->state_networks); 1810 GNUNET_free(s->global_state_networks);
1762 GNUNET_free(s); 1811 GNUNET_free(s);
1763 1812
1764 return NULL ; 1813 return NULL ;
@@ -1786,7 +1835,6 @@ GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network
1786 unsigned int n_old; 1835 unsigned int n_old;
1787 int i; 1836 int i;
1788 unsigned int zero; 1837 unsigned int zero;
1789 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
1790 1838
1791 LOG (GNUNET_ERROR_TYPE_DEBUG, "API_address_add()\n"); 1839 LOG (GNUNET_ERROR_TYPE_DEBUG, "API_address_add()\n");
1792 1840
@@ -1836,10 +1884,7 @@ GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network
1836 agent->m = m_old; 1884 agent->m = m_old;
1837 GNUNET_array_grow(agent->e, agent->m, m_new); 1885 GNUNET_array_grow(agent->e, agent->m, m_new);
1838 1886
1839 if (NULL == agent->address_inuse) 1887 ril_try_unblock_agent(s, agent, GNUNET_NO);
1840 {
1841 envi_set_active_suggestion (s, agent, address, min_bw, min_bw, GNUNET_NO);
1842 }
1843 1888
1844 ril_step (s); 1889 ril_step (s);
1845 1890
@@ -2155,9 +2200,9 @@ GAS_ril_get_preferred_address (void *solver, const struct GNUNET_PeerIdentity *p
2155 agent = ril_get_agent (s, peer, GNUNET_YES); 2200 agent = ril_get_agent (s, peer, GNUNET_YES);
2156 2201
2157 agent->is_active = GNUNET_YES; 2202 agent->is_active = GNUNET_YES;
2203 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, agent->bw_out, GNUNET_YES);
2158 2204
2159 envi_set_active_suggestion (s, agent, agent->address_inuse, agent->bw_in, agent->bw_out, 2205 ril_try_unblock_agent(solver, agent, GNUNET_YES);
2160 GNUNET_YES);
2161 2206
2162 if (agent->address_inuse) 2207 if (agent->address_inuse)
2163 { 2208 {