diff --git a/CHANGELOG b/CHANGELOG index c7567115e..efd30ce9b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,9 @@ Unreleased yet (in development) Features added -------------- +* ``CtcDelay`` now available in Python + + Changes ------- diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index aa4d1d858..a64dac51b 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -64,6 +64,7 @@ src/core/contractors/static/tubex_py_CtcConstell.cpp src/core/contractors/dyn/tubex_py_DynCtc.cpp + src/core/contractors/dyn/tubex_py_CtcDelay.cpp src/core/contractors/dyn/tubex_py_CtcDeriv.cpp src/core/contractors/dyn/tubex_py_CtcEval.cpp src/core/contractors/dyn/tubex_py_CtcPicard.cpp diff --git a/python/src/core/contractors/dyn/tubex_py_CtcDelay.cpp b/python/src/core/contractors/dyn/tubex_py_CtcDelay.cpp new file mode 100644 index 000000000..fe85605f1 --- /dev/null +++ b/python/src/core/contractors/dyn/tubex_py_CtcDelay.cpp @@ -0,0 +1,44 @@ +/** + * \file + * CtcDelay Python binding + * ---------------------------------------------------------------------------- + * \date 2020 + * \license This program is distributed under the terms of + * the GNU Lesser General Public License (LGPL). + */ + +#include +#include +#include +#include +#include "pyIbex_type_caster.h" + +#include "tubex_py_DynCtc.h" +#include "tubex_CtcDelay.h" +// Generated file from Doxygen XML (doxygen2docstring.py): +#include "tubex_py_CtcDelay_docs.h" + +using namespace std; +using namespace ibex; +using namespace tubex; +namespace py = pybind11; +using namespace pybind11::literals; + + +void export_CtcDelay(py::module& m, py::class_& dyn_ctc) +{ + py::class_ ctc_eval(m, "CtcDelay", dyn_ctc, CTCDELAY_MAIN); + ctc_eval + + .def(py::init<>(), + CTCDELAY_CTCDELAY) + + .def("contract", (void (CtcDelay::*)(Interval&,Tube&,Tube&))&CtcDelay::contract, + CTCDELAY_VOID_CONTRACT_INTERVAL_TUBE_TUBE, + "a"_a.noconvert(), "x"_a.noconvert(), "y"_a.noconvert()) + + .def("contract", (void (CtcDelay::*)(Interval&,TubeVector&,TubeVector&))&CtcDelay::contract, + CTCDELAY_VOID_CONTRACT_INTERVAL_TUBEVECTOR_TUBEVECTOR, + "a"_a.noconvert(), "x"_a.noconvert(), "y"_a.noconvert()) + ; +} \ No newline at end of file diff --git a/python/tubex_lib/__init__.py b/python/tubex_lib/__init__.py index 6c4c076db..236399a44 100644 --- a/python/tubex_lib/__init__.py +++ b/python/tubex_lib/__init__.py @@ -8,6 +8,7 @@ class ctc: + delay = CtcDelay() deriv = CtcDeriv() eval = CtcEval() dist = CtcDist() diff --git a/python/tubex_lib/tests/test_ctcdelay.py b/python/tubex_lib/tests/test_ctcdelay.py new file mode 100644 index 000000000..7f520cacd --- /dev/null +++ b/python/tubex_lib/tests/test_ctcdelay.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python + +import unittest +import math +from pyibex import Interval, IntervalVector +from tubex_lib import * + +class TestCtcDelay(unittest.TestCase): + + def assertApproxIntv(self, first, second): + if first.is_empty() is False: + # if isinstance(second, Interval): + self.assertAlmostEqual(first.lb(), second.lb()) + self.assertAlmostEqual(first.ub(), second.ub()) + else: + self.assertEqual(first, second) + + def test_ctcdelay_1(self): + tdomain = Interval(0.,10.) + x = Tube(tdomain, 0.01, TFunction("cos(t)")) + y = Tube(tdomain, 0.01) + + pi = Interval.PI + ctc_delay = CtcDelay() + ctc_delay.contract(pi, x, y) + + beginDrawing() + fig_x = VIBesFigTube("delay x", x) + fig_x.show() + fig_y = VIBesFigTube("delay y", y) + fig_y.show() + endDrawing() + + self.assertEqual(y(Interval(0.,math.pi)), Interval.ALL_REALS) + self.assertApproxIntv(y(Interval(math.pi+0.01,10.)), Interval(-1.,1.)) + self.assertTrue(y(5.).is_superset(x(5. - math.pi))) + + def test_ctcdelay_2(self): + tdomain = Interval(0.,10.) + dt = 0.01 + x = Tube(tdomain, dt, TFunction("cos(t)")) + y = Tube(tdomain, dt, TFunction("sin(t)")) + + delay = Interval(0.,2.*math.pi) + ctc_delay = CtcDelay() + ctc_delay.contract(delay, x, y) + + beginDrawing() + fig_x = VIBesFigTube("delay x", x) + fig_x.show() + fig_y = VIBesFigTube("delay y", y) + fig_y.show() + endDrawing() + + self.assertTrue(delay.contains(math.pi/2.)) + self.assertTrue(delay.diam() < 3.*dt) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/python/tubex_py.cpp b/python/tubex_py.cpp index de2c70ef6..608a12a10 100644 --- a/python/tubex_py.cpp +++ b/python/tubex_py.cpp @@ -32,6 +32,7 @@ void export_CtcFunction(py::module& m); void export_CtcConstell(py::module& m); py::class_ export_DynCtc(py::module& m); +void export_CtcDelay(py::module& m, py::class_& dyn_ctc); void export_CtcDeriv(py::module& m, py::class_& dyn_ctc); void export_CtcEval(py::module& m, py::class_& dyn_ctc); void export_CtcPicard(py::module& m, py::class_& dyn_ctc); @@ -68,6 +69,7 @@ PYBIND11_MODULE(tube, m) export_CtcConstell(m); py::class_ dyn_ctc = export_DynCtc(m); + export_CtcDelay(m, dyn_ctc); export_CtcDeriv(m, dyn_ctc); export_CtcEval(m, dyn_ctc); export_CtcPicard(m, dyn_ctc); diff --git a/src/core/contractors/tubex_predef_contractors.cpp b/src/core/contractors/tubex_predef_contractors.cpp index 8199f5e7a..9c81f3dbe 100644 --- a/src/core/contractors/tubex_predef_contractors.cpp +++ b/src/core/contractors/tubex_predef_contractors.cpp @@ -14,9 +14,9 @@ namespace tubex { namespace ctc { + CtcDelay delay; CtcDeriv deriv; - CtcEval eval; CtcDist dist; - CtcDelay delay; + CtcEval eval; } } \ No newline at end of file diff --git a/src/core/contractors/tubex_predef_contractors.h b/src/core/contractors/tubex_predef_contractors.h index 068287bec..7a776eb65 100644 --- a/src/core/contractors/tubex_predef_contractors.h +++ b/src/core/contractors/tubex_predef_contractors.h @@ -21,10 +21,10 @@ namespace tubex { namespace ctc { + extern CtcDelay delay; // delay constraint (a,x,y) extern CtcDeriv deriv; // derivative constraint (x,v) - extern CtcEval eval; // evaluation constraint (t,z,y,w) extern CtcDist dist; // distance constraint (a,b,d) - extern CtcDelay delay; // delay constraint (a,x,y) + extern CtcEval eval; // evaluation constraint (t,z,y,w) } }