From 251ded5fb795f3224e611d13db26e273c1db18b8 Mon Sep 17 00:00:00 2001 From: oblonski <4sschroeder@gmail.com> Date: Wed, 16 Jul 2014 10:34:06 +0200 Subject: [PATCH] simplified method names --- .../core/algorithm/state/StateManager.java | 43 +++++++++++++++++-- .../route/activity/TourActivities.java | 26 +++++------ 2 files changed, 49 insertions(+), 20 deletions(-) diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/state/StateManager.java b/jsprit-core/src/main/java/jsprit/core/algorithm/state/StateManager.java index 4ef93e72..ca867b44 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/state/StateManager.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/state/StateManager.java @@ -284,7 +284,8 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart } return null; } - + + /** * Generic method to memorize state 'state' of type 'type' of act and stateId. * @@ -298,16 +299,49 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart * @param stateId stateId of state * @param type class of state-value * @param state state-value + * @deprecated use putActivityState(...) instead */ + @Deprecated public void putTypedActivityState(TourActivity act, StateId stateId, Class type, T state){ // if(act.getIndex()>=activity_states.length){ // nuActivities=act.getIndex()+1; // this.activity_states = resizeArr(activity_states,nuActivities); // } - if(stateId.getIndex()<10) StateFactory.throwReservedIdException(stateId.toString()); + if(stateId.getIndex()<10) throw new IllegalStateException("either you use a reserved stateId that is applied\n" + + "internally or your stateId has been created without index, e.g. StateFactory.createId(stateName)\n" + + " does not assign indeces thus do not use it anymore, but use\n " + + "stateManager.createStateId(name)\n" + + " instead.\n"); putInternalTypedActivityState(act, stateId, type, state); } + /** + * Generic method to memorize state 'state' of type 'type' of act and stateId. + * + *

For example:
+ * Capacity loadAtMyActivity = Capacity.Builder.newInstance().addCapacityDimension(0,10).build();
+ * stateManager.putTypedActivityState(myActivity, StateFactory.createStateId("act-load"), Capacity.class, loadAtMyActivity);
+ *

you can retrieve the load at myActivity by
+ * Capacity load = stateManager.getActivityState(myActivity, StateFactory.createStateId("act-load"), Capacity.class); + * + * @param act for which a new state should be memorized + * @param stateId stateId of state + * @param type class of state-value + * @param state state-value + */ + public void putActivityState(TourActivity act, StateId stateId, Class type, T state){ +// if(act.getIndex()>=activity_states.length){ +// nuActivities=act.getIndex()+1; +// this.activity_states = resizeArr(activity_states,nuActivities); +// } + if(stateId.getIndex()<10) throw new IllegalStateException("either you use a reserved stateId that is applied\n" + + "internally or your stateId has been created without index, e.g. StateFactory.createId(stateName)\n" + + " does not assign indeces thus do not use it anymore, but use\n " + + "stateManager.createStateId(name)\n" + + " instead.\n"); + putInternalTypedActivityState(act, stateId, type, state); + } + private Object[][] resizeArr(Object[][] states, int newLength) { int oldSize = states.length; Object[][] new_states = new Object[newLength][stateIndexCounter]; @@ -332,10 +366,11 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart * @param stateId stateId of the state value to identify it * @param type type of state * @param state state value + * @deprecated use putRouteState(...) instead */ @Deprecated public void putTypedRouteState(VehicleRoute route, StateId stateId, Class type, T state){ - putTypedRouteState(route,stateId,state); + putRouteState(route, stateId, state); } /** @@ -351,7 +386,7 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart * @param stateId stateId of the state value to identify it * @param state state value */ - public void putTypedRouteState(VehicleRoute route, StateId stateId, T state){ + public void putRouteState(VehicleRoute route, StateId stateId, T state){ if(stateId.getIndex()<10) StateFactory.throwReservedIdException(stateId.toString()); putTypedInternalRouteState(route, stateId, state); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourActivities.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourActivities.java index 33161cc2..e888bb5c 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourActivities.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourActivities.java @@ -16,17 +16,11 @@ ******************************************************************************/ package jsprit.core.problem.solution.route.activity; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - import jsprit.core.problem.job.Job; import jsprit.core.problem.solution.route.activity.TourActivity.JobActivity; +import java.util.*; + /** @@ -83,6 +77,8 @@ public class TourActivities { private final ArrayList tourActivities = new ArrayList(); private final Set jobs = new HashSet(); + + private final Map> job2activityIndeces = new HashMap>(); private ReverseActivityIterator backward; @@ -178,21 +174,19 @@ public class TourActivities { * ... * */ - if(insertionIndex < tourActivities.size()) tourActivities.add(insertionIndex, act); - else if(insertionIndex >= tourActivities.size()) tourActivities.add(act); + if(insertionIndex < tourActivities.size()) { + tourActivities.add(insertionIndex, act); + } + else if(insertionIndex >= tourActivities.size()) { + tourActivities.add(act); + } addJob(act); } /** -<<<<<<< HEAD - * adds activity. - * - * @throw {@link IllegalStateException} if same activity is added twice. -======= * Adds specified activity at the end of activity-list. *

If act instanceof JobActivity, it adds underlying job also. * @throws IllegalStateException if activity-list already contains act. ->>>>>>> refs/remotes/choose_remote_name/relaxAPI * @param act */ public void addActivity(TourActivity act){