Пример #1
0
    def render(self, file_name):
        fig, axs = plt.subplots(2, 1, figsize=(25, 10))
        x = np.linspace(0, self.episod_len, self.episod_len)

        _agent_list = []
        _step_balances_idx = []
        for i, f in enumerate(self.facility_names):
            if (f.startswith('SKUStoreUnit')
                    or f.startswith('OuterSKUStoreUnit')
                ) and Utils.is_consumer_agent(f):
                _agent_list.append(f)
                _step_balances_idx.append(i)
        _step_balances = [
            self.step_balances[0, :, i] for i in _step_balances_idx
        ]

        # axs[0].set_title('Global balance')
        # axs[0].plot(x, self.global_balances.T)

        axs[0].set_title('Cumulative Sum of Balance')
        axs[0].plot(x, np.cumsum(np.sum(_step_balances, axis=0)))

        axs[1].set_title('Reward Breakdown by Agent (One Episod)')
        axs[1].plot(x, np.cumsum(_step_balances, axis=0).T)
        axs[1].legend(_agent_list, loc='upper left')

        fig.savefig(file_name)
    def _actions_to_control(self, facility, actions):
        control = FacilityCell.Control(unit_price=0,
                                       production_rate=0,
                                       consumer_product_id=0,
                                       consumer_source_id=0,
                                       consumer_quantity=0,
                                       consumer_vlt=0)

        consumer_action_list = Utils.get_consumer_action_space()
        if isinstance(facility, FacilityCell):
            return control

        for agent_id, action in actions:
            # action = np.array(action).flatten()
            if Utils.is_producer_agent(agent_id):
                if isinstance(facility, SKUSupplierUnit):
                    control.production_rate = facility.sku_info[
                        'production_rate']
            if Utils.is_consumer_agent(agent_id):
                product_id = facility.bom.output_product_id
                control.consumer_product_id = product_id
                if facility.consumer.sources is not None:
                    source = facility.consumer.sources[0]
                    control.consumer_vlt = source.sku_info['vlt']
                    control.consumer_source_id = 0  # action[0]
                control.consumer_quantity = int(consumer_action_list[action] *
                                                facility.get_sale_mean())
        return control
Пример #3
0
 def get_retailer_profit(self):
     _agent_list = []
     _step_balances_idx = []
     for i, f in enumerate(self.facility_names):
         if f.startswith('RetailerCell') and Utils.is_consumer_agent(f):
             _agent_list.append(f)
             _step_balances_idx.append(i)
     _step_balances = [
         self.step_balances[0, :, i] for i in _step_balances_idx
     ]
     return np.sum(_step_balances)
Пример #4
0
 def load_policy(agent_id):
     if Utils.is_producer_agent(agent_id):
         return ProducerBaselinePolicy(
             env.observation_space, env.action_space_producer,
             BaselinePolicy.get_config_from_env(env))
     elif Utils.is_consumer_agent(agent_id):
         return ConsumerMinMaxPolicy(
             env.observation_space, env.action_space_consumer,
             BaselinePolicy.get_config_from_env(env))
     else:
         raise Exception(f'Unknown agent type {agent_id}')