edu.kit.ifv.mobitopp.simulation.tour.DefaultTourModeChoiceUtilityFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mobitopp Show documentation
Show all versions of mobitopp Show documentation
mobiTopp (http://mobitopp.ifv.kit.edu/) is an agent-based travel demand model developed at the Institute for transport studies at the Karlsruhe Institute of Technology (http://www.ifv.kit.edu/english/index.php). Publications about mobiTopp can be found on the project site (http://mobitopp.ifv.kit.edu/28.php).
The newest version!
package edu.kit.ifv.mobitopp.simulation.tour;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import edu.kit.ifv.mobitopp.simulation.ImpedanceIfc;
import edu.kit.ifv.mobitopp.simulation.Mode;
import edu.kit.ifv.mobitopp.simulation.Person;
import edu.kit.ifv.mobitopp.simulation.StandardChoiceSet;
import edu.kit.ifv.mobitopp.util.logit.LinearUtilityFunction;
public class DefaultTourModeChoiceUtilityFunction
implements TourModeChoiceUtilityFunction
{
private final TourModeChoiceParameter parameter;
private final ImpedanceIfc impedance;
private final Map modeUtilityFunctions;
private final Collection modes;
public DefaultTourModeChoiceUtilityFunction(
TourModeChoiceParameter modeChoiceParameter,
ImpedanceIfc impedance
) {
this.parameter = modeChoiceParameter;
this.impedance = impedance;
this.modes = Collections.unmodifiableCollection(StandardChoiceSet.CHOICE_SET_FULL);
this.modeUtilityFunctions = Collections.unmodifiableMap(makeUtilityFunctions(this.parameter));
}
private Map makeUtilityFunctions(
TourModeChoiceParameter parameter
) {
Map utilityFunctions = new LinkedHashMap();
for (Mode mode : modes) {
utilityFunctions.put(mode, new LinearUtilityFunction(parameter.parameterForMode(mode)));
}
return utilityFunctions;
}
@Override
public Map calculateUtilities(
Tour tour,
Person person,
Map preferences,
Set choiceSet
) {
Set modes = new LinkedHashSet(choiceSet);
Map utilities = new LinkedHashMap();
Map> attributes = this.parameter.gatherAttributes(
modes, tour, person, preferences, impedance
);
assert attributes != null : modes;
for (Mode mode : modes) {
assert modeUtilityFunctions.containsKey(mode);
assert attributes.containsKey(mode);
LinearUtilityFunction utilityFunction = modeUtilityFunctions.get(mode);
Double u = utilityFunction.calculateUtility(attributes.get(mode));
utilities.put(mode, u);
}
// System.out.println(utilities);
return utilities;
}
}