MATSIM
FacilityOpeningIntervalCalculator.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * CharyparNagelOpenTimesScoringFunction.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2007 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 
21 package org.matsim.core.scoring.functions;
22 
23 import java.util.Iterator;
24 import java.util.Set;
25 
31 
40 
42 
44  this.facilities = facilities;
45  }
46 
47  @Override
49 
50  // openInterval has two values
51  // openInterval[0] will be the opening time
52  // openInterval[1] will be the closing time
54 
55  boolean foundAct = false;
56 
57  ActivityFacility facility = this.facilities.getFacilities().get(act.getFacilityId());
58  Iterator<String> facilityActTypeIterator = facility.getActivityOptions().keySet().iterator();
59  String facilityActType = null;
60  Set<OpeningTime> opentimes = null;
61 
62  while (facilityActTypeIterator.hasNext() && !foundAct) {
63 
64  facilityActType = facilityActTypeIterator.next();
65  if (act.getType().equals(facilityActType)) {
66  foundAct = true;
67 
68  opentimes = facility.getActivityOptions().get(facilityActType).getOpeningTimes();
69  if (opentimes != null && !opentimes.isEmpty()) {
70  // ignoring lunch breaks with the following procedure:
71  // if there is only one open time interval, use it
72  // if there are two or more, use the earliest start time and the latest end time
73  double opening = Double.MAX_VALUE;
74  double closing = Double.MIN_VALUE;
75 
76  for (OpeningTime opentime : opentimes) {
77  opening = Math.min(opening, opentime.getStartTime());
78  closing = Math.max(closing, opentime.getEndTime());
79  }
80 
81  openInterval[0] = OptionalTime.defined(opening);
82  openInterval[1] = OptionalTime.defined(closing);
83  }
84 
85  }
86 
87  }
88 
89  if (!foundAct) {
90  throw new RuntimeException("No suitable facility activity type found. Aborting...");
91  }
92 
93  return openInterval;
94 
95  }
96 
97 
98 
99 }
Map< Id< ActivityFacility >, ? extends ActivityFacility > getFacilities()
static OptionalTime defined(double seconds)
Id< ActivityFacility > getFacilityId()
Map< String, ActivityOption > getActivityOptions()