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)) if agent_id.startswith('SKUStoreUnit') or agent_id.startswith('OuterSKUStoreUnit'): return ConsumerEOQPolicy(env.observation_space, env.action_space_consumer, BaselinePolicy.get_config_from_env(env)) else: return ConsumerBaselinePolicy(env.observation_space, env.action_space_consumer, BaselinePolicy.get_config_from_env(env))
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
def policy_map_fn(agent_id): if Utils.is_producer_agent(agent_id): return 'baseline_producer' else: if agent_id.startswith('SKUStoreUnit') or agent_id.startswith('OuterSKUStoreUnit'): return 'dqn_store_consumer' else: return 'baseline_consumer'
def load_base_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)) else: return ConsumerBaselinePolicy( env.observation_space, env.action_space_consumer, BaselinePolicy.get_config_from_env(env))
def load_policy(agent_id): _facility = env.world.facilities[Utils.agentid_to_fid(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 isinstance(_facility, SKUStoreUnit) or isinstance(_facility, SKUWarehouseUnit): elif isinstance(_facility, SKUStoreUnit): policy = ConsumerBaseStockPolicy(env.observation_space, env.action_space_consumer, BaselinePolicy.get_config_from_env(env), is_static) return policy else: return ConsumerBaselinePolicy(env.observation_space, env.action_space_consumer, BaselinePolicy.get_config_from_env(env))
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}')
def load_policy(agent_id): agent_echelon = env.world.agent_echelon[Utils.agentid_to_fid(agent_id)] if Utils.is_producer_agent(agent_id): policy_name = 'baseline_producer' else: if agent_echelon == total_echelon - 1: policy_name = 'ppo_store_consumer' else: if agent_echelon >= total_echelon-echelon_to_train: policy_name = 'ppo_warehouse_consumer' else: policy_name = 'baseline_consumer' return ppo_trainer.get_policy(policy_name)
def echelon_policy_map_fn(echelon, agent_id): facility_id = Utils.agentid_to_fid(agent_id) if Utils.is_producer_agent(agent_id): return 'baseline_producer' else: agent_echelon = env.world.agent_echelon[facility_id] if agent_echelon == 0: # supplier return 'baseline_consumer' elif agent_echelon == env.world.total_echelon - 1: # retailer return 'ppo_store_consumer' elif agent_echelon >= echelon: # warehouse and current layer is trainning or has been trained. return 'ppo_warehouse_consumer' else: # warehouse on layers that haven't been trained yet return 'baseline_consumer'