Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" The cdd backend for polyhedral computations """
######################################################################### """ Base class for the cdd backend. """
""" Construct polyhedron from V-representation data.
INPUT:
- ``vertices`` -- list of point. Each point can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements.
- ``rays`` -- list of rays. Each ray can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements.
- ``lines`` -- list of lines. Each line can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements.
- ``verbose`` -- boolean (default: ``False``). Whether to print verbose output for debugging purposes.
EXAMPLES::
sage: Polyhedron(vertices=[(0,0)], rays=[(1,1)], ....: lines=[(1,-1)], backend='cdd', base_ring=QQ) # indirect doctest A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 1 vertex, 1 ray, 1 line """
""" Construct polyhedron from H-representation data.
INPUT:
- ``ieqs`` -- list of inequalities. Each line can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements.
- ``eqns`` -- list of equalities. Each line can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements.
- ``verbose`` -- boolean (default: ``False``). Whether to print verbose output for debugging purposes.
EXAMPLES::
sage: Polyhedron(ieqs=[(0,1,1)], eqns=[(0,1,-1)], ....: backend='cdd', base_ring=QQ) # indirect doctest A 1-dimensional polyhedron in QQ^2 defined as the convex hull of 1 vertex and 1 ray """
""" Compute the facet adjacency matrix in case it has not been computed during initialization.
INPUT:
- ``verbose`` -- boolean (default: ``False``). Whether to print verbose output for debugging purposes.
EXAMPLES::
sage: p = Polyhedron(vertices=[(0,0),(1,0),(0,1)], backend='cdd', base_ring=QQ) sage: '_H_adjacency_matrix' in p.__dict__ False sage: p._init_facet_adjacency_matrix() sage: p._H_adjacency_matrix [0 1 1] [1 0 1] [1 1 0] """ '--adjacency', verbose)
""" Compute the vertex adjacency matrix in case it has not been computed during initialization.
INPUT:
- ``verbose`` -- boolean (default: ``False``). Whether to print verbose output for debugging purposes.
EXAMPLES::
sage: p = Polyhedron(vertices=[(0,0),(1,0),(0,1)], backend='cdd', base_ring=QQ) sage: '_V_adjacency_matrix' in p.__dict__ False sage: p._init_vertex_adjacency_matrix() sage: p._V_adjacency_matrix [0 1 1] [1 0 1] [1 1 0] """ '--adjacency', verbose)
""" Internal method: run cdd on a cdd H- or V-representation and initialize ourselves with the output.
TESTS::
sage: p = Polyhedron(vertices=[[0,0,0],[1,0,0],[0,1,0],[0,0,1]], ....: backend='cdd', base_ring=QQ) sage: from sage.geometry.polyhedron.cdd_file_format import cdd_Vrepresentation sage: s = cdd_Vrepresentation('rational', [[0,0,1],[0,1,0],[1,0,0]], [], []) sage: p._init_from_cdd_input(s) sage: p.dim() 2
sage: point_list = [[0.132, -1.028, 0.028],[0.5, 0.5, -1.5], ....: [-0.5, 1.5, -0.5],[0.5, 0.5, 0.5],[1.5, -0.5, -0.5], ....: [-0.332, -0.332, -0.668],[-1.332, 0.668, 0.332], ....: [-0.932, 0.068, 0.932],[-0.38, -0.38, 1.38], ....: [-0.744, -0.12, 1.12],[-0.7781818182, -0.12, 0.9490909091], ....: [0.62, -1.38, 0.38],[0.144, -1.04, 0.04], ....: [0.1309090909, -1.0290909091, 0.04]] sage: Polyhedron(point_list) A 3-dimensional polyhedron in RDF^3 defined as the convex hull of 14 vertices sage: Polyhedron(point_list, base_ring=QQ) A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 14 vertices """ print('---- CDD input -----') print(cdd_input_string)
stdin=PIPE, stdout=PIPE, stderr=PIPE)
print('---- CDD output -----') print(ans) print(err) # cdd reports errors on stdout and misc information on stderr raise ValueError(ans.strip())
""" Initialize ourselves with the output from cdd.
TESTS::
sage: from sage.geometry.polyhedron.cdd_file_format import cdd_Vrepresentation sage: s = cdd_Vrepresentation('rational',[[0,0],[1,0],[0,1],[1,1]], [], []) sage: from subprocess import Popen, PIPE sage: cdd_proc = Popen(['cdd_both_reps_gmp', '--all'], stdin=PIPE, stdout=PIPE, stderr=PIPE) sage: ans, err = cdd_proc.communicate(input=s) sage: p = Polyhedron(vertices = [[0,0],[1,0],[0,1],[1,1]], backend='cdd', base_ring=QQ) sage: p._init_from_cdd_output(ans) sage: p.vertices() (A vertex at (0, 0), A vertex at (1, 0), A vertex at (0, 1), A vertex at (1, 1)) """
# nested function raise ValueError('Error while parsing cdd output: expected "' +expected_string+'" but got "'+l+'".\n') # nested function
# nested function """ Converts the cdd output string to a numerical value. """
# nested function """ Find the expected string in a list of strings, and truncates ``cddout`` to start at that point. Returns ``False`` if search fails. """ # must not assign to cddout in nested function
else: # cdd does not output the vertex if it is only the origin
else:
# nested function
n_cdd=n-1; else: # cdd reports that lines are never adjacent to anything. # I disagree, they are adjacent to everything! for j in range(n): self._V_adjacency_matrix[i,j] = 1 self._V_adjacency_matrix[j,i] = 1 self._V_adjacency_matrix[i,i] = 0 for i in range(n-1): self._V_adjacency_matrix[i,n-1] = 1 self._V_adjacency_matrix[n-1,i] = 1
######################################################################### """ Polyhedra over QQ with cdd
INPUT:
- ``parent`` -- the parent, an instance of :class:`~sage.geometry.polyhedron.parent.Polyhedra`.
- ``Vrep`` -- a list ``[vertices, rays, lines]`` or ``None``.
- ``Hrep`` -- a list ``[ieqs, eqns]`` or ``None``.
EXAMPLES::
sage: from sage.geometry.polyhedron.parent import Polyhedra sage: parent = Polyhedra(QQ, 2, backend='cdd') sage: from sage.geometry.polyhedron.backend_cdd import Polyhedron_QQ_cdd sage: Polyhedron_QQ_cdd(parent, [ [(1,0),(0,1),(0,0)], [], []], None, verbose=False) A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 3 vertices """
""" The Python constructor.
See :class:`Polyhedron_base` for a description of the input data.
TESTS::
sage: p = Polyhedron(backend='cdd', base_ring=QQ) sage: type(p) <class 'sage.geometry.polyhedron.parent.Polyhedra_QQ_cdd_with_category.element_class'> sage: TestSuite(p).run() """
######################################################################### """ Polyhedra over RDF with cdd
INPUT:
- ``ambient_dim`` -- integer. The dimension of the ambient space.
- ``Vrep`` -- a list ``[vertices, rays, lines]`` or ``None``.
- ``Hrep`` -- a list ``[ieqs, eqns]`` or ``None``.
EXAMPLES::
sage: from sage.geometry.polyhedron.parent import Polyhedra sage: parent = Polyhedra(RDF, 2, backend='cdd') sage: from sage.geometry.polyhedron.backend_cdd import Polyhedron_RDF_cdd sage: Polyhedron_RDF_cdd(parent, [ [(1,0),(0,1),(0,0)], [], []], None, verbose=False) A 2-dimensional polyhedron in RDF^2 defined as the convex hull of 3 vertices """
""" The Python constructor.
See :class:`Polyhedron_base` for a description of the input data.
TESTS::
sage: p = Polyhedron(backend='cdd', base_ring=RDF) sage: type(p) <class 'sage.geometry.polyhedron.parent.Polyhedra_RDF_cdd_with_category.element_class'> sage: TestSuite(p).run() """
|