首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >跟踪能力MultiTrip CVRPTW并在超过能力时返回仓库

跟踪能力MultiTrip CVRPTW并在超过能力时返回仓库
EN

Stack Overflow用户
提问于 2018-06-06 01:14:58
回答 1查看 260关注 0票数 0

在一个有时间窗的Capcity vehicle Routing Problem (CVRPTW)中,我在跟踪车辆的持续能力时遇到了问题。

当车辆达到最大载客量时,我正试图使车辆返回仓库。

根据我在这里得到的回应,https://groups.google.com/forum/#!topic/optaplanner-dev/IMG_7D1JvmQ,我目前正在尝试实现每天n次旅行的设计。

我尝试在车辆上使用阴影变量,并在其上使用变量侦听器。

我修改了vehicle类,如下所示:

代码语言:javascript
复制
@XStreamAlias("VrpVehicle")
    public class Vehicle extends AbstractPersistable implements Standstill {

        ...planning entities


        ...other shadow variables


        protected Integer currentDemand;


        @CustomShadowVariable(sources = {@PlanningVariableReference(variableName = "previousStandstill")})
        public Integer getCurrentDemand() { return currentDemand; }

    }
}

我的变量监听器如下:

代码语言:javascript
复制
public class VehicleCapacityReuseVariableListener implements VariableListener<Customer> {
    @Override
    public void afterEntityAdded(ScoreDirector scoreDirector,Customer customer)     {
        if (customer instanceof TimeWindowedCustomer) {
            updateVehicleDemandTotal(scoreDirector, (TimeWindowedCustomer) customer);
       }
    }

    @Override
    public void afterVariableChanged(ScoreDirector scoreDirector, Customer customer) {
        if (customer instanceof TimeWindowedCustomer) {
            updateVehicleDemandTotal(scoreDirector, (TimeWindowedCustomer) customer);
        }
    }

    ...

    protected void updateVehicleDemandTotal(ScoreDirector scoreDirector, Customer sourceCustomer) {
        Standstill previousStandstill = sourceCustomer.getPreviousStandstill();
        Vehicle vehicle = previousStandstill == null ? null : previousStandstill.getVehicle();
        TimeWindowedCustomer shadowCustomer = (TimeWindowedCustomer) sourceCustomer;
        Integer currentDemand = shadowCustomer.getDemand();

        Vehicle currentVehicle = shadowCustomer.getVehicle();
        Vehicle nextVehicle = currentVehicle;
        while (shadowCustomer != null) {
            scoreDirector.beforeVariableChanged(shadowCustomer, "vehicle");

            currentVehicle = shadowCustomer.getVehicle();

            scoreDirector.afterVariableChanged(shadowCustomer, "vehicle");

            shadowCustomer = shadowCustomer.getNextCustomer();
            if (shadowCustomer != null) {
                nextVehicle = shadowCustomer.getVehicle();
                if (!currentVehicle.equals(nextVehicle)){
                    nextVehicle.setCurrentDemand(currentDemand);
                    currentVehicle.setCurrentDemand(currentVehicle.getCurrentDemand() - currentDemand);
                    currentDemand = nextVehicle.getCurrentDemand();
                }
                currentDemand += shadowCustomer.getDemand();
                nextVehicle.setCurrentDemand(currentDemand);
            }
        }
    }
}

如果有人能帮我跟踪容量,那就太好了。

我认为解决方案(回到仓库)应该是将下一个客户设置为“仓库”客户。

PS。还有其他与此相关的堆栈溢出问题,我已经尝试过了,但都没有用。出于完整性考虑:

感谢你花时间来看这篇文章,也非常感谢任何回复的人。

EN

回答 1

Stack Overflow用户

发布于 2018-06-06 09:03:47

我不能完全回答您的问题,但我确实在您的侦听器实现中发现了一个问题。台词

代码语言:javascript
复制
scoreDirector.beforeVariableChanged(shadowCustomer, "vehicle");
scoreDirector.afterVariableChanged(shadowCustomer, "vehicle");

必须将修改计划变量的任何线括起来,例如:

代码语言:javascript
复制
 nextVehicle.setCurrentDemand(currentDemand);

我认为Geoff建议的是,如果您的容量达到0,您的vehicle.getDistanceToPreviousStandstill函数会将到站点的距离添加到计算中。(这只是我的猜测,我没有读太多关于Geoff的设计评论)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50705596

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档