-/* Copyright (c) 2004-2014. The SimGrid Team.
+/* Copyright (c) 2004-2015. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
#include "portable.h"
#include "xbt/misc.h"
+#include "xbt/asserts.h"
#include "surf/datatypes.h"
#include <math.h>
+//#include <float.h>
/** @addtogroup SURF_lmm
extern double sg_maxmin_precision;
extern double sg_surf_precision;
-
+
static XBT_INLINE void double_update(double *variable, double value, double precision)
{
+ //printf("Updating %g -= %g +- %g\n",*variable,value,precision);
+ //xbt_assert(value==0 || value>precision);
+ //Check that precision is higher than the machine-dependent size of the mantissa. If not, brutal rounding may happen, and the precision mechanism is not active...
+ //xbt_assert(*variable< (2<<DBL_MANT_DIG)*precision && FLT_RADIX==2);
*variable -= value;
if (*variable < precision)
*variable = 0.0;
*
* @param cnst The constraint to share
*/
-void lmm_constraint_shared(lmm_constraint_t cnst);
+XBT_PUBLIC(void) lmm_constraint_shared(lmm_constraint_t cnst);
/**
* @brief Check if a constraint is shared (shared by default)
* @param cnst The constraint to share
* @return 1 if shared, 0 otherwise
*/
-int lmm_constraint_is_shared(lmm_constraint_t cnst);
+XBT_PUBLIC(int) lmm_constraint_is_shared(lmm_constraint_t cnst);
/**
* @brief Free a constraint
* @param sys The system associated to the constraint
* @param cnst The constraint to free
*/
-void lmm_constraint_free(lmm_system_t sys, lmm_constraint_t cnst);
+XBT_PUBLIC(void) lmm_constraint_free(lmm_system_t sys, lmm_constraint_t cnst);
/**
* @brief Get the usage of the constraint after the last lmm solve
* @param cnst A constraint
* @return The usage of the constraint
*/
-double lmm_constraint_get_usage(lmm_constraint_t cnst);
+XBT_PUBLIC(double) lmm_constraint_get_usage(lmm_constraint_t cnst);
/**
* @brief Create a new Linear MaxMin variable
* @param var A variable
* @param value The value to add to the coefficient associated to the variable in the constraint
*/
-void lmm_expand_add(lmm_system_t sys, lmm_constraint_t cnst,
+XBT_PUBLIC(void) lmm_expand_add(lmm_system_t sys, lmm_constraint_t cnst,
lmm_variable_t var, double value);
/**
* @param num The rank of constraint we want to get
* @return The numth constraint
*/
-lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t sys,
+XBT_PUBLIC(lmm_constraint_t) lmm_get_cnst_from_var(lmm_system_t sys,
lmm_variable_t var, int num);
/**
* @param num The rank of constraint we want to get
* @return The numth constraint
*/
-double lmm_get_cnst_weight_from_var(lmm_system_t sys, lmm_variable_t var,
+XBT_PUBLIC(double) lmm_get_cnst_weight_from_var(lmm_system_t sys, lmm_variable_t var,
int num);
/**
* @param var A variable
* @return The number of constraint associated to the variable
*/
-int lmm_get_number_of_cnst_from_var(lmm_system_t sys, lmm_variable_t var);
+XBT_PUBLIC(int) lmm_get_number_of_cnst_from_var(lmm_system_t sys, lmm_variable_t var);
/**
* @brief Get a var associated to a constraint
* @param elem A element of constraint of the constraint or NULL
* @return A variable associated to a constraint
*/
-lmm_variable_t lmm_get_var_from_cnst(lmm_system_t sys,
+XBT_PUBLIC(lmm_variable_t) lmm_get_var_from_cnst(lmm_system_t sys,
lmm_constraint_t cnst,
lmm_element_t * elem);
+/**
+ * @brief Get a var associated to a constraint
+ * @details Get the first variable of the next variable of elem if elem is not NULL
+ *
+ * @param cnst A constraint
+ * @param elem A element of constraint of the constraint or NULL
+ * @param nextelem A element of constraint of the constraint or NULL, the one after elem
+ * @param numelem parameter representing the number of elements to go
+ *
+ * @return A variable associated to a constraint
+ */
+XBT_PUBLIC(lmm_variable_t) lmm_get_var_from_cnst_safe(lmm_system_t /*sys*/,
+ lmm_constraint_t cnst,
+ lmm_element_t * elem,
+ lmm_element_t * nextelem,
+ int * numelem);
+
/**
* @brief Get the first active constraint of a system
*
* @param sys A system
* @return The first active constraint
*/
-lmm_constraint_t lmm_get_first_active_constraint(lmm_system_t sys);
+XBT_PUBLIC(lmm_constraint_t) lmm_get_first_active_constraint(lmm_system_t sys);
/**
* @brief Get the next active constraint of a constraint in a system
*
* @return The next active constraint
*/
-lmm_constraint_t lmm_get_next_active_constraint(lmm_system_t sys,
+XBT_PUBLIC(lmm_constraint_t) lmm_get_next_active_constraint(lmm_system_t sys,
lmm_constraint_t cnst);
#ifdef HAVE_LATENCY_BOUND_TRACKING
* @param cnst A constraint
* @return The data associated to the constraint
*/
-void *lmm_constraint_id(lmm_constraint_t cnst);
+XBT_PUBLIC(void *) lmm_constraint_id(lmm_constraint_t cnst);
/**
* @brief Get the data associated to a variable
* @param var A variable
* @return The data associated to the variable
*/
-void *lmm_variable_id(lmm_variable_t var);
+XBT_PUBLIC(void *) lmm_variable_id(lmm_variable_t var);
/**
* @brief Update the value of element linking the constraint and the variable
* @param var A variable
* @param value The new value
*/
-void lmm_update(lmm_system_t sys, lmm_constraint_t cnst,
+XBT_PUBLIC(void) lmm_update(lmm_system_t sys, lmm_constraint_t cnst,
lmm_variable_t var, double value);
/**
* @param var A constraint
* @param bound The new bound
*/
-void lmm_update_variable_bound(lmm_system_t sys, lmm_variable_t var,
+XBT_PUBLIC(void) lmm_update_variable_bound(lmm_system_t sys, lmm_variable_t var,
double bound);
/**
* @brief Update the weight of a variable
*
* @param sys A system
- * @param var A variable
+ * @param var A variable
* @param weight The new weight of the variable
*/
XBT_PUBLIC(void) lmm_update_variable_weight(lmm_system_t sys,
* @param var A variable
* @return The weight of the variable
*/
-double lmm_get_variable_weight(lmm_variable_t var);
+XBT_PUBLIC(double) lmm_get_variable_weight(lmm_variable_t var);
/**
* @brief Update a constraint bound
* @param cnst A constraint
* @return [description]
*/
-int lmm_constraint_used(lmm_system_t sys, lmm_constraint_t cnst);
+XBT_PUBLIC(int) lmm_constraint_used(lmm_system_t sys, lmm_constraint_t cnst);
/**
* @brief Solve the lmm system