gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r19175 - in gnunet/src: ats include


From: gnunet
Subject: [GNUnet-SVN] r19175 - in gnunet/src: ats include
Date: Mon, 16 Jan 2012 18:10:07 +0100

Author: wachs
Date: 2012-01-16 18:10:07 +0100 (Mon, 16 Jan 2012)
New Revision: 19175

Modified:
   gnunet/src/ats/gnunet-service-ats_addresses.c
   gnunet/src/ats/gnunet-service-ats_addresses_mlp.c
   gnunet/src/ats/gnunet-service-ats_addresses_mlp.h
   gnunet/src/ats/test_ats_mlp.c
   gnunet/src/include/gnunet_ats_service.h
Log:
- implemented: quality metrics


Modified: gnunet/src/ats/gnunet-service-ats_addresses.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.c       2012-01-16 15:05:45 UTC 
(rev 19174)
+++ gnunet/src/ats/gnunet-service-ats_addresses.c       2012-01-16 17:10:07 UTC 
(rev 19175)
@@ -536,55 +536,6 @@
 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 @@
 #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
 

Modified: gnunet/src/ats/gnunet-service-ats_addresses_mlp.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_mlp.c   2012-01-16 15:05:45 UTC 
(rev 19174)
+++ gnunet/src/ats/gnunet-service-ats_addresses_mlp.c   2012-01-16 17:10:07 UTC 
(rev 19175)
@@ -46,6 +46,8 @@
 {
   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,9 +94,15 @@
   col = glp_add_cols(mlp->prob, mlp->m);
   mlp->c_q_start = col;
   mlp->c_q_end = col + mlp->m;
+  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]);
+  }
 
-  mlp->co_Q = GNUNET_malloc (mlp->m * sizeof (double));
-
   return res;
 }
 
@@ -285,24 +293,23 @@
  * @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 @@
   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 @@
   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 @@
   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();
 

Modified: gnunet/src/ats/gnunet-service-ats_addresses_mlp.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_mlp.h   2012-01-16 15:05:45 UTC 
(rev 19174)
+++ gnunet/src/ats/gnunet-service-ats_addresses_mlp.h   2012-01-16 17:10:07 UTC 
(rev 19175)
@@ -136,14 +136,19 @@
   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 @@
 /**
  * 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);
 
 
 /**

Modified: gnunet/src/ats/test_ats_mlp.c
===================================================================
--- gnunet/src/ats/test_ats_mlp.c       2012-01-16 15:05:45 UTC (rev 19174)
+++ gnunet/src/ats/test_ats_mlp.c       2012-01-16 17:10:07 UTC (rev 19175)
@@ -53,7 +53,7 @@
 #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);

Modified: gnunet/src/include/gnunet_ats_service.h
===================================================================
--- gnunet/src/include/gnunet_ats_service.h     2012-01-16 15:05:45 UTC (rev 
19174)
+++ gnunet/src/include/gnunet_ats_service.h     2012-01-16 17:10:07 UTC (rev 
19175)
@@ -402,7 +402,17 @@
       // 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
 
 /**




reply via email to

[Prev in Thread] Current Thread [Next in Thread]