reinforcement learning def do(selfaction)"""updates the state based on the agent doing action returns state,reward ""if self state=="healthy"if action=="party"self state "healthyif flip( else "sickreward elseaction=="relaxself state "healthyif flip( else "sickreward elseself state=="sickif action=="party"self state "healthyif flip( else "sickreward elseself state "healthyif flip( else "sickreward return self state,reward simulating an environment from an mdp given the definition for an mdp (page )env from mdp takes in an mdp and simulates the environment with those dynamics note that the mdp does not contain enough information to simulate systembecause it loses any dependency between the rewards and the resulting statehere we assume the agent always received the average reward for the state and action rlproblem py -(continued class env_from_mdp(rl_env)def __init__(selfmdp)initial_state mdp states[ rl_env __init__(self,mdp actionsinitial_stateself mdp mdp self action_index {action:index for (index,actionin enumerate(mdp actions)self state_index {state:index for (index,statein enumerate(mdp states) def do(selfaction)"""updates the state based on the agent doing action returns state,reward ""action_ind self action_index[actionstate_ind self state_index[self stateself state pick_from_dist(self mdp trans[state_ind][action_ind]self mdp statesreward self mdp reward[state_ind][action_indversion june