Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
db79c6faef62f9378433935c40f1490b807422ad
[simgrid.git] / src / surf / maxmin_private.h
1 /* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #ifndef _SURF_MAXMIN_PRIVATE_H
8 #define _SURF_MAXMIN_PRIVATE_H
9
10 #include "surf/maxmin.h"
11 #include "xbt/swag.h"
12 #include "xbt/mallocator.h"
13
14 typedef struct lmm_element {
15   /* hookup to constraint */
16   s_xbt_swag_hookup_t element_set_hookup;
17   s_xbt_swag_hookup_t active_element_set_hookup;
18
19   lmm_constraint_t constraint;
20   lmm_variable_t variable;
21   double value;
22 } s_lmm_element_t;
23 #define make_elem_active(elem) xbt_swag_insert_at_head(elem,&(elem->constraint->active_element_set))
24 #define make_elem_inactive(elem) xbt_swag_remove(elem,&(elem->constraint->active_element_set))
25
26 //typedef struct lmm_constraint_light {
27 //  double remaining_over_usage;
28 //  lmm_constraint_t cnst;
29 //} s_lmm_constraint_light_t;
30
31 typedef struct lmm_constraint {
32   /* hookup to system */
33   s_xbt_swag_hookup_t constraint_set_hookup;
34   s_xbt_swag_hookup_t active_constraint_set_hookup;
35   s_xbt_swag_hookup_t modified_constraint_set_hookup;
36   s_xbt_swag_hookup_t saturated_constraint_set_hookup;
37
38   s_xbt_swag_t element_set;     /* a list of lmm_element_t */
39   s_xbt_swag_t active_element_set;      /* a list of lmm_element_t */
40   double remaining;
41   double usage;
42   double bound;
43   int shared;
44   void *id;
45   int id_int;
46   double lambda;
47   double new_lambda;
48 } s_lmm_constraint_t;
49
50 typedef struct lmm_variable {
51   /* hookup to system */
52   s_xbt_swag_hookup_t variable_set_hookup;
53   s_xbt_swag_hookup_t saturated_variable_set_hookup;
54
55   s_lmm_element_t *cnsts;
56   int cnsts_size;
57   int cnsts_number;
58   double weight;
59   double bound;
60   double value;
61   void *id;
62   int id_int;
63   unsigned visited;             /* used by lmm_update_modified_set */
64   /* \begin{For Lagrange only} */
65   double mu;
66   double new_mu;
67   double (*func_f) (struct lmm_variable * var, double x);       /* (f)    */
68   double (*func_fp) (struct lmm_variable * var, double x);      /* (f')    */
69   double (*func_fpi) (struct lmm_variable * var, double x);     /* (f')^{-1}    */
70   /* \end{For Lagrange only} */
71 } s_lmm_variable_t;
72
73 typedef struct lmm_system {
74   int modified;
75   int selective_update_active;  /* flag to update partially the system only selecting changed portions */
76   unsigned visited_counter;     /* used by lmm_update_modified_set */
77   s_xbt_swag_t variable_set;    /* a list of lmm_variable_t */
78   s_xbt_swag_t constraint_set;  /* a list of lmm_constraint_t */
79
80   s_xbt_swag_t active_constraint_set;   /* a list of lmm_constraint_t */
81   s_xbt_swag_t modified_constraint_set; /* a list of modified lmm_constraint_t */
82
83   s_xbt_swag_t saturated_variable_set;  /* a list of lmm_variable_t */
84   s_xbt_swag_t saturated_constraint_set;        /* a list of lmm_constraint_t_t */
85
86   xbt_swag_t keep_track;
87
88   xbt_mallocator_t variable_mallocator;
89 } s_lmm_system_t;
90
91 #define extract_variable(sys) xbt_swag_extract(&(sys->variable_set))
92 #define extract_constraint(sys) xbt_swag_extract(&(sys->constraint_set))
93 #define insert_constraint(sys,cnst) xbt_swag_insert(cnst,&(sys->constraint_set))
94 #define remove_variable(sys,var) do {xbt_swag_remove(var,&(sys->variable_set));\
95                                  xbt_swag_remove(var,&(sys->saturated_variable_set));} while(0)
96 #define remove_constraint(sys,cnst) do {xbt_swag_remove(cnst,&(sys->constraint_set));\
97                                         xbt_swag_remove(cnst,&(sys->saturated_constraint_set));} while(0)
98 #define make_constraint_active(sys,cnst) xbt_swag_insert(cnst,&(sys->active_constraint_set))
99 #define make_constraint_inactive(sys,cnst) \
100   do { xbt_swag_remove(cnst, &sys->active_constraint_set);              \
101     xbt_swag_remove(cnst, &sys->modified_constraint_set); } while (0)
102
103 static void lmm_var_free(lmm_system_t sys, lmm_variable_t var);
104 static XBT_INLINE void lmm_cnst_free(lmm_system_t sys,
105                                      lmm_constraint_t cnst);
106
107 void lmm_print(lmm_system_t sys);
108
109 extern double (*func_f_def) (lmm_variable_t, double);
110 extern double (*func_fp_def) (lmm_variable_t, double);
111 extern double (*func_fpi_def) (lmm_variable_t, double);
112
113 #endif                          /* _SURF_MAXMIN_PRIVATE_H */