@@ -302,10 +302,10 @@ cdef class NNC_Polyhedron(object):
302302 cc = (< Constraint> constraint).thisptr[0 ]
303303 p_c_r = self .thisptr[0 ].relation_with(cc)
304304 result = Polyhedron_Constraint_Rel()
305- result.thisptr[ 0 ] = p_c_r
305+ result.thisptr = new Poly_Con_Rel( p_c_r)
306306 return result
307307 else :
308- raise TypeError ()
308+ raise TypeError (" Here is a useful error " )
309309
310310 def _relation_with_g (self , generator ):
311311 cdef Gen gg
@@ -314,7 +314,7 @@ cdef class NNC_Polyhedron(object):
314314 gg = (< PPliteGenerator> generator).thisptr[0 ]
315315 p_g_r = self .thisptr[0 ].relation_with(gg)
316316 result = Polyhedron_Generator_Rel()
317- result.thisptr[ 0 ] = p_g_r
317+ result.thisptr = new Poly_Gen_Rel( p_g_r)
318318 return result
319319 else :
320320 raise TypeError (" A :class:`PPliteGenerator` or a :class:`Constraint` should be passed into this method." )
@@ -530,7 +530,7 @@ cdef class NNC_Polyhedron(object):
530530 >>> A = Variable(0)
531531 >>> B = Variable(1)
532532 >>> cons_list = [A >= 0, B == 5]
533- >>> P = NNC_Polyhedron(dim_type = 2, spec_elem = "universe", topology = "nnc") #TODO: Make nicer python constructors
533+ >>> P = NNC_Polyhedron(dim_type = 2, spec_elem = "universe", topology = "nnc")
534534 >>> P.add_constraints(cons_list)
535535 >>> P_2 = NNC_Polyhedron(dim_type = 2, spec_elem = "universe", topology = "nnc")
536536 >>> P_2.add_constraint(A >= 0)
@@ -557,7 +557,7 @@ cdef class NNC_Polyhedron(object):
557557 >>> P_2.add_constraint(A >= 0)
558558 >>> P_2.add_constraint(B >= 0)
559559 >>> P_2.minimize()
560- >>> P == P_2 # Test 01 finished
560+ >>> P == P_2
561561 True
562562 >>> P = NNC_Polyhedron(dim_type = 2, spec_elem = "universe", topology = "nnc")
563563 >>> P.add_constraint(A >= 0)
@@ -566,7 +566,7 @@ cdef class NNC_Polyhedron(object):
566566 >>> P.add_generator(Ray(-A))
567567 >>> P_2 = NNC_Polyhedron(dim_type = 2, spec_elem = "universe", topology = "nnc")
568568 >>> P_2.add_constraint(B >= 0)
569- >>> P == P_2 # Test 03 finished
569+ >>> P == P_2
570570 True
571571 """
572572 if isinstance (generator, PPliteGenerator):
@@ -672,8 +672,6 @@ cdef class NNC_Polyhedron(object):
672672# ## Poly_Con_Rel and Poly_Gen_Rel ###
673673# ####################################
674674
675- # TODO: Add full functionality of these classes.
676-
677675cdef class Polyhedron_Constraint_Rel(object ):
678676 def __cinit__ (self ):
679677 self .thisptr = NULL
@@ -702,33 +700,79 @@ cdef class Polyhedron_Constraint_Rel(object):
702700 >>> from pplite import Polyhedron_Constraint_Rel
703701 >>> Polyhedron_Constraint_Rel.nothing()
704702 nothing
705- """
706- cdef Poly_Con_Rel rel = PPlite_NOTHING
707- cdef Poly_Con_Rel * rel_pointer
708- sig_on()
709- try :
710- rel_pointer = & rel
711- relation = Polyhedron_Constraint_Rel()
712- relation.thisptr = rel_pointer
713- finally :
714- sig_off()
703+ """
704+ relation = Polyhedron_Constraint_Rel()
705+ relation.thisptr = new Poly_Con_Rel(PPlite_NOTHING())
715706 return relation
707+
708+ @classmethod
716709 def is_disjoint (cls ):
717- pass
710+ relation = Polyhedron_Constraint_Rel()
711+ relation.thisptr = new Poly_Con_Rel(PPlite_IS_DISJOINT())
712+ return relation
713+
714+ @classmethod
718715 def strictly_intersects (cls ):
719- pass
716+ relation = Polyhedron_Constraint_Rel()
717+ relation.thisptr = new Poly_Con_Rel(PPlite_STRICTLY_INTERSECTS())
718+ return relation
719+
720+ @classmethod
720721 def is_included (cls ):
721- pass
722+ relation = Polyhedron_Constraint_Rel()
723+ relation.thisptr = new Poly_Con_Rel(PPlite_IS_INCLUDED())
724+ return relation
725+
726+ @classmethod
722727 def saturates (cls ):
723- pass
724- def implies (self , other ):
725- pass
728+ relation = Polyhedron_Constraint_Rel()
729+ relation.thisptr = new Poly_Con_Rel(PPlite_SATURATES())
730+ return relation
731+
732+ def implies (self , Polyhedron_Constraint_Rel y ):
733+ return self .thisptr.implies(y.thisptr[0 ])
734+
726735
727736cdef class Polyhedron_Generator_Rel(object ):
728737 def __cinit__ (self ):
729738 self .thisptr = NULL
730739 def __dealloc__ (self ):
731740 del self .thisptr
741+ def __repr__ (self ):
742+ rel = []
743+ if self .implies(Polyhedron_Constraint_Rel.is_disjoint()):
744+ rel.append(' is_disjoint' )
745+ if self .implies(Polyhedron_Constraint_Rel.strictly_intersects()):
746+ rel.append(' strictly_intersects' )
747+ if self .implies(Polyhedron_Constraint_Rel.is_included()):
748+ rel.append(' is_included' )
749+ if self .implies(Polyhedron_Constraint_Rel.saturates()):
750+ rel.append(' saturates' )
751+ if rel:
752+ return ' , ' .join(rel)
753+ else :
754+ return ' nothing'
755+
756+ @classmethod
757+ def nothing (cls ):
758+ """
759+ TESTS::
760+ >>> from pplite import Polyhedron_Generator_Rel
761+ >>> Polyhedron_Generator_Rel.nothing()
762+ nothing
763+ """
764+ relation = Polyhedron_Generator_Rel()
765+ relation.thisptr = new Poly_Gen_Rel(PPlite_Gen_NOTHING())
766+ return relation
767+
768+ @classmethod
769+ def subsumes (cls ):
770+ relation = Polyhedron_Generator_Rel()
771+ relation.thisptr = new Poly_Gen_Rel(PPlite_SUBSUMES())
772+ return relation
773+
774+ def implies (self , Polyhedron_Generator_Rel y ):
775+ return self .thisptr.implies(y.thisptr[0 ])
732776
733777
734778# TODO Migrate helper functions to a helper function module.
@@ -760,11 +804,11 @@ cdef Spec_Elem string_to_Spec_Elem(s):
760804
761805
762806
763- cdef Poly_Con_Rel _new_Poly_Con_Rel(s):
764- if s == " nothing" :
765- return PPlite_NOTHING
807+ # cdef Poly_Con_Rel _new_Poly_Con_Rel(s):
808+ # if s == "nothing":
809+ # return PPlite_NOTHING
766810
767- raise ValueError (" Unrecognized string {0}." .format(s))
811+ # raise ValueError("Unrecognized string {0}.".format(s))
768812
769813# cdef _new_Poly_Con_Rel_Nothing():
770814# cdef Poly_Con_Rel rel = Polyhedron_Constraint_Rel()
0 commit comments