- implemented: quality metrics
authorMatthias Wachs <wachs@net.in.tum.de>
Mon, 16 Jan 2012 17:10:07 +0000 (17:10 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Mon, 16 Jan 2012 17:10:07 +0000 (17:10 +0000)
src/ats/gnunet-service-ats_addresses.c
src/ats/gnunet-service-ats_addresses_mlp.c
src/ats/gnunet-service-ats_addresses_mlp.h
src/ats/test_ats_mlp.c
src/include/gnunet_ats_service.h

index 8693293d05d5e8b777088e59bfbbbe5dd2078afb..06eee9fb39040d55cae982e562eb51e576092391 100644 (file)
@@ -536,55 +536,6 @@ void
 GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
                     const struct GNUNET_STATISTICS_Handle *stats)
 {
-#if HAVE_LIBGLPK
-  double D;
-  double R;
-  double U;
-  long long unsigned int tmp;
-  unsigned int b_min;
-  unsigned int n_min;
-
-  /* Get diversity coefficient from configuration */
-  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
-                                                      "COEFFICIENT_D",
-                                                      &tmp))
-    D = (double) tmp / 100;
-  else
-    D = 1.0;
-
-  /* Get proportionality coefficient from configuration */
-  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
-                                                      "COEFFICIENT_R",
-                                                      &tmp))
-    R = (double) tmp / 100;
-  else
-    R = 1.0;
-
-  /* Get utilization coefficient from configuration */
-  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
-                                                      "COEFFICIENT_U",
-                                                      &tmp))
-    U = (double) tmp / 100;
-  else
-    U = 1.0;
-
-  /* Get minimum bandwidth per used address from configuration */
-  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
-                                                      "MIN_BANDWIDTH",
-                                                      &tmp))
-    b_min = tmp;
-  else
-    b_min = 64000;
-
-  /* Get minimum number of connections from configuration */
-  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
-                                                      "MIN_CONNECTIONS",
-                                                      &tmp))
-    n_min = tmp;
-  else
-    n_min = 4;
-#endif
-
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
                                                       "WAN_QUOTA_IN",
@@ -601,7 +552,7 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
 #if HAVE_LIBGLPK
           ats_mode = MLP;
           /* Init the MLP solver with default values */
-          mlp = GAS_mlp_init (stats, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS, D, U, R, b_min, n_min);
+          mlp = GAS_mlp_init (cfg, stats, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
           break;
 #else
 
index 785cb736b13827136e705ac5a486220e541c10d0..c0d4dc08e6ee0d0950f94d8c72a1112b9813c12e 100644 (file)
@@ -46,6 +46,8 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp)
 {
   int res = GNUNET_OK;
   int col;
+  int c;
+  char *name;
 
   /* Set a problem name */
   glp_set_prob_name (mlp->prob, "gnunet ats bandwidth distribution");
@@ -92,8 +94,14 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp)
   col = glp_add_cols(mlp->prob, mlp->m);
   mlp->c_q_start = col;
   mlp->c_q_end = col + mlp->m;
-
-  mlp->co_Q = GNUNET_malloc (mlp->m * sizeof (double));
+  for (c = 0; c < mlp->m; c++)
+  {
+    GNUNET_asprintf (&name, "q_%u", mlp->q[c]);
+    glp_set_col_name (mlp->prob, col + c, name);
+    glp_set_col_bnds (mlp->prob, col + c, GLP_LO, 0.0, 0.0);
+    GNUNET_free (name);
+    glp_set_obj_coef (mlp->prob, col + c, mlp->co_Q[c]);
+  }
 
   return res;
 }
@@ -285,24 +293,23 @@ mlp_solve_problem (struct GAS_MLP_Handle *mlp)
  * @param stats the GNUNET_STATISTICS handle
  * @param max_duration maximum numbers of iterations for the LP/MLP Solver
  * @param max_iterations maximum time limit for the LP/MLP Solver
- * @param D Diversity coefficient
- * @param U Utilization coefficient
- * @param R Proportionality coefficient
- * @param b_min minimum bandwidth assigned to an address
- * @param n_min minimum number of addresses with bandwidth assigned
- *
  * @return struct GAS_MLP_Handle * on success, NULL on fail
  */
 struct GAS_MLP_Handle *
