0

两辆车的单一工作时间表。一辆车在工作地点附近开始,另一辆车在远离工作地点的地方开始。似乎它应该更喜欢使用更近的车辆,因为每次距离都有成本。但它使用更远的一个,如果有一个非零setCostPerWaitingTime()。为什么?

public void testUseCloserVehicleWhenCostsAreSet() throws Exception {
    VehicleType type = VehicleTypeImpl.Builder.newInstance("generic")
            .setCostPerDistance(0.017753)
            //.setCostPerTransportTime(1.0)
            .setCostPerWaitingTime(1.0)
            .build();
    double serviceTime = 420.0;
    Location pointA = Location.newInstance(100.0, 100.0);
    Location pointB = Location.newInstance(100.0, 200.0);
    Location closeToPointA = Location.newInstance(110.0, 110.0);
    Location farFromPointA = Location.newInstance(500.0, 110.0);
    VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder
            .newInstance()
            .setFleetSize(VehicleRoutingProblem.FleetSize.FINITE)
            .addVehicle(VehicleImpl.Builder.newInstance("CloseBy")
                    .setType(type)
                    .setStartLocation(closeToPointA)
                    .build())
            .addVehicle(VehicleImpl.Builder.newInstance("FarAway")
                    .setType(type)
                    .setStartLocation(farFromPointA)
                    .build())
            .addJob(Shipment.Builder.newInstance("123")
                    .setPickupLocation(pointA)
                    .setPickupServiceTime(serviceTime)
                    .setDeliveryLocation(pointB)
                    .setDeliveryServiceTime(serviceTime)
                    .setPickupTimeWindow(new TimeWindow(36000.0, 36360.0))
                    .setDeliveryTimeWindow(new TimeWindow(36360.0, 36720.0))
                    .setMaxTimeInVehicle(720.0)
                    .build())
            .build();

    VehicleRoutingAlgorithm algorithm = Jsprit.Builder.newInstance(vrp)
            .buildAlgorithm();

    VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(algorithm.searchSolutions());
    SolutionPrinterWithTimes.print(vrp, bestSolution, SolutionPrinterWithTimes.Print.VERBOSE);
    System.out.flush();
    assertEquals("CloseBy", bestSolution.getRoutes().iterator().next().getVehicle().getId());
}

结果:

+----------------------------------------------------------+
| solution                                                 |
+---------------+------------------------------------------+
| indicator     | value                                    |
+---------------+------------------------------------------+
| costs         | 35616.03246830352                        | 
| noVehicles    | 1                                        | 
| unassgndJobs  | 0                                        | 
+----------------------------------------------------------+
+--------------------------------------------------------------------------------------------------------------------------------+
| detailed solution                                                                                                              |
+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+
| route   | vehicle              | activity              | job             | arrTime         | endTime         | costs           |
+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+
| 1       | FarAway              | start                 | -               | undef           | 0               | 0               |
| 1       | FarAway              | pickupShipment        | 123             | 400             | 36420           | 35607           |
| 1       | FarAway              | deliverShipment       | 123             | 36520           | 36940           | 35609           |
| 1       | FarAway              | end                   | -               | 37350           | undef           | 35616           |
+--------------------------------------------------------------------------------------------------------------------------------+
junit.framework.ComparisonFailure: 
Expected :CloseBy
Actual   :FarAway

我怀疑这与到达的车辆400有关,该工作要到36000. 有没有办法防止这种情况发生,所以车辆只在需要到达第一份工作时才启动?做setCostPerWaitingTime一些我想的以外的事情吗?

4

1 回答 1

0

CloseBy这是仅车辆的工作比较。

+--------------------------------------------------------------------------------------------------------------------------------+
| detailed solution                                                                                                              |
+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+
| route   | vehicle              | activity              | job             | arrTime         | endTime         | costs           |
+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+
| 1       | FarAway              | start                 | -               | undef           | 0               | 0               |
| 1       | FarAway              | pickupShipment        | 123             | 400             | 36420           | 35607           |
| 1       | FarAway              | deliverShipment       | 123             | 36520           | 36940           | 35609           |
| 1       | FarAway              | end                   | -               | 37350           | undef           | 35616           |
+--------------------------------------------------------------------------------------------------------------------------------+

+--------------------------------------------------------------------------------------------------------------------------------+
| detailed solution                                                                                                              |
+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+
| route   | vehicle              | activity              | job             | arrTime         | endTime         | costs           |
+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+
| 1       | CloseBy              | start                 | -               | undef           | 0               | 0               |
| 1       | CloseBy              | pickupShipment        | 123             | 14              | 36420           | 35986           |
| 1       | CloseBy              | deliverShipment       | 123             | 36520           | 36940           | 35988           |
| 1       | CloseBy              | end                   | -               | 37031           | undef           | 35989           |
+--------------------------------------------------------------------------------------------------------------------------------+

我认为问题在于 CloseBy 车辆更早到达,因此它支付更高的等待成本,而另一辆车在此期间正在行驶,因此等待成本更低。如果车辆在需要时才启动,这将得到缓解,但我不确定如何设置。

于 2019-09-04T15:17:34.507 回答