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

时间:2016-04-26 08:47:06

标签: jsprit

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

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

提前致谢!

1 个答案:

答案 0 :(得分:5)

问题似乎与邮件列表中的帖子类似:Vehicle dependent velocities in Jsprit。以下是Stefan在该帖子中的回答:

  

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

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

类似的东西:

vrpBuilder.setRoutingCost(new MultiVehTypeCosts(vrpBuilder.getLocations(), motorbikeMatrix, truckMatrix, ...));

然后在MultiVehTypeCosts类的

getTransportCost(Location from, Location to, double time, Driver driver, Vehicle vehicle) {}

getTransportTime(Location from, Location to, double time, Driver driver, Vehicle vehicle) {}
你有类似的东西:

    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;
        ....
    }
相关问题