projects
/
linpy.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Update reference examples to match the tutorial
[linpy.git]
/
doc
/
tutorial.rst
diff --git
a/doc/tutorial.rst
b/doc/tutorial.rst
index
8598cbd
..
b13a22e
100644
(file)
--- a/
doc/tutorial.rst
+++ b/
doc/tutorial.rst
@@
-4,6
+4,12
@@
Tutorial
========
Tutorial
========
+This section a short introduction to some of LinPy's features.
+For a comprehensive description of its functionalities, please consult the :ref:`reference`.
+
+
+.. _tutorial_polyhedra:
+
Polyhedra
---------
Polyhedra
---------
@@
-18,31
+24,32
@@
Then, we can build the :class:`Polyhedron` object ``square1`` from its constrain
>>> square1 = Le(0, x, 2) & Le(0, y, 2)
>>> square1
>>> square1 = Le(0, x, 2) & Le(0, y, 2)
>>> square1
-And(
Ge(x, 0), Ge(-x + 2, 0), Ge(y, 0), Ge(-y + 2, 0)
)
+And(
0 <= x, x <= 2, 0 <= y, y <= 2
)
LinPy provides comparison functions :func:`Lt`, :func:`Le`, :func:`Eq`, :func:`Ne`, :func:`Ge` and :func:`Gt` to build constraints, and logical operators :func:`And`, :func:`Or`, :func:`Not` to combine them.
Alternatively, a polyhedron can be built from a string:
>>> square2 = Polyhedron('1 <= x <= 3, 1 <= y <= 3')
>>> square2
LinPy provides comparison functions :func:`Lt`, :func:`Le`, :func:`Eq`, :func:`Ne`, :func:`Ge` and :func:`Gt` to build constraints, and logical operators :func:`And`, :func:`Or`, :func:`Not` to combine them.
Alternatively, a polyhedron can be built from a string:
>>> square2 = Polyhedron('1 <= x <= 3, 1 <= y <= 3')
>>> square2
-And(
Ge(x - 1, 0), Ge(-x + 3, 0), Ge(y - 1, 0), Ge(-y + 3, 0)
)
+And(
1 <= x, x <= 3, 1 <= y, y <= 3
)
The usual polyhedral operations are available, including intersection:
The usual polyhedral operations are available, including intersection:
->>> inter = square1.intersection(square2)
+>>> inter = square1.intersection(square2)
# or square1 & square2
>>> inter
>>> inter
-And(
Ge(x - 1, 0), Ge(-x + 2, 0), Ge(y - 1, 0), Ge(-y + 2, 0)
)
+And(
1 <= x, x <= 2, 1 <= y, y <= 2
)
convex union:
>>> hull = square1.convex_union(square2)
>>> hull
convex union:
>>> hull = square1.convex_union(square2)
>>> hull
-And(
Ge(x, 0), Ge(y, 0), Ge(-x + y + 2, 0), Ge(x - y + 2, 0), Ge(-x + 3, 0), Ge(-y + 3, 0)
)
+And(
0 <= x, 0 <= y, x <= y + 2, y <= x + 2, x <= 3, y <= 3
)
and projection:
and projection:
->>> square1.project([y])
-And(Ge(x, 0), Ge(-x + 2, 0))
+>>> proj = square1.project([y])
+>>> proj
+And(0 <= x, x <= 2)
Equality and inclusion tests are also provided.
Special values :data:`Empty` and :data:`Universe` represent the empty and universe polyhedra.
Equality and inclusion tests are also provided.
Special values :data:`Empty` and :data:`Universe` represent the empty and universe polyhedra.
@@
-53,6
+60,8
@@
True
False
False
+.. _tutorial_domains:
+
Domains
-------
Domains
-------
@@
-60,20
+69,22
@@
LinPy is also able to manipulate polyhedral *domains*, that is, unions of polyhe
An example of domain is the set union (as opposed to convex union) of polyhedra ``square1`` and ``square2``.
The result is a :class:`Domain` object.
An example of domain is the set union (as opposed to convex union) of polyhedra ``square1`` and ``square2``.
The result is a :class:`Domain` object.
->>> union = square1 | square2
+>>> union = square1
.union(square2) # or square1
| square2
>>> union
>>> union
-Or(And(
Ge(-x + 2, 0), Ge(x, 0), Ge(-y + 2, 0), Ge(y, 0)), And(Ge(-x + 3, 0), Ge(x - 1, 0), Ge(-y + 3, 0), Ge(y - 1, 0)
))
+Or(And(
x <= 2, 0 <= x, y <= 2, 0 <= y), And(x <= 3, 1 <= x, y <= 3, 1 <= y
))
>>> union <= hull
True
Unlike polyhedra, domains allow exact computation of union, subtraction and complementary operations.
>>> union <= hull
True
Unlike polyhedra, domains allow exact computation of union, subtraction and complementary operations.
->>> diff = square1 - square2
+>>> diff = square1
.difference(square2) # or square1
- square2
>>> diff
>>> diff
-Or(And(
Eq(x, 0), Ge(y, 0), Ge(-y + 2, 0)), And(Eq(y, 0), Ge(x - 1, 0), Ge(-x + 2, 0)
))
+Or(And(
x == 0, 0 <= y, y <= 2), And(y == 0, 1 <= x, x <= 2
))
>>> ~square1
>>> ~square1
-Or(Ge(-x - 1, 0), Ge(x - 3, 0), And(Ge(x, 0), Ge(-x + 2, 0), Ge(-y - 1, 0)), And(Ge(x, 0), Ge(-x + 2, 0), Ge(y - 3, 0)))
+Or(x + 1 <= 0, 3 <= x, And(0 <= x, x <= 2, y + 1 <= 0), And(0 <= x, x <= 2, 3 <= y))
+
+.. _tutorial_plot:
Plotting
--------
Plotting
--------
@@
-95,7
+106,7
@@
Also, keyword arguments can be passed such as color and the degree of transparen
.. figure:: images/union.jpg
:align: center
.. figure:: images/union.jpg
:align: center
-3D plots are also supported
.
+3D plots are also supported
:
>>> import matplotlib.pyplot as plt
>>> from matplotlib import pylab
>>> import matplotlib.pyplot as plt
>>> from matplotlib import pylab