You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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:
I have tried the following functions. It worked well for most of the cases. However, it turned out that it causes unexpected, very counter intuitive errors in some cases. There must be workarounds, but I now believe modifying these fundamental functions just for convenience is not very wise. Therefore, I abandon this plan
def __eq__(self, other):
"""
Override `==` operator to compare objects by name as well as object itself.
"""
if isinstance(other, str):
return self.name == other
elif isinstance(other, Vehicle):
return self.name == other.name
return False
def __hash__(self):
"""
Override hash function, in order to make dict of objects can be accessible by their name as well.
"""
return hash(self.name)
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 likenode == "node_name"
holds true ifnode.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.The text was updated successfully, but these errors were encountered: