mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
moved StateFactory from core.problem.solution.route.state to core.algorithm.state.InternalStates
moved StateId from core.problem.solution.route.state.StateFactory to core.algorithm.state made core.problem.solution.route.state.StateFactory.createId(...) inaccessible
This commit is contained in:
parent
11300b90d3
commit
aec4e307de
37 changed files with 306 additions and 320 deletions
|
|
@ -18,11 +18,11 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.algorithm;
|
||||
|
||||
import jsprit.core.algorithm.state.InternalStates;
|
||||
import jsprit.core.problem.solution.SolutionCostCalculator;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
|
||||
/**
|
||||
* Default objective function which is the sum of all fixed vehicle and variable
|
||||
|
|
@ -48,7 +48,7 @@ public class VariablePlusFixedSolutionCostCalculatorFactory {
|
|||
public double getCosts(VehicleRoutingProblemSolution solution) {
|
||||
double c = 0.0;
|
||||
for(VehicleRoute r : solution.getRoutes()){
|
||||
c += stateManager.getRouteState(r, StateFactory.COSTS,Double.class);
|
||||
c += stateManager.getRouteState(r, InternalStates.COSTS,Double.class);
|
||||
c += r.getVehicle().getType().getVehicleCostParams().fix;
|
||||
}
|
||||
return c;
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ import jsprit.core.problem.solution.route.VehicleRoute;
|
|||
import jsprit.core.problem.solution.route.activity.End;
|
||||
import jsprit.core.problem.solution.route.activity.ReverseActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.vehicle.FiniteFleetManagerFactory;
|
||||
import jsprit.core.problem.vehicle.InfiniteFleetManagerFactory;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
|
@ -619,7 +618,7 @@ public class VehicleRoutingAlgorithms {
|
|||
public double getCosts(VehicleRoutingProblemSolution solution) {
|
||||
double costs = 0.0;
|
||||
for(VehicleRoute route : solution.getRoutes()){
|
||||
costs += stateManager.getRouteState(route, StateFactory.COSTS, Double.class) + getFixedCosts(route.getVehicle());
|
||||
costs += stateManager.getRouteState(route, InternalStates.COSTS, Double.class) + getFixedCosts(route.getVehicle());
|
||||
}
|
||||
return costs;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import jsprit.core.algorithm.recreate.InsertionData.NoInsertionFound;
|
||||
import jsprit.core.algorithm.state.InternalStates;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.constraint.SoftRouteConstraint;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
|
|
@ -24,7 +25,6 @@ import jsprit.core.problem.job.Job;
|
|||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
|
@ -122,7 +122,7 @@ final class JobInsertionConsideringFixCostsCalculator implements JobInsertionCos
|
|||
}
|
||||
|
||||
private Capacity getCurrentMaxLoadInRoute(VehicleRoute route) {
|
||||
Capacity maxLoad = stateGetter.getRouteState(route, StateFactory.MAXLOAD, Capacity.class);
|
||||
Capacity maxLoad = stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class);
|
||||
if(maxLoad == null) maxLoad = Capacity.Builder.newInstance().build();
|
||||
return maxLoad;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import jsprit.core.algorithm.state.InternalStates;
|
||||
import jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
|
|
@ -28,7 +29,6 @@ import jsprit.core.problem.solution.route.activity.End;
|
|||
import jsprit.core.problem.solution.route.activity.Start;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -70,10 +70,10 @@ class RouteLevelActivityInsertionCostsEstimator implements ActivityInsertionCost
|
|||
private double actCostsOld(VehicleRoute vehicleRoute, TourActivity act) {
|
||||
Double cost_at_act;
|
||||
if(act instanceof End){
|
||||
cost_at_act = stateManager.getRouteState(vehicleRoute, StateFactory.COSTS, Double.class);
|
||||
cost_at_act = stateManager.getRouteState(vehicleRoute, InternalStates.COSTS, Double.class);
|
||||
}
|
||||
else{
|
||||
cost_at_act = stateManager.getActivityState(act, StateFactory.COSTS, Double.class);
|
||||
cost_at_act = stateManager.getActivityState(act, InternalStates.COSTS, Double.class);
|
||||
}
|
||||
if(cost_at_act == null) cost_at_act = 0.;
|
||||
return cost_at_act;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import jsprit.core.algorithm.state.InternalStates;
|
||||
import jsprit.core.problem.JobActivityFactory;
|
||||
import jsprit.core.problem.constraint.HardActivityStateLevelConstraint;
|
||||
import jsprit.core.problem.constraint.HardActivityStateLevelConstraint.ConstraintsStatus;
|
||||
|
|
@ -32,7 +33,6 @@ import jsprit.core.problem.solution.route.activity.Start;
|
|||
import jsprit.core.problem.solution.route.activity.TourActivities;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
|
@ -266,7 +266,7 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC
|
|||
/**
|
||||
* compute cost-diff of tour with and without new activity --> insertion_costs
|
||||
*/
|
||||
Double currentRouteCosts = stateManager.getRouteState(currentRoute, StateFactory.COSTS, Double.class);
|
||||
Double currentRouteCosts = stateManager.getRouteState(currentRoute, InternalStates.COSTS, Double.class);
|
||||
if(currentRouteCosts == null) currentRouteCosts = 0.;
|
||||
double insertion_costs = auxilliaryPathCostCalculator.costOfPath(wholeTour, start.getEndTime(), newDriver, newVehicle) - currentRouteCosts;
|
||||
|
||||
|
|
@ -316,9 +316,9 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC
|
|||
private double sumOf_prevCosts_oldVehicle(VehicleRoute vehicleRoute, TourActivity act) {
|
||||
Double prevCost;
|
||||
if(act instanceof End){
|
||||
prevCost = stateManager.getRouteState(vehicleRoute,StateFactory.COSTS,Double.class);
|
||||
prevCost = stateManager.getRouteState(vehicleRoute, InternalStates.COSTS,Double.class);
|
||||
}
|
||||
else prevCost = stateManager.getActivityState(act,StateFactory.COSTS,Double.class);
|
||||
else prevCost = stateManager.getActivityState(act, InternalStates.COSTS,Double.class);
|
||||
if(prevCost == null) prevCost = 0.;
|
||||
return prevCost;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributors:
|
||||
* Stefan Schroeder - initial API and implementation
|
||||
******************************************************************************/
|
||||
package jsprit.core.algorithm.state;
|
||||
|
||||
public class InternalStates {
|
||||
|
||||
|
||||
public final static StateId MAXLOAD = new StateFactory.StateIdImpl("max_load", 0);
|
||||
|
||||
public final static StateId LOAD = new StateFactory.StateIdImpl("load", 1);
|
||||
|
||||
public final static StateId COSTS = new StateFactory.StateIdImpl("costs", 2);
|
||||
|
||||
public final static StateId LOAD_AT_BEGINNING = new StateFactory.StateIdImpl("load_at_beginning", 3);
|
||||
|
||||
public final static StateId LOAD_AT_END = new StateFactory.StateIdImpl("load_at_end", 4);
|
||||
|
||||
public final static StateId DURATION = new StateFactory.StateIdImpl("duration", 5);
|
||||
|
||||
public final static StateId LATEST_OPERATION_START_TIME = new StateFactory.StateIdImpl("latest_operation_start_time", 6);
|
||||
|
||||
public final static StateId EARLIEST_OPERATION_START_TIME = new StateFactory.StateIdImpl("earliest_operation_start_time", 7);
|
||||
|
||||
public final static StateId FUTURE_MAXLOAD = new StateFactory.StateIdImpl("future_max_load", 8);
|
||||
|
||||
public final static StateId PAST_MAXLOAD = new StateFactory.StateIdImpl("past_max_load", 9);
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
package jsprit.core.algorithm.state;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 28.07.14.
|
||||
*/
|
||||
class StateFactory {
|
||||
|
||||
final static List<String> reservedIds = Arrays.asList("max_load", "load", "costs", "load_at_beginning", "load_at_end", "duration", "latest_operation_start_time", "earliest_operation_start_time"
|
||||
, "future_max_load", "past_max_load");
|
||||
|
||||
|
||||
static StateId createId(String name){
|
||||
if(reservedIds.contains(name)){ throwReservedIdException(name); }
|
||||
return new StateIdImpl(name, -1);
|
||||
}
|
||||
|
||||
static StateId createId(String name, int index){
|
||||
if(reservedIds.contains(name)) throwReservedIdException(name);
|
||||
if(index < 10) throwReservedIdException(name);
|
||||
return new StateIdImpl(name, index);
|
||||
}
|
||||
|
||||
|
||||
static boolean isReservedId(String stateId){
|
||||
return reservedIds.contains(stateId);
|
||||
}
|
||||
|
||||
static boolean isReservedId(StateId stateId){
|
||||
return reservedIds.contains(stateId.toString());
|
||||
}
|
||||
|
||||
static void throwReservedIdException(String name) {
|
||||
throw new IllegalStateException("state-id with name '" + name + "' cannot be created. it is already reserved internally.");
|
||||
}
|
||||
|
||||
|
||||
static class StateIdImpl implements StateId {
|
||||
|
||||
private int index;
|
||||
|
||||
public int getIndex(){ return index; }
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
StateIdImpl other = (StateIdImpl) obj;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private String name;
|
||||
|
||||
public StateIdImpl(String name, int index) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package jsprit.core.algorithm.state;
|
||||
|
||||
import jsprit.core.problem.HasIndex;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 28.07.14.
|
||||
*/
|
||||
public interface StateId extends HasIndex {
|
||||
|
||||
}
|
||||
|
|
@ -33,8 +33,6 @@ import jsprit.core.problem.solution.route.activity.ActivityVisitor;
|
|||
import jsprit.core.problem.solution.route.activity.ReverseActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory.StateId;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
import java.util.*;
|
||||
|
|
@ -141,7 +139,7 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
|||
vehicle_dependent_activity_states = new Object[nuActivities][nuVehicleTypeKeys][stateIndexCounter+1];
|
||||
vehicle_dependent_route_states = new Object[nuActivities][nuVehicleTypeKeys][stateIndexCounter+1];
|
||||
}
|
||||
StateId id = StateFactory.createId(name,stateIndexCounter);
|
||||
StateId id = StateFactory.createId(name, stateIndexCounter);
|
||||
incStateIndexCounter();
|
||||
createdStateIds.put(name, id);
|
||||
return id;
|
||||
|
|
@ -152,23 +150,23 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
|||
}
|
||||
|
||||
private void addDefaultStates() {
|
||||
defaultActivityStates_.put(StateFactory.LOAD, Capacity.Builder.newInstance().build());
|
||||
defaultActivityStates_.put(StateFactory.COSTS, 0.);
|
||||
defaultActivityStates_.put(StateFactory.DURATION, 0.);
|
||||
defaultActivityStates_.put(StateFactory.FUTURE_MAXLOAD, Capacity.Builder.newInstance().build());
|
||||
defaultActivityStates_.put(StateFactory.PAST_MAXLOAD, Capacity.Builder.newInstance().build());
|
||||
defaultActivityStates_.put(InternalStates.LOAD, Capacity.Builder.newInstance().build());
|
||||
defaultActivityStates_.put(InternalStates.COSTS, 0.);
|
||||
defaultActivityStates_.put(InternalStates.DURATION, 0.);
|
||||
defaultActivityStates_.put(InternalStates.FUTURE_MAXLOAD, Capacity.Builder.newInstance().build());
|
||||
defaultActivityStates_.put(InternalStates.PAST_MAXLOAD, Capacity.Builder.newInstance().build());
|
||||
|
||||
defaultRouteStates_.put(StateFactory.LOAD, Capacity.Builder.newInstance().build());
|
||||
defaultRouteStates_.put(InternalStates.LOAD, Capacity.Builder.newInstance().build());
|
||||
|
||||
defaultRouteStates_.put(StateFactory.COSTS, 0.);
|
||||
defaultRouteStates_.put(StateFactory.DURATION, 0.);
|
||||
defaultRouteStates_.put(StateFactory.FUTURE_MAXLOAD, Capacity.Builder.newInstance().build());
|
||||
defaultRouteStates_.put(StateFactory.PAST_MAXLOAD, Capacity.Builder.newInstance().build());
|
||||
defaultRouteStates_.put(InternalStates.COSTS, 0.);
|
||||
defaultRouteStates_.put(InternalStates.DURATION, 0.);
|
||||
defaultRouteStates_.put(InternalStates.FUTURE_MAXLOAD, Capacity.Builder.newInstance().build());
|
||||
defaultRouteStates_.put(InternalStates.PAST_MAXLOAD, Capacity.Builder.newInstance().build());
|
||||
|
||||
defaultRouteStates_.put(StateFactory.MAXLOAD, Capacity.Builder.newInstance().build());
|
||||
defaultRouteStates_.put(InternalStates.MAXLOAD, Capacity.Builder.newInstance().build());
|
||||
|
||||
defaultRouteStates_.put(StateFactory.LOAD_AT_END, Capacity.Builder.newInstance().build());
|
||||
defaultRouteStates_.put(StateFactory.LOAD_AT_BEGINNING, Capacity.Builder.newInstance().build());
|
||||
defaultRouteStates_.put(InternalStates.LOAD_AT_END, Capacity.Builder.newInstance().build());
|
||||
defaultRouteStates_.put(InternalStates.LOAD_AT_BEGINNING, Capacity.Builder.newInstance().build());
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -346,10 +344,10 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
|
|||
if(defaultActivityStates_.containsKey(stateId)){
|
||||
return type.cast(defaultActivityStates_.get(stateId));
|
||||
}
|
||||
if(stateId.equals(StateFactory.EARLIEST_OPERATION_START_TIME)){
|
||||
if(stateId.equals(InternalStates.EARLIEST_OPERATION_START_TIME)){
|
||||
return type.cast(act.getTheoreticalEarliestOperationStartTime());
|
||||
}
|
||||
if(stateId.equals(StateFactory.LATEST_OPERATION_START_TIME)){
|
||||
if(stateId.equals(InternalStates.LATEST_OPERATION_START_TIME)){
|
||||
return type.cast(act.getTheoreticalLatestOperationStartTime());
|
||||
}
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import jsprit.core.problem.job.Service;
|
|||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.ActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
|
|
@ -65,7 +64,7 @@ class UpdateLoads implements ActivityVisitor, StateUpdater, InsertionStartsListe
|
|||
|
||||
@Override
|
||||
public void begin(VehicleRoute route) {
|
||||
currentLoad = stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class);
|
||||
currentLoad = stateManager.getRouteState(route, InternalStates.LOAD_AT_BEGINNING, Capacity.class);
|
||||
if(currentLoad == null) currentLoad = defaultValue;
|
||||
this.route = route;
|
||||
}
|
||||
|
|
@ -73,7 +72,7 @@ class UpdateLoads implements ActivityVisitor, StateUpdater, InsertionStartsListe
|
|||
@Override
|
||||
public void visit(TourActivity act) {
|
||||
currentLoad = Capacity.addup(currentLoad, act.getSize());
|
||||
stateManager.putInternalTypedActivityState(act, StateFactory.LOAD, currentLoad);
|
||||
stateManager.putInternalTypedActivityState(act, InternalStates.LOAD, currentLoad);
|
||||
assert currentLoad.isLessOrEqual(route.getVehicle().getType().getCapacityDimensions()) : "currentLoad at activity must not be > vehicleCapacity";
|
||||
assert currentLoad.isGreaterOrEqual(Capacity.Builder.newInstance().build()) : "currentLoad at act must not be < 0 in one of the applied dimensions";
|
||||
}
|
||||
|
|
@ -94,8 +93,8 @@ class UpdateLoads implements ActivityVisitor, StateUpdater, InsertionStartsListe
|
|||
loadAtEnd = Capacity.addup(loadAtEnd, j.getSize());
|
||||
}
|
||||
}
|
||||
stateManager.putTypedInternalRouteState(route, StateFactory.LOAD_AT_BEGINNING, loadAtDepot);
|
||||
stateManager.putTypedInternalRouteState(route, StateFactory.LOAD_AT_END, loadAtEnd);
|
||||
stateManager.putTypedInternalRouteState(route, InternalStates.LOAD_AT_BEGINNING, loadAtDepot);
|
||||
stateManager.putTypedInternalRouteState(route, InternalStates.LOAD_AT_END, loadAtEnd);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -106,14 +105,14 @@ class UpdateLoads implements ActivityVisitor, StateUpdater, InsertionStartsListe
|
|||
@Override
|
||||
public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
|
||||
if(job2insert instanceof Delivery){
|
||||
Capacity loadAtDepot = stateManager.getRouteState(inRoute, StateFactory.LOAD_AT_BEGINNING, Capacity.class);
|
||||
Capacity loadAtDepot = stateManager.getRouteState(inRoute, InternalStates.LOAD_AT_BEGINNING, Capacity.class);
|
||||
if(loadAtDepot == null) loadAtDepot = defaultValue;
|
||||
stateManager.putTypedInternalRouteState(inRoute, StateFactory.LOAD_AT_BEGINNING, Capacity.addup(loadAtDepot, job2insert.getSize()));
|
||||
stateManager.putTypedInternalRouteState(inRoute, InternalStates.LOAD_AT_BEGINNING, Capacity.addup(loadAtDepot, job2insert.getSize()));
|
||||
}
|
||||
else if(job2insert instanceof Pickup || job2insert instanceof Service){
|
||||
Capacity loadAtEnd = stateManager.getRouteState(inRoute, StateFactory.LOAD_AT_END, Capacity.class);
|
||||
Capacity loadAtEnd = stateManager.getRouteState(inRoute, InternalStates.LOAD_AT_END, Capacity.class);
|
||||
if(loadAtEnd == null) loadAtEnd = defaultValue;
|
||||
stateManager.putTypedInternalRouteState(inRoute, StateFactory.LOAD_AT_END, Capacity.addup(loadAtEnd, job2insert.getSize()));
|
||||
stateManager.putTypedInternalRouteState(inRoute, InternalStates.LOAD_AT_END, Capacity.addup(loadAtEnd, job2insert.getSize()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import jsprit.core.problem.Capacity;
|
|||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.ActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
|
||||
/**
|
||||
* Determines and memorizes the maximum capacity utilization at each activity by looking backward in route,
|
||||
|
|
@ -49,14 +48,14 @@ class UpdateMaxCapacityUtilisationAtActivitiesByLookingBackwardInRoute implement
|
|||
@Override
|
||||
public void begin(VehicleRoute route) {
|
||||
this.route = route;
|
||||
maxLoad = stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class);
|
||||
maxLoad = stateManager.getRouteState(route, InternalStates.LOAD_AT_BEGINNING, Capacity.class);
|
||||
if(maxLoad == null) maxLoad = defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TourActivity act) {
|
||||
maxLoad = Capacity.max(maxLoad, stateManager.getActivityState(act, StateFactory.LOAD, Capacity.class));
|
||||
stateManager.putInternalTypedActivityState(act, StateFactory.PAST_MAXLOAD, maxLoad);
|
||||
maxLoad = Capacity.max(maxLoad, stateManager.getActivityState(act, InternalStates.LOAD, Capacity.class));
|
||||
stateManager.putInternalTypedActivityState(act, InternalStates.PAST_MAXLOAD, maxLoad);
|
||||
assert maxLoad.isGreaterOrEqual(Capacity.Builder.newInstance().build()) : "maxLoad can never be smaller than 0";
|
||||
assert maxLoad.isLessOrEqual(route.getVehicle().getType().getCapacityDimensions()) : "maxLoad can never be bigger than vehicleCap";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import jsprit.core.problem.Capacity;
|
|||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.ReverseActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
|
||||
/**
|
||||
* A {@link ReverseActivityVisitor} that looks forward in the vehicle route and determines
|
||||
|
|
@ -62,14 +61,14 @@ class UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute implements
|
|||
@Override
|
||||
public void begin(VehicleRoute route) {
|
||||
this.route = route;
|
||||
maxLoad = stateManager.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class);
|
||||
maxLoad = stateManager.getRouteState(route, InternalStates.LOAD_AT_END, Capacity.class);
|
||||
if(maxLoad == null) maxLoad = defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TourActivity act) {
|
||||
maxLoad = Capacity.max(maxLoad, stateManager.getActivityState(act, StateFactory.LOAD, Capacity.class));
|
||||
stateManager.putInternalTypedActivityState(act, StateFactory.FUTURE_MAXLOAD, maxLoad);
|
||||
maxLoad = Capacity.max(maxLoad, stateManager.getActivityState(act, InternalStates.LOAD, Capacity.class));
|
||||
stateManager.putInternalTypedActivityState(act, InternalStates.FUTURE_MAXLOAD, maxLoad);
|
||||
assert maxLoad.isLessOrEqual(route.getVehicle().getType().getCapacityDimensions()) : "maxLoad can in every capacity dimension never be bigger than vehicleCap";
|
||||
assert maxLoad.isGreaterOrEqual(Capacity.Builder.newInstance().build()) : "maxLoad can never be smaller than 0";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import jsprit.core.problem.Capacity;
|
|||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.ActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
|
||||
/**
|
||||
* Updates load at activity level.
|
||||
|
|
@ -55,7 +54,7 @@ class UpdateMaxCapacityUtilisationAtRoute implements ActivityVisitor, StateUpdat
|
|||
|
||||
@Override
|
||||
public void begin(VehicleRoute route) {
|
||||
currentLoad = stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class);
|
||||
currentLoad = stateManager.getRouteState(route, InternalStates.LOAD_AT_BEGINNING, Capacity.class);
|
||||
if(currentLoad == null) currentLoad = defaultValue;
|
||||
maxLoad = currentLoad;
|
||||
this.route = route;
|
||||
|
|
@ -69,6 +68,6 @@ class UpdateMaxCapacityUtilisationAtRoute implements ActivityVisitor, StateUpdat
|
|||
|
||||
@Override
|
||||
public void finish() {
|
||||
stateManager.putTypedInternalRouteState(route, StateFactory.MAXLOAD, maxLoad);
|
||||
stateManager.putTypedInternalRouteState(route, InternalStates.MAXLOAD, maxLoad);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
|||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.ReverseActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
|
||||
/**
|
||||
* Updates and memorizes latest operation start times at activities.
|
||||
|
|
@ -60,7 +59,7 @@ class UpdatePracticalTimeWindows implements ReverseActivityVisitor, StateUpdater
|
|||
double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocationId(), prevAct.getLocationId(), latestArrTimeAtPrevAct, route.getDriver(),route.getVehicle()) - activity.getOperationTime();
|
||||
double latestArrivalTime = Math.min(activity.getTheoreticalLatestOperationStartTime(), potentialLatestArrivalTimeAtCurrAct);
|
||||
|
||||
states.putInternalTypedActivityState(activity, StateFactory.LATEST_OPERATION_START_TIME, latestArrivalTime);
|
||||
states.putInternalTypedActivityState(activity, InternalStates.LATEST_OPERATION_START_TIME, latestArrivalTime);
|
||||
|
||||
latestArrTimeAtPrevAct = latestArrivalTime;
|
||||
prevAct = activity;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
|||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.ActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.util.ActivityTimeTracker;
|
||||
|
||||
|
||||
|
|
@ -34,10 +33,6 @@ import jsprit.core.util.ActivityTimeTracker;
|
|||
* <p>Thus it modifies <code>stateManager.getRouteState(route, StateTypes.COSTS)</code> and <br>
|
||||
* <code>stateManager.getActivityState(activity, StateTypes.COSTS)</code>
|
||||
*
|
||||
*
|
||||
* @param activityCost
|
||||
* @param transportCost
|
||||
* @param states
|
||||
*/
|
||||
public class UpdateVariableCosts implements ActivityVisitor,StateUpdater{
|
||||
|
||||
|
|
@ -94,7 +89,7 @@ public class UpdateVariableCosts implements ActivityVisitor,StateUpdater{
|
|||
totalOperationCost += transportCost;
|
||||
totalOperationCost += actCost;
|
||||
|
||||
states.putInternalTypedActivityState(act, StateFactory.COSTS, totalOperationCost);
|
||||
states.putInternalTypedActivityState(act, InternalStates.COSTS, totalOperationCost);
|
||||
|
||||
prevAct = act;
|
||||
startTimeAtPrevAct = timeTracker.getActEndTime();
|
||||
|
|
@ -109,7 +104,7 @@ public class UpdateVariableCosts implements ActivityVisitor,StateUpdater{
|
|||
totalOperationCost += transportCost;
|
||||
totalOperationCost += actCost;
|
||||
|
||||
states.putTypedInternalRouteState(vehicleRoute, StateFactory.COSTS, totalOperationCost);
|
||||
states.putTypedInternalRouteState(vehicleRoute, InternalStates.COSTS, totalOperationCost);
|
||||
|
||||
startTimeAtPrevAct = 0.0;
|
||||
prevAct = null;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
|||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.ReverseActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
|
@ -69,7 +68,7 @@ public class UpdateVehicleDependentPracticalTimeWindows implements ReverseActivi
|
|||
double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocationId(), prevLocation,
|
||||
latestArrTimeAtPrevAct, route.getDriver(), vehicle) - activity.getOperationTime();
|
||||
double latestArrivalTime = Math.min(activity.getTheoreticalLatestOperationStartTime(), potentialLatestArrivalTimeAtCurrAct);
|
||||
stateManager.putInternalTypedActivityState(activity, vehicle, StateFactory.LATEST_OPERATION_START_TIME, latestArrivalTime);
|
||||
stateManager.putInternalTypedActivityState(activity, vehicle, InternalStates.LATEST_OPERATION_START_TIME, latestArrivalTime);
|
||||
latest_arrTimes_at_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = latestArrivalTime;
|
||||
location_of_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = activity.getLocationId();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.constraint;
|
||||
|
||||
import jsprit.core.algorithm.state.InternalStates;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.activity.DeliverShipment;
|
||||
|
|
@ -25,7 +26,6 @@ import jsprit.core.problem.solution.route.activity.PickupShipment;
|
|||
import jsprit.core.problem.solution.route.activity.Start;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -69,11 +69,11 @@ public class PickupAndDeliverShipmentLoadActivityLevelConstraint implements Hard
|
|||
}
|
||||
Capacity loadAtPrevAct;
|
||||
if(prevAct instanceof Start){
|
||||
loadAtPrevAct = stateManager.getRouteState(iFacts.getRoute(), StateFactory.LOAD_AT_BEGINNING, Capacity.class);
|
||||
loadAtPrevAct = stateManager.getRouteState(iFacts.getRoute(), InternalStates.LOAD_AT_BEGINNING, Capacity.class);
|
||||
if(loadAtPrevAct == null) loadAtPrevAct = defaultValue;
|
||||
}
|
||||
else{
|
||||
loadAtPrevAct = stateManager.getActivityState(prevAct, StateFactory.LOAD, Capacity.class);
|
||||
loadAtPrevAct = stateManager.getActivityState(prevAct, InternalStates.LOAD, Capacity.class);
|
||||
if(loadAtPrevAct == null) loadAtPrevAct = defaultValue;
|
||||
}
|
||||
if(newAct instanceof PickupShipment){
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.constraint;
|
||||
|
||||
import jsprit.core.algorithm.state.InternalStates;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.activity.*;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -51,15 +51,15 @@ class ServiceLoadActivityLevelConstraint implements HardActivityStateLevelConstr
|
|||
Capacity futureMaxLoad;
|
||||
Capacity prevMaxLoad;
|
||||
if(prevAct instanceof Start){
|
||||
futureMaxLoad = stateManager.getRouteState(iFacts.getRoute(), StateFactory.MAXLOAD, Capacity.class);
|
||||
futureMaxLoad = stateManager.getRouteState(iFacts.getRoute(), InternalStates.MAXLOAD, Capacity.class);
|
||||
if(futureMaxLoad == null) futureMaxLoad = defaultValue;
|
||||
prevMaxLoad = stateManager.getRouteState(iFacts.getRoute(), StateFactory.LOAD_AT_BEGINNING, Capacity.class);
|
||||
prevMaxLoad = stateManager.getRouteState(iFacts.getRoute(), InternalStates.LOAD_AT_BEGINNING, Capacity.class);
|
||||
if(prevMaxLoad == null) prevMaxLoad = defaultValue;
|
||||
}
|
||||
else{
|
||||
futureMaxLoad = stateManager.getActivityState(prevAct, StateFactory.FUTURE_MAXLOAD, Capacity.class);
|
||||
futureMaxLoad = stateManager.getActivityState(prevAct, InternalStates.FUTURE_MAXLOAD, Capacity.class);
|
||||
if(futureMaxLoad == null) futureMaxLoad = defaultValue;
|
||||
prevMaxLoad = stateManager.getActivityState(prevAct, StateFactory.PAST_MAXLOAD, Capacity.class);
|
||||
prevMaxLoad = stateManager.getActivityState(prevAct, InternalStates.PAST_MAXLOAD, Capacity.class);
|
||||
if(prevMaxLoad == null) prevMaxLoad = defaultValue;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,13 +18,13 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.constraint;
|
||||
|
||||
import jsprit.core.algorithm.state.InternalStates;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.job.Delivery;
|
||||
import jsprit.core.problem.job.Pickup;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
|
||||
/**
|
||||
* Ensures that capacity constraint is met, i.e. that current load plus
|
||||
|
|
@ -49,21 +49,21 @@ class ServiceLoadRouteLevelConstraint implements HardRouteStateLevelConstraint {
|
|||
|
||||
@Override
|
||||
public boolean fulfilled(JobInsertionContext insertionContext) {
|
||||
Capacity maxLoadAtRoute = stateManager.getRouteState(insertionContext.getRoute(), StateFactory.MAXLOAD, Capacity.class);
|
||||
Capacity maxLoadAtRoute = stateManager.getRouteState(insertionContext.getRoute(), InternalStates.MAXLOAD, Capacity.class);
|
||||
if(maxLoadAtRoute == null) maxLoadAtRoute = defaultValue;
|
||||
Capacity capacityDimensions = insertionContext.getNewVehicle().getType().getCapacityDimensions();
|
||||
if(!maxLoadAtRoute.isLessOrEqual(capacityDimensions)){
|
||||
return false;
|
||||
}
|
||||
if(insertionContext.getJob() instanceof Delivery){
|
||||
Capacity loadAtDepot = stateManager.getRouteState(insertionContext.getRoute(), StateFactory.LOAD_AT_BEGINNING, Capacity.class);
|
||||
Capacity loadAtDepot = stateManager.getRouteState(insertionContext.getRoute(), InternalStates.LOAD_AT_BEGINNING, Capacity.class);
|
||||
if(loadAtDepot == null) loadAtDepot = defaultValue;
|
||||
if(!Capacity.addup(loadAtDepot, insertionContext.getJob().getSize()).isLessOrEqual(capacityDimensions)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if(insertionContext.getJob() instanceof Pickup || insertionContext.getJob() instanceof Service){
|
||||
Capacity loadAtEnd = stateManager.getRouteState(insertionContext.getRoute(), StateFactory.LOAD_AT_END, Capacity.class);
|
||||
Capacity loadAtEnd = stateManager.getRouteState(insertionContext.getRoute(), InternalStates.LOAD_AT_END, Capacity.class);
|
||||
if(loadAtEnd == null) loadAtEnd = defaultValue;
|
||||
if(!Capacity.addup(loadAtEnd, insertionContext.getJob().getSize()).isLessOrEqual(capacityDimensions)){
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -18,12 +18,12 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.constraint;
|
||||
|
||||
import jsprit.core.algorithm.state.InternalStates;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.activity.End;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.util.CalculationUtils;
|
||||
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ import jsprit.core.util.CalculationUtils;
|
|||
}
|
||||
}
|
||||
else{
|
||||
latestArrTimeAtNextAct = states.getActivityState(nextAct, StateFactory.LATEST_OPERATION_START_TIME, Double.class);
|
||||
latestArrTimeAtNextAct = states.getActivityState(nextAct, InternalStates.LATEST_OPERATION_START_TIME, Double.class);
|
||||
if(latestArrTimeAtNextAct==null) latestArrTimeAtNextAct=nextAct.getTheoreticalLatestOperationStartTime();
|
||||
nextActLocation = nextAct.getLocationId();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,12 +19,12 @@ package jsprit.core.problem.constraint;
|
|||
* Stefan Schroeder - initial API and implementation
|
||||
******************************************************************************/
|
||||
|
||||
import jsprit.core.algorithm.state.InternalStates;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.activity.End;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.util.CalculationUtils;
|
||||
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ public class VehicleDependentTimeWindowConstraints implements HardActivityStateL
|
|||
}
|
||||
else{
|
||||
//try to get latest_operation_start_time of newVehicle
|
||||
latestArrTimeAtNextAct = states.getActivityState(nextAct, iFacts.getNewVehicle(), StateFactory.LATEST_OPERATION_START_TIME ,Double.class);
|
||||
latestArrTimeAtNextAct = states.getActivityState(nextAct, iFacts.getNewVehicle(), InternalStates.LATEST_OPERATION_START_TIME ,Double.class);
|
||||
// if(latestArrTimeAtNextAct == null) //try to get latest_operation_start_time of currVehicle
|
||||
// latestArrTimeAtNextAct = states.getActivityState(nextAct, iFacts.getRoute().getVehicle(), StateFactory.LATEST_OPERATION_START_TIME ,Double.class);
|
||||
if(latestArrTimeAtNextAct == null) //otherwise set it to theoretical_latest_operation_startTime
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.solution.route.state;
|
||||
|
||||
import jsprit.core.algorithm.state.StateId;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory.StateId;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
public interface RouteAndActivityStateGetter {
|
||||
|
|
|
|||
|
|
@ -1,137 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributors:
|
||||
* Stefan Schroeder - initial API and implementation
|
||||
******************************************************************************/
|
||||
package jsprit.core.problem.solution.route.state;
|
||||
|
||||
import jsprit.core.problem.HasIndex;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class StateFactory {
|
||||
|
||||
|
||||
public interface StateId extends HasIndex{
|
||||
|
||||
}
|
||||
|
||||
public final static StateId MAXLOAD = new StateIdImpl("max_load", 0);
|
||||
|
||||
public final static StateId LOAD = new StateIdImpl("load", 1);
|
||||
|
||||
public final static StateId COSTS = new StateIdImpl("costs", 2);
|
||||
|
||||
public final static StateId LOAD_AT_BEGINNING = new StateIdImpl("load_at_beginning", 3);
|
||||
|
||||
public final static StateId LOAD_AT_END = new StateIdImpl("load_at_end", 4);
|
||||
|
||||
public final static StateId DURATION = new StateIdImpl("duration", 5);
|
||||
|
||||
public final static StateId LATEST_OPERATION_START_TIME = new StateIdImpl("latest_operation_start_time", 6);
|
||||
|
||||
public final static StateId EARLIEST_OPERATION_START_TIME = new StateIdImpl("earliest_operation_start_time", 7);
|
||||
|
||||
public final static StateId FUTURE_MAXLOAD = new StateIdImpl("future_max_load", 8);
|
||||
|
||||
public final static StateId PAST_MAXLOAD = new StateIdImpl("past_max_load", 9);
|
||||
|
||||
final static List<String> reservedIds = Arrays.asList("max_load","load","costs","load_at_beginning","load_at_end","duration","latest_operation_start_time","earliest_operation_start_time"
|
||||
,"future_max_load","past_max_load");
|
||||
|
||||
|
||||
|
||||
@Deprecated
|
||||
public static StateId createId(String name){
|
||||
if(reservedIds.contains(name)){ throwReservedIdException(name); }
|
||||
return new StateIdImpl(name, -1);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static StateId createId(String name, int index){
|
||||
if(reservedIds.contains(name)) throwReservedIdException(name);
|
||||
if(index < 10) throwReservedIdException(name);
|
||||
return new StateIdImpl(name, index);
|
||||
}
|
||||
|
||||
|
||||
public static boolean isReservedId(String stateId){
|
||||
return reservedIds.contains(stateId);
|
||||
}
|
||||
|
||||
public static boolean isReservedId(StateId stateId){
|
||||
return reservedIds.contains(stateId.toString());
|
||||
}
|
||||
|
||||
public static void throwReservedIdException(String name) {
|
||||
throw new IllegalStateException("state-id with name '" + name + "' cannot be created. it is already reserved internally.");
|
||||
}
|
||||
|
||||
|
||||
static class StateIdImpl implements StateId {
|
||||
|
||||
private int index;
|
||||
|
||||
public int getIndex(){ return index; }
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
StateIdImpl other = (StateIdImpl) obj;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private String name;
|
||||
|
||||
public StateIdImpl(String name, int index) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -28,7 +28,8 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
|
|||
public VehicleFleetManagerImpl newInstance(Collection<Vehicle> vehicles){
|
||||
return new VehicleFleetManagerImpl(vehicles);
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
public static VehicleFleetManager createDefaultFleetManager() {
|
||||
return new DefaultFleetManager();
|
||||
}
|
||||
|
|
@ -46,7 +47,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
|
|||
|
||||
private ArrayList<Vehicle> vehicleList;
|
||||
|
||||
public TypeContainer(VehicleTypeKey type) {
|
||||
public TypeContainer() {
|
||||
super();
|
||||
vehicleList = new ArrayList<Vehicle>();
|
||||
}
|
||||
|
|
@ -82,8 +83,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
|
|||
private Map<VehicleTypeKey,TypeContainer> typeMapOfAvailableVehicles;
|
||||
|
||||
private Map<VehicleTypeKey,Vehicle> penaltyVehicles = new HashMap<VehicleTypeKey, Vehicle>();
|
||||
|
||||
// private Map<TypeKey,TypeContainer> typeMapOfAvailablePenaltyVehicles;
|
||||
|
||||
|
||||
public VehicleFleetManagerImpl(Collection<Vehicle> vehicles) {
|
||||
super();
|
||||
|
|
@ -128,7 +128,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
|
|||
else{
|
||||
VehicleTypeKey typeKey = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocationId(), v.getEndLocationId(), v.getEarliestDeparture(), v.getLatestArrival());
|
||||
if(!typeMapOfAvailableVehicles.containsKey(typeKey)){
|
||||
typeMapOfAvailableVehicles.put(typeKey, new TypeContainer(typeKey));
|
||||
typeMapOfAvailableVehicles.put(typeKey, new TypeContainer());
|
||||
}
|
||||
typeMapOfAvailableVehicles.get(typeKey).add(v);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue