fixing mantis 2098:
[oweals/gnunet.git] / src / ats / gnunet-service-ats_addresses_mlp.h
index f72cb7c23f9426aa498be97a1a788191412a8903..43c2b66adfd09e36e954e69f3452c59d1835e006 100644 (file)
 #ifndef GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
 #define GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
 
-#define VERBOSE GNUNET_EXTRA_LOGGING
 #define DEBUG_MLP GNUNET_EXTRA_LOGGING
 
 #define MLP_MAX_EXEC_DURATION   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
 #define MLP_MAX_ITERATIONS      INT_MAX
 
+struct ATS_Peer
+{
+  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 */
+  double f;
+
+  /* constraint 2: 1 address per peer*/
+  unsigned int r_c2;
+
+  /* constraint 9: relativity */
+  unsigned int r_c9;
+
+  struct ATS_Address *head;
+  struct ATS_Address *tail;
+};
+
 /**
  * MLP Handle
  */
@@ -59,6 +80,8 @@ struct GAS_MLP_Handle
   void *prob;
 #endif
 
+  double BIG_M;
+
   /**
    * GLPK LP control parameter
    */
@@ -89,6 +112,13 @@ struct GAS_MLP_Handle
    */
   unsigned int max_iterations;
 
+  /**
+   * Solve the problem automatically when updates occur?
+   * Default: GNUNET_YES
+   * Can be disabled for test and measurements
+   */
+  int auto_solve;
+
   /* state information */
 
   /**
@@ -135,6 +165,33 @@ struct GAS_MLP_Handle
 
   /* Information about the problem */
 
+  struct ATS_Peer *peer_head;
+  struct ATS_Peer *peer_tail;
+
+  /* Number of peers */
+  unsigned int c_p;
+
+  /* current problem matrix */
+  /* row index array */
+  int *ia;
+  /* column index array */
+  int *ja;
+  /* column index array */
+  double *ar;
+  /* current size of the constraint matrix |indices| */
+  unsigned int cm_size;
+  unsigned int ci;
+
+  /* Row index constraint 2: */
+  unsigned int r_c2;
+  /* Row index constraint 4: minimum connections */
+  unsigned int r_c4;
+  /* Row index constraint 6: maximize diversity */
+  unsigned int r_c6;
+  /* Row index constraint 8: utilization*/
+  unsigned int r_c8;
+  /* Row index constraint 9: relativity*/
+  unsigned int r_c9;
 
   /* column index Diversity (D) column */
   int c_d;
@@ -149,6 +206,7 @@ struct GAS_MLP_Handle
   double co_R;
 
   /* ATS Quality metrics
+   *
    * array with GNUNET_ATS_QualityPropertiesCount elements
    * contains mapping to GNUNET_ATS_Property*/
   int q[GNUNET_ATS_QualityPropertiesCount];
@@ -156,11 +214,29 @@ struct GAS_MLP_Handle
   /* column index quality metrics  */
   int c_q[GNUNET_ATS_QualityPropertiesCount];
 
+  /* column index quality metrics  */
+  int r_q[GNUNET_ATS_QualityPropertiesCount];
+
   /* quality metric coefficients*/
   double co_Q[GNUNET_ATS_QualityPropertiesCount];
 
   /* number of quality metrics */
-  int m;
+  int m_q;
+
+  /* ATS ressource costs
+   *
+   * array with GNUNET_ATS_QualityPropertiesCount elements
+   * contains mapping to GNUNET_ATS_Property*/
+  int rc[GNUNET_ATS_QualityPropertiesCount];
+
+  /* column index ressource costs  */
+  int c_rc[GNUNET_ATS_QualityPropertiesCount];
+
+  /* ressource costs coefficients*/
+  double co_RC[GNUNET_ATS_QualityPropertiesCount];
+
+  /* number of quality metrics */
+  int m_rc;
 
   /* minimum bandwidth assigned to an address */
   unsigned int b_min;
@@ -180,6 +256,23 @@ struct MLP_information
 
   /* address usage column */
   signed int c_n;
+
+  /* row indexes */
+
+  /* constraint 1: bandwidth capping */
+  unsigned int r_c1;
+
+  /* constraint 3: minimum bandwidth */
+  unsigned int r_c3;
+
+  /* Quality information row indices */
+  unsigned int r_q[GNUNET_ATS_QualityPropertiesCount];
+
+  /* Quality information column indices */
+  unsigned int c_q[GNUNET_ATS_QualityPropertiesCount];
+
+  /* Quality information */
+  double q[GNUNET_ATS_QualityPropertiesCount];
 };
 
 
@@ -198,6 +291,15 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
               struct GNUNET_TIME_Relative max_duration,
               unsigned int max_iterations);
 
+/**
+ * Solves the MLP problem on demand
+ *
+ * @param mlp the MLP Handle
+ * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure
+ */
+int
+GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp);
+
 
 /**
  * Updates a single address in the MLP problem
@@ -210,6 +312,7 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
  *
  * @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
@@ -223,6 +326,7 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult
  *
  * @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
@@ -230,14 +334,18 @@ GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult
 
 
 /**
- * Deletes a single address in the MLP problem
+ * Changes the preferences for a peer in the MLP problem
  *
  * @param mlp the MLP Handle
- * @param addresses the address hashmap
- * @param address the address to change the preference
+ * @param peer the peer
+ * @param kind the kind to change the preference
+ * @param float the score
  */
 void
-GAS_mlp_address_change_preference (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address);
+GAS_mlp_address_change_preference (struct GAS_MLP_Handle *mlp,
+                                   const struct GNUNET_PeerIdentity *peer,
+                                   enum GNUNET_ATS_PreferenceKind kind,
+                                   float score);
 
 
 /**