1 /* Copyright (c) 2004-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 /* \file callbacks.h */
9 #include "xbt/sysdep.h"
11 #include "xbt/strbuff.h"
12 #include "xbt/mallocator.h"
13 #include "maxmin_private.hpp"
15 #include <stdio.h> /* sprintf */
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_maxmin, surf, "Logging specific to SURF (maxmin)");
19 typedef struct s_dyn_light {
23 } s_dyn_light_t, *dyn_light_t;
25 double sg_maxmin_precision = 0.00001; /* Change this with --cfg=maxmin/precision:VALUE */
26 double sg_surf_precision = 0.00001; /* Change this with --cfg=surf/precision:VALUE */
27 int sg_concurrency_limit = -1; /* Change this with --cfg=maxmin/concurrency-limit:VALUE */
29 static void *lmm_variable_mallocator_new_f();
30 static void lmm_variable_mallocator_free_f(void *var);
31 #define lmm_variable_mallocator_reset_f ((void_f_pvoid_t)nullptr)
32 static void lmm_update_modified_set(lmm_system_t sys, lmm_constraint_t cnst);
33 static void lmm_remove_all_modified_set(lmm_system_t sys);
34 static int Global_debug_id = 1;
35 static int Global_const_debug_id = 1;
37 static void lmm_var_free(lmm_system_t sys, lmm_variable_t var);
38 static inline void lmm_cnst_free(lmm_system_t sys, lmm_constraint_t cnst);
40 static void lmm_on_disabled_var(lmm_system_t sys, lmm_constraint_t cnstr);
41 static void lmm_enable_var(lmm_system_t sys, lmm_variable_t var);
42 static int lmm_can_enable_var(lmm_variable_t var);
43 static void lmm_disable_var(lmm_system_t sys, lmm_variable_t var);
44 static int lmm_concurrency_slack(lmm_constraint_t cnstr);
45 static int lmm_cnstrs_min_concurrency_slack(lmm_variable_t var);
47 static void lmm_check_concurrency(lmm_system_t sys);
49 inline int lmm_element_concurrency(lmm_element_t elem) {
50 //Ignore element with weight less than one (e.g. cross-traffic)
51 return (elem->value>=1)?1:0;
52 //There are other alternatives, but they will change the behaviour of the model..
53 //So do not use it unless you want to make a new model.
54 //If you do, remember to change the variables concurrency share to reflect it.
55 //Potential examples are:
56 //return (elem->weight>0)?1:0;//Include element as soon as weight is non-zero
57 //return (int)ceil(elem->weight);//Include element as the rounded-up integer value of the element weight
60 inline void lmm_decrease_concurrency(lmm_element_t elem) {
61 xbt_assert(elem->constraint->concurrency_current>=lmm_element_concurrency(elem));
62 elem->constraint->concurrency_current-=lmm_element_concurrency(elem);
65 inline void lmm_increase_concurrency(lmm_element_t elem) {
66 elem->constraint->concurrency_current+= lmm_element_concurrency(elem);
68 lmm_constraint_t cnstr=elem->constraint;
70 if(cnstr->concurrency_current > cnstr->concurrency_maximum)
71 cnstr->concurrency_maximum= cnstr->concurrency_current;
73 xbt_assert(cnstr->concurrency_limit<0 || cnstr->concurrency_current<=cnstr->concurrency_limit,
74 "Concurrency limit overflow!");
77 lmm_system_t lmm_system_new(bool selective_update)
79 lmm_system_t l = nullptr;
81 s_lmm_constraint_t cnst;
83 l = xbt_new0(s_lmm_system_t, 1);
86 l->selective_update_active = selective_update;
87 l->visited_counter = 1;
89 XBT_DEBUG("Setting selective_update_active flag to %d", l->selective_update_active);
91 xbt_swag_init(&(l->variable_set), xbt_swag_offset(var, variable_set_hookup));
92 xbt_swag_init(&(l->constraint_set), xbt_swag_offset(cnst, constraint_set_hookup));
94 xbt_swag_init(&(l->active_constraint_set), xbt_swag_offset(cnst, active_constraint_set_hookup));
96 xbt_swag_init(&(l->modified_constraint_set), xbt_swag_offset(cnst, modified_constraint_set_hookup));
97 xbt_swag_init(&(l->saturated_variable_set), xbt_swag_offset(var, saturated_variable_set_hookup));
98 xbt_swag_init(&(l->saturated_constraint_set), xbt_swag_offset(cnst, saturated_constraint_set_hookup));
100 l->variable_mallocator = xbt_mallocator_new(65536,
101 lmm_variable_mallocator_new_f,
102 lmm_variable_mallocator_free_f,
103 lmm_variable_mallocator_reset_f);
105 l->solve_fun = &lmm_solve;
110 void lmm_system_free(lmm_system_t sys)
112 lmm_variable_t var = nullptr;
113 lmm_constraint_t cnst = nullptr;
118 while ((var = (lmm_variable_t) extract_variable(sys))) {
119 XBT_WARN("Variable %d still in system when freing it: this may be a bug", var->id_int);
120 lmm_var_free(sys, var);
122 while ((cnst = (lmm_constraint_t) extract_constraint(sys)))
123 lmm_cnst_free(sys, cnst);
125 xbt_mallocator_free(sys->variable_mallocator);
129 static inline void lmm_variable_remove(lmm_system_t sys, lmm_variable_t var)
134 lmm_element_t elem = nullptr;
136 XBT_IN("(sys=%p, var=%p)", sys, var);
139 //TODOLATER Can do better than that by leaving only the variable in only one enabled_element_set, call
140 //lmm_update_modified_set, and then remove it..
141 if(var->cnsts_number)
142 lmm_update_modified_set(sys, var->cnsts[0].constraint);
144 for (i = 0; i < var->cnsts_number; i++) {
145 elem = &var->cnsts[i];
147 lmm_decrease_concurrency(elem);
148 xbt_swag_remove(elem, &(elem->constraint->enabled_element_set));
149 xbt_swag_remove(elem, &(elem->constraint->disabled_element_set));
150 xbt_swag_remove(elem, &(elem->constraint->active_element_set));
151 nelements=xbt_swag_size(&(elem->constraint->enabled_element_set)) +
152 xbt_swag_size(&(elem->constraint->disabled_element_set));
154 make_constraint_inactive(sys, elem->constraint);
156 lmm_on_disabled_var(sys,elem->constraint);
159 //Check if we can enable new variables going through the constraints where var was.
160 //Do it after removing all elements, so he first disabled variables get priority over those with smaller requirement
161 for (i = 0; i < var->cnsts_number; i++) {
162 elem = &var->cnsts[i];
163 if(xbt_swag_size(&(elem->constraint->disabled_element_set)))
164 lmm_on_disabled_var(sys,elem->constraint);
167 var->cnsts_number = 0;
169 lmm_check_concurrency(sys);
174 static void lmm_var_free(lmm_system_t sys, lmm_variable_t var)
176 lmm_variable_remove(sys, var);
177 xbt_mallocator_release(sys->variable_mallocator, var);
180 static inline void lmm_cnst_free(lmm_system_t sys, lmm_constraint_t cnst)
182 make_constraint_inactive(sys, cnst);
186 lmm_constraint_t lmm_constraint_new(lmm_system_t sys, void *id, double bound_value)
188 lmm_constraint_t cnst = nullptr;
189 s_lmm_element_t elem;
191 cnst = xbt_new0(s_lmm_constraint_t, 1);
193 cnst->id_int = Global_const_debug_id++;
194 xbt_swag_init(&(cnst->enabled_element_set), xbt_swag_offset(elem, enabled_element_set_hookup));
195 xbt_swag_init(&(cnst->disabled_element_set), xbt_swag_offset(elem, disabled_element_set_hookup));
196 xbt_swag_init(&(cnst->active_element_set), xbt_swag_offset(elem, active_element_set_hookup));
198 cnst->bound = bound_value;
199 cnst->concurrency_maximum=0;
200 cnst->concurrency_current=0;
201 cnst->concurrency_limit = sg_concurrency_limit;
203 cnst->sharing_policy = 1; /* FIXME: don't hardcode the value */
204 insert_constraint(sys, cnst);
209 int lmm_constraint_concurrency_limit_get(lmm_constraint_t cnst)
211 return cnst->concurrency_limit;
214 void lmm_constraint_concurrency_limit_set(lmm_constraint_t cnst, int concurrency_limit)
216 xbt_assert(concurrency_limit<0 || cnst->concurrency_maximum<=concurrency_limit,
217 "New concurrency limit should be larger than observed concurrency maximum. Maybe you want to call"
218 " lmm_constraint_concurrency_maximum_reset() to reset the maximum?");
219 cnst->concurrency_limit = concurrency_limit;
222 void lmm_constraint_concurrency_maximum_reset(lmm_constraint_t cnst)
224 cnst->concurrency_maximum = 0;
227 int lmm_constraint_concurrency_maximum_get(lmm_constraint_t cnst)
229 xbt_assert(cnst->concurrency_limit<0 || cnst->concurrency_maximum<=cnst->concurrency_limit,
230 "Very bad: maximum observed concurrency is higher than limit. This is a bug of SURF, please report it.");
231 return cnst->concurrency_maximum;
234 void lmm_constraint_shared(lmm_constraint_t cnst)
236 cnst->sharing_policy = 0;
239 /** Return true if the constraint is shared, and false if it's FATPIPE */
240 int lmm_constraint_sharing_policy(lmm_constraint_t cnst)
242 return (cnst->sharing_policy);
245 /* @brief Remove a constraint
246 * Currently this is dead code, but it is exposed in maxmin.h
247 * Apparently, this call was designed assuming that constraint would no more have elements in it.
248 * If not the case, assertion will fail, and you need to add calls e.g. to lmm_shrink before effectively removing it.
250 inline void lmm_constraint_free(lmm_system_t sys,lmm_constraint_t cnst)
252 xbt_assert(!xbt_swag_size(&(cnst->active_element_set)),"Removing constraint but it still has active elements");
253 xbt_assert(!xbt_swag_size(&(cnst->enabled_element_set)),"Removing constraint but it still has enabled elements");
254 xbt_assert(!xbt_swag_size(&(cnst->disabled_element_set)),"Removing constraint but it still has disabled elements");
255 remove_constraint(sys, cnst);
256 lmm_cnst_free(sys, cnst);
259 static void *lmm_variable_mallocator_new_f()
261 lmm_variable_t var = xbt_new(s_lmm_variable_t, 1);
262 var->cnsts = nullptr; /* will be created by realloc */
266 static void lmm_variable_mallocator_free_f(void *var)
268 xbt_free(((lmm_variable_t) var)->cnsts);
272 lmm_variable_t lmm_variable_new(lmm_system_t sys, void *id, double weight, double bound, int number_of_constraints)
274 lmm_variable_t var = nullptr;
277 XBT_IN("(sys=%p, id=%p, weight=%f, bound=%f, num_cons =%d)", sys, id, weight, bound, number_of_constraints);
279 var = (lmm_variable_t) xbt_mallocator_get(sys->variable_mallocator);
281 var->id_int = Global_debug_id++;
282 var->cnsts = (s_lmm_element_t *) xbt_realloc(var->cnsts, number_of_constraints * sizeof(s_lmm_element_t));
283 for (i = 0; i < number_of_constraints; i++) {
284 var->cnsts[i].enabled_element_set_hookup.next = nullptr;
285 var->cnsts[i].enabled_element_set_hookup.prev = nullptr;
286 var->cnsts[i].disabled_element_set_hookup.next = nullptr;
287 var->cnsts[i].disabled_element_set_hookup.prev = nullptr;
288 var->cnsts[i].active_element_set_hookup.next = nullptr;
289 var->cnsts[i].active_element_set_hookup.prev = nullptr;
290 var->cnsts[i].constraint = nullptr;
291 var->cnsts[i].variable = nullptr;
292 var->cnsts[i].value = 0.0;
294 var->cnsts_size = number_of_constraints;
295 var->cnsts_number = 0;
296 var->weight = weight;
297 var->staged_weight = 0.0;
299 var->concurrency_share = 1;
301 var->visited = sys->visited_counter - 1;
304 var->func_f = func_f_def;
305 var->func_fp = func_fp_def;
306 var->func_fpi = func_fpi_def;
308 var->variable_set_hookup.next = nullptr;
309 var->variable_set_hookup.prev = nullptr;
310 var->saturated_variable_set_hookup.next = nullptr;
311 var->saturated_variable_set_hookup.prev = nullptr;
314 xbt_swag_insert_at_head(var, &(sys->variable_set));
316 xbt_swag_insert_at_tail(var, &(sys->variable_set));
318 XBT_OUT(" returns %p", var);
322 void lmm_variable_free(lmm_system_t sys, lmm_variable_t var)
324 remove_variable(sys, var);
325 lmm_var_free(sys, var);
328 double lmm_variable_getvalue(lmm_variable_t var)
333 void lmm_variable_concurrency_share_set(lmm_variable_t var, short int concurrency_share)
335 var->concurrency_share=concurrency_share;
338 double lmm_variable_getbound(lmm_variable_t var)
343 void lmm_shrink(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var)
345 lmm_element_t elem = nullptr;
349 for (i = 0; i < var->cnsts_number; i++) {
350 elem = &(var->cnsts[i]);
351 if (elem->constraint == cnst) {
358 XBT_DEBUG("cnst %p is not found in var %p", cnst, var);
364 XBT_DEBUG("remove elem(value %f, cnst %p, var %p) in var %p", elem->value, elem->constraint, elem->variable, var);
366 /* We are going to change the constraint object and the variable object.
367 * Propagate this change to other objects. Calling here before removing variable from not active elements
368 * (inactive elements are not visited)
370 lmm_update_modified_set(sys, cnst);
371 //Useful in case var was already removed from the constraint
372 lmm_update_modified_set(sys, var->cnsts[0].constraint); // will look up enabled_element_set of this constraint, and
373 //then each var in the enabled_element_set, and each var->cnsts[i].
375 if(xbt_swag_remove(elem, &(elem->constraint->enabled_element_set)))
376 lmm_decrease_concurrency(elem);
378 xbt_swag_remove(elem, &(elem->constraint->active_element_set));
379 elem->constraint = nullptr;
380 elem->variable = nullptr;
383 var->cnsts_number -= 1;
385 //No variable in this constraint -> make it inactive
386 if (xbt_swag_size(&(cnst->enabled_element_set))+xbt_swag_size(&(cnst->disabled_element_set)) == 0)
387 make_constraint_inactive(sys, cnst);
389 //Check maxconcurrency to see if we can enable new variables
390 lmm_on_disabled_var(sys,elem->constraint);
393 lmm_check_concurrency(sys);
396 void lmm_expand(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, double value)
398 lmm_element_t elem = nullptr;
404 //Check if this variable already has an active element in this constraint
405 //If it does, substract it from the required slack
407 if(var->concurrency_share>1){
408 for( i=0; i<var->cnsts_number;i++){
409 if(var->cnsts[i].constraint==cnst &&
410 xbt_swag_belongs(&var->cnsts[i],&(var->cnsts[i].constraint->enabled_element_set)))
411 current_share+=lmm_element_concurrency(&(var->cnsts[i]));
415 //Check if we need to disable the variable
416 if(var->weight>0 && var->concurrency_share-current_share>lmm_concurrency_slack(cnst)) {
418 lmm_disable_var(sys,var);
419 for (i = 0; i < var->cnsts_number; i++)
420 lmm_on_disabled_var(sys,var->cnsts[i].constraint);
422 var->staged_weight=weight;
423 xbt_assert(!var->weight);
426 xbt_assert(var->cnsts_number < var->cnsts_size, "Too much constraints");
428 elem = &(var->cnsts[var->cnsts_number++]);
431 elem->constraint = cnst;
432 elem->variable = var;
435 xbt_swag_insert_at_head(elem, &(elem->constraint->enabled_element_set));
436 lmm_increase_concurrency(elem);
438 xbt_swag_insert_at_tail(elem, &(elem->constraint->disabled_element_set));
440 if(!sys->selective_update_active) {
441 make_constraint_active(sys, cnst);
442 } else if(elem->value>0 || var->weight >0) {
443 make_constraint_active(sys, cnst);
444 lmm_update_modified_set(sys, cnst);
445 //TODOLATER: Why do we need this second call?
446 if (var->cnsts_number > 1)
447 lmm_update_modified_set(sys, var->cnsts[0].constraint);
450 lmm_check_concurrency(sys);
453 void lmm_expand_add(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, double value)
459 lmm_check_concurrency(sys);
461 //BEWARE: In case you have multiple elements in one constraint, this will always add value to the first element.
462 for (i = 0; i < var->cnsts_number; i++)
463 if (var->cnsts[i].constraint == cnst)
466 if (i < var->cnsts_number) {
468 lmm_decrease_concurrency(&var->cnsts[i]);
470 if (cnst->sharing_policy)
471 var->cnsts[i].value += value;
473 var->cnsts[i].value = MAX(var->cnsts[i].value, value);
475 //We need to check that increasing value of the element does not cross the concurrency limit
477 if(lmm_concurrency_slack(cnst)<lmm_element_concurrency(&var->cnsts[i])){
479 lmm_disable_var(sys,var);
480 for (j = 0; j < var->cnsts_number; j++)
481 lmm_on_disabled_var(sys,var->cnsts[j].constraint);
482 var->staged_weight=weight;
483 xbt_assert(!var->weight);
485 lmm_increase_concurrency(&var->cnsts[i]);
487 lmm_update_modified_set(sys, cnst);
489 lmm_expand(sys, cnst, var, value);
491 lmm_check_concurrency(sys);
494 lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t /*sys*/, lmm_variable_t var, int num)
496 if (num < var->cnsts_number)
497 return (var->cnsts[num].constraint);
502 double lmm_get_cnst_weight_from_var(lmm_system_t /*sys*/, lmm_variable_t var, int num)
504 if (num < var->cnsts_number)
505 return (var->cnsts[num].value);
510 int lmm_get_number_of_cnst_from_var(lmm_system_t /*sys*/, lmm_variable_t var)
512 return (var->cnsts_number);
515 lmm_variable_t lmm_get_var_from_cnst(lmm_system_t /*sys*/, lmm_constraint_t cnst, lmm_element_t * elem)
518 // That is the first call, pick the first element among enabled_element_set (or disabled_element_set if
519 // enabled_element_set is empty)
520 *elem = (lmm_element_t) xbt_swag_getFirst(&(cnst->enabled_element_set));
522 *elem = (lmm_element_t) xbt_swag_getFirst(&(cnst->disabled_element_set));
524 //elem is not null, so we carry on
525 if(xbt_swag_belongs(*elem,&(cnst->enabled_element_set))){
526 //Look at enabled_element_set, and jump to disabled_element_set when finished
527 *elem = (lmm_element_t) xbt_swag_getNext(*elem, cnst->enabled_element_set.offset);
529 *elem = (lmm_element_t) xbt_swag_getFirst(&(cnst->disabled_element_set));
531 *elem = (lmm_element_t) xbt_swag_getNext(*elem, cnst->disabled_element_set.offset);
535 return (*elem)->variable;
540 //if we modify the swag between calls, normal version may loop forever
541 //this safe version ensures that we browse the swag elements only once
542 lmm_variable_t lmm_get_var_from_cnst_safe(lmm_system_t /*sys*/, lmm_constraint_t cnst, lmm_element_t * elem,
543 lmm_element_t * nextelem, int * numelem)
546 *elem = (lmm_element_t) xbt_swag_getFirst(&(cnst->enabled_element_set));
547 *numelem = xbt_swag_size(&(cnst->enabled_element_set))+xbt_swag_size(&(cnst->disabled_element_set))-1;
549 *elem = (lmm_element_t) xbt_swag_getFirst(&(cnst->disabled_element_set));
558 //elem is not null, so we carry on
559 if(xbt_swag_belongs(*elem,&(cnst->enabled_element_set))){
560 //Look at enabled_element_set, and jump to disabled_element_set when finished
561 *nextelem = (lmm_element_t) xbt_swag_getNext(*elem, cnst->enabled_element_set.offset);
563 *nextelem = (lmm_element_t) xbt_swag_getFirst(&(cnst->disabled_element_set));
565 *nextelem = (lmm_element_t) xbt_swag_getNext(*elem, cnst->disabled_element_set.offset);
567 return (*elem)->variable;
572 void *lmm_constraint_id(lmm_constraint_t cnst)
577 void *lmm_variable_id(lmm_variable_t var)
582 static inline void saturated_constraint_set_update(double usage, int cnst_light_num,
583 dyn_light_t saturated_constraint_set, double *min_usage)
585 xbt_assert(usage > 0,"Impossible");
587 if (*min_usage < 0 || *min_usage > usage) {
589 XBT_HERE(" min_usage=%f (cnst->remaining / cnst->usage =%f)", *min_usage, usage);
590 saturated_constraint_set->data[0] = cnst_light_num;
591 saturated_constraint_set->pos = 1;
592 } else if (*min_usage == usage) {
593 if(saturated_constraint_set->pos == saturated_constraint_set->size) { // realloc the size
594 saturated_constraint_set->size *= 2;
595 saturated_constraint_set->data =
596 (int*) xbt_realloc(saturated_constraint_set->data, (saturated_constraint_set->size) * sizeof(int));
598 saturated_constraint_set->data[saturated_constraint_set->pos] = cnst_light_num;
599 saturated_constraint_set->pos++;
603 static inline void saturated_variable_set_update(s_lmm_constraint_light_t *cnst_light_tab,
604 dyn_light_t saturated_constraint_set, lmm_system_t sys)
606 /* Add active variables (i.e. variables that need to be set) from the set of constraints to saturate (cnst_light_tab)*/
607 lmm_constraint_light_t cnst = nullptr;
609 lmm_element_t elem = nullptr;
610 xbt_swag_t elem_list = nullptr;
612 for(i = 0; i< saturated_constraint_set->pos; i++){
613 cnst = &cnst_light_tab[saturated_constraint_set->data[i]];
614 elem_list = &(cnst->cnst->active_element_set);
615 xbt_swag_foreach(_elem, elem_list) {
616 elem = (lmm_element_t)_elem;
617 //Visiting active_element_set, so, by construction, should never get a zero weight, correct?
618 xbt_assert(elem->variable->weight > 0);
619 if ((elem->value > 0))
620 xbt_swag_insert(elem->variable, &(sys->saturated_variable_set));
625 void lmm_print(lmm_system_t sys)
630 lmm_constraint_t cnst = nullptr;
631 lmm_element_t elem = nullptr;
632 lmm_variable_t var = nullptr;
633 xbt_swag_t cnst_list = nullptr;
634 xbt_swag_t var_list = nullptr;
635 xbt_swag_t elem_list = nullptr;
636 std::string buf = std::string("MAX-MIN ( ");
639 /* Printing Objective */
640 var_list = &(sys->variable_set);
641 xbt_swag_foreach(_var, var_list) {
642 var = (lmm_variable_t)_var;
643 buf = buf + "'" + std::to_string(var->id_int) + "'(" + std::to_string(var->weight) + ") ";
646 XBT_DEBUG("%20s", buf.c_str());
649 XBT_DEBUG("Constraints");
650 /* Printing Constraints */
651 cnst_list = &(sys->active_constraint_set);
652 xbt_swag_foreach(_cnst, cnst_list) {
653 cnst = (lmm_constraint_t)_cnst;
655 //Show the enabled variables
656 elem_list = &(cnst->enabled_element_set);
658 buf += ((cnst->sharing_policy) ? "(" : "max(");
659 xbt_swag_foreach(_elem, elem_list) {
660 elem = (lmm_element_t)_elem;
661 buf = buf + std::to_string(elem->value) + ".'" + std::to_string(elem->variable->id_int) + "'(" +
662 std::to_string(elem->variable->value) + ")" + ((cnst->sharing_policy) ? " + " : " , ");
663 if(cnst->sharing_policy)
664 sum += elem->value * elem->variable->value;
666 sum = MAX(sum,elem->value * elem->variable->value);
668 //TODO: Adding disabled elements only for test compatibility, but do we really want them to be printed?
669 elem_list = &(cnst->disabled_element_set);
670 xbt_swag_foreach(_elem, elem_list) {
671 elem = (lmm_element_t)_elem;
672 buf = buf + std::to_string(elem->value) + ".'" + std::to_string(elem->variable->id_int) + "'(" +
673 std::to_string(elem->variable->value) + ")" + ((cnst->sharing_policy) ? " + " : " , ");
674 if(cnst->sharing_policy)
675 sum += elem->value * elem->variable->value;
677 sum = MAX(sum,elem->value * elem->variable->value);
680 buf = buf + "0) <= " + std::to_string(cnst->bound) + " ('" + std::to_string(cnst->id_int) + "')";
682 if (!cnst->sharing_policy) {
683 buf += " [MAX-Constraint]";
685 XBT_DEBUG("%s", buf.c_str());
687 xbt_assert(!double_positive(sum - cnst->bound, cnst->bound*sg_maxmin_precision),
688 "Incorrect value (%f is not smaller than %f): %g", sum, cnst->bound, sum - cnst->bound);
689 //if(double_positive(sum - cnst->bound, cnst->bound*sg_maxmin_precision))
690 //XBT_ERROR("Incorrect value (%f is not smaller than %f): %g",sum, cnst->bound, sum - cnst->bound);
693 XBT_DEBUG("Variables");
694 /* Printing Result */
695 xbt_swag_foreach(_var, var_list) {
696 var = (lmm_variable_t)_var;
697 if (var->bound > 0) {
698 XBT_DEBUG("'%d'(%f) : %f (<=%f)", var->id_int, var->weight, var->value, var->bound);
699 xbt_assert(!double_positive(var->value - var->bound, var->bound*sg_maxmin_precision),
700 "Incorrect value (%f is not smaller than %f", var->value, var->bound);
702 XBT_DEBUG("'%d'(%f) : %f", var->id_int, var->weight, var->value);
707 void lmm_solve(lmm_system_t sys)
709 void *_var, *_cnst, *_cnst_next, *_elem;
710 lmm_variable_t var = nullptr;
711 lmm_constraint_t cnst = nullptr;
712 lmm_element_t elem = nullptr;
713 xbt_swag_t cnst_list = nullptr;
714 xbt_swag_t var_list = nullptr;
715 xbt_swag_t elem_list = nullptr;
716 double min_usage = -1;
717 double min_bound = -1;
719 if (!(sys->modified))
722 XBT_IN("(sys=%p)", sys);
724 /* Compute Usage and store the variables that reach the maximum. If selective_update_active is true, only constraints
725 * that changed are considered. Otherwise all constraints with active actions are considered.
727 cnst_list = sys->selective_update_active ? &(sys->modified_constraint_set) : &(sys->active_constraint_set);
729 XBT_DEBUG("Active constraints : %d", xbt_swag_size(cnst_list));
730 /* Init: Only modified code portions: reset the value of active variables */
731 xbt_swag_foreach(_cnst, cnst_list) {
732 cnst = (lmm_constraint_t)_cnst;
733 elem_list = &(cnst->enabled_element_set);
734 //XBT_DEBUG("Variable set : %d", xbt_swag_size(elem_list));
735 xbt_swag_foreach(_elem, elem_list) {
736 var = ((lmm_element_t)_elem)->variable;
737 xbt_assert(var->weight > 0.0);
742 s_lmm_constraint_light_t *cnst_light_tab =
743 (s_lmm_constraint_light_t *)xbt_malloc0(xbt_swag_size(cnst_list)*sizeof(s_lmm_constraint_light_t));
744 int cnst_light_num = 0;
745 dyn_light_t saturated_constraint_set = xbt_new0(s_dyn_light_t,1);
746 saturated_constraint_set->size = 5;
747 saturated_constraint_set->data = xbt_new0(int, saturated_constraint_set->size);
749 xbt_swag_foreach_safe(_cnst, _cnst_next, cnst_list) {
750 cnst = (lmm_constraint_t)_cnst;
751 /* INIT: Collect constraints that actually need to be saturated (i.e remaining and usage are strictly positive)
752 * into cnst_light_tab. */
753 cnst->remaining = cnst->bound;
754 if (!double_positive(cnst->remaining, cnst->bound*sg_maxmin_precision))
757 elem_list = &(cnst->enabled_element_set);
758 xbt_swag_foreach(_elem, elem_list) {
759 elem = (lmm_element_t)_elem;
760 xbt_assert(elem->variable->weight > 0);
761 if ((elem->value > 0)) {
762 if (cnst->sharing_policy)
763 cnst->usage += elem->value / elem->variable->weight;
764 else if (cnst->usage < elem->value / elem->variable->weight)
765 cnst->usage = elem->value / elem->variable->weight;
767 make_elem_active(elem);
768 simgrid::surf::Action *action = static_cast<simgrid::surf::Action*>(elem->variable->id);
769 if (sys->keep_track && !action->is_linked())
770 sys->keep_track->push_back(*action);
773 XBT_DEBUG("Constraint '%d' usage: %f remaining: %f concurrency: %i<=%i<=%i", cnst->id_int, cnst->usage,
774 cnst->remaining,cnst->concurrency_current,cnst->concurrency_maximum,cnst->concurrency_limit);
775 /* Saturated constraints update */
777 if(cnst->usage > 0) {
778 cnst_light_tab[cnst_light_num].cnst = cnst;
779 cnst->cnst_light = &(cnst_light_tab[cnst_light_num]);
780 cnst_light_tab[cnst_light_num].remaining_over_usage = cnst->remaining / cnst->usage;
781 saturated_constraint_set_update(cnst_light_tab[cnst_light_num].remaining_over_usage,
782 cnst_light_num, saturated_constraint_set, &min_usage);
783 xbt_assert(cnst->active_element_set.count>0, "There is no sense adding a constraint that has no active element!");
788 saturated_variable_set_update( cnst_light_tab, saturated_constraint_set, sys);
790 /* Saturated variables update */
792 /* Fix the variables that have to be */
793 var_list = &(sys->saturated_variable_set);
795 xbt_swag_foreach(_var, var_list) {
796 var = (lmm_variable_t)_var;
797 if (var->weight <= 0.0)
799 /* First check if some of these variables could reach their upper bound and update min_bound accordingly. */
801 ("var=%d, var->bound=%f, var->weight=%f, min_usage=%f, var->bound*var->weight=%f",
802 var->id_int, var->bound, var->weight, min_usage, var->bound * var->weight);
803 if ((var->bound > 0) && (var->bound * var->weight < min_usage)) {
805 min_bound = var->bound*var->weight;
807 min_bound = MIN(min_bound, (var->bound*var->weight));
808 XBT_DEBUG("Updated min_bound=%f", min_bound);
812 while ((var = (lmm_variable_t)xbt_swag_getFirst(var_list))) {
816 //If no variable could reach its bound, deal iteratively the constraints usage ( at worst one constraint is
817 // saturated at each cycle)
818 var->value = min_usage / var->weight;
819 // XBT_DEBUG("Setting %p (%d) value to %f\n", var, var->id_int, var->value);
820 XBT_DEBUG("Setting var (%d) value to %f\n", var->id_int, var->value);
822 //If there exist a variable that can reach its bound, only update it (and other with the same bound) for now.
823 if (double_equals(min_bound, var->bound*var->weight, sg_maxmin_precision)){
824 var->value = var->bound;
825 XBT_DEBUG("Setting %p (%d) value to %f\n", var, var->id_int, var->value);
827 // Variables which bound is different are not considered for this cycle, but they will be afterwards.
828 XBT_DEBUG("Do not consider %p (%d) \n", var, var->id_int);
829 xbt_swag_remove(var, var_list);
833 XBT_DEBUG("Min usage: %f, Var(%d)->weight: %f, Var(%d)->value: %f ",
834 min_usage, var->id_int, var->weight, var->id_int, var->value);
836 /* Update the usage of contraints where this variable is involved */
837 for (i = 0; i < var->cnsts_number; i++) {
838 elem = &var->cnsts[i];
839 cnst = elem->constraint;
840 if (cnst->sharing_policy) {
841 //Remember: shared constraints require that sum(elem->value * var->value) < cnst->bound
842 double_update(&(cnst->remaining), elem->value * var->value, cnst->bound*sg_maxmin_precision);
843 double_update(&(cnst->usage), elem->value / var->weight, sg_maxmin_precision);
844 //If the constraint is saturated, remove it from the set of active constraints (light_tab)
845 if(!double_positive(cnst->usage,sg_maxmin_precision) ||
846 !double_positive(cnst->remaining,cnst->bound*sg_maxmin_precision)) {
847 if (cnst->cnst_light) {
848 int index = (cnst->cnst_light-cnst_light_tab);
849 XBT_DEBUG("index: %d \t cnst_light_num: %d \t || usage: %f remaining: %f bound: %f ",
850 index,cnst_light_num, cnst->usage, cnst->remaining, cnst->bound);
851 //XBT_DEBUG("index: %d \t cnst_light_num: %d \t || \t cnst: %p \t cnst->cnst_light: %p "
852 // "\t cnst_light_tab: %p usage: %f remaining: %f bound: %f ", index,cnst_light_num,
853 // cnst, cnst->cnst_light, cnst_light_tab, cnst->usage, cnst->remaining, cnst->bound);
854 cnst_light_tab[index]=cnst_light_tab[cnst_light_num-1];
855 cnst_light_tab[index].cnst->cnst_light = &cnst_light_tab[index];
857 cnst->cnst_light = nullptr;
860 cnst->cnst_light->remaining_over_usage = cnst->remaining / cnst->usage;
862 make_elem_inactive(elem);
864 //Remember: non-shared constraints only require that max(elem->value * var->value) < cnst->bound
866 make_elem_inactive(elem);
867 elem_list = &(cnst->enabled_element_set);
868 xbt_swag_foreach(_elem, elem_list) {
869 elem = (lmm_element_t)_elem;
870 xbt_assert(elem->variable->weight > 0);
871 if (elem->variable->value > 0) continue;
873 cnst->usage = MAX(cnst->usage, elem->value / elem->variable->weight);
875 //If the constraint is saturated, remove it from the set of active constraints (light_tab)
876 if(!double_positive(cnst->usage,sg_maxmin_precision) ||
877 !double_positive(cnst->remaining,cnst->bound*sg_maxmin_precision)) {
878 if(cnst->cnst_light) {
879 int index = (cnst->cnst_light-cnst_light_tab);
880 XBT_DEBUG("index: %d \t cnst_light_num: %d \t || \t cnst: %p \t cnst->cnst_light: %p "
881 "\t cnst_light_tab: %p usage: %f remaining: %f bound: %f ", index,cnst_light_num, cnst,
882 cnst->cnst_light, cnst_light_tab, cnst->usage, cnst->remaining, cnst->bound);
883 cnst_light_tab[index]=cnst_light_tab[cnst_light_num-1];
884 cnst_light_tab[index].cnst->cnst_light = &cnst_light_tab[index];
886 cnst->cnst_light = nullptr;
889 cnst->cnst_light->remaining_over_usage = cnst->remaining / cnst->usage;
890 xbt_assert(cnst->active_element_set.count>0, "Should not keep a maximum constraint that has no active"
891 " element! You want to check the maxmin precision and possible rounding effects." );
895 xbt_swag_remove(var, var_list);
898 /* Find out which variables reach the maximum */
901 saturated_constraint_set->pos = 0;
903 for(pos=0; pos<cnst_light_num; pos++){
904 xbt_assert(cnst_light_tab[pos].cnst->active_element_set.count>0, "Cannot saturate more a constraint that has"
905 " no active element! You may want to change the maxmin precision (--cfg=maxmin/precision:<new_value>)"
906 " because of possible rounding effects.\n\tFor the record, the usage of this constraint is %g while "
907 "the maxmin precision to which it is compared is %g.\n\tThe usage of the previous constraint is %g.",
908 cnst_light_tab[pos].cnst->usage, sg_maxmin_precision, cnst_light_tab[pos-1].cnst->usage);
909 saturated_constraint_set_update(cnst_light_tab[pos].remaining_over_usage, pos, saturated_constraint_set,
913 saturated_variable_set_update(cnst_light_tab, saturated_constraint_set, sys);
915 } while (cnst_light_num > 0);
918 if (sys->selective_update_active)
919 lmm_remove_all_modified_set(sys);
921 if (XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug)) {
925 lmm_check_concurrency(sys);
927 xbt_free(saturated_constraint_set->data);
928 xbt_free(saturated_constraint_set);
929 xbt_free(cnst_light_tab);
933 /** \brief Attribute the value bound to var->bound.
935 * \param sys the lmm_system_t
936 * \param var the lmm_variable_t
937 * \param bound the new bound to associate with var
939 * Makes var->bound equal to bound. Whenever this function is called a change is signed in the system. To
940 * avoid false system changing detection it is a good idea to test (bound != 0) before calling it.
942 void lmm_update_variable_bound(lmm_system_t sys, lmm_variable_t var, double bound)
947 if (var->cnsts_number)
948 lmm_update_modified_set(sys, var->cnsts[0].constraint);
951 int lmm_concurrency_slack(lmm_constraint_t cnstr){
952 //FIXME MARTIN: Replace by infinite value std::numeric_limits<int>::(max)(), or something better within Simgrid?
953 if(cnstr->concurrency_limit<0)
956 return cnstr->concurrency_limit - cnstr->concurrency_current;
959 /** \brief Measure the minimum concurrency slack across all constraints where the given var is involved */
960 int lmm_cnstrs_min_concurrency_slack(lmm_variable_t var){
962 //FIXME MARTIN: Replace by infinite value std::numeric_limits<int>::(max)(), or something better within Simgrid?
963 int slack,minslack=666;
964 for (i = 0; i < var->cnsts_number; i++) {
965 slack=lmm_concurrency_slack(var->cnsts[i].constraint);
967 //This is only an optimization, to avoid looking at more constraints when slack is already zero
968 //Disable it when debugging to let lmm_concurrency_slack catch nasty things
969 if(!slack && !XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug))
979 /* /Check if a variable can be enabled
981 * Make sure to set staged_weight before, if your intent is only to check concurrency
983 int lmm_can_enable_var(lmm_variable_t var){
984 return var->staged_weight>0 && lmm_cnstrs_min_concurrency_slack(var)>=var->concurrency_share;
987 //Small remark: In this implementation of lmm_enable_var and lmm_disable_var, we will meet multiple times with var when
988 // running lmm_update_modified_set.
989 //A priori not a big performance issue, but we might do better by calling lmm_update_modified_set within the for loops
990 // (after doing the first for enabling==1, and before doing the last for disabling==1)
991 void lmm_enable_var(lmm_system_t sys, lmm_variable_t var){
995 xbt_assert(lmm_can_enable_var(var));
997 var->weight = var->staged_weight;
998 var->staged_weight = 0;
1000 //Enabling the variable, move to var to list head. Subtility is: here, we need to call lmm_update_modified_set AFTER
1001 // moving at least one element of var.
1003 xbt_swag_remove(var, &(sys->variable_set));
1004 xbt_swag_insert_at_head(var, &(sys->variable_set));
1005 for (i = 0; i < var->cnsts_number; i++) {
1006 elem = &var->cnsts[i];
1007 xbt_swag_remove(elem, &(elem->constraint->disabled_element_set));
1008 xbt_swag_insert_at_head(elem, &(elem->constraint->enabled_element_set));
1009 lmm_increase_concurrency(elem);
1011 if (var->cnsts_number)
1012 lmm_update_modified_set(sys, var->cnsts[0].constraint);
1014 //When used within lmm_on_disabled_var, we would get an assertion fail, because transiently there can be variables
1015 // that are staged and could be activated.
1016 //Anyway, caller functions all call lmm_check_concurrency() in the end.
1017 // lmm_check_concurrency(sys);
1020 void lmm_disable_var(lmm_system_t sys, lmm_variable_t var){
1024 xbt_assert(!var->staged_weight,"Staged weight should have been cleared");
1025 //Disabling the variable, move to var to list tail. Subtility is: here, we need to call lmm_update_modified_set BEFORE
1026 //moving the last element of var.
1027 xbt_swag_remove(var, &(sys->variable_set));
1028 xbt_swag_insert_at_tail(var, &(sys->variable_set));
1029 if (var->cnsts_number)
1030 lmm_update_modified_set(sys, var->cnsts[0].constraint);
1031 for (i = 0; i < var->cnsts_number; i++) {
1032 elem = &var->cnsts[i];
1033 xbt_swag_remove(elem, &(elem->constraint->enabled_element_set));
1034 xbt_swag_insert_at_tail(elem, &(elem->constraint->disabled_element_set));
1036 xbt_swag_remove(elem, &(elem->constraint->active_element_set));
1038 lmm_decrease_concurrency(elem);
1042 var->staged_weight=0.0;
1044 lmm_check_concurrency(sys);
1047 /* /brief Find variables that can be enabled and enable them.
1049 * Assuming that the variable has already been removed from non-zero weights
1050 * Can we find a staged variable to add?
1051 * If yes, check that none of the constraints that this variable is involved in is at the limit of its concurrency
1052 * And then add it to enabled variables
1054 void lmm_on_disabled_var(lmm_system_t sys, lmm_constraint_t cnstr){
1056 if(cnstr->concurrency_limit<0)
1059 int numelem = xbt_swag_size(&(cnstr->disabled_element_set));
1063 lmm_element_t elem = (lmm_element_t)xbt_swag_getFirst(&(cnstr->disabled_element_set));
1065 //Cannot use xbt_swag_foreach, because lmm_enable_var will modify disabled_element_set.. within the loop
1066 while (numelem-- && elem) {
1068 lmm_element_t nextelem = (lmm_element_t)xbt_swag_getNext(elem, cnstr->disabled_element_set.offset);
1070 if (elem->variable->staged_weight>0 ){
1071 //Found a staged variable
1072 //TODOLATER: Add random timing function to model reservation protocol fuzziness? Then how to make sure that
1073 //staged variables will eventually be called?
1074 if(lmm_can_enable_var(elem->variable)){
1075 lmm_enable_var(sys,elem->variable);
1079 xbt_assert(cnstr->concurrency_current<=cnstr->concurrency_limit,"Concurrency overflow!");
1080 if(cnstr->concurrency_current==cnstr->concurrency_limit)
1086 //We could get an assertion fail, because transiently there can be variables that are staged and could be activated.
1087 //And we need to go through all constraints of the disabled var before getting back a coherent state.
1088 //Anyway, caller functions all call lmm_check_concurrency() in the end.
1089 // lmm_check_concurrency(sys);
1092 /* \brief update the weight of a variable, and enable/disable it.
1093 * @return Returns whether a change was made
1095 void lmm_update_variable_weight(lmm_system_t sys, lmm_variable_t var, double weight)
1098 xbt_assert(weight>=0,"Variable weight should not be negative!");
1100 if (weight == var->weight)
1103 int enabling_var= (weight>0 && var->weight<=0);
1104 int disabling_var= (weight<=0 && var->weight>0);
1106 XBT_IN("(sys=%p, var=%p, weight=%f)", sys, var, weight);
1110 //Are we enabling this variable?
1112 var->staged_weight = weight;
1113 int minslack = lmm_cnstrs_min_concurrency_slack(var);
1114 if (minslack < var->concurrency_share) {
1115 XBT_DEBUG("Staging var (instead of enabling) because min concurrency slack %i, with weight %f and concurrency"
1116 " share %i", minslack, weight, var->concurrency_share);
1119 XBT_DEBUG("Enabling var with min concurrency slack %i", minslack);
1120 lmm_enable_var(sys,var);
1121 } else if (disabling_var){
1122 //Are we disabling this variable?
1123 lmm_disable_var(sys,var);
1128 lmm_check_concurrency(sys);
1133 double lmm_get_variable_weight(lmm_variable_t var)
1138 void lmm_update_constraint_bound(lmm_system_t sys, lmm_constraint_t cnst, double bound)
1141 lmm_update_modified_set(sys, cnst);
1142 cnst->bound = bound;
1145 int lmm_constraint_used(lmm_system_t sys, lmm_constraint_t cnst)
1147 return xbt_swag_belongs(cnst, &(sys->active_constraint_set));
1150 inline lmm_constraint_t lmm_get_first_active_constraint(lmm_system_t sys)
1152 return (lmm_constraint_t)xbt_swag_getFirst(&(sys->active_constraint_set));
1155 inline lmm_constraint_t lmm_get_next_active_constraint(lmm_system_t sys, lmm_constraint_t cnst)
1157 return (lmm_constraint_t)xbt_swag_getNext(cnst, (sys->active_constraint_set).offset);
1160 /** \brief Update the constraint set propagating recursively to
1161 * other constraints so the system should not be entirely computed.
1163 * \param sys the lmm_system_t
1164 * \param cnst the lmm_constraint_t affected by the change
1166 * A recursive algorithm to optimize the system recalculation selecting only constraints that have changed. Each
1167 * constraint change is propagated to the list of constraints for each variable.
1169 static void lmm_update_modified_set_rec(lmm_system_t sys, lmm_constraint_t cnst)
1173 //TODOLATER: Why lmm_modified_set has been changed in git version 2392B5157...? Looks equivalent logically and less obvious..
1174 xbt_swag_foreach(_elem, &cnst->enabled_element_set) {
1175 lmm_variable_t var = ((lmm_element_t)_elem)->variable;
1176 s_lmm_element_t *cnsts = var->cnsts;
1178 for (i = 0; var->visited != sys->visited_counter && i < var->cnsts_number ; i++) {
1179 if (cnsts[i].constraint != cnst && !xbt_swag_belongs(cnsts[i].constraint, &sys->modified_constraint_set)) {
1180 xbt_swag_insert(cnsts[i].constraint, &sys->modified_constraint_set);
1181 lmm_update_modified_set_rec(sys, cnsts[i].constraint);
1184 //var will be ignored in later visits as long as sys->visited_counter does not move
1185 var->visited = sys->visited_counter;
1189 static void lmm_update_modified_set(lmm_system_t sys, lmm_constraint_t cnst)
1191 /* nothing to do if selective update isn't active */
1192 if (sys->selective_update_active && !xbt_swag_belongs(cnst, &sys->modified_constraint_set)) {
1193 xbt_swag_insert(cnst, &sys->modified_constraint_set);
1194 lmm_update_modified_set_rec(sys, cnst);
1198 /** \brief Remove all constraints of the modified_constraint_set.
1200 * \param sys the lmm_system_t
1202 static void lmm_remove_all_modified_set(lmm_system_t sys)
1204 //We cleverly un-flag all variables just by incrementing sys->visited_counter
1205 //In effect, the var->visited value will no more be equal to sys->visited counter
1206 //To be clean, when visited counter has wrapped around, we force these var->visited values so that variables that
1207 //were in the modified a long (long long) time ago are not wrongly skipped here, which would lead to very nasty bugs
1208 //(i.e. not readibily reproducible, and requiring a lot of run time before happening).
1209 if (++sys->visited_counter == 1) {
1210 /* the counter wrapped around, reset each variable->visited */
1212 xbt_swag_foreach(_var, &sys->variable_set)
1213 ((lmm_variable_t)_var)->visited = 0;
1215 xbt_swag_reset(&sys->modified_constraint_set);
1219 * Returns resource load (in flop per second, or byte per second, or similar)
1221 * If the resource is shared (the default case), the load is sum of
1222 * resource usage made by every variables located on this resource.
1224 * If the resource is not shared (ie in FATPIPE mode), then the the
1225 * load is the max (not the sum) of all resource usages located on this resource.
1227 * \param cnst the lmm_constraint_t associated to the resource
1229 double lmm_constraint_get_usage(lmm_constraint_t cnst) {
1231 xbt_swag_t elem_list = &(cnst->enabled_element_set);
1234 xbt_swag_foreach(_elem, elem_list) {
1235 lmm_element_t elem = (lmm_element_t)_elem;
1236 if (elem->value > 0) {
1237 if (cnst->sharing_policy)
1238 usage += elem->value * elem->variable->value;
1239 else if (usage < elem->value * elem->variable->value)
1240 usage = std::max(usage, elem->value * elem->variable->value);
1246 void lmm_check_concurrency(lmm_system_t sys){
1251 lmm_constraint_t cnst;
1254 int i,belong_to_enabled,belong_to_disabled,belong_to_active;
1256 //These checks are very expensive, so do them only if we want to debug SURF LMM
1257 if (XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug)) {
1258 xbt_swag_foreach(_cnst, &(sys->constraint_set)) {
1259 cnst = (lmm_constraint_t) _cnst;
1261 xbt_swag_foreach(_elem, &(cnst->enabled_element_set)) {
1262 elem = (lmm_element_t)_elem;
1263 xbt_assert(elem->variable->weight > 0);
1264 concurrency+=lmm_element_concurrency(elem);
1267 xbt_swag_foreach(_elem, &(cnst->disabled_element_set)) {
1268 elem = (lmm_element_t)_elem;
1269 //We should have staged variables only if concurrency is reached in some constraint
1270 xbt_assert(cnst->concurrency_limit<0 || elem->variable->staged_weight==0 ||
1271 lmm_cnstrs_min_concurrency_slack(elem->variable) < elem->variable->concurrency_share,
1272 "should not have staged variable!");
1275 xbt_assert(cnst->concurrency_limit<0 || cnst->concurrency_limit >= concurrency,"concurrency check failed!");
1276 xbt_assert(cnst->concurrency_current == concurrency, "concurrency_current is out-of-date!");
1279 //Check that for each variable, all corresponding elements are in the same state (i.e. same element sets)
1280 xbt_swag_foreach(_var, &(sys->variable_set)) {
1281 var= (lmm_variable_t) _var;
1283 if(!var->cnsts_number)
1286 elem = &var->cnsts[0];
1287 belong_to_enabled=xbt_swag_belongs(elem,&(elem->constraint->enabled_element_set));
1288 belong_to_disabled=xbt_swag_belongs(elem,&(elem->constraint->disabled_element_set));
1289 belong_to_active=xbt_swag_belongs(elem,&(elem->constraint->active_element_set));
1291 for (i = 1; i < var->cnsts_number; i++) {
1292 elem = &var->cnsts[i];
1293 xbt_assert(belong_to_enabled==xbt_swag_belongs(elem,&(elem->constraint->enabled_element_set)),
1294 "Variable inconsistency (1): enabled_element_set");
1295 xbt_assert(belong_to_disabled==xbt_swag_belongs(elem,&(elem->constraint->disabled_element_set)),
1296 "Variable inconsistency (2): disabled_element_set");
1297 xbt_assert(belong_to_active==xbt_swag_belongs(elem,&(elem->constraint->active_element_set)),
1298 "Variable inconsistency (3): active_element_set");