如何在JSprit中使用具有自己的成本矩阵的车辆类型

1 jsprit

是否可以为Jsprit中的每种车型定义单独的成本矩阵?我有许多非常不同的车型(卡车,自行车,汽车,电动皮卡等),每种类型都有自己的成本矩阵.矩阵不是线性相关的,因此不能选择使用不同的距离和时间成本因子.VRP具有无限的机队规模.

我使用JSprit 1.6.2并实现了AbstractForwardVehicleRoutingTransportCosts -Interface.它的两个方法都有一个车辆参数,我用它来选择正确的矩阵,但传递的值总是为null,随后抛出NullPointerException.任何想法为什么这种方法不起作用,以及我如何让它工作?

提前致谢!

小智 5

问题似乎与邮件列表中的帖子相似:Jsprit中依赖于车辆的速度.以下是Stefan在该帖子中的回答:

您需要实现自己的VehicleRoutingTransportCosts.在这里,您需要区分车辆类型.例如,如果您有两个旅行时间矩阵motorbikeMatrix和truckMatrix,那么您在实施中指定如果车辆是摩托车类型,则应使用motorbikeMatrix.

我想你已经有了那些与车型相关的成本矩阵,你的问题是在VehicleRoutingTransportCosts类中调用相应的成本矩阵.

就像是:

vrpBuilder.setRoutingCost(new MultiVehTypeCosts(vrpBuilder.getLocations(), motorbikeMatrix, truckMatrix, ...));
Run Code Online (Sandbox Code Playgroud)

然后在MultiVehTypeCosts类中

getTransportCost(Location from, Location to, double time, Driver driver, Vehicle vehicle) {}
Run Code Online (Sandbox Code Playgroud)

getTransportTime(Location from, Location to, double time, Driver driver, Vehicle vehicle) {}
Run Code Online (Sandbox Code Playgroud)

你有类似的东西:

    if (vehicle.getType().getTypeId().equals("motorbike")) {
        double time = motorbikeMatrix[from.getIndex()][to.getIndex()][1];
        double distance = motorbikeMatrix[from.getIndex()][to.getIndex()][0];
        VehicleTypeImpl.VehicleCostParams costParams = vehicle.getType().getVehicleCostParams();
        double cost = costParams.perDistanceUnit * distance + costParams.perTimeUnit * time;
        ....
    }
Run Code Online (Sandbox Code Playgroud)