Solve() now backtracks at the end/ RejectSolution on SearchMonitor is now split into AcceptSolution() and AtSolution/ There is a new virtual OnStart() on neighborhoods/Examples were tweaked to adapt to the new API
This commit is contained in:
@@ -36,10 +36,12 @@ def main(unused_argv):
|
||||
solver.Add(solver.Distribute(all_vars, all_values, all_vars))
|
||||
solver.Add(solver.Sum(all_vars) == size)
|
||||
|
||||
solver.Solve(solver.Phase(all_vars,
|
||||
solver.CHOOSE_FIRST_UNBOUND,
|
||||
solver.ASSIGN_MIN_VALUE))
|
||||
solver.NewSearch(solver.Phase(all_vars,
|
||||
solver.CHOOSE_FIRST_UNBOUND,
|
||||
solver.ASSIGN_MIN_VALUE))
|
||||
solver.NextSolution()
|
||||
print all_vars
|
||||
solver.EndSearch()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -43,13 +43,14 @@ def main():
|
||||
solver.INT_VALUE_DEFAULT)
|
||||
|
||||
# And solve.
|
||||
solver.Solve(db)
|
||||
solver.NewSearch(db)
|
||||
solver.NextSolution()
|
||||
|
||||
# Display output.
|
||||
print solver
|
||||
print pheasant
|
||||
print rabbit
|
||||
|
||||
solver.EndSearch()
|
||||
print solver
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -49,9 +49,12 @@ def main(unused_argv):
|
||||
|
||||
solver.Add(solver.AllDifferent(letters, True))
|
||||
|
||||
solver.Solve(solver.Phase(letters, solver.INT_VAR_DEFAULT,
|
||||
solver.INT_VALUE_DEFAULT))
|
||||
solver.NewSearch(solver.Phase(letters,
|
||||
solver.INT_VAR_DEFAULT,
|
||||
solver.INT_VALUE_DEFAULT))
|
||||
solver.NextSolution()
|
||||
print letters
|
||||
solver.EndSearch()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -103,9 +103,10 @@ def main(unused_argv):
|
||||
tea, coffee, water, milk, fruit_juice,
|
||||
red, green, yellow, blue, ivory]
|
||||
|
||||
if solver.Solve(solver.Phase(all_vars,
|
||||
solver.INT_VAR_DEFAULT,
|
||||
solver.INT_VALUE_DEFAULT)):
|
||||
solver.NewSearch(solver.Phase(all_vars,
|
||||
solver.INT_VAR_DEFAULT,
|
||||
solver.INT_VALUE_DEFAULT))
|
||||
if solver.NextSolution():
|
||||
people = [englishman, spaniard, japanese, ukrainian, norwegian]
|
||||
water_drinker = [p for p in people if p.Value() == water.Value()][0]
|
||||
zebra_owner = [p for p in people if p.Value() == zebra.Value()][0]
|
||||
@@ -113,6 +114,7 @@ def main(unused_argv):
|
||||
print 'The %s owns the zebra.' % zebra_owner.name()
|
||||
else:
|
||||
print 'No solutions to the zebra problem, this is unusual!'
|
||||
solver.EndSearch()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user