spur-sim / spur

Simulation for Planning and Understanding Railways
MIT License
9 stars 4 forks source link

SpurResource: custom SimPy Resource class #58

Closed peterlai1 closed 1 year ago

peterlai1 commented 1 year ago

Proposing to create a new custom class called SpurResource that inherits SimPy's native Resource class. The resource object created as a class attribute in the various Spur component constructors would now use this custom class. In addition to the environment and capacity, the custom class would also take in the component itself as a parameter upon initialization.

The main extension compared to the default Resource class would be an updated _do_put() method, where the conditions for accepting the Request event would depend on more than just the resource capacity. It would also call a new method in its component that could contain logic custom to the specific component type to decide whether to accept a new train. In other words, the train's Request (to use the resource) would only succeed if there are free usage slots within the resource capacity AND if the associated component allows the entry.

The BaseComponent class would also be modified to include this new method that inspects the state of the component and returns True / False representing whether it will allow the entry of / use by a new train. A tentative name for this method could be check_usage_eligibility().

Checklist:

peterlai1 commented 1 year ago

Closed as completed. (PR #62)