Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge 'master' into mc
[simgrid.git] / src / surf / maxmin_private.hpp
1 /* Copyright (c) 2004-2014. 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 #include "surf_interface.hpp"
14
15 /** @ingroup SURF_lmm
16  * @brief LMM element
17  */
18 typedef struct lmm_element {
19   /* hookup to constraint */
20   s_xbt_swag_hookup_t element_set_hookup;
21   s_xbt_swag_hookup_t active_element_set_hookup;
22
23   lmm_constraint_t constraint;
24   lmm_variable_t variable;
25   double value;
26 } s_lmm_element_t;
27 #define make_elem_active(elem) xbt_swag_insert_at_head(elem,&(elem->constraint->active_element_set))
28 #define make_elem_inactive(elem) xbt_swag_remove(elem,&(elem->constraint->active_element_set))
29
30 typedef struct lmm_constraint_light {
31   double remaining_over_usage;
32   lmm_constraint_t cnst;
33 } s_lmm_constraint_light_t;
34
35 /** @ingroup SURF_lmm
36  * @brief LMM constraint
37  */
38 typedef struct lmm_constraint {
39   /* hookup to system */
40   s_xbt_swag_hookup_t constraint_set_hookup;
41   s_xbt_swag_hookup_t active_constraint_set_hookup;
42   s_xbt_swag_hookup_t modified_constraint_set_hookup;
43   s_xbt_swag_hookup_t saturated_constraint_set_hookup;
44
45   s_xbt_swag_t element_set;     /* a list of lmm_element_t */
46   s_xbt_swag_t active_element_set;      /* a list of lmm_element_t */
47   double remaining;
48   double usage;
49   double bound;
50   int shared;
51   void *id;
52   int id_int;
53   double lambda;
54   double new_lambda;
55   lmm_constraint_light_t cnst_light;
56 } s_lmm_constraint_t;
57
58 /** @ingroup SURF_lmm
59  * @brief LMM variable
60  */
61 typedef struct lmm_variable {
62   /* hookup to system */
63   s_xbt_swag_hookup_t variable_set_hookup;
64   s_xbt_swag_hookup_t saturated_variable_set_hookup;
65
66   s_lmm_element_t *cnsts;
67   int cnsts_size;
68   int cnsts_number;
69   double weight;
70   double bound;
71   double value;
72   void *id;
73   int id_int;
74   unsigned visited;             /* used by lmm_update_modified_set */
75   /* \begin{For Lagrange only} */
76   double mu;
77   double new_mu;
78   double (*func_f) (struct lmm_variable * var, double x);       /* (f)    */
79   double (*func_fp) (struct lmm_variable * var, double x);      /* (f')    */
80   double (*func_fpi) (struct lmm_variable * var, double x);     /* (f')^{-1}    */
81   /* \end{For Lagrange only} */
82 } s_lmm_variable_t;
83
84 /** @ingroup SURF_lmm
85  * @brief LMM system
86  */
87 typedef struct lmm_system {
88   int modified;
89   int selective_update_active;  /* flag to update partially the system only selecting changed portions */
90   unsigned visited_counter;     /* used by lmm_update_modified_set */
91   s_xbt_swag_t variable_set;    /* a list of lmm_variable_t */
92   s_xbt_swag_t constraint_set;  /* a list of lmm_constraint_t */
93
94   s_xbt_swag_t active_constraint_set;   /* a list of lmm_constraint_t */
95   s_xbt_swag_t modified_constraint_set; /* a list of modified lmm_constraint_t */
96
97   s_xbt_swag_t saturated_variable_set;  /* a list of lmm_variable_t */
98   s_xbt_swag_t saturated_constraint_set;        /* a list of lmm_constraint_t_t */
99
100   ActionLmmListPtr keep_track;
101
102   xbt_mallocator_t variable_mallocator;
103 } s_lmm_system_t;
104
105 #define extract_variable(sys) xbt_swag_extract(&(sys->variable_set))
106 #define extract_constraint(sys) xbt_swag_extract(&(sys->constraint_set))
107 #define insert_constraint(sys,cnst) xbt_swag_insert(cnst,&(sys->constraint_set))
108 #define remove_variable(sys,var) do {xbt_swag_remove(var,&(sys->variable_set));\
109                                  xbt_swag_remove(var,&(sys->saturated_variable_set));} while(0)
110 #define remove_constraint(sys,cnst) do {xbt_swag_remove(cnst,&(sys->constraint_set));\
111                                         xbt_swag_remove(cnst,&(sys->saturated_constraint_set));} while(0)
112 #define make_constraint_active(sys,cnst) xbt_swag_insert(cnst,&(sys->active_constraint_set))
113 #define make_constraint_inactive(sys,cnst) \
114   do { xbt_swag_remove(cnst, &sys->active_constraint_set);              \
115     xbt_swag_remove(cnst, &sys->modified_constraint_set); } while (0)
116
117 /** @ingroup SURF_lmm
118  * @brief Print informations about a lmm system
119  * 
120  * @param sys A lmm system
121  */
122 void lmm_print(lmm_system_t sys);
123
124 extern double (*func_f_def) (lmm_variable_t, double);
125 extern double (*func_fp_def) (lmm_variable_t, double);
126 extern double (*func_fpi_def) (lmm_variable_t, double);
127
128 #endif                          /* _SURF_MAXMIN_PRIVATE_H */