From fdea19a9e51f6337106e5f92637d4cc9b5ab64fb Mon Sep 17 00:00:00 2001 From: wJsJwr Date: Thu, 22 Nov 2018 17:10:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=9A=E5=BC=88=E5=9B=A2=E7=B0=87=E5=AF=BF?= =?UTF-8?q?=E5=91=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cluster_stat.py | 67 +++++++++++++++++++++++++++++++----- outputs/cluster.npy | Bin 216 -> 104 bytes outputs/cluster_life_1.json | 1 + outputs/cluster_life_2.json | 1 + outputs/cluster_life_3.json | 1 + outputs/cluster_life_4.json | 1 + outputs/cluster_life_5.json | 1 + outputs/cluster_life_6.json | 1 + outputs/cluster_life_7.json | 1 + outputs/cluster_life_8.json | 1 + outputs/cluster_life_9.json | 1 + plot_cluster_life.py | 37 ++++++++++++++++++++ 12 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 outputs/cluster_life_1.json create mode 100644 outputs/cluster_life_2.json create mode 100644 outputs/cluster_life_3.json create mode 100644 outputs/cluster_life_4.json create mode 100644 outputs/cluster_life_5.json create mode 100644 outputs/cluster_life_6.json create mode 100644 outputs/cluster_life_7.json create mode 100644 outputs/cluster_life_8.json create mode 100644 outputs/cluster_life_9.json create mode 100644 plot_cluster_life.py diff --git a/cluster_stat.py b/cluster_stat.py index cd9cb4c..b64b78a 100644 --- a/cluster_stat.py +++ b/cluster_stat.py @@ -2,22 +2,28 @@ 统计所有的连通子图规模 """ import csv +import json import numpy as np from collections import Counter from island.matches import Matches from island.match import Match +from matplotlib import pyplot as plt class ClusterStat: - def __init__(self): + def __init__(self, cb): self.detail = {} # self.matches = Matches.from_profile_expr(lambda r: True) self.matches = Matches.from_profile('SURVIVE') + self.life = {} # key(size), value(list of cluster-life) + self.cluster_born = cb def stat(self): for m in self.matches.data: cluster = {} + dick = {} no = 0 + cluster_life = {} for r in m.query('player','join').raw_data: cluster[r['pid']] = no no += 1 @@ -27,10 +33,50 @@ class ClusterStat: cmax, cmin = cluster[r['b']], cluster[r['a']] else: cmax, cmin = cluster[r['a']], cluster[r['b']] - lmax = [k for (k,v) in cluster.items() if v == cmax] - for k in lmax: - cluster[k] = cmin - res = [v for v in Counter(cluster.values()).values()] + if self.cluster_born == 1 or ((cmin,cmax) in dick and dick[(cmin,cmax)] > self.cluster_born - 1): + #link + lmax = [k for (k,v) in cluster.items() if v == cmax] + for k in lmax: + cluster[k] = cmin + else: + if (cmin, cmax) not in dick: + dick[(cmin, cmax)] = 1 + else: + dick[(cmin, cmax)] += 1 + info = m.query('game', 'created').select('info').first()['info'] + conf = json.loads(info['config']) + game_end_at = int(info['game_end_at']) + foods = {} + for p in m.query('player', 'join').select('pid').raw_data: + foods[p['pid']] = conf['start_resource'] + + for i in range(1, game_end_at + 1): + for a in m.query('action', 'done').where(lambda x: x['rno'] == i).raw_data: + foods[a['a']] += conf['payoffs']["%s%s" % (a['act_a'], a['act_b'])][0] * a['tr'] / 1440.0 + foods[a['b']] += conf['payoffs']["%s%s" % (a['act_a'], a['act_b'])][1] * a['tr'] / 1440.0 + for j in foods.keys(): + foods[j] -= conf['rounds']['consumption'] + for k,v in foods.items(): + if -10 < v <= 0: + if cluster[k] in cluster_life: + if cluster_life[cluster[k]] < i: + cluster_life[cluster[k]] = i + else: + cluster_life[cluster[k]] = i + foods[k] = -1000 + for k,v in foods.items(): + if v >= 0: + if cluster[k] in cluster_life: + if cluster_life[cluster[k]] < game_end_at: + cluster_life[cluster[k]] = game_end_at + else: + cluster_life[cluster[k]] = game_end_at + counter = Counter(cluster.values()) + for k,v in counter.items(): + if v not in self.life: + self.life[v] = [] + self.life[v].append(cluster_life[k]) + res = [v for v in counter.values()] # print(m.name, list(sorted(res, reverse=True))) self.detail[m.name] = res @@ -44,10 +90,13 @@ class ClusterStat: for d in data: res[d-1] += d res /= s - print(res) + # print(res) np.save('outputs/cluster.npy', res) + with open("outputs/cluster_life_%d.json" % self.cluster_born, 'w') as f: + json.dump(self.life, f) if __name__ == '__main__': - c = ClusterStat() - c.stat() - c.output() \ No newline at end of file + for i in range(1, 10): + c = ClusterStat(i) + c.stat() + c.output() diff --git a/outputs/cluster.npy b/outputs/cluster.npy index 81c02873ec62c2893753de11aad9637c3100408c..e3f651e56f638d2c9493fc6726189eb3afd6f431 100644 GIT binary patch delta 49 ucmcb?m@&at+gL|aN1;{$32=#LG>T<3KC@3!F9V`W_JVv51^6B|*aHAN^9}|8 delta 162 zcmd0}!8pOT-q2h}Q%9jz0Rgx|+){z)i2d`db