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

Initial support for areas #106

Closed
wants to merge 1 commit into from
Closed

Initial support for areas #106

wants to merge 1 commit into from

Conversation

EwoutH
Copy link
Contributor

@EwoutH EwoutH commented Aug 18, 2024

This PR adds initial support for Areas in UXsim. I approached it in the following way:

  • Introduced a new area attribute in the Node class to define the area a node belongs to.
  • Modified the __init__ method of the Node class to accept an optional area parameter.
  • Added W.NODES_AREA_DICT to store nodes grouped by their respective areas.
  • Implemented update_nodes_area_dict() to populate the area dictionary with nodes.
  • Added a method get_random_node_in_area() to retrieve a random node within a specified area.
  • Updated finalize_scenario() to call update_nodes_area_dict() ensuring the area dictionary is up to date.

In my model, I use it like this:

When adding the nodes to the model, I define the area keyword

# Create Nodes in UXsim from OSMnx graph nodes
for node_id, data in road_network.nodes(data=True):
    mrdh65 = data1.pc4_to_mrdh65[int(data['postcode'])]
    world.addNode(name=str(node_id), x=data['x'], y=data['y'], area=mrdh65)

When planning trips, I ask to get a random node from an area, which I use as starting point.

starting_node = self.model.uxsim_world.get_random_node_in_area(self.mrdh65)
target_node = self.model.uxsim_world.get_random_node_in_area(destination)

# Add the car trip to the UXsim world
self.model.uxsim_world.addVehicle(orig=starting_node, dest=target_node, departure_time=self.model.simulator.time)

More features could be added. But before I develop this further, I would like to know @toruseo if this is a desired development direction.

I could also understand that you want to approach this subject differently, by making Areas objects or by tracking areas in a different way.

Part of #102.

- Introduced a new `area` attribute in the `Node` class to define the area a node belongs to.
- Modified the `__init__` method of the `Node` class to accept an optional `area` parameter.
- Added `W.NODES_AREA_DICT` to store nodes grouped by their respective areas.
- Implemented `update_nodes_area_dict()` to populate the area dictionary with nodes.
- Added a method `get_random_node_in_area()` to retrieve a random node within a specified area.
- Updated `finalize_scenario()` to call `update_nodes_area_dict()` ensuring the area dictionary is up to date.
@toruseo
Copy link
Owner

toruseo commented Aug 19, 2024

Thank you very much for your effort.

But I think "area" variable is better to be defined more generally and should not depends on the simulator too much. This is because "area" will be useful as a input and output for the simulation but will not be utilized by the simulation model itself.

For example, a node may belong to multiple areas in general (e.g., an intersection belong to a city and a prefecture). But for some particular purposes, areas need to be mutually exclusive. Therefore, I think it is better to leave this kind of setting to the users rather than implementing it within the simulator

I think I can implement them today.

@EwoutH
Copy link
Contributor Author

EwoutH commented Aug 19, 2024

Thanks for getting back! I agree adding only one single area per node might be a bit limiting.

I will open a separate PR to add get_random_node_in_area as util.

@EwoutH
Copy link
Contributor Author

EwoutH commented Aug 19, 2024

For reference, this is what I needed to do to work with the latest uxsim (that being 4687807):

So I think you made the right call: The attribute is useful, and I didn't need to add too much code on my part.

@EwoutH
Copy link
Contributor Author

EwoutH commented Aug 19, 2024

Closing this PR, as current functionality is either enclosed in current UXsim or can easily be added like shown above.

@EwoutH EwoutH closed this Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants