回答編集履歴
1
ijime_link()変更案の追記
test
CHANGED
@@ -1,3 +1,159 @@
|
|
1
|
+
以下は返信コメントを受けての追記分です。
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
bullying_listの挙動が意図した物でないなら、何らかの方法で同じ物を含まないようにチェックする必要があります。たとえば、以下のようにijime_link()を変更した場合、私の環境(3年前のノートPC)上で ```num_agents = 31```, ```turns = 4000``` の設定で動かして完了まで7分くらいになります。
|
6
|
+
|
7
|
+
(プログラムの内容は見ていないので、この変更でOKなのかは不明ですが)
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
```python
|
12
|
+
|
13
|
+
import numpy as np
|
14
|
+
|
15
|
+
import random
|
16
|
+
|
17
|
+
from time import perf_counter
|
18
|
+
|
19
|
+
import pandas as pd
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
class Agent:
|
24
|
+
|
25
|
+
# 途中省略
|
26
|
+
|
27
|
+
def ijime_link(self,agents): #いじめリンク設定
|
28
|
+
|
29
|
+
for agent in agents:
|
30
|
+
|
31
|
+
if agent is self:
|
32
|
+
|
33
|
+
continue
|
34
|
+
|
35
|
+
if agent.id in self.friend_list and self.id in agent.friend_list:
|
36
|
+
|
37
|
+
if agent.id in self.bullying_list:
|
38
|
+
|
39
|
+
continue
|
40
|
+
|
41
|
+
candidate = set(self.exclusion_list) & set(agent.exclusion_list)
|
42
|
+
|
43
|
+
for age in agents:
|
44
|
+
|
45
|
+
if age is self or agent is age:
|
46
|
+
|
47
|
+
continue
|
48
|
+
|
49
|
+
if age.id in self.friend_list and self.id in agent.friend_list:
|
50
|
+
|
51
|
+
ijime = set(candidate) & set(age.exclusion_list)
|
52
|
+
|
53
|
+
for ij in ijime:
|
54
|
+
|
55
|
+
if ij not in self.bullying_list:
|
56
|
+
|
57
|
+
self.bullying_list.append(ij)
|
58
|
+
|
59
|
+
#if len(ijime) > 0:
|
60
|
+
|
61
|
+
# self.bullying_list += list(ijime)
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
for agent in agents:
|
66
|
+
|
67
|
+
if agent is self:
|
68
|
+
|
69
|
+
continue
|
70
|
+
|
71
|
+
if agent.id in self.bullying_list:
|
72
|
+
|
73
|
+
if self.id in agent.hi_bullying_list:
|
74
|
+
|
75
|
+
continue
|
76
|
+
|
77
|
+
agent.hi_bullying_list.append(self.id)
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
class Simulation:
|
84
|
+
|
85
|
+
def __init__(self):
|
86
|
+
|
87
|
+
self.agents = []
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
def generate_agents(self, agents_num):
|
92
|
+
|
93
|
+
self.agents = [Agent(agent_id) for agent_id in range(agents_num)]
|
94
|
+
|
95
|
+
for agent in self.agents:
|
96
|
+
|
97
|
+
agent.First_set(self.agents)
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
def play_the_game(self):
|
102
|
+
|
103
|
+
num_agents = 31
|
104
|
+
|
105
|
+
turns = 4000
|
106
|
+
|
107
|
+
self.generate_agents(num_agents)
|
108
|
+
|
109
|
+
for turn in range(turns):
|
110
|
+
|
111
|
+
for agent in self.agents:
|
112
|
+
|
113
|
+
self.talk = agent.decide_talk_man(self.agents)
|
114
|
+
|
115
|
+
self.topic = agent.decide_topic(self.agents,self.talk)
|
116
|
+
|
117
|
+
dlu,dlx = agent.update_like1(self.agents,self.talk,self.topic)
|
118
|
+
|
119
|
+
agent.update_like2(self.talk,self.topic,dlu,dlx)
|
120
|
+
|
121
|
+
agent.link(self.agents)
|
122
|
+
|
123
|
+
agent.ijime_link(self.agents)
|
124
|
+
|
125
|
+
agent.update_f(turn)
|
126
|
+
|
127
|
+
agent.updete_Pnet(self.agents)
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
st = perf_counter()
|
132
|
+
|
133
|
+
sim = Simulation()
|
134
|
+
|
135
|
+
sim.play_the_game()
|
136
|
+
|
137
|
+
ed = perf_counter()
|
138
|
+
|
139
|
+
for agent in sim.agents:
|
140
|
+
|
141
|
+
print(" Agent", ":",agent.id)
|
142
|
+
|
143
|
+
print(" いじめ",":",agent.bullying_list)
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
print(ed - st)
|
148
|
+
|
149
|
+
```
|
150
|
+
|
151
|
+
---
|
152
|
+
|
153
|
+
以下は以前の回答です。
|
154
|
+
|
155
|
+
|
156
|
+
|
1
157
|
試しに ```num_agents = 7```, ```turns = 2000``` の設定で動かしてみたところ、sim.play_the_game()が終わった時点で添付図のようにsim.agents[]のbullying_listが非常に大きなデータになっていました(13,595項目)。
|
2
158
|
|
3
159
|
![イメージ説明](fdbf41276e522422e0abfaed0e80bd13.jpeg)
|