简体   繁体   English

Optaplanner 时间约束 windows

[英]Optaplanner constraints for time windows

I am trying to solve VRP with OptaPlanner.我正在尝试使用 OptaPlanner 解决 VRP。 I have multiple customers that have different time windows.我有多个客户有不同的时间 windows。 Here are my constraint providers这是我的约束提供者

protected Constraint arrivalAfterDueTime(ConstraintFactory factory) {
        return factory.from(TimeWindowedCustomer.class)
                .filter(customer -> customer.getArrivalTime() >= customer.getDueTime())
                .penalizeLong("arrivalAfterDueTime",
                        HardSoftLongScore.ONE_HARD,
                        customer -> customer.getArrivalTime() - customer.getDueTime());
    }

protected Constraint arrivalBeforeReadyTime(ConstraintFactory factory) {
        return factory.from(TimeWindowedCustomer.class)
                .filter(customer -> customer.getArrivalTime() > customer.getReadyTime()
                && customer.getArrivalTime() < customer.getDueTime() )
                .penalizeLong("arrivalBeforeReadyTime",
                        HardSoftLongScore.ONE_HARD,
                        customer -> customer.getReadyTime() - customer.getArrivalTime());
    }

But in the solution I get arrival times that are < ready time.但在解决方案中,我得到的到达时间是<准备时间。 How can I fix this?我怎样才能解决这个问题? Thank you in advance.先感谢您。

There are generally three approaches when arriving too early:过早到达时通常有三种方法:

  • A) Wait until the time windows open, losing that time but with no extra penalty. A) 等到 windows 打开的时间,失去那个时间但没有额外的惩罚。 So when it arrives at 9:30, with a service time of 0:10 and ready time of 10:00, the vehicle departs at 10:10 (not 9:40.).因此,当它在 9:30 到达时,服务时间为 0:10,准备时间为 10:00,车辆在 10:10(不是 9:40)出发。 This will automatically be avoided if you have a general constraint to reduce the total activity time of vehicles (or a combination of max activity time per vehicle with too many tasks per day).如果您有减少车辆总活动时间的一般约束(或每辆车的最大活动时间与每天任务过多的组合),这将自动避免。
  • B) Same as A), with an extra soft penalty. B) 与 A) 相同,但有一个额外的软惩罚。 This can be useful if you don't have a global constraint to reduce the total activity time of vehicles.如果您没有全局约束来减少车辆的总活动时间,这将很有用。
  • C) Same as A) with an extra hard penalty. C) 与 A) 相同,但有额外的重罚。 This is dangerous because given 2 tasks, one with a time window from 9:00 to 10:00 and one from 11:00 to 12:00, with a 10 minute drive in between, and no other tasks, you're not allowing one vehicle to do both those tasks.这是危险的,因为给定 2 项任务,一项的时间 window 从 9:00 到 10:00,一项从 11:00 到 12:00,中间有 10 分钟车程,没有其他任务,您不允许一辆车完成这两项任务。

In any case, use ConstraintVerifier to unit test your constraints!无论如何,请使用ConstraintVerifier对您的约束进行单元测试!

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

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