def greedy_val(task): name, order = task from pygrout import VrptwSolution, VrptwTask, build_first VrptwTask.sort_order = order sol = VrptwSolution(VrptwTask(name)) build_first(sol) return sol.val()
def test_find_pos(): """Check consistency of finding the best position in a route.""" from pygrout import (VrptwSolution, VrptwTask, build_first, print_like_Czarnas, find_bestpos_on, find_allpos_on, R_EDG) sol = VrptwSolution(VrptwTask('solomons/rc206.txt')) build_first(sol) for i in xrange(sol.k): for c in sol.r[i][R_EDG][1:]: for j in xrange(sol.k): if i <> j: best = find_bestpos_on(sol, c[0], j) allp = list(find_allpos_on(sol, c[0], j)) print "Best:", best, "all:", allp if best == (None, None): assert allp == [] else: assert best in allp assert best == max(allp)
def test_flattening(): """Checks the format for interchange with other programs, like grout.""" from pygrout import (VrptwSolution, VrptwTask, build_first, print_like_Czarnas) task = VrptwTask('solomons/rc208.txt') s1 = VrptwSolution(task) build_first(s1) print_like_Czarnas(s1) data1 = s1.flatten() print data1 s2 = VrptwSolution(task) s2.inflate(data1) print "Ok, inflated... Let's see:" print_like_Czarnas(s2) print s2.flatten() assert s2.check() assert s2.flatten()==data1 _rec_assert_simmilar(s1.get_essence(), s2.get_essence())
def check_one(test): s = VrptwSolution(VrptwTask(test)) build_first(s) assert s.check()==True, 'Benchmark %s failed at initial solution' % test