Пример #1
0
    def cache_data(self):
        self.df = self._read_df()
        self._transfer_to_daily_sale()
        # id_list = self.df[self.id_col].unique().tolist()
        id_list = Utils.get_all_skus()
        dt_min, dt_max = self.df[self.dt_col].min(), self.df[self.dt_col].max()
        self.total_span = (dt_max - dt_min).days + 1

        for id_val in id_list:
            df_tmp = self.df[self.df[self.id_col] == id_val]
            df_tmp[f"{self.dt_col}_str"] = df_tmp[self.dt_col].map(
                lambda x: x.strftime(self.dt_format))
            sale_cache_tmp = df_tmp.set_index(f"{self.dt_col}_str").to_dict(
                'dict')[self.sale_col]
            sale_price_cache_tmp = df_tmp.set_index(
                f"{self.dt_col}_str").to_dict('dict')[self.sale_price_col]
            date_cache_tmp = df_tmp.set_index(f"{self.dt_col}_str").to_dict(
                'dict')[self.dt_col]
            dt_tmp = dt_min
            self.sale_ts_cache[id_val] = []
            self.sale_price_ts_cache[id_val] = []
            self.date_cache[id_val] = []
            self.sale_mean[id_val] = df_tmp[self.sale_col].mean()
            sale_price_mean = df_tmp[self.sale_price_col].mean()
            while dt_tmp <= dt_max:
                dt_tmp_str = datetime.strftime(dt_tmp, self.dt_format)
                if sale_cache_tmp.get(dt_tmp_str) == None:
                    print(f"this day is lose in dataset: {dt_tmp_str}")
                    #print(f"press any key to continue ...")
                    #input()
                self.sale_ts_cache[id_val].append(
                    sale_cache_tmp.get(dt_tmp_str, 0))
                self.sale_price_ts_cache[id_val].append(
                    sale_price_cache_tmp.get(dt_tmp_str, sale_price_mean))
                self.date_cache[id_val].append(
                    date_cache_tmp.get(dt_tmp_str, dt_tmp))
                dt_tmp = dt_tmp + timedelta(days=1)
Пример #2
0
 def _product_ids(self):
     return Utils.get_all_skus()
Пример #3
0
    # initializing for base stock policies
    for epoch in tqdm(range(args.episod)):
        action_dict = {}
        for agent_id, obs in obss.items():
            policy = base_policies[agent_id]
            action, _, _ = policy.compute_single_action(
                obs,
                state=rnn_states[agent_id],
                info=infos[agent_id],
                explore=True)
            action_dict[agent_id] = action
        obss, rewards, _, infos = env.step(action_dict)

    sku_base_stocks = {}
    time_hrz_len = env_config_for_rendering['sale_hist_len']
    for sku_name in Utils.get_all_skus():
        supplier_skus = []
        for facility in env.world.facilities.values():
            if isinstance(
                    facility,
                    ProductUnit) and facility.sku_info['sku_name'] == sku_name:
                supplier_skus.append(facility)
        _sku_base_stocks = ConsumerBaseStockPolicy.get_base_stock(
            supplier_skus, time_hrz_len)
        sku_base_stocks.update(_sku_base_stocks)

    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,