mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
added indeces to main elements
This commit is contained in:
parent
4f2689529f
commit
f9bad784ff
25 changed files with 334 additions and 203 deletions
|
|
@ -20,6 +20,7 @@ package jsprit.core.algorithm.recreate;
|
|||
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListeners;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.problem.AbstractActivity;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.constraint.ConstraintManager;
|
||||
import jsprit.core.problem.constraint.HardActivityStateLevelConstraint;
|
||||
|
|
@ -119,7 +120,7 @@ public class ServiceInsertionAndLoadConstraintsTest {
|
|||
route.setVehicleAndDepartureTime(vehicle, 0.0);
|
||||
|
||||
Inserter inserter = new Inserter(new InsertionListeners(), vehicleRoutingProblem);
|
||||
List<TourActivity> acts = new ArrayList<TourActivity>();
|
||||
List<AbstractActivity> acts = new ArrayList<AbstractActivity>();
|
||||
acts.add(new DeliverService(delivery));
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(delivery)).thenReturn(acts);
|
||||
inserter.insertJob(delivery, new InsertionData(0,0,0,vehicle,null), route);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ package jsprit.core.algorithm.recreate;
|
|||
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListeners;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.problem.AbstractActivity;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.constraint.*;
|
||||
import jsprit.core.problem.constraint.ConstraintManager.Priority;
|
||||
|
|
@ -131,8 +132,8 @@ public class ShipmentInsertionCalculatorTest {
|
|||
assertEquals(2,iData.getDeliveryInsertionIndex());
|
||||
}
|
||||
|
||||
private List<TourActivity> getTourActivities(Shipment shipment) {
|
||||
List<TourActivity> acts = new ArrayList<TourActivity>();
|
||||
private List<AbstractActivity> getTourActivities(Shipment shipment) {
|
||||
List<AbstractActivity> acts = new ArrayList<AbstractActivity>();
|
||||
PickupShipment pick = new PickupShipment(shipment);
|
||||
DeliverShipment del = new DeliverShipment(shipment);
|
||||
acts.add(pick);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ package jsprit.core.algorithm.recreate;
|
|||
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionListeners;
|
||||
import jsprit.core.algorithm.state.UpdateEndLocationIfRouteIsOpen;
|
||||
import jsprit.core.problem.AbstractActivity;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
|
|
@ -29,7 +30,6 @@ import jsprit.core.problem.solution.route.VehicleRoute;
|
|||
import jsprit.core.problem.solution.route.activity.DeliverShipment;
|
||||
import jsprit.core.problem.solution.route.activity.PickupService;
|
||||
import jsprit.core.problem.solution.route.activity.PickupShipment;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
|
|
@ -65,7 +65,7 @@ public class TestInserter {
|
|||
when(iData.getSelectedVehicle()).thenReturn(vehicle);
|
||||
|
||||
VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class);
|
||||
List<TourActivity> acts = new ArrayList<TourActivity>();
|
||||
List<AbstractActivity> acts = new ArrayList<AbstractActivity>();
|
||||
PickupService act = new PickupService(serviceToInsert);
|
||||
acts.add(act);
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(serviceToInsert)).thenReturn(acts);
|
||||
|
|
@ -105,8 +105,8 @@ public class TestInserter {
|
|||
assertEquals(route.getEnd().getLocationId(),serviceToInsert.getLocationId());
|
||||
}
|
||||
|
||||
private List<TourActivity> getTourActivities(Service serviceToInsert) {
|
||||
List<TourActivity> acts = new ArrayList<TourActivity>();
|
||||
private List<AbstractActivity> getTourActivities(Service serviceToInsert) {
|
||||
List<AbstractActivity> acts = new ArrayList<AbstractActivity>();
|
||||
acts.add(new PickupService(serviceToInsert));
|
||||
return acts;
|
||||
}
|
||||
|
|
@ -126,11 +126,7 @@ public class TestInserter {
|
|||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build();
|
||||
//start - pick(shipment) - del(shipment) - end
|
||||
Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setDeliveryLocation("delLoc").setPickupLocation("pickLoc").build();
|
||||
// Shipment shipmentToInsert = mock(Shipment.class);
|
||||
// when(shipmentToInsert.getSize()).thenReturn(capacity);
|
||||
// when(shipmentToInsert.getDeliveryLocation()).thenReturn("delLoc");
|
||||
// when(shipmentToInsert.getPickupLocation()).thenReturn("pickLoc");
|
||||
// when(shipmentToInsert.getSize()).thenReturn(Capacity.Builder.newInstance().build());
|
||||
|
||||
InsertionData iData = mock(InsertionData.class);
|
||||
when(iData.getPickupInsertionIndex()).thenReturn(2);
|
||||
when(iData.getDeliveryInsertionIndex()).thenReturn(2);
|
||||
|
|
@ -147,8 +143,8 @@ public class TestInserter {
|
|||
assertEquals(route.getEnd().getLocationId(),vehicle.getEndLocationId());
|
||||
}
|
||||
|
||||
private List<TourActivity> getTourActivities(Shipment shipmentToInsert) {
|
||||
List<TourActivity> acts = new ArrayList<TourActivity>();
|
||||
private List<AbstractActivity> getTourActivities(Shipment shipmentToInsert) {
|
||||
List<AbstractActivity> acts = new ArrayList<AbstractActivity>();
|
||||
acts.add(new PickupShipment(shipmentToInsert));
|
||||
acts.add(new DeliverShipment(shipmentToInsert));
|
||||
return acts;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
package jsprit.core.algorithm.state;
|
||||
|
||||
import jsprit.core.problem.AbstractActivity;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.JobActivityFactory;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.job.*;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
|
|
@ -12,13 +15,14 @@ import org.junit.Test;
|
|||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 13.07.14.
|
||||
* Unit tests to test correct calc of load states
|
||||
*/
|
||||
public class LoadStateTest {
|
||||
|
||||
|
|
@ -37,10 +41,11 @@ public class LoadStateTest {
|
|||
when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0,20).build());
|
||||
when(vehicle.getType()).thenReturn(type);
|
||||
|
||||
Service s1 = mock(Service.class);
|
||||
when(s1.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0,10).build());
|
||||
Service s2 = mock(Service.class);
|
||||
when(s2.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0,5).build());
|
||||
VehicleRoutingProblem.Builder serviceProblemBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
Service s1 = Service.Builder.newInstance("s").addSizeDimension(0,10).setLocationId("loc").build();
|
||||
Service s2 = Service.Builder.newInstance("s2").addSizeDimension(0,5).setLocationId("loc").build();
|
||||
serviceProblemBuilder.addJob(s1).addJob(s2);
|
||||
final VehicleRoutingProblem serviceProblem = serviceProblemBuilder.build();
|
||||
|
||||
Pickup pickup = mock(Pickup.class);
|
||||
when(pickup.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10).build());
|
||||
|
|
@ -52,16 +57,27 @@ public class LoadStateTest {
|
|||
Shipment shipment2 = mock(Shipment.class);
|
||||
when(shipment2.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 5).build());
|
||||
|
||||
serviceRoute = VehicleRoute.Builder.newInstance(vehicle).addService(s1).addService(s2).build();
|
||||
VehicleRoute.Builder serviceRouteBuilder = VehicleRoute.Builder.newInstance(vehicle);
|
||||
serviceRouteBuilder.setJobActivityFactory(new JobActivityFactory() {
|
||||
|
||||
@Override
|
||||
public List<AbstractActivity> createActivity(Job job) {
|
||||
return serviceProblem.copyAndGetActivities(job);
|
||||
}
|
||||
|
||||
});
|
||||
serviceRoute = serviceRouteBuilder.addService(s1).addService(s2).build();
|
||||
pickup_delivery_route = VehicleRoute.Builder.newInstance(vehicle).addService(pickup).addService(delivery).build();
|
||||
shipment_route = VehicleRoute.Builder.newInstance(vehicle).addPickup(shipment1).addPickup(shipment2).addDelivery(shipment2).addDelivery(shipment1).build();
|
||||
|
||||
stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
stateManager.updateLoadStates();
|
||||
stateManager.informInsertionStarts(Arrays.asList(serviceRoute,pickup_delivery_route,shipment_route), Collections.<Job>emptyList());
|
||||
stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.<Job>emptyList());
|
||||
// <stateManager.informInsertionStarts(Arrays.asList(serviceRoute,pickup_delivery_route,shipment_route), Collections.<Job>emptyList());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void loadAtEndShouldBe15(){
|
||||
Capacity routeState = stateManager.getRouteState(serviceRoute, StateFactory.LOAD_AT_END, Capacity.class);
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.algorithm.state;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
|
|
@ -27,9 +25,11 @@ import jsprit.core.problem.solution.route.activity.TourActivity;
|
|||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory.State;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory.StateId;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class StateManagerTest {
|
||||
|
||||
@Test
|
||||
|
|
@ -145,4 +145,29 @@ public class StateManagerTest {
|
|||
boolean problemState = stateManager.getProblemState(id, Boolean.class);
|
||||
assertFalse(problemState);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreatingNewState_itShouldHaveAnIndex(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
StateId stateId = stateManager.createStateId("foo-state");
|
||||
assertEquals(10,stateId.getIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreatingNewStates_theyShouldHaveAnIndex(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
StateId fooState = stateManager.createStateId("foo-state");
|
||||
StateId foofooState = stateManager.createStateId("foo-foo-state");
|
||||
assertEquals(10,fooState.getIndex());
|
||||
assertEquals(11,foofooState.getIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreatingTwoStatesWithTheSameName_theyShouldHaveTheSameIndex(){
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingTransportCosts.class));
|
||||
StateId fooState = stateManager.createStateId("foo-state");
|
||||
StateId foofooState = stateManager.createStateId("foo-state");
|
||||
assertEquals(10,fooState.getIndex());
|
||||
assertEquals(10,foofooState.getIndex());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue