How to use vehicle types with own cost matrix in JSprit

若如初见. 提交于 2021-01-28 18:15:33

问题


Is it possible to define a seperate cost matrix for every vehicle type in Jsprit? I have a number of very different vehicle types (trucks, bikes, cars, electrical pickups etc.) and every type has its own cost matrix. The matrices are not linearly dependent, therefore working with different cost factors for distance and time is not an option. The VRP has infinite fleet size.

I use JSprit 1.6.2 and implemented the AbstractForwardVehicleRoutingTransportCosts-Interface. Both of its methods have a vehicle parameter that I use to select the correct matrix, but the passed values are always null and subsequently a NullPointerException is thrown. Any ideas why this approach is not working and how I can get it to work?

Thanks in advance!


回答1:


The problem seems similar to a post in the mailing list: Vehicle dependent velocities in Jsprit. Below is Stefan's answer in that post:

You need to implement your own VehicleRoutingTransportCosts. Here you need to differentiate between vehicle types. For example, if you have two travel time matrices motorbikeMatrix and truckMatrix, then you specify in your implementation that motorbikeMatrix should be used if vehicle is of type motorbike.

I suppose you already have those vehicle-type-dependent cost matrices, and your problem would be to call corresponding cost matrix in the VehicleRoutingTransportCosts class.

Something like:

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

Then in the MultiVehTypeCosts class, in

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

and

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

you have something like:

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


来源:https://stackoverflow.com/questions/36859783/how-to-use-vehicle-types-with-own-cost-matrix-in-jsprit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!