Commit e2e3b4d845af581c3fc99b271cd55cf4c46cd375

Authored by Olivier Mullier
1 parent f6c4062f

nouvelle version plus claire

src/integrale.cpp deleted
@@ -1,289 +0,0 @@ @@ -1,289 +0,0 @@
1 -#include "integrale.h"  
2 -  
3 -integrale::integrale(const ibex::Interval & inf, const ibex::Interval & sup, ibex::Function* f) : _inf_bound(inf), _sup_bound(sup), _f(f)  
4 -{  
5 - _zeros_inf = nullptr;  
6 - _zeros_sup = nullptr;  
7 - _result = nullptr;  
8 -}  
9 -  
10 -integrale::~integrale()  
11 -{  
12 - if (_zeros_inf)  
13 - delete _zeros_inf;  
14 - if (_zeros_sup)  
15 - delete _zeros_sup;  
16 - if (_result)  
17 - delete _result;  
18 -  
19 -// if (_f)  
20 -// delete _f;  
21 -}  
22 -  
23 -  
24 - std::list<zero*> * integrale::construct_zeros_intern(const ibex::Interval & inf_bound)  
25 -{  
26 -#ifdef __DEBUG__  
27 - __SHOW_FCT_NAME__  
28 -#endif  
29 - //ATTENTION pas de cout << elem << endl;preuve d'unicité  
30 - std::list<zero*> * res = new std::list<zero*>();  
31 -  
32 - ibex::CtcNewton newton(*_f);  
33 -  
34 - ibex::CtcFwdBwd fb (*_f);  
35 - ibex::RoundRobin bisector(0);  
36 -  
37 - ibex::CellStack buff;  
38 -  
39 - ibex::CtcCompo comp( fb, newton);  
40 -  
41 - ibex::CtcFixPoint fix(comp, 1e-7);  
42 -  
43 - ibex::Solver s(fix, bisector, buff);  
44 -  
45 -  
46 - ibex::IntervalVector inf(1);  
47 - inf[0] = inf_bound;  
48 - std::vector<ibex::IntervalVector> sols = s.solve(inf);  
49 -  
50 - unsigned int i;  
51 - for (i = 0; i < sols.size(); i++){  
52 - //ATTENTION detection foireuse de la pente dans la cas ou [f(temp)] contient 0  
53 - ibex::IntervalVector temp(sols[i].diam());  
54 - if (i < sols.size() - 1){  
55 - for (int j = 0; j < sols[i].size(); j++){  
56 - temp[j] = (sols[i][j] + sols[i+1][j]) / 2.;  
57 - }  
58 - } else {  
59 - for (int j = 0; j < sols[i].size(); j++){  
60 - temp[j] = (sols[i][j] + inf_bound.ub()) / 2.;  
61 - }  
62 - }  
63 - if( (_f->eval_vector(temp)[0].ub() < 0.) ){  
64 - zero *current = new zero(sols[i][0], -1);  
65 - res->push_back(current);  
66 - } else {  
67 - zero *current = new zero(sols[i][0], 1);  
68 - res->push_back(current);  
69 - }  
70 - }  
71 - return res;  
72 -}  
73 -  
74 -unsigned int integrale::construct_zeros_inf()  
75 -{  
76 - _zeros_inf = construct_zeros_intern(_inf_bound);  
77 - _zeros_inf->sort();  
78 - return _zeros_inf->size();  
79 -}  
80 -  
81 -unsigned int integrale::construct_zeros_sup()  
82 -{  
83 - _zeros_sup = construct_zeros_intern(_sup_bound);  
84 - return _zeros_sup->size();  
85 -}  
86 -  
87 -ibex::Interval integrale::compute_integral(const double inf, const double sup)  
88 -{  
89 - ibex::Interval res(0.0);  
90 - double current = inf;  
91 - ibex::IntervalVector current_vec(1);  
92 - while (current < sup){  
93 - current_vec[0] = ibex::Interval(current, current + __EPS__);  
94 - res += _f->eval_vector(current_vec)[0] *__EPS__;  
95 - current += __EPS__;  
96 - }  
97 -  
98 - return res;  
99 -}  
100 -  
101 -unsigned int integrale::construct_zeros()  
102 -{  
103 - return construct_zeros_inf() + construct_zeros_sup();  
104 -}  
105 -  
106 -integrale_sol integrale::compute_integral(zero *inf, zero *sup)  
107 -{  
108 - ibex::Interval res_inter = compute_integral(inf->get_x().lb(), sup->get_x().ub());  
109 - integrale_sol res(inf, sup, res_inter);  
110 - return res;  
111 -}  
112 -  
113 -  
114 -std::pair<integrale_sol, integrale_sol> integrale::compute_integral_inf(const ibex::Interval& range)  
115 -{  
116 - std::list<integrale_sol> res_tmp;  
117 - if (!_zeros_inf){  
118 - construct_zeros_inf();  
119 - }  
120 - if (_zeros_inf->size()){  
121 - std::list<zero*>::iterator it = _zeros_inf->begin();  
122 - zero *bound_inf = new zero(ibex::Interval(range.lb()), 0);  
123 - integrale_sol integ0 = compute_integral(bound_inf, *(it));  
124 - res_tmp.push_back(integ0);  
125 -  
126 - while (it != _zeros_inf->end()){  
127 - if (*it != _zeros_inf->back()){  
128 - std::list<zero*>::iterator it_first = it;  
129 - it++;  
130 - std::list<zero*>::iterator it_second = it;  
131 - integrale_sol integ = compute_integral(*it_first, *it_second);  
132 - std::list<integrale_sol>::iterator it_tmp = res_tmp.begin();  
133 - while (it_tmp != res_tmp.end()){  
134 - *it_tmp = *it_tmp + integ;  
135 - it_tmp++;  
136 - }  
137 - res_tmp.push_back(integ);  
138 -  
139 - } else {  
140 - zero *bound = new zero(ibex::Interval(range.ub()), 0);  
141 - integrale_sol integ = compute_integral(*it, bound);  
142 - std::list<integrale_sol>::iterator it_tmp = res_tmp.begin();  
143 - while (it_tmp != res_tmp.end()){  
144 - (*it_tmp) = (*it_tmp) + integ;  
145 - it_tmp++;  
146 - }  
147 - it++;  
148 - res_tmp.push_back(integ);  
149 - }  
150 - }  
151 - } else {  
152 - zero * bound_sup = new zero(ibex::Interval(range.ub()), 0);  
153 - zero * bound_inf = new zero(ibex::Interval(range.lb()), 0);  
154 - integrale_sol integ = compute_integral(bound_inf, bound_sup);  
155 - res_tmp.push_back(integ);  
156 - ibex::Interval nul_inter(0.);  
157 - integrale_sol nul(bound_sup, bound_sup, nul_inter);  
158 - res_tmp.push_back(nul);  
159 - }  
160 - if (res_tmp.size() == 0){  
161 - cout << "Erreur, il devrait y avoir au moins une solution" << endl;  
162 - exit(EXIT_FAILURE);  
163 - }  
164 - integrale_sol min = *(res_tmp.begin());  
165 - integrale_sol max = *(res_tmp.begin());  
166 - for (auto elem : res_tmp){  
167 - if (elem.get_res_integrale().lb() < min.get_res_integrale().lb()){  
168 - min = elem;  
169 - }  
170 - if (elem.get_res_integrale().ub() > max.get_res_integrale().ub()){  
171 - max = elem;  
172 - }  
173 - }  
174 - for (auto elem : res_tmp){  
175 - if (elem != min || elem != max){  
176 - if (elem.get_inf_bound() && !elem.get_inf_bound()->is_non_zero())  
177 - delete elem.get_inf_bound();  
178 - if (elem.get_sup_bound() && !elem.get_sup_bound()->is_non_zero())  
179 - delete elem.get_sup_bound();  
180 - }  
181 - }  
182 - return pair<integrale_sol, integrale_sol>(min, max);  
183 -}  
184 -  
185 -  
186 -std::pair<integrale_sol, integrale_sol> integrale::compute_integral_sup(const ibex::Interval& range)  
187 -{  
188 - std::list<integrale_sol> res_temp;  
189 - if (!_zeros_sup){  
190 - construct_zeros_sup();  
191 - }  
192 - if (_zeros_sup->size() > 0){  
193 - std::list<zero*>::iterator it = _zeros_sup->begin();  
194 - zero * bound_sup = new zero(ibex::Interval(range.ub()), 0);  
195 - integrale_sol integ0 = compute_integral((*it), bound_sup);  
196 - res_temp.push_back(integ0);  
197 -  
198 - while (it != _zeros_sup->end()){  
199 - if (*it != _zeros_sup->back()){  
200 - std::list<zero*>::iterator it_second = it;  
201 - it++;  
202 - std::list<zero*>::iterator it_first = it;  
203 - integrale_sol integ = compute_integral(*it_first, *it_second);  
204 - std::list<integrale_sol>::iterator it_tmp = res_temp.begin();  
205 - while (it_tmp != res_temp.end()){  
206 - *it_tmp = *it_tmp + integ;  
207 - it_tmp++;  
208 - }  
209 - res_temp.push_back(integ);  
210 -  
211 - } else {  
212 - zero * bound = new zero(ibex::Interval(range.lb()), 0);  
213 - integrale_sol integ = compute_integral(bound, *it);  
214 - std::list<integrale_sol>::iterator it_tmp = res_temp.begin();  
215 - while (it_tmp != res_temp.end()){  
216 - *it_tmp = *it_tmp + integ;  
217 - it_tmp++;  
218 - }  
219 - it++;  
220 - res_temp.push_back(integ);  
221 - }  
222 - }  
223 - } else {  
224 - zero * bound_sup = new zero(ibex::Interval(range.ub()), 0);  
225 - zero * bound_inf = new zero(ibex::Interval(range.lb()), 0);  
226 - integrale_sol integ = compute_integral(bound_inf, bound_sup);  
227 - res_temp.push_back(integ);  
228 - ibex::Interval nul_inter(0.);  
229 - integrale_sol nul(bound_inf, bound_inf, nul_inter);  
230 - res_temp.push_back(nul);  
231 - }  
232 - if (res_temp.size() == 0){  
233 - cout << "Erreur, il devrait y avoir au moins une solution" << endl;  
234 - exit(EXIT_FAILURE);  
235 - }  
236 - integrale_sol min = *(res_temp.begin());  
237 - integrale_sol max = *(res_temp.begin());  
238 - for (auto elem : res_temp){  
239 - if (elem.get_res_integrale().lb() < min.get_res_integrale().lb()){  
240 - min = elem;  
241 - }  
242 - if (elem.get_res_integrale().ub() > max.get_res_integrale().ub()){  
243 - max = elem;  
244 - }  
245 - }  
246 - for (auto elem : res_temp){  
247 - if (elem != min || elem != max){  
248 - if (elem.get_inf_bound() && !elem.get_inf_bound()->is_non_zero())  
249 - delete elem.get_inf_bound();  
250 - if (elem.get_sup_bound() && !elem.get_sup_bound()->is_non_zero())  
251 - delete elem.get_sup_bound();  
252 - }  
253 - }  
254 - return pair<integrale_sol, integrale_sol>(min, max);  
255 -}  
256 -  
257 -std::pair<integrale_sol, integrale_sol> integrale::compute_integral()  
258 -{  
259 - std::pair<integrale_sol, integrale_sol> res = compute_integral_inf(_inf_bound);  
260 - zero * inf = res.first.get_sup_bound();  
261 - std::pair<integrale_sol, integrale_sol> res_sup = compute_integral_sup(_sup_bound);  
262 -  
263 - zero * sup = res_sup.first.get_inf_bound();  
264 - ibex::Interval mid = compute_integral(_inf_bound.ub(), _sup_bound.lb());  
265 - integrale_sol integ_mid(inf, sup, mid);  
266 -  
267 - res.first+= integ_mid;  
268 - res.second+= integ_mid;  
269 - res.first+= res_sup.first;  
270 - res.second+= res_sup.second;  
271 - if (_result == nullptr){  
272 - _result = new std::pair<integrale_sol, integrale_sol>(res);  
273 - } else {  
274 - *_result = res;  
275 - }  
276 - return res;  
277 -}  
278 -  
279 -  
280 -  
281 -  
282 -//========================================================================  
283 -std::ostream& operator<<(std::ostream& os, const integrale& inte)  
284 -{  
285 - os << "Integral from " << inte.get_inf_bound() << " to " << inte.get_sup_bound() << " of "  
286 - << *inte.get_f();  
287 - return os;  
288 -}  
289 -  
src/integrale.h deleted
@@ -1,70 +0,0 @@ @@ -1,70 +0,0 @@
1 -#ifndef _INTEGRALE_  
2 -#define _INTEGRALE_  
3 -#include <ibex.h>  
4 -#include <vector>  
5 -#include "zero.h"  
6 -#include "integrale_sol.h"  
7 -  
8 -// #define __DEBUG__  
9 -  
10 -  
11 -  
12 -#define __PREC__ (1e-5)  
13 -#define __EPS__ (1e-1)  
14 -#define __SHOW_FCT_NAME__ {std::cout << __func__ << std::endl;}  
15 -  
16 -  
17 -  
18 -class integrale{  
19 -private:  
20 -  
21 - ibex::Interval _inf_bound;  
22 - ibex::Interval _sup_bound;  
23 -  
24 - ibex::Function * _f;  
25 -// ibex::Variable * _x_var;  
26 -  
27 - std::list<zero*> * _zeros_inf;  
28 - std::list<zero*> * _zeros_sup;  
29 -  
30 - std::pair<integrale_sol, integrale_sol> * _result;  
31 -  
32 - std::list<zero*> * construct_zeros_intern(const ibex::Interval & inf_bound);  
33 -  
34 - integrale_sol compute_integral(zero* inf, zero* sup);  
35 -  
36 - std::list<ibex::Interval> compute_integral(const double & inf_bound, const ibex::Interval & sup_bound);  
37 -  
38 - ibex::Interval compute_integral(const double inf_bound, const double sup_bound);  
39 -  
40 - std::pair<integrale_sol, integrale_sol> compute_integral_inf(const ibex::Interval & range);  
41 -  
42 - std::pair<integrale_sol, integrale_sol> compute_integral_sup(const ibex::Interval & range);  
43 -  
44 -public:  
45 - //CONSTRUCTORS  
46 - integrale(const ibex::Interval& inf, const ibex::Interval& sup, ibex::Function * f);  
47 - ~integrale();  
48 -  
49 - //GETTERS  
50 - inline ibex::Interval get_inf_bound() const {return _inf_bound;};  
51 - inline ibex::Interval get_sup_bound() const {return _sup_bound;};  
52 - inline ibex::Function * get_f() const {return _f;};  
53 -// inline ibex::Variable * get_x_var() const {return _x_var;};  
54 - inline std::list<zero*> * get_zeros_inf(){return _zeros_inf;};  
55 - inline std::list<zero*> * get_zeros_sup(){return _zeros_sup;};  
56 - inline std::pair<integrale_sol, integrale_sol> * get_result(){return _result;};  
57 -  
58 - unsigned int construct_zeros_inf();  
59 -  
60 - unsigned int construct_zeros_sup();  
61 -  
62 - unsigned int construct_zeros();  
63 -  
64 - std::pair<integrale_sol, integrale_sol> compute_integral();  
65 -};  
66 -  
67 -  
68 -std::ostream& operator<<(std::ostream& os, const integrale& inte);  
69 -  
70 -#endif //_INTEGRALE_  
src/integrale_sol.cpp deleted
@@ -1,76 +0,0 @@ @@ -1,76 +0,0 @@
1 -/*  
2 - * <one line to give the library's name and an idea of what it does.>  
3 - * Copyright (C) 2019 <copyright holder> <email>  
4 - *  
5 - * This program is free software: you can redistribute it and/or modify  
6 - * it under the terms of the GNU General Public License as published by  
7 - * the Free Software Foundation, either version 3 of the License, or  
8 - * (at your option) any later version.  
9 - *  
10 - * This program is distributed in the hope that it will be useful,  
11 - * but WITHOUT ANY WARRANTY; without even the implied warranty of  
12 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
13 - * GNU General Public License for more details.  
14 - *  
15 - * You should have received a copy of the GNU General Public License  
16 - * along with this program. If not, see <http://www.gnu.org/licenses/>.  
17 - */  
18 -  
19 -#include "integrale_sol.h"  
20 -  
21 -integrale_sol::integrale_sol(zero* inf, zero* sup, const ibex::Interval& res) : _res_integrale(res)  
22 -{  
23 - _inf = (inf);  
24 - _sup = (sup);  
25 - _min_candidate = false;  
26 - _max_candidate = false;  
27 - if (res.ub() < 0.){  
28 - _min_candidate = true;  
29 - }  
30 - if (res.lb() > 0.){  
31 - _max_candidate = true;  
32 - }  
33 -}  
34 -  
35 -integrale_sol::~integrale_sol()  
36 -{  
37 -// if (_inf)  
38 -// delete _inf;  
39 -// if (_sup)  
40 -// delete _sup;  
41 -}  
42 -  
43 -  
44 -integrale_sol & integrale_sol::operator+=(const integrale_sol &rhs){  
45 - *this = *this + rhs;  
46 - return *this;  
47 -}  
48 -  
49 -integrale_sol operator+(const integrale_sol& lhs, const integrale_sol& rhs)  
50 -{  
51 -  
52 - if (lhs.get_sup_bound() == rhs.get_inf_bound()){  
53 - return integrale_sol(lhs.get_inf_bound(), rhs.get_sup_bound(), (lhs.get_res_integrale() + rhs.get_res_integrale()));  
54 - } else {  
55 - return integrale_sol(rhs.get_inf_bound(), lhs.get_sup_bound(), (lhs.get_res_integrale() + rhs.get_res_integrale()));  
56 - }  
57 -  
58 -}  
59 -  
60 -std::ostream & operator<<(std::ostream& os, const integrale_sol& inte)  
61 -{  
62 - os << "Integral from (" << *(inte.get_inf_bound()) << ") to (" << *inte.get_sup_bound() << ") : " << inte.get_res_integrale();  
63 - return os;  
64 -}  
65 -  
66 -bool operator==(const integrale_sol& lhs, const integrale_sol& rhs)  
67 -{  
68 - return (lhs.get_inf_bound() == rhs.get_inf_bound() && lhs.get_sup_bound() == rhs.get_sup_bound());  
69 -}  
70 -  
71 -bool operator!=(const integrale_sol& lhs, const integrale_sol& rhs)  
72 -{  
73 - return !(lhs == rhs);  
74 -}  
75 -  
76 -  
src/integrale_sol.h deleted
@@ -1,57 +0,0 @@ @@ -1,57 +0,0 @@
1 -/*  
2 - * <one line to give the library's name and an idea of what it does.>  
3 - * Copyright (C) 2019 <copyright holder> <email>  
4 - *  
5 - * This program is free software: you can redistribute it and/or modify  
6 - * it under the terms of the GNU General Public License as published by  
7 - * the Free Software Foundation, either version 3 of the License, or  
8 - * (at your option) any later version.  
9 - *  
10 - * This program is distributed in the hope that it will be useful,  
11 - * but WITHOUT ANY WARRANTY; without even the implied warranty of  
12 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
13 - * GNU General Public License for more details.  
14 - *  
15 - * You should have received a copy of the GNU General Public License  
16 - * along with this program. If not, see <http://www.gnu.org/licenses/>.  
17 - */  
18 -  
19 -#ifndef INTEGRALE_SOL_H  
20 -#define INTEGRALE_SOL_H  
21 -  
22 -#include "zero.h"  
23 -  
24 -/**  
25 - * @todo write docs  
26 - */  
27 -class integrale_sol  
28 -{  
29 -private:  
30 - zero * _inf;  
31 - zero * _sup;  
32 - ibex::Interval _res_integrale;  
33 - bool _min_candidate;  
34 - bool _max_candidate;  
35 -  
36 -public:  
37 - integrale_sol(zero *inf, zero *sup, const ibex::Interval & res);  
38 - ~integrale_sol();  
39 -  
40 - inline zero * get_inf_bound() const {return _inf;};  
41 - inline zero * get_sup_bound() const {return _sup;};  
42 - inline ibex::Interval get_res_integrale() const {return _res_integrale;};  
43 - inline bool is_min_candidate(){return _min_candidate;};  
44 - inline bool is_max_candidate(){return _max_candidate;};  
45 - void set_min_candidate(bool min){_min_candidate = min;};  
46 - void set_max_candidate(bool max){_max_candidate = max;};  
47 -  
48 -  
49 - integrale_sol & operator+=(const integrale_sol &rhs);  
50 -};  
51 -  
52 -integrale_sol operator+(const integrale_sol &, const integrale_sol &);  
53 -bool operator==(const integrale_sol &, const integrale_sol &);  
54 -bool operator!=(const integrale_sol &, const integrale_sol &);  
55 -std::ostream& operator<<(std::ostream& os, const integrale_sol& inte_sol);  
56 -  
57 -#endif // INTEGRALE_SOL_H  
src/integralii.cpp 0 → 100644
@@ -0,0 +1,176 @@ @@ -0,0 +1,176 @@
  1 +/*
  2 + * <one line to give the library's name and an idea of what it does.>
  3 + * Copyright (C) 2019 mullier <email>
  4 + *
  5 + * This program is free software: you can redistribute it and/or modify
  6 + * it under the terms of the GNU General Public License as published by
  7 + * the Free Software Foundation, either version 3 of the License, or
  8 + * (at your option) any later version.
  9 + *
  10 + * This program is distributed in the hope that it will be useful,
  11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13 + * GNU General Public License for more details.
  14 + *
  15 + * You should have received a copy of the GNU General Public License
  16 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17 + */
  18 +
  19 +#include "integralii.h"
  20 +
  21 +
  22 +std::list<ibex::Interval *>& IntegralII::compute_list_of_zeros(ibex::Interval searchdomain)
  23 +{
  24 + //ATTENTION pas de preuve d'unicité
  25 + std::list<ibex::Interval *>* res = new std::list<ibex::Interval *>();
  26 +
  27 + ibex::CtcNewton newton(*_f);
  28 +
  29 + ibex::CtcFwdBwd fb (*_f);
  30 + ibex::RoundRobin bisector(0);
  31 +
  32 + ibex::CellStack buff;
  33 +
  34 + ibex::CtcCompo comp( fb, newton);
  35 +
  36 + ibex::CtcFixPoint fix(comp, 1e-7);
  37 +
  38 + ibex::Solver s(fix, bisector, buff);
  39 +
  40 +
  41 + ibex::IntervalVector inf(1);
  42 + inf[0] = searchdomain;
  43 + std::vector<ibex::IntervalVector> sols = s.solve(inf);
  44 +
  45 + unsigned int i;
  46 + for (i = 0; i < sols.size(); i++){
  47 + //ATTENTION detection foireuse de la pente dans la cas ou [f(temp)] contient 0
  48 + ibex::Interval * current = new ibex::Interval(sols[i][0]);
  49 + res->push_back(current);
  50 + }
  51 + return *res;
  52 +}
  53 +
  54 +std::list<ibex::Interval *>& IntegralII::compute_list_of_zeros_inf()
  55 +{
  56 + std::list<ibex::Interval *>& res = compute_list_of_zeros(_inf_endpoint);
  57 + res.sort();
  58 + return res;
  59 +}
  60 +
  61 +std::list<ibex::Interval *>& IntegralII::compute_list_of_zeros_sup()
  62 +{
  63 + return compute_list_of_zeros(_sup_endpoint);
  64 +}
  65 +
  66 +
  67 +void IntegralII::compute_integral()
  68 +{
  69 +
  70 + std::list<IntegralRR> res_temp;
  71 + std::list<IntegralRR>::iterator it_sols;
  72 + ibex::Interval *current = new ibex::Interval(_inf_endpoint.lb());
  73 + IntegralRR min, max;
  74 + //=======================================================================
  75 + //Computation of the integrals in the _inf_endpoint
  76 + std::list<ibex::Interval *> list_of_zeros_inf = compute_list_of_zeros_inf();
  77 + if (list_of_zeros_inf.size()>0){
  78 + std::list<ibex::Interval *>::iterator it_zeros_inf = list_of_zeros_inf.begin();
  79 + while (it_zeros_inf != list_of_zeros_inf.end()){//calcul des intégrales entre chaque zéro de f
  80 + IntegralRR current_integral(current->mid(), (*it_zeros_inf)->mid(), _f);
  81 + it_sols = res_temp.begin();
  82 + while (it_sols != res_temp.end()){//On ajoute l'intégrale courante aux autres intégrales
  83 + *it_sols += current_integral;
  84 + it_sols++;
  85 + }
  86 + res_temp.push_back(current_integral);
  87 + current = *it_zeros_inf;
  88 + it_zeros_inf++;
  89 + }
  90 + //Dernière intégrale du dernier zéro vers la borne inf de l'intervalle
  91 + IntegralRR current_integral(current->mid(), _inf_endpoint.ub(), _f);
  92 + it_sols = res_temp.begin();
  93 + while (it_sols != res_temp.end()){//On ajoute l'intégrale courante aux autres intégrales
  94 + *it_sols += current_integral;
  95 + it_sols++;
  96 + }
  97 + res_temp.push_back(current_integral);
  98 + } else {
  99 + IntegralRR whole_integral(_inf_endpoint.lb(), _inf_endpoint.ub(), _f);
  100 + res_temp.push_back(whole_integral);
  101 + res_temp.push_back(IntegralRR(_inf_endpoint.ub(), _inf_endpoint.ub(), _f, 0.));
  102 + }
  103 + it_sols = res_temp.begin();
  104 + min = *it_sols;
  105 + max = *it_sols;
  106 + it_sols++;
  107 + while (it_sols != res_temp.end()){//On recherche le min et le max
  108 + if (max < *it_sols){
  109 + max = *it_sols;
  110 + }
  111 + if (*it_sols < min){
  112 + min = *it_sols;
  113 + }
  114 + it_sols ++;
  115 + }
  116 + delete current;
  117 +
  118 + //Calcul de l'intégrale entre les intervalles
  119 + IntegralRR integrale_milieu(_inf_endpoint.ub(), _sup_endpoint.lb(), _f);
  120 + _solution.first = min + integrale_milieu;
  121 + _solution.second = max + integrale_milieu;
  122 +
  123 + //=======================================================================
  124 + current = new ibex::Interval(_sup_endpoint.ub());
  125 + res_temp.clear();
  126 + std::list<ibex::Interval *> list_of_zeros_sup = compute_list_of_zeros_sup();
  127 + if (list_of_zeros_sup.size()>0){
  128 + std::list<ibex::Interval *>::iterator it_zeros_sup = list_of_zeros_sup.begin();
  129 + while (it_zeros_sup != list_of_zeros_sup.end()){//calcul des intégrales entre chaque zéro de f
  130 + IntegralRR current_integral((*it_zeros_sup)->mid(), current->mid(), _f);
  131 + it_sols = res_temp.begin();
  132 + while (it_sols != res_temp.end()){//On ajoute l'intégrale courante aux autres intégrales
  133 + *it_sols += current_integral;
  134 + it_sols++;
  135 + }
  136 + res_temp.push_back(current_integral);
  137 + current = *it_zeros_sup;
  138 + it_zeros_sup++;
  139 + }
  140 + //Dernière intégrale du dernier zéro vers la borne inf de l'intervalle
  141 + IntegralRR current_integral(_sup_endpoint.lb(), current->mid(), _f);
  142 + it_sols = res_temp.begin();
  143 + while (it_sols != res_temp.end()){//On ajoute l'intégrale courante aux autres intégrales
  144 + *it_sols += current_integral;
  145 + it_sols++;
  146 + }
  147 + res_temp.push_back(current_integral);
  148 + } else {
  149 + IntegralRR whole_integral(_sup_endpoint.lb(), _sup_endpoint.ub(), _f);
  150 + res_temp.push_back(whole_integral);
  151 + res_temp.push_back(IntegralRR(_sup_endpoint.lb(), _sup_endpoint.lb(), _f, 0.));
  152 + }
  153 + it_sols = res_temp.begin();
  154 + min = *it_sols;
  155 + max = *it_sols;
  156 + it_sols++;
  157 + while (it_sols != res_temp.end()){//On recherche le min et le max
  158 + if (max < *it_sols){
  159 + max = *it_sols;
  160 + }
  161 + if (*it_sols < min){
  162 + min = *it_sols;
  163 + }
  164 + it_sols ++;
  165 + }
  166 +
  167 + _solution.first += min;
  168 + _solution.second += max;
  169 +
  170 +}
  171 +
  172 +std::ostream& operator<<(std::ostream& os, const IntegralII& integral){
  173 + os << "Integrale from " << integral.get_inf_endpoint() << " to " << integral.get_sup_endpoint();
  174 + os << " of the function " << *integral.get_f() << " : " << endl << "minimum : " << integral.get_solution().first << endl << "maximum : " << integral.get_solution().second;
  175 + return os;
  176 +}
