This commit is contained in:
chenxiaodong 2024-06-19 16:01:00 +08:00
parent 88bbddbb7f
commit 63f145467b
5 changed files with 18 additions and 18 deletions

View File

@ -43,7 +43,7 @@ if __name__ == '__main__':
# args.save_network=False # args.save_network=False
# args.test_network=False # args.test_network=False
# args.save_test_data=False # args.save_test_data=False
# args.compare_with_pyomo=False # args.compare_with_gurobi=False
if args.train: if args.train:
collect_data = True collect_data = True
@ -97,8 +97,8 @@ if __name__ == '__main__':
with open(test_data_save_path, 'wb') as tf: with open(test_data_save_path, 'wb') as tf:
pickle.dump(record, tf) pickle.dump(record, tf)
'''compare with pyomo data and results''' '''compare with gurobi data and results'''
if args.compare_with_pyomo: if args.compare_with_gurobi:
month = record['init_info'][0][0] month = record['init_info'][0][0]
day = record['init_info'][0][1] day = record['init_info'][0][1]
initial_soc = record['init_info'][0][3] initial_soc = record['init_info'][0][3]
@ -112,7 +112,7 @@ if __name__ == '__main__':
plot_dir = make_dir(args.cwd, plot_args.feature_change) plot_dir = make_dir(args.cwd, plot_args.feature_change)
plot_optimization_result(base_result, plot_dir) plot_optimization_result(base_result, plot_dir)
plot_evaluation_information(args.cwd + '/' + 'test_data.pkl', plot_dir) plot_evaluation_information(args.cwd + '/' + 'test_data.pkl', plot_dir)
'''compare the different cost get from pyomo and DDPG''' '''compare the different cost get from gurobi and DDPG'''
ration = sum(eval_data['operation_cost']) / sum(base_result['step_cost']) ration = sum(eval_data['operation_cost']) / sum(base_result['step_cost'])
print('operation_cost_sum:', sum(eval_data['operation_cost'])) print('operation_cost_sum:', sum(eval_data['operation_cost']))
print('step_cost_sum:', sum(base_result['step_cost'])) print('step_cost_sum:', sum(base_result['step_cost']))

10
PPO.py
View File

@ -261,7 +261,7 @@ class Arguments:
self.save_network = True self.save_network = True
self.test_network = True self.test_network = True
self.save_test_data = True self.save_test_data = True
self.compare_with_pyomo = True self.compare_with_gurobi = True
self.plot_on = True self.plot_on = True
def init_before_training(self, if_main): def init_before_training(self, if_main):
@ -336,7 +336,7 @@ if __name__ == '__main__':
# args.save_network=False # args.save_network=False
# args.test_network=False # args.test_network=False
# args.save_test_data=False # args.save_test_data=False
# args.compare_with_pyomo=False # args.compare_with_gurobi=False
if args.train: if args.train:
for i_episode in range(num_episode): for i_episode in range(num_episode):
with torch.no_grad(): with torch.no_grad():
@ -379,8 +379,8 @@ if __name__ == '__main__':
with open(test_data_save_path, 'wb') as tf: with open(test_data_save_path, 'wb') as tf:
pickle.dump(record, tf) pickle.dump(record, tf)
'''compare with pyomo data and results''' '''compare with gurobi data and results'''
if args.compare_with_pyomo: if args.compare_with_gurobi:
month = record['init_info'][0][0] month = record['init_info'][0][0]
day = record['init_info'][0][1] day = record['init_info'][0][1]
initial_soc = record['init_info'][0][3] initial_soc = record['init_info'][0][3]
@ -394,7 +394,7 @@ if __name__ == '__main__':
plot_dir = make_dir(args.cwd, plot_args.feature_change) plot_dir = make_dir(args.cwd, plot_args.feature_change)
plot_optimization_result(base_result, plot_dir) plot_optimization_result(base_result, plot_dir)
plot_evaluation_information(args.cwd + '/' + 'test_data.pkl', plot_dir) plot_evaluation_information(args.cwd + '/' + 'test_data.pkl', plot_dir)
'''compare the different cost get from pyomo and PPO''' '''compare the different cost get from gurobi and PPO'''
ration = sum(eval_data['operation_cost']) / sum(base_result['step_cost']) ration = sum(eval_data['operation_cost']) / sum(base_result['step_cost'])
print('operation_cost_sum:', sum(eval_data['operation_cost'])) print('operation_cost_sum:', sum(eval_data['operation_cost']))
print('step_cost_sum:', sum(base_result['step_cost'])) print('step_cost_sum:', sum(base_result['step_cost']))

8
SAC.py
View File

@ -46,7 +46,7 @@ if __name__ == '__main__':
# args.save_network=False # args.save_network=False
# args.test_network=False # args.test_network=False
# args.save_test_data=False # args.save_test_data=False
# args.compare_with_pyomo=False # args.compare_with_gurobi=False
# #
if args.train: if args.train:
collect_data = True collect_data = True
@ -102,8 +102,8 @@ if __name__ == '__main__':
with open(test_data_save_path, 'wb') as tf: with open(test_data_save_path, 'wb') as tf:
pickle.dump(record, tf) pickle.dump(record, tf)
'''compare with pyomo data and results''' '''compare with gurobi data and results'''
if args.compare_with_pyomo: if args.compare_with_gurobi:
month = record['init_info'][0][0] month = record['init_info'][0][0]
day = record['init_info'][0][1] day = record['init_info'][0][1]
initial_soc = record['init_info'][0][3] initial_soc = record['init_info'][0][3]
@ -117,7 +117,7 @@ if __name__ == '__main__':
plot_dir = make_dir(args.cwd, plot_args.feature_change) plot_dir = make_dir(args.cwd, plot_args.feature_change)
plot_optimization_result(base_result, plot_dir) plot_optimization_result(base_result, plot_dir)
plot_evaluation_information(args.cwd + '/' + 'test_data.pkl', plot_dir) plot_evaluation_information(args.cwd + '/' + 'test_data.pkl', plot_dir)
'''compare the different cost get from pyomo and SAC''' '''compare the different cost get from gurobi and SAC'''
ration = sum(eval_data['operation_cost']) / sum(base_result['step_cost']) ration = sum(eval_data['operation_cost']) / sum(base_result['step_cost'])
print('operation_cost_sum:', sum(eval_data['operation_cost'])) print('operation_cost_sum:', sum(eval_data['operation_cost']))
print('step_cost_sum:', sum(base_result['step_cost'])) print('step_cost_sum:', sum(base_result['step_cost']))

8
TD3.py
View File

@ -43,7 +43,7 @@ if __name__ == '__main__':
# args.save_network=False # args.save_network=False
# args.test_network=False # args.test_network=False
# args.save_test_data=False # args.save_test_data=False
# args.compare_with_pyomo=False # args.compare_with_gurobi=False
if args.train: if args.train:
collect_data = True collect_data = True
@ -98,8 +98,8 @@ if __name__ == '__main__':
with open(test_data_save_path, 'wb') as tf: with open(test_data_save_path, 'wb') as tf:
pickle.dump(record, tf) pickle.dump(record, tf)
'''compare with pyomo data and results''' '''compare with gurobi data and results'''
if args.compare_with_pyomo: if args.compare_with_gurobi:
month = record['init_info'][0][0] month = record['init_info'][0][0]
day = record['init_info'][0][1] day = record['init_info'][0][1]
initial_soc = record['init_info'][0][3] initial_soc = record['init_info'][0][3]
@ -113,7 +113,7 @@ if __name__ == '__main__':
plot_dir = make_dir(args.cwd, plot_args.feature_change) plot_dir = make_dir(args.cwd, plot_args.feature_change)
plot_optimization_result(base_result, plot_dir) plot_optimization_result(base_result, plot_dir)
plot_evaluation_information(args.cwd + '/' + 'test_data.pkl', plot_dir) plot_evaluation_information(args.cwd + '/' + 'test_data.pkl', plot_dir)
'''compare the different cost get from pyomo and TD3''' '''compare the different cost get from gurobi and TD3'''
ration = sum(eval_data['operation_cost']) / sum(base_result['step_cost']) ration = sum(eval_data['operation_cost']) / sum(base_result['step_cost'])
print('operation_cost_sum:', sum(eval_data['operation_cost'])) print('operation_cost_sum:', sum(eval_data['operation_cost']))
print('step_cost_sum:', sum(base_result['step_cost'])) print('step_cost_sum:', sum(base_result['step_cost']))

View File

@ -152,7 +152,7 @@ class Arguments:
self.save_network = True self.save_network = True
self.test_network = True self.test_network = True
self.save_test_data = True self.save_test_data = True
self.compare_with_pyomo = True self.compare_with_gurobi = True
self.plot_on = True self.plot_on = True
def init_before_training(self, if_main): def init_before_training(self, if_main):