*/
#define DEBUG_MLP_PROBLEM_CREATION GNUNET_NO
-/**
- * Enable GLPK verbose output
- */
-#define VERBOSE_GLPK GNUNET_NO
/**
* Maximize bandwidth assigned
mlp_term_hook (void *info, const char *s)
{
/* Not needed atm struct MLP_information *mlp = info; */
- LOG (GNUNET_ERROR_TYPE_DEBUG, "%s", s);
+ LOG (GNUNET_ERROR_TYPE_ERROR, "%s", s);
return 1;
}
struct CountContext
{
- const struct GNUNET_CONTAINER_MultiPeerMap *peers;
+ const struct GNUNET_CONTAINER_MultiPeerMap *map;
int result;
};
struct CountContext *cctx = cls;
/* Check if we have to add this peer due to a pending request */
- if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (cctx->peers, key))
+ if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (cctx->map, key))
cctx->result++;
return GNUNET_OK;
}
static int
-mlp_create_problem_count_addresses (const struct GNUNET_CONTAINER_MultiPeerMap *peers,
+mlp_create_problem_count_addresses (const struct GNUNET_CONTAINER_MultiPeerMap *requested_peers,
const struct GNUNET_CONTAINER_MultiPeerMap *addresses)
{
struct CountContext cctx;
- cctx.peers = peers;
+ cctx.map = requested_peers;
cctx.result = 0;
GNUNET_CONTAINER_multipeermap_iterate (addresses,
- &mlp_create_problem_count_addresses_it, &cctx);
+ &mlp_create_problem_count_addresses_it, &cctx);
+ return cctx.result;
+}
+
+
+static int
+mlp_create_problem_count_peers_it (void *cls,
+ const struct GNUNET_PeerIdentity *key,
+ void *value)
+{
+ struct CountContext *cctx = cls;
+
+ /* Check if we have to addresses for the requested peer */
+ if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (cctx->map, key))
+ cctx->result++;
+ return GNUNET_OK;
+}
+
+
+static int
+mlp_create_problem_count_peers (const struct GNUNET_CONTAINER_MultiPeerMap *requested_peers,
+ const struct GNUNET_CONTAINER_MultiPeerMap *addresses)
+{
+ struct CountContext cctx;
+
+ cctx.map = addresses;
+ cctx.result = 0;
+ GNUNET_CONTAINER_multipeermap_iterate (requested_peers,
+ &mlp_create_problem_count_peers_it, &cctx);
return cctx.result;
}
/* create the glpk problem */
p->prob = glp_create_prob ();
GNUNET_assert (NULL != p->prob);
- p->num_peers = GNUNET_CONTAINER_multipeermap_size (mlp->requested_peers);
+ p->num_peers = mlp_create_problem_count_peers (mlp->requested_peers, mlp->addresses);
p->num_addresses = mlp_create_problem_count_addresses (mlp->requested_peers, mlp->addresses);
/* Create problem matrix: 10 * #addresses + #q * #addresses + #q, + #peer + 2 + 1 */
GNUNET_assert(NULL != solver);
- if (GNUNET_YES == mlp->bulk_lock)
+ if (GNUNET_YES == mlp->stat_bulk_lock)
{
- mlp->bulk_request++;
+ mlp->stat_bulk_requests++;
return GNUNET_NO;
}
notify(mlp, GAS_OP_SOLVE_START, GAS_STAT_SUCCESS,
- (GNUNET_YES == mlp->mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
+ (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
start_total = GNUNET_TIME_absolute_get();
if (0 == GNUNET_CONTAINER_multipeermap_size(mlp->requested_peers))
return GNUNET_OK; /* No addresses available */
}
- if ((GNUNET_NO == mlp->mlp_prob_changed)
- && (GNUNET_NO == mlp->mlp_prob_updated))
+ if ((GNUNET_NO == mlp->stat_mlp_prob_changed)
+ && (GNUNET_NO == mlp->stat_mlp_prob_updated))
{
LOG(GNUNET_ERROR_TYPE_DEBUG, "No changes to problem\n");
notify(mlp, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS, GAS_INFO_NONE);
return GNUNET_OK;
}
- if (GNUNET_YES == mlp->mlp_prob_changed)
+ if (GNUNET_YES == mlp->stat_mlp_prob_changed)
{
LOG(GNUNET_ERROR_TYPE_DEBUG, "Problem size changed, rebuilding\n");
notify(mlp, GAS_OP_SOLVE_SETUP_START, GAS_STAT_SUCCESS, GAS_INFO_FULL);
dur_setup = GNUNET_TIME_absolute_get_duration (start_total);
/* Run LP solver */
- mlp->control_param_lp.presolve = GLP_YES;
notify(mlp, GAS_OP_SOLVE_MLP_LP_START, GAS_STAT_SUCCESS,
- (GNUNET_YES == mlp->mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
+ (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
LOG(GNUNET_ERROR_TYPE_DEBUG,
"Running LP solver %s\n",
(GLP_YES == mlp->control_param_lp.presolve)? "with presolver": "without presolver");
start_cur_op = GNUNET_TIME_absolute_get();
/* Solve LP */
+ mlp->control_param_lp.presolve = GLP_YES;
res_lp = mlp_solve_lp_problem(mlp);
dur_lp = GNUNET_TIME_absolute_get_duration (start_cur_op);
notify(mlp, GAS_OP_SOLVE_MLP_LP_STOP,
(GNUNET_OK == res_lp) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL,
- (GNUNET_YES == mlp->mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
+ (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
/* Run MLP solver */
{
LOG(GNUNET_ERROR_TYPE_DEBUG, "Running MLP solver \n");
notify(mlp, GAS_OP_SOLVE_MLP_MLP_START, GAS_STAT_SUCCESS,
- (GNUNET_YES == mlp->mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
+ (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
start_cur_op = GNUNET_TIME_absolute_get();
/* Solve MIP */
+ //mlp->control_param_mlp.presolve = GNUNET_YES;
res_mip = mlp_solve_mlp_problem(mlp);
dur_mlp = GNUNET_TIME_absolute_get_duration (start_cur_op);
notify(mlp, GAS_OP_SOLVE_MLP_MLP_STOP,
(GNUNET_OK == res_mip) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL,
- (GNUNET_YES == mlp->mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
+ (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
}
else
{
/* Do not execute mip solver since lp solution is invalid */
dur_mlp = GNUNET_TIME_UNIT_ZERO;
dur_total = GNUNET_TIME_absolute_get_duration (start_total);
- GNUNET_break (0);
notify(mlp, GAS_OP_SOLVE_MLP_MLP_STOP, GAS_STAT_FAIL,
- (GNUNET_YES == mlp->mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
+ (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
res_mip = GNUNET_SYSERR;
}
/* Notify about end */
notify(mlp, GAS_OP_SOLVE_STOP,
((GNUNET_OK == res_mip) && (GNUNET_OK == res_mip)) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL,
- (GNUNET_YES == mlp->mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
+ (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Execution time for %s solve: (total/setup/lp/mlp) : %llu %llu %llu %llu\n",
- (GNUNET_YES == mlp->mlp_prob_changed) ? "full" : "updated",
+ (GNUNET_YES == mlp->stat_mlp_prob_changed) ? "full" : "updated",
(unsigned long long) dur_total.rel_value_us,
(unsigned long long) dur_setup.rel_value_us,
(unsigned long long) dur_lp.rel_value_us,
GAS_INFO_NONE);
struct GNUNET_TIME_Absolute time = GNUNET_TIME_absolute_get();
- if ( (GNUNET_YES == mlp->dump_solution_all) ||
- (mlp->dump_solution_on_fail && ((GNUNET_OK != res_lp) || (GNUNET_OK != res_mip))) )
+ if ( (GNUNET_YES == mlp->opt_dump_solution_all) ||
+ (mlp->opt_dump_solution_on_fail && ((GNUNET_OK != res_lp) || (GNUNET_OK != res_mip))) )
{
/* Write problem to disk */
- GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.mps", mlp->p.num_peers,
+ GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.lp", mlp->p.num_peers,
mlp->p.num_addresses, time.abs_value_us);
LOG(GNUNET_ERROR_TYPE_ERROR, "Dumped problem to file: `%s' \n", filename);
- glp_write_mps (mlp->p.prob, GLP_MPS_FILE, NULL, filename);
+ glp_write_lp (mlp->p.prob, NULL, filename);
GNUNET_free(filename);
}
- if ( (mlp->dump_solution_all) ||
- (mlp->dump_solution_on_fail && ((GNUNET_OK != res_lp) || (GNUNET_OK != res_mip))) )
+ if ( (mlp->opt_dump_solution_all) ||
+ (mlp->opt_dump_solution_on_fail && ((GNUNET_OK != res_lp) || (GNUNET_OK != res_mip))) )
{
/* Write solution to disk */
GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.sol", mlp->p.num_peers,
/* Reset change and update marker */
mlp->control_param_lp.presolve = GLP_NO;
- mlp->mlp_prob_updated = GNUNET_NO;
- mlp->mlp_prob_changed = GNUNET_NO;
+ mlp->stat_mlp_prob_updated = GNUNET_NO;
+ mlp->stat_mlp_prob_changed = GNUNET_NO;
if ((GNUNET_OK == res_lp) && (GNUNET_OK == res_mip))
return GNUNET_OK;
LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding address for peer `%s' with address request \n", GNUNET_i2s(&address->peer));
/* Problem size changed: new address for peer with pending request */
- mlp->mlp_prob_changed = GNUNET_YES;
- if (GNUNET_YES == mlp->mlp_auto_solve)
+ mlp->stat_mlp_prob_changed = GNUNET_YES;
+ if (GNUNET_YES == mlp->opt_mlp_auto_solve)
GAS_mlp_solve_problem (solver);
}
if (GNUNET_YES == mlp_create_problem_update_value (&mlp->p,
mlp->p.r_q[type_index], mlpi->c_b, rel_value, __LINE__))
{
- mlp->mlp_prob_updated = GNUNET_YES;
- if (GNUNET_YES == mlp->mlp_auto_solve)
+ mlp->stat_mlp_prob_updated = GNUNET_YES;
+ if (GNUNET_YES == mlp->opt_mlp_auto_solve)
GAS_mlp_solve_problem (solver);
}
}
}
}
- mlp->mlp_prob_changed = GNUNET_YES;
+ mlp->stat_mlp_prob_changed = GNUNET_YES;
}
if (NULL == (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers,
&address->peer)))
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Deleting %s for peer `%s' without address request \n",
+ LOG (GNUNET_ERROR_TYPE_INFO, "Deleting %s for peer `%s' without address request \n",
(session_only == GNUNET_YES) ? "session" : "address",
GNUNET_i2s(&address->peer));
return;
GNUNET_i2s(&address->peer));
/* Problem size changed: new address for peer with pending request */
- mlp->mlp_prob_changed = GNUNET_YES;
- if (GNUNET_YES == mlp->mlp_auto_solve)
+ mlp->stat_mlp_prob_changed = GNUNET_YES;
+ if (GNUNET_YES == mlp->opt_mlp_auto_solve)
{
GAS_mlp_solve_problem (solver);
}
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
/* Added new peer, we have to rebuild problem before solving */
- mlp->mlp_prob_changed = GNUNET_YES;
+ mlp->stat_mlp_prob_changed = GNUNET_YES;
- if ((GNUNET_YES == mlp->mlp_auto_solve)&&
+ if ((GNUNET_YES == mlp->opt_mlp_auto_solve)&&
(GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(mlp->addresses,
peer)))
{
GNUNET_assert (NULL != solver);
- s->bulk_lock ++;
+ s->stat_bulk_lock ++;
}
void
struct GAS_MLP_Handle *s = (struct GAS_MLP_Handle *) solver;
GNUNET_assert (NULL != solver);
- if (s->bulk_lock < 1)
+ if (s->stat_bulk_lock < 1)
{
GNUNET_break (0);
return;
}
- s->bulk_lock --;
+ s->stat_bulk_lock --;
- if (0 < s->bulk_request)
+ if (0 < s->stat_bulk_requests)
{
GAS_mlp_solve_problem (solver);
- s->bulk_request= 0;
+ s->stat_bulk_requests= 0;
}
}
GNUNET_CONTAINER_multipeermap_remove (mlp->requested_peers, peer, p);
GNUNET_free (p);
- mlp->mlp_prob_changed = GNUNET_YES;
- if (GNUNET_YES == mlp->mlp_auto_solve)
+ mlp->stat_mlp_prob_changed = GNUNET_YES;
+ if (GNUNET_YES == mlp->opt_mlp_auto_solve)
{
GAS_mlp_solve_problem (solver);
}
mlp_create_problem_update_value (&mlp->p, p->r_c9, mlp->p.c_r, -p->f, __LINE__);
/* Problem size changed: new address for peer with pending request */
- mlp->mlp_prob_updated = GNUNET_YES;
- if (GNUNET_YES == mlp->mlp_auto_solve)
+ mlp->stat_mlp_prob_updated = GNUNET_YES;
+ if (GNUNET_YES == mlp->opt_mlp_auto_solve)
GAS_mlp_solve_problem (solver);
return;
}
long long unsigned int max_iterations;
GNUNET_assert (NULL != env->cfg);
- GNUNET_assert (NULL != env->stats);
GNUNET_assert (NULL != env->addresses);
GNUNET_assert (NULL != env->bandwidth_changed_cb);
GNUNET_assert (NULL != env->get_preferences);
break;
}
- mlp->dump_problem_all = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
- "ats", "DUMP_PROBLEM_ALL");
- if (GNUNET_SYSERR == mlp->dump_problem_all)
- mlp->dump_problem_all = GNUNET_NO;
+ mlp->opt_dump_problem_all = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
+ "ats", "MLP_DUMP_PROBLEM_ALL");
+ if (GNUNET_SYSERR == mlp->opt_dump_problem_all)
+ mlp->opt_dump_problem_all = GNUNET_NO;
- mlp->dump_solution_all = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
- "ats", "DUMP_SOLUTION_ALL");
- if (GNUNET_SYSERR == mlp->dump_solution_all)
- mlp->dump_solution_all = GNUNET_NO;
+ mlp->opt_dump_solution_all = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
+ "ats", "MLP_DUMP_SOLUTION_ALL");
+ if (GNUNET_SYSERR == mlp->opt_dump_solution_all)
+ mlp->opt_dump_solution_all = GNUNET_NO;
- mlp->dump_problem_on_fail = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
- "ats", "DUMP_PROBLEM_ON_FAIL");
- if (GNUNET_SYSERR == mlp->dump_problem_on_fail)
- mlp->dump_problem_on_fail = GNUNET_NO;
+ mlp->opt_dump_problem_on_fail = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
+ "ats", "MLP_DUMP_PROBLEM_ON_FAIL");
+ if (GNUNET_SYSERR == mlp->opt_dump_problem_on_fail)
+ mlp->opt_dump_problem_on_fail = GNUNET_NO;
- mlp->dump_solution_on_fail = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
- "ats", "DUMP_SOLUTION_ON_FAIL");
- if (GNUNET_SYSERR == mlp->dump_solution_on_fail)
- mlp->dump_solution_on_fail = GNUNET_NO;
+ mlp->opt_dump_solution_on_fail = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
+ "ats", "MLP_DUMP_SOLUTION_ON_FAIL");
+ if (GNUNET_SYSERR == mlp->opt_dump_solution_on_fail)
+ mlp->opt_dump_solution_on_fail = GNUNET_NO;
+
+ mlp->opt_glpk_verbose = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
+ "ats", "MLP_GLPK_VERBOSE");
+ if (GNUNET_SYSERR == mlp->opt_glpk_verbose)
+ mlp->opt_glpk_verbose = GNUNET_NO;
mlp->pv.BIG_M = (double) BIG_M_VALUE;
}
/* Get diversity coefficient from configuration */
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
- "MLP_COEFFICIENT_D",
- &tmp))
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg,
+ "ats", "MLP_COEFFICIENT_D", &tmp))
D = (double) tmp / 100;
else
D = DEFAULT_D;
/* Get proportionality coefficient from configuration */
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
- "MLP_COEFFICIENT_R",
- &tmp))
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg,
+ "ats", "MLP_COEFFICIENT_R", &tmp))
R = (double) tmp / 100;
else
R = DEFAULT_R;
/* Get utilization coefficient from configuration */
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
- "MLP_COEFFICIENT_U",
- &tmp))
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg,
+ "ats", "MLP_COEFFICIENT_U", &tmp))
U = (double) tmp / 100;
else
U = DEFAULT_U;
mlp->pv.b_min = b_min;
mlp->pv.n_min = n_min;
mlp->pv.m_q = GNUNET_ATS_QualityPropertiesCount;
- mlp->mlp_prob_changed = GNUNET_NO;
- mlp->mlp_prob_updated = GNUNET_NO;
- mlp->mlp_auto_solve = GNUNET_YES;
+ mlp->stat_mlp_prob_changed = GNUNET_NO;
+ mlp->stat_mlp_prob_updated = GNUNET_NO;
+ mlp->opt_mlp_auto_solve = GNUNET_YES;
mlp->requested_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
- mlp->bulk_request = 0;
- mlp->bulk_lock = 0;
+ mlp->stat_bulk_requests = 0;
+ mlp->stat_bulk_lock = 0;
/* Setup GLPK */
/* Redirect GLPK output to GNUnet logging */
/* Init LP solving parameters */
glp_init_smcp(&mlp->control_param_lp);
mlp->control_param_lp.msg_lev = GLP_MSG_OFF;
-#if VERBOSE_GLPK
- mlp->control_param_lp.msg_lev = GLP_MSG_ALL;
-#endif
+ if (GNUNET_YES == mlp->opt_glpk_verbose)
+ mlp->control_param_lp.msg_lev = GLP_MSG_ALL;
+
mlp->control_param_lp.it_lim = max_iterations;
mlp->control_param_lp.tm_lim = max_duration.rel_value_us / 1000LL;
/* Init MLP solving parameters */
glp_init_iocp(&mlp->control_param_mlp);
mlp->control_param_mlp.msg_lev = GLP_MSG_OFF;
-#if VERBOSE_GLPK
- mlp->control_param_mlp.msg_lev = GLP_MSG_ALL;
-#endif
+ if (GNUNET_YES == mlp->opt_glpk_verbose)
+ mlp->control_param_mlp.msg_lev = GLP_MSG_ALL;
mlp->control_param_mlp.tm_lim = max_duration.rel_value_us / 1000LL;
LOG (GNUNET_ERROR_TYPE_DEBUG, "solver ready\n");