src/zero.h renamed to src/integralii.h
1 /* 1 /*
2 * <one line to give the library's name and an idea of what it does.> 2 * <one line to give the library's name and an idea of what it does.>
3 - * Copyright (C) 2019 <copyright holder> <email> 3 + * Copyright (C) 2019 mullier <email>
4 * 4 *
5 * This program is free software: you can redistribute it and/or modify 5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
@@ -16,40 +16,45 @@ @@ -16,40 +16,45 @@
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19 -#ifndef ZERO_H  
20 -#define ZERO_H 19 +#ifndef INTEGRALII_H
  20 +#define INTEGRALII_H
21 21
22 #include <ibex.h> 22 #include <ibex.h>
  23 +#include "integralrr.h"
23 24
24 /** 25 /**
25 * @todo write docs 26 * @todo write docs
26 */ 27 */
27 -class zero 28 +class IntegralII
28 { 29 {
29 private: 30 private:
30 - ibex::Interval _x;  
31 - int _slope; 31 + ibex::Interval _inf_endpoint;
  32 + ibex::Interval _sup_endpoint;
  33 +
  34 + ibex::Function * _f;
  35 +
  36 + std::pair<IntegralRR, IntegralRR> _solution;
  37 +
  38 + std::list<ibex::Interval*>& compute_list_of_zeros(ibex::Interval searchdomain);
32 39
33 public: 40 public:
34 - zero(const zero &z) : _x(z.get_x()), _slope(z.get_slope()){};  
35 - zero(ibex::Interval x, int slope) : _x(x), _slope(slope) {}; 41 + IntegralII(const ibex::Interval & inf, const ibex::Interval & sup, ibex::Function * f) : _inf_endpoint(inf), _sup_endpoint(sup), _f(f){};
36 42
37 - inline ibex::Interval get_x() const {return _x;};  
38 - inline int get_slope() const {return _slope;}; 43 + ibex::Interval get_inf_endpoint() const {return _inf_endpoint;};
  44 + ibex::Interval get_sup_endpoint() const {return _sup_endpoint;};
39 45
40 - inline bool is_neg() const {return _slope < 0;};  
41 - inline bool is_pos() const {return _slope > 0;};  
42 - inline bool is_non_zero() const {return _slope == 0;};  
43 -};  
44 -  
45 -inline bool operator< (const zero& lhs, const zero& rhs){ return lhs.get_x().mid() < rhs.get_x().mid(); }  
46 -inline bool operator> (const zero& lhs, const zero& rhs){ return rhs < lhs; }  
47 -inline bool operator<=(const zero& lhs, const zero& rhs){ return !(lhs > rhs); }  
48 -inline bool operator>=(const zero& lhs, const zero& rhs){ return !(lhs < rhs); } 46 + ibex::Function * get_f() const {return _f;};
  47 +
  48 + std::pair<IntegralRR, IntegralRR> get_solution() const {return _solution;};
49 49
50 -inline bool operator==(const zero& lhs, const zero& rhs){ return lhs.get_x() == rhs.get_x(); }  
51 -inline bool operator!=(const zero& lhs, const zero& rhs){ return !(lhs == rhs); } 50 + std::list<ibex::Interval*>& compute_list_of_zeros_inf();
  51 +
  52 + std::list<ibex::Interval*>& compute_list_of_zeros_sup();
  53 +
  54 + void compute_integral();
  55 +
  56 +};
52 57
53 -ostream& operator<<(ostream& os, const zero& z); 58 +std::ostream& operator<<(std::ostream& os, const IntegralII& integral);
54 59
55 -#endif // ZERO_H 60 +#endif // INTEGRALEII_H
src/integralrr.cpp 0 → 100644
@@ -0,0 +1,69 @@ @@ -0,0 +1,69 @@
  1 +/*
  2 + * <one line to give the library's name and an idea of what it does.>
  3 + * Copyright (C) 2019 mullier <email>
  4 + *
  5 + * This program is free software: you can redistribute it and/or modify
  6 + * it under the terms of the GNU General Public License as published by
  7 + * the Free Software Foundation, either version 3 of the License, or
  8 + * (at your option) any later version.
  9 + *
  10 + * This program is distributed in the hope that it will be useful,
  11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13 + * GNU General Public License for more details.
  14 + *
  15 + * You should have received a copy of the GNU General Public License
  16 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17 + */
  18 +
  19 +#include "integralrr.h"
  20 +
  21 +IntegralRR::IntegralRR(double inf_endpoint, double sup_endpoint, ibex::Function* f) : _inf_endpoint(inf_endpoint), _sup_endpoint(sup_endpoint), _f(f), _solution(0.)
  22 +{
  23 + compute_integral();
  24 +}
  25 +
  26 +void IntegralRR::compute_integral()
  27 +{
  28 + ibex::Interval res(0.0);
  29 + double current = _inf_endpoint;
  30 + ibex::IntervalVector current_vec(1);
  31 + while (current < _sup_endpoint){
  32 + current_vec[0] = ibex::Interval(current, current + __EPS__);
  33 + res += _f->eval_vector(current_vec)[0] *__EPS__;
  34 + current += __EPS__;
  35 + }
  36 + current_vec[0] = ibex::Interval(current - __EPS__, _sup_endpoint);
  37 + res += _f->eval_vector(current_vec)[0] * (_sup_endpoint - current + __EPS__);
  38 + _solution = res;
  39 +}
  40 +
  41 +
  42 +IntegralRR& IntegralRR::operator+=(const IntegralRR& other)
  43 +{
  44 + *this = *this + other;
  45 + return *this;
  46 +}
  47 +
  48 +
  49 +IntegralRR operator+(const IntegralRR& lhs, const IntegralRR& rhs)
  50 +{
  51 + if (lhs.get_sup_endpoint() == rhs.get_inf_endpoint()){
  52 + return IntegralRR(lhs.get_inf_endpoint(), rhs.get_sup_endpoint(), lhs.get_f(), lhs.get_solution() + rhs.get_solution());
  53 + } else {
  54 + return IntegralRR(rhs.get_inf_endpoint(), lhs.get_sup_endpoint(), lhs.get_f(), lhs.get_solution() + rhs.get_solution());
  55 + }
  56 +
  57 +}
  58 +
  59 +std::ostream & operator<<(std::ostream& os, const IntegralRR& integral)
  60 +{
  61 + os << "Integrale from " << integral.get_inf_endpoint() << " to " << integral.get_sup_endpoint();
  62 + os << " of the function " << *integral.get_f() << " : " << integral.get_solution();
  63 + return os;
  64 +}
  65 +
  66 +bool operator<(const IntegralRR& lhs, const IntegralRR& rhs)
  67 +{
  68 + return lhs.get_solution().ub() < rhs.get_solution().lb();
  69 +}
src/integralrr.h 0 → 100644
@@ -0,0 +1,67 @@ @@ -0,0 +1,67 @@
  1 +/*
  2 + * <one line to give the library's name and an idea of what it does.>
  3 + * Copyright (C) 2019 mullier <email>
  4 + *
  5 + * This program is free software: you can redistribute it and/or modify
  6 + * it under the terms of the GNU General Public License as published by
  7 + * the Free Software Foundation, either version 3 of the License, or
  8 + * (at your option) any later version.
  9 + *
  10 + * This program is distributed in the hope that it will be useful,
  11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13 + * GNU General Public License for more details.
  14 + *
  15 + * You should have received a copy of the GNU General Public License
  16 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17 + */
  18 +
  19 +#ifndef INTEGRALRR_H
  20 +#define INTEGRALRR_H
  21 +
  22 +#include <ibex.h>
  23 +
  24 +#define __EPS__ (1e-4)
  25 +
  26 +/**
  27 + * @todo write docs
  28 + */
  29 +class IntegralRR
  30 +{
  31 +private:
  32 + double _inf_endpoint;
  33 + double _sup_endpoint;
  34 +
  35 + ibex::Function * _f;
  36 +
  37 + ibex::Interval _solution;
  38 +
  39 +public:
  40 + //CONSTRUCTORS
  41 + IntegralRR(double, double, ibex::Function *);
  42 + IntegralRR(double inf, double sup, ibex::Function * f, const ibex::Interval & sol) :
  43 + _inf_endpoint(inf), _sup_endpoint(sup), _f(f), _solution(sol){};
  44 + IntegralRR(){_f = nullptr;};
  45 + IntegralRR(const IntegralRR & other) : IntegralRR(other.get_inf_endpoint(), other.get_sup_endpoint(), other.get_f(), other.get_solution()){};
  46 +
  47 + //GETTERS
  48 + inline double get_inf_endpoint() const {return _inf_endpoint;};
  49 + inline double get_sup_endpoint() const {return _sup_endpoint;};
  50 + inline ibex::Function * get_f() const {return _f;};
  51 + inline ibex::Interval get_solution() const {return _solution;};
  52 +
  53 + //SETTERS
  54 + void set_solution(const ibex::Interval & res){_solution = res;};
  55 +
  56 + void compute_integral();
  57 +
  58 + IntegralRR& operator+=(const IntegralRR& other);
  59 +};
  60 +
  61 +IntegralRR operator+(const IntegralRR& lhs, const IntegralRR& rhs);
  62 +
  63 +bool operator<(const IntegralRR &, const IntegralRR &);
  64 +
  65 +std::ostream& operator<<(std::ostream& os, const IntegralRR& integral);
  66 +
  67 +#endif // INTEGRALRR_H
1 -#include <ibex.h>  
2 -#include "integrale.h" 1 +#include <iostream>
3 2
4 -using namespace std; 3 +#include "integralii.h"
5 4
6 -  
7 -  
8 -void example(){ 5 +int main(){
9 cout << setprecision(15); 6 cout << setprecision(15);
10 ibex::Variable x(1); 7 ibex::Variable x(1);
11 - ibex::Function f(x, -15. + x+5.*ibex::sin(x));  
12 - ibex::Interval inf(0., 5.5);  
13 - ibex::Interval sup(10, 15.);  
14 -  
15 - integrale example(inf, sup, &f);  
16 -  
17 - cout << example << endl;  
18 - example.construct_zeros();  
19 - for (auto elem : *example.get_zeros_sup()){  
20 - cout << elem << endl;  
21 - cout << *elem << endl << endl;  
22 - }  
23 - example.compute_integral();  
24 - cout << "minimum: " << example.get_result()->first << endl;  
25 - cout << "maximum: " << example.get_result()->second << endl; 8 + ibex::Function f(x, ibex::sin(x));
  9 + ibex::Interval inf_inter(0, 5);
  10 + ibex::Interval sup_inter(9, 10);
26 11
27 -}  
28 -  
29 -  
30 -int main(/*int argc, char * argv[]*/){  
31 - example(); 12 + IntegralII integ_inter(inf_inter, sup_inter, &f);
  13 + integ_inter.compute_integral();
  14 + cout << "Result: " << endl;
  15 + cout << integ_inter << endl;
32 return EXIT_SUCCESS; 16 return EXIT_SUCCESS;
33 } 17 }
src/zero.cpp deleted
@@ -1,33 +0,0 @@ @@ -1,33 +0,0 @@
1 -/*  
2 - * <one line to give the library's name and an idea of what it does.>  
3 - * Copyright (C) 2019 <copyright holder> <email>  
4 - *  
5 - * This program is free software: you can redistribute it and/or modify  
6 - * it under the terms of the GNU General Public License as published by  
7 - * the Free Software Foundation, either version 3 of the License, or  
8 - * (at your option) any later version.  
9 - *  
10 - * This program is distributed in the hope that it will be useful,  
11 - * but WITHOUT ANY WARRANTY; without even the implied warranty of  
12 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  
13 - * GNU General Public License for more details.  
14 - *  
15 - * You should have received a copy of the GNU General Public License  
16 - * along with this program. If not, see <http://www.gnu.org/licenses/>.  
17 - */  
18 -  
19 -#include "zero.h"  
20 -  
21 -ostream& operator<<(ostream& os, const zero& z)  
22 -{  
23 - if (z.is_non_zero())  
24 - os << "boundary: " << z.get_x();  
25 - else {  
26 - os << "Zero of the function: " << z.get_x() << ", derivative is ";  
27 - if (z.is_neg())  
28 - os << " negative";  
29 - else  
30 - os << " positive";  
31 - }  
32 - return os;  
33 -}