Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: consecutiveTime is misleading for unordered trainruns #319

Closed
3 tasks done
shenriotpro opened this issue Oct 22, 2024 · 4 comments
Closed
3 tasks done

[Bug]: consecutiveTime is misleading for unordered trainruns #319

shenriotpro opened this issue Oct 22, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@shenriotpro
Copy link
Contributor

Preflight Checklist

Bug type

Functionality

Which version are you using

2.8.0

Operating system

No response

Browser / Browser version

No response

Input mode

None

Additional settings

No response

What happened?

Describe in detail the issue you are having.
What did you expect to happen? What happened instead? What would you like to see changed?
Is the issue related to a specific component?

Steps to reproduce the issue

  1. Trace a first trainrun section
  2. Trace a second trainrun section, from the same source node
  3. Export the JSON and look at consecutiveTimes

Relevant log output

"trainrunSections": [
        {
            "id": 1,
            "sourceNodeId": 7,
            "sourcePortId": 1,
            "targetNodeId": 1,
            "targetPortId": 2,
            "travelTime": {
                "time": 1,
                "consecutiveTime": 1,
                "lock": true,
                "warning": null,
                "timeFormatter": null
            },
            "sourceDeparture": {
                "time": 0,
                "consecutiveTime": 60,
                "lock": false,
                "warning": null,
                "timeFormatter": null
            },
            "sourceArrival": {
                "time": 0,
                "consecutiveTime": 120,
                "lock": false,
                "warning": null,
                "timeFormatter": null
            },
            "targetDeparture": {
                "time": 59,
                "consecutiveTime": 119,
                "lock": false,
                "warning": null,
                "timeFormatter": null
            },
            "targetArrival": {
                "time": 1,
                "consecutiveTime": 61,
                "lock": false,
                "warning": null,
                "timeFormatter": null
            },
            "numberOfStops": 0,
            "trainrunId": 1,
            "resourceId": 0,
            "specificTrainrunSectionFrequencyId": null,
            "path": ...,
            "warnings": null
        },
        {
            "id": 2,
            "sourceNodeId": 7,
            "sourcePortId": 3,
            "targetNodeId": 8,
            "targetPortId": 4,
            "travelTime": {
                "time": 1,
                "consecutiveTime": 1,
                "lock": true,
                "warning": null,
                "timeFormatter": null
            },
            "sourceDeparture": {
                "time": 2,
                "consecutiveTime": 122,
                "lock": false,
                "warning": null,
                "timeFormatter": null
            },
            "sourceArrival": {
                "time": 58,
                "consecutiveTime": 58,
                "lock": false,
                "warning": null,
                "timeFormatter": null
            },
            "targetDeparture": {
                "time": 57,
                "consecutiveTime": 57,
                "lock": false,
                "warning": null,
                "timeFormatter": null
            },
            "targetArrival": {
                "time": 3,
                "consecutiveTime": 123,
                "lock": false,
                "warning": null,
                "timeFormatter": null
            },
            "numberOfStops": 0,
            "trainrunId": 1,
            "resourceId": 0,
            "specificTrainrunSectionFrequencyId": null,
            "path": ...,
            "warnings": null
        }
    ],
@shenriotpro shenriotpro added the bug Something isn't working label Oct 22, 2024
@shenriotpro
Copy link
Contributor Author

related: #285 and #312

@aiAdrian
Copy link
Collaborator

aiAdrian commented Oct 23, 2024

To understand how traversing the trainrun works, please also take a look at this figure:

image

More information can be found at https://github.com/SchweizerischeBundesbahnen/netzgrafik-editor-frontend/blob/main/documentation/DATA_MODEL.md#data-model

The TrainrunIterator operates over a structure that can be conceptualized as an undirected acyclic graph (DAG), where each trainrun is a connected component.

Structure

  • TrainrunSection: Each section has a source and a target node, analogous to an edge in a graph.
  • Node: Nodes manage connections through ports, effectively acting as junction points within the graph.
  • Transition: Transitions are internal connections within nodes, linking two trainrun sections through ports.

Traversal

  • Start from a given node and trainrun section.
  • The orientation (direction) is determined by the tuple of the node and trainrun section. This tuple can be interpreted as the oriented edge that points towards another node. For example, if the given node is the source node, the iterator moves towards the target node; if the node is the target node, the iterator moves towards the source node.
  • When reaching a transition, continue traversing through the next connected section.
  • Stop when no further transitions are available.

The TrainrunIterator can effectively traverse through the trainrun sections by leveraging the source and target nodes of each section. This approach removes the need to explicitly define a direction and uses the inherent structure of the trainrun sections and nodes to guide the traversal. By managing transitions within nodes and ensuring each section is visited once, the iterator can navigate through the entire trainrun efficiently.

@aiAdrian
Copy link
Collaborator

aiAdrian commented Oct 23, 2024

TrainrunIterator

The TrainrunIterator is a concept aimed at iterating through the sections of a trainrun, similar to how one navigates through the edges of a graph. Here is a detailed description of how this iterator works and how it can be used:

Structure of the Trainrun

  • TrainrunSection: Each section has a source node and a target node, connected by ports. These sections function similarly to edges in a graph.
  • Node: Nodes manage the ports and serve as connection points within the graph.
  • Transition: Transitions are internal connections within a node that link two trainrun sections through ports.
  • Graph: The entire graph is generally an undirected acyclic graph (DAG). Each trainrun (segment) represents a connected component.

Traversal Logic

  • Starting Point: Iteration begins with a given node ID and a specific trainrun section.
  • Section Connection: The iterator moves through connected sections by utilizing the source and target nodes of each section.
  • Transitions: When a transition is reached, the next connected section is followed through the corresponding port.
  • End of Traversal: Iteration ends when no further sections or transitions are available.

Example Application

  • Initialization: The iterator is initialized with a start node ID and a specific trainrun section.
  • Forward Traversal: The iterator moves from section to section by navigating from one node to the next. During traversal, the source and target nodes of the sections are used to determine the path.
  • Backward Traversal: To traverse in the opposite direction, the iterator can be re-initialized with the end node ID of the current traversal and the corresponding trainrun section. This reverses the path and allows a return to the starting point.

Detailed Steps

  1. Start with a Node ID and a Trainrun Section: The iterator begins with a defined node ID and a specific trainrun section. This represents the starting point.
  2. Section-wise Traversal: The iterator traverses the sections by using the connections between the nodes. It moves from the source node to the target node of a section.
  3. Handling Transitions: When a transition within a node is reached, the iterator follows the transition to the next connected section.
  4. Traversal End: Iteration ends when no further connected sections or transitions are available. This signals the end of the trainrun.

Summary

The TrainrunIterator enables structured traversal through the sections of a trainrun by using both a node ID and a specific trainrun section as a starting point. This increases the precision and flexibility of the traversal. By utilizing the source and target nodes of each section and following transitions within the nodes, the iterator can efficiently navigate through the entire trainrun. This method is particularly useful for traversing complex trainrun paths and ensuring that the traversal logic is correctly understood and applied both forwards and backwards.

If functionality should be initiated by providing a port ID, this could be a further extension allowing a start directly from a specific port. However, this functionality is not yet implemented.

@shenriotpro
Copy link
Contributor Author

Closing this since I had misunderstood consecutiveTime: it makes sense to start from 57 here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants