mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
remove redundant state stuff
This commit is contained in:
parent
415ce961d2
commit
7166ac2515
4 changed files with 37 additions and 85 deletions
|
|
@ -638,4 +638,5 @@ public class Jsprit {
|
|||
return solutionCostCalculator;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,33 +45,6 @@ import java.util.*;
|
|||
*/
|
||||
public class StateManager implements RouteAndActivityStateGetter, IterationStartsListener, RuinListener, InsertionStartsListener, JobInsertedListener, InsertionEndsListener {
|
||||
|
||||
static class States_ {
|
||||
|
||||
private Map<StateId, Object> states = new HashMap<StateId, Object>();
|
||||
|
||||
public <T> void putState(StateId id, Class<T> type, T state) {
|
||||
states.put(id, type.cast(state));
|
||||
}
|
||||
|
||||
public <T> T getState(StateId id, Class<T> type) {
|
||||
if (states.containsKey(id)) {
|
||||
return type.cast(states.get(id));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean containsKey(StateId stateId) {
|
||||
return states.containsKey(stateId);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
states.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private States_ problemStates_ = new States_();
|
||||
|
||||
private RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor();
|
||||
|
||||
private ReverseRouteActivityVisitor revRouteActivityVisitor = new ReverseRouteActivityVisitor();
|
||||
|
|
@ -98,6 +71,8 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
|||
|
||||
private int nuVehicleTypeKeys;
|
||||
|
||||
private Object[] problemStates;
|
||||
|
||||
private Object[][] activityStates;
|
||||
|
||||
private Object[][][] vehicleDependentActivityStates;
|
||||
|
|
@ -135,6 +110,7 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
|||
vehicleDependentActivityStates = new Object[nuActivities][nuVehicleTypeKeys][stateIndexCounter + 1];
|
||||
routeStatesArr = new Object[vrp.getNuActivities()+1][stateIndexCounter+1];
|
||||
vehicleDependentRouteStatesArr = new Object[nuActivities][nuVehicleTypeKeys][stateIndexCounter+1];
|
||||
problemStates = new Object[stateIndexCounter+1];
|
||||
}
|
||||
StateId id = StateFactory.createId(name, stateIndexCounter);
|
||||
incStateIndexCounter();
|
||||
|
|
@ -170,6 +146,7 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
|||
routeStateMap = new HashMap<VehicleRoute, Object[]>();
|
||||
vehicleDependentRouteStateMap = new HashMap<VehicleRoute, Object[][]>();
|
||||
}
|
||||
problemStates = new Object[initialStateArrayLength];
|
||||
}
|
||||
|
||||
private int getNuVehicleTypes(VehicleRoutingProblem vrp) {
|
||||
|
|
@ -190,7 +167,8 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
|||
* @param <T> the type of the state value
|
||||
*/
|
||||
public <T> void putProblemState(StateId stateId, Class<T> type, T state) {
|
||||
problemStates_.putState(stateId, type, state);
|
||||
problemStates[stateId.getIndex()] = state;
|
||||
// problemStates.putState(stateId, type, state);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -203,7 +181,7 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
|||
* @return the state value that is associated to the specified stateId or null if no value is associated
|
||||
*/
|
||||
public <T> T getProblemState(StateId stateId, Class<T> type) {
|
||||
return problemStates_.getState(stateId, type);
|
||||
return type.cast(problemStates[stateId.getIndex()]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -220,7 +198,7 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
|||
routeStateMap.clear();
|
||||
vehicleDependentRouteStateMap.clear();
|
||||
}
|
||||
problemStates_.clear();
|
||||
Arrays.fill(problemStates,null);
|
||||
}
|
||||
|
||||
private void fill_threeDimArr(Object[][][] states, Object o) {
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ public class StateManagerTest {
|
|||
@Test
|
||||
public void whenProblemStateIsSetAndStateManagerClearedAfterwards_itReturnsNull() {
|
||||
StateManager stateManager = new StateManager(vrpMock);
|
||||
StateId id = StateFactory.createId("problemState");
|
||||
StateId id = stateManager.createStateId("problemState");
|
||||
stateManager.putProblemState(id, Boolean.class, true);
|
||||
stateManager.clear();
|
||||
Boolean problemState = stateManager.getProblemState(id, Boolean.class);
|
||||
|
|
|
|||
|
|
@ -2,9 +2,24 @@
|
|||
<problem xmlns="http://www.w3schools.com"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd">
|
||||
<problemType>
|
||||
<fleetSize>INFINITE</fleetSize>
|
||||
<fleetSize>FINITE</fleetSize>
|
||||
</problemType>
|
||||
<vehicles>
|
||||
<vehicle>
|
||||
<id>v2</id>
|
||||
<typeId>vehType2</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>
|
||||
<vehicle>
|
||||
<id>v1</id>
|
||||
<typeId>vehType</typeId>
|
||||
|
|
@ -33,58 +48,16 @@
|
|||
<time>0.0</time>
|
||||
</costs>
|
||||
</type>
|
||||
<type>
|
||||
<id>vehType2</id>
|
||||
<capacity-dimensions>
|
||||
<dimension index="0">200</dimension>
|
||||
</capacity-dimensions>
|
||||
<costs>
|
||||
<fixed>0.0</fixed>
|
||||
<distance>1.0</distance>
|
||||
<time>0.0</time>
|
||||
</costs>
|
||||
</type>
|
||||
</vehicleTypes>
|
||||
<services>
|
||||
<service id="1" type="service">
|
||||
<location>
|
||||
<id>loc</id>
|
||||
</location>
|
||||
<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>
|
||||
<service id="2" type="service">
|
||||
<location>
|
||||
<id>loc2</id>
|
||||
</location>
|
||||
<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>
|
||||
</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>
|
||||
</problem>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue