Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
document last changes
[simgrid.git] / src / nws_portability / Include / forc.h
1 #if !defined(FORC_H)
2
3 #define FORC_H
4
5 /*
6  * forcb structure contains generic forecasting fields.  The individual
7  * forecastres can see the current time series and time_stamps as well
8  * as any other local state that wish to preserve.
9  */
10
11 #include "fbuff.h"
12 #include "mse_forc.h"
13
14 struct forcb_stc
15 {
16         fbuff series;                   /* data series */
17         fbuff time_stamps;              /* time stamp series */
18         fbuff se_series;                /* cumulative sq. err. series */
19         fbuff ae_series;                /* cumulative ab err series */
20         double best_f;                  /* best forecast */
21         int best_i;                     /* best forecast number */
22         double best_err;                /* cum best err */
23         char *state;
24         double se;
25         double ae;
26         double count;
27         void (*update)();
28         int (*forecast)();
29         void (*free)();
30         char name[255];
31 };
32
33 typedef struct forcb_stc *forcb;
34
35 #define FORCB_SIZE (sizeof(struct forcb_stc))
36
37
38 /*
39  * list of forcb structs -- used as a cookie through the interface
40  */
41 struct fork_list_stc
42 {
43         forcb *forcs;
44         int count;
45         forcb *derived_forcs;
46         int derived_count;
47         forcb total_mse;
48         int total_mse_method;
49         forcb total_mae;
50         int total_mae_method;
51 };
52
53 #define FORCL_SIZE (sizeof(struct fork_list_stc))
54
55 typedef struct fork_list_stc *forcl;
56
57 struct forc_life_stc
58 {
59         char *forc_list;
60         double lifetime;
61         double epoch_end;
62         double total;
63         double count;
64 };
65 #define FORCLIFE_SIZE (sizeof(struct forc_life_stc))
66
67 typedef struct forc_life_stc *forclife;
68
69
70 /*
71  * initializes forecasting structure with as many as #max_forc_count#
72  * forecasters and a circular buffer with #buff_size# values and
73  * time_stamp entries.  Returns a cookie to be passed subsequently
74  */
75 char *
76 InitForcl(int max_forc_count, int buff_size);
77
78 /*
79  * lifetime version 
80  */
81 char *
82 InitForcLife(int max_forc_count, int buff_size, double lifetime);
83
84 /*
85  * frees forecaster state associated with cookie #i_forcl#
86  */
87 void
88 FreeForcl(char *cookie);
89
90 /*
91  * lifetime version
92  */
93 void
94 FreeForcLife(char *state);
95
96
97 /*
98  * updates forecaster state associated with #cookie# using #value#
99  * and #time_stamp#.  Neither #value# nore #time_stamp# are checked
100  * for validity
101  */
102 void
103 UpdateForecasts(char *cookie, double time_stamp, double value);
104
105 /*
106  * lifetime version
107  */
108 void
109 UpdateForcLife(char *state, double ts, double value);
110
111 /*
112  * returns value and lifetime from series (may be averages)
113  */
114 double
115 LifetimeValue(char *state);
116
117 double
118 LifetimeTimestamp(char *state);
119
120
121
122 /*
123  * generates MSE nd MAE forecasts value for data associated with #cookie#
124  */
125 double MSEForecast(char *cookie);
126 double MSEOptForecast(char *cookie);
127 double MSEError(char *cookie);
128 int MSEMethod(char *cookie);
129 int MSEOptMethod(char *cookie);
130 double MAEForecast(char *cookie);
131 double MAEOptForecast(char *cookie);
132 double MAEError(char *cookie);
133 int MAEMethod(char *cookie);
134 int MAEOptMethod(char *cookie);
135
136 /*
137  * same API for versions that take a lifetime and forecast the average
138  */
139 double MSELifetimeForecast(char *cookie);
140 double MSELifetimeError(char *cookie);
141 int MSELifetimeMethod(char *cookie);
142 double MSELifetimeEpoch(char *cookie);
143 double MAELifetimeForecast(char *cookie);
144 double MAELifetimeError(char *cookie);
145 int MAELifetimeMethod(char *cookie);
146 double MAELifetimeEpoch(char *cookie);
147
148 /*
149  * prints the low and high forecasts and their forecast numbers
150  */
151 int
152 ForcRange(char *cookie, double *low, double *high, int *low_i, int *high_i);
153
154 /*
155  * prints a summary of forecaster state
156  */
157 void PrintForecastSummary(char *state);
158 void PrintLifetimeForecastSummary(char *state);
159
160 /*
161  * routine put in to support FORECASTAPI_MethodName which doesn't
162  * take a state record
163  */
164 void GetForcNames(char *state, 
165                   char *methodNames[], 
166                   int max_size, 
167                   int *out_size);
168
169 /*
170  * generic interface requiring no size parameterization -- could waste
171  * space
172  */
173
174 /*
175  * maximum number of forecasters
176  */
177 #define MAX_FORC (35)
178
179 /*
180  * default size of circular buffer
181  */
182 #define MAX_DATA_ENTRIES (100)
183
184 #define INITFORECASTER() (InitForcl(MAX_FORC,MAX_DATA_ENTRIES))
185 #define FREEFORECASTER(cookie) (FreeForcl(cookie))
186 #define UPDATEFORECASTER(cookie,ts,v) (UpdateForecasts((cookie),(ts),(v)))
187 #define FORECAST(cookie) (MSEForecast((cookie)))
188
189 #define DBIG_VAL (999999999999999999999999999.99)
190 #define FORE_ERROR_VAL (DBIG_VAL)
191
192
193 #endif