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

Feature requrest: Estimate and record trip travel times #45

Open
1 of 2 tasks
EwoutH opened this issue Mar 21, 2024 · 3 comments
Open
1 of 2 tasks

Feature requrest: Estimate and record trip travel times #45

EwoutH opened this issue Mar 21, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@EwoutH
Copy link
Contributor

EwoutH commented Mar 21, 2024

It would be a very useful feature for me to be able to estimate and record travel times of trips in UXsim.

  • Estimate the expected travel time based on the current state of the network.
  • Record the final travel time a trip took.

The first one can be used to make decisions on (for agents making a mode choice for example), the second can be usefull as metric / KPI.

@toruseo
Copy link
Owner

toruseo commented Mar 21, 2024

They are available :)

Record the final travel time a trip took.

This is already implemented. Vehicle.travel_time records its trip travel time. Or, you can output all vehicles' detailed travel logs by World.analyzer.vehicles_to_pandas() and analyze anything as you want.

Estimate the expected travel time based on the current state of the network.

For this, so-called "instantaneous travel time" may be useful. Link.instant_travel_time(t) returns one for that link on time t. In fact, vehicles in UXsim basically uses this information for their routing.

@EwoutH
Copy link
Contributor Author

EwoutH commented Mar 21, 2024

Vehicle.travel_time records its trip travel time.

I missed that, thanks!

so-called "instantaneous travel time" may be useful.

Do you think it would be useful to have a function that returns that total value for the shortest route from some node A to some node B? For example, if I'm an agent deciding to go by car or by bike from A to B, I might want to check what the current travel time is from A to B by car to base my decision on.

@toruseo
Copy link
Owner

toruseo commented Mar 22, 2024

That is not difficult. You can create a graph whose link cost is Link.instant_travel_time(t) and then perform shortest path search.

RouteChoice.route_search_all() is doing very similar thing, so it can be a basis for that. Maybe adding the following function to RouteChoice can work. I havent tested it at all, so please check carefully.

    def route_search_all_on_time(s, t, infty=np.inf):
        """
        Compute the current shortest path based on instantanious travel time on time t.
        Experimental, not tested.

        Parameters
        ----------
        t : float
            Time in seconds.
        infty : float
            value representing infinity.
            
        Returns
        -------
        np.array
            The distance matrix. dist[i,j] is the shortest distance from node i to node j.
        """
        adj_mat_time = np.zeros([len(s.W.NODES), len(s.W.NODES)])
        for link in s.W.LINKS:
            i = link.start_node.id
            j = link.end_node.id
            if s.W.ADJ_MAT[i,j]:
                adj_mat_time[i,j] = link.instant_travel_time(t) + link.route_choice_penalty #TODO: link.route_choice_penalty may be time-dependent
                if link.capacity_in == 0: #流入禁止の場合は通行不可
                    adj_mat_time[i,j] = np.inf
            else:
                adj_mat_time[i,j] = np.inf

        dist, pred = floyd_warshall(adj_mat_time, return_predecessors=True)

        return dist 

@toruseo toruseo added the enhancement New feature or request label Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants