Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@ wheelhouse/

# Graphics files
examples/**/*.xml
*.ipe
*.ipe

# Matlab files
*.asv
51 changes: 50 additions & 1 deletion doc/manual/manual/contractors/analytic/ctcinverse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ To represent the vectors :math:`\mathbf{x}\in\mathbb{R}^n` consistent with the c
:end-before: [ctcinv-1-end]
:dedent: 4

.. group-tab:: Matlab

.. literalinclude:: src.m
:language: matlab
:start-after: [ctcinv-1-beg]
:end-before: [ctcinv-1-end]
:dedent: 0

The contractor can be used as an operator to contract a 2d box :math:`[\mathbf{x}]`. It can also be involved in a paver in order to reveal the constraint:

.. tabs::
Expand All @@ -104,6 +112,14 @@ The contractor can be used as an operator to contract a 2d box :math:`[\mathbf{x
:end-before: [ctcinv-2-end]
:dedent: 4

.. group-tab:: Matlab

.. literalinclude:: src.m
:language: matlab
:start-after: [ctcinv-2-beg]
:end-before: [ctcinv-2-end]
:dedent: 0

Which produces the following output:

.. figure:: ./himmelblau_50.png
Expand Down Expand Up @@ -131,6 +147,15 @@ We recall that for thick solution sets, one should prefer the use of the ``SepIn
:end-before: [ctcinv-3-end]
:dedent: 4

.. group-tab:: Matlab

.. literalinclude:: src.m
:language: matlab
:start-after: [ctcinv-3-beg]
:end-before: [ctcinv-3-end]
:dedent: 0


.. figure:: ./himmelblau_50_inner.png
:width: 400px

Expand Down Expand Up @@ -163,6 +188,14 @@ can be easily approximated by the following union of contractors:
:end-before: [ctcinv-4-end]
:dedent: 4

.. group-tab:: Matlab

.. literalinclude:: src.m
:language: matlab
:start-after: [ctcinv-4-beg]
:end-before: [ctcinv-4-end]
:dedent: 0

.. figure:: ./himmelblau_50_150_250.png
:width: 400px

Expand Down Expand Up @@ -302,14 +335,22 @@ When the constraint is a complement constraint :math:`\mathbf{f}(\mathbf{x})\not
:end-before: [ctcinv-5-end]
:dedent: 4

.. group-tab:: Matlab

.. literalinclude:: src.m
:language: matlab
:start-after: [ctcinv-5-beg]
:end-before: [ctcinv-5-end]
:dedent: 0


Miscellaneous
-------------

Access to the underlying function
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The underlying analytic function can be accessed through ``.function()`` (useful for dimension checks or meta-programming).
The underlying analytic function can be accessed through ``.f()`` (useful for dimension checks or meta-programming).

.. tabs::

Expand All @@ -329,6 +370,14 @@ The underlying analytic function can be accessed through ``.function()`` (useful
:end-before: [ctcinv-6-end]
:dedent: 4

.. group-tab:: Matlab

.. literalinclude:: src.m
:language: matlab
:start-after: [ctcinv-6-beg]
:end-before: [ctcinv-6-end]
:dedent: 0

Centered form option
^^^^^^^^^^^^^^^^^^^^

Expand Down
8 changes: 4 additions & 4 deletions doc/manual/manual/contractors/analytic/src.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ TEST_CASE("CtcInverse - manual")
VectorVar x(2);
AnalyticFunction f({x}, x[0]-x[1]);
CtcInverse c(f, 0);
// c.function().input_size() == 2
// c.function().output_size() == 1
// c.f().input_size() == 2
// c.f().output_size() == 1
// [ctcinv-6-end]

CHECK(c.function().input_size() == 2);
CHECK(c.function().output_size() == 1);
CHECK(c.f().input_size() == 2);
CHECK(c.f().output_size() == 1);
}
}
53 changes: 53 additions & 0 deletions doc/manual/manual/contractors/analytic/src.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
% Codac tests
% ----------------------------------------------------------------------------
% \date 2026
% \author Simon Rohou
% \copyright Copyright 2026 Codac Team
% \license GNU Lesser General Public License (LGPL)

