REST: nothing triggers rest
[oweals/gnunet.git] / src / ats / plugin_ats_mlp.c
index 900a07fa57df7194b10bc47e8b4d6a59b6a00054..0f3a727a74a482275d050c774650e0ca1d49a79e 100644 (file)
@@ -1,21 +1,21 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2011-2014 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2011-2014 GNUnet e.V.
 
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
+     GNUnet is free software: you can redistribute it and/or modify it
+     under the terms of the GNU Affero General Public License as published
+     by the Free Software Foundation, either version 3 of the License,
+     or (at your option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
+     Affero General Public License for more details.
+    
+     You should have received a copy of the GNU Affero General Public License
+     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     SPDX-License-Identifier: AGPL3.0-or-later
 */
 
 /**
@@ -62,6 +62,29 @@ enum MLP_Output_Format
 };
 
 
+enum QualityMetrics
+{
+  RQ_QUALITY_METRIC_DELAY = 0,
+  RQ_QUALITY_METRIC_DISTANCE = 1,
+  RQ_QUALITY_METRIC_COUNT = 2
+};
+
+
+static const char *
+print_quality_type (enum QualityMetrics qm)
+{
+  switch (qm){
+  case RQ_QUALITY_METRIC_DELAY:
+    return "delay";
+  case RQ_QUALITY_METRIC_DISTANCE:
+    return "distance";
+  default:
+    GNUNET_break (0);
+    return NULL;
+  }
+}
+
+
 struct MLP_Solution
 {
   int lp_res;
@@ -125,9 +148,9 @@ struct MLP_Problem
   /* Row index constraint 9: relativity*/
   unsigned int r_c9;
   /* Row indices quality metrics  */
-  int r_q[GNUNET_ATS_QualityPropertiesCount];
+  int r_q[RQ_QUALITY_METRIC_COUNT];
   /* Row indices ATS network quotas */
-  int r_quota[GNUNET_ATS_NetworkTypeCount];
+  int r_quota[GNUNET_NT_COUNT];
 
   /* Column index Diversity (D) column */
   int c_d;
@@ -136,7 +159,7 @@ struct MLP_Problem
   /* Column index Proportionality (R) column */
   int c_r;
   /* Column index quality metrics  */
-  int c_q[GNUNET_ATS_QualityPropertiesCount];
+  int c_q[RQ_QUALITY_METRIC_COUNT];
 
   /* Problem matrix */
   /* Current index */
@@ -161,23 +184,17 @@ struct MLP_Variables
   /* LP MIP Gap */
   double lp_mip_gap;
 
-  /* ATS Quality metrics
-   *
-   * Array with GNUNET_ATS_QualityPropertiesCount elements
-   * contains mapping to GNUNET_ATS_Property*/
-  int q[GNUNET_ATS_QualityPropertiesCount];
-
-  /* Number of quality metrics */
+  /* Number of quality metrics @deprecated, use RQ_QUALITY_METRIC_COUNT */
   int m_q;
 
   /* Number of quality metrics */
   int m_rc;
 
   /* Quality metric coefficients*/
-  double co_Q[GNUNET_ATS_QualityPropertiesCount];
+  double co_Q[RQ_QUALITY_METRIC_COUNT];
 
   /* Ressource costs coefficients*/
-  double co_RC[GNUNET_ATS_QualityPropertiesCount];
+  double co_RC[RQ_QUALITY_METRIC_COUNT];
 
   /* Diversity coefficient */
   double co_D;
@@ -196,18 +213,18 @@ struct MLP_Variables
 
   /* Quotas */
   /* Array mapping array index to ATS network */
-  int quota_index[GNUNET_ATS_NetworkTypeCount];
+  int quota_index[GNUNET_NT_COUNT];
   /* Outbound quotas */
-  unsigned long long quota_out[GNUNET_ATS_NetworkTypeCount];
+  unsigned long long quota_out[GNUNET_NT_COUNT];
   /* Inbound quotas */
 
-  unsigned long long quota_in[GNUNET_ATS_NetworkTypeCount];
+  unsigned long long quota_in[GNUNET_NT_COUNT];
 
   /* ATS ressource costs
    * array with GNUNET_ATS_QualityPropertiesCount elements
    * contains mapping to GNUNET_ATS_Property
    * */
-  int rc[GNUNET_ATS_QualityPropertiesCount];
+  int rc[RQ_QUALITY_METRIC_COUNT];
 
 };
 
@@ -584,9 +601,9 @@ mlp_delete_problem (struct GAS_MLP_Handle *mlp)
   mlp->p.r_c4 = MLP_UNDEFINED;
   mlp->p.r_c6 = MLP_UNDEFINED;
   mlp->p.r_c9 = MLP_UNDEFINED;
-  for (c = 0; c < mlp->pv.m_q ; c ++)
+  for (c = 0; c < RQ_QUALITY_METRIC_COUNT ; c ++)
     mlp->p.r_q[c] = MLP_UNDEFINED;
-  for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c ++)
+  for (c = 0; c < GNUNET_NT_COUNT; c ++)
     mlp->p.r_quota[c] = MLP_UNDEFINED;
   mlp->p.ci = MLP_UNDEFINED;
 
@@ -679,30 +696,6 @@ mlp_solve_to_string (int retcode)
   }
 }
 
-/**
- * Extract an ATS performance info from an address
- *
- * @param address the address
- * @param type the type to extract in HBO
- * @return the value in HBO or GNUNET_ATS_VALUE_UNDEFINED in HBO if value does not exist
- */
-static uint32_t
-get_performance_info (struct ATS_Address *address, uint32_t type)
-{
-  int c1;
-  GNUNET_assert (NULL != address);
-
-  if ((NULL == address->atsi) || (0 == address->atsi_count))
-    return GNUNET_ATS_VALUE_UNDEFINED;
-
-  for (c1 = 0; c1 < address->atsi_count; c1++)
-  {
-    if (ntohl (address->atsi[c1].type) == type)
-      return ntohl (address->atsi[c1].value);
-  }
-  return GNUNET_ATS_VALUE_UNDEFINED;
-}
-
 
 struct CountContext
 {
@@ -792,7 +785,6 @@ mlp_create_problem_update_value (struct MLP_Problem *p,
   double *val_array;
   int *ind_array;
 
-  GNUNET_assert (NULL != p);
   GNUNET_assert (NULL != p->prob);
 
   /* Get number of columns and prepare data structure */
@@ -960,7 +952,6 @@ mlp_create_problem_add_address_information (void *cls,
   struct ATS_Peer *peer;
   struct MLP_information *mlpi;
   char *name;
-  double prop;
   double cur_bigm;
   uint32_t addr_net;
   uint32_t addr_net_index;
@@ -979,21 +970,21 @@ mlp_create_problem_add_address_information (void *cls,
       return GNUNET_OK;
   }
 
-  addr_net = get_performance_info (address, GNUNET_ATS_NETWORK_TYPE);
-  for (addr_net_index = 0; addr_net_index < GNUNET_ATS_NetworkTypeCount; addr_net_index++)
+  addr_net = address->properties.scope;
+  for (addr_net_index = 0; addr_net_index < GNUNET_NT_COUNT; addr_net_index++)
   {
     if (mlp->pv.quota_index[addr_net_index] == addr_net)
       break;
   }
 
-  if (addr_net_index >= GNUNET_ATS_NetworkTypeCount)
+  if (addr_net_index >= GNUNET_NT_COUNT)
   {
     GNUNET_break (0);
     return GNUNET_OK;
   }
 
   max_quota = 0;
-  for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
+  for (c = 0; c < GNUNET_NT_COUNT; c++)
   {
     if (mlp->pv.quota_out[c] > max_quota)
       max_quota = mlp->pv.quota_out[c];
@@ -1110,22 +1101,16 @@ mlp_create_problem_add_address_information (void *cls,
     /* For all quality metrics, set quality of this address */
     if (GNUNET_YES == mlp->opt_dbg_optimize_quality)
     {
-      for (c = 0; c < mlp->pv.m_q; c++)
-      {
-        prop = address->atsin[c].norm;
-        if ((prop < 1.0) && (prop > 2.0))
-        {
-          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                      "PROP == %.3f \t ",
-                      prop);
-          GNUNET_break (0);
-        }
-        mlp_create_problem_set_value (p,
-                                      p->r_q[c],
-                                      mlpi->c_b,
-                                      prop,
-                                      __LINE__);
-      }
+      mlp_create_problem_set_value (p,
+                                    p->r_q[RQ_QUALITY_METRIC_DELAY],
+                                    mlpi->c_b,
+                                    address->norm_delay.norm,
+                                    __LINE__);
+      mlp_create_problem_set_value (p,
+                                    p->r_q[RQ_QUALITY_METRIC_DISTANCE],
+                                    mlpi->c_b,
+                                    address->norm_distance.norm,
+                                    __LINE__);
     }
   }
 
@@ -1148,11 +1133,11 @@ mlp_create_problem_add_invariant_rows (struct GAS_MLP_Handle *mlp, struct MLP_Pr
   p->r_c4 = mlp_create_problem_create_constraint (p, "c4", GLP_LO, (mlp->pv.n_min > p->num_peers) ? p->num_peers : mlp->pv.n_min, 0.0);
 
   /* Rows for c 10) Enforce network quotas */
-  for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
+  for (c = 0; c < GNUNET_NT_COUNT; c++)
   {
     char * text;
     GNUNET_asprintf(&text, "c10_quota_ats_%s",
-        GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]));
+        GNUNET_NT_to_string(mlp->pv.quota_index[c]));
     p->r_quota[c] = mlp_create_problem_create_constraint (p, text, GLP_DB, 0.0, mlp->pv.quota_out[c]);
     GNUNET_free (text);
   }
@@ -1183,11 +1168,14 @@ mlp_create_problem_add_invariant_rows (struct GAS_MLP_Handle *mlp, struct MLP_Pr
     {
       for (c = 0; c < mlp->pv.m_q; c++)
       {
-        GNUNET_asprintf (&name, "c7_q%i_%s", c,
-                         GNUNET_ATS_print_property_type (mlp->pv.q[c]));
+        GNUNET_asprintf (&name,
+                         "c7_q%i_%s", c,
+                         print_quality_type (c));
         p->r_q[c] = mlp_create_problem_create_constraint (p, name, GLP_FX, 0.0, 0.0);
         GNUNET_free (name);
-        mlp_create_problem_set_value (p, p->r_q[c], p->c_q[c], -1, __LINE__);
+        mlp_create_problem_set_value (p,
+                                      p->r_q[c],
+                                      p->c_q[c], -1, __LINE__);
       }
     }
   }
@@ -1222,7 +1210,7 @@ mlp_create_problem_add_invariant_columns (struct GAS_MLP_Handle *mlp, struct MLP
     {
       for (c = 0; c < mlp->pv.m_q; c++)
       {
-        GNUNET_asprintf (&name, "q_%u", mlp->pv.q[c]);
+        GNUNET_asprintf (&name, "q_%u", c);
         p->c_q[c] = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_Q[c]);
         GNUNET_free (name);
       }
@@ -1413,7 +1401,7 @@ mlp_propagate_results (void *cls,
       mlpi->b_in = mlp_bw_in;
       address->assigned_bw_out = mlp_bw_out;
       mlpi->b_out = mlp_bw_out;
-      if ((NULL == mlp->exclude_peer) || (0 != memcmp (&address->peer, mlp->exclude_peer, sizeof (address->peer))))
+      if ((NULL == mlp->exclude_peer) || (0 != GNUNET_memcmp (&address->peer, mlp->exclude_peer)))
         mlp->env->bandwidth_changed_cb (mlp->env->cls, address);
       return GNUNET_OK;
     }
@@ -1429,7 +1417,7 @@ mlp_propagate_results (void *cls,
           mlpi->b_in = mlp_bw_in;
           address->assigned_bw_out = mlp_bw_out;
           mlpi->b_out = mlp_bw_out;
-          if ((NULL == mlp->exclude_peer) || (0 != memcmp (&address->peer, mlp->exclude_peer, sizeof (address->peer))))
+          if ((NULL == mlp->exclude_peer) || (0 != GNUNET_memcmp (&address->peer, mlp->exclude_peer)))
             mlp->env->bandwidth_changed_cb (mlp->env->cls, address);
           return GNUNET_OK;
       }
@@ -1568,6 +1556,7 @@ GAS_mlp_solve_problem (void *solver)
   struct GNUNET_TIME_Relative dur_mlp;
 
   GNUNET_assert(NULL != solver);
+  dur_lp = GNUNET_TIME_UNIT_ZERO; 
 
   if (GNUNET_YES == mlp->stat_bulk_lock)
     {
@@ -1600,8 +1589,8 @@ GAS_mlp_solve_problem (void *solver)
   {
     LOG(GNUNET_ERROR_TYPE_DEBUG, "Problem size changed, rebuilding\n");
     notify(mlp, GAS_OP_SOLVE_SETUP_START, GAS_STAT_SUCCESS, GAS_INFO_FULL);
-    mlp_delete_problem(mlp);
-    if (GNUNET_SYSERR == mlp_create_problem(mlp))
+    mlp_delete_problem (mlp);
+    if (GNUNET_SYSERR == mlp_create_problem (mlp))
       {
         notify(mlp, GAS_OP_SOLVE_SETUP_STOP, GAS_STAT_FAIL, GAS_INFO_FULL);
         return GNUNET_SYSERR;
@@ -1866,13 +1855,10 @@ GAS_mlp_address_add (void *solver,
 {
   struct GAS_MLP_Handle *mlp = solver;
 
-  GNUNET_assert (NULL != solver);
-  GNUNET_assert (NULL != address);
-
-  if (GNUNET_ATS_NetworkTypeCount <= network)
+  if (GNUNET_NT_COUNT <= network)
   {
-   GNUNET_break (0);
-   return;
+    GNUNET_break (0);
+    return;
   }
 
   if (NULL == address->solver_information)
@@ -1911,36 +1897,26 @@ GAS_mlp_address_add (void *solver,
  *
  * @param solver solver handle
  * @param address the address
- * @param type the ATSI type in HBO
- * @param abs_value the absolute value of the property
- * @param rel_value the normalized value
  */
 static void
 GAS_mlp_address_property_changed (void *solver,
-                                  struct ATS_Address *address,
-                                  enum GNUNET_ATS_Property type,
-                                  uint32_t abs_value,
-                                  double rel_value)
+                                  struct ATS_Address *address)
 {
   struct MLP_information *mlpi = address->solver_information;
   struct GAS_MLP_Handle *mlp = solver;
-  int c1;
-  int type_index;
 
-  GNUNET_assert (NULL != solver);
-  GNUNET_assert (NULL != address);
+  if (NULL == mlp->p.prob)
+    return; /* There is no MLP problem to update yet */
 
   if (NULL == mlpi)
   {
-      LOG (GNUNET_ERROR_TYPE_INFO,
-          _("Updating address property `%s' for peer `%s' %p not added before\n"),
-          GNUNET_ATS_print_property_type (type),
-          GNUNET_i2s(&address->peer),
-          address);
-      GNUNET_break (0);
-      return;
+    LOG (GNUNET_ERROR_TYPE_INFO,
+         _("Updating address property for peer `%s' %p not added before\n"),
+         GNUNET_i2s (&address->peer),
+         address);
+    GNUNET_break (0);
+    return;
   }
-
   if (NULL ==
       GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers,
                                          &address->peer))
@@ -1948,34 +1924,26 @@ GAS_mlp_address_property_changed (void *solver,
     /* Peer is not requested, so no need to update problem */
     return;
   }
-  LOG (GNUNET_ERROR_TYPE_INFO, "Updating property `%s' address for peer `%s' to abs %llu rel %.3f\n",
-      GNUNET_ATS_print_property_type (type),
-      GNUNET_i2s(&address->peer),
-      abs_value,
-      rel_value);
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Updating properties for peer `%s'\n",
+       GNUNET_i2s(&address->peer));
 
   if (GNUNET_YES == mlp->opt_dbg_feasibility_only)
     return;
 
-  /* Find row index */
-  type_index = -1;
-  for (c1 = 0; c1 < mlp->pv.m_q; c1++)
-  {
-    if (type == mlp->pv.q[c1])
-    {
-      type_index = c1;
-      break;
-    }
-  }
-  if (-1 == type_index)
-  {
-    GNUNET_break (0);
-    return; /* quality index not found */
-  }
-
   /* Update c7) [r_q[index]][c_b] = f_q * q_averaged[type_index] */
-  if (GNUNET_YES == mlp_create_problem_update_value (&mlp->p,
-      mlp->p.r_q[type_index], mlpi->c_b, rel_value, __LINE__))
+  if ( (GNUNET_YES ==
+        mlp_create_problem_update_value (&mlp->p,
+                                         mlp->p.r_q[RQ_QUALITY_METRIC_DELAY],
+                                         mlpi->c_b,
+                                         address->norm_delay.norm,
+                                         __LINE__)) ||
+       (GNUNET_YES ==
+        mlp_create_problem_update_value (&mlp->p,
+                                         mlp->p.r_q[RQ_QUALITY_METRIC_DISTANCE],
+                                         mlpi->c_b,
+                                         address->norm_distance.norm,
+                                         __LINE__)) )
   {
     mlp->stat_mlp_prob_updated = GNUNET_YES;
     if (GNUNET_YES == mlp->opt_mlp_auto_solve)
@@ -2037,17 +2005,14 @@ get_peer_pref_value (struct GAS_MLP_Handle *mlp,
 
   preferences = mlp->env->get_preferences (mlp->env->cls, peer);
   res = 0.0;
-  for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
+  for (c = 0; c < GNUNET_ATS_PREFERENCE_END; c++)
   {
-    if (c != GNUNET_ATS_PREFERENCE_END)
-    {
-      /* fprintf (stderr, "VALUE[%u] %s %.3f \n",
-       *        c, GNUNET_i2s (&cur->addr->peer), t[c]); */
-      res += preferences[c];
-    }
+    /* fprintf (stderr, "VALUE[%u] %s %.3f \n",
+     *        c, GNUNET_i2s (&cur->addr->peer), t[c]); */
+    res += preferences[c];
   }
 
-  res /= (GNUNET_ATS_PreferenceCount -1);
+  res /= GNUNET_ATS_PREFERENCE_END;
   res += 1.0;
 
   LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -2063,9 +2028,8 @@ get_peer_pref_value (struct GAS_MLP_Handle *mlp,
  *
  * @param solver the MLP Handle
  * @param peer the peer
- * @return suggested address
  */
-static const struct ATS_Address *
+static void
 GAS_mlp_get_preferred_address (void *solver,
                                const struct GNUNET_PeerIdentity *peer)
 {
@@ -2073,11 +2037,9 @@ GAS_mlp_get_preferred_address (void *solver,
   struct ATS_Peer *p;
   struct ATS_Address *res;
 
-  GNUNET_assert (NULL != solver);
-  GNUNET_assert (NULL != peer);
-
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Getting preferred address for `%s'\n",
-      GNUNET_i2s (peer));
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Getting preferred address for `%s'\n",
+       GNUNET_i2s (peer));
 
   /* Is this peer included in the problem? */
   if (NULL ==
@@ -2110,7 +2072,9 @@ GAS_mlp_get_preferred_address (void *solver,
   res = NULL;
   GNUNET_CONTAINER_multipeermap_get_multiple (mlp->env->addresses, peer,
                                               &mlp_get_preferred_address_it, &res);
-  return res;
+  if (NULL != res)
+    mlp->env->bandwidth_changed_cb (mlp->env->cls,
+                                    res);
 }
 
 
@@ -2128,6 +2092,7 @@ GAS_mlp_address_delete (void *solver,
 {
   struct GAS_MLP_Handle *mlp = solver;
   struct MLP_information *mlpi;
+  struct ATS_Address *res;
   int was_active;
 
   mlpi = address->solver_information;
@@ -2164,7 +2129,13 @@ GAS_mlp_address_delete (void *solver,
   }
   if (GNUNET_YES == was_active)
   {
-    if (NULL == GAS_mlp_get_preferred_address (solver, &address->peer))
+    GAS_mlp_get_preferred_address (solver, &address->peer);
+    res = NULL;
+    GNUNET_CONTAINER_multipeermap_get_multiple (mlp->env->addresses,
+                                                &address->peer,
+                                                &mlp_get_preferred_address_it,
+                                                &res);
+    if (NULL == res)
     {
       /* No alternative address, disconnecting peer */
       mlp->env->bandwidth_changed_cb (mlp->env->cls, address);
@@ -2311,7 +2282,7 @@ GAS_mlp_address_change_preference (void *solver,
  */
 static void
 GAS_mlp_address_preference_feedback (void *solver,
-                                     struct GNUNET_SERVER_Client *application,
+                                     struct GNUNET_SERVICE_Client *application,
                                      const struct GNUNET_PeerIdentity *peer,
                                      const struct GNUNET_TIME_Relative scope,
                                      enum GNUNET_ATS_PreferenceKind kind,
@@ -2640,34 +2611,28 @@ libgnunet_plugin_ats_mlp_init (void *cls)
   }
 
   /* Get quality metric coefficients from configuration */
-  int i_delay = MLP_NaN;
-  int i_distance = MLP_NaN;
-  int q[GNUNET_ATS_QualityPropertiesCount] = GNUNET_ATS_QualityProperties;
-  for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++)
+  for (c = 0; c < RQ_QUALITY_METRIC_COUNT; c++)
   {
     /* initialize quality coefficients with default value 1.0 */
-      mlp->pv.co_Q[c] = MLP_DEFAULT_QUALITY;
-
-    mlp->pv.q[c] = q[c];
-    if (q[c] == GNUNET_ATS_QUALITY_NET_DELAY)
-      i_delay = c;
-    if (q[c] == GNUNET_ATS_QUALITY_NET_DISTANCE)
-      i_distance = c;
+    mlp->pv.co_Q[c] = MLP_DEFAULT_QUALITY;
   }
 
-  if ( (i_delay != MLP_NaN) &&
-       (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
-          "MLP_COEFFICIENT_QUALITY_DELAY", &tmp)) )
-    mlp->pv.co_Q[i_delay] = (double) tmp / 100;
+
+  if (GNUNET_OK ==
+      GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
+                                           "MLP_COEFFICIENT_QUALITY_DELAY",
+                                           &tmp))
+    mlp->pv.co_Q[RQ_QUALITY_METRIC_DELAY] = (double) tmp / 100;
   else
-    mlp->pv.co_Q[i_delay] = MLP_DEFAULT_QUALITY;
+    mlp->pv.co_Q[RQ_QUALITY_METRIC_DELAY] = MLP_DEFAULT_QUALITY;
 
-  if ( (i_distance != MLP_NaN) &&
-        (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
-          "MLP_COEFFICIENT_QUALITY_DISTANCE", &tmp)) )
-    mlp->pv.co_Q[i_distance] = (double) tmp / 100;
+  if (GNUNET_OK ==
+      GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
+                                           "MLP_COEFFICIENT_QUALITY_DISTANCE",
+                                           &tmp))
+    mlp->pv.co_Q[RQ_QUALITY_METRIC_DISTANCE] = (double) tmp / 100;
   else
-    mlp->pv.co_Q[i_distance] = MLP_DEFAULT_QUALITY;
+    mlp->pv.co_Q[RQ_QUALITY_METRIC_DISTANCE] = MLP_DEFAULT_QUALITY;
 
   /* Get minimum bandwidth per used address from configuration */
   if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
@@ -2688,7 +2653,7 @@ libgnunet_plugin_ats_mlp_init (void *cls)
     n_min = MLP_DEFAULT_MIN_CONNECTIONS;
 
   /* Init network quotas */
-  for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++)
+  for (c = 0; c < GNUNET_NT_COUNT; c++)
   {
     mlp->pv.quota_index[c] = c;
     mlp->pv.quota_out[c] = env->out_quota[c];
@@ -2696,7 +2661,7 @@ libgnunet_plugin_ats_mlp_init (void *cls)
 
     LOG (GNUNET_ERROR_TYPE_INFO,
          "Quota for network `%s' (in/out) %llu/%llu\n",
-         GNUNET_ATS_print_network_type (c),
+         GNUNET_NT_to_string (c),
          mlp->pv.quota_out[c],
          mlp->pv.quota_in[c]);
     /* Check if defined quota could make problem unsolvable */
@@ -2704,7 +2669,7 @@ libgnunet_plugin_ats_mlp_init (void *cls)
     {
       LOG (GNUNET_ERROR_TYPE_INFO,
            _("Adjusting inconsistent outbound quota configuration for network `%s', is %llu must be at least %llu\n"),
-           GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
+           GNUNET_NT_to_string(mlp->pv.quota_index[c]),
            mlp->pv.quota_out[c],
            (n_min * b_min));
       mlp->pv.quota_out[c] = (n_min * b_min);
@@ -2713,7 +2678,7 @@ libgnunet_plugin_ats_mlp_init (void *cls)
     {
       LOG (GNUNET_ERROR_TYPE_INFO,
            _("Adjusting inconsistent inbound quota configuration for network `%s', is %llu must be at least %llu\n"),
-           GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
+           GNUNET_NT_to_string(mlp->pv.quota_index[c]),
            mlp->pv.quota_in[c],
            (n_min * b_min));
       mlp->pv.quota_in[c] = (n_min * b_min);
@@ -2723,7 +2688,7 @@ libgnunet_plugin_ats_mlp_init (void *cls)
     {
       LOG (GNUNET_ERROR_TYPE_INFO,
            _("Adjusting outbound quota configuration for network `%s'from %llu to %.0f\n"),
-           GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
+           GNUNET_NT_to_string(mlp->pv.quota_index[c]),
            mlp->pv.quota_out[c],
            mlp->pv.BIG_M);
       mlp->pv.quota_out[c] = mlp->pv.BIG_M ;
@@ -2732,7 +2697,7 @@ libgnunet_plugin_ats_mlp_init (void *cls)
     {
       LOG (GNUNET_ERROR_TYPE_INFO,
            _("Adjusting inbound quota configuration for network `%s' from %llu to %.0f\n"),
-           GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]),
+           GNUNET_NT_to_string(mlp->pv.quota_index[c]),
            mlp->pv.quota_in[c],
            mlp->pv.BIG_M);
       mlp->pv.quota_in[c] = mlp->pv.BIG_M ;
@@ -2753,7 +2718,7 @@ libgnunet_plugin_ats_mlp_init (void *cls)
   /* Setting MLP Input variables */
   mlp->pv.b_min = b_min;
   mlp->pv.n_min = n_min;
-  mlp->pv.m_q = GNUNET_ATS_QualityPropertiesCount;
+  mlp->pv.m_q = RQ_QUALITY_METRIC_COUNT;
   mlp->stat_mlp_prob_changed = GNUNET_NO;
   mlp->stat_mlp_prob_updated = GNUNET_NO;
   mlp->opt_mlp_auto_solve = GNUNET_YES;