[英]CustomChangeMove in chained planning entities throws IllegalStateException (Optaplanner)
[英]OptaPlanner: Make planning entities chained and nullable
尊敬的OptaPlanner社区
对于OptaPlanner框架的特定用例,我想使用车辆数据示例中使用的链式数据结构。 在我们的案例中,问题在于有很多客户,并且并非所有客户都能在特定的计划周期内得到服务。 因此,我认为使用可为空的计划变量可能会很有用,因此并非所有任务都需要分配,同时仍具有有效的供应商链。 我的问题是,我该如何解决这个问题? 有未分配任务的额外链条吗? 还有另一种方法可以规避此问题? 问候拉斐尔
我遇到了类似的问题,我需要允许某些客户跳过并尽量减少所用车辆的数量。 我使用“ Ghost”载具修改了标准的Optaplanner(7.12.0)VRP示例,如下所示:
@XStreamAlias("VrpGhostVehicle")
public class GhostVehicle extends Vehicle {
@Override
public Depot getDepot() {
return null;
}
@Override
public Long getId() {
return Long.valueOf(0);
}
@Override
public boolean isGhost() {
return true;
}
@Override
public int getCapacity() {
return Integer.MAX_VALUE;
}
}
为了对不能跳过的客户建模,我向Customer.java添加了“ unskipable”布尔字段。 然后,在您的vehicleRoutingScoreRules.drl中,我调整并添加了以下约束:
rule "vehicleCapacity"
when
$vehicle : Vehicle(ghost == false, $capacity : capacity)
accumulate(
Customer(
vehicle == $vehicle,
$demand : demand);
$demandTotal : sum($demand);
$demandTotal > $capacity
)
then
scoreHolder.addHardConstraintMatch(kcontext, $capacity - $demandTotal);
end
// ############################################################################
// Soft distance constraints
// ############################################################################
rule "distanceToPreviousStandstill"
when
$vehicle : Vehicle(ghost == false)
$customer : Customer(previousStandstill != null, vehicle == $vehicle, $distanceFromPreviousStandstill : distanceFromPreviousStandstill)
then
scoreHolder.addSoftConstraintMatch(kcontext, - $distanceFromPreviousStandstill);
end
rule "distanceFromLastCustomerToDepot"
when
$vehicle : Vehicle(ghost == false)
$customer : Customer(previousStandstill != null, vehicle == $vehicle)
not Customer(previousStandstill == $customer)
then
Vehicle vehicle = $customer.getVehicle();
scoreHolder.addSoftConstraintMatch(kcontext, - $customer.getDistanceTo(vehicle));
end
// ############################################################################
// Time window constraints
// ############################################################################
rule "arrivalAfterDueTime"
when
$vehicle : Vehicle(ghost == false)
TimeWindowedCustomer(dueTime < arrivalTime, vehicle == $vehicle, $dueTime : dueTime, $arrivalTime : arrivalTime)
then
scoreHolder.addSoftConstraintMatch(kcontext, -1000 * Math.abs($dueTime - $arrivalTime.longValue()));
end
rule "arrivalBeforeReadyTime"
when
$vehicle : Vehicle(ghost == false)
TimeWindowedCustomer(readyTime > arrivalTime, vehicle == $vehicle, $readyTime : readyTime, $arrivalTime : arrivalTime)
then
scoreHolder.addSoftConstraintMatch(kcontext, -1000 * Math.abs($readyTime - $arrivalTime.longValue()));
end
// ############################################################################
// Constraints pertaining to station skipping and vehicle usage
// ############################################################################
rule "skippedCustomer"
when
$vehicle : Vehicle(ghost == true)
$customer : Customer(vehicle == $vehicle, $unskippable : unskippable, $demand : demand)
then
if ($unskippable) {
scoreHolder.addHardConstraintMatch(kcontext, -10000 * $demand);
} else {
scoreHolder.addSoftConstraintMatch(kcontext, -10000 * $demand);
}
end
rule "usedTooManyVehicles"
when
$vehicle : Vehicle(nextCustomer != null, ghost == false)
then
scoreHolder.addSoftConstraintMatch(kcontext, -500000);
end
最下面的三个规则是我添加到示例中的约束,并且在仅适用于实际车辆的规则中添加了对ghost == false的进一步检查。 注意,对于不可跳过的客户,我们设置了硬约束,而对于可跳过的客户,我们设置了软约束。 跳过顾客或使用车辆的相对权重当然是特定于应用的。
链接的计划变量尚不支持nullable=true
(至少在7.8版中)。
无论如何,我都会应用连续的计划并开始计划接下来的几天-接下来几天的决定可能会影响第一天的决定(例如,假设您有100个数据包需要在第2天之前传送,但是在第二天,您有一半的司机正在休假,您没有足够的时间在第二天就把他们全部交付,因此您已经需要在第一天交付一些东西。
所以,我倒是创建VehicleDay
具有固定Vehicle
和Day
-我倒是用处处都是示例使用Vehicle
了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.