-GAS_mlp_init (const struct GNUNET_STATISTICS_Handle *stats,
+GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
+              const struct GNUNET_STATISTICS_Handle *stats,
               struct GNUNET_TIME_Relative max_duration,
-              unsigned int max_iterations,
-              double D, double U, double R,
-              unsigned int b_min,
-              unsigned int n_min)
+              unsigned int max_iterations)
 {
   struct GAS_MLP_Handle * mlp = GNUNET_malloc (sizeof (struct GAS_MLP_Handle));
 
+  double D;
+  double R;
+  double U;
+  long long unsigned int tmp;
+  unsigned int b_min;
+  unsigned int n_min;
+
   /* Init GLPK environment */
   GNUNET_assert (glp_init_env() == 0);
 
@@ -310,6 +317,78 @@ GAS_mlp_init (const struct GNUNET_STATISTICS_Handle *stats,
   mlp->prob = glp_create_prob();
   GNUNET_assert (mlp->prob != NULL);
 
+  /* Get diversity coefficient from configuration */
+  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
+                                                      "COEFFICIENT_D",
+                                                      &tmp))
+    D = (double) tmp / 100;
+  else
+    D = 1.0;
+
+  /* Get proportionality coefficient from configuration */
+  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
+                                                      "COEFFICIENT_R",
+                                                      &tmp))
+    R = (double) tmp / 100;
+  else
+    R = 1.0;
+
+  /* Get utilization coefficient from configuration */
+  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
+                                                      "COEFFICIENT_U",
+                                                      &tmp))
+    U = (double) tmp / 100;
+  else
+    U = 1.0;
+
+  /* Get quality metric coefficients from configuration */
+  int i_delay = -1;
+  int i_distance = -1;
+  int q[GNUNET_ATS_QualityPropertiesCount] = GNUNET_ATS_QualityProperties;
+  int c;
+  for (c = 0; c < GNUNET_ATS_QualityPropertiesCount; c++)
+  {
+    /* initialize quality coefficients with default value 1.0 */
+    mlp->co_Q[c] = 1.0;
+
+    mlp->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;
+  }
+
+  if ((i_delay != -1) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
+                                                      "COEFFICIENT_QUALITY_DELAY",
+                                                      &tmp)))
+
+    mlp->co_Q[i_delay] = (double) tmp / 100;
+  else
+    mlp->co_Q[i_delay] = 1.0;
+
+  if ((i_distance != -1) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
+                                                      "COEFFICIENT_QUALITY_DISTANCE",
+                                                      &tmp)))
+    mlp->co_Q[i_distance] = (double) tmp / 100;
+  else
+    mlp->co_Q[i_distance] = 1.0;
+
+  /* Get minimum bandwidth per used address from configuration */
+  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
+                                                      "MIN_BANDWIDTH",
+                                                      &tmp))
+    b_min = tmp;
+  else
+    b_min = 64000;
+
+  /* Get minimum number of connections from configuration */
+  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (cfg, "ats",
+                                                      "MIN_CONNECTIONS",
+                                                      &tmp))
+    n_min = tmp;
+  else
+    n_min = 4;
+
   mlp->stats = (struct GNUNET_STATISTICS_Handle *) stats;
   mlp->max_iterations = max_iterations;
   mlp->max_exec_duration = max_duration;
@@ -340,6 +419,7 @@ GAS_mlp_init (const struct GNUNET_STATISTICS_Handle *stats,
   mlp->co_U = U;
   mlp->b_min = b_min;
   mlp->n_min = n_min;
+  mlp->m = GNUNET_ATS_QualityPropertiesCount;
 
   mlp_create_problem (mlp);
   return mlp;
@@ -438,9 +518,6 @@ GAS_mlp_done (struct GAS_MLP_Handle *mlp)
   if (mlp != NULL)
     glp_delete_prob(mlp->prob);
 
-  if (mlp->co_Q != NULL)
-    GNUNET_free (mlp->co_Q);
-
   /* Clean up GLPK environment */
   glp_free_env();
 
index e604919be8884ef683117212f41de00f780eddbc..62df7a7337e903b806e1b96f559cbca4fd6bb93c 100644 (file)
@@ -136,14 +136,19 @@ struct GAS_MLP_Handle
   int c_r;
   double co_R;
 
+  /* ATS Quality metrics
+   * array with GNUNET_ATS_QualityPropertiesCount elements
+   * contains mapping to GNUNET_ATS_Property*/
+  int q[GNUNET_ATS_QualityPropertiesCount];
+
   /* column index first quality metric (q_1) column */
   int c_q_start;
 
   /* column index last quality metric (q_n) column */
   int c_q_end;
 
-  /* Array of quality metric coefficients (m elements) */
-  double *co_Q;
+  /* quality metric coefficients*/
+  double co_Q[GNUNET_ATS_QualityPropertiesCount];
 
   /* number of quality metrics */
   int m;
@@ -172,24 +177,17 @@ struct MLP_information
 /**
  * Init the MLP problem solving component
  *
+ * @param cfg configuration handle
  * @param stats the GNUNET_STATISTICS handle
  * @param max_duration maximum numbers of iterations for the LP/MLP Solver
  * @param max_iterations maximum time limit for the LP/MLP Solver
- * @param D Diversity coefficient
- * @param U Utilization coefficient
- * @param R Proportionality coefficient
- * @param b_min minimum bandwidth assigned to an address
- * @param n_min minimum number of addresses with bandwidth assigned
- *
  * @return struct GAS_MLP_Handle * on success, NULL on fail
  */
 struct GAS_MLP_Handle *
-GAS_mlp_init (const struct GNUNET_STATISTICS_Handle *stats,
+GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
+              const struct GNUNET_STATISTICS_Handle *stats,
               struct GNUNET_TIME_Relative max_duration,
-              unsigned int max_iterations,
-              double D, double U, double R,
-              unsigned int b_min,
-              unsigned int n_min);
+              unsigned int max_iterations);
 
 
 /**
index 32917d546c9fdaa9794065634a098d5adfe26fa7..e3e714557d175337c3621e19203ab62c43d485de 100644 (file)
@@ -53,7 +53,7 @@ check (void *cls, char *const *args, const char *cfgfile,
 #endif
   stats = GNUNET_STATISTICS_create("ats", cfg);
 
-  mlp = GAS_mlp_init(NULL, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
+  mlp = GAS_mlp_init (cfg, NULL, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
   GNUNET_assert (mlp != NULL);
 
   GAS_mlp_done (mlp);
index 88cab0d9bd427035f798eb513c0d55e413678675..0db277597582c873ba5819b5856770b14aff3f85 100644 (file)
@@ -402,6 +402,16 @@ enum GNUNET_ATS_Property
       // GNUNET_ATS_AVAILABILITY_CONNECTED = 2049
 };
 
+/**
+ * Number of ATS quality properties
+ */
+#define GNUNET_ATS_QualityPropertiesCount 2
+
+/**
+ * ATS quality properties as array initializer
+ */
+#define GNUNET_ATS_QualityProperties {GNUNET_ATS_QUALITY_NET_DELAY, GNUNET_ATS_QUALITY_NET_DISTANCE}
+
 
 GNUNET_NETWORK_STRUCT_BEGIN