Using Open VRP: defining your own fitness function
mck- edited this page Feb 10, 2012
·
2 revisions
By default, we minimize the fitness function, which is the total distance traveled by all vehicles. fitness
, as defined in util/fitness.lisp, takes one problem object argument, and returns the total distance. When we call fitness
on a problem that has constraints (such as the Capacitated VRP and the VRP with time windows), then fitness
returns a second value, which is a boolean to test for feasibility of the solution.
- To define your own fitness function, you'll need to create a new problem class first and inherit from the base Problem class, CVRP or VRPTW to your choice. When you inherit from CVRP, calling
constraintsp
on the problem instance will check the capacity constraint for you. When you inherit from a VRPTW, callingconstraintsp
will check the time-window constraints. Multiple-inheritance is allowed.
(defclass my-problem (vrptw)
((name :initform "Your problem")
(desc :initform "A short description of your problem")))
where the slot :desc is optional.
- Now define your fitness function by writing a method for your problem-type:
(defmethod fitness ((prob my-problem))
...)
This function is used by print-routes
and plot-solution
. Iterator also uses fitness
to automatically set new best solutions.