简体   繁体   中英

SimPy using logic to choose between one of two or more resources

How do I give a process the option of picking from two or more different resources?

I need to do this as I am simulating maintenance activities as processes, with resources representing shared facilities available to carry out maintenance. Some maintenance activities can only use one type of facility but other maintenance activities are more flexible and have the option of using multiple types of facility.

So in SimPy terms one process only has the option of choosing a single unique type of resource but other processes can choose from multiple unique types of resource.

Crude explanation of what I'm trying to achieve:

resource_A_req = resource_A.request()

resource_B_req = resource_B.request()

yield resource_A_req or resource_B_req

Would learning how to use FilterStore be the answer to my question?

yield resource_A_req | resource_B_req yield resource_A_req | resource_B_req might work for you. You then need to check which request was successful and call cancel() on the other one in order to avoid problems (search the docs for "condition events").

FilterStore might work, too. See this answer for a short example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM