Created
February 11, 2020 15:59
-
-
Save ikatsov/d4b7ec98ef7b8716da9d22880918bc23 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 SupplyChainEnvironment(object): | |
| ... | |
| def step(self, state, action): | |
| demands = np.fromfunction(lambda j: self.demand(j+1, self.t), (self.warehouse_num,)) | |
| # Calculating the reward (profit) | |
| total_revenue = self.unit_price * np.sum(demands) | |
| total_production_cost = self.unit_cost * action.production_level | |
| total_storage_cost = np.dot( self.storage_costs, | |
| np.maximum(state.stock_levels(), np.zeros(self.warehouse_num + 1)) ) | |
| total_penalty_cost = - self.penalty_unit_cost * ( | |
| np.sum( np.minimum(state.warehouse_stock, | |
| np.zeros(self.warehouse_num)) ) + | |
| min(state.factory_stock, 0) ) | |
| total_transportation_cost = np.dot( self.transporation_costs, | |
| action.shippings_to_warehouses ) | |
| reward = total_revenue - total_production_cost - total_storage_cost | |
| - total_penalty_cost - total_transportation_cost | |
| # Calculating the next state | |
| next_state = State(self.warehouse_num, self.T, self.t) | |
| next_state.factory_stock = min(state.factory_stock + action.production_level - | |
| np.sum(action.shippings_to_warehouses), | |
| self.storage_capacities[0]) | |
| for w in range(self.warehouse_num): | |
| next_state.warehouse_stock[w] = min(state.warehouse_stock[w] + | |
| action.shippings_to_warehouses[w] - | |
| demands[w], self.storage_capacities[w+1]) | |
| next_state.demand_history = list(self.demand_history) | |
| self.t += 1 | |
| self.demand_history.append(demands) | |
| return next_state, reward, self.t == self.T - 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment