-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.jl
76 lines (66 loc) · 1.41 KB
/
generate.jl
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
using Graphs
using Random
function writeset(io, S)
for s in S
write(io, "$s ")
end
write(io, "\n")
end
function generategraph(n, d)
G = SimpleDiGraph(n)
ecount = 0
# cnt = 0
while ecount < d*n/2 && ecount < binomial(n, 2)
a = rand(1:n)
b = rand(1:n)
# cnt += 1
# if cnt % 10^6 == 0
# println(a, b)
# end
if b < a
tmp = a
a = b
b = tmp
end
if a != b && !has_edge(G, a, b)
add_edge!(G, a, b)
add_edge!(G, b, a)
ecount += 1
end
end
ts = randperm(n)
for a in 1:n, b in inneighbors(G, a)
ts[b] < ts[a] && rem_edge!(G, a, b)
end
return G
end
function generateinstance(id, n, xsize, ysize, isize, rsize, dens)
X = Set{Integer}(1:xsize)
Y = Set{Integer}((n-ysize+1):n)
R = Set{Integer}((xsize+1):(n-ysize))
while(length(R) > rsize)
rem = rand(R)
delete!(R, rem)
end
#I = copy(R)
#while(length(I) > isize)
# rem = rand(I)
# delete!(I, rem)
#end
I = Set{Integer}()
G = generategraph(n, dens)
if id != "return"
writeinstance(G, X, Y, I, R, "instances/$id.in")
else
return G, X, Y, I, R
end
end
function generateinstances()
for rep in 1:50
for n in [10, 20, 30, 40, 50, 60]
for dens in [0.025, 0.05, 0.1, 0.2]
generateinstance("$n-$dens-$rep", n, div(n, 10), div(n, 10), div(n, 10), div(n, 2), dens)
end
end
end
end