Optaplanner 车辆路线问题优化以使用最佳卡车

问题描述 投票:0回答:1

我正在尝试使用 Optaplanner 解决车辆路径问题。虽然代码运行正常,但我注意到一些奇怪的事情。

当我构建模型时,我有一个具有不同特征的车辆列表。车队是异构的并且由多种车辆类型组成。每种车辆类型可以有 1 辆或多辆车辆。车辆类别 A 可以是大型卡车,而车辆类别 B 可以是小型卡车(依此类推)。

虽然我能够在 Optaplanner 中正确建模车辆,但当我实际运行求解器时,我意识到车辆是根据它们在列表中的位置进行分配的。因此,如果我将所有车辆 A 放在开头,解算器将尝试先使用它们,然后再使用车辆 B,反之亦然。

这是我使用的模型示例(与我在 Github 中找到的非常相似):

@PlanningSolution
public class VehicleRoutingSolution {
    @ProblemFactCollectionProperty
    protected List<Location> locationList;

    @ProblemFactCollectionProperty
    protected List<Depot> depotList;

    @PlanningEntityCollectionProperty
    protected List<Vehicle> vehicleList;

    @ProblemFactCollectionProperty
    @ValueRangeProvider
    protected List<Customer> customerList;
    
    @PlanningScore
    protected HardSoftLongScore score;
}

@PlanningEntity
public class Vehicle {
    private int weight;
    private int volume;
    private float cost;

    @PlanningListVariable
    private List<Customer> customers = new ArrayList<>();
}
...

我的目标不仅是在不打破卡车约束(重量、体积)的情况下分配卡车内部的订单,更重要的是让求解器根据具体条件决定最好使用哪辆卡车,并最小化总体得分(成本、距离、时间) ),主要是因为路线距离也会根据车辆类型而变化。

有没有一种方法可以对域进行建模,以便我可以让 Optaplanner 选择最好的卡车,而不是根据它们在

PlanningEntityCollectionProperty
列表中的位置来使用它们?

optaplanner
1个回答
0
投票

OptaPlanner(和Timefold)对于分配一辆卡车或另一辆卡车没有任何偏好。 是的。您看到解算器在执行某些操作,但您不喜欢它。这告诉我你缺少一些限制。

他们通过编写约束来惩罚不需要的行为或奖励首选行为来指定您的偏好。每当您看到不喜欢的解决方案时,请思考您是否为求解器提供了足够的信息来避免该解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.