-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathPython_WRFirst.txt
79 lines (74 loc) · 2.47 KB
/
Python_WRFirst.txt
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
This is a Python implementation of WeightestRolesFirst Assignment.
It can be used as a benchmark for comparison in Role Assignment.
It has the same function as Algorithm 1: IGRA [2], which simulates individualism
by choosing the best agents for the most important roles first.
Please cite:
[1] H. Zhu, E-CARGO and Role-Based Collaboration: Modeling and Solving Problems in the Complex World, Wiley-IEEE Press, NJ, USA, Dec. 2021.
[2] H. Zhu, “Computational Social Simulation with E-CARGO: Comparison between Collectivism and Individualism,” IEEE Trans. on Computational Social Systems, vol. 7, no. 6, Dec. 2020, pp. 1345-1357.
[3] H. Zhu, M.C. Zhou, and R. Alkins, “Group Role Assignment via a Kuhn-Munkres Algorithm-based Solution”, IEEE Trans. on Systems, Man, and Cybernetics, Part A: Systems and Humans, vol. 42, no. 3, May 2012, pp. 739-750.
Authors: Haibin Zhu, Aug. 20, 2022
"""
def printIMatrix(x, m, n):
txt = "{:2}"
for i in range(m):
for j in range(n):
print(txt.format(x[i*n+j]), " ", end='')
print()
def printDMatrix(x, m, n):
txt = "{:.2f}"
for i in range(m):
for j in range(n):
print(txt.format(x[i][j]), " ", end='')
print()
def tupleV (V):
n = len(V)
nV =[(V[i], i) for i in range (n)]
nV.sort(reverse=True)
return nV
def WRFirst (m, n, Q, L, W):
A = [i for i in range (m)]
T = [0]*m*n
nVb=tupleV(W)
Lp =[L[i] for i in [nVb[j][1] for j in range (n)]]
for j1 in range (n):
j = nVb[j1][1]
Y = [Q[i][j] for i in range (m)]
tY=tupleV (Y)
for i1 in range (L[j]):
ii = tY[i1][1]
T[ii*n+j] = 1
for j2 in range (n):
Q[ii][j2] = -1
A.remove(ii)
if len(A) == 0:
break
if len(A) == 0:
break
return T
def rearrange(T, V):
tV = tupleV(V);
T1 = [0]*m*n
for i in range (m):
for j in range (n):
T1[i*n+tV[j][1]] = T[i*n+j]
return T1
m = 8
n = 4
L = [1, 1, 2, 1]
Q = [
[0.35, 0.82, 0.58, 0.45],
[0.62, 0.78, 0.68, 0.31],
[0.96, 0.50, 0.10, 0.73],
[0.20, 0.50, 0.80, 0.96],
[0.38, 0.54, 0.72, 0.20],
[0.91, 0.31, 0.34, 0.15],
[0.45, 0.68, 0.53, 0.49],
[0.78, 0.67, 0.80, 0.62]]
printDMatrix(Q, m, n)
W = [2, 1, 4, 3]
T = WRFirst (m, n, Q, L, W)
T1 = rearrange(T, W)
printIMatrix(T1, m, n)
print (L)
print (W)