-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOrder_Env.py
More file actions
56 lines (49 loc) · 2.5 KB
/
Copy pathOrder_Env.py
File metadata and controls
56 lines (49 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import pandas as pd
class Demand():
def __init__(self, demand_path):
self.demand = pd.read_csv(demand_path)
self.filtered_demand = self.demand.loc[self.demand['minute'] == 0].reset_index(drop=True)
self.current_demand = self.demand.loc[self.demand['minute'] == 0].reset_index(drop=True)
self.episode_time = 0
self.current_time = 0
self.num_lost_demand = 0
'''
episode_time: start minute in this episode
p_sample: randomly select 100p% samples from the dataset
wait_time: the maximum waiting time of each order
'''
def reset(self, episode_time=0, p_sample=0.95, wait_time=5):
self.filtered_demand = self.demand.sample(frac=p_sample).sort_index()
mask = (self.filtered_demand['minute'] >= episode_time) & (self.filtered_demand['minute'] <= 60)
print("p_sample is:", p_sample)
print("total number of demand at this episode is:", len(self.filtered_demand[mask]))
self.current_demand = self.filtered_demand.loc[self.filtered_demand['minute'] == episode_time].reset_index(drop=True)
self.episode_time = episode_time
self.current_time = episode_time
self.num_lost_demand = 0
self.wait_time = wait_time
'''
update the order in the next minute
throw away orders waiting longer than <wait_time> minutes
'''
def update(self):
self.current_time += 1
self.current_demand = pd.concat(
[self.current_demand, self.filtered_demand.loc[self.filtered_demand['minute'] == self.current_time]])
self.current_demand = self.current_demand.reset_index(drop=True)
# drop those orders that are not taken over <wait_time> minutes
if self.current_time >= self.wait_time + self.episode_time:
self.num_lost_demand += len(self.current_demand[self.current_demand['minute'] <= (self.current_time - self.wait_time)])
self.current_demand = self.current_demand.drop(
index=self.current_demand[self.current_demand['minute'] <= (self.current_time - self.wait_time)].index).reset_index(
drop=True)
'''
delete the accepted orders from current_demand list
'''
def pickup(self,unique_r_ids):
# Convert the set to a list
unique_r_ids_list = list(unique_r_ids)
# Drop rows whose index is in unique_r_ids_list
self.current_demand = self.current_demand.drop(unique_r_ids_list)
# Reset index
self.current_demand = self.current_demand.reset_index(drop=True)