Пример #1
0
 def _adjust_bounds(self):
     # TODO: take into account vertex_min_degree
     if self._fmax is None:
         if self._emax is None:
             raise ValueError("'fmax' or 'emax' must be set")
         self._fmax = 2*self._emax
     if self._vmax is None:
         if self._emax is None:
             raise ValueError("'vmax' or 'emax' must be set")
         self._vmax = 2*self._emax
     if self._emax is None:
         # e = 2g - 2 + v  + f
         self._emax = 2*(self._gmax-1) - 2 + (self._vmax-1) + (self._fmax-1) + 1
     # v, e, f, g
     # -2 + v - e + f + 2g = 0
     from sage.geometry.polyhedron.constructor import Polyhedron
     P = Polyhedron(ieqs=[
         (-self._vmin,   1, 0, 0, 0),
         (self._vmax-1, -1, 0, 0, 0),
         (-self._emin,  0,  1, 0, 0),
         (self._emax-1, 0, -1, 0, 0),
         (-self._fmin,  0, 0,  1, 0),
         (self._fmax-1, 0, 0, -1, 0),
         (-self._gmin,  0, 0, 0,  1),
         (self._gmax-1, 0, 0, 0, -1)],
         eqns = [(-2, 1, -1, 1, 2)])
     if P.is_empty():
         raise ValueError('conditions lead to an empty set')
     half = QQ((1,2))
     self._vmin, self._vmax = minmax([v[0] for v in P.vertices_list()])
     self._vmin = self._vmin.floor()
     self._vmax = (self._vmax + half).ceil()
     self._emin, self._emax = minmax([v[1] for v in P.vertices_list()])
     self._emin = self._emin.floor()
     self._emax = (self._emax + half).ceil()
     self._fmin, self._fmax = minmax([v[2] for v in P.vertices_list()])
     self._fmin = self._fmin.floor()
     self._fmax = (self._fmax + half).ceil()
     self._gmin, self._gmax = minmax([v[3] for v in P.vertices_list()])
     self._gmin = self._gmin.floor()
     self._gmax = (self._gmax + half).ceil()
    def _adjust_bounds(self):
        r"""
        TESTS::

            sage: from surface_dynamics import FatGraphs
            sage: FatGraphs(g=0, nv_max=4, vertex_min_degree=3)
            Traceback (most recent call last):
            ...
            ValueError: infinitely many fat graphs
            sage: FatGraphs(g=0, nf_max=4, vertex_min_degree=3)
            FatGraphs(g=0, nf_min=2, nf_max=4, ne_min=1, ne_max=4, nv_min=1, nv_max=3, vertex_min_degree=3)

            sage: F = FatGraphs(g=0, nv=2, ne=1, nf=2)
            sage: F
            EmptySet
            sage: F.cardinality_and_weighted_cardinality()
            (0, 0)

            sage: FatGraphs(ne=0).list()
            [FatGraph('()', '()', '()')]
            sage: FatGraphs(ne=1).list()
            [FatGraph('(0,1)', '(0,1)', '(0)(1)'),
             FatGraph('(0)(1)', '(0,1)', '(0,1)')]
            sage: FatGraphs(ne=2).list()
            [FatGraph('(0,1,2,3)', '(0,2)(1,3)', '(0,1,2,3)'),
             FatGraph('(0,2,1)(3)', '(0,1)(2,3)', '(0,2,3)(1)'),
             FatGraph('(0,2)(1,3)', '(0,1)(2,3)', '(0,3)(1,2)'),
             FatGraph('(0,3,2,1)', '(0,1)(2,3)', '(0,2)(1)(3)'),
             FatGraph('(0,2)(1)(3)', '(0,1)(2,3)', '(0,1,2,3)')]
        """
        # variable order: v, e, f, g
        from sage.geometry.polyhedron.constructor import Polyhedron
        eqns = [(-2, 1, -1, 1, 2)]  # -2 + v - e + f + 2g = 0
        ieqs = [
            (-self._vmin, 1, 0, 0, 0),  # -vim + v >= 0
            (-self._emin, 0, 1, 0, 0),  # -emin + e >= 0
            (-self._fmin, 0, 0, 1, 0),  # -fmin + f >= 0
            (-self._gmin, 0, 0, 0, 1),  # -gmin + g >= 0
            (0, -self._vertex_min_degree, 2, 0, 0)
        ]  # -v_min_degree*v + 2e >= 0
        if self._vmax is not None:
            ieqs.append((self._vmax - 1, -1, 0, 0, 0))  # v < vmax
        if self._emax is not None:
            ieqs.append((self._emax - 1, 0, -1, 0, 0))  # e < emax
        if self._fmax is not None:
            ieqs.append((self._fmax - 1, 0, 0, -1, 0))  # f < fmax
        if self._gmax is not None:
            ieqs.append((self._gmax - 1, 0, 0, 0, -1))  # g < gmax
        P = Polyhedron(ieqs=ieqs, eqns=eqns, ambient_dim=4, base_ring=QQ)
        if P.is_empty():
            self._vmin = self._vmax = 1
            self._emin = self._emax = 0
            self._fmin = self._fmax = 1
            self._gmin = self._gmax = 0
            self._vertex_min_degree = 0
            return
        if not P.is_compact():
            raise ValueError('infinitely many fat graphs')

        half = QQ((1, 2))
        self._vmin, self._vmax = minmax([v[0] for v in P.vertices_list()])
        self._vmin = self._vmin.floor()
        self._vmax = (self._vmax + half).ceil()
        self._emin, self._emax = minmax([v[1] for v in P.vertices_list()])
        self._emin = self._emin.floor()
        self._emax = (self._emax + half).ceil()
        self._fmin, self._fmax = minmax([v[2] for v in P.vertices_list()])
        self._fmin = self._fmin.floor()
        self._fmax = (self._fmax + half).ceil()
        self._gmin, self._gmax = minmax([v[3] for v in P.vertices_list()])
        self._gmin = self._gmin.floor()
        self._gmax = (self._gmax + half).ceil()