-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,048 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
182 changes: 182 additions & 0 deletions
182
src/main/java/org/matsim/run/scoring/AdvancedScoringConfigGroup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
package org.matsim.run.scoring; | ||
|
||
import org.matsim.core.config.ConfigGroup; | ||
import org.matsim.core.config.ReflectiveConfigGroup; | ||
|
||
import java.util.*; | ||
|
||
/** | ||
* COPIED FROM BERLIN - DO NOT DEVELOP HERE. WILL BE DELETED AS SOON AS THIS FUNCTIONALITY IS MOVED THE MATSIM CORE. | ||
* | ||
* Stores scoring parameters for {@link AdvancedScoringModule}. | ||
*/ | ||
@SuppressWarnings("checkstyle:VisibilityModifier") | ||
public final class AdvancedScoringConfigGroup extends ReflectiveConfigGroup { | ||
|
||
private static final String GROUP_NAME = "advancedScoring"; | ||
|
||
@Parameter | ||
@Comment("The distance groups if marginal utility of distance is adjusted. In meters.") | ||
public List<Integer> distGroups; | ||
|
||
@Parameter | ||
@Comment("Enable income dependent marginal utility of money.") | ||
public IncomeDependentScoring incomeDependent = IncomeDependentScoring.avgByPersonalIncome; | ||
|
||
@Parameter | ||
@Comment("Exponent for (global_income / personal_income) ** x.") | ||
public double incomeExponent = 1; | ||
|
||
@Parameter | ||
@Comment("Define how to load existing preferences.") | ||
public LoadPreferences loadPreferences = LoadPreferences.none; | ||
|
||
private final List<ScoringParameters> scoringParameters = new ArrayList<>(); | ||
|
||
public AdvancedScoringConfigGroup() { | ||
super(GROUP_NAME); | ||
} | ||
|
||
/** | ||
* Return the defined scoring parameters. | ||
*/ | ||
public List<ScoringParameters> getScoringParameters() { | ||
return Collections.unmodifiableList(scoringParameters); | ||
} | ||
|
||
@Override | ||
public ConfigGroup createParameterSet(String type) { | ||
if (type.equals(ScoringParameters.GROUP_NAME)) { | ||
return new ScoringParameters(); | ||
} else { | ||
throw new IllegalArgumentException("Unsupported parameter set type: " + type); | ||
} | ||
} | ||
|
||
@Override | ||
public void addParameterSet(ConfigGroup set) { | ||
if (set instanceof ScoringParameters p) { | ||
super.addParameterSet(set); | ||
scoringParameters.add(p); | ||
} else { | ||
throw new IllegalArgumentException("Unsupported parameter set class: " + set); | ||
} | ||
} | ||
|
||
/** | ||
* Different options for income dependent scoring. | ||
*/ | ||
public enum IncomeDependentScoring { | ||
none, | ||
avgByPersonalIncome | ||
} | ||
|
||
/** | ||
* Define how existing preferences are loaded. | ||
*/ | ||
public enum LoadPreferences { | ||
none, | ||
requireAttribute, | ||
skipMissing, | ||
skipRefPersons | ||
} | ||
|
||
/** | ||
* Variate values with random draw from specific distribution. | ||
*/ | ||
public enum VariationType { | ||
fixed, normal, truncatedNormal | ||
} | ||
|
||
/** | ||
* Scoring parameters for a specific group of agents. | ||
* This group allows arbitrary attributes to be defined, which are matched against person attributes. | ||
*/ | ||
public static final class ScoringParameters extends ReflectiveConfigGroup { | ||
|
||
private static final String GROUP_NAME = "scoringParameters"; | ||
|
||
/** | ||
* Params per mode. | ||
*/ | ||
private final Map<String, ModeParams> modeParams = new HashMap<>(); | ||
|
||
public ScoringParameters() { | ||
super(GROUP_NAME, true); | ||
} | ||
|
||
public Map<String, ModeParams> getModeParams() { | ||
return modeParams; | ||
} | ||
|
||
@Override | ||
public ConfigGroup createParameterSet(final String type) { | ||
return switch (type) { | ||
case ModeParams.GROUP_NAME -> new ModeParams(); | ||
default -> throw new IllegalArgumentException(type); | ||
}; | ||
} | ||
|
||
@Override | ||
public void addParameterSet(ConfigGroup set) { | ||
if (set instanceof ModeParams p) { | ||
super.addParameterSet(set); | ||
modeParams.put(p.mode, p); | ||
} else { | ||
throw new IllegalArgumentException("Unsupported parameter set class: " + set); | ||
} | ||
} | ||
|
||
/** | ||
* Retrieve mode parameters. | ||
*/ | ||
public ModeParams getOrCreateModeParams(String mode) { | ||
if (!modeParams.containsKey(mode)) { | ||
ModeParams p = new ModeParams(); | ||
p.mode = mode; | ||
|
||
addParameterSet(p); | ||
return p; | ||
} | ||
|
||
return modeParams.get(mode); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Stores mode specific parameters and also attributes to whom to apply this specification. | ||
*/ | ||
public static final class ModeParams extends ReflectiveConfigGroup { | ||
|
||
private static final String GROUP_NAME = "modeParams"; | ||
|
||
@Parameter | ||
@Comment("The mode for which the parameters are defined.") | ||
public String mode; | ||
|
||
@Parameter | ||
@Comment("[utils/leg] alternative-specific constant.") | ||
public double deltaConstant; | ||
|
||
@Parameter | ||
@Comment("Variation of the constant across individuals.") | ||
public VariationType varConstant = VariationType.fixed; | ||
|
||
@Parameter | ||
@Comment("[utils/day] if the mode is used at least once.") | ||
public double deltaDailyConstant; | ||
|
||
@Parameter | ||
@Comment("Variation of the daily constant across individuals.") | ||
public VariationType varDailyConstant = VariationType.fixed; | ||
|
||
@Parameter | ||
@Comment("total delta utility per dist group.") | ||
public List<Double> deltaPerDistGroup; | ||
|
||
public ModeParams() { | ||
super(GROUP_NAME); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/org/matsim/run/scoring/AdvancedScoringFunctionFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.matsim.run.scoring; | ||
|
||
import com.google.inject.Inject; | ||
import org.matsim.api.core.v01.network.Network; | ||
import org.matsim.api.core.v01.population.Person; | ||
import org.matsim.core.config.Config; | ||
import org.matsim.core.scoring.ScoringFunction; | ||
import org.matsim.core.scoring.ScoringFunctionFactory; | ||
import org.matsim.core.scoring.SumScoringFunction; | ||
import org.matsim.core.scoring.functions.*; | ||
|
||
/** | ||
* COPIED FROM BERLIN - DO NOT DEVELOP HERE. WILL BE DELETED AS SOON AS THIS FUNCTIONALITY IS MOVED THE MATSIM CORE. | ||
* | ||
* Same as {@link CharyparNagelScoringFunctionFactory} but with {@link PiecewiseLinearlLegScoring}. | ||
*/ | ||
public class AdvancedScoringFunctionFactory implements ScoringFunctionFactory { | ||
|
||
@Inject | ||
private Config config; | ||
|
||
@Inject | ||
private ScoringParametersForPerson params; | ||
|
||
@Inject | ||
private Network network; | ||
|
||
@Override | ||
public ScoringFunction createNewScoringFunction(Person person) { | ||
final ScoringParameters parameters = params.getScoringParameters(person); | ||
|
||
SumScoringFunction sumScoringFunction = new SumScoringFunction(); | ||
sumScoringFunction.addScoringFunction(new CharyparNagelActivityScoring(parameters)); | ||
// replaced original leg scoring | ||
sumScoringFunction.addScoringFunction(new PiecewiseLinearlLegScoring(parameters, this.network, config.transit().getTransitModes())); | ||
sumScoringFunction.addScoringFunction(new CharyparNagelMoneyScoring(parameters)); | ||
sumScoringFunction.addScoringFunction(new CharyparNagelAgentStuckScoring(parameters)); | ||
sumScoringFunction.addScoringFunction(new ScoreEventScoring()); | ||
return sumScoringFunction; | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/org/matsim/run/scoring/AdvancedScoringModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.matsim.run.scoring; | ||
|
||
import jakarta.inject.Singleton; | ||
import org.matsim.core.config.ConfigUtils; | ||
import org.matsim.core.controler.AbstractModule; | ||
import org.matsim.core.scoring.functions.ScoringParametersForPerson; | ||
|
||
/** | ||
* COPIED FROM BERLIN - DO NOT DEVELOP HERE. WILL BE DELETED AS SOON AS THIS FUNCTIONALITY IS MOVED THE MATSIM CORE. | ||
* | ||
* Module to bind components needed for advanced scoring functionality configured by {@link AdvancedScoringConfigGroup}. | ||
*/ | ||
public class AdvancedScoringModule extends AbstractModule { | ||
|
||
@Override | ||
public void install() { | ||
|
||
ConfigUtils.addOrGetModule(getConfig(), AdvancedScoringConfigGroup.class); | ||
|
||
bind(ScoringParametersForPerson.class).to(IndividualPersonScoringParameters.class).in(Singleton.class); | ||
|
||
addControlerListenerBinding().to(AdvancedScoringOutputWriter.class).in(Singleton.class); | ||
|
||
bindScoringFunctionFactory().to(AdvancedScoringFunctionFactory.class).in(Singleton.class); | ||
} | ||
} |
Oops, something went wrong.