20 package org.matsim.facilities;
24 import java.util.HashMap;
25 import java.util.HashSet;
27 import java.util.Objects;
30 import org.apache.logging.log4j.LogManager;
31 import org.apache.logging.log4j.Logger;
84 this.removeLinksAndCoordinates = false ;
86 this.addEmptyActivityOptions = true ;
105 if ( oneFacilityPerLink ) {
113 this.idPrefix = prefix;
137 this.removeLinksAndCoordinates = doRemoval;
142 this.scoringConfigGroup = calcScoreConfigGroup ;
147 if (this.scoringConfigGroup != null ) {
148 if (this.addEmptyActivityOptions) {
151 log.error(
"Cannot assign opening times to activity facilities because switch to add empty activity option to activity facilities is set to false.");
162 Map<Coord, ActivityFacility> facilitiesPerCoordinate =
new HashMap<>();
165 for (
Plan plan : person.getPlans()) {
168 Activity activity = (Activity) pe;
181 if ( linkId == null ) {
194 facility = facilitiesPerLinkId.
get(linkId);
195 if (facility == null) {
198 if ( preExistingFacilityIfAny == null ){
200 facilitiesPerLinkId.
put( linkId , facility );
203 if ( Objects.equals( preExistingFacilityIfAny.
getLinkId() ,
204 linkId ) && Objects.equals( preExistingFacilityIfAny.
getCoord() , coord ) ) {
206 facility = preExistingFacilityIfAny;
208 throw new RuntimeException(
"Facility with id=" + facilityId +
" but different in coordinates and/or linkId already exists." ) ;
217 throw new RuntimeException(
"Coordinate for the activity "+activity+
" is null, cannot collect facilities per coordinate. " +
219 "instead and collect facilities per link.");
222 facility = facilitiesPerCoordinate.
get(coord);
223 if (facility == null) {
226 if ( preExistingFacilityIfAny == null ){
228 facilitiesPerCoordinate.
put( coord , facility );
231 if ( Objects.equals( preExistingFacilityIfAny.
getLinkId() , linkId ) && Objects.equals( preExistingFacilityIfAny.
getCoord() , coord ) ) {
233 facility = preExistingFacilityIfAny;
235 throw new RuntimeException(
"Facility with id=" + facilityId +
" but different in coordinates and/or linkId already exists." ) ;
241 throw new RuntimeException(
"should never get to this location; either class/method used with invalid" +
242 " setting of facilitiesSource, or something there is " +
243 "something that was not understood while implementing " +
247 if (this.addEmptyActivityOptions) {
248 String actType = activity.
getType();
250 if (option == null) {
257 if (this.removeLinksAndCoordinates) {
268 Set<String> missingActTypes =
new HashSet<>();
271 String actType = ao.getType();
273 if (params == null) {
274 if (missingActTypes.add(actType)) {
275 log.error(
"No information for activity type " + actType +
" found in given configuration.");
final ActivityFacilities facilities
Map< Id< ActivityFacility >, ? extends ActivityFacility > getFacilities()
onePerActivityLocationInPlansFile
static void assertIf(boolean flag)
ScoringConfigGroup scoringConfigGroup
void run(final Population population)
void addActivityOption(ActivityOption option)
void addActivityFacility(ActivityFacility facility)
void setFacilitiesSource(final FacilitiesSource facilitiesSource)
Collection< ActivityParams > getActivityParams()
void setOneFacilityPerLink(final boolean oneFacilityPerLink)
onePerActivityLinkInPlansFileExceptWhenCoordinatesAreGiven
void setLinkId(final Id< Link > id)
FacilitiesFromPopulation(final ActivityFacilities facilities)
Map< Id< Person >,? extends Person > getPersons()
void setIdPrefix(final String prefix)
final ScoringConfigGroup scoring()
ActivityOption createActivityOption(String type)
OptionalTime getClosingTime()
static< T > Id< T > create(final long key, final Class< T > type)
OptionalTime getOpeningTime()
ActivityFacilitiesFactory getFactory()
static Link getNearestLinkExactly(Network network, Coord coord)
final FacilitiesConfigGroup facilities()
ActivityFacility createActivityFacility(Id< ActivityFacility > id, Coord coord)
void handleActivities(final Population population)
onePerActivityLinkInPlansFile
boolean removeLinksAndCoordinates
void setAssignLinksToFacilitiesIfMissing(final Network network)
FacilitiesFromPopulation(Scenario scenario)
static void assertNotNull(Object obj)
void setAddEmptyActivityOptions(boolean addEmptyActivityOptions)
void setRemoveLinksAndCoordinates(final boolean doRemoval)
FacilitiesSource getFacilitiesSource()
void assignOpeningTimes(final ScoringConfigGroup calcScoreConfigGroup)
ActivityFacilities getActivityFacilities()
static Coord decideOnCoordForActivity(Activity act, Scenario sc)
Map< String, ActivityOption > getActivityOptions()
FacilitiesSource facilitiesSource
V put(Id< T > key, V value)
void assignOpeningTimes()
void setCoord(Coord coord)
void setFacilityId(final Id< ActivityFacility > id)
static OpeningTime createFromOptionalTimes(OptionalTime start, OptionalTime end)
boolean addEmptyActivityOptions