Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Olivier Mullier
interval_integrals
Commits
0c06be4a
Commit
0c06be4a
authored
Apr 01, 2019
by
Olivier Mullier
Browse files
premier version qui marche
parent
d2eceb6d
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/integrale.cpp
View file @
0c06be4a
#include "integrale.h"
integrale
::
integrale
(
ibex
::
Interval
inf
,
ibex
::
Interval
sup
,
ibex
::
Function
*
f
,
ibex
::
Variable
*
var
)
:
_inf_bound
(
inf
),
_sup_bound
(
sup
),
_f
(
f
)
integrale
::
integrale
(
const
ibex
::
Interval
&
inf
,
const
ibex
::
Interval
&
sup
,
ibex
::
Function
*
f
,
ibex
::
Variable
*
var
)
:
_inf_bound
(
inf
),
_sup_bound
(
sup
),
_f
(
f
)
{
_zeros_inf
=
nullptr
;
_zeros_sup
=
nullptr
;
_result
=
nullptr
;
}
std
::
list
<
zero
>
*
integrale
::
construct_zeros_intern
(
const
ibex
::
Interval
&
inf_bound
)
std
::
list
<
zero
*
>
*
integrale
::
construct_zeros_intern
(
const
ibex
::
Interval
&
inf_bound
)
{
#ifdef __DEBUG__
__SHOW_FCT_NAME__
#endif
//ATTENTION pas de preuve d'unicité
std
::
list
<
zero
>
*
res
=
new
std
::
list
<
zero
>
();
std
::
list
<
zero
*
>
*
res
=
new
std
::
list
<
zero
*
>
();
ibex
::
CtcNewton
newton
(
*
_f
);
...
...
@@ -47,9 +48,11 @@ integrale::integrale(ibex::Interval inf, ibex::Interval sup, ibex::Function* f,
}
}
if
(
(
_f
->
eval_vector
(
temp
)[
0
].
ub
()
<
0.
)
){
res
->
push_back
(
zero
(
sols
[
i
][
0
],
-
1
));
zero
*
current
=
new
zero
(
sols
[
i
][
0
],
-
1
);
res
->
push_back
(
current
);
}
else
{
res
->
push_back
(
zero
(
sols
[
i
][
0
],
1
));
zero
*
current
=
new
zero
(
sols
[
i
][
0
],
1
);
res
->
push_back
(
current
);
}
}
return
res
;
...
...
@@ -68,16 +71,17 @@ unsigned int integrale::construct_zeros_sup()
return
_zeros_sup
->
size
();
}
ibex
::
Interval
integrale
::
compute_integral
(
const
double
&
inf
_bound
,
const
double
&
sup
_bound
)
ibex
::
Interval
integrale
::
compute_integral
(
const
double
inf
,
const
double
sup
)
{
ibex
::
Interval
res
(
0.0
);
double
current
=
inf
_bound
;
double
current
=
inf
;
ibex
::
IntervalVector
current_vec
(
1
);
while
(
current
<
sup
_bound
){
while
(
current
<
sup
){
current_vec
[
0
]
=
ibex
::
Interval
(
current
,
current
+
__EPS__
);
res
+=
_f
->
eval_vector
(
current_vec
)[
0
]
*
__EPS__
;
current
+=
__EPS__
;
}
return
res
;
}
...
...
@@ -86,10 +90,11 @@ unsigned int integrale::construct_zeros()
return
construct_zeros_inf
()
+
construct_zeros_sup
();
}
integrale_sol
integrale
::
compute_integral
(
const
zero
&
inf
,
const
zero
&
sup
)
integrale_sol
integrale
::
compute_integral
(
zero
*
inf
,
zero
*
sup
)
{
ibex
::
Interval
res_int
=
compute_integral
(
inf
.
get_x
().
lb
(),
sup
.
get_x
().
ub
());
return
integrale_sol
(
inf
,
sup
,
res_int
);
ibex
::
Interval
res_inter
=
compute_integral
(
inf
->
get_x
().
lb
(),
sup
->
get_x
().
ub
());
integrale_sol
res
(
inf
,
sup
,
res_inter
);
return
res
;
}
...
...
@@ -100,27 +105,31 @@ std::pair<integrale_sol, integrale_sol> integrale::compute_integral_inf(const ib
construct_zeros_inf
();
}
std
::
list
<
zero
>::
iterator
it
=
_zeros_inf
->
begin
();
zero
bound_inf
(
ibex
::
Interval
(
range
.
lb
()),
0
);
std
::
list
<
zero
*
>::
iterator
it
=
_zeros_inf
->
begin
();
zero
*
bound_inf
=
new
zero
(
ibex
::
Interval
(
range
.
lb
()),
0
);
integrale_sol
integ0
=
compute_integral
(
bound_inf
,
*
(
it
));
res_tmp
.
push_back
(
integ0
);
while
(
it
!=
_zeros_inf
->
end
()){
if
(
*
it
!=
_zeros_inf
->
back
()){
std
::
list
<
zero
>::
iterator
it_first
=
it
;
std
::
list
<
zero
*
>::
iterator
it_first
=
it
;
it
++
;
std
::
list
<
zero
>::
iterator
it_second
=
it
;
std
::
list
<
zero
*
>::
iterator
it_second
=
it
;
integrale_sol
integ
=
compute_integral
(
*
it_first
,
*
it_second
);
for
(
auto
elem
:
res_tmp
){
elem
+=
integ
;
std
::
list
<
integrale_sol
>::
iterator
it_tmp
=
res_tmp
.
begin
();
while
(
it_tmp
!=
res_tmp
.
end
()){
*
it_tmp
=
*
it_tmp
+
integ
;
it_tmp
++
;
}
res_tmp
.
push_back
(
integ
);
}
else
{
zero
bound
(
ibex
::
Interval
(
range
.
ub
()),
0
);
zero
*
bound
=
new
zero
(
ibex
::
Interval
(
range
.
ub
()),
0
);
integrale_sol
integ
=
compute_integral
(
*
it
,
bound
);
for
(
auto
elem
:
res_tmp
){
elem
+=
integ
;
std
::
list
<
integrale_sol
>::
iterator
it_tmp
=
res_tmp
.
begin
();
while
(
it_tmp
!=
res_tmp
.
end
()){
(
*
it_tmp
)
=
(
*
it_tmp
)
+
integ
;
it_tmp
++
;
}
it
++
;
res_tmp
.
push_back
(
integ
);
...
...
@@ -151,39 +160,39 @@ std::pair<integrale_sol, integrale_sol> integrale::compute_integral_sup(const ib
construct_zeros_sup
();
}
std
::
list
<
zero
>::
iterator
it
=
_zeros_sup
->
begin
();
zero
bound_sup
(
ibex
::
Interval
(
range
.
ub
()),
0
);
std
::
cout
<<
"inf bound: "
<<
*
it
<<
endl
;
std
::
cout
<<
"sup bound: "
<<
bound_sup
<<
endl
;
std
::
list
<
zero
*
>::
iterator
it
=
_zeros_sup
->
begin
();
zero
*
bound_sup
=
new
zero
(
ibex
::
Interval
(
range
.
ub
()),
0
);
//
std::cout << "inf bound: " << *it << endl;
//
std::cout << "sup bound: " << bound_sup << endl;
integrale_sol
integ0
=
compute_integral
((
*
it
),
bound_sup
);
res_temp
.
push_back
(
integ0
);
while
(
it
!=
_zeros_sup
->
end
()){
if
(
*
it
!=
_zeros_sup
->
back
()){
std
::
list
<
zero
>::
iterator
it_second
=
it
;
std
::
list
<
zero
*
>::
iterator
it_second
=
it
;
it
++
;
std
::
list
<
zero
>::
iterator
it_first
=
it
;
std
::
list
<
zero
*
>::
iterator
it_first
=
it
;
// std::cout << "inf bound: " << *it_first << endl;
// std::cout << "sup bound: " << *it_second << endl;
integrale_sol
integ
=
compute_integral
(
*
it_first
,
*
it_second
);
for
(
auto
elem
:
res_temp
){
// cout << "elem : " << elem << endl;
// cout << "integ : " << integ << endl;
elem
+=
integ
;
// cout << "new elem : " << elem << endl;
std
::
list
<
integrale_sol
>::
iterator
it_tmp
=
res_temp
.
begin
();
while
(
it_tmp
!=
res_temp
.
end
()){
*
it_tmp
=
*
it_tmp
+
integ
;
it_tmp
++
;
}
res_temp
.
push_back
(
integ
);
}
else
{
zero
bound
(
ibex
::
Interval
(
range
.
lb
()),
0
);
// cout << "on passe ici" << endl;
zero
*
bound
=
new
zero
(
ibex
::
Interval
(
range
.
lb
()),
0
);
// std::cout << "inf bound: " << bound << endl;
// std::cout << "sup bound: " << *it << endl;
integrale_sol
integ
=
compute_integral
(
bound
,
*
it
);
for
(
auto
elem
:
res_temp
){
//
cout << "elem : " << elem << endl
;
//
cout << "integ : " << integ << endl;
elem
+=
integ
;
//
cout << "new elem : " << elem << endl
;
//
cout << integ << endl;
std
::
list
<
integrale_sol
>::
iterator
it_tmp
=
res_temp
.
begin
()
;
while
(
it_tmp
!=
res_temp
.
end
()){
*
it_tmp
=
*
it_tmp
+
integ
;
it_tmp
++
;
}
it
++
;
res_temp
.
push_back
(
integ
);
...
...
@@ -196,7 +205,7 @@ std::pair<integrale_sol, integrale_sol> integrale::compute_integral_sup(const ib
integrale_sol
min
=
*
(
res_temp
.
begin
());
integrale_sol
max
=
*
(
res_temp
.
begin
());
for
(
auto
elem
:
res_temp
){
cout
<<
"
\t
candidate : "
<<
elem
<<
endl
;
//
cout << "\tcandidate : " << elem << endl;
if
(
elem
.
get_res_integrale
().
lb
()
<
min
.
get_res_integrale
().
lb
()){
min
=
elem
;
}
...
...
@@ -207,6 +216,38 @@ std::pair<integrale_sol, integrale_sol> integrale::compute_integral_sup(const ib
return
pair
<
integrale_sol
,
integrale_sol
>
(
min
,
max
);
}
std
::
pair
<
integrale_sol
,
integrale_sol
>
integrale
::
compute_integral
()
{
std
::
pair
<
integrale_sol
,
integrale_sol
>
res
=
compute_integral_inf
(
_inf_bound
);
// std::cout << "in inf : " << endl;
// std::cout << "\tmin : " << res.first << endl;
// std::cout << "\tmax : " << res.second << endl;
zero
*
inf
=
res
.
first
.
get_sup_bound
();
std
::
pair
<
integrale_sol
,
integrale_sol
>
res_sup
=
compute_integral_sup
(
_sup_bound
);
// std::cout << "in sup : " << endl;
// std::cout << "\tmin : " << res_sup.first << endl;
// std::cout << "\tmax : " << res_sup.second << endl;
zero
*
sup
=
res_sup
.
first
.
get_inf_bound
();
ibex
::
Interval
mid
=
compute_integral
(
_inf_bound
.
ub
(),
_sup_bound
.
lb
());
cout
<<
*
inf
<<
endl
;
cout
<<
*
sup
<<
endl
;
integrale_sol
integ_mid
(
inf
,
sup
,
mid
);
// cout << "integrale mid : " << integ_mid << endl;
res
.
first
+=
integ_mid
;
res
.
second
+=
integ_mid
;
// std::cout << "mid : " << mid << endl;
res
.
first
+=
res_sup
.
first
;
res
.
second
+=
res_sup
.
second
;
if
(
_result
==
nullptr
){
_result
=
new
std
::
pair
<
integrale_sol
,
integrale_sol
>
(
res
);
}
else
{
*
_result
=
res
;
}
return
res
;
}
...
...
src/integrale.h
View file @
0c06be4a
...
...
@@ -24,24 +24,35 @@ private:
ibex
::
Function
*
_f
;
ibex
::
Variable
*
_x_var
;
std
::
list
<
zero
>
*
_zeros_inf
;
std
::
list
<
zero
>
*
_zeros_sup
;
std
::
list
<
zero
*
>
*
_zeros_inf
;
std
::
list
<
zero
*
>
*
_zeros_sup
;
std
::
pair
<
integrale_sol
,
integrale_sol
>
*
_result
;
std
::
list
<
zero
*>
*
construct_zeros_intern
(
const
ibex
::
Interval
&
inf_bound
);
std
::
list
<
zero
>
*
construct_zeros_intern
(
const
ibex
::
Interval
&
inf_bound
);
integrale_sol
compute_integral
(
zero
*
inf
,
zero
*
sup
);
std
::
list
<
ibex
::
Interval
>
compute_integral
(
const
double
&
inf_bound
,
const
ibex
::
Interval
&
sup_bound
);
ibex
::
Interval
compute_integral
(
const
double
inf_bound
,
const
double
sup_bound
);
std
::
pair
<
integrale_sol
,
integrale_sol
>
compute_integral_inf
(
const
ibex
::
Interval
&
range
);
std
::
pair
<
integrale_sol
,
integrale_sol
>
compute_integral_sup
(
const
ibex
::
Interval
&
range
);
public:
//CONSTRUCTORS
integrale
(
ibex
::
Interval
inf
,
ibex
::
Interval
sup
,
ibex
::
Function
*
f
,
ibex
::
Variable
*
var
);
integrale
(
const
ibex
::
Interval
&
inf
,
const
ibex
::
Interval
&
sup
,
ibex
::
Function
*
f
,
ibex
::
Variable
*
var
);
//GETTERS
inline
ibex
::
Interval
get_inf_bound
()
const
{
return
_inf_bound
;};
inline
ibex
::
Interval
get_sup_bound
()
const
{
return
_sup_bound
;};
inline
ibex
::
Function
*
get_f
()
const
{
return
_f
;};
inline
ibex
::
Variable
*
get_x_var
()
const
{
return
_x_var
;};
inline
std
::
list
<
zero
>
*
get_zeros_inf
(){
return
_zeros_inf
;};
inline
std
::
list
<
zero
>
*
get_zeros_sup
(){
return
_zeros_sup
;};
inline
std
::
list
<
zero
*>
*
get_zeros_inf
(){
return
_zeros_inf
;};
inline
std
::
list
<
zero
*>
*
get_zeros_sup
(){
return
_zeros_sup
;};
inline
std
::
pair
<
integrale_sol
,
integrale_sol
>
*
get_result
(){
return
_result
;};
unsigned
int
construct_zeros_inf
();
...
...
@@ -49,15 +60,7 @@ public:
unsigned
int
construct_zeros
();
integrale_sol
compute_integral
(
const
zero
&
inf
,
const
zero
&
sup
);
std
::
list
<
ibex
::
Interval
>
compute_integral
(
const
double
&
inf_bound
,
const
ibex
::
Interval
&
sup_bound
);
ibex
::
Interval
compute_integral
(
const
double
&
inf_bound
,
const
double
&
sup_bound
);
std
::
pair
<
integrale_sol
,
integrale_sol
>
compute_integral_inf
(
const
ibex
::
Interval
&
range
);
std
::
pair
<
integrale_sol
,
integrale_sol
>
compute_integral_sup
(
const
ibex
::
Interval
&
range
);
std
::
pair
<
integrale_sol
,
integrale_sol
>
compute_integral
();
};
...
...
src/integrale_sol.cpp
View file @
0c06be4a
...
...
@@ -18,10 +18,10 @@
#include "integrale_sol.h"
integrale_sol
::
integrale_sol
(
const
zero
&
inf
,
const
zero
&
sup
,
const
ibex
::
Interval
&
res
)
:
_res_integrale
(
res
)
integrale_sol
::
integrale_sol
(
zero
*
inf
,
zero
*
sup
,
const
ibex
::
Interval
&
res
)
:
_res_integrale
(
res
)
{
_inf
=
new
zero
(
inf
);
_sup
=
new
zero
(
sup
);
_inf
=
(
inf
);
_sup
=
(
sup
);
_min_candidate
=
false
;
_max_candidate
=
false
;
if
(
res
.
ub
()
<
0.
){
...
...
@@ -39,12 +39,12 @@ integrale_sol & integrale_sol::operator+=(const integrale_sol &rhs){
integrale_sol
operator
+
(
const
integrale_sol
&
lhs
,
const
integrale_sol
&
rhs
)
{
if
(
lhs
.
get_sup_bound
()
->
get_x
().
lb
()
==
rhs
.
get_
sup
_bound
()
->
get_x
().
lb
()
){
cout
<<
"ici"
<<
endl
;
return
integrale_sol
(
*
lhs
.
get_inf_bound
(),
*
rhs
.
get_sup_bound
(),
(
lhs
.
get_res_integrale
()
+
rhs
.
get_res_integrale
()));
if
(
lhs
.
get_sup_bound
()
==
rhs
.
get_
inf
_bound
()){
//
cout << "ici" << endl;
return
integrale_sol
(
&
*
lhs
.
get_inf_bound
(),
&
*
rhs
.
get_sup_bound
(),
(
lhs
.
get_res_integrale
()
+
rhs
.
get_res_integrale
()));
}
else
{
cout
<<
"la"
<<
endl
;
return
integrale_sol
(
*
rhs
.
get_inf_bound
(),
*
lhs
.
get_sup_bound
(),
(
lhs
.
get_res_integrale
()
+
rhs
.
get_res_integrale
()));
//
cout << "la" << endl;
return
integrale_sol
(
&
*
rhs
.
get_inf_bound
(),
&
*
lhs
.
get_sup_bound
(),
(
lhs
.
get_res_integrale
()
+
rhs
.
get_res_integrale
()));
}
}
...
...
src/integrale_sol.h
View file @
0c06be4a
...
...
@@ -34,7 +34,7 @@ private:
bool
_max_candidate
;
public:
integrale_sol
(
const
zero
&
inf
,
const
zero
&
sup
,
const
ibex
::
Interval
&
res
);
integrale_sol
(
zero
*
inf
,
zero
*
sup
,
const
ibex
::
Interval
&
res
);
inline
zero
*
get_inf_bound
()
const
{
return
_inf
;};
inline
zero
*
get_sup_bound
()
const
{
return
_sup
;};
...
...
src/main.cpp
View file @
0c06be4a
...
...
@@ -15,21 +15,14 @@ void example(){
integrale
example
(
inf
,
sup
,
&
f
,
&
x
);
cout
<<
example
<<
endl
;
example
.
construct_zeros
();
// pair<integrale_sol, integrale_sol> res = example.compute_integral_inf(inf);
// cout << "minimum: " << res.first << endl;
// cout << "maximum: " << res.second << endl;
// for (auto elem : *(example.get_zeros_inf())){
// cout << elem << endl;
// }
cout
<<
"======================================================"
<<
endl
;
pair
<
integrale_sol
,
integrale_sol
>
res2
=
example
.
compute_integral_sup
(
sup
);
cout
<<
"minimum: "
<<
res2
.
first
<<
endl
;
cout
<<
"maximum: "
<<
res2
.
second
<<
endl
;
for
(
auto
elem
:
*
(
example
.
get_zeros_sup
())){
for
(
auto
elem
:
*
example
.
get_zeros_sup
()){
cout
<<
elem
<<
endl
;
}
example
.
compute_integral
();
cout
<<
"minimum: "
<<
example
.
get_result
()
->
first
<<
endl
;
cout
<<
"maximum: "
<<
example
.
get_result
()
->
second
<<
endl
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment