gpt4 book ai didi

java - 多日车辆路线 - 使用日指数较小的车辆

转载 作者:行者123 更新时间:2023-11-30 06:23:50 24 4
gpt4 key购买 nike

我尝试根据 optaplanner 车辆路线示例构建多日车辆路线。我创建了 VehicleDay 类来为单日旅行的车辆建模。 VehicleDay 类是 Vehicle 对象和 Day 对象的连接。这是类(class):

public class Day extends AbstractPersistable {
protected int dayIndex;
protected int dayInt;
protected String day;

// getter and setter methods
...
}

public class Vehicle extends AbstractPersistable {
protected int capacity;
protected Depot depot;

// getter and setter methods
...
}

public class VehicleDay extends AbstractPersistable implements Standstill {
protected Vehicle vehicle;
protected Day day;

// Shadow variables
protected Customer nextCustomer;

// getter and setter methods
...
}

我将计划实体从 Vehicle 移至 VehicleDay。然后我尝试创建一个示例数据集 ( cvrp-72customers-edited.xml ),其中包含 8 个车辆日和 71 个客户。我从 cvrp-72customers 获取此示例数据集,并将车辆容量修改为原始数据的 3/4 (22000)。 8 个车辆日包括:

  1. 第 1 天(星期一)的车辆 ID 1
  2. 车辆 ID 1,第 2 天(星期二)
  3. 第 1 天(星期一)的车辆 ID 2
  4. 车辆 ID 2,第 2 天(星期二)
  5. 车辆 ID 3,第 1 天(星期一)
  6. 车辆 ID 3,第 2 天(星期二)
  7. 车辆 ID 4,第 1 天(星期一)
  8. 车辆 ID 4,第 2 天(星期二)

但是当我尝试运行它时,结果是没有使用第一天的一些车辆,而是规划器使用了第二天的一些车辆( cvrp-72customers-edited-solved.xml )。我试图实现的是,规划者首先使用第 1 天的车辆,在使用第 1 天的所有车辆之后,然后规划者开始在第 2 天使用车辆。我尝试使用 Comparator 并创建 StandstillDifficultyComparator 类:

public class StandstillDifficultyComparator implements Comparator<Standstill>, Serializable {

@Override
public int compare(Standstill a, Standstill b) {
if (a instanceof Customer) {
return new CompareToBuilder()
.append(((Customer)a).getId(), ((Customer)b).getId())
.toComparison();
} else {
return new CompareToBuilder()
.append(((VehicleDay)a).getDay().getDayIndex(), ((VehicleDay)b).getDay().getDayIndex())
.append(((VehicleDay)a).getId(), ((VehicleDay)b).getId())
.toComparison();
}
}

}

然后在 unionMoveSelector 配置中,我添加比较器类,如下所示:

<unionMoveSelector>
<changeMoveSelector>
<entitySelector>
<cacheType>PHASE</cacheType>
<selectionOrder>SORTED</selectionOrder>
<sorterComparatorClass>org.optaplanner.examples.vehiclerouting.domain.solver.StandstillDifficultyComparator</sorterComparatorClass>
<sorterOrder>ASCENDING</sorterOrder>
</entitySelector>
</changeMoveSelector>
<swapMoveSelector>
<entitySelector>
<cacheType>PHASE</cacheType>
<selectionOrder>SORTED</selectionOrder>
<sorterComparatorClass>org.optaplanner.examples.vehiclerouting.domain.solver.StandstillDifficultyComparator</sorterComparatorClass>
<sorterOrder>ASCENDING</sorterOrder>
</entitySelector>
</swapMoveSelector>
<tailChainSwapMoveSelector>
<entitySelector>
<cacheType>PHASE</cacheType>
<selectionOrder>SORTED</selectionOrder>
<sorterComparatorClass>org.optaplanner.examples.vehiclerouting.domain.solver.StandstillDifficultyComparator</sorterComparatorClass>
<sorterOrder>ASCENDING</sorterOrder>
</entitySelector>
</tailChainSwapMoveSelector>
<subChainChangeMoveSelector>
<selectReversingMoveToo>true</selectReversingMoveToo>
<entitySelector>
<cacheType>PHASE</cacheType>
<selectionOrder>SORTED</selectionOrder>
<sorterComparatorClass>org.optaplanner.examples.vehiclerouting.domain.solver.StandstillDifficultyComparator</sorterComparatorClass>
<sorterOrder>ASCENDING</sorterOrder>
</entitySelector>
</subChainChangeMoveSelector>
<subChainSwapMoveSelector>
<selectReversingMoveToo>true</selectReversingMoveToo>
<entitySelector>
<cacheType>PHASE</cacheType>
<selectionOrder>SORTED</selectionOrder>
<sorterComparatorClass>org.optaplanner.examples.vehiclerouting.domain.solver.StandstillDifficultyComparator</sorterComparatorClass>
<sorterOrder>ASCENDING</sorterOrder>
</entitySelector>
</subChainSwapMoveSelector>
</unionMoveSelector>

当我运行它时,抛出一个异常,如下所示:

Exception in thread "main" java.lang.IllegalArgumentException: Unmarshalling of solverConfigResource (org/optaplanner/examples/vehiclerouting/solver/vehicleRoutingSolverConfig.xml) fails on line number (53).
at org.optaplanner.core.impl.solver.XStreamXmlSolverFactory.configure(XStreamXmlSolverFactory.java:123)
at org.optaplanner.core.api.solver.SolverFactory.createFromXmlResource(SolverFactory.java:90)
at org.optaplanner.examples.common.app.CommonApp.createSolver(CommonApp.java:102)
at org.optaplanner.examples.common.app.CommonApp.createSolutionBusiness(CommonApp.java:97)
at org.optaplanner.examples.common.app.CommonApp.init(CommonApp.java:84)
at org.optaplanner.examples.common.app.CommonApp.init(CommonApp.java:80)
at org.optaplanner.examples.vehiclerouting.app.VehicleRoutingApp.main(VehicleRoutingApp.java:34)
Caused by: " com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$UnknownFieldException: No such field org.optaplanner.core.config.heuristic.selector.move.generic.chained.SubChainChangeMoveSelectorConfig.entitySelector
---- Debugging information ----
message : No such field org.optaplanner.core.config.heuristic.selector.move.generic.chained.SubChainChangeMoveSelectorConfig.entitySelector
field : entitySelector
class : org.optaplanner.core.config.heuristic.selector.move.generic.chained.SubChainChangeMoveSelectorConfig
required-type : org.optaplanner.core.config.heuristic.selector.move.generic.chained.SubChainChangeMoveSelectorConfig
converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
line number : 53
class[1] : org.optaplanner.core.config.heuristic.selector.move.composite.UnionMoveSelectorConfig
class[2] : org.optaplanner.core.config.localsearch.LocalSearchPhaseConfig
class[3] : org.optaplanner.core.config.solver.SolverConfig
version : 1.4.10
-------------------------------
at org.optaplanner.core.impl.solver.XStreamXmlSolverFactory.configure(XStreamXmlSolverFactory.java:123)
at org.optaplanner.core.api.solver.SolverFactory.createFromXmlResource(SolverFactory.java:90)
at org.optaplanner.examples.common.app.CommonApp.createSolver(CommonApp.java:102)
at org.optaplanner.examples.common.app.CommonApp.createSolutionBusiness(CommonApp.java:97)
at org.optaplanner.examples.common.app.CommonApp.init(CommonApp.java:84)
at org.optaplanner.examples.common.app.CommonApp.init(CommonApp.java:80)
at org.optaplanner.examples.vehiclerouting.app.VehicleRoutingApp.main(VehicleRoutingApp.java:34)

如何让规划者首先在第一天使用所有车辆,然后在第二天使用车辆?

最佳答案

我认为您需要创建一个评分规则,奖励 OptaPlanner 按顺序安排日期。因此,在规则中,您可以说,如果第 X-1 天尚未满员,则对于第 X 天安排的每辆车扣一分。

关于java - 多日车辆路线 - 使用日指数较小的车辆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47628308/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com