MATSIM
CharyparNagelOpenTimesActivityScoring.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.deprecated.scoring.functions;
22 
23 import java.util.Iterator;
24 import java.util.Set;
25 
32 
40 @Deprecated // this version should not be used any more. Instead the SumScoringFunction variant should be used. kai, aug'18
42 
44 
45  @Deprecated // this version should not be used any more. Instead the SumScoringFunction variant should be used. kai, aug'18
47  super(params);
48  this.facilities = facilities;
49  }
50 
51  @Override
53 
54  // openInterval has two values
55  // openInterval[0] will be the opening time
56  // openInterval[1] will be the closing time
58 
59  boolean foundAct = false;
60 
61  ActivityFacility facility = this.facilities.getFacilities().get(act.getFacilityId());
62  Iterator<String> facilityActTypeIterator = facility.getActivityOptions().keySet().iterator();
63  String facilityActType = null;
64  Set<OpeningTime> opentimes = null;
65 
66  while (facilityActTypeIterator.hasNext() && !foundAct) {
67 
68  facilityActType = facilityActTypeIterator.next();
69  if (act.getType().equals(facilityActType)) {
70  foundAct = true;
71 
72  opentimes = facility.getActivityOptions().get(facilityActType).getOpeningTimes();
73  if (opentimes != null && !opentimes.isEmpty()) {
74  // ignoring lunch breaks with the following procedure:
75  // if there is only one open time interval, use it
76  // if there are two or more, use the earliest start time and the latest end time
77  double opening = Double.MAX_VALUE;
78  double closing = Double.MIN_VALUE;
79 
80  for (OpeningTime opentime : opentimes) {
81  opening = Math.min(opening, opentime.getStartTime());
82  closing = Math.max(closing, opentime.getEndTime());
83  }
84 
85  openInterval[0] = OptionalTime.defined(opening);
86  openInterval[1] = OptionalTime.defined(closing);
87  }
88 
89  }
90 
91  }
92 
93  if (!foundAct) {
94  throw new RuntimeException("No suitable facility activity type found. Aborting...");
95  }
96 
97  return openInterval;
98 
99  }
100 
101 
102 
103 }
Map< Id< ActivityFacility >, ? extends ActivityFacility > getFacilities()
static OptionalTime defined(double seconds)
Id< ActivityFacility > getFacilityId()
Map< String, ActivityOption > getActivityOptions()
CharyparNagelOpenTimesActivityScoring(final ScoringParameters params, final ActivityFacilities facilities)