简体   繁体   English

使用 DEAP 的遗传算法多目标优化

[英]Multi-objective optimization with Genetic Algorithm using DEAP

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.例如,有 x 辆卡车需要将 y 种产品从其各自的起点分发到各自的目的地。

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.在阅读了 DEAP 文档及其示例后,我仍然不确定实现这一点的好方法是什么。 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?因为对于上面的问题 1 和 2,我有不同的选择、交叉和变异函数,但在 DEAP 中似乎只能在工具箱中为每个函数注册一个函数?

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.我定义的个体是一个类实例,由卡车类实例的字典、产品类实例的字典、卡车 ID 列表、产品 ID 列表和产品-卡车组合选项的字典组成。 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!谢谢!

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然后只需在您的工具箱中注册此评估函数,并在您的适应度定义中设置weights向量以包含两个数字

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM