-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sivia] added SIVIA algorithms (Ctc,Sep) + binding
- Loading branch information
1 parent
c77aea3
commit f37e819
Showing
5 changed files
with
205 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* \file | ||
* Sep Python binding | ||
* Originated from the former pyIbex library (Benoît Desrochers) | ||
* ---------------------------------------------------------------------------- | ||
* \date 2020 | ||
* \author Benoît Desrochers, Simon Rohou | ||
* \copyright Copyright 2021 Codac Team | ||
* \license This program is distributed under the terms of | ||
* the GNU Lesser General Public License (LGPL). | ||
*/ | ||
|
||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
#include <pybind11/operators.h> | ||
#include <pybind11/functional.h> | ||
#include "codac_type_caster.h" | ||
|
||
#include "../contractors/static/codac_py_Ctc.h" | ||
#include "../separators/codac_py_Sep.h" | ||
|
||
#include <codac_sivia.h> | ||
|
||
using namespace std; | ||
using namespace codac; | ||
namespace py = pybind11; | ||
using namespace pybind11::literals; | ||
|
||
|
||
void export_unsupported_geometry(py::module& m, py::class_<Ctc,pyCtc>& ctc, py::class_<ibex::Sep,pySep>& sep) | ||
{ | ||
m.def("SIVIA", [](const IntervalVector& x, Ctc& ctc, float precision, const SetColorMap& color_map) | ||
{ | ||
SIVIA(x, &ctc, precision, color_map); | ||
}, | ||
"x"_a.noconvert(), "ctc"_a.noconvert(), "precision"_a.noconvert(), "color_map"_a.noconvert() = DEFAULT_SET_COLOR_MAP); | ||
|
||
m.def("SIVIA", [](const IntervalVector& x, ibex::Sep& sep, float precision, const SetColorMap& color_map) | ||
{ | ||
SIVIA(x, &sep, precision, color_map); | ||
}, | ||
"x"_a.noconvert(), "sep"_a.noconvert(), "precision"_a.noconvert(), "color_map"_a.noconvert() = DEFAULT_SET_COLOR_MAP); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/** | ||
* SIVIA | ||
* ---------------------------------------------------------------------------- | ||
* \date 2022 | ||
* \author Simon Rohou | ||
* \copyright Copyright 2022 Codac Team | ||
* \license This program is distributed under the terms of | ||
* the GNU Lesser General Public License (LGPL). | ||
*/ | ||
|
||
#include <list> | ||
#include <iostream> | ||
|
||
#include "codac_sivia.h" | ||
#include "codac_VIBesFig.h" | ||
#include <ibex_LargestFirst.h> | ||
#include "vibes.h" | ||
|
||
using namespace std; | ||
|
||
namespace codac | ||
{ | ||
vector<IntervalVector> box_diff(const IntervalVector& x0, const IntervalVector& x) | ||
{ | ||
vector<IntervalVector> v; | ||
IntervalVector* boxes; | ||
int n = x0.diff(x, boxes); | ||
v.assign(boxes, boxes + n); | ||
return v; | ||
} | ||
|
||
void SIVIA(const IntervalVector& x0, Ctc* ctc, float precision, const SetColorMap& color_map) | ||
{ | ||
assert(x0.size() >= 2); | ||
|
||
ibex::LargestFirst bisector(0.); | ||
deque<IntervalVector> stack = { x0 }; | ||
int k = 0; | ||
|
||
while(!stack.empty()) | ||
{ | ||
k++; | ||
IntervalVector x = stack.front(); | ||
stack.pop_front(); | ||
IntervalVector x_before_ctc(x); | ||
|
||
ctc->contract(x); | ||
|
||
vector<IntervalVector> x_out_l = box_diff(x_before_ctc.subvector(0,1), x.subvector(0,1)); | ||
for(const auto& o : x_out_l) | ||
vibes::drawBox(o, color_map.at(SetValue::OUT)); | ||
|
||
if(x.is_empty()) | ||
continue; | ||
|
||
else | ||
{ | ||
if(x.max_diam() < precision) | ||
vibes::drawBox(x.subvector(0,1), color_map.at(SetValue::UNKNOWN)); | ||
|
||
else | ||
{ | ||
pair<IntervalVector,IntervalVector> p = bisector.bisect(x.subvector(0,1)); | ||
stack.push_back(cart_prod(p.first,x[2])); | ||
stack.push_back(cart_prod(p.second,x[2])); | ||
} | ||
} | ||
} | ||
|
||
cout << "Number of contractions: " << k << endl; | ||
//cout << "Number of boxes: " << 0 << endl; | ||
} | ||
|
||
void SIVIA(const IntervalVector& x0, ibex::Sep* sep, float precision, const SetColorMap& color_map) | ||
{ | ||
assert(x0.size() >= 2); | ||
|
||
ibex::LargestFirst bisector(0.); | ||
deque<IntervalVector> stack = { x0 }; | ||
int k = 0; | ||
|
||
while(!stack.empty()) | ||
{ | ||
k++; | ||
IntervalVector x_before_ctc = stack.front(); | ||
stack.pop_front(); | ||
IntervalVector x_in(x_before_ctc), x_out(x_before_ctc); | ||
|
||
sep->separate(x_in, x_out); | ||
|
||
IntervalVector x = x_in & x_out; | ||
|
||
vector<IntervalVector> x_in_l = box_diff(x_before_ctc, x_in); | ||
for(const auto& i : x_in_l) | ||
vibes::drawBox(i, color_map.at(SetValue::IN)); | ||
|
||
vector<IntervalVector> x_out_l = box_diff(x_before_ctc, x_out); | ||
for(const auto& o : x_out_l) | ||
vibes::drawBox(o, color_map.at(SetValue::OUT)); | ||
|
||
if(x.is_empty()) | ||
continue; | ||
|
||
else | ||
{ | ||
|
||
if(x.max_diam() < precision) | ||
vibes::drawBox(x.subvector(0,1), color_map.at(SetValue::UNKNOWN)); | ||
|
||
else | ||
{ | ||
pair<IntervalVector,IntervalVector> p = bisector.bisect(x); | ||
stack.push_back(p.first); | ||
stack.push_back(p.second); | ||
} | ||
} | ||
} | ||
|
||
cout << "Number of contractions: " << k << endl; | ||
//cout << "Number of boxes: " << 0 << endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* \file | ||
* SIVIA | ||
* ---------------------------------------------------------------------------- | ||
* \date 2022 | ||
* \author Simon Rohou | ||
* \copyright Copyright 2022 Codac Team | ||
* \license This program is distributed under the terms of | ||
* the GNU Lesser General Public License (LGPL). | ||
*/ | ||
|
||
#ifndef __CODAC_SIVIA_H__ | ||
#define __CODAC_SIVIA_H__ | ||
|
||
#include <ibex_Sep.h> | ||
#include "codac_Ctc.h" | ||
#include "codac_VIBesFigPaving.h" | ||
#include "codac_IntervalVector.h" | ||
|
||
namespace codac | ||
{ | ||
void SIVIA(const IntervalVector& x, Ctc* ctc, float precision, | ||
const SetColorMap& color_map = DEFAULT_SET_COLOR_MAP); | ||
|
||
void SIVIA(const IntervalVector& x, ibex::Sep* sep, float precision, | ||
const SetColorMap& color_map = DEFAULT_SET_COLOR_MAP); | ||
} | ||
|
||
#endif |