- improved error logging
[oweals/gnunet.git] / src / ats / gnunet-service-ats_addresses_mlp.h
index 9272a291462130ea0afd1dc226d91246765ea30f..4b4b933196c44f74d71b4515378fa312c208f707 100644 (file)
@@ -25,7 +25,8 @@
  * @author Christian Grothoff
  */
 #include "platform.h"
-
+#include "gnunet_statistics_service.h"
+#include "gnunet-service-ats_addresses.h"
 #if HAVE_LIBGLPK
 #include "glpk.h"
 #endif
 #define MLP_MAX_EXEC_DURATION   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
 #define MLP_MAX_ITERATIONS      INT_MAX
 
+/**
+ * MLP Handle
+ */
 struct GAS_MLP_Handle
 {
+  /**
+   * Statistics handle
+   */
+  struct GNUNET_STATISTICS_Handle *stats;
+
   /**
    * GLPK (MLP) problem object
    */
@@ -70,7 +79,6 @@ struct GAS_MLP_Handle
    */
   unsigned int max_iterations;
 
-
   /* state information */
 
   /**
@@ -84,22 +92,141 @@ struct GAS_MLP_Handle
    * presolver_required == GNUNET_NO
    */
   int presolver_required;
+
+  /* statistics */
+
+  /**
+   * Time of last execution
+   */
+  struct GNUNET_TIME_Absolute last_execution;
+
+
+  /**
+   * How often was the LP problem solved
+   */
+  unsigned int lp_solved;
+
+  /**
+   * total duration of all lp solver executions
+   */
+  uint64_t lp_total_duration;
+
+  /**
+   * How often was the MLP problem solved
+   */
+  unsigned int mlp_solved;
+
+  /**
+   * total duration of all mlp solver executions
+   */
+  uint64_t mlp_total_duration;
+
+  /* Information about the problem */
+
+
+  /* column index Diversity (D) column */
+  int c_d;
+  double co_D;
+
+  /* column index Utilization (U) column */
+  int c_u;
+  double co_U;
+
+  /* column index Proportionality (R) column */
+  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 quality metrics  */
+  int c_q[GNUNET_ATS_QualityPropertiesCount];
+
+  /* quality metric coefficients*/
+  double co_Q[GNUNET_ATS_QualityPropertiesCount];
+
+  /* number of quality metrics */
+  int m;
+
+  /* minimum bandwidth assigned to an address */
+  unsigned int b_min;
+
+  /* minimum number of addresses with bandwidth assigned */
+  unsigned int n_min;
 };
 
+
+/**
+ * Address specific MLP information
+ */
+struct MLP_information
+{
+  /* bandwidth column index */
+  signed int c_b;
+
+  /* address usage column */
+  signed int c_n;
+};
+
+
 /**
  * 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
- * @return GNUNET_OK on success, GNUNET_SYSERR on fail
+ * @return struct GAS_MLP_Handle * on success, NULL on fail
  */
-int
-GAS_mlp_init (struct GNUNET_TIME_Relative max_duration, unsigned int max_iterations);
+struct GAS_MLP_Handle *
+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);
+
+
+/**
+ * Updates a single address in the MLP problem
+ *
+ * If the address did not exist before in the problem:
+ * The MLP problem has to be recreated and the problem has to be resolved
+ *
+ * Otherwise the addresses' values can be updated and the existing base can
+ * be reused
+ *
+ * @param mlp the MLP Handle
+ * @param addresses the address 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);
+
 
 /**
- * Update address in the MLP problem
+ * Deletes a single address in the MLP problem
+ *
+ * The MLP problem has to be recreated and the problem has to be resolved
+ *
+ * @param mlp the MLP Handle
+ * @param addresses the address hashmap
+ * @param address the address to delete
  */
 void
-GAS_mlp_update (struct ATS_Address *address);
+GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address);
+
+
+/**
+ * Deletes a single address in the MLP problem
+ *
+ * @param mlp the MLP Handle
+ * @param addresses the address hashmap
+ * @param address the address to change the preference
+ */
+void
+GAS_mlp_address_change_preference (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address);
+
 
 /**
  * Shutdown the MLP problem solving component