diff --git a/src/main/java/org/matsim/run/scoring/DetailedPersonScoringParameters.java b/src/main/java/org/matsim/run/scoring/DetailedPersonScoringParameters.java index 43b312f8..fe993601 100644 --- a/src/main/java/org/matsim/run/scoring/DetailedPersonScoringParameters.java +++ b/src/main/java/org/matsim/run/scoring/DetailedPersonScoringParameters.java @@ -13,22 +13,28 @@ import java.util.Map; import java.util.TreeMap; +import java.util.concurrent.ConcurrentHashMap; public class DetailedPersonScoringParameters implements ScoringParametersForPerson { /** - * Cache instances of {@link ActivityUtilityParameters} for each activity type. - * All params are the same for each person. + * Cache instances of {@link ActivityUtilityParameters} for each subpopulation. */ - private final Map utilParams = new TreeMap<>(); + private final Map> activityParamsPerSubpopulation = new ConcurrentHashMap<>(); /** * Cache instances of {@link ModeUtilityParameters} for each mode. */ private final Map modeParams = new TreeMap<>(); + private final Scenario scenario; + private final VspScoringConfigGroup vspScoring; + @Inject - private Scenario scenario; + public DetailedPersonScoringParameters(Scenario scenario) { + this.scenario = scenario; + this.vspScoring = ConfigUtils.addOrGetModule(scenario.getConfig(), VspScoringConfigGroup.class); + } @Override public ScoringParameters getScoringParameters(Person person) { @@ -38,24 +44,20 @@ public ScoringParameters getScoringParameters(Person person) { ScoringConfigGroup.ScoringParameterSet scoringParameters = scoring.getScoringParameters(subpopulation); - Map personParams = new TreeMap<>(); - - for (ScoringConfigGroup.ActivityParams params : scoringParameters.getActivityParams()) { - ActivityUtilityParameters p = utilParams.computeIfAbsent(params.getActivityType(), k -> { + Map personParams = this.activityParamsPerSubpopulation.computeIfAbsent(subpopulation, k -> { + Map activityParams = new TreeMap<>(); + for (ScoringConfigGroup.ActivityParams params : scoringParameters.getActivityParams()) { ActivityUtilityParameters.Builder factory = new ActivityUtilityParameters.Builder(params); - return factory.build(); - }); - - personParams.put(params.getActivityType(), p); - } + activityParams.put(params.getActivityType(), factory.build()); + } + return activityParams; + }); ScoringParameters.Builder builder = new ScoringParameters.Builder(scoring, scoringParameters, personParams, scenario.getConfig().scenario()); // TODO: not configurable at the moment - if (subpopulation.equals("person")) { - - VspScoringConfigGroup vspScoring = ConfigUtils.addOrGetModule(scenario.getConfig(), VspScoringConfigGroup.class); + if ("person".equals(subpopulation)) { for (Map.Entry e : vspScoring.getModeParams().entrySet()) {