gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r19247 - gnunet/src/ats
Date: Wed, 18 Jan 2012 19:01:57 +0100

Author: wachs
Date: 2012-01-18 19:01:57 +0100 (Wed, 18 Jan 2012)
New Revision: 19247

Modified:
   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
Log:
- more changes


Modified: gnunet/src/ats/gnunet-service-ats_addresses_mlp.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_mlp.c   2012-01-18 16:47:05 UTC 
(rev 19246)
+++ gnunet/src/ats/gnunet-service-ats_addresses_mlp.c   2012-01-18 18:01:57 UTC 
(rev 19247)
@@ -34,8 +34,7 @@
 #endif
 #include "float.h"
 
-#define DEBUG_ATS GNUNET_NO
-
+#define DEBUG_ATS GNUNET_YES
 /* A very big value */
 #define M DBL_MAX
 
@@ -175,19 +174,31 @@
 {
   if (mlp != NULL)
   {
-    glp_delete_prob(mlp->prob);
+    if (mlp->prob != NULL)
+      glp_delete_prob(mlp->prob);
 
     /* delete row index */
     if (mlp->ia != NULL)
+    {
       GNUNET_free (mlp->ia);
+      mlp->ja = NULL;
+    }
 
     /* delete column index */
     if (mlp->ja != NULL)
+    {
       GNUNET_free (mlp->ja);
+      mlp->ja = NULL;
+    }
 
     /* delete coefficients */
     if (mlp->ar != NULL)
+    {
       GNUNET_free (mlp->ar);
+      mlp->ar = NULL;
+    }
+    mlp->ci = 0;
+    mlp->prob = NULL;
   }
 }
 
@@ -372,7 +383,60 @@
   }
 }
 
+
 /**
+ * Add columns for all addresses
+ *
+ * @param cls GAS_MLP_Handle
+ * @param key Hashcode
+ * @param value ATS_Address
+ *
+ * @return GNUNET_OK to continue
+ */
+static int
+create_columns_it (void *cls, const GNUNET_HashCode * key, void *value)
+{
+  struct GAS_MLP_Handle *mlp = cls;
+  struct ATS_Address *address = value;
+  struct MLP_information *mlpi;
+  unsigned int col;
+  char *name;
+
+  GNUNET_assert (address->mlp_information != NULL);
+  mlpi = address->mlp_information;
+
+  /* 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);
+
+  return GNUNET_OK;
+}
+
+
+
+/**
  * Create the MLP problem
  *
  * @param mlp the MLP handle
@@ -441,8 +505,12 @@
     glp_set_obj_coef (mlp->prob, col + c, mlp->co_Q[c]);
   }
 
-  /* Add columns for existing addresses */
+  /* Add columns for addresses */
+  GNUNET_CONTAINER_multihashmap_iterate (addresses, create_columns_it, mlp);
 
+  /* Add constraints */
+  mlp_add_constraints_all_addresses (mlp, addresses);
+
   return res;
 }
 
@@ -644,6 +712,10 @@
   res = mlp_solve_lp_problem (mlp);
   if (res == GNUNET_OK)
     res = mlp_solve_mlp_problem (mlp);
+
+
+  /* Process result */
+
   if (mlp->mlp_task != GNUNET_SCHEDULER_NO_TASK)
   {
     GNUNET_SCHEDULER_cancel(mlp->mlp_task);
@@ -813,15 +885,14 @@
  *
  * @param mlp the MLP Handle
  * @param addresses the address hashmap
+ *        the address has to be already removed from the hashmap
  * @param address the address to update
  */
 void
 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);
 
@@ -831,12 +902,6 @@
   else
     new = GNUNET_NO;
 
-  if (mlp->prob == NULL)
-  {
-    mlp_create_problem(mlp, addresses);
-    mlp_add_constraints_all_addresses (mlp, addresses);
-  }
-
   /* Do the update */
   if (new == GNUNET_YES)
   {
@@ -874,33 +939,6 @@
 #endif
       GNUNET_CONTAINER_DLL_insert (peer->head, peer->tail, address);
     }
-
-
-    /* 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);
   }
   else
   {
@@ -922,6 +960,7 @@
  *
  * @param mlp the MLP Handle
  * @param addresses the address hashmap
+ *        the address has to be already removed from the hashmap
  * @param address the address to delete
  */
 void
@@ -951,7 +990,6 @@
   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting address for `%s'\n", 
GNUNET_i2s (&address->peer));
 #endif
   GNUNET_CONTAINER_DLL_remove (head->head, head->tail, address);
-  mlp->c_p --;
   if ((head->head == NULL) && (head->tail == NULL))
   {
     /* No address for peer left, remove peer */
@@ -960,13 +998,22 @@
 #endif
     GNUNET_CONTAINER_DLL_remove (mlp->peer_head, mlp->peer_tail, head);
     GNUNET_free (head);
+    mlp->c_p --;
   }
 
   /* Update problem */
+  mlp_delete_problem (mlp);
+  if ((GNUNET_CONTAINER_multihashmap_size (addresses) > 0) && (mlp->c_p > 0))
+  {
+#if DEBUG_ATS
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "mlp_create_problem %i\n",__LINE__);
+#endif
+    mlp_create_problem (mlp, addresses);
 
-  /* Recalculate */
-  mlp->presolver_required = GNUNET_YES;
-  mlp_solve_problem (mlp);
+    /* Recalculate */
+    mlp->presolver_required = GNUNET_YES;
+    mlp_solve_problem (mlp);
+  }
 }
 
 /**

Modified: gnunet/src/ats/gnunet-service-ats_addresses_mlp.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_mlp.h   2012-01-18 16:47:05 UTC 
(rev 19246)
+++ gnunet/src/ats/gnunet-service-ats_addresses_mlp.h   2012-01-18 18:01:57 UTC 
(rev 19247)
@@ -248,6 +248,7 @@
  *
  * @param mlp the MLP Handle
  * @param addresses the address hashmap
+ *        the address has to be already added from the hashmap
  * @param address the address to update
  */
 void
@@ -261,6 +262,7 @@
  *
  * @param mlp the MLP Handle
  * @param addresses the address hashmap
+ *        the address has to be already removed from the hashmap
  * @param address the address to delete
  */
 void

Modified: gnunet/src/ats/test_ats_mlp.c
===================================================================
--- gnunet/src/ats/test_ats_mlp.c       2012-01-18 16:47:05 UTC (rev 19246)
+++ gnunet/src/ats/test_ats_mlp.c       2012-01-18 18:01:57 UTC (rev 19247)
@@ -79,6 +79,7 @@
   GNUNET_assert (mlp->addr_in_problem == 1);
 
   /* Delete an address */
+  GNUNET_CONTAINER_multihashmap_remove (addresses, &addr.peer.hashPubKey, 
&addr);
   GAS_mlp_address_delete (mlp, addresses, &addr);
 
   GAS_mlp_done (mlp);




reply via email to

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