Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Polyhedron_normaliz: In verbose mode, write out normaliz format files
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Apr 4, 2018
1 parent fcd8101 commit 19d8539
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/sage/geometry/polyhedron/backend_normaliz.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ def _init_from_normaliz_data(self, data, verbose=False):
import PyNormaliz
if verbose:
print("# Calling PyNormaliz.NmzCone(**{})".format(data))
import six
if isinstance(verbose, six.string_types):
print("# Wrote equivalent Normaliz input file to {}".format(verbose))
self._normaliz_format(data, file_output=verbose)
else:
print("# ----8<---- Equivalent Normaliz input file ----8<----")
print(self._normaliz_format(data), end='')
print("# ----8<-------------------8<-------------------8<----")
cone = PyNormaliz.NmzCone(**data)
assert cone, "NmzCone(**{}) did not return a cone".format(data)
self._init_from_normaliz_cone(cone)
Expand Down Expand Up @@ -389,6 +397,48 @@ def _from_normaliz_cone(cls, parent, normaliz_cone):
"""
return cls(parent, None, None, normaliz_cone=normaliz_cone)

def _normaliz_format(self, data, file_output=None):
r"""
Return a string containing normaliz format.
INPUT:
- ``data`` -- a dictionary of PyNormaliz cone input properties.
- ``file_output`` (string; optional) -- a filename to which the
representation should be written. If set to ``None`` (default),
representation is returned as a string.
EXAMPLES::
sage: P = Polyhedron(vertices=[[0, 0], [0, 1], [1, 0]], # indirect doctest; optional - pynormaliz
....: backend='normaliz', verbose=True)
# Calling ...
# ----8<---- Equivalent Normaliz input file ----8<----
amb_space 2
subspace 0
vertices 3
0 0 1
0 1 1
1 0 1
cone 0
# ----8<-------------------8<-------------------8<----
"""
s = 'amb_space {}\n'.format(self.ambient_dim())
for key, value in dict.iteritems():
s += '{} {}\n'.format(key, len(value))
for e in value:
for x in e:
s += ' ' + repr(x)
s += '\n'

if file_output is not None:
in_file = open(file_output, 'w')
in_file.write(s)
in_file.close()
else:
return s

def integral_hull(self):
r"""
Return the integral hull in the polyhedron.
Expand Down

0 comments on commit 19d8539

Please sign in to comment.