-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun_hrl.py
598 lines (533 loc) · 24.8 KB
/
run_hrl.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
import os
os.environ['MKL_NUM_THREADS'] = '1'
import argparse
from copyreg import pickle
import os.path as osp
import sys
sys.path.append('../')
from simulator.envs import *
from tools.create_envs import *
from algo.hrl import *
import torch
import pickle
import time
from torch.utils.tensorboard import SummaryWriter
import setproctitle
os.environ["CUDA_VISIBLE_DEVICES"] = "4"
setproctitle.setproctitle("didi@ft")
upper_bound=0
def get_parameter():
parser = argparse.ArgumentParser()
args = parser.parse_args()
# parameter
args.MAX_ITER = 60000
args.TEST_ITER = 1
args.TEST_SEED = 10000
args.resume_iter = 0
args.device = 'cpu'
args.neighbor_dispatch = False # 是否考虑相邻网格接单
args.onoff_driver = False # 不考虑车辆的随机下线
# args.log_name='M2_a0.01_reward2_t2_gamma0_value_noprice_noentropy'
# args.log_name='advnormal_gradMean_iter10_lr3e-4_step144_clipno_batchall3_parallel1_minibatch1'
# args.log_name='debug'
args.dispatch_interval = 10 # 决策间隔/min
args.speed = args.dispatch_interval
args.wait_time = args.dispatch_interval
args.TIME_LEN = int(1440 // args.dispatch_interval) # 一天的总决策次数
args.grid_num = 36 # 网格数量,决定了数据集
args.driver_num = 6000 # 改变初始化司机数量
args.city_time_start = 0 # 一天的开始时间,时间的总长度是TIME_LEN
args.batch_size = int(1e3)
args.actor_lr = 1e-3
args.critic_lr = 1e-3
args.train_actor_iters = 1
args.train_critic_iters = 1
args.batch_size = int(args.batch_size)
args.gamma = 0.97
args.lam = 0.99
args.max_grad_norm = 10
args.clip_ratio = 0.2
args.ent_factor = 0.01
args.adv_normal = True
args.clip = True
args.steps_per_epoch = 144
args.grad_multi = 'mean' # sum or mean
# args.minibatch_num= int(round(args.steps_per_epoch*args.grid_num/args.batch_size))
args.minibatch_num = 5
args.parallel_episode = 5
args.parallel_way = 'mix' # mix, mean
args.parallel_queue = True
args.return_scale = False
args.use_orthogonal = True
args.use_value_clip = True
args.use_valuenorm = False
args.use_huberloss = True
args.use_lr_anneal = False
args.use_GAEreturn = True
args.use_rnn = False
args.use_GAT = False
args.use_dropout = False
args.use_auxi = False
args.auxi_effi = 0.1
args.use_fake_auxi = 0
args.use_regularize = ['None', 'L1', 'L2', 'L1state', 'L2state'][0]
args.regularize_alpha = 1e-1
args.use_neighbor_state = False # 表示使用固定的多少阶邻居的信息作为状态
args.adj_rank = 2
args.merge_method = 'cat' # ['cat','res']
args.actor_centralize = False
args.critic_centralize = False
args.order_value = False
args.new_order_entropy = True
args.update_value = False
args.order_grid = True
args.reward_scale = 5
args.memory_size = int(args.TIME_LEN * args.parallel_episode)
args.FM = False
args.remove_fake_order = False
args.team_reward_factor = 5
args.team_rank = 0
args.full_share = True
args.global_share = False
args.ORR_reward = False
args.ORR_reward_effi = 1
args.only_ORR = False
args.fix_phi = False
args.policy_num=4
args.phi = [0.025088, 0.087006, 0.184027, 0.236112, 0.218559, 0.249208]
log_name_dict = {
'OD': args.grid_num,
'Batch': args.batch_size,
# 'Advnorm': '' if args.adv_normal else 'NO',
# 'Grad': args.grad_multi,
'Gamma': args.gamma,
'Lambda': args.lam,
'Iter': args.train_actor_iters,
'Ir': args.actor_lr,
'Step': args.steps_per_epoch,
# 'Clipnew': args.clip_ratio if args.clip else 'NO',
'Ent': args.ent_factor,
'Minibatch': args.minibatch_num,
'Parallel': str(args.parallel_episode) + args.parallel_way,
# 'Rscale':args.reward_scale,
'value': '' if args.order_value else 'NO',
'queue': '' if args.parallel_queue else 'NO',
# 'TeamR': 'share' if args.full_share else args.team_reward_factor,
'TeamRank': 'global' if args.global_share else args.team_rank,
'ORR': args.ORR_reward_effi if args.ORR_reward else 'NO',
'Actor': 'Cen' if args.actor_centralize else 'Decen',
'Critic': 'Cen' if args.critic_centralize else 'Decen',
'Auxi': args.auxi_effi if args.use_auxi else 'No',
'FakeNewAuxi': args.use_fake_auxi
}
args.log_name = ''
for k, v in log_name_dict.items():
args.log_name += k + str(v) + '_'
# args.log_name+='seed0'
# args.log_name+='_car50'
if args.order_grid == False:
args.log_name += '_RmGrid'
if args.only_ORR:
args.log_name += '_onlyORR'
if args.fix_phi:
args.log_name += '_fixPhi'
if args.update_value:
args.log_name += '_UpVal'
# args.log_name+='_KLNEW'
if args.new_order_entropy:
args.log_name += '_NewEntropy'
if args.use_orthogonal == True:
args.log_name += '_OrthoInit'
if args.use_value_clip:
args.log_name += '_ValueClip'
if args.use_valuenorm:
args.log_name += '_ValueNorm'
if args.use_huberloss:
args.log_name += '_Huberloss'
if args.use_lr_anneal:
args.log_name += '_LRAnneal'
if args.use_GAEreturn:
args.log_name += '_GAEreturn'
if args.use_rnn:
args.log_name += '_GRU2'
if args.use_GAT:
args.log_name += '_GATnew'
if args.use_neighbor_state:
args.log_name += '_Statenew' + str(args.adj_rank)
if args.use_regularize is not 'None':
args.log_name += '_' + args.use_regularize + str(args.regularize_alpha)
# args.log_name+= '_'+args.merge_method
# args.log_name+='_GAE'
# args.log_name='advnormal_gradMean_iter10_lr3e-4_step144_clipno_batchall3_parallel1_minibatch1'
# args.log_name='debug'
current_time = time.strftime("%Y%m%d_%H-%M")
# log_dir = '../logs/' + "{}".format(current_time)
#log_dir = 'logs/' + 'synthetic/' + 'PPO2/' + args.log_name
log_dir = os.path.join('logs', 'synthetic', 'PPO2')
#log_dir = log_dir.replace('/','\\')
args.log_dir = log_dir
mkdir_p(log_dir)
print("log dir is {}".format(log_dir))
args.writer_logs = True
if args.writer_logs:
args_dict = args.__dict__
with open(log_dir + '/setting.txt', 'w') as f:
for key, value in args_dict.items():
f.writelines(key + ' : ' + str(value) + '\n')
return args
def train(env, agent, writer=None, args=None, device='cpu'):
best_gmv = 0
best_orr = 0
wri = True
s_gridid = np.arange(args.grid_num)
if args.return_scale:
record_return = test(env, agent, test_iter=1, args=args, device=device) / 20
record_return[record_return == 0] = 1
for iteration in np.arange(args.resume_iter, args.MAX_ITER):
t_begin = time.time()
print('\n---- ROUND: #{} ----'.format(iteration))
RANDOM_SEED = iteration + args.MAX_ITER
env.reset_randomseed(RANDOM_SEED)
gmv = []
fake_orr = []
fleet_orr = []
kl = []
entropy = []
order_response_rates = []
T = 0
states_node, _, order_states, order_idx, order_feature, global_order_states = env.reset(mode='PPO2')
state = agent.process_state(states_node, T) # state dim= (grid_num, 119)
state_rnn_actor = torch.zeros((1, agent.agent_num, agent.hidden_dim), dtype=torch.float)
state_rnn_critic = torch.zeros((1, agent.agent_num, agent.hidden_dim), dtype=torch.float)
order_states = agent.add_order_value(order_states)
order, mask_order = agent.process_order(order_states)
order = agent.remove_order_grid(order)
mask_order = agent.mask_fake(order, mask_order)
####上层策略
if iteration ==0 or iteration>upper_bound:
cluster_prob, cluster = agent.action_hrl(s_gridid, device=device)
cluster_action = np.zeros((args.grid_num, args.policy_num))
for inter8 in range(args.grid_num):
cluster_action[inter8, int(cluster[inter8])] = 1
cluster_dict = {}
for inter in range(args.policy_num):
cluster_dict[inter] = []
for inter1 in range(len(cluster)):
cluster_dict[cluster[inter1]].append(inter1)
shunxu_ = list(cluster_dict.values())
shunxu = []
for inter in shunxu_:
shunxu += inter
shunxu = np.array(shunxu)
shunxu = np.argsort(shunxu)
agent.set_replay_buffer([int(len(cluster_dict[k])) for k in range(args.policy_num)])
if iteration:
np.save("begin.npy",cluster_dict)
for T in np.arange(args.TIME_LEN):
assert len(order_idx) == args.grid_num, 'dim error'
assert len(order_states) == args.grid_num, 'dim error'
for i in range(len(order_idx)):
assert len(order_idx[i]) == len(order_states[i]), 'dim error'
# t0=time.time()
MDP.cur_time = T
action, value, logp, mask_agent, mask_order_multi, mask_action, next_state_rnn_actor, next_state_rnn_critic, action_ids, selected_ids = agent.action(
state, order, state_rnn_actor, state_rnn_critic, mask_order, order_idx, device, sample=False,
random_action=False, MDP=MDP, fleet_help=args.FM,cluster_dict_=cluster_dict,shunxu_=shunxu)
if args.order_value and args.update_value:
MDP.update_value(order_states, selected_ids, env)
# t1=time.time()
orders = env.get_orders_by_id(action_ids)
next_states_node, next_order_states, next_order_idx, next_order_feature = env.step(orders, generate_order=1,
mode='PPO2')
# t2=time.time()
# distribution should gotten after step
dist = env.step_get_distribution()
entr_value = env.step_get_entropy()
order_dist, driver_dist = dist[:, 0], dist[:, 1]
kl_value = np.sum(order_dist * np.log(order_dist / driver_dist))
entropy.append(entr_value)
kl.append(kl_value)
gmv.append(env.gmv)
fake_orr.append(env.fake_response_rate)
fleet_orr.append(env.fleet_response_rate)
if env.order_response_rate >= 0:
order_response_rates.append(env.order_response_rate)
# store transition
if T == args.TIME_LEN - 1:
done = True
else:
done = False
reward = torch.Tensor([node.gmv for node in env.nodes])
if args.global_share:
reward = torch.mean(reward, 0, keepdim=True).repeat(args.grid_num)
else:
if args.full_share == False:
if args.fix_phi:
team_reward = torch.zeros_like(reward)
for i in range(args.grid_num):
for rank in range(args.team_rank):
neighb = env.layer_neighborhood[i][rank]
team_reward[i] += torch.mean(reward[neighb]) * args.phi[rank + 1]
reward = args.phi[0] * reward + team_reward
else:
team_reward = torch.zeros_like(reward)
for i in range(args.grid_num):
for rank in range(args.team_rank):
neighb = env.layer_neighborhood[i][rank]
team_reward[i] += torch.mean(reward[neighb])
reward = 1 / np.sqrt(
1 + args.team_reward_factor ** 2) * reward + args.team_reward_factor / np.sqrt(
1 + args.team_reward_factor ** 2) * team_reward
else:
team_reward = torch.zeros_like(reward)
for i in range(args.grid_num):
num = 1
team_reward[i] = reward[i]
for rank in range(args.team_rank):
neighb = env.layer_neighborhood[i][rank]
num += len(neighb)
team_reward[i] += torch.sum(reward[neighb])
team_reward[i] /= num
reward = team_reward
if args.ORR_reward == True:
ORR_reward = torch.zeros_like(reward)
driver_num = torch.Tensor([node.idle_driver_num for node in env.nodes]) + 1e-5
order_num = torch.Tensor([node.real_order_num for node in env.nodes]) + 1e-5
driver_order = torch.stack([driver_num, order_num], dim=1)
ORR_entropy = torch.min(driver_order, dim=1)[0] / torch.max(driver_order, dim=1)[0]
'''
ORR_entropy= ORR_entropy*torch.log(ORR_entropy)
global_entropy= torch.min(torch.sum(driver_order,dim=0))/torch.max(torch.sum(driver_order,dim=0))
global_entropy = global_entropy*torch.log(global_entropy)
ORR_entropy= torch.abs(ORR_entropy-global_entropy)
order_num/=torch.sum(order_num)
driver_num/=torch.sum(driver_num)
ORR_KL = torch.sum(order_num * torch.log(order_num / driver_num))
'''
for i in range(args.grid_num):
num = 1
ORR_reward[i] = ORR_entropy[i]
for rank in range(args.team_rank):
neighb = env.nodes[i].layers_neighbors_id[rank]
num += len(neighb)
ORR_reward[i] += torch.sum(ORR_entropy[neighb])
ORR_reward[i] /= num
# ORR_reward= -ORR_reward*10-ORR_KL+2.5
reward += ORR_reward * args.ORR_reward_effi
if args.only_ORR:
reward = ORR_reward * args.ORR_reward_effi
# print(0)
if args.return_scale:
reward /= record_return
else:
reward /= args.reward_scale
next_order_states = agent.add_order_value(next_order_states)
next_state = agent.process_state(next_states_node, T) # state dim= (grid_num, 119)
next_order, next_order_mask = agent.process_order(next_order_states)
next_order = agent.remove_order_grid(next_order)
next_order_mask = agent.mask_fake(next_order, next_order_mask)
epoch_ended = (T % args.steps_per_epoch) == (args.steps_per_epoch - 1)
if iteration<500000:
for inter1 in range(args.policy_num):
id = cluster_dict[inter1]
agent.replay_buffer_l[inter1].push(state[id], next_state[id], order[id], action[id], reward[id, None], value[id], logp[id], mask_order_multi[id],
mask_action[id], mask_agent[id], state_rnn_actor.squeeze(0)[id], state_rnn_critic.squeeze(0)[id])
done = T == args.TIME_LEN - 1
if done or epoch_ended:
if done:
next_value = torch.zeros((agent.agent_num, 1))
elif epoch_ended:
next_value, _ = agent.critic(next_state.to(device), agent.adj,
next_state_rnn_critic.to(device)).detach().cpu()
agent.replay_buffer_l[inter1].finish_path(next_value[id])
# agent.update(device,writer)
### global critic
agent.buffer.push(state, next_state, order, action, reward[:, None], value, logp, mask_order_multi,
mask_action, mask_agent, state_rnn_actor.squeeze(0), state_rnn_critic.squeeze(0))
done = T == args.TIME_LEN - 1
if done or epoch_ended:
if done:
next_value = torch.zeros((agent.agent_num, 1))
elif epoch_ended:
next_value, _ = agent.critic(next_state.to(device), agent.adj,
next_state_rnn_critic.to(device)).detach().cpu()
agent.buffer.finish_path(next_value)
# t3=time.time()
# print(t1-t0,t2-t0,t3-t0)
states_node = next_states_node
order_idx = next_order_idx
order_states = next_order_states
order_feature = next_order_feature
state = next_state
order = next_order
mask_order = next_order_mask
state_rnn_actor = next_state_rnn_actor
state_rnn_critic = next_state_rnn_critic
T += 1
if args.parallel_queue == False:
if (iteration + 1) % args.parallel_episode == 0:
agent.update(device, writer)
else:
if iteration < 500000:
if (iteration + 1) >= args.parallel_episode:
agent.update_center(device, writer)
agent.update(device, writer)
t_end = time.time()
if iteration>upper_bound:
if iteration!=0:
agent.hrl_buffer.append((s_gridid,cluster_action,cluster_prob,np.sum(gmv)/100000.0))
if (iteration+1)%10==0:
for ii in range(4):
entropy=agent.ppo_hrl_train(device)
agent.hrl_buffer.clear()
print('entropy_hrl:',entropy)
writer.add_scalar('train ent_up', entropy, iteration)
if np.sum(gmv) >25000 and wri==True:
np.save("midium.npy", cluster_dict)
wri =False
if np.sum(gmv) > best_gmv:
best_gmv = np.sum(gmv)
best_orr = order_response_rates[-1]
if np.sum(gmv) >28000:
np.save("best.npy",cluster_dict)
# agent.save_param(args.log_dir, 'Best')
print(
'>>> Time: [{0:<.4f}] Mean_ORR: [{1:<.4f}] GMV: [{2:<.4f}] Best_hrl_ORR: [{3:<.4f}] Best_hrl_GMV: [{4:<.4f}]'.format(
t_end - t_begin, order_response_rates[-1], np.sum(gmv), best_orr, best_gmv))
# agent.save_param(args.log_dir, 'param')
writer.add_scalar('train hrl ORR', order_response_rates[-1], iteration)
writer.add_scalar('train hrl GMV', np.sum(gmv), iteration)
# writer.add_scalar('train KL',np.mean(kl),iteration)
# writer.add_scalar('train Suply/demand',np.mean(entropy),iteration)
# if args.order_value:
# writer.add_scalar('train value feature', np.mean(np.abs(MDP.value_iter)), iteration)
# MDP.value_iter = []
# if iteration % 10 == 0:
# MDP.save_param(args.log_dir)
def test(env, agent, test_iter=1, writer=None, args=None, device='cpu'):
best_gmv = 0
best_orr = 0
record_return = torch.zeros((args.TIME_LEN, args.grid_num))
record_driver = torch.zeros((args.TIME_LEN, args.grid_num))
record_prob = []
for iteration in np.arange(test_iter):
print('\n---- ROUND: #{} ----'.format(iteration))
RANDOM_SEED = iteration + args.MAX_ITER
env.reset_randomseed(RANDOM_SEED)
gmv = []
fake_orr = []
fleet_orr = []
kl = []
entropy = []
order_response_rates = []
T = 0
states_node, _, order_states, order_idx, order_feature, global_order_states = env.reset(mode='PPO2')
state = agent.process_state(states_node, T) # state dim= (grid_num, 119)
order, mask_order = agent.process_order(order_states)
for T in np.arange(args.TIME_LEN):
assert len(order_idx) == args.grid_num, 'dim error'
assert len(order_states) == args.grid_num, 'dim error'
for i in range(len(order_idx)):
assert len(order_idx[i]) == len(order_states[i]), 'dim error'
MDP.cur_time = T
action, value, logp, mask_agent, mask_order_multi, mask_action, action_ids, full_prob, driver_num = agent.action(
state, order, mask_order, order_idx, device, sample=False, random_action=False, MDP=MDP,
fleet_help=args.FM, need_full_prob=True, random_fleet=False and args.FM)
record_driver[T] = driver_num
record_prob.append(full_prob[:, :20])
orders = env.get_orders_by_id(action_ids)
next_states_node, next_order_states, next_order_idx, next_order_feature = env.step(orders, generate_order=1,
mode='PPO2')
# distribution should gotten after step
dist = env.step_get_distribution()
entr_value = env.step_get_entropy()
order_dist, driver_dist = dist[:, 0], dist[:, 1]
kl_value = np.sum(order_dist * np.log(order_dist / driver_dist))
entropy.append(entr_value)
kl.append(kl_value)
gmv.append(env.gmv)
fake_orr.append(env.fake_response_rate)
fleet_orr.append(env.fleet_response_rate)
if env.order_response_rate >= 0:
order_response_rates.append(env.order_response_rate)
# store transition
if T == args.TIME_LEN - 1:
done = True
else:
done = False
reward = torch.Tensor([node.gmv for node in env.nodes])
if args.return_scale:
reward /= record_return
else:
reward /= args.reward_scale
agent.buffer.push(state, order, action, reward[:, None], value, logp, mask_order_multi, mask_action,
mask_agent)
next_state = agent.process_state(next_states_node, T) # state dim= (grid_num, 119)
next_order, next_order_mask = agent.process_order(next_order_states)
states_node = next_states_node
order_idx = next_order_idx
order_states = next_order_states
order_feature = next_order_feature
state = next_state
order = next_order
mask_order = next_order_mask
T += 1
print(
'>>> Mean_ORR: [{0:<.4f}] GMV: [{1:<.4f}] Mean_KL: [{2:<.4f}] Mean_Entropy: [{3:<.4f}] Best_ORR: [{4:<.4f}] Best_GMV: [{5:<.4f}]'.format(
order_response_rates[-1], np.sum(gmv), np.mean(kl), np.mean(entropy), best_orr, best_gmv))
'''
writer.add_scalar('train ORR',np.mean(order_response_rates),iteration)
writer.add_scalar('train GMV',np.sum(gmv),iteration)
writer.add_scalar('train KL',np.mean(kl),iteration)
writer.add_scalar('train Suply/demand',np.mean(entropy),iteration)
if args.order_value:
writer.add_scalar('train value feature',np.mean(np.abs(MDP.value_iter)),iteration)
MDP.value_iter=[]
'''
test_log = {
'order': agent.buffer.order_pool[:, :144, :20, 4],
'action': agent.buffer.action_pool[:, :144, :20],
'reward': agent.buffer.reward_pool[:, :144],
'advantge': agent.buffer.advantage_pool[:, :144],
'return': agent.buffer.return_pool[:, :144],
'driver': record_driver,
'prob': torch.stack(record_prob, dim=1)
}
# with open(args.log_dir+'/'+'test_log.pkl','wb') as f:
# pickle.dump(test_log,f)
return torch.sum(record_return, dim=0)
if __name__ == "__main__":
args = get_parameter()
# if args.device == 'gpu':
# device = torch.device('cuda')
# else:
# device = torch.device('cpu')
device = 'cuda' if torch.cuda.is_available() else 'cpu'
'''
dataset=kdd18(args)
dataset.build_dataset(args)
env=CityReal(dataset=dataset,args=args)
'''
if args.grid_num == 100:
env, args.M, args.N, _, args.grid_num = create_OD()
elif args.grid_num == 36:
env, args.M, args.N, _, args.grid_num = create_OD_36()
env.fleet_help = args.FM
if args.writer_logs:
writer = SummaryWriter(args.log_dir)
else:
writer = None
agent = PPO(env, args, device)
MDP = MdpAgent(args.TIME_LEN, args.grid_num, args.gamma)
if args.order_value:
MDP.load_param('../logs/synthetic/MDP/OD+localFM/MDPsave.pkl')
# logs/synthetic/MDP/OD+randomFM/MDP.pkl
agent.MDP = MDP
# agent=None
# agent.move_device(device)
# args.log_dir='../logs/synthetic/PPO2/OD_Advnorm_Gradmean_Iter5_Ir0.0003_Step144_ClipnewNO_Ent0.0_Minibatch5_Parallel5mean_seed0'
# model_dir = '../logs/MT/synthetic/PPO2/OD_Advnorm_Gradmean_Iter1_Ir0.001_Step144_Clipnew0.2_Ent0.01_Minibatch5_Parallel5mix_Rscale5_value_queue_TeamRshare_TeamRankglobal_ORRNO_seed0_car50_KLNEW/Best.pkl'
# agent.load_param(model_dir)
# agent.step=args.resume_iter
# test(env,agent, test_iter=1,args=args,device=device)
train(env, agent, writer=writer, args=args, device=device)