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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import jsprit.core.algorithm.ruin.RandomRuinStrategyFactory;
|
|||
import jsprit.core.algorithm.ruin.RuinStrategy;
|
||||
import jsprit.core.algorithm.ruin.distance.AvgServiceDistance;
|
||||
import jsprit.core.algorithm.selector.SelectBest;
|
||||
import jsprit.core.algorithm.state.InternalStates;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.algorithm.state.UpdateVariableCosts;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
|
|
@ -33,7 +34,6 @@ import jsprit.core.problem.io.VrpXMLReader;
|
|||
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.StateFactory;
|
||||
import jsprit.core.problem.vehicle.InfiniteFleetManagerFactory;
|
||||
import jsprit.core.problem.vehicle.VehicleFleetManager;
|
||||
import jsprit.core.util.Solutions;
|
||||
|
|
@ -81,7 +81,7 @@ public class BuildCVRPAlgoFromScratch_IT {
|
|||
public double getCosts(VehicleRoutingProblemSolution solution) {
|
||||
double costs = 0.0;
|
||||
for(VehicleRoute route : solution.getRoutes()){
|
||||
costs += stateManager.getRouteState(route, StateFactory.COSTS,Double.class);
|
||||
costs += stateManager.getRouteState(route, InternalStates.COSTS,Double.class);
|
||||
}
|
||||
return costs;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import jsprit.core.algorithm.ruin.RandomRuinStrategyFactory;
|
|||
import jsprit.core.algorithm.ruin.RuinStrategy;
|
||||
import jsprit.core.algorithm.ruin.distance.AvgServiceDistance;
|
||||
import jsprit.core.algorithm.selector.SelectBest;
|
||||
import jsprit.core.algorithm.state.InternalStates;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.algorithm.termination.IterationWithoutImprovementTermination;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
|
|
@ -33,7 +34,6 @@ import jsprit.core.problem.io.VrpXMLReader;
|
|||
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.StateFactory;
|
||||
import jsprit.core.problem.vehicle.InfiniteFleetManagerFactory;
|
||||
import jsprit.core.problem.vehicle.VehicleFleetManager;
|
||||
import jsprit.core.util.Solutions;
|
||||
|
|
@ -81,7 +81,7 @@ public class BuildPDVRPAlgoFromScratch_IT {
|
|||
public double getCosts(VehicleRoutingProblemSolution solution) {
|
||||
double costs = 0.0;
|
||||
for(VehicleRoute route : solution.getRoutes()){
|
||||
Double cost_of_route = stateManager.getRouteState(route, StateFactory.COSTS, Double.class);
|
||||
Double cost_of_route = stateManager.getRouteState(route, InternalStates.COSTS, Double.class);
|
||||
if(cost_of_route == null) cost_of_route = 0.;
|
||||
costs += cost_of_route;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import jsprit.core.algorithm.ruin.RandomRuinStrategyFactory;
|
|||
import jsprit.core.algorithm.ruin.RuinStrategy;
|
||||
import jsprit.core.algorithm.ruin.distance.AvgServiceAndShipmentDistance;
|
||||
import jsprit.core.algorithm.selector.SelectBest;
|
||||
import jsprit.core.algorithm.state.InternalStates;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.algorithm.state.UpdateVariableCosts;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
|
|
@ -33,7 +34,6 @@ import jsprit.core.problem.io.VrpXMLReader;
|
|||
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.StateFactory;
|
||||
import jsprit.core.problem.vehicle.InfiniteFleetManagerFactory;
|
||||
import jsprit.core.problem.vehicle.VehicleFleetManager;
|
||||
import org.junit.Test;
|
||||
|
|
@ -77,7 +77,7 @@ public class BuildPDVRPWithShipmentsAlgoFromScratch_IT {
|
|||
public double getCosts(VehicleRoutingProblemSolution solution) {
|
||||
double costs = 0.0;
|
||||
for(VehicleRoute route : solution.getRoutes()){
|
||||
costs += stateManager.getRouteState(route, StateFactory.COSTS, Double.class);
|
||||
costs += stateManager.getRouteState(route, InternalStates.COSTS, Double.class);
|
||||
}
|
||||
return costs;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,21 +18,21 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import jsprit.core.algorithm.state.InternalStates;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.job.Job;
|
||||
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.VehicleType;
|
||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class JobInsertionConsideringFixCostsCalculatorTest {
|
||||
|
||||
private JobInsertionConsideringFixCostsCalculator calc;
|
||||
|
|
@ -67,7 +67,7 @@ public class JobInsertionConsideringFixCostsCalculatorTest {
|
|||
when(jobInsertionCosts.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE)).thenReturn(iData);
|
||||
|
||||
stateGetter = mock(RouteAndActivityStateGetter.class);
|
||||
when(stateGetter.getRouteState(route, StateFactory.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().build());
|
||||
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().build());
|
||||
|
||||
calc = new JobInsertionConsideringFixCostsCalculator(jobInsertionCosts, stateGetter);
|
||||
}
|
||||
|
|
@ -213,7 +213,7 @@ public class JobInsertionConsideringFixCostsCalculatorTest {
|
|||
calc.setSolutionCompletenessRatio(0.5);
|
||||
calc.setWeightOfFixCost(.5);
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
when(stateGetter.getRouteState(route, StateFactory.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).build());
|
||||
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).build());
|
||||
//(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*(100-50)+0.5*(75-25))*0.5*0.5 = 12.5
|
||||
assertEquals(12.5,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
}
|
||||
|
|
@ -241,7 +241,7 @@ public class JobInsertionConsideringFixCostsCalculatorTest {
|
|||
when(nVehicle.getType()).thenReturn(type);
|
||||
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
when(stateGetter.getRouteState(route, StateFactory.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).addDimension(1, 100).build());
|
||||
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).addDimension(1, 100).build());
|
||||
//(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*(100-50)+0.5*(75-25))*0.5*0.5 = 12.5
|
||||
/*
|
||||
* (0.5*(100-50)+0.5*(
|
||||
|
|
@ -266,7 +266,7 @@ public class JobInsertionConsideringFixCostsCalculatorTest {
|
|||
when(nVehicle.getType()).thenReturn(type);
|
||||
|
||||
when(route.getVehicle()).thenReturn(oVehicle);
|
||||
when(stateGetter.getRouteState(route, StateFactory.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).addDimension(1, 100).build());
|
||||
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).addDimension(1, 100).build());
|
||||
//(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*(100.-50.)+0.25*12.5)*0.75*0.5 = 15.234375
|
||||
|
||||
assertEquals(15.234375,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01);
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import jsprit.core.problem.misc.JobInsertionContext;
|
|||
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.state.StateFactory;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
|
|
@ -91,7 +90,7 @@ public class HardPickupAndDeliveryShipmentActivityConstraintTest {
|
|||
PickupService anotherService = (PickupService) vrp.getActivities(s2).get(0);
|
||||
PickupShipment pickupShipment = (PickupShipment) vrp.getActivities(shipment).get(0);
|
||||
|
||||
stateManager.putInternalTypedActivityState(pickupService, StateFactory.LOAD, Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||
stateManager.putInternalTypedActivityState(pickupService, InternalStates.LOAD, Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||
// when(stateManager.getActivityState(pickupService, StateFactory.LOAD)).thenReturn(StateFactory.createState(2.0));
|
||||
assertEquals(ConstraintsStatus.NOT_FULFILLED,constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0));
|
||||
}
|
||||
|
|
@ -103,7 +102,7 @@ public class HardPickupAndDeliveryShipmentActivityConstraintTest {
|
|||
|
||||
DeliverShipment deliverShipment = (DeliverShipment) vrp.getActivities(shipment).get(1);
|
||||
|
||||
stateManager.putInternalTypedActivityState(pickupService, StateFactory.LOAD, Capacity.Builder.newInstance().addDimension(0, 1).build());
|
||||
stateManager.putInternalTypedActivityState(pickupService, InternalStates.LOAD, Capacity.Builder.newInstance().addDimension(0, 1).build());
|
||||
// stateManager.putInternalActivityState(pickupService, StateFactory.LOAD, StateFactory.createState(1));
|
||||
assertEquals(ConstraintsStatus.FULFILLED,constraint.fulfilled(iFacts, pickupService, deliverShipment, anotherService, 0.0));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import jsprit.core.problem.JobActivityFactory;
|
|||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.job.*;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
import org.junit.Before;
|
||||
|
|
@ -96,56 +95,56 @@ public class LoadStateTest {
|
|||
@Test
|
||||
public void loadAtEndShouldBe15(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.<Job>emptyList());
|
||||
Capacity routeState = stateManager.getRouteState(serviceRoute, StateFactory.LOAD_AT_END, Capacity.class);
|
||||
Capacity routeState = stateManager.getRouteState(serviceRoute, InternalStates.LOAD_AT_END, Capacity.class);
|
||||
assertEquals(15,routeState.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadAtBeginningShouldBe0(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.<Job>emptyList());
|
||||
Capacity routeState = stateManager.getRouteState(serviceRoute, StateFactory.LOAD_AT_BEGINNING, Capacity.class);
|
||||
Capacity routeState = stateManager.getRouteState(serviceRoute, InternalStates.LOAD_AT_BEGINNING, Capacity.class);
|
||||
assertEquals(0,routeState.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadAtAct1ShouldBe10(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.<Job>emptyList());
|
||||
Capacity atAct1 = stateManager.getActivityState(serviceRoute.getActivities().get(0), StateFactory.LOAD, Capacity.class);
|
||||
Capacity atAct1 = stateManager.getActivityState(serviceRoute.getActivities().get(0), InternalStates.LOAD, Capacity.class);
|
||||
assertEquals(10,atAct1.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadAtAct2ShouldBe15(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.<Job>emptyList());
|
||||
Capacity atAct2 = stateManager.getActivityState(serviceRoute.getActivities().get(1), StateFactory.LOAD, Capacity.class);
|
||||
Capacity atAct2 = stateManager.getActivityState(serviceRoute.getActivities().get(1), InternalStates.LOAD, Capacity.class);
|
||||
assertEquals(15,atAct2.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void futureMaxLoatAtAct1ShouldBe15(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.<Job>emptyList());
|
||||
Capacity atAct1 = stateManager.getActivityState(serviceRoute.getActivities().get(0), StateFactory.FUTURE_MAXLOAD, Capacity.class);
|
||||
Capacity atAct1 = stateManager.getActivityState(serviceRoute.getActivities().get(0), InternalStates.FUTURE_MAXLOAD, Capacity.class);
|
||||
assertEquals(15,atAct1.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void futureMaxLoatAtAct2ShouldBe15(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.<Job>emptyList());
|
||||
Capacity atAct2 = stateManager.getActivityState(serviceRoute.getActivities().get(1), StateFactory.FUTURE_MAXLOAD, Capacity.class);
|
||||
Capacity atAct2 = stateManager.getActivityState(serviceRoute.getActivities().get(1), InternalStates.FUTURE_MAXLOAD, Capacity.class);
|
||||
assertEquals(15,atAct2.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pastMaxLoatAtAct1ShouldBe0(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.<Job>emptyList());
|
||||
Capacity atAct1 = stateManager.getActivityState(serviceRoute.getActivities().get(0), StateFactory.PAST_MAXLOAD, Capacity.class);
|
||||
Capacity atAct1 = stateManager.getActivityState(serviceRoute.getActivities().get(0), InternalStates.PAST_MAXLOAD, Capacity.class);
|
||||
assertEquals(10,atAct1.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pastMaxLoatAtAct2ShouldBe10(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.<Job>emptyList());
|
||||
Capacity atAct2 = stateManager.getActivityState(serviceRoute.getActivities().get(1), StateFactory.PAST_MAXLOAD, Capacity.class);
|
||||
Capacity atAct2 = stateManager.getActivityState(serviceRoute.getActivities().get(1), InternalStates.PAST_MAXLOAD, Capacity.class);
|
||||
assertEquals(15,atAct2.get(0));
|
||||
}
|
||||
|
||||
|
|
@ -156,56 +155,56 @@ public class LoadStateTest {
|
|||
@Test
|
||||
public void when_pdroute_loadAtEndShouldBe10(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.<Job>emptyList());
|
||||
Capacity routeState = stateManager.getRouteState(pickup_delivery_route, StateFactory.LOAD_AT_END, Capacity.class);
|
||||
Capacity routeState = stateManager.getRouteState(pickup_delivery_route, InternalStates.LOAD_AT_END, Capacity.class);
|
||||
assertEquals(10,routeState.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_pdroute_loadAtBeginningShouldBe5(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.<Job>emptyList());
|
||||
Capacity routeState = stateManager.getRouteState(pickup_delivery_route, StateFactory.LOAD_AT_BEGINNING, Capacity.class);
|
||||
Capacity routeState = stateManager.getRouteState(pickup_delivery_route, InternalStates.LOAD_AT_BEGINNING, Capacity.class);
|
||||
assertEquals(5,routeState.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_pdroute_loadAtAct1ShouldBe15(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.<Job>emptyList());
|
||||
Capacity atAct1 = stateManager.getActivityState(pickup_delivery_route.getActivities().get(0), StateFactory.LOAD, Capacity.class);
|
||||
Capacity atAct1 = stateManager.getActivityState(pickup_delivery_route.getActivities().get(0), InternalStates.LOAD, Capacity.class);
|
||||
assertEquals(15,atAct1.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_pdroute_loadAtAct2ShouldBe10(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.<Job>emptyList());
|
||||
Capacity atAct2 = stateManager.getActivityState(pickup_delivery_route.getActivities().get(1), StateFactory.LOAD, Capacity.class);
|
||||
Capacity atAct2 = stateManager.getActivityState(pickup_delivery_route.getActivities().get(1), InternalStates.LOAD, Capacity.class);
|
||||
assertEquals(10,atAct2.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_pdroute_futureMaxLoatAtAct1ShouldBe15(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.<Job>emptyList());
|
||||
Capacity atAct1 = stateManager.getActivityState(pickup_delivery_route.getActivities().get(0), StateFactory.FUTURE_MAXLOAD, Capacity.class);
|
||||
Capacity atAct1 = stateManager.getActivityState(pickup_delivery_route.getActivities().get(0), InternalStates.FUTURE_MAXLOAD, Capacity.class);
|
||||
assertEquals(15,atAct1.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_pdroute_futureMaxLoatAtAct2ShouldBe10(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.<Job>emptyList());
|
||||
Capacity atAct2 = stateManager.getActivityState(pickup_delivery_route.getActivities().get(1), StateFactory.FUTURE_MAXLOAD, Capacity.class);
|
||||
Capacity atAct2 = stateManager.getActivityState(pickup_delivery_route.getActivities().get(1), InternalStates.FUTURE_MAXLOAD, Capacity.class);
|
||||
assertEquals(10,atAct2.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_pdroute_pastMaxLoatAtAct1ShouldBe15(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.<Job>emptyList());
|
||||
Capacity atAct1 = stateManager.getActivityState(pickup_delivery_route.getActivities().get(0), StateFactory.PAST_MAXLOAD, Capacity.class);
|
||||
Capacity atAct1 = stateManager.getActivityState(pickup_delivery_route.getActivities().get(0), InternalStates.PAST_MAXLOAD, Capacity.class);
|
||||
assertEquals(15,atAct1.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_pdroute_pastMaxLoatAtAct2ShouldBe10(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.<Job>emptyList());
|
||||
Capacity atAct2 = stateManager.getActivityState(pickup_delivery_route.getActivities().get(1), StateFactory.PAST_MAXLOAD, Capacity.class);
|
||||
Capacity atAct2 = stateManager.getActivityState(pickup_delivery_route.getActivities().get(1), InternalStates.PAST_MAXLOAD, Capacity.class);
|
||||
assertEquals(15,atAct2.get(0));
|
||||
}
|
||||
|
||||
|
|
@ -219,98 +218,98 @@ public class LoadStateTest {
|
|||
@Test
|
||||
public void when_shipmentroute_loadAtEndShouldBe0(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.<Job>emptyList());
|
||||
Capacity routeState = stateManager.getRouteState(shipment_route, StateFactory.LOAD_AT_END, Capacity.class);
|
||||
Capacity routeState = stateManager.getRouteState(shipment_route, InternalStates.LOAD_AT_END, Capacity.class);
|
||||
assertEquals(0,routeState.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_shipmentroute_loadAtBeginningShouldBe0(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.<Job>emptyList());
|
||||
Capacity routeState = stateManager.getRouteState(shipment_route, StateFactory.LOAD_AT_BEGINNING, Capacity.class);
|
||||
Capacity routeState = stateManager.getRouteState(shipment_route, InternalStates.LOAD_AT_BEGINNING, Capacity.class);
|
||||
assertEquals(0,routeState.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_shipmentroute_loadAtAct1ShouldBe10(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.<Job>emptyList());
|
||||
Capacity atAct1 = stateManager.getActivityState(shipment_route.getActivities().get(0), StateFactory.LOAD, Capacity.class);
|
||||
Capacity atAct1 = stateManager.getActivityState(shipment_route.getActivities().get(0), InternalStates.LOAD, Capacity.class);
|
||||
assertEquals(10,atAct1.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_shipmentroute_loadAtAct2ShouldBe15(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.<Job>emptyList());
|
||||
Capacity atAct2 = stateManager.getActivityState(shipment_route.getActivities().get(1), StateFactory.LOAD, Capacity.class);
|
||||
Capacity atAct2 = stateManager.getActivityState(shipment_route.getActivities().get(1), InternalStates.LOAD, Capacity.class);
|
||||
assertEquals(15,atAct2.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_shipmentroute_loadAtAct3ShouldBe10(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.<Job>emptyList());
|
||||
Capacity atAct = stateManager.getActivityState(shipment_route.getActivities().get(2), StateFactory.LOAD, Capacity.class);
|
||||
Capacity atAct = stateManager.getActivityState(shipment_route.getActivities().get(2), InternalStates.LOAD, Capacity.class);
|
||||
assertEquals(10, atAct.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_shipmentroute_loadAtAct4ShouldBe0(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.<Job>emptyList());
|
||||
Capacity atAct = stateManager.getActivityState(shipment_route.getActivities().get(3), StateFactory.LOAD, Capacity.class);
|
||||
Capacity atAct = stateManager.getActivityState(shipment_route.getActivities().get(3), InternalStates.LOAD, Capacity.class);
|
||||
assertEquals(0, atAct.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_shipmentroute_futureMaxLoatAtAct1ShouldBe15(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.<Job>emptyList());
|
||||
Capacity atAct1 = stateManager.getActivityState(shipment_route.getActivities().get(0), StateFactory.FUTURE_MAXLOAD, Capacity.class);
|
||||
Capacity atAct1 = stateManager.getActivityState(shipment_route.getActivities().get(0), InternalStates.FUTURE_MAXLOAD, Capacity.class);
|
||||
assertEquals(15,atAct1.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_shipmentroute_futureMaxLoatAtAct2ShouldBe15(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.<Job>emptyList());
|
||||
Capacity atAct2 = stateManager.getActivityState(shipment_route.getActivities().get(1), StateFactory.FUTURE_MAXLOAD, Capacity.class);
|
||||
Capacity atAct2 = stateManager.getActivityState(shipment_route.getActivities().get(1), InternalStates.FUTURE_MAXLOAD, Capacity.class);
|
||||
assertEquals(15,atAct2.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_shipmentroute_futureMaxLoatAtAct3ShouldBe10(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.<Job>emptyList());
|
||||
Capacity atAct = stateManager.getActivityState(shipment_route.getActivities().get(2), StateFactory.FUTURE_MAXLOAD, Capacity.class);
|
||||
Capacity atAct = stateManager.getActivityState(shipment_route.getActivities().get(2), InternalStates.FUTURE_MAXLOAD, Capacity.class);
|
||||
assertEquals(10,atAct.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_shipmentroute_futureMaxLoatAtAct4ShouldBe0(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.<Job>emptyList());
|
||||
Capacity atAct = stateManager.getActivityState(shipment_route.getActivities().get(3), StateFactory.FUTURE_MAXLOAD, Capacity.class);
|
||||
Capacity atAct = stateManager.getActivityState(shipment_route.getActivities().get(3), InternalStates.FUTURE_MAXLOAD, Capacity.class);
|
||||
assertEquals(0,atAct.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_shipmentroute_pastMaxLoatAtAct1ShouldBe10(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.<Job>emptyList());
|
||||
Capacity atAct1 = stateManager.getActivityState(shipment_route.getActivities().get(0), StateFactory.PAST_MAXLOAD, Capacity.class);
|
||||
Capacity atAct1 = stateManager.getActivityState(shipment_route.getActivities().get(0), InternalStates.PAST_MAXLOAD, Capacity.class);
|
||||
assertEquals(10,atAct1.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_shipmentroute_pastMaxLoatAtAct2ShouldBe10(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.<Job>emptyList());
|
||||
Capacity atAct2 = stateManager.getActivityState(shipment_route.getActivities().get(1), StateFactory.PAST_MAXLOAD, Capacity.class);
|
||||
Capacity atAct2 = stateManager.getActivityState(shipment_route.getActivities().get(1), InternalStates.PAST_MAXLOAD, Capacity.class);
|
||||
assertEquals(15,atAct2.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_shipmentroute_pastMaxLoatAtAct3ShouldBe15(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.<Job>emptyList());
|
||||
Capacity atAct = stateManager.getActivityState(shipment_route.getActivities().get(2), StateFactory.PAST_MAXLOAD, Capacity.class);
|
||||
Capacity atAct = stateManager.getActivityState(shipment_route.getActivities().get(2), InternalStates.PAST_MAXLOAD, Capacity.class);
|
||||
assertEquals(15,atAct.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_shipmentroute_pastMaxLoatAtAct4ShouldBe15(){
|
||||
stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.<Job>emptyList());
|
||||
Capacity atAct = stateManager.getActivityState(shipment_route.getActivities().get(3), StateFactory.PAST_MAXLOAD, Capacity.class);
|
||||
Capacity atAct = stateManager.getActivityState(shipment_route.getActivities().get(3), InternalStates.PAST_MAXLOAD, Capacity.class);
|
||||
assertEquals(15,atAct.get(0));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,8 +27,6 @@ import jsprit.core.problem.job.Service;
|
|||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.ServiceActivity;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory.StateId;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ import jsprit.core.problem.job.Pickup;
|
|||
import jsprit.core.problem.solution.route.ReverseRouteActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
|
|
@ -86,19 +85,19 @@ public class UpdatePracticalTimeWindowTest {
|
|||
@Test
|
||||
public void whenVehicleRouteHasPickupAndDeliveryAndPickup_latestStartTimeOfAct3MustBeCorrect(){
|
||||
assertEquals(50.,route.getActivities().get(2).getTheoreticalLatestOperationStartTime(),0.01);
|
||||
assertEquals(50.,stateManager.getActivityState(route.getActivities().get(2), StateFactory.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
assertEquals(50.,stateManager.getActivityState(route.getActivities().get(2), InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehicleRouteHasPickupAndDeliveryAndPickup_latestStartTimeOfAct2MustBeCorrect(){
|
||||
assertEquals(40.,route.getActivities().get(1).getTheoreticalLatestOperationStartTime(),0.01);
|
||||
assertEquals(30.,stateManager.getActivityState(route.getActivities().get(1), StateFactory.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
assertEquals(30.,stateManager.getActivityState(route.getActivities().get(1), InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenVehicleRouteHasPickupAndDeliveryAndPickup_latestStartTimeOfAct1MustBeCorrect(){
|
||||
assertEquals(30.,route.getActivities().get(0).getTheoreticalLatestOperationStartTime(),0.01);
|
||||
assertEquals(10.,stateManager.getActivityState(route.getActivities().get(0), StateFactory.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
assertEquals(10.,stateManager.getActivityState(route.getActivities().get(0), InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
|||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.vehicle.FiniteFleetManagerFactory;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleFleetManager;
|
||||
|
|
@ -107,75 +106,75 @@ public class UpdateVehicleDependentTimeWindowTest {
|
|||
|
||||
stateManager.addStateUpdater(updater);
|
||||
stateManager.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
assertTrue(stateManager.hasActivityState(route.getActivities().get(0), vehicle, StateFactory.LATEST_OPERATION_START_TIME));
|
||||
assertFalse(stateManager.hasActivityState(route.getActivities().get(0), vehicle2, StateFactory.LATEST_OPERATION_START_TIME));
|
||||
assertTrue(stateManager.hasActivityState(route.getActivities().get(0), vehicle, InternalStates.LATEST_OPERATION_START_TIME));
|
||||
assertFalse(stateManager.hasActivityState(route.getActivities().get(0), vehicle2, InternalStates.LATEST_OPERATION_START_TIME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct3(){
|
||||
assertEquals(70.,stateManager.getActivityState(route.getActivities().get(2),vehicle,
|
||||
StateFactory.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct3_v2(){
|
||||
assertEquals(70.,stateManager.getActivityState(route.getActivities().get(2),vehicle,
|
||||
StateFactory.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct3WithVehicle2(){
|
||||
assertEquals(30.,stateManager.getActivityState(route.getActivities().get(2),vehicle2,
|
||||
StateFactory.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct3WithVehicle3(){
|
||||
assertEquals(90.,stateManager.getActivityState(route.getActivities().get(2),vehicle3,
|
||||
StateFactory.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct2(){
|
||||
assertEquals(60.,stateManager.getActivityState(route.getActivities().get(1),vehicle,
|
||||
StateFactory.LATEST_OPERATION_START_TIME,Double.class),0.01);
|
||||
InternalStates.LATEST_OPERATION_START_TIME,Double.class),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct2_v2(){
|
||||
assertEquals(60.,stateManager.getActivityState(route.getActivities().get(1),vehicle,
|
||||
StateFactory.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct2WithVehicle2(){
|
||||
assertEquals(20.,stateManager.getActivityState(route.getActivities().get(1),vehicle2,
|
||||
StateFactory.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct2WithVehicle3(){
|
||||
assertEquals(80.,stateManager.getActivityState(route.getActivities().get(1),vehicle3,
|
||||
StateFactory.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct2WithEquivalentOfVehicle3(){
|
||||
assertEquals(80.,stateManager.getActivityState(route.getActivities().get(1),equivalentOf3,
|
||||
StateFactory.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct1WithVehicle2(){
|
||||
assertEquals(10.,stateManager.getActivityState(route.getActivities().get(0),vehicle2,
|
||||
StateFactory.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct1WithVehicle3(){
|
||||
assertEquals(70.,stateManager.getActivityState(route.getActivities().get(0),vehicle3,
|
||||
StateFactory.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.constraint;
|
||||
|
||||
import jsprit.core.algorithm.state.InternalStates;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
|
|
@ -30,7 +31,6 @@ import jsprit.core.problem.job.Service;
|
|||
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;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
|
|
@ -83,9 +83,9 @@ public class ServiceLoadRouteLevelConstraintTest {
|
|||
|
||||
Capacity currentLoad = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 1).addDimension(2, 1).build();
|
||||
stateGetter = mock(RouteAndActivityStateGetter.class);
|
||||
when(stateGetter.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class)).thenReturn(currentLoad);
|
||||
when(stateGetter.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class)).thenReturn(currentLoad);
|
||||
when(stateGetter.getRouteState(route, StateFactory.MAXLOAD, Capacity.class)).thenReturn(currentLoad);
|
||||
when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_BEGINNING, Capacity.class)).thenReturn(currentLoad);
|
||||
when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_END, Capacity.class)).thenReturn(currentLoad);
|
||||
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(currentLoad);
|
||||
|
||||
constraint = new ServiceLoadRouteLevelConstraint(stateGetter);
|
||||
|
||||
|
|
@ -258,9 +258,9 @@ public class ServiceLoadRouteLevelConstraintTest {
|
|||
Capacity atEnd = Capacity.Builder.newInstance().addDimension(0, 0).addDimension(1, 0).addDimension(2, 0).build();
|
||||
|
||||
RouteAndActivityStateGetter stateGetter = mock(RouteAndActivityStateGetter.class);
|
||||
when(stateGetter.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class)).thenReturn(atBeginning);
|
||||
when(stateGetter.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class)).thenReturn(atEnd);
|
||||
when(stateGetter.getRouteState(route, StateFactory.MAXLOAD, Capacity.class)).thenReturn(atBeginning);
|
||||
when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_BEGINNING, Capacity.class)).thenReturn(atBeginning);
|
||||
when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_END, Capacity.class)).thenReturn(atEnd);
|
||||
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(atBeginning);
|
||||
|
||||
JobInsertionContext iContext = mock(JobInsertionContext.class);
|
||||
when(iContext.getJob()).thenReturn(service);
|
||||
|
|
@ -286,9 +286,9 @@ public class ServiceLoadRouteLevelConstraintTest {
|
|||
Capacity atEnd = Capacity.Builder.newInstance().addDimension(0, 0).addDimension(1, 0).addDimension(2, 0).build();
|
||||
|
||||
RouteAndActivityStateGetter stateGetter = mock(RouteAndActivityStateGetter.class);
|
||||
when(stateGetter.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class)).thenReturn(atBeginning);
|
||||
when(stateGetter.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class)).thenReturn(atEnd);
|
||||
when(stateGetter.getRouteState(route, StateFactory.MAXLOAD, Capacity.class)).thenReturn(atBeginning);
|
||||
when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_BEGINNING, Capacity.class)).thenReturn(atBeginning);
|
||||
when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_END, Capacity.class)).thenReturn(atEnd);
|
||||
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(atBeginning);
|
||||
|
||||
JobInsertionContext iContext = mock(JobInsertionContext.class);
|
||||
when(iContext.getJob()).thenReturn(service);
|
||||
|
|
@ -314,9 +314,9 @@ public class ServiceLoadRouteLevelConstraintTest {
|
|||
Capacity atEnd = Capacity.Builder.newInstance().addDimension(0, 0).addDimension(1, 0).addDimension(2, 0).build();
|
||||
|
||||
RouteAndActivityStateGetter stateGetter = mock(RouteAndActivityStateGetter.class);
|
||||
when(stateGetter.getRouteState(route, StateFactory.LOAD_AT_BEGINNING, Capacity.class)).thenReturn(atBeginning);
|
||||
when(stateGetter.getRouteState(route, StateFactory.LOAD_AT_END, Capacity.class)).thenReturn(atEnd);
|
||||
when(stateGetter.getRouteState(route, StateFactory.MAXLOAD, Capacity.class)).thenReturn(atBeginning);
|
||||
when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_BEGINNING, Capacity.class)).thenReturn(atBeginning);
|
||||
when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_END, Capacity.class)).thenReturn(atEnd);
|
||||
when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(atBeginning);
|
||||
|
||||
JobInsertionContext iContext = mock(JobInsertionContext.class);
|
||||
when(iContext.getJob()).thenReturn(service);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package jsprit.core.problem.constraint;
|
||||
|
||||
import jsprit.core.algorithm.state.InternalStates;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.algorithm.state.UpdateActivityTimes;
|
||||
import jsprit.core.algorithm.state.UpdateVehicleDependentPracticalTimeWindows;
|
||||
|
|
@ -13,7 +14,6 @@ import jsprit.core.problem.job.Service;
|
|||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.PickupService;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
import jsprit.core.problem.vehicle.*;
|
||||
import jsprit.core.util.CostFactory;
|
||||
import org.junit.Before;
|
||||
|
|
@ -120,19 +120,19 @@ public class VehicleDependentTimeWindowTest {
|
|||
@Test
|
||||
public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct3(){
|
||||
assertEquals(70.,stateManager.getActivityState(route.getActivities().get(2),
|
||||
vehicle, StateFactory.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
vehicle, InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct2(){
|
||||
assertEquals(60.,stateManager.getActivityState(route.getActivities().get(1),
|
||||
vehicle, StateFactory.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
vehicle, InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct1(){
|
||||
assertEquals(50.,stateManager.getActivityState(route.getActivities().get(0),
|
||||
vehicle, StateFactory.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
vehicle, InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue