All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.kit.ifv.mobitopp.populationsynthesis.ipu.WeightedHouseholdReproducer Maven / Gradle / Ivy

Go to download

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 static java.util.stream.Collectors.toList;

import java.util.List;
import java.util.stream.Stream;

import edu.kit.ifv.mobitopp.data.PanelDataRepository;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class WeightedHouseholdReproducer implements HouseholdReproducer {

	private final List attributes;
	private final WeightedHouseholdSelector householdSelector;
  private final PanelDataRepository panelData;

  @Override
  public Stream getHouseholdsToCreate(List households) {
    return attributes.stream().flatMap(attribute -> householdsFor(attribute, households));
  }

  private Stream householdsFor(
      Attribute attribute, List households) {
    List possibleHouseholds = filterBy(attribute, households);
    int totalSum = calculateTotalSum(possibleHouseholds);
    return householdSelector.selectFrom(possibleHouseholds, totalSum).stream();
  }

  private int calculateTotalSum(List possibleHouseholds) {
    return Math
        .toIntExact(
            Math.round(possibleHouseholds.stream().mapToDouble(WeightedHousehold::weight).sum()));
  }

  private List filterBy(
      Attribute attribute, List households) {
    return households
        .stream()
        .filter(household -> 0 < attribute.valueFor(household.household(), panelData))
        .collect(toList());
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy