Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
9fd51c0725c328e1fdccc55728d79d09840bd037
[simgrid.git] / src / include / surf / maxmin.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_H
8 #define _SURF_MAXMIN_H
9
10 #include "portable.h"
11 #include "xbt/misc.h"
12 #include "surf/datatypes.h"
13 #include <math.h>
14
15 extern double sg_maxmin_precision;
16 #define MAXMIN_PRECISION sg_maxmin_precision
17 static XBT_INLINE void double_update(double *variable, double value)
18 {
19   *variable -= value;
20   if (*variable < MAXMIN_PRECISION)
21     *variable = 0.0;
22 }
23
24 static XBT_INLINE int double_positive(double value)
25 {
26   return (value > MAXMIN_PRECISION);
27 }
28
29 static XBT_INLINE int double_equals(double value1, double value2)
30 {
31   return (fabs(value1 - value2) < MAXMIN_PRECISION);
32 }
33
34 XBT_PUBLIC(lmm_system_t) lmm_system_new(int selective_update);
35 XBT_PUBLIC(void) lmm_system_free(lmm_system_t sys);
36 void lmm_variable_disable(lmm_system_t sys, lmm_variable_t var);
37
38 XBT_PUBLIC(lmm_constraint_t) lmm_constraint_new(lmm_system_t sys, void *id,
39                                                 double bound_value);
40 void lmm_constraint_shared(lmm_constraint_t cnst);
41 int lmm_constraint_is_shared(lmm_constraint_t cnst);
42
43 void lmm_constraint_free(lmm_system_t sys, lmm_constraint_t cnst);
44
45 XBT_PUBLIC(lmm_variable_t) lmm_variable_new(lmm_system_t sys, void *id,
46                                             double weight_value,
47                                             double bound,
48                                             int number_of_constraints);
49 void lmm_variable_free(lmm_system_t sys, lmm_variable_t var);
50 XBT_PUBLIC(double) lmm_variable_getvalue(lmm_variable_t var);
51 XBT_PUBLIC(double) lmm_variable_getbound(lmm_variable_t var);
52
53 XBT_PUBLIC(void) lmm_expand(lmm_system_t sys, lmm_constraint_t cnst,
54                             lmm_variable_t var, double value);
55 void lmm_expand_add(lmm_system_t sys, lmm_constraint_t cnst,
56                     lmm_variable_t var, double value);
57 void lmm_elem_set_value(lmm_system_t sys, lmm_constraint_t cnst,
58                         lmm_variable_t var, double value);
59
60 lmm_constraint_t lmm_get_cnst_from_var(lmm_system_t sys,
61                                        lmm_variable_t var, int num);
62 double lmm_get_cnst_weight_from_var(lmm_system_t sys, lmm_variable_t var,
63                                     int num);
64 int lmm_get_number_of_cnst_from_var(lmm_system_t sys, lmm_variable_t var);
65 lmm_variable_t lmm_get_var_from_cnst(lmm_system_t sys,
66                                      lmm_constraint_t cnst,
67                                      lmm_element_t * elem);
68
69 lmm_constraint_t lmm_get_first_active_constraint(lmm_system_t sys);
70 lmm_constraint_t lmm_get_next_active_constraint(lmm_system_t sys,
71                                                 lmm_constraint_t cnst);
72 #ifdef HAVE_LATENCY_BOUND_TRACKING
73 XBT_PUBLIC(int) lmm_is_variable_limited_by_latency(lmm_variable_t var);
74 #endif
75
76 void *lmm_constraint_id(lmm_constraint_t cnst);
77 void *lmm_variable_id(lmm_variable_t var);
78
79 void lmm_update(lmm_system_t sys, lmm_constraint_t cnst,
80                 lmm_variable_t var, double value);
81 void lmm_update_variable_bound(lmm_system_t sys, lmm_variable_t var,
82                                double bound);
83
84
85 XBT_PUBLIC(void) lmm_update_variable_weight(lmm_system_t sys,
86                                             lmm_variable_t var,
87                                             double weight);
88 double lmm_get_variable_weight(lmm_variable_t var);
89
90 XBT_PUBLIC(void) lmm_update_constraint_bound(lmm_system_t sys,
91                                              lmm_constraint_t cnst,
92                                              double bound);
93
94 int lmm_constraint_used(lmm_system_t sys, lmm_constraint_t cnst);
95
96
97 XBT_PUBLIC(void) lmm_solve(lmm_system_t sys);
98
99 XBT_PUBLIC(void) lagrange_solve(lmm_system_t sys);
100 XBT_PUBLIC(void) bottleneck_solve(lmm_system_t sys);
101
102 /**
103  * Default functions associated to the chosen protocol. When
104  * using the lagrangian approach.
105  */
106
107 XBT_PUBLIC(void) lmm_set_default_protocol_function(double (*func_f)
108                                                     (lmm_variable_t var,
109                                                      double x),
110                                                    double (*func_fp)
111                                                     (lmm_variable_t var,
112                                                      double x),
113                                                    double (*func_fpi)
114                                                     (lmm_variable_t var,
115                                                      double x));
116
117 XBT_PUBLIC(double func_reno_f) (lmm_variable_t var, double x);
118 XBT_PUBLIC(double func_reno_fp) (lmm_variable_t var, double x);
119 XBT_PUBLIC(double func_reno_fpi) (lmm_variable_t var, double x);
120
121 XBT_PUBLIC(double func_reno2_f) (lmm_variable_t var, double x);
122 XBT_PUBLIC(double func_reno2_fp) (lmm_variable_t var, double x);
123 XBT_PUBLIC(double func_reno2_fpi) (lmm_variable_t var, double x);
124
125 XBT_PUBLIC(double func_vegas_f) (lmm_variable_t var, double x);
126 XBT_PUBLIC(double func_vegas_fp) (lmm_variable_t var, double x);
127 XBT_PUBLIC(double func_vegas_fpi) (lmm_variable_t var, double x);
128
129
130 #endif                          /* _SURF_MAXMIN_H */