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:
[x] Create new SpurResource class
[x] Add check_usage_eligibility() to BaseComponent
[x] Update the class for the resource attribute in all components
Proposing to create a new custom class called
SpurResource
that inherits SimPy's nativeResource
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 theRequest
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'sRequest
(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 becheck_usage_eligibility()
.Checklist:
SpurResource
classcheck_usage_eligibility()
toBaseComponent
resource
attribute in all components