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

edu.kit.ifv.mobitopp.populationsynthesis.region.DemandRegionOdPairCreator 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.region;

import static java.util.stream.Collectors.toList;

import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.Predicate;
import java.util.stream.Stream;

import edu.kit.ifv.mobitopp.data.DemandRegion;
import edu.kit.ifv.mobitopp.data.DemandZone;
import edu.kit.ifv.mobitopp.data.Zone;
import edu.kit.ifv.mobitopp.data.ZoneId;
import edu.kit.ifv.mobitopp.populationsynthesis.PersonBuilder;
import edu.kit.ifv.mobitopp.simulation.ActivityType;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class DemandRegionOdPairCreator implements DemandRegionOdPairSelector {

	private final DemandRegionRelationsRepository relationsRepository;
	private final Predicate isDestination;

	public DemandRegionOdPairCreator(
			final DemandRegionRelationsRepository relationsRepository, final ActivityType activityType) {
		super();
		this.relationsRepository = relationsRepository;
		isDestination = zone -> zone.isDestinationFor(activityType);
	}

	public static DemandRegionOdPairSelector forWork(
			final DemandRegionRelationsRepository relationsRepository) {
		return new DemandRegionOdPairCreator(relationsRepository, ActivityType.WORK);
	}

	@Override
	public Collection select(final PersonBuilder person) {
	  Set filteredZones = new TreeSet<>();
		List odPairs = getCommutingCommunitiesFor(person)
		    .flatMap(DemandRegion::zones)
				.map(DemandZone::zone)
				.peek(zone -> filteredZones.add(zone.getId()))
				.filter(isDestination)
				.peek(zone -> filteredZones.remove(zone.getId()))
				.map(d -> new OdPair(person.homeZone(), d))
				.collect(toList());
    if (odPairs.isEmpty()) {
    	log.warn(String
              .format("No destinations left for person %s. Filtered out the zones: %s",
                  person.getId(), filteredZones));
    }
    return odPairs;
	}

	private Stream getCommutingCommunitiesFor(PersonBuilder person) {
		return relationsRepository.getCommutingRegionsFrom(person.homeZone().getId());
	}

	@Override
	public void scale(DemandRegion region, int numberOfCommuters) {
		relationsRepository.scale(region, numberOfCommuters);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy