+ /* Adding constraint rows
+ * This constraints are kind of "for all addresses"
+ * Feasibility constraints:
+ *
+ * c 1) bandwidth capping
+ * c 3) minimum bandwidth
+ * c 4) minimum number of connections
+ * c 6) maximize diversity
+ * c 10) obey network specific quota
+ */
+
+ 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_name (mlp->prob, mlp->r_c4, "c4");
+ glp_set_row_bnds (mlp->prob, mlp->r_c4, GLP_LO, min, min);
+
+ /* Add row for c6) */
+
+ 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);
+ /* Setting -D */
+ ia[mlp->ci] = mlp->r_c6 ;
+ ja[mlp->ci] = mlp->c_d;
+ ar[mlp->ci] = -1;
+ mlp->ci++;
+
+ /* Add rows for c 10) */
+ for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
+ {
+ mlp->r_quota[c] = glp_add_rows (mlp->prob, 1);
+ char * text;
+ GNUNET_asprintf(&text, "quota_ats_%i", mlp->quota_index[c]);
+ glp_set_row_name (mlp->prob, mlp->r_quota[c], text);
+ GNUNET_free (text);
+ /* Set bounds to 0 <= x <= quota_out */
+ glp_set_row_bnds (mlp->prob, mlp->r_quota[c], GLP_UP, 0.0, mlp->quota_out[c]);
+ }
+
+ GNUNET_CONTAINER_multihashmap_iterate (addresses, create_constraint_it, mlp);
+
+ /* Adding constraint rows
+ * This constraints are kind of "for all peers"
+ * Feasibility constraints:
+ *
+ * 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 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 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, peer->r_c2, name);
+ GNUNET_free (name);
+ /* Set row bound == 1 */
+ glp_set_row_bnds (mlp->prob, peer->r_c2, GLP_FX, 1.0, 1.0);
+
+ /* Adding rows for c 9) */
+#if ENABLE_C9
+ 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++;
+#endif
+
+ while (addr != NULL)
+ {
+ mlpi = (struct MLP_information *) addr->mlp_information;
+
+ /* coefficient for c 2) */
+
+ ia[mlp->ci] = peer->r_c2;
+ ja[mlp->ci] = mlpi->c_n;
+ ar[mlp->ci] = 1;
+ mlp->ci++;
+
+ /* coefficient for c 8) */
+ ia[mlp->ci] = mlp->r_c8;
+ ja[mlp->ci] = mlpi->c_b;
+ ar[mlp->ci] = peer->f;
+ mlp->ci++;
+
+#if ENABLE_C9
+ /* coefficient for c 9) */
+ ia[mlp->ci] = peer->r_c9;
+ ja[mlp->ci] = mlpi->c_b;
+ ar[mlp->ci] = 1;
+ mlp->ci++;
+#endif
+
+ addr = addr->next;
+ }
+ peer = peer->next;
+ }
+
+ /* c 7) For all quality metrics */
+
+
+ for (c = 0; c < mlp->m_q; c++)
+ {
+ struct ATS_Peer *tp;
+ struct ATS_Address *ta;
+ struct MLP_information * mlpi;
+ double value = 1.0;
+
+ /* Adding rows for c 7) */
+ mlp->r_q[c] = glp_add_rows (mlp->prob, 1);
+ GNUNET_asprintf(&name, "c7_q%i_%s", c, mlp_ats_to_string(mlp->q[c]));
+ glp_set_row_name (mlp->prob, mlp->r_q[c], name);
+ GNUNET_free (name);
+ /* Set row bound == 0 */
+ glp_set_row_bnds (mlp->prob, mlp->r_q[c], GLP_LO, 0.0, 0.0);
+
+ ia[mlp->ci] = mlp->r_q[c];
+ ja[mlp->ci] = mlp->c_q[c];
+ ar[mlp->ci] = -1;
+ mlp->ci++;
+
+ for (tp = mlp->peer_head; tp != NULL; tp = tp->next)
+ for (ta = tp->head; ta != NULL; ta = ta->next)
+ {
+ mlpi = ta->mlp_information;
+ value = mlpi->q_averaged[c];
+
+ mlpi->r_q[c] = mlp->r_q[c];
+
+ ia[mlp->ci] = mlp->r_q[c];
+ ja[mlp->ci] = mlpi->c_b;
+ ar[mlp->ci] = tp->f * value;
+ mlp->ci++;
+ }
+ }
+}
+