2

I'm trying to solve a logistics distribution routing problem. For example, there are x trucks that need to distribute y products from their respective starting point to respective destination.

Problems to solve:

  1. which product is delivered by which truck;
  2. in what order are the products getting picked up and dropped off.

What to achieve: (with different weights)

  • minimal waiting time for one product to get picked up;
  • minimal delivery time for each product.

After reading the DEAP documentation and their examples, I'm still not sure what would be a good way to implement this. Because for the problems 1 and 2 above, I have different selection, crossover, and mutation functions but it seems in DEAP you can only register one function in the toolbox for each?

Secondly, how do I implement the evaluation function here? The individual I defined is a class instance comprised of a dict of truck class instances, a dict of product class instances, a list of truck ids, a list of product ids, and a dict of product-truck combination options. The link between the individual and the evaluated value is not so straightforward, with one single evaluation function it's a bit hard (at least for me as a newbie). Thanks!

Stephanie
  • 51
  • 1
  • 7

1 Answers1

0

You can implement an evaluation function that returns two values, one for the waiting time, one for the delivery time.

def waiting(individual):
    # do some calculation

def delivery(individual):
    # do some other calculation

def evaluate(individual):
    return waiting(individual), delivery(individual)

Then simply register this evaluate function in your toolbox, and set the weights vector in your definition of fitness to contain two numbers

toolbox = base.Toolbox()
toolbox.register("attr_flt", random.uniform, 0, 1)

creator.create("FitnessMin", base.Fitness, weights=(-1.0, -1.0)) #you want to minimize both times
creator.create("Individual", list, fitness=creator.FitnessMin)

toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attr_float, n=5)
toolbox.register("evaluate", evaluate)
usernumber
  • 1,958
  • 1
  • 21
  • 58