简体   繁体   English

在车辆路径问题 (VRP) 中使用 Optaplanner 对车队进行长途旅行规划

[英]Using Optaplanner for long trip planning of a fleet of vehicles in a Vehicle Routing Problem (VRP)

I am applying the VRP example of optaplanner with time windows and I get feasible solutions whenever I define time windows in a range of 24 hours (00:00 to 23:59).我正在应用带有时间 windows 的 optaplanner 的 VRP 示例,每当我在 24 小时(00:00 到 23:59)的范围内定义时间 windows 时,我都会得到可行的解决方案。 But I am needing:但我需要:

  • Manage long trips, where I know that the duration between leaving the depot to the first visit, or durations between visits, will be more than 24 hours.管理长途旅行,我知道从离开仓库到第一次访问之间的持续时间或访问之间的持续时间将超过 24 小时。 So currently it does not give me workable solutions, because the TW format is in 24 hour format.所以目前它没有给我可行的解决方案,因为 TW 格式是 24 小时格式。 It happens that when applying the scoring rule "arrivalAfterDueTime", always the "arrivalTime" is higher than the "dueTime", because the "dueTime" is in a range of (00:00 to 23:59) and the "arrivalTime" is the next day.碰巧在应用评分规则“arrivalAfterDueTime”时,“arrivalTime”总是高于“dueTime”,因为“dueTime”在(00:00到23:59)的范围内,而“arrivalTime”是第二天。

I have thought that I should take each TW of each Customer and add more TW to it, one for each day that is planned.我想我应该拿每个客户的每个 TW 并添加更多的 TW,计划的每一天一个。 Example, if I am planning a trip for 3 days, then I would have 3 time windows in each Customer.例如,如果我计划进行为期 3 天的旅行,那么我将在每个客户中有 3 次 windows。 Something like this: if Customer 1 is available from [08:00-10:00], then say it will also be available from [32:00-34:00] and [56:00-58:00] which are the equivalent of the same TW for the following days.像这样:如果客户 1 在 [08:00-10:00] 可用,那么说它也将在 [32:00-34:00] 和 [56:00-58:00] 可用,它们是相当于接下来几天的相同 TW。 Likewise I handle the times with long, converted to milliseconds.同样,我处理时间很长,转换为毫秒。

I don't know if this is the right way, my consultation would be more about some ideas to approach this constraint, maybe you have a similar problematic and any idea for me would be very appreciated.我不知道这是否是正确的方法,我的咨询将更多地是关于解决这个约束的一些想法,也许你有类似的问题,对我来说任何想法都会非常感激。

Sorry for the wording, I am a Spanish speaker.抱歉措辞,我是说西班牙语的人。 Thank you.谢谢你。

Without having checked the example, handing multiple days shouldn't be complicated.在没有检查示例的情况下,处理多天不应该很复杂。 It all depends on how you model your time variable.这完全取决于您如何 model 您的时间变量。

For example, you could:例如,您可以:

  • model the time stamps as a long value denoted as seconds since epoch. model 时间戳作为一个long值,表示为自纪元以来的秒数。 This is how most of the examples are model if I remember correctly.如果我没记错的话,这就是大多数示例的 model。 Note that this is not very human-readable, but is the fastest to compute with请注意,这不是人类可读的,但计算速度最快
  • you could use a time data type, eg LocalTime , this is a human-readable time format but will work in the 24-hour range and will be slower than using a primitive data type您可以使用时间数据类型,例如LocalTime ,这是一种人类可读的时间格式,但将在 24 小时范围内工作,并且比使用原始数据类型慢
  • you could use a date time data tpe, eg LocalDateTime , this is also human-readable and will work in any time range and will also be slower than using a primitive data type.您可以使用日期时间数据,例如LocalDateTime ,这也是人类可读的,并且可以在任何时间范围内工作,并且也比使用原始数据类型慢。

I would strongly encourage to not simply map the current day or current hour to a zero value and start counting from there.我强烈建议不要简单地将当前日期或当前时间的 map 归零并从那里开始计数。 So, in your example you denote the times as [32:00-34:00].因此,在您的示例中,您将时间表示为 [32:00-34:00]。 This makes it appear as you are using the current day midnight as the 0th hour and start counting from there.这使它看起来就像您使用当天的午夜作为第 0 个小时并从那里开始计数一样。 While you can do this it will affect debugging and maintainability of your code.虽然您可以这样做,但它会影响代码的调试和可维护性。 That is just my general advice, you don't have to follow it.这只是我的一般建议,您不必遵循它。

What I would advise is to have your own domain models and map them to Optaplanner models where you use a long value for any time stamp that is denoted as seconds since epoch.我的建议是拥有自己的域模型和 map 到 Optaplanner 模型,在其中您对任何时间戳使用long值,表示为自纪元以来的秒数。

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

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