@Override public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { if (makeNoise) { return noiseLevel * maxCosts * randomArray[newAct.getIndex()].nextDouble(); } return 0; }
<T> void putInternalTypedActivityState(TourActivity act, StateId stateId, T state) { activityStates[act.getIndex()][stateId.getIndex()] = state; }
/** * Returns true if a state value is associated to the specified activity, vehicle and stateId. * * @param act the activity for which a state value is associated to * @param vehicle the vehicle for which a state value is associated to * @param stateId the stateId which is the associated key to the problem state * @return true if a state value is associated otherwise false * @throws java.lang.IllegalStateException if <code>act.getIndex()==0</code> since this suggests that act has no index at all */ public boolean hasActivityState(TourActivity act, Vehicle vehicle, StateId stateId) { if (act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be."); return vehicleDependentActivityStates[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()] != null; }
/** * Returns associated state for the specified activity and stateId, or it returns null if no value is associated. * <p>If type class is not equal to the associated type class of the requested state value, it throws a ClassCastException.</p> * * @param act the activity for which a state value is associated to * @param stateId the stateId for which a state value is associated to * @param type the type of class of the associated state value * @param <T> the type * @return the state value that is associated to the specified activity and stateId, or null if no value is associated. * @throws java.lang.ClassCastException if type class is not equal to the associated type class of the requested state value * @throws java.lang.IllegalStateException if <code>act.getIndex()==0</code> since this suggests that act has no index at all */ @Override public <T> T getActivityState(TourActivity act, StateId stateId, Class<T> type) { if (act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be."); if (act.getIndex() < 0) return null; T state; try { state = type.cast(activityStates[act.getIndex()][stateId.getIndex()]); } catch (ClassCastException e) { throw getClassCastException(e, stateId, type.toString(), activityStates[act.getIndex()][stateId.getIndex()].getClass().toString()); } return state; }
/** * Associates the specified activity, vehicle and stateId to the state value. If a state value is already associated to the * specified activity and stateId, it is replaced by the new state value. * * @param act the activity for which a state value is associated to * @param vehicle the vehicle for which a state value is associated to * @param stateId the stateId which is the associated key to the activity state * @param state the state that is associated to the activity and stateId * @param <T> the type of the state * @throws java.lang.IllegalStateException if <code>act.getIndex() == 0</code> * || stateId.getIndex < noInternalStates */ public <T> void putActivityState(TourActivity act, Vehicle vehicle, StateId stateId, T state) { if (act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be."); if (stateId.getIndex() < initialNoStates) 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, vehicle, stateId, state); }
/** * Associates the specified activity and stateId to the state value. If a state value is already associated to the * specified activity and stateId, it is replaced by the new state value. * * @param act the activity for which a state value is associated to * @param stateId the stateId which is the associated key to the activity state * @param state the state that is associated to the activity and stateId * @param <T> the type of the state * @throws java.lang.IllegalStateException if <code>act.getIndex() == 0</code> * || stateId.getIndex < noInternalStates */ public <T> void putActivityState(TourActivity act, StateId stateId, T state) { if (act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be."); if (stateId.getIndex() < initialNoStates) 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, state); }
/** * Returns the associated state value to the specified activity, vehicle and stateId, or null if no state value is * associated. * <p>If type class is not equal to the associated type class of the requested state value, it throws a ClassCastException.</p> * * @param act the activity for which a state value is associated to * @param vehicle the vehicle for which a state value is associated to * @param stateId the stateId which is the associated key to the problem state * @param type the class of the associated state value * @param <T> the type of the class * @return the associated state value to the specified activity, vehicle and stateId, or null if no state value is * associated. * @throws java.lang.ClassCastException if type class is not equal to the associated type class of the requested state value * @throws java.lang.IllegalStateException if <code>act.getIndex()==0</code> since this suggests that act has no index at all */ public <T> T getActivityState(TourActivity act, Vehicle vehicle, StateId stateId, Class<T> type) { if (act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be."); if (act.getIndex() < 0) return null; //act.getIndex() < 0 indicates that act is either Start (-1) or End (-2) T state; try { state = type.cast(vehicleDependentActivityStates[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()]); } catch (ClassCastException e) { Object state_class = vehicleDependentActivityStates[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()]; throw getClassCastException(e, stateId, type.toString(), state_class.getClass().toString()); } return state; }
<T> void putInternalTypedActivityState(TourActivity act, Vehicle vehicle, StateId stateId, T state) { vehicleDependentActivityStates[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()] = state; }
private void verify(VehicleRoutingProblemSolution solution) { Set<Job> allJobs = new HashSet<Job>(problem.getJobs().values()); allJobs.removeAll(solution.getUnassignedJobs()); for (VehicleRoute route : solution.getRoutes()) { allJobs.removeAll(route.getTourActivities().getJobs()); if (route.getVehicle().getIndex() == 0) throw new IllegalStateException("vehicle used in initial solution has no index. probably a vehicle is used that has not been added to the " + " the VehicleRoutingProblem. only use vehicles that have already been added to the problem."); for (TourActivity act : route.getActivities()) { if (act.getIndex() == 0) throw new IllegalStateException("act in initial solution has no index. activities are created and associated to their job in VehicleRoutingProblem\n." + " thus if you build vehicle-routes use the jobActivityFactory from vehicle routing problem like that \n" + " VehicleRoute.Builder.newInstance(knownVehicle).setJobActivityFactory(vrp.getJobActivityFactory).addService(..)....build() \n" + " then the activities that are created to build the route are identical to the ones used in VehicleRoutingProblem"); } } solution.getUnassignedJobs().addAll(allJobs); solution.setCost(getObjectiveFunction().getCosts(solution)); // if (nuJobs != problem.getJobs().values().size()) { // logger.warn("number of jobs in initial solution ({}) is not equal nuJobs in vehicle routing problem ({})" + // "\n this might yield unintended effects, e.g. initial solution cannot be improved anymore.", nuJobs, problem.getJobs().values().size()); // } }
int index = 0; for (TourActivity act : seedRoute.getActivities()) { if (act.getIndex() == randomSeedAct.getIndex()) { seedIndex = index; break;
if (act.getIndex() == randomSeedAct.getIndex()) { seedIndex = index; break;
@Override public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { if (makeNoise) { return noiseLevel * maxCosts * randomArray[newAct.getIndex()].nextDouble(); } return 0; }
<T> void putInternalTypedActivityState(TourActivity act, StateId stateId, T state) { activityStates[act.getIndex()][stateId.getIndex()] = state; }
/** * Returns associated state for the specified activity and stateId, or it returns null if no value is associated. * <p>If type class is not equal to the associated type class of the requested state value, it throws a ClassCastException.</p> * * @param act the activity for which a state value is associated to * @param stateId the stateId for which a state value is associated to * @param type the type of class of the associated state value * @param <T> the type * @return the state value that is associated to the specified activity and stateId, or null if no value is associated. * @throws java.lang.ClassCastException if type class is not equal to the associated type class of the requested state value * @throws java.lang.IllegalStateException if <code>act.getIndex()==0</code> since this suggests that act has no index at all */ @Override public <T> T getActivityState(TourActivity act, StateId stateId, Class<T> type) { if (act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be."); if (act.getIndex() < 0) return null; T state; try { state = type.cast(activityStates[act.getIndex()][stateId.getIndex()]); } catch (ClassCastException e) { throw getClassCastException(e, stateId, type.toString(), activityStates[act.getIndex()][stateId.getIndex()].getClass().toString()); } return state; }
/** * Returns true if a state value is associated to the specified activity, vehicle and stateId. * * @param act the activity for which a state value is associated to * @param vehicle the vehicle for which a state value is associated to * @param stateId the stateId which is the associated key to the problem state * @return true if a state value is associated otherwise false * @throws java.lang.IllegalStateException if <code>act.getIndex()==0</code> since this suggests that act has no index at all */ public boolean hasActivityState(TourActivity act, Vehicle vehicle, StateId stateId) { if (act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be."); return vehicleDependentActivityStates[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()] != null; }
/** * Associates the specified activity, vehicle and stateId to the state value. If a state value is already associated to the * specified activity and stateId, it is replaced by the new state value. * * @param act the activity for which a state value is associated to * @param vehicle the vehicle for which a state value is associated to * @param stateId the stateId which is the associated key to the activity state * @param state the state that is associated to the activity and stateId * @param <T> the type of the state * @throws java.lang.IllegalStateException if <code>act.getIndex() == 0</code> * || stateId.getIndex < noInternalStates */ public <T> void putActivityState(TourActivity act, Vehicle vehicle, StateId stateId, T state) { if (act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be."); if (stateId.getIndex() < initialNoStates) 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, vehicle, stateId, state); }
/** * Associates the specified activity and stateId to the state value. If a state value is already associated to the * specified activity and stateId, it is replaced by the new state value. * * @param act the activity for which a state value is associated to * @param stateId the stateId which is the associated key to the activity state * @param state the state that is associated to the activity and stateId * @param <T> the type of the state * @throws java.lang.IllegalStateException if <code>act.getIndex() == 0</code> * || stateId.getIndex < noInternalStates */ public <T> void putActivityState(TourActivity act, StateId stateId, T state) { if (act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be."); if (stateId.getIndex() < initialNoStates) 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, state); }
/** * Returns the associated state value to the specified activity, vehicle and stateId, or null if no state value is * associated. * <p>If type class is not equal to the associated type class of the requested state value, it throws a ClassCastException.</p> * * @param act the activity for which a state value is associated to * @param vehicle the vehicle for which a state value is associated to * @param stateId the stateId which is the associated key to the problem state * @param type the class of the associated state value * @param <T> the type of the class * @return the associated state value to the specified activity, vehicle and stateId, or null if no state value is * associated. * @throws java.lang.ClassCastException if type class is not equal to the associated type class of the requested state value * @throws java.lang.IllegalStateException if <code>act.getIndex()==0</code> since this suggests that act has no index at all */ public <T> T getActivityState(TourActivity act, Vehicle vehicle, StateId stateId, Class<T> type) { if (act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be."); if (act.getIndex() < 0) return null; //act.getIndex() < 0 indicates that act is either Start (-1) or End (-2) T state; try { state = type.cast(vehicleDependentActivityStates[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()]); } catch (ClassCastException e) { Object state_class = vehicleDependentActivityStates[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()]; throw getClassCastException(e, stateId, type.toString(), state_class.getClass().toString()); } return state; }
<T> void putInternalTypedActivityState(TourActivity act, Vehicle vehicle, StateId stateId, T state) { vehicleDependentActivityStates[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()] = state; }
private void verify(VehicleRoutingProblemSolution solution) { int nuJobs = 0; for (VehicleRoute route : solution.getRoutes()) { nuJobs += route.getTourActivities().getJobs().size(); if (route.getVehicle().getIndex() == 0) throw new IllegalStateException("vehicle used in initial solution has no index. probably a vehicle is used that has not been added to the " + " the VehicleRoutingProblem. only use vehicles that have already been added to the problem."); for (TourActivity act : route.getActivities()) { if (act.getIndex() == 0) { throw new IllegalStateException("act in initial solution has no index. activities are created and associated to their job in VehicleRoutingProblem\n." + " thus if you build vehicle-routes use the jobActivityFactory from vehicle routing problem like that \n" + " VehicleRoute.Builder.newInstance(knownVehicle).setJobActivityFactory(vrp.getJobActivityFactory).addService(..)....build() \n" + " then the activities that are created to build the route are identical to the ones used in VehicleRoutingProblem"); } } } // if (nuJobs != problem.getJobs().values().size()) { // logger.warn("number of jobs in initial solution ({}) is not equal nuJobs in vehicle routing problem ({})" + // "\n this might yield unintended effects, e.g. initial solution cannot be improved anymore.", nuJobs, problem.getJobs().values().size()); // } }