-/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2004-2011. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
static void *lmm_variable_mallocator_new_f(void);
static void lmm_variable_mallocator_free_f(void *var);
-static void lmm_variable_mallocator_reset_f(void *var);
+#define lmm_variable_mallocator_reset_f ((void_f_pvoid_t)NULL)
static void lmm_update_modified_set(lmm_system_t sys,
lmm_constraint_t cnst);
static void lmm_remove_all_modified_set(lmm_system_t sys);
-int sg_maxmin_selective_update = 1;
static int Global_debug_id = 1;
static int Global_const_debug_id = 1;
extern xbt_swag_t keep_track;
-lmm_system_t lmm_system_new(void)
+lmm_system_t lmm_system_new(int selective_update)
{
lmm_system_t l = NULL;
s_lmm_variable_t var;
l = xbt_new0(s_lmm_system_t, 1);
l->modified = 0;
- l->selective_update_active = sg_maxmin_selective_update;
+ l->selective_update_active = selective_update;
XBT_DEBUG("Setting selective_update_active flag to %d\n",
l->selective_update_active);
XBT_INLINE void lmm_variable_disable(lmm_system_t sys, lmm_variable_t var)
{
int i;
+ int n;
+
lmm_element_t elem = NULL;
XBT_IN("(sys=%p, var=%p)", sys, var);
sys->modified = 1;
+ n = 0;
for (i = 0; i < var->cnsts_number; i++) {
elem = &var->cnsts[i];
xbt_swag_remove(elem, &(elem->constraint->element_set));
xbt_swag_remove(elem, &(elem->constraint->active_element_set));
if (!xbt_swag_size(&(elem->constraint->element_set)))
make_constraint_inactive(sys, elem->constraint);
- else
- lmm_update_modified_set(sys, elem->constraint);
+ else {
+ if (n < i)
+ var->cnsts[n].constraint = elem->constraint;
+ n++;
+ }
}
+ if (n) {
+ var->cnsts_number = n;
+ lmm_update_modified_set(sys, var->cnsts[0].constraint);
+ }
+
var->cnsts_number = 0;
XBT_OUT();
}
{
/* xbt_assert(xbt_swag_size(&(cnst->element_set)), */
/* "This list should be empty!"); */
- remove_active_constraint(sys, cnst);
+ make_constraint_inactive(sys, cnst);
free(cnst);
}
xbt_free(var);
}
-static void lmm_variable_mallocator_reset_f(void *var)
-{
- /* lmm_variable_new() initializes everything */
-}
-
lmm_variable_t lmm_variable_new(lmm_system_t sys, void *id,
double weight,
double bound, int number_of_constraints)
make_constraint_active(sys, cnst);
lmm_update_modified_set(sys, cnst);
+ if (var->cnsts_number > 1)
+ lmm_update_modified_set(sys, var->cnsts[0].constraint);
}
void lmm_expand_add(lmm_system_t sys, lmm_constraint_t cnst,
trace_buf =
xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
strcat(trace_buf, print_buf);
- fprintf(stderr, "%s", trace_buf);
- //XBT_DEBUG("%20s", trace_buf); FIXME
+ XBT_DEBUG("%20s", trace_buf);
trace_buf[0] = '\000';
XBT_DEBUG("Constraints");
strlen(trace_buf) + strlen(print_buf) + 1);
strcat(trace_buf, print_buf);
}
- // XBT_DEBUG("%s", trace_buf);
- fprintf(stderr, "%s\n", trace_buf);
+ XBT_DEBUG("%s", trace_buf);
trace_buf[0] = '\000';
xbt_assert(!double_positive(sum - cnst->bound),
"Incorrect value (%f is not smaller than %f): %g",
}
/* Find out which variables reach the maximum */
- cnst_list =
- sys->selective_update_active ? &(sys->modified_constraint_set) :
- &(sys->active_constraint_set);
min_usage = -1;
min_bound = -1;
xbt_swag_foreach(cnst, cnst_list) {
void lmm_update_variable_bound(lmm_system_t sys, lmm_variable_t var,
double bound)
{
- int i;
-
sys->modified = 1;
var->bound = bound;
- for (i = 0; i < var->cnsts_number; i++)
- lmm_update_modified_set(sys, var->cnsts[i].constraint);
-
+ if (var->cnsts_number)
+ lmm_update_modified_set(sys, var->cnsts[0].constraint);
}
xbt_swag_insert_at_head(elem, &(elem->constraint->element_set));
else
xbt_swag_insert_at_tail(elem, &(elem->constraint->element_set));
-
- lmm_update_modified_set(sys, elem->constraint);
}
if (!weight)
var->value = 0.0;
+ if (var->cnsts_number)
+ lmm_update_modified_set(sys, var->cnsts[0].constraint);
+
XBT_OUT();
}
*/
static void lmm_remove_all_modified_set(lmm_system_t sys)
{
- lmm_element_t elem = NULL;
- lmm_element_t elem_next = NULL;
- xbt_swag_t elem_list = NULL;
-
- elem_list = &(sys->modified_constraint_set);
- xbt_swag_foreach_safe(elem, elem_next, elem_list) {
- xbt_swag_remove(elem, elem_list);
- }
+ xbt_swag_reset(&sys->modified_constraint_set);
}