Example #1
0
 def from_polyhedron_to_linear_system(cls, p, poly_ring=None):
     """
     Convert a instance of Polyhedron to a instance of BasicSemialgebraicSet_polyhedral_linear_system
     """
     if p.__class__ == cls:
         return p
     base_ring = p.base_ring().fraction_field()
     ambient_dim = p.ambient_dim()
     if poly_ring is None:
         poly_ring = PolynomialRing(base_ring, "x", ambient_dim)
     else:
         if ambient_dim != poly_ring.ambient_dim():
             raise ValueError(
                 "Ambient dimensions of p and poly_ring do not match.")
     self = cls(base_ring=base_ring,
                ambient_dim=ambient_dim,
                poly_ring=poly_ring)
     i = 1
     for lhs in p.inequalities_list():
         self.add_linear_constraint(lhs[1:], lhs[0], operator.ge)
         self.history_set[-sum(lhs[1:][i] * self.poly_ring().gens()[i]
                               for i in range(len(lhs) - 1)) -
                          lhs[0]] = {i}
         i += 1
     for lhs in p.equations_list():
         self.add_linear_constraint(lhs[1:], lhs[0], operator.eq)
         self.history_set[sum(lhs[1:][i] * self.poly_ring().gens()[i]
                              for i in range(len(lhs) - 1)) + lhs[0]] = {i}
         i += 1
     return self