gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r19185 - gnunet/src/ats


From: gnunet
Subject: [GNUnet-SVN] r19185 - gnunet/src/ats
Date: Tue, 17 Jan 2012 11:47:00 +0100

Author: wachs
Date: 2012-01-17 11:47:00 +0100 (Tue, 17 Jan 2012)
New Revision: 19185

Modified:
   gnunet/src/ats/gnunet-service-ats_addresses_mlp.c
   gnunet/src/ats/test_ats_mlp.c
Log:
- more mlp


Modified: gnunet/src/ats/gnunet-service-ats_addresses_mlp.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_mlp.c   2012-01-17 09:30:27 UTC 
(rev 19184)
+++ gnunet/src/ats/gnunet-service-ats_addresses_mlp.c   2012-01-17 10:47:00 UTC 
(rev 19185)
@@ -33,7 +33,20 @@
 #include "glpk.h"
 #endif
 
+/**
+ * Intercept GLPK terminal output
+ *
+ */
 
+static int
+mlp_term_hook (void *info, const char *s)
+{
+  /* Not needed atm struct MLP_information *mlp = info; */
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", s);
+  /* 0: glpk prints output on terminal, != surpress output */
+  return 1;
+}
+
 /**
  * Create the MLP problem
  *
@@ -79,8 +92,7 @@
   /* Column lower bound = 0.0 */
   glp_set_col_bnds (mlp->prob, col, GLP_LO, 0.0, 0.0);
 
-  /* Relitivity r column  */
-
+  /* Relativity r column  */
   col = glp_add_cols (mlp->prob, 1);
   mlp->c_r = col;
   /* Column name */
@@ -97,8 +109,10 @@
     mlp->c_q[c] = col + c;
     GNUNET_asprintf (&name, "q_%u", mlp->q[c]);
     glp_set_col_name (mlp->prob, col + c, name);
+    /* Column lower bound = 0.0 */
     glp_set_col_bnds (mlp->prob, col + c, GLP_LO, 0.0, 0.0);
     GNUNET_free (name);
+    /* Coefficient == Qm */
     glp_set_obj_coef (mlp->prob, col + c, mlp->co_Q[c]);
   }
 
@@ -157,7 +171,7 @@
       /* Problem was ill-defined, no way to handle that */
       GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
           "ats-mlp",
-          "Solving LP problem failed: glp_simplex error 0x%X", res);
+          "Solving LP problem failed: glp_simplex error 0x%X\n", res);
       return GNUNET_SYSERR;
     }
   }
@@ -186,7 +200,7 @@
     default:
       GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
           "ats-mlp",
-          "Solving LP problem failed, no solution: glp_get_status 0x%X", res);
+          "Solving LP problem failed, no solution: glp_get_status 0x%X\n", 
res);
       return GNUNET_SYSERR;
       break;
   }
@@ -234,7 +248,7 @@
     /* Problem was ill-defined, no way to handle that */
     GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
         "ats-mlp",
-        "Solving MLP problem failed: glp_intopt error 0x%X", res);
+        "Solving MLP problem failed: glp_intopt error 0x%X\n", res);
     return GNUNET_SYSERR;
   }
 
@@ -261,7 +275,7 @@
     default:
       GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
           "ats-mlp",
-          "Solving MLP problem failed, no solution: glp_mip_status 0x%X", res);
+          "Solving MLP problem failed, no solution: glp_mip_status 0x%X\n", 
res);
       return GNUNET_SYSERR;
       break;
   }
@@ -392,6 +406,9 @@
   mlp->max_iterations = max_iterations;
   mlp->max_exec_duration = max_duration;
 
+  /* Redirect GLPK output to GNUnet logging */
+  glp_error_hook((void *) mlp, &mlp_term_hook);
+
   /* Init LP solving parameters */
   glp_init_smcp(&mlp->control_param_lp);
 #if DEBUG_MLP
@@ -441,6 +458,9 @@
 GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct 
GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address)
 {
   int new;
+  int col;
+  struct MLP_information *mlpi;
+  char * name;
 
   GNUNET_STATISTICS_update (mlp->stats,"# LP address updates", 1, GNUNET_NO);
 
@@ -448,11 +468,35 @@
   if (address->mlp_information == NULL)
   {
     new = GNUNET_YES;
-    address->mlp_information = GNUNET_malloc (sizeof (struct MLP_information));
+    mlpi = GNUNET_malloc (sizeof (struct MLP_information));
+    address->mlp_information = mlpi;
 
-    /* Add bandwidth columns */
+    /* Add bandwidth column */
+    col = glp_add_cols (mlp->prob, 2);
+    mlpi->c_b = col;
+    mlpi->c_n = col + 1;
 
+    GNUNET_asprintf (&name, "b_%s_%s", GNUNET_i2s (&address->peer), 
address->plugin);
+    glp_set_col_name (mlp->prob, mlpi->c_b , name);
+    GNUNET_free (name);
+    /* Lower bound == 0 */
+    glp_set_col_bnds (mlp->prob, mlpi->c_b , GLP_LO, 0.0, 0.0);
+    /* Continuous value*/
+    glp_set_col_kind (mlp->prob, mlpi->c_b , GLP_CV);
+    /* Objective function coefficient == 0 */
+    glp_set_obj_coef (mlp->prob, mlpi->c_b , 0);
 
+    /* Add usage column */
+    GNUNET_asprintf (&name, "n_%s_%s", GNUNET_i2s (&address->peer), 
address->plugin);
+    glp_set_col_name (mlp->prob, mlpi->c_n, name);
+    GNUNET_free (name);
+    /* Limit value : 0 <= value <= 1 */
+    glp_set_col_bnds (mlp->prob, mlpi->c_n, GLP_DB, 0.0, 1.0);
+    /* Integer value*/
+    glp_set_col_kind (mlp->prob, mlpi->c_n, GLP_IV);
+    /* Objective function coefficient == 0 */
+    glp_set_obj_coef (mlp->prob, mlpi->c_n, 0);
+
     /* Add */
   }
   else

Modified: gnunet/src/ats/test_ats_mlp.c
===================================================================
--- gnunet/src/ats/test_ats_mlp.c       2012-01-17 09:30:27 UTC (rev 19184)
+++ gnunet/src/ats/test_ats_mlp.c       2012-01-17 10:47:00 UTC (rev 19185)
@@ -40,6 +40,8 @@
 
 struct GNUNET_STATISTICS_Handle * stats;
 
+struct GNUNET_CONTAINER_MultiHashMap * addresses;
+
 struct GAS_MLP_Handle *mlp;
 
 static void
@@ -51,13 +53,25 @@
   ret = 1;
   return;
 #endif
+  struct ATS_Address addr;
+
   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.plugin = strdup ("dummy");
+  GNUNET_CONTAINER_multihashmap_put(addresses, &addr.peer.hashPubKey, &addr, 
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+
   mlp = GAS_mlp_init (cfg, NULL, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
+
+  GAS_mlp_address_update(mlp, addresses, &addr);
+
   GNUNET_assert (mlp != NULL);
 
   GAS_mlp_done (mlp);
 
+  GNUNET_CONTAINER_multihashmap_destroy (addresses);
   GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
 
   ret = 0;




reply via email to

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