This commit is contained in:
wjsjwr 2018-09-01 16:32:24 +08:00
parent c1abe1cab6
commit 1f5cde5761
2 changed files with 12 additions and 6 deletions

View File

@ -99,10 +99,13 @@ class Match:
def get_tr(self, i, target, nb, sv): def get_tr(self, i, target, nb, sv):
""" """
# 计算tau_p的方式是统计周围邻居剩余的tr # 计算tau_f的方式是统计周围邻居剩余的tr
# 本函数计算第i轮所有有消耗tr的player最后剩余的tr # 本函数计算第i轮所有有消耗tr的player最后剩余的tr
# 由于是计算剩余tr所以不能计算和target之间的交互 # 由于是计算剩余tr所以不能计算和target之间的交互
# nb是target的邻居 # nb是target的邻居
# 2018/08/31 更新即便是已经交互过的邻居他的剩余时间资源依旧应该计算入tau_f中使得公式完整。
# 2018/09/01 更新不应该算在tau_P中尝试单独列成一项因为优化目标不同。
# 2018/09.01 更新将tau_p更改为tau_f
""" """
trs = {} trs = {}
req = self.query('action', 'request').where(lambda x: x['rno'] == i+1) req = self.query('action', 'request').where(lambda x: x['rno'] == i+1)

View File

@ -15,18 +15,18 @@ def error(f,x,y):
return sp.sum((f(x)-y)**2) return sp.sum((f(x)-y)**2)
def p1(x, coopr, tau, postfix, show=True): def p1(x, coopr, tau, postfix, show=True):
fig = plt.figure(figsize=(5, 4)) fig = plt.figure(figsize=(2.5, 2))
ax = fig.gca() ax = fig.gca()
ax.plot(x, coopr, color=blue, linewidth=2, label="$f_c$") ax.plot(x, coopr, color=blue, linewidth=2, label="$f_c$")
ax.set_ylim(0, 1) ax.set_ylim(0, 1)
ax2 = ax.twinx() ax2 = ax.twinx()
ax2.plot(x, tau, color=red, linewidth=2, label=r"$\tau_p$") ax2.plot(x, tau, color=red, linewidth=2, label=r"$\tau_f$")
ax2.set_ylim(0, 1440) ax2.set_ylim(0, 1440)
ax.set_xlim(1, 15) ax.set_xlim(1, 15)
ax.set_xlabel("Rounds") ax.set_xlabel("Rounds")
ax.set_ylabel(r"$f_c$", color=blue) ax.set_ylabel(r"$f_c$", color=blue)
ax.tick_params(axis='y', labelcolor=blue) ax.tick_params(axis='y', labelcolor=blue)
ax2.set_ylabel(r"$\tau_{p}$", family='sans-serif', color=red) ax2.set_ylabel(r"$\tau_{f}$", family='sans-serif', color=red)
ax2.tick_params(axis='y', labelcolor=red) ax2.tick_params(axis='y', labelcolor=red)
fig.legend() fig.legend()
@ -49,6 +49,8 @@ def p2(tau, coopr, limited, postfix, show=True):
tau_r.append(tau[i]) tau_r.append(tau[i])
coopr_r.append(coopr[i]) coopr_r.append(coopr[i])
print(tau, coopr)
print(tau2, coopr2)
# p2散点图 # p2散点图
fig = plt.figure(figsize=(4, 3)) fig = plt.figure(figsize=(4, 3))
ax = fig.gca() ax = fig.gca()
@ -154,7 +156,7 @@ if __name__ == '__main__':
else: else:
trs = matches.data[j].get_tr(i, k, neighbors[matches.names[j]][k], survivals[matches.names[j]][str(i)]) trs = matches.data[j].get_tr(i, k, neighbors[matches.names[j]][k], survivals[matches.names[j]][str(i)])
for l in neighbors[matches.names[j]][k]: for l in neighbors[matches.names[j]][k]:
if l in trs: if l in trs and trs[l] > 0:
t += trs[l] t += trs[l]
tp.append(t if t < 1440 else 1440) tp.append(t if t < 1440 else 1440)
mwTau["%s-%d"%(j,i)] = tp[-1] mwTau["%s-%d"%(j,i)] = tp[-1]
@ -170,8 +172,9 @@ if __name__ == '__main__':
# p1折线图 # p1折线图
# p1(x, coopr, tau, 'classic', False) # p1(x, coopr, tau, 'classic', False)
p1(x, coopr, tau, 'survive', True)
p2(tau[:12], coopr[:12], 720, 'survive', True) # p2(tau[:12], coopr[:12], 720, 'survive', True)
# p2(tau, coopr, 1440, 'classic', False) # p2(tau, coopr, 1440, 'classic', False)