import py.codac4matlab.*

% [ctcinv-1-beg]
% Example of Himmelblau's function
a = 11.0;
b = 7.0;
x = VectorVar(2);
f = AnalyticFunction({x}, sqr(sqr(x(1))+x(2)-a)+sqr(x(1)+sqr(x(2))-b));
c = CtcInverse(f,50.0);
% [ctcinv-1-end]

% [ctcinv-2-beg]
DefaultFigure().pave(IntervalVector({{-6,6},{-6,6}}), c, 1e-2);
% [ctcinv-2-end]

% [ctcinv-3-beg]
s = SepInverse(f, Interval(0,50));
DefaultFigure().pave(IntervalVector({{-6,6},{-6,6}}), s, 1e-2);
% [ctcinv-3-end]

% [ctcinv-4-beg]
cu = CtcUnion(CtcUnion(CtcInverse(f,50), CtcInverse(f,150)), CtcInverse(f,250));
DefaultFigure().pave(IntervalVector({{-6,6},{-6,6}}), cu, 1e-2)
% [ctcinv-4-end]

% [ctcinv-5-beg]
x = VectorVar(2);
f = AnalyticFunction({x}, x(1));

% Enforce the first component not in [0,1]
c = CtcInverseNotIn(f, Interval(0,1));

y = IntervalVector({{0.5,3},{-1,1}});
c.contract(y); % [[1,3],[-1,1]]
% Only the first component is constrained by the not-in condition
% [ctcinv-5-end]

assert(y==IntervalVector({{1,3},{-1,1}}));

% [ctcinv-6-beg]
x = VectorVar(2);
f = AnalyticFunction({x}, x(1)-x(2));
c = CtcInverse(f, 0);
assert(c.f().input_size()==2);
assert(c.f().output_size()==1);
% [ctcinv-6-end]
4 changes: 2 additions & 2 deletions doc/manual/manual/contractors/analytic/src.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def tests_CtcInverse_manual(test):
x = VectorVar(2)
f = AnalyticFunction([x], x[0]-x[1])
c = CtcInverse(f, 0)
assert c.function().input_size() == 2
assert c.function().output_size() == 1
assert c.f().input_size() == 2
assert c.f().output_size() == 1
# [ctcinv-6-end]

if __name__ == '__main__':
Expand Down
Binary file not shown.
Binary file modified doc/manual/tuto/cp_robotics/img/CtcConstell_constell.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/manual/tuto/cp_robotics/img/datasso_solved.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/manual/tuto/cp_robotics/img/first_result.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/manual/tuto/cp_robotics/img/loc_robot_landmarks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/manual/tuto/cp_robotics/img/loc_robot_landmarks_obs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/manual/tuto/cp_robotics/img/result_rangebearing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions doc/manual/tuto/cp_robotics/lesson_a_static_range_and_bearing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,31 @@ where :math:`a,b,\dots,e` are intermediate variables used for the decomposition.
Interval d(4.5,5); // interval for y
ctc_g.contract(a,d,b);

.. code-tab:: matlab

import py.codac4matlab.*

% Symbolic variables:
y = ScalarVar();
[x,m] = deal(VectorVar(2),VectorVar(2));

% Analytic scalar function g(x,m,y) involved in the constraint:
g = AnalyticFunction({x,y,m}, sqrt(((x(1)-m(1))^2)+((x(2)-m(2))^2))-y);

% Contractor associated with the constraint g(x,m,y)\in[u], with [u]=[0,0]
ctc_g = CtcInverse(g, 0);

% Now ctc_g can be called with the .contract(..) method to contract all domains:
% Example:
a = IntervalVector(2); % box for x
b = IntervalVector({{2,3},{5,6.2}}); % box for m
d = Interval(4.5,5); % interval for y

res = ctc_g.contract(cart_prod(a,d,b));
a = res.subvector(1,2);
b = res.subvector(3,4);
c = res(5);


