/*
This file is part of GNUnet.
- (C) 2011 Christian Grothoff (and other contributing authors)
+ (C) 2011-2014 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
*/
#include "plugin_ats_mlp.h"
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_ats_service.h"
+#include "gnunet_ats_plugin.h"
+#include "gnunet-service-ats_addresses.h"
+#include "gnunet_statistics_service.h"
+#include <float.h>
+#include <glpk.h>
+
+
+#define BIG_M_VALUE (UINT32_MAX) /10
+#define BIG_M_STRING "unlimited"
+
+#define MLP_AVERAGING_QUEUE_LENGTH 3
+
+#define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
+#define MLP_MAX_ITERATIONS 4096
+
+#define DEFAULT_D 1.0
+#define DEFAULT_R 1.0
+#define DEFAULT_U 1.0
+#define DEFAULT_QUALITY 1.0
+#define DEFAULT_MIN_CONNECTIONS 4
+#define DEFAULT_PEER_PREFERENCE 1.0
+
+#define MLP_NaN -1
+#define MLP_UNDEFINED 0
+#define GLP_YES 1.0
+#define GLP_NO 0.0
+
+enum MLP_Output_Format
+{
+ MLP_MPS,
+ MLP_CPLEX,
+ MLP_GLPK
+};
+
+
+struct MLP_Solution
+{
+ int lp_res;
+ int lp_presolv;
+ int mip_res;
+ int mip_presolv;
+
+ double lp_objective_value;
+ double mlp_objective_value;
+ double mlp_gap;
+ double lp_mlp_gap;
+
+ int p_elements;
+ int p_cols;
+ int p_rows;
+
+ int n_peers;
+ int n_addresses;
+
+};
+
+struct ATS_Peer
+{
+ struct GNUNET_PeerIdentity id;
+
+ /* Was this peer already added to the current problem? */
+ int processed;
+
+ /* constraint 2: 1 address per peer*/
+ unsigned int r_c2;
+
+ /* constraint 9: relativity */
+ unsigned int r_c9;
+
+ /* Legacy preference value */
+ double f;
+};
+
+struct MLP_Problem
+{
+ /**
+ * GLPK (MLP) problem object
+ */
+ glp_prob *prob;
+
+ /* Number of addresses in problem */
+ unsigned int num_addresses;
+ /* Number of peers in problem */
+ unsigned int num_peers;
+ /* Number of elements in problem matrix */
+ unsigned int num_elements;
+
+ /* 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;
+ /* Row indices quality metrics */
+ int r_q[GNUNET_ATS_QualityPropertiesCount];
+ /* Row indices ATS network quotas */
+ int r_quota[GNUNET_ATS_NetworkTypeCount];
+
+ /* Column index Diversity (D) column */
+ int c_d;
+ /* Column index Utilization (U) column */
+ int c_u;
+ /* Column index Proportionality (R) column */
+ int c_r;
+ /* Column index quality metrics */
+ int c_q[GNUNET_ATS_QualityPropertiesCount];
+
+ /* Problem matrix */
+ /* Current index */
+ unsigned int ci;
+ /* Row index array */
+ int *ia;
+ /* Column index array */
+ int *ja;
+ /* Column index value */
+ double *ar;
+
+};
+
+struct MLP_Variables
+{
+ /* Big M value for bandwidth capping */
+ double BIG_M;
+
+ /* MIP Gap */
+ double mip_gap;
+
+ /* LP MIP Gap */
+ double lp_mip_gap;
+
+ /* ATS Quality metrics
+ *
+ * Array with GNUNET_ATS_QualityPropertiesCount elements
+ * contains mapping to GNUNET_ATS_Property*/
+ int q[GNUNET_ATS_QualityPropertiesCount];
+
+ /* Number of quality metrics */
+ int m_q;
+
+ /* Number of quality metrics */
+ int m_rc;
+
+ /* Quality metric coefficients*/
+ double co_Q[GNUNET_ATS_QualityPropertiesCount];
+
+ /* Ressource costs coefficients*/
+ double co_RC[GNUNET_ATS_QualityPropertiesCount];
+
+ /* Diversity coefficient */
+ double co_D;
+
+ /* Utility coefficient */
+ double co_U;
+
+ /* Relativity coefficient */
+ double co_R;
+
+ /* Minimum bandwidth assigned to an address */
+ unsigned int b_min;
+
+ /* Minimum number of addresses with bandwidth assigned */
+ unsigned int n_min;
+
+ /* Quotas */
+ /* Array mapping array index to ATS network */
+ int quota_index[GNUNET_ATS_NetworkTypeCount];
+ /* Outbound quotas */
+ unsigned long long quota_out[GNUNET_ATS_NetworkTypeCount];
+ /* Inbound quotas */
+
+ unsigned long long quota_in[GNUNET_ATS_NetworkTypeCount];
+
+ /* ATS ressource costs
+ * array with GNUNET_ATS_QualityPropertiesCount elements
+ * contains mapping to GNUNET_ATS_Property
+ * */
+ int rc[GNUNET_ATS_QualityPropertiesCount];
+
+};
+
+/**
+ * MLP Handle
+ */
+struct GAS_MLP_Handle
+{
+ struct GNUNET_ATS_PluginEnvironment *env;
+
+ /**
+ * Statistics handle
+ */
+ struct GNUNET_STATISTICS_Handle *stats;
+
+ /**
+ * Address hashmap for lookups
+ */
+ const struct GNUNET_CONTAINER_MultiPeerMap *addresses;
+
+ /**
+ * Addresses' bandwidth changed callback
+ */
+ GAS_bandwidth_changed_cb bw_changed_cb;
+
+ /**
+ * Addresses' bandwidth changed callback closure
+ */
+ void *bw_changed_cb_cls;
+
+ /**
+ * ATS function to get preferences
+ */
+ GAS_get_preferences get_preferences;
+
+ /**
+ * Closure for ATS function to get preferences
+ */
+ void *get_preferences_cls;
+
+ /**
+ * ATS function to get properties
+ */
+ GAS_get_properties get_properties;
+
+ /**
+ * Closure for ATS function to get properties
+ */
+ void *get_properties_cls;
+
+ /**
+ * Exclude peer from next result propagation
+ */
+ const struct GNUNET_PeerIdentity *exclude_peer;
+
+ /**
+ * Encapsulation for the MLP problem
+ */
+ struct MLP_Problem p;
+
+ /**
+ * Encapsulation for the MLP problem variables
+ */
+ struct MLP_Variables pv;
+
+ /**
+ * Encapsulation for the MLP solution
+ */
+ struct MLP_Solution ps;
+
+ /**
+ * Bulk lock
+ */
+
+ int stat_bulk_lock;
+
+ /**
+ * Number of changes while solver was locked
+ */
+ int stat_bulk_requests;
+
+ /**
+ * GLPK LP control parameter
+ */
+ glp_smcp control_param_lp;
+
+ /**
+ * GLPK LP control parameter
+ */
+ glp_iocp control_param_mlp;
+
+ /**
+ * Peers with pending address requests
+ */
+ struct GNUNET_CONTAINER_MultiPeerMap *requested_peers;
+
+ /**
+ * Was the problem updated since last solution
+ */
+ int stat_mlp_prob_updated;
+
+ /**
+ * Has the problem size changed since last solution
+ */
+ int stat_mlp_prob_changed;
+
+ /**
+ * Solve the problem automatically when updates occur?
+ * Default: GNUNET_YES
+ * Can be disabled for test and measurements
+ */
+ int opt_mlp_auto_solve;
+
+ /**
+ * Write all MILP problems to a MPS file
+ */
+ int opt_dump_problem_all;
+
+ /**
+ * Write all MILP problem solutions to a file
+ */
+ int opt_dump_solution_all;
+
+ /**
+ * Write MILP problems to a MPS file when solver fails
+ */
+ int opt_dump_problem_on_fail;
+
+ /**
+ * Write MILP problem solutions to a file when solver fails
+ */
+ int opt_dump_solution_on_fail;
+
+ /**
+ * solve feasibility only
+ */
+ int opt_dbg_feasibility_only;
+
+ /**
+ * solve autoscale the problem
+ */
+ int opt_dbg_autoscale_problem;
+
+ /**
+ * use the intopt presolver instead of simplex
+ */
+ int opt_dbg_intopt_presolver;
+
+ /**
+ * Print GLPK output
+ */
+ int opt_dbg_glpk_verbose;
+
+ /**
+ * solve autoscale the problem
+ */
+ int opt_dbg_optimize_relativity;
+
+ /**
+ * solve autoscale the problem
+ */
+ int opt_dbg_optimize_diversity;
+
+ /**
+ * solve autoscale the problem
+ */
+ int opt_dbg_optimize_quality;
+
+ /**
+ * solve autoscale the problem
+ */
+ int opt_dbg_optimize_utility;
+
+
+ /**
+ * Output format
+ */
+ enum MLP_Output_Format opt_log_format;
+};
+
+/**
+ * Address specific MLP information
+ */
+struct MLP_information
+{
+
+ /* Bandwidth assigned */
+ struct GNUNET_BANDWIDTH_Value32NBO b_out;
+ struct GNUNET_BANDWIDTH_Value32NBO b_in;
+
+ /* Address selected */
+ int n;
+
+ /* bandwidth column index */
+ signed int c_b;
+
+ /* 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;
+};
+
/**
mlp_term_hook (void *info, const char *s)
{
struct GAS_MLP_Handle *mlp = info;
+
if (mlp->opt_dbg_glpk_verbose)
LOG (GNUNET_ERROR_TYPE_ERROR, "%s", s);
return 1;
* @param ats_index the ATS index
* @return string with result
*/
-const char *
+static const char *
mlp_ats_to_string (int ats_index)
{
switch (ats_index) {
* @param retcode return code
* @return string with result
*/
-const char *
+static const char *
mlp_status_to_string (int retcode)
{
switch (retcode) {
}
}
+
/**
* Translate glpk solver error codes to text
* @param retcode return code
* @return string with result
*/
-const char *
+static const char *
mlp_solve_to_string (int retcode)
{
switch (retcode) {
return GNUNET_OK;
}
+
/**
* Create the invariant columns c4, c6, c10, c8, c7
*/
* Create the MLP problem
*
* @param mlp the MLP handle
- * @return GNUNET_OK or GNUNET_SYSERR
+ * @return #GNUNET_OK or #GNUNET_SYSERR
*/
static int
mlp_create_problem (struct GAS_MLP_Handle *mlp)
return res;
}
+
/**
* Solves the LP problem
*
* @param mlp the MLP Handle
- * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure
+ * @return #GNUNET_OK if could be solved, #GNUNET_SYSERR on failure
*/
static int
mlp_solve_lp_problem (struct GAS_MLP_Handle *mlp)
* @param value the address
* @return #GNUNET_OK to continue
*/
-int
+static int
mlp_propagate_results (void *cls,
const struct GNUNET_PeerIdentity *key,
void *value)
return GNUNET_OK;
}
-static void notify (struct GAS_MLP_Handle *mlp,
- enum GAS_Solver_Operation op,
- enum GAS_Solver_Status stat,
- enum GAS_Solver_Additional_Information add)
+
+static void
+notify (struct GAS_MLP_Handle *mlp,
+ enum GAS_Solver_Operation op,
+ enum GAS_Solver_Status stat,
+ enum GAS_Solver_Additional_Information add)
{
if (NULL != mlp->env->info_cb)
mlp->env->info_cb (mlp->env->info_cb_cls, op, stat, add);
}
-static void mlp_branch_and_cut_cb (glp_tree *tree, void *info)
+
+static void
+mlp_branch_and_cut_cb (glp_tree *tree, void *info)
{
struct GAS_MLP_Handle *mlp = info;
double mlp_obj = 0;
* Solves the MLP problem
*
* @param solver the MLP Handle
- * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure
+ * @return #GNUNET_OK if could be solved, #GNUNET_SYSERR on failure
*/
-int
+static int
GAS_mlp_solve_problem (void *solver)
{
struct GAS_MLP_Handle *mlp = solver;
* @param address the address to add
* @param network network type of this address
*/
-void
+static void
GAS_mlp_address_add (void *solver,
struct ATS_Address *address,
uint32_t network)
* @param abs_value the absolute value of the property
* @param rel_value the normalized value
*/
-void
+static void
GAS_mlp_address_property_changed (void *solver,
struct ATS_Address *address,
uint32_t type,
* @param cur_session the current session
* @param new_session the new session
*/
-void
+static void
GAS_mlp_address_session_changed (void *solver,
struct ATS_Address *address,
uint32_t cur_session,
* @param address the address
* @param in_use usage state
*/
-void
+static void
GAS_mlp_address_inuse_changed (void *solver,
struct ATS_Address *address,
int in_use)
* @param current_network the current network
* @param new_network the new network
*/
-void
+static void
GAS_mlp_address_change_network (void *solver,
struct ATS_Address *address,
uint32_t current_network,
* @param address the address to delete
* @param session_only delete only session not whole address
*/
-void
+static void
GAS_mlp_address_delete (void *solver,
- struct ATS_Address *address,
- int session_only)
+ struct ATS_Address *address,
+ int session_only)
{
struct ATS_Peer *p;
struct GAS_MLP_Handle *mlp = solver;
* @param peer the peer
* @return suggested address
*/
-const struct ATS_Address *
+static const struct ATS_Address *
GAS_mlp_get_preferred_address (void *solver,
const struct GNUNET_PeerIdentity *peer)
{
*
* @param solver the solver
*/
-void
+static void
GAS_mlp_bulk_start (void *solver)
{
LOG (GNUNET_ERROR_TYPE_DEBUG, "Locking solver for bulk operation ...\n");
s->stat_bulk_lock ++;
}
-void
+
+static void
GAS_mlp_bulk_stop (void *solver)
{
LOG (GNUNET_ERROR_TYPE_DEBUG, "Unlocking solver from bulk operation ...\n");
* @param solver the MLP handle
* @param peer the peer
*/
-void
+static void
GAS_mlp_stop_get_preferred_address (void *solver,
const struct GNUNET_PeerIdentity *peer)
{
* @param kind the kind to change the preference
* @param pref_rel the relative score
*/
-void
+static void
GAS_mlp_address_change_preference (void *solver,
const struct GNUNET_PeerIdentity *peer,
enum GNUNET_ATS_PreferenceKind kind,
* @param kind the kind to change the preference
* @param score the score
*/
-void
+static void
GAS_mlp_address_preference_feedback (void *solver,
void *application,
const struct GNUNET_PeerIdentity *peer,
struct GAS_MLP_Handle *mlp = cls;
GNUNET_assert (mlp != NULL);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down mlp solver\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Shutting down mlp solver\n");
mlp_delete_problem (mlp);
GNUNET_CONTAINER_multipeermap_iterate (mlp->requested_peers,
glp_free_env();
GNUNET_free (mlp);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutdown down of mlp solver complete\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Shutdown down of mlp solver complete\n");
return NULL;
}
+++ /dev/null
-/*
- (C) 2011 Christian Grothoff (and other contributing authors)
-
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
- */
-
-/**
- * @file ats/plugin_ats_mlp.h
- * @brief ats MLP problem solver
- * @author Matthias Wachs
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_ats_service.h"
-#include "gnunet_ats_plugin.h"
-#include "gnunet-service-ats_addresses.h"
-#include "gnunet_statistics_service.h"
-#include <float.h>
-#if HAVE_LIBGLPK
-#include "glpk.h"
-#endif
-
-#ifndef GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
-#define GNUNET_SERVICE_ATS_ADDRESSES_MLP_H
-
-#define BIG_M_VALUE (UINT32_MAX) /10
-#define BIG_M_STRING "unlimited"
-
-#define MLP_AVERAGING_QUEUE_LENGTH 3
-
-#define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
-#define MLP_MAX_ITERATIONS 4096
-
-#define DEFAULT_D 1.0
-#define DEFAULT_R 1.0
-#define DEFAULT_U 1.0
-#define DEFAULT_QUALITY 1.0
-#define DEFAULT_MIN_CONNECTIONS 4
-#define DEFAULT_PEER_PREFERENCE 1.0
-
-#define MLP_NaN -1
-#define MLP_UNDEFINED 0
-#define GLP_YES 1.0
-#define GLP_NO 0.0
-
-enum MLP_Output_Format
-{
- MLP_MPS,
- MLP_CPLEX,
- MLP_GLPK
-};
-
-
-struct MLP_Solution
-{
- int lp_res;
- int lp_presolv;
- int mip_res;
- int mip_presolv;
-
- double lp_objective_value;
- double mlp_objective_value;
- double mlp_gap;
- double lp_mlp_gap;
-
- int p_elements;
- int p_cols;
- int p_rows;
-
- int n_peers;
- int n_addresses;
-
-};
-
-struct ATS_Peer
-{
- struct GNUNET_PeerIdentity id;
-
- /* Was this peer already added to the current problem? */
- int processed;
-
- /* constraint 2: 1 address per peer*/
- unsigned int r_c2;
-
- /* constraint 9: relativity */
- unsigned int r_c9;
-
- /* Legacy preference value */
- double f;
-};
-
-struct MLP_Problem
-{
- /**
- * GLPK (MLP) problem object
- */
-#if HAVE_LIBGLPK
- glp_prob *prob;
-#else
- void *prob;
-#endif
-
- /* Number of addresses in problem */
- unsigned int num_addresses;
- /* Number of peers in problem */
- unsigned int num_peers;
- /* Number of elements in problem matrix */
- unsigned int num_elements;
-
- /* 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;
- /* Row indices quality metrics */
- int r_q[GNUNET_ATS_QualityPropertiesCount];
- /* Row indices ATS network quotas */
- int r_quota[GNUNET_ATS_NetworkTypeCount];
-
- /* Column index Diversity (D) column */
- int c_d;
- /* Column index Utilization (U) column */
- int c_u;
- /* Column index Proportionality (R) column */
- int c_r;
- /* Column index quality metrics */
- int c_q[GNUNET_ATS_QualityPropertiesCount];
-
- /* Problem matrix */
- /* Current index */
- unsigned int ci;
- /* Row index array */
- int *ia;
- /* Column index array */
- int *ja;
- /* Column index value */
- double *ar;
-
-};
-
-struct MLP_Variables
-{
- /* Big M value for bandwidth capping */
- double BIG_M;
-
- /* MIP Gap */
- double mip_gap;
-
- /* LP MIP Gap */
- double lp_mip_gap;
-
- /* ATS Quality metrics
- *
- * Array with GNUNET_ATS_QualityPropertiesCount elements
- * contains mapping to GNUNET_ATS_Property*/
- int q[GNUNET_ATS_QualityPropertiesCount];
-
- /* Number of quality metrics */
- int m_q;
-
- /* Number of quality metrics */
- int m_rc;
-
- /* Quality metric coefficients*/
- double co_Q[GNUNET_ATS_QualityPropertiesCount];
-
- /* Ressource costs coefficients*/
- double co_RC[GNUNET_ATS_QualityPropertiesCount];
-
- /* Diversity coefficient */
- double co_D;
-
- /* Utility coefficient */
- double co_U;
-
- /* Relativity coefficient */
- double co_R;
-
- /* Minimum bandwidth assigned to an address */
- unsigned int b_min;
-
- /* Minimum number of addresses with bandwidth assigned */
- unsigned int n_min;
-
- /* Quotas */
- /* Array mapping array index to ATS network */
- int quota_index[GNUNET_ATS_NetworkTypeCount];
- /* Outbound quotas */
- unsigned long long quota_out[GNUNET_ATS_NetworkTypeCount];
- /* Inbound quotas */
-
- unsigned long long quota_in[GNUNET_ATS_NetworkTypeCount];
-
- /* ATS ressource costs
- * array with GNUNET_ATS_QualityPropertiesCount elements
- * contains mapping to GNUNET_ATS_Property
- * */
- int rc[GNUNET_ATS_QualityPropertiesCount];
-
-};
-
-/**
- * MLP Handle
- */
-struct GAS_MLP_Handle
-{
- struct GNUNET_ATS_PluginEnvironment *env;
-
- /**
- * Statistics handle
- */
- struct GNUNET_STATISTICS_Handle *stats;
-
- /**
- * Address hashmap for lookups
- */
- const struct GNUNET_CONTAINER_MultiPeerMap *addresses;
-
- /**
- * Addresses' bandwidth changed callback
- */
- GAS_bandwidth_changed_cb bw_changed_cb;
-
- /**
- * Addresses' bandwidth changed callback closure
- */
- void *bw_changed_cb_cls;
-
- /**
- * ATS function to get preferences
- */
- GAS_get_preferences get_preferences;
-
- /**
- * Closure for ATS function to get preferences
- */
- void *get_preferences_cls;
-
- /**
- * ATS function to get properties
- */
- GAS_get_properties get_properties;
-
- /**
- * Closure for ATS function to get properties
- */
- void *get_properties_cls;
-
- /**
- * Exclude peer from next result propagation
- */
- const struct GNUNET_PeerIdentity *exclude_peer;
-
- /**
- * Encapsulation for the MLP problem
- */
- struct MLP_Problem p;
-
- /**
- * Encapsulation for the MLP problem variables
- */
- struct MLP_Variables pv;
-
- /**
- * Encapsulation for the MLP solution
- */
- struct MLP_Solution ps;
-
- /**
- * Bulk lock
- */
-
- int stat_bulk_lock;
-
- /**
- * Number of changes while solver was locked
- */
- int stat_bulk_requests;
-
- /**
- * GLPK LP control parameter
- */
-#if HAVE_LIBGLPK
- glp_smcp control_param_lp;
-#else
- void *control_param_lp;
-#endif
-
- /**
- * GLPK LP control parameter
- */
-#if HAVE_LIBGLPK
- glp_iocp control_param_mlp;
-#else
- void *control_param_mlp;
-#endif
-
- /**
- * Peers with pending address requests
- */
- struct GNUNET_CONTAINER_MultiPeerMap *requested_peers;
-
- /**
- * Was the problem updated since last solution
- */
- int stat_mlp_prob_updated;
-
- /**
- * Has the problem size changed since last solution
- */
- int stat_mlp_prob_changed;
-
- /**
- * Solve the problem automatically when updates occur?
- * Default: GNUNET_YES
- * Can be disabled for test and measurements
- */
- int opt_mlp_auto_solve;
-
- /**
- * Write all MILP problems to a MPS file
- */
- int opt_dump_problem_all;
-
- /**
- * Write all MILP problem solutions to a file
- */
- int opt_dump_solution_all;
-
- /**
- * Write MILP problems to a MPS file when solver fails
- */
- int opt_dump_problem_on_fail;
-
- /**
- * Write MILP problem solutions to a file when solver fails
- */
- int opt_dump_solution_on_fail;
-
- /**
- * solve feasibility only
- */
- int opt_dbg_feasibility_only;
-
- /**
- * solve autoscale the problem
- */
- int opt_dbg_autoscale_problem;
-
- /**
- * use the intopt presolver instead of simplex
- */
- int opt_dbg_intopt_presolver;
-
- /**
- * Print GLPK output
- */
- int opt_dbg_glpk_verbose;
-
- /**
- * solve autoscale the problem
- */
- int opt_dbg_optimize_relativity;
-
- /**
- * solve autoscale the problem
- */
- int opt_dbg_optimize_diversity;
-
- /**
- * solve autoscale the problem
- */
- int opt_dbg_optimize_quality;
-
- /**
- * solve autoscale the problem
- */
- int opt_dbg_optimize_utility;
-
-
- /**
- * Output format
- */
- enum MLP_Output_Format opt_log_format;
-};
-
-/**
- * Address specific MLP information
- */
-struct MLP_information
-{
-
- /* Bandwidth assigned */
- struct GNUNET_BANDWIDTH_Value32NBO b_out;
- struct GNUNET_BANDWIDTH_Value32NBO b_in;
-
- /* Address selected */
- int n;
-
- /* bandwidth column index */
- signed int c_b;
-
- /* 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;
-};
-
-
-/**
- * Solves the MLP problem
- *
- * @param solver the MLP Handle
- * @return #GNUNET_OK if could be solved, GNUNET_SYSERR on failure
- */
-int
-GAS_mlp_solve_problem (void *solver);
-
-
-/**
- * Init the MLP problem solving component
- *
- * @param cfg the GNUNET_CONFIGURATION_Handle handle
- * @param stats the GNUNET_STATISTICS handle
- * @param addresses Hashmap containing addresses
- * @param network array of GNUNET_ATS_NetworkType with length dest_length
- * @param out_dest array of outbound quotas
- * @param in_dest array of outbound quota
- * @param dest_length array length for quota arrays
- * @param bw_changed_cb callback for changed bandwidth amounts
- * @param bw_changed_cb_cls cls for callback
- * @param get_preference callback to get relative preferences for a peer
- * @param get_preference_cls cls for callback to get relative preferences for a peer
- * @param get_properties callback to get relative properties
- * @param get_properties_cls cls for callback to get relative properties
- * @return struct GAS_MLP_Handle on success, NULL on fail
- */
-void *
-GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const struct GNUNET_STATISTICS_Handle *stats,
- const struct GNUNET_CONTAINER_MultiPeerMap *addresses,
- int *network,
- unsigned long long *out_dest,
- unsigned long long *in_dest,
- int dest_length,
- GAS_bandwidth_changed_cb bw_changed_cb,
- void *bw_changed_cb_cls,
- GAS_get_preferences get_preference,
- void *get_preference_cls,
- GAS_get_properties get_properties,
- void *get_properties_cls);
-
-
-/**
- * Add a single address within a network to the solver
- *
- * @param solver the solver Handle
- * @param address the address to add
- * @param network network type of this address
- */
-void
-GAS_mlp_address_add (void *solver, struct ATS_Address *address,
- uint32_t network);
-
-
-/**
- * Transport properties for this address have changed
- *
- * @param solver solver handle
- * @param address the address
- * @param type the ATSI type in HBO
- * @param abs_value the absolute value of the property
- * @param rel_value the normalized value
- */
-void
-GAS_mlp_address_property_changed (void *solver, struct ATS_Address *address,
- uint32_t type, uint32_t abs_value, double rel_value);
-
-
-/**
- * Transport session for this address has changed
- *
- * NOTE: values in addresses are already updated
- *
- * @param solver solver handle
- * @param address the address
- * @param cur_session the current session
- * @param new_session the new session
- */
-void
-GAS_mlp_address_session_changed (void *solver, struct ATS_Address *address,
- uint32_t cur_session, uint32_t new_session);
-
-
-/**
- * Usage for this address has changed
- *
- * NOTE: values in addresses are already updated
- *
- * @param solver solver handle
- * @param address the address
- * @param in_use usage state
- */
-void
-GAS_mlp_address_inuse_changed (void *solver, struct ATS_Address *address,
- int in_use);
-
-/**
- * Network scope for this address has changed
- *
- * NOTE: values in addresses are already updated
- *
- * @param solver solver handle
- * @param address the address
- * @param current_network the current network
- * @param new_network the new network
- */
-void
-GAS_mlp_address_change_network (void *solver, struct ATS_Address *address,
- uint32_t current_network, uint32_t new_network);
-
-/**
- * Deletes a single address in the MLP problem
- *
- * The MLP problem has to be recreated and the problem has to be resolved
- *
- * @param solver the MLP Handle
- * @param address the address to delete
- * @param session_only delete only session not whole address
- */
-void
-GAS_mlp_address_delete (void *solver, struct ATS_Address *address,
- int session_only);
-
-/**
- * Changes the preferences for a peer in the MLP problem
- *
- * @param solver the MLP Handle
- * @param peer the peer
- * @param kind the kind to change the preference
- * @param pref_rel the relative score
- */
-void
-GAS_mlp_address_change_preference (void *solver,
- const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind,
- double pref_rel);
-
-/**
- * Get application feedback for a peer
- *
- * @param solver the solver handle
- * @param application the application
- * @param peer the peer to change the preference for
- * @param scope the time interval for this feedback: [now - scope .. now]
- * @param kind the kind to change the preference
- * @param score the score
- */
-void
-GAS_mlp_address_preference_feedback (void *solver, void *application,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TIME_Relative scope,
- enum GNUNET_ATS_PreferenceKind kind, double score);
-
-/**
- * Start a bulk operation
- *
- * @param solver the solver
- */
-void
-GAS_mlp_bulk_start (void *solver);
-
-/**
- * Bulk operation done
- */
-void
-GAS_mlp_bulk_stop (void *solver);
-
-/**
- * Get the preferred address for a specific peer until
- * GAS_mlp_stop_get_preferred_address is called
- *
- * @param solver the MLP Handle
- * @param peer the peer
- * @return suggested address
- */
-const struct ATS_Address *
-GAS_mlp_get_preferred_address (void *solver,
- const struct GNUNET_PeerIdentity *peer);
-
-/**
- * Stop notifying about address and bandwidth changes for this peer
- *
- * @param solver the MLP handle
- * @param peer the peer
- */
-void
-GAS_mlp_stop_get_preferred_address (void *solver,
- const struct GNUNET_PeerIdentity *peer);
-
-/**
- * Shutdown the MLP problem solving component
- *
- * @param solver the solver handle
- */
-void
-GAS_mlp_done (void *solver);
-
-#endif
-/* end of plugin_ats_mlp.h */
/*
This file is part of GNUnet.
- (C) 2011 Christian Grothoff (and other contributing authors)
+ (C) 2011-2014 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
* @author Fabian Oehlmann
* @author Matthias Wachs
*/
-#include "plugin_ats_ril.h"
+#include "platform.h"
+#include <float.h>
+#include <math.h>
+#include "gnunet_ats_plugin.h"
+#include "gnunet-service-ats_addresses.h"
+
+
#define LOG(kind,...) GNUNET_log_from (kind, "ats-ril",__VA_ARGS__)
* @param kind the kind to change the preference
* @param pref_rel the normalized preference value for this kind over all clients
*/
-void
+static void
GAS_ril_address_change_preference (void *solver,
- const struct GNUNET_PeerIdentity *peer,
- enum GNUNET_ATS_PreferenceKind kind,
- double pref_rel)
+ const struct GNUNET_PeerIdentity *peer,
+ enum GNUNET_ATS_PreferenceKind kind,
+ double pref_rel)
{
LOG(GNUNET_ERROR_TYPE_DEBUG,
"API_address_change_preference() Preference '%s' for peer '%s' changed to %.2f \n",
ril_step (s);
}
+
/**
- * Entry point for the plugin
+ * Add a new address for a peer to the solver
*
- * @param cls pointer to the 'struct GNUNET_ATS_PluginEnvironment'
+ * The address is already contained in the addresses hashmap!
+ *
+ * @param solver the solver Handle
+ * @param address the address to add
+ * @param network network type of this address
*/
-void *
-libgnunet_plugin_ats_ril_init (void *cls)
+static void
+GAS_ril_address_add (void *solver,
+ struct ATS_Address *address,
+ uint32_t network)
{
- struct GNUNET_ATS_PluginEnvironment *env = cls;
- struct GAS_RIL_Handle *solver = GNUNET_new (struct GAS_RIL_Handle);
- struct RIL_Scope * cur;
- int c;
- char *string;
- float f_tmp;
-
- LOG(GNUNET_ERROR_TYPE_DEBUG, "API_init() Initializing RIL solver\n");
+ struct GAS_RIL_Handle *s = solver;
+ struct RIL_Peer_Agent *agent;
+ struct RIL_Address_Wrapped *address_wrapped;
+ struct RIL_Scope *net;
+ unsigned int m_new;
+ unsigned int m_old;
+ unsigned int n_new;
+ unsigned int n_old;
+ int i;
+ unsigned int zero;
- GNUNET_assert(NULL != env);
- GNUNET_assert(NULL != env->cfg);
- GNUNET_assert(NULL != env->stats);
- GNUNET_assert(NULL != env->bandwidth_changed_cb);
- GNUNET_assert(NULL != env->get_preferences);
- GNUNET_assert(NULL != env->get_property);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "API_address_add()\n");
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, "ats", "RIL_RBF_DIVISOR", &solver->parameters.rbf_divisor))
- {
- solver->parameters.rbf_divisor = RIL_DEFAULT_RBF_DIVISOR;
- }
+ net = ril_get_network (s, network);
+ address->solver_information = net;
- if (GNUNET_OK
- != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats", "RIL_STEP_TIME_MIN",
- &solver->parameters.step_time_min))
+ if (!ril_network_is_active (s, network))
{
- solver->parameters.step_time_min = RIL_DEFAULT_STEP_TIME_MIN;
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "API_address_add() Did not add %s address %s for peer '%s', network does not have enough bandwidth\n",
+ address->plugin, address->addr, GNUNET_i2s (&address->peer));
+ return;
}
- if (GNUNET_OK
- != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats", "RIL_STEP_TIME_MAX",
- &solver->parameters.step_time_max))
- {
- solver->parameters.step_time_max = RIL_DEFAULT_STEP_TIME_MAX;
- }
+ s->parameters.temperature = s->parameters.temperature_init;
+ s->parameters.epsilon = s->parameters.epsilon_init;
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_ALGORITHM", &string))
- {
- solver->parameters.algorithm = !strcmp (string, "SARSA") ? RIL_ALGO_SARSA : RIL_ALGO_Q;
- GNUNET_free (string);
- }
- else
- {
- solver->parameters.algorithm = RIL_DEFAULT_ALGORITHM;
- }
+ agent = ril_get_agent (s, &address->peer, GNUNET_YES);
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_SELECT", &string))
- {
- solver->parameters.select = !strcmp (string, "EGREEDY") ? RIL_SELECT_EGREEDY : RIL_SELECT_SOFTMAX;
- GNUNET_free (string);
- }
- else
- {
- solver->parameters.select = RIL_DEFAULT_SELECT;
- }
+ //add address
+ address_wrapped = GNUNET_new (struct RIL_Address_Wrapped);
+ address_wrapped->address_naked = address;
+ GNUNET_CONTAINER_DLL_insert_tail(agent->addresses_head, agent->addresses_tail, address_wrapped);
+ //increase size of W
+ m_new = agent->m + ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1));
+ m_old = agent->m;
+ n_new = agent->n + 1;
+ n_old = agent->n;
- solver->parameters.beta = RIL_DEFAULT_DISCOUNT_BETA;
- if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
- "RIL_DISCOUNT_BETA", &f_tmp))
+ GNUNET_array_grow(agent->W, agent->n, n_new);
+ agent->n = n_old;
+ GNUNET_array_grow(agent->E, agent->n, n_new);
+ for (i = 0; i < n_new; i++)
{
- if (f_tmp < 0.0)
+ if (i < n_old)
{
- LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
- "RIL_DISCOUNT_BETA", f_tmp);
+ agent->m = m_old;
+ GNUNET_array_grow(agent->W[i], agent->m, m_new);
+ agent->m = m_old;
+ GNUNET_array_grow(agent->E[i], agent->m, m_new);
}
else
{
- solver->parameters.beta = f_tmp;
- LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
- "RIL_DISCOUNT_BETA", f_tmp);
+ zero = 0;
+ GNUNET_array_grow(agent->W[i], zero, m_new);
+ zero = 0;
+ GNUNET_array_grow(agent->E[i], zero, m_new);
}
}
- solver->parameters.gamma = RIL_DEFAULT_DISCOUNT_GAMMA;
- if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
- "RIL_DISCOUNT_GAMMA", &f_tmp))
+ //increase size of old state vector
+ agent->m = m_old;
+ GNUNET_array_grow(agent->s_old, agent->m, m_new);
+
+ ril_try_unblock_agent(s, agent, GNUNET_NO);
+
+ ril_step (s);
+
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_add() Added %s %s address %s for peer '%s'\n",
+ address->active ? "active" : "inactive", address->plugin, address->addr,
+ GNUNET_i2s (&address->peer));
+}
+
+/**
+ * Delete an address in the solver
+ *
+ * The address is not contained in the address hashmap anymore!
+ *
+ * @param solver the solver handle
+ * @param address the address to remove
+ * @param session_only delete only session not whole address
+ */
+static void
+GAS_ril_address_delete (void *solver,
+ struct ATS_Address *address,
+ int session_only)
+{
+ struct GAS_RIL_Handle *s = solver;
+ struct RIL_Peer_Agent *agent;
+ struct RIL_Address_Wrapped *address_wrapped;
+ int address_was_used = address->active;
+ int address_index;
+ unsigned int m_new;
+ unsigned int n_new;
+ int i;
+ struct RIL_Scope *net;
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "API_address_delete() Delete %s%s %s address %s for peer '%s'\n",
+ session_only ? "session for " : "", address->active ? "active" : "inactive", address->plugin,
+ address->addr,
+ GNUNET_i2s (&address->peer));
+
+ agent = ril_get_agent (s, &address->peer, GNUNET_NO);
+ if (NULL == agent)
{
- if ((f_tmp < 0.0) || (f_tmp > 1.0))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
- "RIL_DISCOUNT_GAMMA", f_tmp);
- }
- else
- {
- solver->parameters.gamma = f_tmp;
- LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
- "RIL_DISCOUNT_GAMMA", f_tmp);
- }
+ net = address->solver_information;
+ GNUNET_assert(!ril_network_is_active (s, net->type));
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "No agent allocated for peer yet, since address was in inactive network\n");
+ return;
}
- solver->parameters.alpha = RIL_DEFAULT_GRADIENT_STEP_SIZE;
- if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
- "RIL_GRADIENT_STEP_SIZE", &f_tmp))
+ s->parameters.temperature = s->parameters.temperature_init;
+ s->parameters.epsilon = s->parameters.epsilon_init;
+
+ address_index = agent_address_get_index (agent, address);
+ address_wrapped = agent_address_get_wrapped (agent, address);
+
+ if (NULL == address_wrapped)
{
- if ((f_tmp < 0.0) || (f_tmp > 1.0))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
- "RIL_GRADIENT_STEP_SIZE", f_tmp);
- }
- else
- {
- solver->parameters.alpha = f_tmp;
- LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
- "RIL_GRADIENT_STEP_SIZE", f_tmp);
- }
+ net = address->solver_information;
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "Address not considered by agent, address was in inactive network\n");
+ return;
}
- solver->parameters.lambda = RIL_DEFAULT_TRACE_DECAY;
- if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
- "RIL_TRACE_DECAY", &f_tmp))
+ GNUNET_CONTAINER_DLL_remove(agent->addresses_head, agent->addresses_tail, address_wrapped);
+ GNUNET_free(address_wrapped);
+
+ //decrease W
+ m_new = agent->m - ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1));
+ n_new = agent->n - 1;
+
+ for (i = 0; i < agent->n; i++)
{
- if ((f_tmp < 0.0) || (f_tmp > 1.0))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
- "RIL_TRACE_DECAY", f_tmp);
- }
- else
- {
- solver->parameters.lambda = f_tmp;
- LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
- "RIL_TRACE_DECAY", f_tmp);
- }
+ ril_cut_from_vector ((void **) &agent->W[i], sizeof(double),
+ address_index * ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)),
+ ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), agent->m);
+ ril_cut_from_vector ((void **) &agent->E[i], sizeof(double),
+ address_index * ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)),
+ ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), agent->m);
+ }
+ GNUNET_free_non_null(agent->W[RIL_ACTION_TYPE_NUM + address_index]);
+ GNUNET_free_non_null(agent->E[RIL_ACTION_TYPE_NUM + address_index]);
+ ril_cut_from_vector ((void **) &agent->W, sizeof(double *), RIL_ACTION_TYPE_NUM + address_index,
+ 1, agent->n);
+ ril_cut_from_vector ((void **) &agent->E, sizeof(double *), RIL_ACTION_TYPE_NUM + address_index,
+ 1, agent->n);
+ //correct last action
+ if (agent->a_old > (RIL_ACTION_TYPE_NUM + address_index))
+ {
+ agent->a_old -= 1;
+ }
+ else if (agent->a_old == (RIL_ACTION_TYPE_NUM + address_index))
+ {
+ agent->a_old = RIL_ACTION_INVALID;
}
+ //decrease old state vector
+ ril_cut_from_vector ((void **) &agent->s_old, sizeof(double),
+ address_index * ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)),
+ ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), agent->m);
+ agent->m = m_new;
+ agent->n = n_new;
- solver->parameters.epsilon_init = RIL_DEFAULT_EXPLORE_RATIO;
- if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
- "RIL_EXPLORE_RATIO", &f_tmp))
+ if (address_was_used)
{
- if ((f_tmp < 0.0) || (f_tmp > 1.0))
+ if (NULL != agent->addresses_head) //if peer has an address left, use it
{
- LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
- "RIL_EXPLORE_RATIO", f_tmp);
+ envi_set_active_suggestion (s, agent, agent->addresses_head->address_naked, agent->bw_in, agent->bw_out,
+ GNUNET_YES);
}
else
{
- solver->parameters.epsilon_init = f_tmp;
- LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
- "RIL_EXPLORE_RATIO", f_tmp);
- }
- }
-
- solver->parameters.epsilon_decay = RIL_DEFAULT_EXPLORE_DECAY;
- if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
- "RIL_EXPLORE_DECAY", &f_tmp))
- {
- if ((f_tmp < 0.0) || (f_tmp > 0.0))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
- "RIL_EXPLORE_DECAY", f_tmp);
- }
- else
- {
- solver->parameters.epsilon_decay = f_tmp;
- LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
- "RIL_EXPLORE_DECAY", f_tmp);
- }
- }
-
- solver->parameters.temperature_init = RIL_DEFAULT_TEMPERATURE;
- if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
- "RIL_TEMPERATURE", &f_tmp))
- {
- if (f_tmp <= 0.0)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
- "RIL_TEMPERATURE", f_tmp);
- }
- else
- {
- solver->parameters.temperature_init = f_tmp;
- LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
- "RIL_TEMPERATURE", f_tmp);
+ envi_set_active_suggestion (s, agent, NULL, 0, 0, GNUNET_NO);
}
}
- solver->parameters.temperature_decay = RIL_DEFAULT_TEMPERATURE_DECAY;
- if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
- "RIL_TEMPERATURE_DECAY", &f_tmp))
- {
- if ((f_tmp <= 0.0) || solver->parameters.temperature_decay > 1)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
- "RIL_TEMPERATURE_DECAY", f_tmp);
- }
- else
- {
- solver->parameters.temperature_decay = f_tmp;
- LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
- "RIL_TEMPERATURE_DECAY", f_tmp);
- }
- }
+ ril_step (solver);
+}
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, "ats", "RIL_SIMULATE", &solver->simulate))
- {
- solver->simulate = GNUNET_NO;
- }
+/**
+ * Update the properties of an address in the solver
+ *
+ * @param solver solver handle
+ * @param address the address
+ * @param type the ATSI type in HBO
+ * @param abs_value the absolute value of the property
+ * @param rel_value the normalized value
+ */
+static void
+GAS_ril_address_property_changed (void *solver,
+ struct ATS_Address *address,
+ uint32_t type,
+ uint32_t abs_value,
+ double rel_value)
+{
+ struct GAS_RIL_Handle *s = solver;
- if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(env->cfg, "ats", "RIL_REPLACE_TRACES"))
- {
- solver->parameters.eligibility_trace_mode = RIL_E_REPLACE;
- }
- else
- {
- solver->parameters.eligibility_trace_mode = RIL_E_ACCUMULATE;
- }
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "API_address_property_changed() Property '%s' for peer '%s' address %s changed "
+ "to %.2f \n",
+ GNUNET_ATS_print_property_type (type),
+ GNUNET_i2s (&address->peer),
+ address->addr, rel_value);
- if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_SOCIAL_WELFARE", &string))
- {
- solver->parameters.social_welfare = !strcmp (string, "NASH") ? RIL_WELFARE_NASH : RIL_WELFARE_EGALITARIAN;
- GNUNET_free (string);
- }
- else
- {
- solver->parameters.social_welfare = RIL_DEFAULT_WELFARE;
- }
- env->sf.s_add = &GAS_ril_address_add;
- env->sf.s_address_update_property = &GAS_ril_address_property_changed;
- env->sf.s_address_update_session = &GAS_ril_address_session_changed;
- env->sf.s_address_update_inuse = &GAS_ril_address_inuse_changed;
- env->sf.s_address_update_network = &GAS_ril_address_change_network;
- env->sf.s_get = &GAS_ril_get_preferred_address;
- env->sf.s_get_stop = &GAS_ril_stop_get_preferred_address;
- env->sf.s_pref = &GAS_ril_address_change_preference;
- env->sf.s_feedback = &GAS_ril_address_preference_feedback;
- env->sf.s_del = &GAS_ril_address_delete;
- env->sf.s_bulk_start = &GAS_ril_bulk_start;
- env->sf.s_bulk_stop = &GAS_ril_bulk_stop;
+ s->parameters.temperature = s->parameters.temperature_init;
+ s->parameters.epsilon = s->parameters.epsilon_init;
+ ril_step (s);
+}
- solver->plugin_envi = env;
- solver->networks_count = env->network_count;
- solver->network_entries = GNUNET_malloc (env->network_count * sizeof (struct RIL_Scope));
- solver->step_count = 0;
- solver->done = GNUNET_NO;
- for (c = 0; c < env->network_count; c++)
- {
- cur = &solver->network_entries[c];
- cur->type = env->networks[c];
- cur->bw_in_available = env->in_quota[c];
- cur->bw_out_available = env->out_quota[c];
- LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Quotas for %s network: IN %llu - OUT %llu\n", GNUNET_ATS_print_network_type(cur->type), cur->bw_in_available/1024, cur->bw_out_available/1024);
- }
+/**
+ * Update the session of an address in the solver
+ *
+ * NOTE: values in addresses are already updated
+ *
+ * @param solver solver handle
+ * @param address the address
+ * @param cur_session the current session
+ * @param new_session the new session
+ */
+static void
+GAS_ril_address_session_changed (void *solver,
+ struct ATS_Address *address,
+ uint32_t cur_session,
+ uint32_t new_session)
+{
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "API_address_session_changed()\n");
+}
- LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Parameters:\n");
- LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Algorithm = %s, alpha = %f, beta = %f, lambda = %f\n",
- solver->parameters.algorithm ? "Q" : "SARSA",
- solver->parameters.alpha,
- solver->parameters.beta,
- solver->parameters.lambda);
- LOG(GNUNET_ERROR_TYPE_DEBUG, "init() exploration_ratio = %f, temperature = %f, ActionSelection = %s\n",
- solver->parameters.epsilon,
- solver->parameters.temperature,
- solver->parameters.select ? "EGREEDY" : "SOFTMAX");
- LOG(GNUNET_ERROR_TYPE_DEBUG, "init() RBF_DIVISOR = %llu\n",
- solver->parameters.rbf_divisor);
- return solver;
+/**
+ * Notify the solver that an address is (not) actively used by transport
+ * to communicate with a remote peer
+ *
+ * NOTE: values in addresses are already updated
+ *
+ * @param solver solver handle
+ * @param address the address
+ * @param in_use usage state
+ */
+static void
+GAS_ril_address_inuse_changed (void *solver,
+ struct ATS_Address *address,
+ int in_use)
+{
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "API_address_inuse_changed() Usage for %s address of peer '%s' changed to %s\n",
+ address->plugin, GNUNET_i2s (&address->peer), (GNUNET_YES == in_use) ? "USED" : "UNUSED");
}
+
/**
- * Exit point for the plugin
+ * Notify solver that the network an address is located in has changed
*
- * @param cls the solver handle
+ * NOTE: values in addresses are already updated
+ *
+ * @param solver solver handle
+ * @param address the address
+ * @param current_network the current network
+ * @param new_network the new network
*/
-void *
-libgnunet_plugin_ats_ril_done (void *cls)
+static void
+GAS_ril_address_change_network (void *solver,
+ struct ATS_Address *address,
+ uint32_t current_network,
+ uint32_t new_network)
{
- struct GAS_RIL_Handle *s = cls;
- struct RIL_Peer_Agent *cur_agent;
- struct RIL_Peer_Agent *next_agent;
+ struct GAS_RIL_Handle *s = solver;
+ struct RIL_Peer_Agent *agent;
- LOG(GNUNET_ERROR_TYPE_DEBUG, "API_done() Shutting down RIL solver\n");
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "API_address_change_network() Network type changed, moving "
+ "%s address of peer %s from '%s' to '%s'\n",
+ (GNUNET_YES == address->active) ? "active" : "inactive", GNUNET_i2s (&address->peer),
+ GNUNET_ATS_print_network_type (current_network), GNUNET_ATS_print_network_type (new_network));
- s->done = GNUNET_YES;
+ s->parameters.temperature = s->parameters.temperature_init;
+ s->parameters.epsilon = s->parameters.epsilon_init;
- cur_agent = s->agents_head;
- while (NULL != cur_agent)
+ if (address->active && !ril_network_is_active (solver, new_network))
{
- next_agent = cur_agent->next;
- GNUNET_CONTAINER_DLL_remove(s->agents_head, s->agents_tail, cur_agent);
- agent_die (s, cur_agent);
- cur_agent = next_agent;
+ GAS_ril_address_delete (solver, address, GNUNET_NO);
+ return;
}
- if (GNUNET_SCHEDULER_NO_TASK != s->step_next_task_id)
+ agent = ril_get_agent (s, &address->peer, GNUNET_NO);
+ if (NULL == agent)
{
- GNUNET_SCHEDULER_cancel (s->step_next_task_id);
+ GNUNET_assert(!ril_network_is_active (solver, current_network));
+
+ GAS_ril_address_add (s, address, new_network);
+ return;
}
- GNUNET_free(s->network_entries);
- GNUNET_free(s);
- return NULL;
+ address->solver_information = ril_get_network(solver, new_network);
}
+
/**
- * Add a new address for a peer to the solver
+ * Give feedback about the current assignment
*
- * The address is already contained in the addresses hashmap!
+ * @param solver the solver handle
+ * @param application the application
+ * @param peer the peer to change the preference for
+ * @param scope the time interval for this feedback: [now - scope .. now]
+ * @param kind the kind to change the preference
+ * @param score the score
+ */
+static void
+GAS_ril_address_preference_feedback (void *solver,
+ void *application,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TIME_Relative scope,
+ enum GNUNET_ATS_PreferenceKind kind,
+ double score)
+{
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f from application %s for "
+ "preference %s for %d seconds\n", GNUNET_i2s (peer), "UNKNOWN",
+ GNUNET_ATS_print_preference_type (kind), scope.rel_value_us / 1000000);
+}
+
+
+/**
+ * Start a bulk operation
*
- * @param solver the solver Handle
- * @param address the address to add
- * @param network network type of this address
+ * @param solver the solver
*/
-void
-GAS_ril_address_add (void *solver, struct ATS_Address *address, uint32_t network)
+static void
+GAS_ril_bulk_start (void *solver)
{
struct GAS_RIL_Handle *s = solver;
- struct RIL_Peer_Agent *agent;
- struct RIL_Address_Wrapped *address_wrapped;
- struct RIL_Scope *net;
- unsigned int m_new;
- unsigned int m_old;
- unsigned int n_new;
- unsigned int n_old;
- int i;
- unsigned int zero;
-
- LOG (GNUNET_ERROR_TYPE_DEBUG, "API_address_add()\n");
- net = ril_get_network (s, network);
- address->solver_information = net;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "API_bulk_start() lock: %d\n", s->bulk_lock+1);
- if (!ril_network_is_active (s, network))
- {
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "API_address_add() Did not add %s address %s for peer '%s', network does not have enough bandwidth\n",
- address->plugin, address->addr, GNUNET_i2s (&address->peer));
- return;
- }
+ s->bulk_lock++;
+}
- s->parameters.temperature = s->parameters.temperature_init;
- s->parameters.epsilon = s->parameters.epsilon_init;
- agent = ril_get_agent (s, &address->peer, GNUNET_YES);
+/**
+ * Bulk operation done
+ *
+ * @param solver the solver handle
+ */
+static void
+GAS_ril_bulk_stop (void *solver)
+{
+ struct GAS_RIL_Handle *s = solver;
- //add address
- address_wrapped = GNUNET_new (struct RIL_Address_Wrapped);
- address_wrapped->address_naked = address;
- GNUNET_CONTAINER_DLL_insert_tail(agent->addresses_head, agent->addresses_tail, address_wrapped);
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "API_bulk_stop() lock: %d\n",
+ s->bulk_lock - 1);
- //increase size of W
- m_new = agent->m + ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1));
- m_old = agent->m;
- n_new = agent->n + 1;
- n_old = agent->n;
+ if (s->bulk_lock < 1)
+ {
+ GNUNET_break(0);
+ return;
+ }
+ s->bulk_lock--;
- GNUNET_array_grow(agent->W, agent->n, n_new);
- agent->n = n_old;
- GNUNET_array_grow(agent->E, agent->n, n_new);
- for (i = 0; i < n_new; i++)
+ if (0 < s->bulk_changes)
{
- if (i < n_old)
- {
- agent->m = m_old;
- GNUNET_array_grow(agent->W[i], agent->m, m_new);
- agent->m = m_old;
- GNUNET_array_grow(agent->E[i], agent->m, m_new);
- }
- else
- {
- zero = 0;
- GNUNET_array_grow(agent->W[i], zero, m_new);
- zero = 0;
- GNUNET_array_grow(agent->E[i], zero, m_new);
- }
+ ril_step (solver);
+ s->bulk_changes = 0;
}
+}
- //increase size of old state vector
- agent->m = m_old;
- GNUNET_array_grow(agent->s_old, agent->m, m_new);
- ril_try_unblock_agent(s, agent, GNUNET_NO);
+/**
+ * Tell solver to notify ATS if the address to use changes for a specific
+ * peer using the bandwidth changed callback
+ *
+ * The solver must only notify about changes for peers with pending address
+ * requests!
+ *
+ * @param solver the solver handle
+ * @param peer the identity of the peer
+ */
+static const struct ATS_Address *
+GAS_ril_get_preferred_address (void *solver,
+ const struct GNUNET_PeerIdentity *peer)
+{
+ struct GAS_RIL_Handle *s = solver;
+ struct RIL_Peer_Agent *agent;
- ril_step (s);
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "API_get_preferred_address()\n");
- LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_add() Added %s %s address %s for peer '%s'\n",
- address->active ? "active" : "inactive", address->plugin, address->addr,
- GNUNET_i2s (&address->peer));
+ agent = ril_get_agent (s, peer, GNUNET_YES);
+
+ agent->is_active = GNUNET_YES;
+ envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, agent->bw_out, GNUNET_YES);
+
+ ril_try_unblock_agent(solver, agent, GNUNET_YES);
+
+ if (agent->address_inuse)
+ {
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "API_get_preferred_address() Activated agent for peer '%s' with %s address %s\n",
+ GNUNET_i2s (peer), agent->address_inuse->plugin, agent->address_inuse->addr);
+ }
+ else
+ {
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "API_get_preferred_address() Activated agent for peer '%s', but no address available\n",
+ GNUNET_i2s (peer));
+ s->parameters.temperature = s->parameters.temperature_init;
+ s->parameters.epsilon = s->parameters.epsilon_init;
+ }
+ return agent->address_inuse;
}
/**
- * Delete an address in the solver
+ * Tell solver stop notifying ATS about changes for this peers
*
- * The address is not contained in the address hashmap anymore!
+ * The solver must only notify about changes for peers with pending address
+ * requests!
*
* @param solver the solver handle
- * @param address the address to remove
- * @param session_only delete only session not whole address
+ * @param peer the peer
*/
-void
-GAS_ril_address_delete (void *solver, struct ATS_Address *address, int session_only)
+static void
+GAS_ril_stop_get_preferred_address (void *solver,
+ const struct GNUNET_PeerIdentity *peer)
{
struct GAS_RIL_Handle *s = solver;
struct RIL_Peer_Agent *agent;
- struct RIL_Address_Wrapped *address_wrapped;
- int address_was_used = address->active;
- int address_index;
- unsigned int m_new;
- unsigned int n_new;
- int i;
- struct RIL_Scope *net;
- LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_delete() Delete %s%s %s address %s for peer '%s'\n",
- session_only ? "session for " : "", address->active ? "active" : "inactive", address->plugin,
- address->addr, GNUNET_i2s (&address->peer));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "API_stop_get_preferred_address()");
+
+ agent = ril_get_agent (s, peer, GNUNET_NO);
- agent = ril_get_agent (s, &address->peer, GNUNET_NO);
if (NULL == agent)
{
- net = address->solver_information;
- GNUNET_assert(!ril_network_is_active (s, net->type));
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "No agent allocated for peer yet, since address was in inactive network\n");
+ GNUNET_break(0);
+ return;
+ }
+ if (GNUNET_NO == agent->is_active)
+ {
+ GNUNET_break(0);
return;
}
s->parameters.temperature = s->parameters.temperature_init;
s->parameters.epsilon = s->parameters.epsilon_init;
- address_index = agent_address_get_index (agent, address);
- address_wrapped = agent_address_get_wrapped (agent, address);
+ agent->is_active = GNUNET_NO;
- if (NULL == address_wrapped)
+ envi_set_active_suggestion (s, agent, agent->address_inuse, agent->bw_in, agent->bw_out,
+ GNUNET_YES);
+
+ ril_step (s);
+
+ LOG(GNUNET_ERROR_TYPE_DEBUG,
+ "API_stop_get_preferred_address() Paused agent for peer '%s' with %s address\n",
+ GNUNET_i2s (peer), agent->address_inuse->plugin);
+}
+
+
+/**
+ * Entry point for the plugin
+ *
+ * @param cls pointer to the 'struct GNUNET_ATS_PluginEnvironment'
+ */
+void *
+libgnunet_plugin_ats_ril_init (void *cls)
+{
+ struct GNUNET_ATS_PluginEnvironment *env = cls;
+ struct GAS_RIL_Handle *solver = GNUNET_new (struct GAS_RIL_Handle);
+ struct RIL_Scope * cur;
+ int c;
+ char *string;
+ float f_tmp;
+
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "API_init() Initializing RIL solver\n");
+
+ GNUNET_assert(NULL != env);
+ GNUNET_assert(NULL != env->cfg);
+ GNUNET_assert(NULL != env->stats);
+ GNUNET_assert(NULL != env->bandwidth_changed_cb);
+ GNUNET_assert(NULL != env->get_preferences);
+ GNUNET_assert(NULL != env->get_property);
+
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, "ats", "RIL_RBF_DIVISOR", &solver->parameters.rbf_divisor))
{
- net = address->solver_information;
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Address not considered by agent, address was in inactive network\n");
- return;
+ solver->parameters.rbf_divisor = RIL_DEFAULT_RBF_DIVISOR;
}
- GNUNET_CONTAINER_DLL_remove(agent->addresses_head, agent->addresses_tail, address_wrapped);
- GNUNET_free(address_wrapped);
+ if (GNUNET_OK
+ != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats", "RIL_STEP_TIME_MIN",
+ &solver->parameters.step_time_min))
+ {
+ solver->parameters.step_time_min = RIL_DEFAULT_STEP_TIME_MIN;
+ }
- //decrease W
- m_new = agent->m - ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1));
- n_new = agent->n - 1;
+ if (GNUNET_OK
+ != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats", "RIL_STEP_TIME_MAX",
+ &solver->parameters.step_time_max))
+ {
+ solver->parameters.step_time_max = RIL_DEFAULT_STEP_TIME_MAX;
+ }
- for (i = 0; i < agent->n; i++)
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_ALGORITHM", &string))
{
- ril_cut_from_vector ((void **) &agent->W[i], sizeof(double),
- address_index * ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)),
- ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), agent->m);
- ril_cut_from_vector ((void **) &agent->E[i], sizeof(double),
- address_index * ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)),
- ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), agent->m);
+ solver->parameters.algorithm = !strcmp (string, "SARSA") ? RIL_ALGO_SARSA : RIL_ALGO_Q;
+ GNUNET_free (string);
}
- GNUNET_free_non_null(agent->W[RIL_ACTION_TYPE_NUM + address_index]);
- GNUNET_free_non_null(agent->E[RIL_ACTION_TYPE_NUM + address_index]);
- ril_cut_from_vector ((void **) &agent->W, sizeof(double *), RIL_ACTION_TYPE_NUM + address_index,
- 1, agent->n);
- ril_cut_from_vector ((void **) &agent->E, sizeof(double *), RIL_ACTION_TYPE_NUM + address_index,
- 1, agent->n);
- //correct last action
- if (agent->a_old > (RIL_ACTION_TYPE_NUM + address_index))
+ else
{
- agent->a_old -= 1;
+ solver->parameters.algorithm = RIL_DEFAULT_ALGORITHM;
}
- else if (agent->a_old == (RIL_ACTION_TYPE_NUM + address_index))
+
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_SELECT", &string))
{
- agent->a_old = RIL_ACTION_INVALID;
+ solver->parameters.select = !strcmp (string, "EGREEDY") ? RIL_SELECT_EGREEDY : RIL_SELECT_SOFTMAX;
+ GNUNET_free (string);
+ }
+ else
+ {
+ solver->parameters.select = RIL_DEFAULT_SELECT;
}
- //decrease old state vector
- ril_cut_from_vector ((void **) &agent->s_old, sizeof(double),
- address_index * ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)),
- ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), agent->m);
- agent->m = m_new;
- agent->n = n_new;
- if (address_was_used)
+
+ solver->parameters.beta = RIL_DEFAULT_DISCOUNT_BETA;
+ if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
+ "RIL_DISCOUNT_BETA", &f_tmp))
{
- if (NULL != agent->addresses_head) //if peer has an address left, use it
+ if (f_tmp < 0.0)
{
- envi_set_active_suggestion (s, agent, agent->addresses_head->address_naked, agent->bw_in, agent->bw_out,
- GNUNET_YES);
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
+ "RIL_DISCOUNT_BETA", f_tmp);
}
else
{
- envi_set_active_suggestion (s, agent, NULL, 0, 0, GNUNET_NO);
+ solver->parameters.beta = f_tmp;
+ LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
+ "RIL_DISCOUNT_BETA", f_tmp);
}
}
- ril_step (solver);
-}
-
-/**
- * Update the properties of an address in the solver
- *
- * @param solver solver handle
- * @param address the address
- * @param type the ATSI type in HBO
- * @param abs_value the absolute value of the property
- * @param rel_value the normalized value
- */
-void
-GAS_ril_address_property_changed (void *solver,
- struct ATS_Address *address,
- uint32_t type,
- uint32_t abs_value,
- double rel_value)
-{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "API_address_property_changed() Property '%s' for peer '%s' address %s changed "
- "to %.2f \n", GNUNET_ATS_print_property_type (type), GNUNET_i2s (&address->peer),
- address->addr, rel_value);
-
- struct GAS_RIL_Handle *s = solver;
-
- s->parameters.temperature = s->parameters.temperature_init;
- s->parameters.epsilon = s->parameters.epsilon_init;
- ril_step (s);
-}
-
-/**
- * Update the session of an address in the solver
- *
- * NOTE: values in addresses are already updated
- *
- * @param solver solver handle
- * @param address the address
- * @param cur_session the current session
- * @param new_session the new session
- */
-void
-GAS_ril_address_session_changed (void *solver,
- struct ATS_Address *address,
- uint32_t cur_session,
- uint32_t new_session)
-{
- LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_session_changed()\n");
-}
-
-/**
- * Notify the solver that an address is (not) actively used by transport
- * to communicate with a remote peer
- *
- * NOTE: values in addresses are already updated
- *
- * @param solver solver handle
- * @param address the address
- * @param in_use usage state
- */
-void
-GAS_ril_address_inuse_changed (void *solver, struct ATS_Address *address, int in_use)
-{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "API_address_inuse_changed() Usage for %s address of peer '%s' changed to %s\n",
- address->plugin, GNUNET_i2s (&address->peer), (GNUNET_YES == in_use) ? "USED" : "UNUSED");
-}
-
-/**
- * Notify solver that the network an address is located in has changed
- *
- * NOTE: values in addresses are already updated
- *
- * @param solver solver handle
- * @param address the address
- * @param current_network the current network
- * @param new_network the new network
- */
-void
-GAS_ril_address_change_network (void *solver,
- struct ATS_Address *address,
- uint32_t current_network,
- uint32_t new_network)
-{
- struct GAS_RIL_Handle *s = solver;
- struct RIL_Peer_Agent *agent;
-
- LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_change_network() Network type changed, moving "
- "%s address of peer %s from '%s' to '%s'\n",
- (GNUNET_YES == address->active) ? "active" : "inactive", GNUNET_i2s (&address->peer),
- GNUNET_ATS_print_network_type (current_network), GNUNET_ATS_print_network_type (new_network));
-
- s->parameters.temperature = s->parameters.temperature_init;
- s->parameters.epsilon = s->parameters.epsilon_init;
-
- if (address->active && !ril_network_is_active (solver, new_network))
+ solver->parameters.gamma = RIL_DEFAULT_DISCOUNT_GAMMA;
+ if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
+ "RIL_DISCOUNT_GAMMA", &f_tmp))
{
- GAS_ril_address_delete (solver, address, GNUNET_NO);
- return;
+ if ((f_tmp < 0.0) || (f_tmp > 1.0))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
+ "RIL_DISCOUNT_GAMMA", f_tmp);
+ }
+ else
+ {
+ solver->parameters.gamma = f_tmp;
+ LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
+ "RIL_DISCOUNT_GAMMA", f_tmp);
+ }
}
- agent = ril_get_agent (s, &address->peer, GNUNET_NO);
- if (NULL == agent)
+ solver->parameters.alpha = RIL_DEFAULT_GRADIENT_STEP_SIZE;
+ if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
+ "RIL_GRADIENT_STEP_SIZE", &f_tmp))
{
- GNUNET_assert(!ril_network_is_active (solver, current_network));
-
- GAS_ril_address_add (s, address, new_network);
- return;
+ if ((f_tmp < 0.0) || (f_tmp > 1.0))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
+ "RIL_GRADIENT_STEP_SIZE", f_tmp);
+ }
+ else
+ {
+ solver->parameters.alpha = f_tmp;
+ LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
+ "RIL_GRADIENT_STEP_SIZE", f_tmp);
+ }
}
- address->solver_information = ril_get_network(solver, new_network);
-}
-
-/**
- * Give feedback about the current assignment
- *
- * @param solver the solver handle
- * @param application the application
- * @param peer the peer to change the preference for
- * @param scope the time interval for this feedback: [now - scope .. now]
- * @param kind the kind to change the preference
- * @param score the score
- */
-void
-GAS_ril_address_preference_feedback (void *solver,
- void *application,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TIME_Relative scope,
- enum GNUNET_ATS_PreferenceKind kind,
- double score)
-{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f from application %s for "
- "preference %s for %d seconds\n", GNUNET_i2s (peer), "UNKNOWN",
- GNUNET_ATS_print_preference_type (kind), scope.rel_value_us / 1000000);
-}
-
-/**
- * Start a bulk operation
- *
- * @param solver the solver
- */
-void
-GAS_ril_bulk_start (void *solver)
-{
- struct GAS_RIL_Handle *s = solver;
-
- LOG(GNUNET_ERROR_TYPE_DEBUG, "API_bulk_start() lock: %d\n", s->bulk_lock+1);
-
- s->bulk_lock++;
-}
-
-/**
- * Bulk operation done
- *
- * @param solver the solver handle
- */
-void
-GAS_ril_bulk_stop (void *solver)
-{
- struct GAS_RIL_Handle *s = solver;
-
- LOG(GNUNET_ERROR_TYPE_DEBUG, "API_bulk_stop() lock: %d\n", s->bulk_lock-1);
-
- if (s->bulk_lock < 1)
+ solver->parameters.lambda = RIL_DEFAULT_TRACE_DECAY;
+ if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
+ "RIL_TRACE_DECAY", &f_tmp))
{
- GNUNET_break(0);
- return;
+ if ((f_tmp < 0.0) || (f_tmp > 1.0))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
+ "RIL_TRACE_DECAY", f_tmp);
+ }
+ else
+ {
+ solver->parameters.lambda = f_tmp;
+ LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
+ "RIL_TRACE_DECAY", f_tmp);
+ }
}
- s->bulk_lock--;
- if (0 < s->bulk_changes)
+ solver->parameters.epsilon_init = RIL_DEFAULT_EXPLORE_RATIO;
+ if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
+ "RIL_EXPLORE_RATIO", &f_tmp))
{
- ril_step (solver);
- s->bulk_changes = 0;
+ if ((f_tmp < 0.0) || (f_tmp > 1.0))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
+ "RIL_EXPLORE_RATIO", f_tmp);
+ }
+ else
+ {
+ solver->parameters.epsilon_init = f_tmp;
+ LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
+ "RIL_EXPLORE_RATIO", f_tmp);
+ }
}
-}
-/**
- * Tell solver to notify ATS if the address to use changes for a specific
- * peer using the bandwidth changed callback
- *
- * The solver must only notify about changes for peers with pending address
- * requests!
- *
- * @param solver the solver handle
- * @param peer the identity of the peer
- */
-const struct ATS_Address *
-GAS_ril_get_preferred_address (void *solver, const struct GNUNET_PeerIdentity *peer)
-{
- struct GAS_RIL_Handle *s = solver;
- struct RIL_Peer_Agent *agent;
+ solver->parameters.epsilon_decay = RIL_DEFAULT_EXPLORE_DECAY;
+ if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
+ "RIL_EXPLORE_DECAY", &f_tmp))
+ {
+ if ((f_tmp < 0.0) || (f_tmp > 0.0))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
+ "RIL_EXPLORE_DECAY", f_tmp);
+ }
+ else
+ {
+ solver->parameters.epsilon_decay = f_tmp;
+ LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
+ "RIL_EXPLORE_DECAY", f_tmp);
+ }
+ }
- LOG(GNUNET_ERROR_TYPE_DEBUG, "API_get_preferred_address()\n");
+ solver->parameters.temperature_init = RIL_DEFAULT_TEMPERATURE;
+ if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
+ "RIL_TEMPERATURE", &f_tmp))
+ {
+ if (f_tmp <= 0.0)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
+ "RIL_TEMPERATURE", f_tmp);
+ }
+ else
+ {
+ solver->parameters.temperature_init = f_tmp;
+ LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
+ "RIL_TEMPERATURE", f_tmp);
+ }
+ }
- agent = ril_get_agent (s, peer, GNUNET_YES);
+ solver->parameters.temperature_decay = RIL_DEFAULT_TEMPERATURE_DECAY;
+ if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
+ "RIL_TEMPERATURE_DECAY", &f_tmp))
+ {
+ if ((f_tmp <= 0.0) || solver->parameters.temperature_decay > 1)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
+ "RIL_TEMPERATURE_DECAY", f_tmp);
+ }
+ else
+ {
+ solver->parameters.temperature_decay = f_tmp;
+ LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
+ "RIL_TEMPERATURE_DECAY", f_tmp);
+ }
+ }
- agent->is_active = GNUNET_YES;
- envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, agent->bw_out, GNUNET_YES);
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, "ats", "RIL_SIMULATE", &solver->simulate))
+ {
+ solver->simulate = GNUNET_NO;
+ }
- ril_try_unblock_agent(solver, agent, GNUNET_YES);
+ if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(env->cfg, "ats", "RIL_REPLACE_TRACES"))
+ {
+ solver->parameters.eligibility_trace_mode = RIL_E_REPLACE;
+ }
+ else
+ {
+ solver->parameters.eligibility_trace_mode = RIL_E_ACCUMULATE;
+ }
- if (agent->address_inuse)
+ if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_SOCIAL_WELFARE", &string))
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "API_get_preferred_address() Activated agent for peer '%s' with %s address %s\n",
- GNUNET_i2s (peer), agent->address_inuse->plugin, agent->address_inuse->addr);
+ solver->parameters.social_welfare = !strcmp (string, "NASH") ? RIL_WELFARE_NASH : RIL_WELFARE_EGALITARIAN;
+ GNUNET_free (string);
}
else
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "API_get_preferred_address() Activated agent for peer '%s', but no address available\n",
- GNUNET_i2s (peer));
- s->parameters.temperature = s->parameters.temperature_init;
- s->parameters.epsilon = s->parameters.epsilon_init;
+ solver->parameters.social_welfare = RIL_DEFAULT_WELFARE;
}
- return agent->address_inuse;
+
+ env->sf.s_add = &GAS_ril_address_add;
+ env->sf.s_address_update_property = &GAS_ril_address_property_changed;
+ env->sf.s_address_update_session = &GAS_ril_address_session_changed;
+ env->sf.s_address_update_inuse = &GAS_ril_address_inuse_changed;
+ env->sf.s_address_update_network = &GAS_ril_address_change_network;
+ env->sf.s_get = &GAS_ril_get_preferred_address;
+ env->sf.s_get_stop = &GAS_ril_stop_get_preferred_address;
+ env->sf.s_pref = &GAS_ril_address_change_preference;
+ env->sf.s_feedback = &GAS_ril_address_preference_feedback;
+ env->sf.s_del = &GAS_ril_address_delete;
+ env->sf.s_bulk_start = &GAS_ril_bulk_start;
+ env->sf.s_bulk_stop = &GAS_ril_bulk_stop;
+
+ solver->plugin_envi = env;
+ solver->networks_count = env->network_count;
+ solver->network_entries = GNUNET_malloc (env->network_count * sizeof (struct RIL_Scope));
+ solver->step_count = 0;
+ solver->done = GNUNET_NO;
+
+ for (c = 0; c < env->network_count; c++)
+ {
+ cur = &solver->network_entries[c];
+ cur->type = env->networks[c];
+ cur->bw_in_available = env->in_quota[c];
+ cur->bw_out_available = env->out_quota[c];
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Quotas for %s network: IN %llu - OUT %llu\n", GNUNET_ATS_print_network_type(cur->type), cur->bw_in_available/1024, cur->bw_out_available/1024);
+ }
+
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Parameters:\n");
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Algorithm = %s, alpha = %f, beta = %f, lambda = %f\n",
+ solver->parameters.algorithm ? "Q" : "SARSA",
+ solver->parameters.alpha,
+ solver->parameters.beta,
+ solver->parameters.lambda);
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "init() exploration_ratio = %f, temperature = %f, ActionSelection = %s\n",
+ solver->parameters.epsilon,
+ solver->parameters.temperature,
+ solver->parameters.select ? "EGREEDY" : "SOFTMAX");
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "init() RBF_DIVISOR = %llu\n",
+ solver->parameters.rbf_divisor);
+
+ return solver;
}
+
/**
- * Tell solver stop notifying ATS about changes for this peers
- *
- * The solver must only notify about changes for peers with pending address
- * requests!
+ * Exit point for the plugin
*
- * @param solver the solver handle
- * @param peer the peer
+ * @param cls the solver handle
*/
-void
-GAS_ril_stop_get_preferred_address (void *solver, const struct GNUNET_PeerIdentity *peer)
+void *
+libgnunet_plugin_ats_ril_done (void *cls)
{
- struct GAS_RIL_Handle *s = solver;
- struct RIL_Peer_Agent *agent;
+ struct GAS_RIL_Handle *s = cls;
+ struct RIL_Peer_Agent *cur_agent;
+ struct RIL_Peer_Agent *next_agent;
- LOG(GNUNET_ERROR_TYPE_DEBUG, "API_stop_get_preferred_address()");
+ LOG(GNUNET_ERROR_TYPE_DEBUG, "API_done() Shutting down RIL solver\n");
- agent = ril_get_agent (s, peer, GNUNET_NO);
+ s->done = GNUNET_YES;
- if (NULL == agent)
+ cur_agent = s->agents_head;
+ while (NULL != cur_agent)
{
- GNUNET_break(0);
- return;
+ next_agent = cur_agent->next;
+ GNUNET_CONTAINER_DLL_remove(s->agents_head, s->agents_tail, cur_agent);
+ agent_die (s, cur_agent);
+ cur_agent = next_agent;
}
- if (GNUNET_NO == agent->is_active)
+
+ if (GNUNET_SCHEDULER_NO_TASK != s->step_next_task_id)
{
- GNUNET_break(0);
- return;
+ GNUNET_SCHEDULER_cancel (s->step_next_task_id);
}
+ GNUNET_free(s->network_entries);
+ GNUNET_free(s);
- s->parameters.temperature = s->parameters.temperature_init;
- s->parameters.epsilon = s->parameters.epsilon_init;
-
- agent->is_active = GNUNET_NO;
-
- envi_set_active_suggestion (s, agent, agent->address_inuse, agent->bw_in, agent->bw_out,
- GNUNET_YES);
-
- ril_step (s);
-
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "API_stop_get_preferred_address() Paused agent for peer '%s' with %s address\n",
- GNUNET_i2s (peer), agent->address_inuse->plugin);
+ return NULL;
}
+
/* end of plugin_ats_ril.c */