gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r26178 - gnunet/src/ats
Date: Thu, 21 Feb 2013 15:38:26 +0100

Author: wachs
Date: 2013-02-21 15:38:26 +0100 (Thu, 21 Feb 2013)
New Revision: 26178

Modified:
   gnunet/src/ats/gnunet-service-ats_addresses_mlp.c
   gnunet/src/ats/gnunet-service-ats_addresses_mlp.h
Log:
changes


Modified: gnunet/src/ats/gnunet-service-ats_addresses_mlp.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_mlp.c   2013-02-21 14:20:35 UTC 
(rev 26177)
+++ gnunet/src/ats/gnunet-service-ats_addresses_mlp.c   2013-02-21 14:38:26 UTC 
(rev 26178)
@@ -230,7 +230,32 @@
   }
 }
 
-#if 0
+/**
+ * Translate glpk status error codes to text
+ * @param retcode return code
+ * @return string with result
+ */
+const char *
+mlp_status_to_string (int retcode)
+{
+  switch (retcode) {
+    case GLP_UNDEF:
+      return "solution is undefined";
+    case GLP_FEAS:
+      return "solution is feasible";
+    case GLP_INFEAS:
+      return "solution is infeasible";
+    case GLP_NOFEAS:
+      return "no feasible solution exists";
+    case GLP_OPT:
+      return "solution is optimal";
+    case GLP_UNBND:
+      return "solution is unbounded";
+    default:
+      GNUNET_break (0);
+      return "unknown error";
+  }
+}
 
 /**
  * Translate glpk solver error codes to text
@@ -263,6 +288,8 @@
       return "time limit exceeded";
     case GLP_ENOPFS:
       return "no primal feasible solution";
+    case GLP_ENODFS:
+      return "no dual feasible solution";
     case GLP_EROOT:
       return "root LP optimum not provided";
     case GLP_ESTOP:
@@ -286,35 +313,8 @@
 }
 
 
+#if 0
 /**
- * Translate glpk status error codes to text
- * @param retcode return code
- * @return string with result
- */
-const char *
-mlp_status_to_string (int retcode)
-{
-  switch (retcode) {
-    case GLP_UNDEF:
-      return "solution is undefined";
-    case GLP_FEAS:
-      return "solution is feasible";
-    case GLP_INFEAS:
-      return "solution is infeasible";
-    case GLP_NOFEAS:
-      return "no feasible solution exists";
-    case GLP_OPT:
-      return "solution is optimal";
-    case GLP_UNBND:
-      return "solution is unbounded";
-    default:
-      GNUNET_break (0);
-      return "unknown error";
-  }
-}
-
-
-/**
  * Find a peer in the DLL
  *
  * @param mlp the mlp handle
@@ -1175,7 +1175,7 @@
                                p->ia[p->ci], p->ja[p->ci], p->ar[p->ci]);
 #endif
     p->ci++;
-
+#if 0
     for (tp = mlp->peer_head; tp != NULL; tp = tp->next)
       for (ta = tp->head; ta != NULL; ta = ta->next)
         {
@@ -1193,6 +1193,7 @@
 #endif
           p->ci++;
         }
+#endif
   }
 }
 
@@ -1212,6 +1213,7 @@
   struct GAS_MLP_Handle *mlp = cls;
   struct MLP_Problem *p = &mlp->p;
   struct ATS_Address *address = value;
+  struct ATS_Peer *peer;
   struct MLP_information *mlpi;
   unsigned int col;
   char *name;
@@ -1226,6 +1228,10 @@
   if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(mlp->peers, key))
        return GNUNET_OK;
 
+  /* Get peer */
+  peer = GNUNET_CONTAINER_multihashmap_get (mlp->peers, key);
+  peer->processed = GNUNET_NO;
+
        p->num_addresses ++;
   mlpi = GNUNET_malloc (sizeof (struct MLP_information));
   address->solver_information = mlpi;
@@ -1378,15 +1384,92 @@
 
   /* Load the matrix */
        LOG (GNUNET_ERROR_TYPE_DEBUG, "Loading matrix\n");
-  //glp_load_matrix(mlp->prob, (mlp->ci-1), mlp->ia, mlp->ja, mlp->ar);
+  glp_load_matrix(p->prob, (p->ci)-1, p->ia, p->ja, p->ar);
 
   return res;
 }
 
+/**
+ * Solves the LP problem
+ *
+ * @param mlp the MLP Handle
+ * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure
+ */
+static int
+mlp_solve_lp_problem (struct GAS_MLP_Handle *mlp)
+{
+       int res = 0;
+       if (GNUNET_YES == mlp->mlp_prob_changed)
+       {
+               /* Problem was recreated: use LP presolver */
+    mlp->control_param_lp.presolve = GLP_ON;
+       }
+       else
+       {
+               /* Problem was not recreated: do not use LP presolver */
+               mlp->control_param_lp.presolve = GLP_OFF;
+       }
 
+       res = glp_simplex(mlp->p.prob, &mlp->control_param_lp);
+       if (0 == res)
+               LOG (GNUNET_ERROR_TYPE_DEBUG, "Solving LP problem: 0x%02X 
%s\n", res, mlp_solve_to_string(res));
+       else
+               LOG (GNUNET_ERROR_TYPE_DEBUG, "Solving LP problem failed: 
0x%02X %s\n", res, mlp_solve_to_string(res));
+
+  /* Analyze problem status  */
+  res = glp_get_status (mlp->p.prob);
+  switch (res) {
+    /* solution is optimal */
+    case GLP_OPT:
+    /* solution is feasible */
+    case GLP_FEAS:
+      LOG (GNUNET_ERROR_TYPE_DEBUG, "Solving LP problem: 0x%02X %s\n",
+               res, mlp_status_to_string(res));
+      return GNUNET_OK;
+    /* Problem was ill-defined, no way to handle that */
+    default:
+      LOG (GNUNET_ERROR_TYPE_DEBUG, "Solving LP problem failed, no solution: 
0x%02X %s\n",
+               res, mlp_status_to_string(res));
+      return GNUNET_SYSERR;
+  }
+}
+
+
 /**
  * Solves the MLP problem
  *
+ * @param mlp the MLP Handle
+ * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure
+ */
+int
+mlp_solve_mlp_problem (struct GAS_MLP_Handle *mlp)
+{
+       int res = 0;
+       res = glp_intopt(mlp->p.prob, &mlp->control_param_mlp);
+       if (0 == res)
+               LOG (GNUNET_ERROR_TYPE_DEBUG, "Solving MLP problem: 0x%02X 
%s\n", res, mlp_solve_to_string(res));
+       else
+               LOG (GNUNET_ERROR_TYPE_DEBUG, "Solving MLP problem failed: 
0x%02X %s\n", res, mlp_solve_to_string(res));
+  /* Analyze problem status  */
+  res = glp_mip_status(mlp->p.prob);
+  switch (res) {
+    /* solution is optimal */
+    case GLP_OPT:
+    /* solution is feasible */
+    case GLP_FEAS:
+      LOG (GNUNET_ERROR_TYPE_DEBUG, "Solving LP problem: %s\n", 
mlp_status_to_string(res));
+      return GNUNET_OK;
+    /* Problem was ill-defined, no way to handle that */
+    default:
+      LOG (GNUNET_ERROR_TYPE_DEBUG,"Solving MLP problem failed, %s\n\n", 
mlp_status_to_string(res));
+      return GNUNET_SYSERR;
+  }
+}
+
+
+/**
+ * Solves the MLP problem
+ *
  * @param solver the MLP Handle
  * @param addresses the address hashmap
  * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure
@@ -1396,7 +1479,10 @@
 {
        struct GAS_MLP_Handle *mlp = solver;
        int res = 0;
-
+       struct GNUNET_TIME_Absolute start_lp;
+       struct GNUNET_TIME_Relative duration_lp;
+       struct GNUNET_TIME_Absolute start_mlp;
+       struct GNUNET_TIME_Relative duration_mlp;
        GNUNET_assert (NULL != solver);
 
        if ((GNUNET_NO == mlp->mlp_prob_changed) && (GNUNET_NO == 
mlp->mlp_prob_updated))
@@ -1416,6 +1502,27 @@
                        LOG (GNUNET_ERROR_TYPE_DEBUG, "Problem was updated, 
resolving\n");
        }
 
+       /* Run LP solver */
+       LOG (GNUNET_ERROR_TYPE_DEBUG, "Running LP solver \n");
+       start_lp = GNUNET_TIME_absolute_get();
+       mlp_solve_lp_problem (mlp);
+       duration_lp = GNUNET_TIME_absolute_get_duration (start_lp);
+
+  /* Run LP solver */
+       LOG (GNUNET_ERROR_TYPE_DEBUG, "Running MLP solver \n");
+       start_mlp = GNUNET_TIME_absolute_get();
+       mlp_solve_lp_problem (mlp);
+       duration_mlp = GNUNET_TIME_absolute_get_duration (start_mlp);
+       LOG (GNUNET_ERROR_TYPE_DEBUG, "Solver took LP %llu ms,  MLP %llu ms\n",
+                       (unsigned long long) duration_lp.rel_value,
+                       (unsigned long long) duration_mlp.rel_value);
+
+       /* Reset change and update marker */
+       mlp->mlp_prob_updated = GNUNET_NO;
+       mlp->mlp_prob_changed = GNUNET_NO;
+
+       return res;
+
        /* Solve problem */
 #if 0
   struct GAS_MLP_Handle *mlp = solver;
@@ -1544,12 +1651,6 @@
   mlp->semaphore = GNUNET_NO;
   return res;
 #endif
-
-       /* Reset change and update marker */
-       mlp->mlp_prob_updated = GNUNET_NO;
-       mlp->mlp_prob_changed = GNUNET_NO;
-
-       return res;
 }
 
 /**
@@ -1950,34 +2051,9 @@
 GAS_mlp_done (void *solver)
 {
   struct GAS_MLP_Handle *mlp = solver;
-  struct ATS_Peer * peer;
-  struct ATS_Address *addr;
-
   GNUNET_assert (mlp != NULL);
 
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down mlp solver\n");
-
-  if (mlp->mlp_task != GNUNET_SCHEDULER_NO_TASK)
-  {
-    GNUNET_SCHEDULER_cancel(mlp->mlp_task);
-    mlp->mlp_task = GNUNET_SCHEDULER_NO_TASK;
-  }
-
-  /* clean up peer list */
-  peer = mlp->peer_head;
-  while (peer != NULL)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up peer `%s'\n", GNUNET_i2s 
(&peer->id));
-    GNUNET_CONTAINER_DLL_remove(mlp->peer_head, mlp->peer_tail, peer);
-    for (addr = peer->head; NULL != addr; addr = peer->head)
-    {
-      GNUNET_CONTAINER_DLL_remove(peer->head, peer->tail, addr);
-      GNUNET_free (addr->solver_information);
-      addr->solver_information = NULL;
-    }
-    GNUNET_free (peer);
-    peer = mlp->peer_head;
-  }
   mlp_delete_problem (mlp);
 
   GNUNET_CONTAINER_multihashmap_iterate (mlp->peers, &mlp_free_peers, 
mlp->peers);
@@ -2023,7 +2099,6 @@
   unsigned long long tmp;
   unsigned int b_min;
   unsigned int n_min;
-  struct GNUNET_TIME_Relative i_exec;
   int c;
   int c2;
   int found;
@@ -2214,14 +2289,6 @@
                        }
   }
 
-  /* Get minimum number of connections from configuration */
-  if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_time (cfg, "ats",
-                                                        "MLP_EXEC_INTERVAL",
-                                                        &i_exec))
-    mlp->exec_interval = i_exec;
-  else
-    mlp->exec_interval = 
GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30);
-
   /* Assign options to handle */
   mlp->stats = (struct GNUNET_STATISTICS_Handle *) stats;
   mlp->bw_changed_cb = bw_changed_cb;
@@ -2233,12 +2300,6 @@
   mlp->pv.b_min = b_min;
   mlp->pv.n_min = n_min;
   mlp->pv.m_q = GNUNET_ATS_QualityPropertiesCount;
-
-  mlp->semaphore = GNUNET_NO;
-  mlp->max_iterations = max_iterations;
-  mlp->max_exec_duration = max_duration;
-  mlp->last_execution = GNUNET_TIME_UNIT_FOREVER_ABS;
-  mlp->auto_solve = GNUNET_YES;
   mlp->mlp_prob_changed = GNUNET_NO;
   mlp->mlp_prob_updated = GNUNET_NO;
 

Modified: gnunet/src/ats/gnunet-service-ats_addresses_mlp.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_mlp.h   2013-02-21 14:20:35 UTC 
(rev 26177)
+++ gnunet/src/ats/gnunet-service-ats_addresses_mlp.h   2013-02-21 14:38:26 UTC 
(rev 26178)
@@ -52,11 +52,16 @@
 
 struct ATS_Peer
 {
+       struct GNUNET_PeerIdentity id;
+
+       /* Was this peer already added to the current problem? */
+       int processed;
+#if 0
   struct ATS_Peer *next;
   struct ATS_Peer *prev;
 
-  struct GNUNET_PeerIdentity id;
 
+
   /* Array of quality preferences */
   double f_q[GNUNET_ATS_QualityPropertiesCount];
   /* Legacy preference value */
@@ -70,6 +75,7 @@
 
   struct ATS_Address *head;
   struct ATS_Address *tail;
+#endif
 };
 
 struct GAS_MLP_SolutionContext
@@ -216,8 +222,6 @@
 
   struct MLP_Variables pv;
 
-
-
   /**
    * GLPK LP control parameter
    */
@@ -251,11 +255,8 @@
    */
   int mlp_prob_changed;
 
-  /**
-   * Solves the task in an regular interval
-   */
-  GNUNET_SCHEDULER_TaskIdentifier mlp_task;
 
+#if 0
   /**
    * Interval between scheduled problem solving
    */
@@ -329,6 +330,7 @@
 
   struct ATS_Peer *peer_head;
   struct ATS_Peer *peer_tail;
+#endif
 };
 
 




reply via email to

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