Created
February 11, 2020 16:28
-
-
Save ikatsov/201f61105eb6096477aa51856c6575ad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SQPolicy(object): | |
| def __init__(self, factory_safety_stock, | |
| factory_reorder_amount, safety_stock, reorder_amount): | |
| self.factory_safety_stock = factory_safety_stock | |
| self.factory_reorder_amount = factory_reorder_amount | |
| self.safety_stock = safety_stock | |
| self.reorder_amount = reorder_amount | |
| def select_action(self, state): | |
| action = Action(state.warehouse_num) | |
| for w in range(state.warehouse_num): | |
| if state.warehouse_stock[w] < self.safety_stock[w]: | |
| action.shippings_to_warehouses[w] = self.reorder_amount[w] | |
| if state.factory_stock - np.sum(action.shippings_to_warehouses) < self.factory_safety_stock: | |
| action.production_level = self.factory_reorder_amount | |
| else: | |
| action.production_level = 0 | |
| return action | |
| def simulate_episode(env, policy): | |
| state = env.initial_state() | |
| transitions = [] | |
| for t in range(env.T): | |
| action = policy.select_action(state) | |
| state, reward, _ = env.step(state, action) | |
| transitions.append([state, action, reward]) | |
| return transitions | |
| # Basic policy evaluation process | |
| def simulate(env, policy, num_episodes): | |
| returns_trace = [] | |
| for episode in range(num_episodes): | |
| env.reset() | |
| returns_trace.append( sum(np.array(simulate_episode(env, policy)).T[2]) ) | |
| return returns_trace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment