/* This program is free software; you can redistribute it and/or modify it
under the terms of the license (GNU LGPL) which comes with this package. */
-typedef long double FLOAT ;
+typedef long double FLOAT;
-typedef struct lmm_var_element *lmm_var_element_t;
-typedef struct lmm_cnst_element *lmm_cnst_element_t;
+typedef struct lmm_variable *lmm_variable_t;
+typedef struct lmm_constraint *lmm_constraint_t;
typedef struct lmm_system *lmm_system_t;
lmm_system_t lmm_system_new(void);
-void lmm_system_free(lmm_system_t system);
+void lmm_system_free(lmm_system_t sys);
-lmm_cnst_element_t lmm_add_constraint(lmm_system_t system, void *id, FLOAT bound_value);
-lmm_var_element_t lmm_add_variable(lmm_system_t system, void *id, FLOAT weight_value, int number_of_constraints);
-void lmm_extend_cnsts(lmm_system_t system, lmm_cnst_element_t cnsts,
- lmm_var_element_t var, FLOAT value);
+lmm_constraint_t lmm_constraint_new(lmm_system_t sys, /* void *id, */
+ FLOAT bound_value);
+void lmm_constraint_free(lmm_system_t sys, lmm_constraint_t cnst);
-void lmm_del_constraint(lmm_system_t system, lmm_cnst_element_t cnsts);
-void lmm_del_var(lmm_system_t system, lmm_var_element_t var);
+lmm_variable_t lmm_variable_new(lmm_system_t sys, /* void *id, */
+ FLOAT weight_value, FLOAT bound,
+ int number_of_constraints);
+void lmm_variable_free(lmm_system_t sys, lmm_variable_t var);
+void lmm_add_constraint(lmm_system_t sys, lmm_constraint_t cnst,
+ lmm_variable_t var, FLOAT value);
-void lmm_solve(lmm_system_t system, void ***p_id_table, int *p_id_table_size);
+void lmm_solve(lmm_system_t sys);
/* This program is free software; you can redistribute it and/or modify it
under the terms of the license (GNU LGPL) which comes with this package. */
+#include "xbt/sysdep.h"
+#include "xbt/error.h"
#include "maxmin_private.h"
+#include <stdlib.h>
+lmm_system_t lmm_system_new(void)
+{
+ lmm_system_t l = NULL;
+ s_lmm_variable_t var;
+ s_lmm_constraint_t cnst;
+
+ l = xbt_new0(s_lmm_system_t, 1);
+
+ xbt_swag_init(&(l->variable_set),
+ xbt_swag_offset(var, variable_set_hookup));
+ xbt_swag_init(&(l->constraint_set),
+ xbt_swag_offset(cnst, constraint_set_hookup));
+
+ return l;
+}
+
+void lmm_system_free(lmm_system_t sys)
+{
+ lmm_variable_t var = NULL;
+ lmm_constraint_t cnst = NULL;
+
+ while ((var = extract_variable(sys)))
+ lmm_var_free(var);
+
+ while ((cnst = extract_constraint(sys)))
+ lmm_cnst_free(cnst);
+
+ xbt_free(sys);
+}
+
+static void lmm_var_free(lmm_variable_t var)
+{
+ int i;
+ lmm_element_t elem = NULL;
+
+ for (i = 0; i < var->cnsts_number; i++) {
+ elem = &var->cnsts[i];
+ xbt_swag_extract(elem, &(elem->constraint->element_set));
+ }
+ xbt_free(var->cnsts);
+ xbt_free(var);
+}
+
+static void lmm_cnst_free(lmm_constraint_t cnst)
+{
+/* xbt_assert0(xbt_fifo_size(&(cnst->row)), */
+/* "This list should be empty!"); */
+ xbt_free(cnst);
+}
+
+lmm_constraint_t lmm_constraint_new(lmm_system_t sys, /* void *id, */
+ FLOAT bound_value)
+{
+ lmm_constraint_t cnst = NULL;
+ s_lmm_element_t elem;
+
+ cnst = xbt_new0(s_lmm_constraint_t, 1);
+/* cnst->id = id; */
+ xbt_swag_init(&(cnst->element_set),
+ xbt_swag_offset(elem, element_set_hookup));
+
+ cnst->bound = bound_value;
+ cnst->usage = UNUSED_CONSTRAINT;
+ insert_constraint(sys, cnst);
+
+ return cnst;
+}
+
+void lmm_constraint_free(lmm_system_t sys, lmm_constraint_t cnst)
+{
+ remove_constraint(sys, cnst);
+ lmm_cnst_free(cnst);
+}
+
+lmm_variable_t lmm_variable_new(lmm_system_t sys, /* void *id, */
+ FLOAT weight_value, FLOAT bound,
+ int number_of_constraints)
+{
+ lmm_variable_t var = NULL;
+
+ var = xbt_new0(s_lmm_variable_t, 1);
+/* var->id = id; */
+ var->cnsts = xbt_new0(s_lmm_element_t, number_of_constraints);
+ var->cnsts_size = number_of_constraints;
+ /* var->cnsts_number = 0; *//* Useless because of the calloc */
+ var->weight_value = weight_value;
+ var->bound = bound;
+ var->value = -1;
+ insert_variable(sys, var);
+
+ return var;
+}
+
+void lmm_variable_free(lmm_system_t sys, lmm_variable_t var)
+{
+ remove_variable(sys, var);
+ lmm_var_free(var);
+}
+
+void lmm_add_constraint(lmm_system_t sys, lmm_constraint_t cnst,
+ lmm_variable_t var, FLOAT value)
+{
+ lmm_element_t elem = NULL;
+
+/* xbt_assert0(var->cnsts_number<var->cnsts_size,"Too much constraint"); */
+
+ elem = &(var->cnsts[var->cnsts_number++]);
+
+ elem->value = value;
+ elem->constraint = cnst;
+
+ insert_elem_in_constraint(elem);
+
+}
+
+void lmm_solve(lmm_system_t sys)
+{
+ void **id_table = NULL;
+
+ /* Compute Usage and store the variables that reach the maximum */
+
+ do {
+ /* Fix the variables that have to be */
+
+ /* Update Usage and store the variables that reach the maximum */
+
+ } while (1);
+
+}
under the terms of the license (GNU LGPL) which comes with this package. */
#include "surf/maxmin.h"
-#include "../src/xbt/fifo_private.h" /* Yeah! I know. It is very dirty. */
+#include "xbt/swag.h"
-typedef struct lmm_mat_element {
- s_xbt_fifo_item_t row;
+typedef struct lmm_element {
+ s_xbt_swag_hookup_t element_set_hookup;
+ lmm_constraint_t constraint;
FLOAT value;
-} s_mat_element_t;
+} s_lmm_element_t, *lmm_element_t;
+#define insert_elem_in_constraint(elem) xbt_swag_insert(elem,&(elem->constraint->element_set))
-typedef struct lmm_cnst_element {
- s_xbt_fifo_t row; /* in fact a list of lmm_mat_element_t */
- void *id;
+typedef struct lmm_constraint {
+ s_xbt_swag_hookup_t constraint_set_hookup;
+ /* void *id; */
+ s_xbt_swag_t element_set; /* a list of lmm_mat_element_t */
FLOAT bound;
FLOAT usage;
-} s_lmm_cnst_element_t;
+} s_lmm_constraint_t;
-typedef struct lmm_var_element {
- void *id;
- s_mat_element_t *cnsts;
+typedef struct lmm_variable {
+ s_xbt_swag_hookup_t variable_set_hookup;
+ /* void *id; */
+ s_lmm_element_t *cnsts;
int cnsts_size;
- FLOAT value;
+ int cnsts_number;
+ FLOAT weight_value;
FLOAT bound;
-} s_lmm_var_element_t;
+ FLOAT value;
+} s_lmm_variable_t;
typedef struct lmm_system {
- s_xbt_fifo_item_t var_set; /* in fact a list of lmm_var_element_t */
- s_xbt_fifo_item_t cnst_set; /* in fact a list of lmm_cnst_element_t */
-};
+ s_xbt_swag_t variable_set; /* a list of lmm_variable_t */
+ s_xbt_swag_t constraint_set; /* a list of lmm_constraint_t */
+
+ s_xbt_swag_t active_constraint_set; /* a list of lmm_constraint_t */
+} s_lmm_system_t;
+
+#define extract_variable(sys) xbt_swag_extract(xbt_swag_getFirst(&(sys->variable_set)),&(sys->variable_set))
+#define extract_constraint(sys) xbt_swag_extract(xbt_swag_getFirst(&(sys->constraint_set)),&(sys->constraint_set))
+#define insert_variable(sys,var) xbt_swag_insert(var,&(sys->variable_set))
+#define insert_constraint(sys,cnst) xbt_swag_insert(cnst,&(sys->constraint_set))
+#define remove_variable(sys,var) xbt_swag_extract(var,&(sys->variable_set))
+#define remove_constraint(sys,cnst) xbt_swag_extract(cnst,&(sys->constraint_set))
+
+static void lmm_var_free(lmm_variable_t e);
+static void lmm_cnst_free(lmm_constraint_t cnst);
+
+/* #define UNDEFINED_VALUE -1.0 */
+#define UNUSED_CONSTRAINT -2.0
--- /dev/null
+/* A few tests for the maxmin library */
+
+/* Authors: Arnaud Legrand */
+
+/* This program is free software; you can redistribute it and/or modify it
+ under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "surf/maxmin.h"
+
+/* */
+/* ______ */
+/* ==l1== l2 ==l3== */
+/* ------ */
+/* */
+
+void test(void);
+void test(void)
+{
+ lmm_system_t sys = NULL ;
+ lmm_constraint_t l1 = NULL;
+ lmm_constraint_t l2 = NULL;
+ lmm_constraint_t l3 = NULL;
+
+ lmm_variable_t r_1_2_3 = NULL;
+ lmm_variable_t r_1 = NULL;
+ lmm_variable_t r_2 = NULL;
+ lmm_variable_t r_3 = NULL;
+
+
+
+ sys = lmm_system_new();
+ l1 = lmm_constraint_new(sys, /* (void *) "L1", */ 1.0);
+ l2 = lmm_constraint_new(sys, /* (void *) "L2", */ 10.0);
+ l3 = lmm_constraint_new(sys, /* (void *) "L3", */ 1.0);
+
+ r_1_2_3 = lmm_variable_new(sys, /* (void *) "R 1->2->3", */ 1.0 , 1.0 , 3);
+ r_1 = lmm_variable_new(sys, /* (void *) "R 1", */ 1.0 , 1.0 , 1);
+ r_2 = lmm_variable_new(sys, /* (void *) "R 2", */ 1.0 , 1.0 , 1);
+ r_3 = lmm_variable_new(sys, /* (void *) "R 3", */ 1.0 , 1.0 , 1);
+
+ lmm_add_constraint(sys, l1, r_1_2_3, 1.0);
+ lmm_add_constraint(sys, l2, r_1_2_3, 1.0);
+ lmm_add_constraint(sys, l3, r_1_2_3, 1.0);
+
+ lmm_add_constraint(sys, l1, r_1, 1.0);
+
+ lmm_add_constraint(sys, l2, r_2, 1.0);
+
+ lmm_add_constraint(sys, l3, r_3, 1.0);
+
+ lmm_system_free(sys);
+}
+
+
+int main(int argc, char **argv)
+{
+ test();
+ return 0;
+}