[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r30831 - gnunet/src/ats
From: |
gnunet |
Subject: |
[GNUnet-SVN] r30831 - gnunet/src/ats |
Date: |
Wed, 20 Nov 2013 17:56:06 +0100 |
Author: oehlmann
Date: 2013-11-20 17:56:06 +0100 (Wed, 20 Nov 2013)
New Revision: 30831
Modified:
gnunet/src/ats/libgnunet_plugin_ats_ril.c
Log:
- variables renamed
- no suggestion if not at least min_bw bandwidth is theoretically available
Modified: gnunet/src/ats/libgnunet_plugin_ats_ril.c
===================================================================
--- gnunet/src/ats/libgnunet_plugin_ats_ril.c 2013-11-20 16:20:26 UTC (rev
30830)
+++ gnunet/src/ats/libgnunet_plugin_ats_ril.c 2013-11-20 16:56:06 UTC (rev
30831)
@@ -298,22 +298,22 @@
/**
* Whether a step is already scheduled
*/
- int task_pending;
+ int step_task_pending;
/**
* Variable discount factor, dependent on time between steps
*/
- double discount_variable;
+ double global_discount_variable;
/**
* Integrated variable discount factor, dependent on time between steps
*/
- double discount_integrated;
+ double global_discount_integrated;
/**
* State vector for networks for the current step
*/
- double *state_networks;
+ double *global_state_networks;
/**
* Lock for bulk operations
@@ -504,8 +504,8 @@
double delta;
double *theta = agent->W[agent->a_old];
- delta = agent->envi->discount_integrated * reward; //reward
- delta += agent->envi->discount_variable * agent_estimate_q (agent, s_next,
a_prime); //discounted future value
+ delta = agent->envi->global_discount_integrated * reward; //reward
+ delta += agent->envi->global_discount_variable * agent_estimate_q (agent,
s_next, a_prime); //discounted future value
delta -= agent_estimate_q (agent, agent->s_old, agent->a_old); //one step
for (i = 0; i < agent->m; i++)
{
@@ -540,7 +540,7 @@
e[i] = 1;
break;
case RIL_E_SET:
- e[i] *= agent->envi->discount_variable * agent->envi->parameters.lambda;
+ e[i] *= agent->envi->global_discount_variable *
agent->envi->parameters.lambda;
break;
case RIL_E_ZERO:
e[i] = 0;
@@ -681,10 +681,10 @@
for (i = 0; i < solver->networks_count; i++)
{
net = solver->network_entries[i];
- solver->state_networks[i * RIL_FEATURES_NETWORK_COUNT + 0] = (double)
ril_network_get_assigned(solver, net.type, GNUNET_YES);
- solver->state_networks[i * RIL_FEATURES_NETWORK_COUNT + 1] = (double)
net.bw_in_available;
- solver->state_networks[i * RIL_FEATURES_NETWORK_COUNT + 2] = (double)
ril_network_get_assigned(solver, net.type, GNUNET_NO);
- solver->state_networks[i * RIL_FEATURES_NETWORK_COUNT + 3] = (double)
net.bw_out_available;
+ solver->global_state_networks[i * RIL_FEATURES_NETWORK_COUNT + 0] =
(double) ril_network_get_assigned(solver, net.type, GNUNET_YES);
+ solver->global_state_networks[i * RIL_FEATURES_NETWORK_COUNT + 1] =
(double) net.bw_in_available;
+ solver->global_state_networks[i * RIL_FEATURES_NETWORK_COUNT + 2] =
(double) ril_network_get_assigned(solver, net.type, GNUNET_NO);
+ solver->global_state_networks[i * RIL_FEATURES_NETWORK_COUNT + 3] =
(double) net.bw_out_available;
}
}
@@ -707,10 +707,10 @@
//copy global networks state
for (i = 0; i < solver->networks_count; i++)
{
- state[i * RIL_FEATURES_NETWORK_COUNT + 0] = solver->state_networks[i *
RIL_FEATURES_NETWORK_COUNT + 0];
- state[i * RIL_FEATURES_NETWORK_COUNT + 1] = solver->state_networks[i *
RIL_FEATURES_NETWORK_COUNT + 1];
- state[i * RIL_FEATURES_NETWORK_COUNT + 2] = solver->state_networks[i *
RIL_FEATURES_NETWORK_COUNT + 2];
- state[i * RIL_FEATURES_NETWORK_COUNT + 3] = solver->state_networks[i *
RIL_FEATURES_NETWORK_COUNT + 3];
+ state[i * RIL_FEATURES_NETWORK_COUNT + 0] =
solver->global_state_networks[i * RIL_FEATURES_NETWORK_COUNT + 0];
+ state[i * RIL_FEATURES_NETWORK_COUNT + 1] =
solver->global_state_networks[i * RIL_FEATURES_NETWORK_COUNT + 1];
+ state[i * RIL_FEATURES_NETWORK_COUNT + 2] =
solver->global_state_networks[i * RIL_FEATURES_NETWORK_COUNT + 2];
+ state[i * RIL_FEATURES_NETWORK_COUNT + 3] =
solver->global_state_networks[i * RIL_FEATURES_NETWORK_COUNT + 3];
}
//get peer features
@@ -1212,7 +1212,7 @@
{
struct GAS_RIL_Handle *solver = cls;
- solver->task_pending = GNUNET_NO;
+ solver->step_task_pending = GNUNET_NO;
ril_step (solver);
}
@@ -1249,6 +1249,72 @@
}
/**
+ * Lookup network struct by type
+ *
+ * @param s the solver handle
+ * @param type the network type
+ * @return the network struct
+ */
+static struct RIL_Network *
+ril_get_network (struct GAS_RIL_Handle *s, uint32_t type)
+{
+ int i;
+
+ for (i = 0; i < s->networks_count; i++)
+ {
+ if (s->network_entries[i].type == type)
+ {
+ return &s->network_entries[i];
+ }
+ }
+ return NULL ;
+}
+
+static int
+ril_network_is_not_full (struct GAS_RIL_Handle *solver, enum
GNUNET_ATS_Network_Type network)
+{
+ struct RIL_Network *net;
+ uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
+ struct RIL_Peer_Agent *agent;
+ unsigned long long address_count = 0;
+
+ for (agent = solver->agents_head; NULL != agent; agent = agent->next)
+ {
+ if (agent->address_inuse && agent->is_active)
+ {
+ net = agent->address_inuse->solver_information;
+ if (net->type == network)
+ {
+ address_count++;
+ }
+ }
+ }
+
+ net = ril_get_network (solver, network);
+ return (net->bw_in_available > min_bw * address_count) &&
(net->bw_out_available > min_bw * address_count);
+}
+
+static void
+ril_try_unblock_agent (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent
*agent, int silent)
+{
+ struct RIL_Address_Wrapped *addr_wrap;
+ struct RIL_Network *net;
+ uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
+
+ for (addr_wrap = agent->addresses_head; NULL != addr_wrap; addr_wrap =
addr_wrap->next)
+ {
+ net = addr_wrap->address_naked->solver_information;
+ if (ril_network_is_not_full(solver, net->type))
+ {
+ if (NULL == agent->address_inuse)
+ envi_set_active_suggestion (solver, agent, addr_wrap->address_naked,
min_bw, min_bw, silent);
+ return;
+ }
+ }
+ agent->address_inuse = NULL;
+}
+
+/**
* Schedules the next global step in an adaptive way. The more resources are
* left, the earlier the next step is scheduled. This serves the reactivity of
* the solver to changed inputs.
@@ -1264,7 +1330,7 @@
double offset;
struct GNUNET_TIME_Relative time_next;
- if (solver->task_pending)
+ if (solver->step_task_pending)
{
GNUNET_SCHEDULER_cancel (solver->step_next_task_id);
}
@@ -1287,7 +1353,7 @@
solver->step_next_task_id = GNUNET_SCHEDULER_add_delayed (time_next,
&ril_step_scheduler_task,
solver);
- solver->task_pending = GNUNET_YES;
+ solver->step_task_pending = GNUNET_YES;
}
/**
@@ -1325,8 +1391,8 @@
solver->step_time_last = time_now;
//calculate reward discounts (once per step for all agents)
- solver->discount_variable = pow (M_E, ((-1.) * ((double)
solver->parameters.beta) * tau));
- solver->discount_integrated = (1 - solver->discount_variable)
+ solver->global_discount_variable = pow (M_E, ((-1.) * ((double)
solver->parameters.beta) * tau));
+ solver->global_discount_integrated = (1 - solver->global_discount_variable)
/ ((double) solver->parameters.beta);
//calculate network state vector
@@ -1335,9 +1401,16 @@
//trigger one step per active agent
for (cur = solver->agents_head; NULL != cur; cur = cur->next)
{
- if (cur->is_active && cur->address_inuse)
+ if (cur->is_active)
{
- agent_step (cur);
+ if (NULL == cur->address_inuse)
+ {
+ ril_try_unblock_agent(solver, cur, GNUNET_NO);
+ }
+ if (cur->address_inuse)
+ {
+ agent_step (cur);
+ }
}
}
@@ -1431,8 +1504,6 @@
agent->e = (double *) GNUNET_malloc (sizeof (double) * agent->m);
agent_modify_eligibility (agent, RIL_E_ZERO);
- GNUNET_CONTAINER_DLL_insert_tail(solver->agents_head, solver->agents_tail,
agent);
-
return agent;
}
@@ -1480,34 +1551,14 @@
if (create)
{
- return agent_init (solver, peer);
+ cur = agent_init (solver, peer);
+ GNUNET_CONTAINER_DLL_insert_tail(solver->agents_head, solver->agents_tail,
cur);
+ return cur;
}
return NULL ;
}
/**
- * Lookup network struct by type
- *
- * @param s the solver handle
- * @param type the network type
- * @return the network struct
- */
-static struct RIL_Network *
-ril_get_network (struct GAS_RIL_Handle *s, uint32_t type)
-{
- int i;
-
- for (i = 0; i < s->networks_count; i++)
- {
- if (s->network_entries[i].type == type)
- {
- return &s->network_entries[i];
- }
- }
- return NULL ;
-}
-
-/**
* Determine whether at least the minimum bandwidth is set for the network.
Otherwise the network is
* considered inactive and not used. Addresses in an inactive network are
ignored.
*
@@ -1522,9 +1573,7 @@
uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
net = ril_get_network (solver, network);
- if (net->bw_out_available < min_bw)
- return GNUNET_NO;
- return GNUNET_YES;
+ return net->bw_out_available >= min_bw;
}
/**
@@ -1712,7 +1761,7 @@
solver->networks_count = env->network_count;
solver->network_entries = GNUNET_malloc (env->network_count * sizeof (struct
RIL_Network));
solver->step_count = 0;
- solver->state_networks = GNUNET_malloc (solver->networks_count *
RIL_FEATURES_NETWORK_COUNT * sizeof (double));
+ solver->global_state_networks = GNUNET_malloc (solver->networks_count *
RIL_FEATURES_NETWORK_COUNT * sizeof (double));
for (c = 0; c < env->network_count; c++)
{
@@ -1725,7 +1774,7 @@
solver->step_next_task_id = GNUNET_SCHEDULER_add_delayed (
GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_get_millisecond_ (),
1000),
&ril_step_scheduler_task, solver);
- solver->task_pending = GNUNET_YES;
+ solver->step_task_pending = GNUNET_YES;
return solver;
}
@@ -1753,12 +1802,12 @@
cur_agent = next_agent;
}
- if (s->task_pending)
+ if (s->step_task_pending)
{
GNUNET_SCHEDULER_cancel (s->step_next_task_id);
}
GNUNET_free(s->network_entries);
- GNUNET_free(s->state_networks);
+ GNUNET_free(s->global_state_networks);
GNUNET_free(s);
return NULL ;
@@ -1786,7 +1835,6 @@
unsigned int n_old;
int i;
unsigned int zero;
- uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
LOG (GNUNET_ERROR_TYPE_DEBUG, "API_address_add()\n");
@@ -1836,10 +1884,7 @@
agent->m = m_old;
GNUNET_array_grow(agent->e, agent->m, m_new);
- if (NULL == agent->address_inuse)
- {
- envi_set_active_suggestion (s, agent, address, min_bw, min_bw, GNUNET_NO);
- }
+ ril_try_unblock_agent(s, agent, GNUNET_NO);
ril_step (s);
@@ -2155,9 +2200,9 @@
agent = ril_get_agent (s, peer, GNUNET_YES);
agent->is_active = GNUNET_YES;
+ envi_set_active_suggestion (solver, agent, agent->address_inuse,
agent->bw_in, agent->bw_out, GNUNET_YES);
- envi_set_active_suggestion (s, agent, agent->address_inuse, agent->bw_in,
agent->bw_out,
- GNUNET_YES);
+ ril_try_unblock_agent(solver, agent, GNUNET_YES);
if (agent->address_inuse)
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r30831 - gnunet/src/ats,
gnunet <=