|
| 1 | +.. _sec-ctc-set-ctcunion: |
| 2 | +.. _sec-sep-set-sepunion: |
| 3 | + |
| 4 | +Union: CtcUnion and SepUnion |
| 5 | +============================ |
| 6 | + |
| 7 | + Main author: `Simon Rohou <https://www.simon-rohou.fr/research/>`_ |
| 8 | + |
| 9 | + |
| 10 | +``CtcUnion`` and ``SepUnion`` implement the logical union/disjunction counterpart of |
| 11 | +``CtcInter`` and ``SepInter``: |
| 12 | + |
| 13 | +.. list-table:: |
| 14 | + :header-rows: 1 |
| 15 | + :widths: 20 35 45 |
| 16 | + |
| 17 | + * - Class |
| 18 | + - Combines |
| 19 | + - Meaning |
| 20 | + * - ``CtcUnion`` |
| 21 | + - contractors |
| 22 | + - disjunction of constraints, obtained by joining the contracted branches |
| 23 | + * - ``SepUnion`` |
| 24 | + - separators |
| 25 | + - separator associated with the union of the represented sets |
| 26 | + |
| 27 | +Both classes can be constructed explicitly or with the ``|`` operator. |
| 28 | + |
| 29 | + |
| 30 | +CtcUnion: disjunction of contractors |
| 31 | +------------------------------------ |
| 32 | + |
| 33 | +For box contractors, ``CtcUnion`` applies every stored contractor independently to the |
| 34 | +same input box and returns a box enclosing the union of the resulting branches: |
| 35 | + |
| 36 | +.. math:: |
| 37 | +
|
| 38 | + \mathcal{C}_{\mathrm{union}}([\mathbf{x}]) |
| 39 | + = |
| 40 | + \operatorname{hull}\!\left( |
| 41 | + \bigcup_{i=1}^{n}\mathcal{C}_i([\mathbf{x}]) |
| 42 | + \right), |
| 43 | +
|
| 44 | +where :math:`\operatorname{hull}` denotes the smallest box containing the union. |
| 45 | + |
| 46 | +This evaluation differs from ``CtcInter``: the branches are **not** applied |
| 47 | +sequentially. Each contractor receives the original input domain. |
| 48 | + |
| 49 | +.. note:: |
| 50 | + |
| 51 | + The exact union of several boxes is generally not a box. ``CtcUnion`` therefore |
| 52 | + returns a box enclosure of this union. This enclosure may contain points that do not |
| 53 | + belong to any individual branch. |
| 54 | + |
| 55 | +The usual construction uses ``|`` or the ``CtcUnion`` constructor. |
| 56 | + |
| 57 | +.. tabs:: |
| 58 | + |
| 59 | + .. group-tab:: Python |
| 60 | + |
| 61 | + .. literalinclude:: src.py |
| 62 | + :language: py |
| 63 | + :start-after: [union-ctc-1-beg] |
| 64 | + :end-before: [union-ctc-1-end] |
| 65 | + :dedent: 4 |
| 66 | + |
| 67 | + .. group-tab:: C++ |
| 68 | + |
| 69 | + .. literalinclude:: src.cpp |
| 70 | + :language: c++ |
| 71 | + :start-after: [union-ctc-1-beg] |
| 72 | + :end-before: [union-ctc-1-end] |
| 73 | + :dedent: 2 |
| 74 | + |
| 75 | +Applying it to a box gives the hull of the contracted branches: |
| 76 | + |
| 77 | +.. tabs:: |
| 78 | + |
| 79 | + .. group-tab:: Python |
| 80 | + |
| 81 | + .. literalinclude:: src.py |
| 82 | + :language: py |
| 83 | + :start-after: [union-ctc-2-beg] |
| 84 | + :end-before: [union-ctc-2-end] |
| 85 | + :dedent: 4 |
| 86 | + |
| 87 | + .. group-tab:: C++ |
| 88 | + |
| 89 | + .. literalinclude:: src.cpp |
| 90 | + :language: c++ |
| 91 | + :start-after: [union-ctc-2-beg] |
| 92 | + :end-before: [union-ctc-2-end] |
| 93 | + :dedent: 2 |
| 94 | + |
| 95 | +For the two boxes used here, the exact union is not itself a box. Its interval hull is |
| 96 | + |
| 97 | +.. math:: |
| 98 | +
|
| 99 | + [-12,10]\times[-2,4]. |
| 100 | +
|
| 101 | +
|
| 102 | +SepUnion: union of represented sets |
| 103 | +----------------------------------- |
| 104 | + |
| 105 | +``SepUnion`` is the separator counterpart. If separators |
| 106 | +:math:`\mathcal{S}_1,\ldots,\mathcal{S}_n` are associated with sets |
| 107 | +:math:`\mathbb{S}_1,\ldots,\mathbb{S}_n`, then ``SepUnion`` is associated with |
| 108 | + |
| 109 | +.. math:: |
| 110 | +
|
| 111 | + \mathbb{S}_{\mathrm{union}} |
| 112 | + = |
| 113 | + \mathbb{S}_1 \cup \cdots \cup \mathbb{S}_n. |
| 114 | +
|
| 115 | +Construction follows the same syntax as for ``CtcUnion``: |
| 116 | + |
| 117 | +.. tabs:: |
| 118 | + |
| 119 | + .. group-tab:: Python |
| 120 | + |
| 121 | + .. literalinclude:: src.py |
| 122 | + :language: py |
| 123 | + :start-after: [union-sep-1-beg] |
| 124 | + :end-before: [union-sep-1-end] |
| 125 | + :dedent: 4 |
| 126 | + |
| 127 | + .. group-tab:: C++ |
| 128 | + |
| 129 | + .. literalinclude:: src.cpp |
| 130 | + :language: c++ |
| 131 | + :start-after: [union-sep-1-beg] |
| 132 | + :end-before: [union-sep-1-end] |
| 133 | + :dedent: 2 |
| 134 | + |
| 135 | + |
| 136 | +Building a union incrementally |
| 137 | +------------------------------ |
| 138 | + |
| 139 | +Both classes support ``|=`` and ``nb()``. |
| 140 | + |
| 141 | +For ``CtcUnion``, a union may be created from the dimension only. Before a branch is |
| 142 | +added, it represents the empty disjunction: contracting a box with it returns the empty |
| 143 | +domain. Adding contractors with ``|=`` then builds the disjunction incrementally. |
| 144 | + |
| 145 | +.. tabs:: |
| 146 | + |
| 147 | + .. group-tab:: Python |
| 148 | + |
| 149 | + .. literalinclude:: src.py |
| 150 | + :language: py |
| 151 | + :start-after: [union-ctc-3-beg] |
| 152 | + :end-before: [union-ctc-3-end] |
| 153 | + :dedent: 4 |
| 154 | + |
| 155 | + .. group-tab:: C++ |
| 156 | + |
| 157 | + .. literalinclude:: src.cpp |
| 158 | + :language: c++ |
| 159 | + :start-after: [union-ctc-3-beg] |
| 160 | + :end-before: [union-ctc-3-end] |
| 161 | + :dedent: 2 |
| 162 | + |
| 163 | +``SepUnion`` currently has no constructor taking only a dimension, so incremental |
| 164 | +construction starts from an existing separator: |
| 165 | + |
| 166 | +.. tabs:: |
| 167 | + |
| 168 | + .. group-tab:: Python |
| 169 | + |
| 170 | + .. literalinclude:: src.py |
| 171 | + :language: py |
| 172 | + :start-after: [union-sep-2-beg] |
| 173 | + :end-before: [union-sep-2-end] |
| 174 | + :dedent: 4 |
| 175 | + |
| 176 | + .. group-tab:: C++ |
| 177 | + |
| 178 | + .. literalinclude:: src.cpp |
| 179 | + :language: c++ |
| 180 | + :start-after: [union-sep-2-beg] |
| 181 | + :end-before: [union-sep-2-end] |
| 182 | + :dedent: 2 |
| 183 | + |
| 184 | + |
| 185 | +.. admonition:: Technical documentation |
| 186 | + |
| 187 | + See the `C++ API documentation of CtcUnion <../../api/html/classcodac2_1_1_ctc_union.html>`_ |
| 188 | + and the `C++ API documentation of SepUnion <../../api/html/classcodac2_1_1_sep_union.html>`_. |
0 commit comments