toruseo / UXsim

Vehicular traffic flow simulator in road network, written in pure Python
https://toruseo.jp/UXsim/docs/
MIT License
121 stars 56 forks source link

Override `__eq__` methods of `Node` and other UXsim object? #135

Open toruseo opened 3 days ago

toruseo commented 3 days ago

Currently we can specify Node (or Link, Vehicle) by Node object itself or its name which is str. This is sometimes confusing and causes a bug. It may be possible to solve this issue by overriding __eq__ method (==) properly so that something like node == "node_name" holds true if node.name = "node_name".

Also, it will be great if we can use Node object and node name as a dictionary key interchangeably.

But I am not familiar to overriding __eq__ method, so this requires some study.

EwoutH commented 3 days ago

I have found it confusing at times that the Node id and name are used in different situations. I would suggest always using the id in UXsim internally, and leaving the name just for something the user can use to track different nodes.

We recently had a similar discussion over at Mesa, it might be interesting:

toruseo commented 3 days ago

yes, that is also confusing. Refactoring the internal code will be difficult, but let me think if there are feasible solutions.

Thanks for the info too. It is interesting that many people are facing similar issues.