# Print current best score print scores[0][0] return scores[0][1] # There are nine outbound and inbound flights respectively for every person # so the domain in the list is set to (0,8) repeated twice for each person domain = [(0, 8)] * (len(gto.people) * 2) # [(0,8), (0,8), ..., ] # Optimizing s = geneticoptimize(domain, gto.schedulecost) print s # Pull the data and present gto.schedulecost(s) gto.printschedule(s) # In case the code yield error: This code is working # Just try several times and it will run # Expected answer # Total cost: 3533 # sol = [4, 3, 3, 3, 4, 3, 3, 0, 0, 0, 0, 0] # Seymour BOS 12:34-15:02 $109 10:33-12:03 $ 74 # Franny DAL 10:30-14:57 $290 10:51-14:16 $256 # Zooey CAK 10:53-13:36 $189 10:32-13:16 $139 # Walt MIA 11:28-14:40 $248 12:37-15:05 $170 # Buddy ORD 12:44-14:17 $134 10:33-13:11 $132 # Les OMA 11:08-13:07 $175 11:07-13:24 $171
# If best != current, the new sol will be used to loop again return sol # There are nine outbound and inbound flights respectively for every person # so the domain in the list is set to (min,max) repeated for each person domain = [(0,8)]*(len(gto.people)*2) # [(0,8), (0,8), ..., ] # Optimizing s = hillclimb(domain, gto.schedulecost) print s # Pull the data and present gto.schedulecost(s) gto.printschedule(s) # Example case # sol = [1, 4, 3, 2, 7, 3, 6, 3, 2, 4, 5, 3] # neighbours = # [[2, 4, 3, 2, 7, 3, 6, 3, 2, 4, 5, 3], # [0, 4, 3, 2, 7, 3, 6, 3, 2, 4, 5, 3], # [1, 5, 3, 2, 7, 3, 6, 3, 2, 4, 5, 3], # [1, 3, 3, 2, 7, 3, 6, 3, 2, 4, 5, 3], # [1, 4, 4, 2, 7, 3, 6, 3, 2, 4, 5, 3], # [1, 4, 2, 2, 7, 3, 6, 3, 2, 4, 5, 3], # [1, 4, 3, 3, 7, 3, 6, 3, 2, 4, 5, 3], # [1, 4, 3, 1, 7, 3, 6, 3, 2, 4, 5, 3], # [1, 4, 3, 2, 8, 3, 6, 3, 2, 4, 5, 3],