Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Random searching isn’t a very good optimization method, but it makes it easy to understand exactly what all the algorithms are trying to do, and it also serves as a baseline so you can see if the other algorithms are doing a good job.
The function takes a couple of parameters. Domain is a list of 2-tuples that specify the
minimum and maximum values for each variable. The length of the solution
is the same as the length of this list. In the current example, there
are nine outbound flights and nine inbound flights for every person, so
the domain in the list is (0,8)
repeated twice for each person.
The second parameter, costf, is
the cost function, which in this example will be schedulecost. This is passed as a parameter so
that the function can be reused for other optimization problems. This
function randomly generates 1,000 guesses and calls costf on them. It keeps track of the best
guess (the one with the lowest cost) and returns it. Add it to optimization.py: