当前位置: 首页 > 知识库问答 >
问题:

跟踪容量MultiTrip CVRPTW并在超过容量时返回仓库

孟自强
2023-03-14

在有时间窗的容量车辆路径问题(CVRPTW)中,我无法跟踪车辆的持续容量。

我试图让车辆在达到最大容量时返回仓库。

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

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

我将车辆等级修改如下:

@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; }

    }
}

我的可变监听器如下:

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);
            }
        }
    }
}

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

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

附言。还有其他与此相关的stackoverflow问题,我已经尝试过了,但没有用。为了完整起见:

  • 用Optaplanner求解VRPTWPD
  • Optaplanner:扩展vrp示例以处理多行程情况

也谢谢你花时间看这个,非常感谢任何回复的人。

共有1个答案

傅新
2023-03-14

我不能完全回答您的问题,但我确实发现您的侦听器实现中存在问题。线路

scoreDirector.beforeVariableChanged(shadowCustomer, "vehicle");
scoreDirector.afterVariableChanged(shadowCustomer, "vehicle");

必须围绕修改计划变量的任何行,例如:

 nextVehicle.setCurrentDemand(currentDemand);

我认为杰夫的建议是,如果你的容量达到0,你的车。getDistanceToPreviousStandstill函数将把到仓库的距离添加到计算中。(这只是我的猜测,我没有深入阅读杰夫的设计评论)。

 类似资料:
  • 我正在创建一个 Flume 代理的概念验证,该代理将缓冲事件,并在接收器不可用时停止使用源中的事件。仅当接收器再次可用时,才应处理缓冲的事件,然后源重新启动消耗。 为此,我创建了一个简单的代理,它从SpoolDir读取并写入文件。为了模拟接收器服务关闭,我更改了文件权限,以便Flume无法写入。然后我启动Flume,一些事件被缓冲在内存通道中,当通道容量已满时,它将停止消耗事件,正如预期的那样。一

  • 问题内容: adminCov继续返回null。当我运行SQL事件探查器时,可以看到生成的linq,将其粘贴到management Studio中时,可以得到预期的结果。 LinqToSql生成此代码: 当我执行时,我得到一个结果。我在这里想念什么?感谢您的帮助,〜ck在圣地亚哥 问题答案: 这确实是一个很好的问题。在日期范围内选择发票时,Linq to SQL遇到了相同的问题。其中一些未包含在生成

  • 问题内容: 我敢肯定有人在附近有一个可插拔的应用程序(或教程),但是我很难找到它:我希望能够跟踪特定对象的“视图”数量(就像这里的问题一样)在stackoverflow上有一个“视图计数”)。 如果用户未登录,则我不介意尝试放置cookie(或记录IP),以便他们不会因刷新页面而无意间增加视图计数;并且如果用户已登录,则仅允许他们跨会话/浏览器/ IP地址进行一个“查看”。我认为没有比这更理想的选

  • 问题内容: 我有一个带有变量StudentID的班级Student: 我希望变量StudentID继续分配给每个Student创建的新ID号。每个ID号都应比上一个创建的ID号大一个,并且应等于已创建的对象总数。现在,每个对象的ID号为1。 问题答案: 将studentID设为静态成员 静态成员将在整个类的每个实例中保留,无论有多少个clas实例。

  • 我一直在测试Laravel,我运行了以下查询: 数据库只包含1条记录,我var_dump$site,我得到的输出类似于下面,除了返回了近900,000个字符。 如果我保持查询简单,例如: 输出为: 对象(照亮\数据库\雄辩\收集)#121(1){[“项目”:受保护]= 这是相当少(1,600个字符),运行第一个查询时的性能很慢,我做了什么错事,因为我担心性能(为什么第一个查询这么慢)。 谢谢

  • 和我的CSS: