#include "gnunet_statistics_service.h"
#include "glpk.h"
-#define WRITE_MLP GNUNET_YES
-#define DEBUG_ATS GNUNET_YES
+#define WRITE_MLP GNUNET_NO
+#define DEBUG_ATS GNUNET_EXTRA_LOGGING
/**
* Translate glpk solver error codes to text
struct ATS_Address *address = value;
struct MLP_information *mlpi;
unsigned int row_index;
+ char *name;
GNUNET_assert (address->mlp_information != NULL);
mlpi = (struct MLP_information *) address->mlp_information;
*/
row_index = glp_add_rows (mlp->prob, 1);
mlpi->r_c1 = row_index;
+ /* set row name */
+ GNUNET_asprintf(&name, "c1_%s_%s", GNUNET_i2s(&address->peer), address->plugin);
+ glp_set_row_name (mlp->prob, row_index, name);
+ GNUNET_free (name);
/* set row bounds: <= 0 */
glp_set_row_bnds (mlp->prob, row_index, GLP_UP, 0.0, 0.0);
mlp->ia[mlp->ci] = row_index;
*/
row_index = glp_add_rows (mlp->prob, 1);
+ /* set row name */
+ GNUNET_asprintf(&name, "c3_%s_%s", GNUNET_i2s(&address->peer), address->plugin);
+ glp_set_row_name (mlp->prob, row_index, name);
+ GNUNET_free (name);
mlpi->r_c3 = row_index;
/* set row bounds: >= 0 */
glp_set_row_bnds (mlp->prob, row_index, GLP_LO, 0.0, 0.0);
- GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "ats-mlp", "bmin %i %f\n", mlp->b_min, mlp->BIG_M);
mlp->ia[mlp->ci] = row_index;
mlp->ja[mlp->ci] = mlpi->c_b;
mlp->ja[mlp->ci] = mlpi->c_n;
mlp->ar[mlp->ci] = - (double) mlp->b_min;
mlp->ci++;
-#if 0
+
/* c 4) minimum connections
* (1)*n_1 + ... + (1)*n_m >= n_min
*/
mlp->ja[mlp->ci] = mlpi->c_n;
mlp->ar[mlp->ci] = 1;
mlp->ci++;
-#endif
return GNUNET_OK;
}
unsigned int n_addresses;
int row_index;
//int c;
+ char *name;
/* Problem matrix*/
n_addresses = GNUNET_CONTAINER_multihashmap_size(addresses);
* #indices:|quality properties| + |n_addresses|
* */
- int pi = ((7 * n_addresses) /*+ (2 * n_addresses + mlp->m_q + 1)*/);
+ int pi = ((7 * n_addresses) + (2 * n_addresses + mlp->m_q + 1));
mlp->cm_size = pi;
mlp->ci = 1;
int min = mlp->n_min;
if (mlp->n_min > mlp->c_p)
min = mlp->c_p;
-/*
+
mlp->r_c4 = glp_add_rows (mlp->prob, 1);
- glp_set_row_bnds (mlp->prob, mlp->r_c4, GLP_FX, min, min);
-*/
+ glp_set_row_name (mlp->prob, mlp->r_c4, "c4");
+ glp_set_row_bnds (mlp->prob, mlp->r_c4, GLP_LO, min, min);
+
/* Add row for c6) */
-#if 0
+
mlp->r_c6 = glp_add_rows (mlp->prob, 1);
/* Set type type to fix */
glp_set_row_bnds (mlp->prob, mlp->r_c6, GLP_FX, 0.0, 0.0);
ja[mlp->ci] = mlp->c_d;
ar[mlp->ci] = -1;
mlp->ci++;
-#endif
+
GNUNET_CONTAINER_multihashmap_iterate (addresses, create_constraint_it, mlp);
/* Adding constraint rows
* c 2) 1 address per peer
* sum (n_p1_1 + ... + n_p1_n) = 1
*/
-return;
+
/* Adding rows for c 2) */
row_index = glp_add_rows (mlp->prob, mlp->c_p);
while (peer != NULL)
{
struct ATS_Address *addr = peer->head;
- struct MLP_information *mlpi = (struct MLP_information *) addr->mlp_information;
+ struct MLP_information *mlpi = NULL;
/* Adding row for c 2) */
+ GNUNET_asprintf(&name, "c2_%s", GNUNET_i2s(&peer->id));
+ glp_set_row_name (mlp->prob, row_index, name);
+ GNUNET_free (name);
/* Set row bound == 1 */
glp_set_row_bnds (mlp->prob, row_index, GLP_FX, 1.0, 1.0);
while (addr != NULL)
{
+ mlpi = (struct MLP_information *) addr->mlp_information;
ia[mlp->ci] = row_index;
ja[mlp->ci] = mlpi->c_n;
ar[mlp->ci] = 1;
mlp->ci++;
-
addr = addr->next;
}
peer = peer->next;
/* Continuous value*/
glp_set_col_kind (mlp->prob, mlpi->c_b , GLP_CV);
/* Objective function coefficient == 0 */
- glp_set_obj_coef (mlp->prob, mlpi->c_b , 1);
+ glp_set_obj_coef (mlp->prob, mlpi->c_b , 0);
/* Add usage column */
/* Integer value*/
glp_set_col_kind (mlp->prob, mlpi->c_n, GLP_IV);
/* Objective function coefficient == 0 */
- glp_set_obj_coef (mlp->prob, mlpi->c_n, 1);
+ glp_set_obj_coef (mlp->prob, mlpi->c_n, 0);
return GNUNET_OK;
}
mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses)
{
int res = GNUNET_OK;
-/*
+
int col;
+/*
int c;
char *name;
*/
/* Adding invariant columns */
/* Diversity d column */
-#if 0
+
col = glp_add_cols (mlp->prob, 1);
mlp->c_d = col;
/* Column name */
glp_set_obj_coef (mlp->prob, col, mlp->co_D);
/* Column lower bound = 0.0 */
glp_set_col_bnds (mlp->prob, col, GLP_LO, 0.0, 0.0);
-
+#if 0
/* Utilization u column */
col = glp_add_cols (mlp->prob, 1);
glp_print_mip (mlp->prob, name);
GNUNET_free (name);
# endif
-
-
if (res != GNUNET_OK)
{
#if DEBUG_ATS
return GNUNET_SYSERR;
}
- res = glp_mip_status(mlp->prob);
-
- if (res != GNUNET_OK)
- {
-#if DEBUG_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "LP Problem solving failed\n");
-#endif
- return GNUNET_SYSERR;
- }
-
#if DEBUG_ATS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem solved: %i %s\n", res, mlp_status_to_string(res));
#endif
mlp_delete_problem (mlp);
if ((GNUNET_CONTAINER_multihashmap_size (addresses) > 0) && (mlp->c_p > 0))
{
-#if DEBUG_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "mlp_create_problem %i\n",__LINE__);
-#endif
mlp_create_problem (mlp, addresses);
/* Recalculate */