-
Notifications
You must be signed in to change notification settings - Fork 6
/
Variantcrp.py
40 lines (34 loc) · 920 Bytes
/
Variantcrp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
n = 10000
class cluster:
count = 0
clusters = []
def __str__(self):
return str(self.count)
def add(self, i):
self.count += 1
self.clusters.append(i)
return self
def getSim(v, table):
#相似性函数,返回概率值
pass
def getVec():
#载入向量
pass
if __name__ == "__main__":
V = getVec() #向量集合
first = cluster().add(0) #第一位顾客选择第一个桌子
restaurant = [first]
for i in range(1, n):
p = []
pn = 1.0/(1 + len(restaurant))
for table in restaurant:
p.append(getSim(V[i], table))
maxVal = max(p)
maxIdx = p.index(maxVal)
if maxVal < pn:
if random.uniform(0,1) < pn:#创造桌子
new = cluster().add(i)
restaurant.append(new)
restaurant[maxIdx].add(i)
for i in restaurant:
print(i)