Open
Description
I'm trying to order instances based on a list of classes that should occur before and other that should occur after.
This raises an exception saying that the classes cannot be compared with "<", but I'd like to assign them index.
How should the library be used in such case?
Thanks
import constraint as cst
p = cst.Problem()
class A():
after = []
before = ["B"]
class B():
after = ["A"]
before = ["C"]
class C():
after = ["B"]
before = []
l = [A(), B(), C()]
p.addVariables(l, range(len(l)))
for e in l:
for other_e in l:
for a in e.after:
if a in [c.__name__ for c in other_e.__class__.__mro__]:
p.addConstraint(lambda x,y: x > y, [e, other_e])
for b in e.after:
if b in [c.__name__ for c in other_e.__class__.__mro__]:
p.addConstraint(lambda x,y: x < y, [e, other_e])
p.getSolution()
Metadata
Metadata
Assignees
Labels
No labels