abdelkimo / or-tools

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

Time limit do not work #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Following program does not stop.

from constraint_solver import pywrapcp

def main():
   solver = pywrapcp.Solver('time limit test')
   n = 10
   x = [solver.IntVar(1, n, 'x[%i]'%i) for i in range(n)]
   solver.Add(solver.AllDifferent(x, True))

   solution = solver.Assignment()
   solution.Add(x)

   db = solver.Phase(x,
                     solver.CHOOSE_FIRST_UNBOUND,
                     solver.ASSIGN_MIN_VALUE)

   time_limit = 10
   branch_limit = 100000000
   failures_limit = 100000000
   solutions_limit = 10000000
   limits = solver.Limit(time_limit, branch_limit, failures_limit, solutions_limit, True)

   search_log = solver.SearchLog(1000)

   solver.NewSearch(db, [limits, search_log])
   num_solutions = 0
   while solver.NextSolution():
       print "x:", [x[i].Value() for i in range(n)]
       num_solutions += 1
   solver.EndSearch()

   print
   print "num_solutions:", num_solutions
   print "failures:", solver.failures()
   print "branches:", solver.branches()
   print "wall_time:", solver.wall_time()

if __name__ == '__main__':
   main()

Original issue reported on code.google.com by lper...@google.com on 10 Oct 2010 at 12:15

GoogleCodeExporter commented 9 years ago
The timer need to be started.

Original comment by lper...@google.com on 10 Oct 2010 at 12:25