edu.kit.ifv.mobitopp.populationsynthesis.ipu.StandardAttribute 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.populationsynthesis.ipu;
import java.util.function.Function;
import java.util.stream.Stream;
import edu.kit.ifv.mobitopp.data.demand.Demography;
import edu.kit.ifv.mobitopp.data.demand.RangeDistributionItem;
import edu.kit.ifv.mobitopp.util.panel.HouseholdOfPanelData;
import edu.kit.ifv.mobitopp.util.panel.PersonOfPanelData;
public enum StandardAttribute implements AttributeType {
domCode("dom_code") {
@Override
public Stream createAttributes(
final Demography demography, final RegionalContext context) {
return createHouseholdAttributes(context, demography, HouseholdOfPanelData::domCode);
}
},
householdSize("household_size") {
@Override
public Stream createAttributes(
final Demography demography, final RegionalContext context) {
return createHouseholdAttributes(context, demography, HouseholdOfPanelData::size);
}
},
householdType("household_type") {
@Override
public Stream createAttributes(
final Demography demography, final RegionalContext context) {
return createHouseholdAttributes(context, demography, HouseholdOfPanelData::type);
}
},
income("income") {
@Override
public Stream createAttributes(
final Demography demography, final RegionalContext context) {
return createHouseholdAttributes(context, demography, HouseholdOfPanelData::income);
}
},
femaleAge("age_f") {
@Override
public Stream createAttributes(
final Demography demography, final RegionalContext context) {
return demography
.femaleAge()
.items()
.map(item -> new FemaleAge(context, this, item.lowerBound(), item.upperBound(), item.amount()));
}
},
maleAge("age_m") {
@Override
public Stream createAttributes(
final Demography demography, final RegionalContext context) {
return demography
.maleAge()
.items()
.map(item -> new MaleAge(context, this, item.lowerBound(), item.upperBound(), item.amount()));
}
},
age("age") {
@Override
public Stream createAttributes(
final Demography demography, final RegionalContext context) {
return createPersonAttributes(context, demography, person -> person.age());
}
},
gender("gender") {
@Override
public Stream createAttributes(
final Demography demography, final RegionalContext context) {
return createPersonAttributes(context, demography, person -> person.gender().getTypeAsInt());
}
},
employment("job") {
@Override
public Stream createAttributes(
final Demography demography, final RegionalContext context) {
return demography
.employment()
.items()
.map(item -> new PersonAttribute(context, this, item.getTypeAsInt(),
item.getTypeAsInt(), item.amount(), PersonOfPanelData::getEmploymentTypeAsInt));
}
},
graduation("graduation") {
@Override
public Stream createAttributes(
final Demography demography, final RegionalContext context) {
return createPersonAttributes(context, demography, person -> (int) person.getGenderTypeAsInt());
}
},
commuterTicket("commuter_ticket") {
@Override
public Stream createAttributes(
final Demography demography, final RegionalContext context) {
return createPersonAttributes(context, demography, person -> person.hasCommuterTicket() ? 1:0);
}
},
distance("distance") {
@Override
public Stream createAttributes(
final Demography demography, final RegionalContext context) {
return createPersonAttributes(context, demography, person -> (int) person.getPoleDistance());
}
},
numberOfCars("number_of_cars") {
@Override
public Stream createAttributes(
final Demography demography, final RegionalContext context) {
return createHouseholdAttributes(context, demography, HouseholdOfPanelData::numberOfCars);
}
};
private final String attributeName;
private StandardAttribute(final String attributeName) {
this.attributeName = attributeName;
}
@Override
public String attributeName() {
return attributeName;
}
@Override
public String prefix() {
return attributeName + ":";
}
@Override
public String createInstanceName(final int lowerBound, final int upperBound) {
return prefix() + lowerBound + "-" + upperBound;
}
@Override
public String createInstanceName(final RangeDistributionItem item) {
return createInstanceName(item.lowerBound(), item.upperBound());
}
Stream createPersonAttributes(
final RegionalContext context, final Demography demography,
final Function valueOfPerson) {
return demography
.getDistribution(this)
.items()
.map(item -> createPersonAttribute(context, valueOfPerson, item));
}
private PersonAttribute createPersonAttribute(
final RegionalContext context, final Function personValue,
final RangeDistributionItem item) {
return new PersonAttribute(context, this, item.lowerBound(), item.upperBound(), item.amount(),
personValue);
}
Stream createHouseholdAttributes(
final RegionalContext context, final Demography demography,
final Function valueOfHousehold) {
return demography
.getDistribution(this)
.items()
.map(item -> createHouseholdAttribute(context, valueOfHousehold, item));
}
private DynamicHouseholdAttribute createHouseholdAttribute(
final RegionalContext context,
final Function valueOfHousehold, final RangeDistributionItem item) {
return new DynamicHouseholdAttribute(context, this, item.lowerBound(), item.upperBound(),
item.amount(), valueOfHousehold);
}
@Override
public abstract Stream createAttributes(
final Demography demography, final RegionalContext context);
}