Skip to content

Commit 6f37022

Browse files
committed
doc: Add design doc calendar
1 parent ccd2ddc commit 6f37022

File tree

6 files changed

+186
-16
lines changed

6 files changed

+186
-16
lines changed

ARCHITECTURE.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ Be sure to also read the [developer documentation](docs/Developers-Guide.md).
1616
## Modules/Components
1717

1818
Below is a list of documented components in OTP. Not every component is documented at a high level,
19-
but this is a start and we would like to expand this list in the future.
19+
but this is a start, and we would like to expand this list in the future.
20+
21+
22+
### [OTP Transit Model](src/main/java/org/opentripplanner/transit/model/package.md)
23+
24+
Sometimes also referred to as the internal transit model. This is OTPs internal model witch is a
25+
unified model of GTFS and Transmodel(NeTEx) relevant for OTP. The model is optimized for transit
26+
routing.
2027

2128
### [OTP Configuration design](src/main/java/org/opentripplanner/standalone/config/package.md)
2229

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Transit Calendar Model
2+
3+
4+
![Transit Calendar](transit-calendar-diagram.png)
5+
6+
### PatternsForDay
7+
8+
For a given day(start at 04:00 until 04:00+1d), list all patterns relevant for boarding or
9+
alighting on that day. A PatternForDay is included If it runs on that day. When searching for a
10+
pattern, we might have to look at the next or previous day to find an instance e can use as a
11+
starting point for the boarding search.
12+
13+
OTPs internal model will use a fixed time and time zone for all alight and board times. It do not
14+
follow the imported agency/operator time-zone or service time. We will keep enough information to
15+
be able to map back to the service time of the operator/agency. This is important to be able to
16+
match these in real-time updates.
17+
18+
19+
20+
## Use Cases/Features
21+
22+
Below are some main important features described.
23+
24+
25+
### Pattens Filtering
26+
27+
- Describe the use of BitSet for filtering
28+
- Filtering with request parameters (modes, agencies, lines)
29+
- Filtering to find active patterns for stops reached in last round in Raptor
30+
- Optimizations:
31+
- BitSets should be deduplicated
32+
- A Set can be used to combine all BitSets to eliminate BitSet merge operations
33+
- Cache `merge(stop : BitSet, activePatterns : BitSet) -> BitSet`. Many stops will have the same
34+
set of visiting patterns.
35+
36+
We can use patternMask to find all relevant patterns in a multi-day search - supporting journeys
37+
ending in another day. There is no need to distinguish between scheduled and realtime patterns for
38+
this, just make sure we include the super set.
187 KB
Loading
58.6 KB
Loading
-1.96 KB
Loading

src/main/java/org/opentripplanner/transit/model/package.md

Lines changed: 140 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,34 @@ VICE VERSA.
99
- We will go over and make a "none draft" when it is time for review.
1010

1111

12-
![OTP Model Overview](OTPModelOverview.png)
12+
## Notation
1313

14-
(THIS IS WORK IN PROGRESS! The packages are probably almost ok, but the dependencies are not...)
14+
### Diagram notations
1515

16+
Here is an example explaining most of the notation used in the diagrams.
1617

