#include "glpk.h"
#define WRITE_MLP GNUNET_NO
-#define DEBUG_ATS GNUNET_EXTRA_LOGGING
+#define DEBUG_ATS GNUNET_YES
+#define VERBOSE_GLPK GNUNET_NO
/**
* Translate glpk solver error codes to text
mlp_add_constraints_all_addresses (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses)
{
unsigned int n_addresses;
- int row_index;
//int c;
char *name;
* c 7) quality
* #rows: |quality properties|
* #indices:|quality properties| + |n_addresses|
+ *
+ * c 8) utilization
+ * #rows: 1
+ * #indices: |n_addresses| + 1
+ *
+ * c 9) relativity
+ * #rows: |peers|
+ * #indices: |n_addresses| + |peers|
* */
- int pi = ((7 * n_addresses) + (2 * n_addresses + mlp->m_q + 1));
+ int pi = ((7 * n_addresses) + (3 * n_addresses + mlp->m_q + 2));
mlp->cm_size = pi;
mlp->ci = 1;
*
* c 2) 1 address per peer
* sum (n_p1_1 + ... + n_p1_n) = 1
- */
+ *
+ * c 8) utilization
+ * sum (f_p * b_p1_1 + ... + f_p * b_p1_n) - u = 0
+ *
+ * c 9) relativity
+ * V p : sum (bt_1 + ... +bt_n) - f_p * r = 0
+ * */
- /* Adding rows for c 2) */
- row_index = glp_add_rows (mlp->prob, mlp->c_p);
+ /* Adding rows for c 8) */
+ mlp->r_c8 = glp_add_rows (mlp->prob, mlp->c_p);
+ glp_set_row_name (mlp->prob, mlp->r_c8, "c8");
+ /* Set row bound == 0 */
+ glp_set_row_bnds (mlp->prob, mlp->r_c8, GLP_FX, 0.0, 0.0);
+ /* -u */
+ ia[mlp->ci] = mlp->r_c8;
+ ja[mlp->ci] = mlp->c_u;
+ ar[mlp->ci] = -1;
+ mlp->ci++;
struct ATS_Peer * peer = mlp->peer_head;
while (peer != NULL)
{
struct ATS_Address *addr = peer->head;
struct MLP_information *mlpi = NULL;
- /* Adding row for c 2) */
+
+ /* Adding rows for c 2) */
+ peer->r_c2 = glp_add_rows (mlp->prob, 1);
GNUNET_asprintf(&name, "c2_%s", GNUNET_i2s(&peer->id));
- glp_set_row_name (mlp->prob, row_index, name);
+ glp_set_row_name (mlp->prob, peer->r_c2, name);
GNUNET_free (name);
/* Set row bound == 1 */
- glp_set_row_bnds (mlp->prob, row_index, GLP_FX, 1.0, 1.0);
+ glp_set_row_bnds (mlp->prob, peer->r_c2, GLP_FX, 1.0, 1.0);
+
+
+ /* Adding rows for c 9) */
+ peer->r_c9 = glp_add_rows (mlp->prob, 1);
+ GNUNET_asprintf(&name, "c9_%s", GNUNET_i2s(&peer->id));
+ glp_set_row_name (mlp->prob, peer->r_c9, name);
+ GNUNET_free (name);
+ /* Set row bound == 0 */
+ glp_set_row_bnds (mlp->prob, peer->r_c9, GLP_LO, 0.0, 0.0);
+
+ /* Set -r */
+ ia[mlp->ci] = peer->r_c9;
+ ja[mlp->ci] = mlp->c_r;
+ ar[mlp->ci] = -1;
+ mlp->ci++;
while (addr != NULL)
{
mlpi = (struct MLP_information *) addr->mlp_information;
- ia[mlp->ci] = row_index;
+
+ ia[mlp->ci] = peer->r_c2;
ja[mlp->ci] = mlpi->c_n;
ar[mlp->ci] = 1;
mlp->ci++;
+
+ ia[mlp->ci] = mlp->r_c8;
+ ja[mlp->ci] = mlpi->c_b;
+ ar[mlp->ci] = peer->f;
+ mlp->ci++;
+
+ ia[mlp->ci] = peer->r_c9;
+ ja[mlp->ci] = mlpi->c_b;
+ ar[mlp->ci] = 1;
+ mlp->ci++;
+
addr = addr->next;
}
peer = peer->next;
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_set_obj_coef (mlp->prob, col, mlp->co_R);
/* Column lower bound = 0.0 */
glp_set_col_bnds (mlp->prob, col, GLP_LO, 0.0, 0.0);
-
+#if 0
/* Quality metric columns */
col = glp_add_cols(mlp->prob, mlp->m_q);
for (c = 0; c < mlp->m_q; c++)
}
#if DEBUG_ATS
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem solved: %i %s\n", res, mlp_status_to_string(res));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem solved\n");
#endif
/* Process result */
/* Init LP solving parameters */
glp_init_smcp(&mlp->control_param_lp);
-#if DEBUG_ATS
+#if VERBOSE_GLPK
mlp->control_param_lp.msg_lev = GLP_MSG_ALL;
#else
mlp->control_param_lp.msg_lev = GLP_MSG_OFF;
/* Init MLP solving parameters */
glp_init_iocp(&mlp->control_param_mlp);
-#if DEBUG_ATS
+#if VERBOSE_GLPK
mlp->control_param_mlp.msg_lev = GLP_MSG_ALL;
#else
mlp->control_param_mlp.msg_lev = GLP_MSG_OFF;
{
peer->f_q[c] = 1.0;
}
+ peer->f = 1.0;
memcpy (&peer->id, &address->peer, sizeof (struct GNUNET_PeerIdentity));
GNUNET_assert(address->prev == NULL);
#include "gnunet_statistics_service.h"
#include "gnunet-service-ats_addresses_mlp.h"
-#define VERBOSE GNUNET_EXTRA_LOGGING
+#define VERBOSE GNUNET_YES
#define VERBOSE_ARM GNUNET_EXTRA_LOGGING
#define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
ret = 1;
return;
#endif
- struct ATS_Address addr;
+ struct ATS_Address addr[10];
stats = GNUNET_STATISTICS_create("ats", cfg);
addresses = GNUNET_CONTAINER_multihashmap_create (10);
- GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &addr.peer.hashPubKey);
- addr.mlp_information = NULL;
- addr.next = NULL;
- addr.prev = NULL;
- addr.plugin = strdup ("dummy");
- GNUNET_CONTAINER_multihashmap_put(addresses, &addr.peer.hashPubKey, &addr, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &addr[0].peer.hashPubKey);
+ addr[0].mlp_information = NULL;
+ addr[0].next = NULL;
+ addr[0].prev = NULL;
+ addr[0].plugin = strdup ("dummy");
+
+ addr[1].peer = addr[0].peer;
+ addr[1].mlp_information = NULL;
+ addr[1].next = NULL;
+ addr[1].prev = NULL;
+ addr[1].plugin = strdup ("dummy2");
+
+ GNUNET_CONTAINER_multihashmap_put(addresses, &addr[0].peer.hashPubKey, &addr[0], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
mlp = GAS_mlp_init (cfg, NULL, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
/* Add a new address */
- GAS_mlp_address_update (mlp, addresses, &addr);
+ GAS_mlp_address_update (mlp, addresses, &addr[0]);
GNUNET_assert (mlp != NULL);
GNUNET_assert (mlp->addr_in_problem == 1);
/* Update an new address */
- GAS_mlp_address_update (mlp, addresses, &addr);
+ GAS_mlp_address_update (mlp, addresses, &addr[0]);
GNUNET_assert (mlp->addr_in_problem == 1);
+ /* Add a second address for same peer */
+ GNUNET_CONTAINER_multihashmap_put(addresses, &addr[0].peer.hashPubKey, &addr[1], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ GAS_mlp_address_update (mlp, addresses, &addr[1]);
+ GNUNET_assert (mlp->addr_in_problem == 2);
+
/* Delete an address */
- GNUNET_CONTAINER_multihashmap_remove (addresses, &addr.peer.hashPubKey, &addr);
- GAS_mlp_address_delete (mlp, addresses, &addr);
+ GNUNET_CONTAINER_multihashmap_remove (addresses, &addr[0].peer.hashPubKey, &addr[0]);
+ GAS_mlp_address_delete (mlp, addresses, &addr[0]);
+ GAS_mlp_address_delete (mlp, addresses, &addr[1]);
GAS_mlp_done (mlp);
- GNUNET_free (addr.plugin);
+ GNUNET_free (addr[0].plugin);
+ GNUNET_free (addr[1].plugin);
GNUNET_CONTAINER_multihashmap_destroy (addresses);
GNUNET_STATISTICS_destroy(stats, GNUNET_NO);