public final List<GenericPlanStrategy<PL, AG>> getStrategies(String subpopulation) { return getStrategyWeights( subpopulation ).unmodifiableStrategies; }
public final List<Double> getWeights(String subpopulation) { return getStrategyWeights( subpopulation ).unmodifiableWeights; }
/** * removes the specified strategy from this manager for the specified subpopulation * * @param strategy the strategy to be removed * @param subpopulation the subpopulation for which the strategy must be removed * @return true if the strategy was successfully removed from this manager, * false if the strategy was not part of this manager and could thus not be removed. */ final boolean removeStrategy( final GenericPlanStrategy<PL, AG> strategy, final String subpopulation) { final StrategyWeights<PL, AG> weights = getStrategyWeights( subpopulation ); int idx = weights.strategies.indexOf(strategy); if (idx != -1) { weights.strategies.remove(idx); double weight = weights.weights.remove(idx); weights.totalWeights -= weight; return true; } return false; }
/** * changes the weight of the specified strategy * * @return true if the strategy is part of this manager and the weight could * be changed successfully, false otherwise. */ final boolean changeWeightOfStrategy( final GenericPlanStrategy<PL, AG> strategy, final String subpopulation, final double newWeight) { final StrategyWeights<PL, AG> weights = getStrategyWeights(subpopulation); int idx = weights.strategies.indexOf(strategy); if (idx != -1) { double oldWeight = weights.weights.set(idx, newWeight); weights.totalWeights += (newWeight - oldWeight); Logger.getLogger(this.getClass()).info( strategy.toString() + ": oldWeight=" + oldWeight + " newWeight=" + newWeight ); return true; } return false; }
/** * Adds a strategy to this manager with the specified weight. This weight * compared to the sum of weights of all strategies in this manager defines * the probability this strategy will be used for an agent. * */ public final void addStrategy( final GenericPlanStrategy<PL, AG> strategy, final String subpopulation, final double weight) { final StrategyWeights<PL, AG> weights = getStrategyWeights( subpopulation ); if ( weights.strategies.contains( strategy ) ) { log.error( "Strategy "+strategy+" is already defined for subpopulation "+subpopulation ); log.error( "This can lead to undefined behavior. Please only specify each strategy once" ); throw new IllegalStateException( "Strategy "+strategy+" is already defined for subpopulation "+subpopulation ); } weights.strategies.add(strategy); weights.weights.add(weight); weights.totalWeights += weight; }
/** * Schedules a {@link #changeWeightOfStrategy(GenericPlanStrategy, String, double)} command for a later iteration. The * change will take place before the strategies are applied. * */ public final void addChangeRequest( final int iteration, final GenericPlanStrategy<PL, AG> strategy, final String subpopulation, final double newWeight) { final StrategyWeights<PL, AG> weights = getStrategyWeights( subpopulation ); Integer iter = iteration; Map<GenericPlanStrategy<PL, AG>, Double> iterationRequests = weights.changeRequests.get(iter); if (iterationRequests == null) { iterationRequests = new HashMap<>(3); weights.changeRequests.put(iter, iterationRequests); } iterationRequests.put(strategy, newWeight); Logger.getLogger(this.getClass()).info( "added change request: " + " iteration=" + iter + " newWeight=" + newWeight + " strategy=" + strategy.toString() ); }