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 sys The system associated to the variable (not used)
+ * @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
*
return NULL;
}
+//if we modify the swag between calls, normal version may loop forever
+//this safe version ensures that we browse the swag elements only once
+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)
+{
+ if (!(*elem)){
+ *elem = (lmm_element_t) xbt_swag_getFirst(&(cnst->element_set));
+ *numelem = xbt_swag_size(&(cnst->element_set))-1;
+ }else{
+ *elem = *nextelem;
+ if(*numelem>0){
+ (*numelem) --;
+ }else
+ return NULL;
+ }
+ if (*elem){
+ *nextelem = (lmm_element_t) xbt_swag_getNext(*elem, cnst->element_set.offset);
+ return (*elem)->variable;
+ }else
+ return NULL;
+}
+
void *lmm_constraint_id(lmm_constraint_t cnst)
{
return cnst->id;
(p_power.peak * p_power.scale);
lmm_variable_t var = NULL;
lmm_element_t elem = NULL;
+ lmm_element_t nextelem = NULL;
+ int numelem = 0;
+
NetworkCm02ActionPtr action = NULL;
p_power.peak = value;
TRACE_surf_link_set_bandwidth(date, getName(), sg_bandwidth_factor * p_power.peak * p_power.scale);
#endif
if (sg_weight_S_parameter > 0) {
- while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), getConstraint(), &elem))) {
+ while ((var = lmm_get_var_from_cnst_safe(getModel()->getMaxminSystem(), getConstraint(), &elem, &nextelem, &numelem))) {
action = (NetworkCm02ActionPtr) lmm_variable_id(var);
action->m_weight += delta;
if (!action->isSuspended())
double delta = value - m_latCurrent;
lmm_variable_t var = NULL;
lmm_element_t elem = NULL;
+ lmm_element_t nextelem = NULL;
+ int numelem = 0;
NetworkCm02ActionPtr action = NULL;
m_latCurrent = value;
- while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), getConstraint(), &elem))) {
+ while ((var = lmm_get_var_from_cnst_safe(getModel()->getMaxminSystem(), getConstraint(), &elem, &nextelem, &numelem))) {
action = (NetworkCm02ActionPtr) lmm_variable_id(var);
action->m_latCurrent += delta;
action->m_weight += delta;