Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeQAPuni.py
More file actions
Latest commit
124 lines (103 loc) · 3.58 KB
/
Copy pathmakeQAPuni.py
File metadata and controls
124 lines (103 loc) · 3.58 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
importsys
importrandom
fromnumpyimportndarray
MAX_K=5
MAX_N=500
d_matrix=ndarray((MAX_N, MAX_N))
f_matrix=ndarray((MAX_K, MAX_N, MAX_N))
defmain():
n_fac=30# number of facilities/locations in the QAP
n_k=2
corr=0
max_flow=100
max_dist=100
arg=sys.argv[1:]
iflen(arg) ==1:
ifarg[0] =="-h":
print("You have requested help with the -h argument. \nOther optional parameters are: -n positive integer : number of facilities/locations -k positive integer : number of objectives -c1 real in the interval [-1,1]: correlation between objectives 1 and 2 -c2 real in the interval [-1,1]: correlation between objectives 1 and 3 -c3 real in the interval [-1,1]: correlation between objectives 1 and 4 -c4 real in the interval [-1,1]: correlation between objectives 1 and 5 -ov real in the interval [0:1]: sets the fraction of flows that are correlated -A integer : flow control parameter (must be set less than B; negative values cause a sparse matrix) -B positive integer : flow control parameter -K positive integer : maximum number of points in a small cluster -M non-negative integer : radius of large clusters -m non-negative integer : radius of small clusters -s positive long : random seed\n Default values are: n = 30, k = 2, c1 = 0, c2 = 0, c3 = 0, c4 = 0, A = -5, B = 5, m = 100, M = 0, K = 1, ov = 0.7, s = 23453464")
sys.exit()
iflen(arg) >1andlen(arg)%2==0:
foriinrange(0,len(arg),2):
ifarg[i] =="-n":
n_fac=arg[i+1]
elifarg[i] =="-k":
n_k=arg[i+1]
elifarg[i] =="-c":
corr=arg[i+1]
elifarg[i] =="-f":
max_flow=arg[i+1]
elifarg[i] =="-d":
max_dist=arg[i+1]
elifarg[i] =="-s":
seed=arg[i+1]
else:
print("Undefined command line parameter entered. Do \"./makeQAPrl -h\" for help with parameters.")
sys.exit()
ifint(n_fac) >int(MAX_N) :
print("Number of facilities too high. Maximum is currently set at "+str(MAX_N));
sys.exit()
iffloat(corr) >1.0orfloat(corr) < (-1.0):
print("Correlations must be in the interval [-1,1]")
sys.exit()
ifint(n_k) >int(MAX_K):
print("number of objectives too high. Maximum is currently set at "+str(MAX_K))
sys.exit()
foriinrange(0,int(n_fac)):
forjinrange(0,int(n_fac)):
ifi==j:
d_matrix[i][i]=0
else:
d1=1+int(max_dist*random.random())
d_matrix[i][j]=d1
d_matrix[j][i]=d1
foriinrange(0,int(n_fac)):
forjinrange(0,int(n_fac)):
ifi==j:
f_matrix[0][i][i]=0
else:
r1=random.random()
f1=1+int(max_flow*r1)
f_matrix[0][i][j]=f1
f_matrix[0][j][i]=f1
forkinrange(1,int(n_k)):
ifi==j:
f_matrix[k][i][i]=0
else:
r2=random.random()
ifcorr>=0:
fk=1+int(max_flow*correl_val(r1,corr))
else:
fk=1+int(max_flow*(1.0-correl_val(r1,corr)))
f_matrix[k][i][j]=fk
f_matrix[k][j][i]=fk
print_output(int(n_k),int(n_fac))
defcorrel_val(v,c):
p=0.5
ifc==1:
returnv
ifc==0:
returnrandom.random()
whileTrue:
q=random.random()
diff=q-v
ifdiff<0:
diff*=-1
w=math.exp(-(diff*diff)/(2.0*(1.0-math.pow(c,p))*(1.0-math.pow(c,p))))/(1.0-math.pow(c,p))*2.506
r=random.random()*1.0/(1.0-math.pow(c,p))*2.506
ifw>=r:
break
returnq
defprint_output(n_k,n_fac):
print (str(n_k)+" "+str(n_fac))
foriinrange (0,n_fac):
forjinrange (0,n_fac):
printint(d_matrix[i][j]),
print("")
forkinrange(0,n_k):
print("")
foriinrange(0,n_fac):
forjinrange(0,n_fac):
printint(f_matrix[k][i][j]),
print("")
if__name__=='__main__':
main()