+ xbt_swag_remove(elem, &(elem->constraint->enabled_element_set));
+ xbt_swag_insert_at_tail(elem, &(elem->constraint->disabled_element_set));
+
+ xbt_swag_remove(elem, &(elem->constraint->active_element_set));
+
+ lmm_decrease_concurrency(elem);
+ }
+
+ var->weight=0.0;
+ var->staged_weight=0.0;
+ var->value = 0.0;
+ lmm_check_concurrency(sys);
+}
+
+/* /brief Find variables that can be enabled and enable them.
+ *
+ * Assuming that the variable has already been removed from non-zero weights
+ * Can we find a staged variable to add?
+ * If yes, check that none of the constraints that this variable is involved in is at the limit of its concurrency
+ * And then add it to enabled variables
+ */
+void lmm_on_disabled_var(lmm_system_t sys, lmm_constraint_t cnstr){
+
+ if(cnstr->concurrency_limit<0)
+ return;
+
+ int numelem = xbt_swag_size(&(cnstr->disabled_element_set));
+ if(!numelem)
+ return;
+
+ lmm_element_t elem = (lmm_element_t)xbt_swag_getFirst(&(cnstr->disabled_element_set));
+
+ //Cannot use xbt_swag_foreach, because lmm_enable_var will modify disabled_element_set.. within the loop
+ while (numelem-- && elem) {
+
+ lmm_element_t nextelem = (lmm_element_t)xbt_swag_getNext(elem, cnstr->disabled_element_set.offset);
+
+ if (elem->variable->staged_weight>0 ){
+ //Found a staged variable
+ //TODOLATER: Add random timing function to model reservation protocol fuzziness? Then how to make sure that
+ //staged variables will eventually be called?
+ if(lmm_can_enable_var(elem->variable)){
+ lmm_enable_var(sys,elem->variable);
+ }
+ }
+
+ xbt_assert(cnstr->concurrency_current<=cnstr->concurrency_limit,"Concurrency overflow!");
+ if(cnstr->concurrency_current==cnstr->concurrency_limit)
+ break;
+
+ elem = nextelem;
+ }
+
+ //We could get an assertion fail, because transiently there can be variables that are staged and could be activated.
+ //And we need to go through all constraints of the disabled var before getting back a coherent state.
+ //Anyway, caller functions all call lmm_check_concurrency() in the end.
+ // lmm_check_concurrency(sys);
+}
+
+/* \brief update the weight of a variable, and enable/disable it.
+ * @return Returns whether a change was made
+ */
+void lmm_update_variable_weight(lmm_system_t sys, lmm_variable_t var, double weight)
+{
+
+ xbt_assert(weight>=0,"Variable weight should not be negative!");
+
+ if (weight == var->weight)
+ return;
+
+ int enabling_var= (weight>0 && var->weight<=0);
+ int disabling_var= (weight<=0 && var->weight>0);
+
+ XBT_IN("(sys=%p, var=%p, weight=%f)", sys, var, weight);
+
+ sys->modified = 1;