I am trying to model a machine having many states, similar to a Markov chain, but the transition between the states are random variables, (time to shift from a state to another). I am trying to do it on python using simpy but I am lost honestly. if anyone uses simpy and have an idea on how to proceed, I would be thankful ! thank you in advance,

1

There are 1 answers

0
Ana On

So you want your machine to randomly change between the states and then stay in that particular state for some time (also random or does each state have a specific timeout time?)? Maybe something like the code below would work for you? You assign a number to each state (state_dic) and a timeout time for each state (state_time_dic, this could also be an random number), and then in the function you see that the variable i is generated randomly. You could go through that loop as often you like.

    state_dic= {1: "state 1", 2: "state 2", 3: "state 3"}
    state_time_dic = {"state 1": 5, "state 2": 10, "state 3": 8}

    def mulit_state_system(resource):
        i = random.randint(1,4)
        if i in state_dic.keys:
        state = state_dic[i]
        with resource.request as req:
            yield req
            yield timeout(state_time_dic[state])

I did not test the code. It's just to give you an idea.