1、输出到txt文档,‘a’表示不覆盖源文件在末尾写,‘w’是覆盖
with open(", "a") as f:f.writelines('n' + "job_sequencing: {}".format(sqc_data))
2、将数据输出到excel,显示成折线图
import pandas as pdreward_list = []# example of a real reward functiondef store_result(self, reward):'''store reward'''reward_list.append(reward)each_reward_file = pd.DataFrame(reward_list)if self.m_idx == 0:each__csv('./reward/3/0_reward.csv')if self.m_idx == 1:each__csv('./reward/3/1_reward.csv')if self.m_idx == 2:each__csv('./reward/3/2_reward.csv')if self.m_idx == 3:each__csv('./reward/3/3_reward.csv')def get_reward1(self):...rwd = ((rwd_slack + rwd_winq)/20).clip(-1,1)r_t = sor(rwd , dtype=torch.float)x = r_t.numpy()self.store_result(x)return r_t
import matplotlib.pyplot as plt
import pandas as pd
import numpy as npY_value=[]
X_value=[]r_n=36
l_n=1def AeragList(list,count):newlis=[]#each_r=0for i in range(len(list)):#count = r_n =180if i!=0 and i % count == 0:#所有轮的均值集合newlis.append(averagenum(list[i-count:i]))#each_r += list[1]return newlisdef averagenum(num):nsum = 0for i in range(len(num)):nsum += num[i]return nsum / len(num)'''
reward
'''all_r=[]
reward_dataad_csv('./reward/2/3_reward.csv') #原MADDPGfor row in reward_list():a=row[1:][0]all_r.append(row[1:][0])# all_reward=AeragList(all_r, r_n)
# plt.plot(all_reward,color='red')all_reward=AeragList(all_r, 100)
plt.plot(all_reward,color='red')plt.ylabel("REWARD")
plt.show()# '''
# --------------COUNT----------------------------------------------------------------
# '''
# A1_N=[]
# A2_N=[]
# A3_N=[]
# A4_N=[]
# A5_N=[]
# A6_N=[]
# A7_N=[]
# A8_N=[]
# A9_N=[]
# all_N=[]
#
# N_dataad_csv('./reward/each_count.csv')
# for row in N_list():
# A1_N.append(row[1])
# A2_N.append(row[2])
# A3_N.append(row[3])
# A4_N.append(row[4])
# A5_N.append(row[5])
# A6_N.append(row[6])
# A7_N.append(row[7])
# A8_N.append(row[8])
# A9_N.append(row[9])
# a=row[1:]
# #每一次所有路口的均值
# all_N.append((np.sum(row[1:]))/9)
#
# A1_N = AeragList(A1_N, r_n)
# A2_N = AeragList(A2_N, r_n)
# A3_N= AeragList(A3_N, r_n)
# A4_N = AeragList(A4_N, r_n)
# A5_N = AeragList(A5_N, r_n)
# A6_N = AeragList(A6_N, r_n)
# A7_N = AeragList(A7_N, r_n)
# A8_N = AeragList(A8_N, r_n)
# A9_N = AeragList(A9_N, r_n)
# #
# all_N= AeragList(all_N, r_n)
#
# # plt.plot(A1_N,color='red')
# # plt.plot(A2_N,color='red')
# # plt.plot(A3_N,color='red')
# # plt.plot(A4_N,color='red')
# # plt.plot(A5_N,color='red')
# # plt.plot(A6_N,color='red')
# # plt.plot(A7_N,color='red')
# # plt.plot(A8_N,color='red')
# # plt.plot(A9_N,color='red')
# plt.plot(all_N,color='red')
# plt.ylabel("total N")
# plt.show()
#
# A1_W=[]
# A2_W=[]
# A3_W=[]
# A4_W=[]
# A5_W=[]
# A6_W=[]
# A7_W=[]
# A8_W=[]
# A9_W=[]
# all_W=[]
#
# w_dataad_csv('./reward/each_wait.csv')
# for row in w_list():
# A1_W.append(row[1])
# A2_W.append(row[2])
# A3_W.append(row[3])
# A4_W.append(row[4])
# A5_W.append(row[5])
# A6_W.append(row[6])
# A7_W.append(row[7])
# A8_W.append(row[8])
# A9_W.append(row[9])
# a=row[1:]
# all_W.append((np.sum(row[1:]))/9)
#
# A1_W = AeragList(A1_W, r_n)
# A2_W = AeragList(A2_W, r_n)
# A3_W= AeragList(A3_W, r_n)
# A4_W = AeragList(A4_W, r_n)
# A5_W = AeragList(A5_W, r_n)
# A6_W = AeragList(A6_W, r_n)
# A7_W = AeragList(A7_W, r_n)
# A8_W = AeragList(A8_W, r_n)
# A9_W = AeragList(A9_W, r_n)
# all_W= AeragList(all_W, r_n)
#
# # plt.plot(A1_W,color='red')
# # plt.plot(A2_W,color='red')
# # plt.plot(A3_W,color='red')
# # plt.plot(A4_W,color='red')
# # plt.plot(A5_W,color='red')
# # plt.plot(A6_W,color='red')
# # plt.plot(A7_W,color='red')
# # plt.plot(A8_W,color='red')
# # plt.plot(A9_W,color='red')
# plt.plot(all_W,color='red')
# plt.ylabel("Wait_time")
# plt.show()
本文发布于:2024-01-28 06:58:35,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17063963195626.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |