1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

switch to Location

This commit is contained in:
oblonski 2014-12-17 16:20:29 +01:00
parent e33590b380
commit 7e39d08e3d
23 changed files with 390 additions and 271 deletions

View file

@ -1,38 +1,35 @@
/*******************************************************************************
* Copyright (c) 2014 Stefan Schroeder.
*
* Copyright (C) 2014 Stefan Schroeder
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package jsprit.core.algorithm.recreate;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import jsprit.core.problem.cost.VehicleRoutingActivityCosts;
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
import jsprit.core.problem.solution.route.activity.End;
import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.problem.vehicle.Vehicle;
import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class TestAuxilliaryCostCalculator {
private VehicleRoutingTransportCosts routingCosts;
@ -76,7 +73,7 @@ public class TestAuxilliaryCostCalculator {
public void whenRouteIsClosed_itCalculatesCostUpToEnd_v2(){
TourActivity prevAct = mock(TourActivity.class);
when(prevAct.getLocationId()).thenReturn("i");
End nextAct = End.newInstance("j", 0.0, 0.0);
End nextAct = new End("j", 0.0, 0.0);
TourActivity newAct = mock(TourActivity.class);
when(newAct.getLocationId()).thenReturn("k");

View file

@ -95,6 +95,8 @@ public class VrpXMLReaderTest {
assertEquals("depotLoc2",v1.getStartLocationId());
assertNotNull(v1.getType());
assertEquals("vehType", v1.getType().getTypeId());
assertNotNull(v1.getStartLocation());
assertEquals(1,v1.getStartLocation().getIndex());
assertEquals(1000.0,v1.getLatestArrival(),0.01);
}
@ -320,6 +322,8 @@ public class VrpXMLReaderTest {
VehicleRoutingProblem vrp = builder.build();
Vehicle v3 = getVehicle("v3",vrp.getVehicles());
assertEquals("startLoc",v3.getStartLocationId());
assertNotNull(v3.getEndLocation());
assertEquals(4,v3.getEndLocation().getIndex());
}
@Test

View file

@ -16,6 +16,7 @@
******************************************************************************/
package jsprit.core.problem.io;
import jsprit.core.problem.Location;
import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.VehicleRoutingProblem.Builder;
import jsprit.core.problem.VehicleRoutingProblem.FleetSize;
@ -138,7 +139,10 @@ public class VrpXMLWriterTest {
@Test
public void shouldWriteNameOfShipment(){
Builder builder = VehicleRoutingProblem.Builder.newInstance();
Shipment s1 = Shipment.Builder.newInstance("1").setName("cleaning").setPickupLocationId("pick").setDeliveryLocationId("del").build();
Location pickLocation = Location.Builder.newInstance().setId("pick").setIndex(1).build();
Shipment s1 = Shipment.Builder.newInstance("1").setName("cleaning")
.setPickupLocation(pickLocation)
.setDeliveryLocationId("del").build();
VehicleRoutingProblem vrp = builder.addJob(s1).build();
new VrpXMLWriter(vrp, null).write(infileName);

View file

@ -20,6 +20,7 @@ import jsprit.core.problem.Capacity;
import jsprit.core.problem.driver.Driver;
import jsprit.core.problem.job.Shipment;
import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.problem.vehicle.VehicleImpl;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@ -93,10 +94,9 @@ public class VehicleRouteBuilderTest {
Capacity capacity = Capacity.Builder.newInstance().build();
when(s.getSize()).thenReturn(capacity);
when(s2.getSize()).thenReturn(capacity);
Vehicle vehicle = mock(Vehicle.class);
when(vehicle.isReturnToDepot()).thenReturn(true);
when(vehicle.getStartLocationId()).thenReturn("vehLoc");
when(vehicle.getEndLocationId()).thenReturn("vehLoc");
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("vehLoc").setEndLocationId("vehLoc")
.build();
VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class));
builder.addPickup(s);
builder.addPickup(s2);

View file

@ -31,6 +31,7 @@
<location>
<id>depotLoc2</id>
<coord x="100.0" y="100.0"/>
<index>1</index>
</location>
<typeId>vehType</typeId>
<timeSchedule>
@ -44,6 +45,7 @@
<location>
<id>depotLoc</id>
<coord x="10.0" y="100.0"/>
<index>2</index>
</location>
<returnToDepot>false</returnToDepot>
<typeId>vehType2</typeId>
@ -57,10 +59,12 @@
<startLocation>
<id>startLoc</id>
<coord x="10.0" y="100.0"/>
<index>3</index>
</startLocation>
<endLocation>
<id>endLoc</id>
<coord x="1000.0" y="2000.0"/>
<index>4</index>
</endLocation>
<typeId>vehType2</typeId>
<timeSchedule>

View file

@ -155,8 +155,10 @@
</vehicleTypes>
<services>
<service id="2" type="service">
<locationId>i(3,9)</locationId>
<coord x="10.0" y="10.0"/>
<location>
<id>i(3,9)</id>
<coord x="10.0" y="10.0"/>
</location>
<capacity-dimensions>
<dimension index="0">1</dimension>
</capacity-dimensions>
@ -169,8 +171,10 @@
</timeWindows>
</service>
<service id="1" type="service">
<locationId>j(1,5)</locationId>
<coord x="10.0" y="10.0"/>
<location>
<id>j(1,5)</id>
<coord x="10.0" y="10.0"/>
</location>
<capacity-dimensions>
<dimension index="0">1</dimension>
</capacity-dimensions>
@ -186,8 +190,10 @@
<shipments>
<shipment id="3">
<pickup>
<locationId>i(3,9)</locationId>
<coord x="10.0" y="10.0"/>
<location>
<id>i(3,9)</id>
<coord x="10.0" y="10.0"/>
</location>
<duration>10.0</duration>
<timeWindows>
<timeWindow>
@ -197,8 +203,10 @@
</timeWindows>
</pickup>
<delivery>
<locationId>i(9,9)</locationId>
<coord x="10.0" y="0.0"/>
<location>
<id>i(9,9)</id>
<coord x="10.0" y="0.0"/>
</location>
<duration>100.0</duration>
<timeWindows>
<timeWindow>
@ -213,8 +221,10 @@
</shipment>
<shipment id="4">
<pickup>
<locationId>[x=10.0][y=10.0]</locationId>
<coord x="10.0" y="10.0"/>
<location>
<id>[x=10.0][y=10.0]</id>
<coord x="10.0" y="10.0"/>
</location>
<duration>0.0</duration>
<timeWindows>
<timeWindow>
@ -224,8 +234,10 @@
</timeWindows>
</pickup>
<delivery>
<locationId>[x=10.0][y=0.0]</locationId>
<coord x="10.0" y="0.0"/>
<location>
<id>[x=10.0][y=0.0]</id>
<coord x="10.0" y="0.0"/>
</location>
<duration>100.0</duration>
<timeWindows>
<timeWindow>

View file

@ -21,83 +21,37 @@
<problemType>
<fleetSize>INFINITE</fleetSize>
</problemType>
<vehicles>
<vehicle>
<id>v1</id>
<typeId>vehType</typeId>
<startLocation>
<id>loc</id>
</startLocation>
<endLocation>
<id>loc</id>
</endLocation>
<timeSchedule>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeSchedule>
<returnToDepot>true</returnToDepot>
</vehicle>
</vehicles>
<vehicleTypes>
<type>
<id>vehType</id>
<shipments>
<shipment id="1">
<pickup>
<location>
<id>pick</id>
<index>1</index>
</location>
<duration>0.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeWindow>
</timeWindows>
</pickup>
<delivery>
<location>
<id>del</id>
</location>
<duration>0.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeWindow>
</timeWindows>
</delivery>
<capacity-dimensions>
<dimension index="0">20</dimension>
<dimension index="0">0</dimension>
</capacity-dimensions>
<costs>
<fixed>0.0</fixed>
<distance>1.0</distance>
<time>0.0</time>
</costs>
</type>
</vehicleTypes>
<services>
<service id="2" type="service">
<locationId>loc2</locationId>
<capacity-dimensions>
<dimension index="0">1</dimension>
</capacity-dimensions>
<duration>4.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeWindow>
</timeWindows>
</service>
<service id="1" type="service">
<locationId>loc</locationId>
<capacity-dimensions>
<dimension index="0">1</dimension>
</capacity-dimensions>
<duration>2.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeWindow>
</timeWindows>
</service>
</services>
<solutions>
<solution>
<cost>10.0</cost>
<routes>
<route>
<driverId>noDriver</driverId>
<vehicleId>v1</vehicleId>
<start>0.0</start>
<act type="service">
<serviceId>1</serviceId>
<arrTime>0.0</arrTime>
<endTime>0.0</endTime>
</act>
<end>0.0</end>
</route>
</routes>
<unassignedJobs>
<job id="2"/>
</unassignedJobs>
</solution>
</solutions>
<name>cleaning</name>
</shipment>
</shipments>
</problem>