Optimality of contractors
-------------------------
Expand Down Expand Up @@ -176,6 +201,17 @@ could be implemented by
// Contractor associated with the constraint g(x,m,y)\in[u] with [u]=[[0,0],[0,0]]
CtcInverse ctc_g(g, {0,0}) // {0,0} is equivalent to Vector::zero(2)

.. code-tab:: matlab

% Symbolic variables:
[x,m,y] = deal(VectorVar(3),VectorVar(2),VectorVar(2));

% Analytic vectorial function g(x,y,m) involved in the constraint:
g = AnalyticFunction({x,y,m}, vec(x(1)+y(1)*cos(x(3)+y(2))-m(1), x(2)+y(1)*sin(x(3)+y(2))-m(2)));

% Contractor associated with the constraint g(x,m,y)\in[u] with [u]=[[0,0],[0,0]]
ctc_g = CtcInverse(g, Vector([0,0])); % [0,0] is equivalent to Vector.zero(2)

However, this involves a multi-occurrence of variables which leads to pessimism. For instance, the sum :math:`(x_3+y_2)` appears twice in functions :math:`\cos` and :math:`\sin`, which is hardly handled by a classical decomposition.


Expand Down Expand Up @@ -266,6 +302,13 @@ A robot depicted by the state :math:`\mathbf{x}=\left(2,1,\pi/6\right)^\intercal

Vector x_truth = {2,1,PI/6}; // actual state vector (pose = position + bearing)

.. code-tab:: matlab

% We recall that you can use the Vector class for
% representing mathematical vectors. For instance:

x_truth = Vector([2,1,PI/6]); % actual state vector (pose = position + bearing)

.. container:: toggle, toggle-hidden

.. tabs::
Expand Down Expand Up @@ -309,6 +352,10 @@ A robot depicted by the state :math:`\mathbf{x}=\left(2,1,\pi/6\right)^\intercal

x[2] &= x_truth[2]; // the heading is assumed to be known

.. code-tab:: matlab

x(3).self_inter(x_truth(3)); % the heading is assumed to be known

.. container:: toggle, toggle-hidden

.. tabs::
Expand Down Expand Up @@ -351,6 +398,11 @@ A robot depicted by the state :math:`\mathbf{x}=\left(2,1,\pi/6\right)^\intercal
DefaultFigure::draw_tank(x_truth, 1, {Color::black(),Color::yellow()}); // robot's size is 1
DefaultFigure::draw_box(m, Color::red());

.. code-tab:: matlab

DefaultFigure().draw_tank(x_truth, 1, StyleProperties({Color().black(),Color().yellow()}));
DefaultFigure().draw_box(m,Color().red());

**A.5.** Display the range-and-bearing measurement with its uncertainties. For this, we will use the function ``.draw_pie(<c>, <[rho]>, <[theta]>)`` to display a portion of a ring :math:`[\rho]\times[\theta]` centered on :math:`(x,y)^\intercal`. Here, we must add in :math:`[\theta]` the robot heading :math:`x_3` and the bounded bearing :math:`[y_2]`.

You should obtain this figure:
Expand All @@ -370,6 +422,10 @@ A robot depicted by the state :math:`\mathbf{x}=\left(2,1,\pi/6\right)^\intercal

DefaultFigure::draw_pie({<x>, <y>}, <[rho]> | 0, <[theta]>, Color::light_gray()); // with: <[rho]> | 0

.. code-tab:: matlab

DefaultFigure().draw_pie(Vector([<x>, <y>]), <[rho]>.union(0), <[theta]>, Color().light_gray()); % with: <[rho]> | 0

.. container:: toggle, toggle-hidden

.. tabs::
Expand Down Expand Up @@ -499,6 +555,10 @@ The following code illustrates how to implement such fixpoint:
etc.
}, <domains related to c1,c2,..>);

.. code-tab:: matlab

% Not supported yet

The ``fixpoint`` function will execute the content of the function ``contractors_list`` until there are no more contractions on the sets listed in ``<domains related to c1,c2,..>``.

.. admonition:: Exercise
Expand Down
Loading