17-
## Notation
18+
![Class Diagram Example](class-diagram-example.png)
19+
20+
- `A ––––– B` Strong reference. There is a relationship between A and B. A and B may reference
21+
each other, but the details are left to the implementation.
22+
- `A ––––> B` Strong reference. There is a relationship between A and B. A has a reference to B.
23+
- `A – – > B` Weak reference/uses: A uses B.
24+
- Composition - `A ♦︎–> B` B is part of A and B is bound to the life-cycle of A.
25+
- Aggregation - `A ♢–> B` B is part of A, but may live when A dies. B is shared.
26+
- The **calendar** package is the main package with all classes inside and its relations outside.
27+
- `(o.o.t.m.network)` means this class belong to the `org.opentripplanner.transit.model.network`
28+
package.
29+
- `<< classifier >>` Used to mark interfaces or group types
30+
- `: RaptorTripPattern` means this class implements/extends `RaptorTripPattern`.
31+
- `(o.o.t.m.network)` means this class belong to the `org.opentripplanner.transit.model.network`
32+
package.
33+
- `#patternIndex` - The pattern is indexed using an [integer index](#indexing-the-main-entities)
1834

19-
UML Diagrams are used to illustrate the model. Colors are used to emphasise relationships,
20-
similarities or just visual grouping. For class diagrams we use a modified version of
35+
36+
### UML Modeling in color
37+
38+
UML Diagrams are used to illustrate the model. Colors are used to emphasise relationships,
39+
similarities or just visual grouping. For class diagrams we use a modified version of
2140
[Object Modeling in Color](https://en.wikipedia.org/wiki/Object_Modeling_in_Color).
2241

2342
![UML Modeling in color](model-in-color.png)
@@ -30,37 +49,103 @@ The colors indicate:
3049
- Lifecycle
3150
- Blue(descriptions) - live forever
3251
- Green(entities…) - live for a long time, but may change over time
33-
- Read(Moment/Interval/Event) Live until the next realtime update
52+
- Read(Moment/Interval/Event) - live until the next realtime update
3453
- Orange - live in the scope of a request - a very short time
35-
- Dependencies - Long lived types should not reference short-lived types:
36-
- Yellow Orange Red Green Blue
54+
- Dependencies - Be careful when referencing short-lived type from long-lived types
55+
- Safe: Yellow Orange Red Green Blue
3756
- Not relevant for Purple
3857

3958

40-
## Components
59+
### 🚧 TODOs
60+
61+
The issue [#4002 - Transit model refactor for easier integration with RT-updaters and transit model maintenance](https://github.com/opentripplanner/OpenTripPlanner/issues/4002) contains a list of reminding tasks. Also, a lot of code is tagged with:
62+
63+
- `TODO RTM` - Refactor Transit Model
64+
65+
66+
### ⚠️ Missing from the model
67+
68+
Some concepts and features are excluded from most of the design models - for simplicity. This is
69+
of cause not excluded from the code, but we focus on serving the main use-case - Raptor routing.
70+
71+
#### Missing concepts
72+
73+
- Mutable part of the model used by realtime updaters.
74+
- Views and indexes making it easier for APIs to traverse the model.
75+
- The model focus on relationships, not exact listing of fields and methods.
76+
- Some fields and methods are included to give the reader a better context, but not all.
4177

42-
This is the top level package structure
4378

44-
- [framework](framework/package.md) - framework to support the transit model
45-
- basic - Value objects used across multiple packages.
46-
- organization
79+
#### Missing Features
80+
81+
- Wheelchair accessibility
82+
- Constrained transfers
83+
84+
85+
## Use Cases to supported
86+
87+
- Raptor search
88+
- w/ realtime, ignore realtime, include planned-cancellations
89+
- Realtime updates
90+
- Cancel: Trip, Stop, Call(cancel either alighting or boarding, not both)
91+
- Replace/update: Trip, Stop, Call (update on arrival and/or departure times)
92+
- Insert/add: Trip, Stop, (Call, if it does not exist)
93+
- Planned information is kept and it should be possible to revert to planned, previous update is not
94+
95+
- Index (API data queries)
96+
- query(get, find, list) for all entities (Agency, Operator, Route, Trip, Stop ...)
97+
- list Routes, Trips, TripPatterns for stop
98+
- list Rotes, Trips, Calls for a stop in a given period of time
99+
- Frequency based and scheduled trips
100+
- Support late platform assignment
101+
- Support for routing with at least N seats. This requires request scoped patterns.
102+
103+
104+
105+
## Components (main packages)
106+
107+
The diagram show the main access point(`TransitService`) and the main packages and their
108+
dependencies.
109+
110+
![OTP transit model package structure](overview.png)
111+
112+
(THIS IS WORK IN PROGRESS! The packages are probably almost ok, but the dependencies are not...)
113+
114+
115+
- [framework](framework/package.md) - framework to support other transit model classes.
116+
- basic - Value objects used across multiple packages.
117+
- organization - Agency(*Authority*), operator and contact info
47118
- site - StopLocation, RegularStop and Station +++
48-
- organization - Authority, Operator and booking info
49119
- network - Route
50120
- trip - Trip and TripOnDate
51121
- transfers - Regular and constrained transfer information
52-
- calendar - Operating days and patterns on day
122+
- [calendar](calendar/package.md) - Operating days and patterns on day
53123
- timetable - Trip times for one operating day and trip schedule search
54124
- trip schedule??? To avoid circular dependencies we might need to join trip and timetable
55125
- plan - Support trip planning by implementing Raptor SPI. This is the main entry point.
56126

57127
## Plan query
128+
58129
The plan query is number ONE reason why OTP exist, and the primary design goal of the transit model
59130
is to support the plan query to be as efficient "as possible".
60131

61132

62133
TODO RTM - Add an object diagram witch show the main types involved in a Raptor trip plan query.
63134

135+
Main outline of Raptor[1] Algorithm
136+
137+
- Find the set of patterns[2] matching the request (q : BitSet = pattern indexes)
138+
- Set access times for stops S reached
139+
- Loop N times [3]:
140+
- For all patterns visiting stops with new arrivals
141+
- Board best trip in pattern
142+
- Alight at each stop in pattern
143+
- transfer from all stops reach by transit
144+
145+
1. Raptor, not Range Raptor(not relevant here)
146+
2. By pattern here we mean RaptorTripPattern/RoutingTripPattern
147+
3. N is the max number of transfers in the network
148+
64149

65150
## Services and its context
66151

@@ -77,6 +162,46 @@ are made active by calling the `commit()` on the context. Before the `commit()`
77162
visible by e.g. the routing. [TODO Diagram]
78163

79164

165+
## Indexing the main entities
166+
167+
Indexes is used to speed up the plan search. For most indexes we can use regular maps and
168+
references between entities. But, in some cases we want to optimize, and we use `int` based
169+
indexes. For example Raptor keep stop arrivals in big arrays - so Raptor expect the transit model
170+
to pass in a stop index as an int, not the stop reference. In fact, Raptor never access the actual
171+
Stop instance during the search.
172+
173+
% is used as a prefix on fields and methods added to improve performance.
174+
175+
OTP uses int indexes for calendar-intervals, stops, trips, and trip patterns. These indexes allow
176+
us to avoid accessing these objects during the trip routing, and instead look these objects by
177+
their indexes after the search - when creating the itineraries.
178+
179+
180+
### `#stopIndex`
181+
182+
All stops are indexed, raptor do not access stops. Raptor keep its state in an array of stop
183+
arrivals, this matches the stop index.
184+
185+
186+
### `#dayIndex`
187+
188+
The transit data model is broken into ~24h "periods"s or *operating days*, we reference these
189+
intervals using the **#dayIndex**.
190+
191+
192+
### `#tripIndex` - TODO RTM
193+
194+
Both a trip reference and an index is returned by Raptor for each transit leg today. We should be
195+
able to use only the index.
196+
197+
198+
### `#patternIndex`
199+
200+
RaptorTripPattern are indexed, this allows us to use BitSet to represent a set of patterns. This
201+
comes in handy when we want to find all patterns for a set of stops.
202+
203+
204+
80205
## Support for real-time updates
81206

82207
### RT-Notes

0 commit comments

Comments
 (0)