Example of a local search problem formulation. Based on code in: Toby Segaran, Programming Collective Intelligence, O'Reilly, 2007. The Glass family is traveling from different locations to the same place. Seymour is flying from Boston (BOS), Franny is flying from Dallas (DAL), ..., Les is flying from Omaha (OMA). people = [('Seymour','BOS'), ('Franny','DAL'), ('Zooey','CAK'), ('Walt','MIA'), ('Buddy','ORD'), ('Les','OMA')] destination='LGA' Flight data: http://kiwitobes.com/optimize/schedule.txt origin,dest,depart,arrive,price LGA,OMA,6:19,8:13,239 OMA,LGA,6:11,8:31,249 LGA,OMA,8:04,10:59,136 OMA,LGA,7:39,10:24,219 LGA,OMA,9:31,11:43,210 OMA,LGA,9:15,12:03,99 LGA,OMA,11:07,13:24,171 OMA,LGA,11:08,13:07,175 LGA,OMA,12:31,14:02,234 OMA,LGA,12:18,14:56,172 .... LGA,BOS,6:39,8:09,86 BOS,LGA,6:17,8:26,89 LGA,BOS,8:23,10:28,149 BOS,LGA,8:04,10:11,95 LGA,BOS,9:58,11:18,130 BOS,LGA,9:45,11:50,172 LGA,BOS,10:33,12:03,74 BOS,LGA,11:16,13:29,83 LGA,BOS,12:08,14:05,142 BOS,LGA,12:34,15:02,109 LGA,BOS,13:39,15:30,74 ... State representation (the simpler the better): s=[1,4,3,2,7,3,6,3,2,4,5,3] Seymour takes the second flight of the day from Boston to LGA, Seymour takes the 5th flight of the day from LGA to Boston, Franny takes the 4th flight of the day from Dallas to LGA, Franny takes the 3rd flight of the day from LGA to Dallas, etc. All the lists begin with 0, including the one storing flight information. The "people" list determines the order of the people in the state representation and their home cities; everyone is going to LGA. What are the successor states? All schedules that have one person on the next later or the next earlier departing or returning flight. Seymour (only one of the 1st two numbers changes): s=[0,4,3,2,7,3,6,3,2,4,5,3] s=[2,4,3,2,7,3,6,3,2,4,5,3] s=[1,3,3,2,7,3,6,3,2,4,5,3] s=[1,5,3,2,7,3,6,3,2,4,5,3] Franny (only one of the 2nd two numbers changes): s=[1,4,2,2,7,3,6,3,2,4,5,3] s=[1,4,4,2,7,3,6,3,2,4,5,3] s=[1,4,3,1,7,3,6,3,2,4,5,3] # Suppose there are only 3 flights from LGA to Dallas, # so, there isn't a 4th successor state for Franny ... The cost function (objective function): def schedulecost(state): totalprice=0 latestarrival=0 earliestdep=24*60 for each person p: totalprice+=cost of p's outbound flight totalprice+=cost of p's return flight # Track the latest arrival and earliest departure if latestarrival< p's AT, latestarrival = p's AT if earliestdep> p's DT,earliestdep=p's DT # Every person must wait at the airport until the latest person # arrives. They also must arrive at the same time and wait for # their flights. totalwait=0 for each person p: totalwait+=latestarrival-p's AT totalwait+=p's DT-earliestdep # Does this state require an extra day of car rental? That'll # be $50! if latestarrival>earliestdep: totalprice+=50 return totalprice+totalwait