miguelkachondo / or-tools

Automatically exported from code.google.com/p/or-tools
0 stars 0 forks source link

Problem with Sequence Var in Python #46

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I have some problem that I don't understand with the SequenceVar created by the 
DisjunctivConstraint.
One example : 
def main():
    solver = pywrapcp.Solver('Ordo')
    tasks = []
    [tasks.append(solver.FixedDurationIntervalVar(0, 25, 5, False, 'Tasks%i' %i)) for i in range(3)]
    print tasks
    disj = solver.DisjunctiveConstraint(tasks, 'Disjunctive')
    solver.Add(disj)
    collector = solver.AllSolutionCollector()
    collector.Add(tasks)
    intervalPhase = solver.Phase(tasks, solver.INTERVAL_DEFAULT)
    solver.Solve(intervalPhase, [ collector])
    print collector.SolutionCount()
    for i in range(collector.SolutionCount()):
        print "Solution " , i
        print collector.ObjectiveValue(i)
        print [collector.StartValue(i, tasks[j]) for j in range(3)]
        print [collector.EndValue(i, tasks[j]) for j in range(3)]
With this code all is good, I have 6 solutions and it's what I expected.
But when I want call SequenceVar (for example make first the first task) that 
doesn't work :
def main():
    solver = pywrapcp.Solver('Ordo')
    tasks = []
    [tasks.append(solver.FixedDurationIntervalVar(0, 25, 5, False, 'Tasks%i' %i)) for i in range(3)]
    print tasks
    disj = solver.DisjunctiveConstraint(tasks, 'Disjunctive')
    sequence = []
    sequence.append(disj.SequenceVar())
    sequence[0].RankFirst(0)
    solver.Add(disj)
    collector = solver.AllSolutionCollector()
    collector.Add(sequence)
    collector.Add(tasks)
    sequencePhase = solver.Phase(sequence, solver.SEQUENCE_DEFAULT)
    intervalPhase = solver.Phase(tasks, solver.INTERVAL_DEFAULT)
    mainPhase = solver.Compose([sequencePhase, intervalPhase])
    solver.Solve(mainPhase, [ collector])
    print collector.SolutionCount()
    for i in range(collector.SolutionCount()):
        print "Solution " , i
        print collector.ObjectiveValue(i)
        print [collector.StartValue(i, tasks[j]) for j in range(3)]
        print [collector.EndValue(i, tasks[j]) for j in range(3)]

So how can I use SequenceVar from the disjunctivConstraint and what is the use 
of the SequenceVar ?

Original issue reported on code.google.com by lper...@google.com on 21 Jul 2014 at 5:25