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:
lperron@google.com
2010-10-06 16:04:31 +00:00
parent e0c66e81da
commit 672aa0605c
14 changed files with 310 additions and 296 deletions

View File

@@ -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__':

View File

@@ -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()

View File

@@ -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__':

View File

@@ -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__':