-
Notifications
You must be signed in to change notification settings - Fork 0
/
gerador_pbp.jl
75 lines (62 loc) · 1.68 KB
/
gerador_pbp.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
# Extraído de:
# Yunsong Guo, Andrew Lim, Brian Rodrigues, and Jiqing Tang.
# Using alagrangian heuristic for a combinatorial auction problem.
# In17th IEEEInternational Conference on Tools with Artificial
# Intelligence (ICTAI’05),pages 5–pp. IEEE, 2005.
using Printf, DelimitedFiles
function PBP_testset(m, n, d)
P = 1:m # Conjunto de produtos
L = 1:n # Conjunto de lances
# Step 1: Generate coefficient matrix A
a = zeros(Int, m, n)
for j in L
for i in P
rnd = rand(Float64)
if rnd < d
a[i,j] = 1
end
end
end
# Step 2: Generate prices for the products
p = zeros(m)
for i in P
f = 0.9 + rand(Float64)*.2
p[i] = sum(a[i,:])*f
end
# Step 3: Generate prices for the bids
c = zeros(1,n)
for j in L
f = 0.9 + rand(Float64)*.2
c[j] = sum(p[i]*a[i,j] for i in P)*f
end
return a, c
end
# Características do conjunto de dados
nomeBase = "Instâncias/pbp_"
m = 50 # Numero de produtos
n = 50 # Numero de lances (pacotes)
d = 0.2 # Densidade de probabilidade de um lance cobrir um produto
# Criando e salvando o conjunto
a, c = PBP_testset(m, n, d)
outFile = @sprintf("%s%i-%i_dens%f.txt", nomeBase, m, n, d)
P = 1:m
L = 1:n
open(outFile, "w") do io
writedlm(io, [m n])
writedlm(io, c)
for i in P
lances = Int64[]
for j in L
if a[i,j] == 1
push!(lances, j)
end
end
nLances = length(lances)
writedlm(io, nLances)
if nLances > 0
writedlm(io, reshape(lances, 1, nLances))
else
writedlm(io, " ")
end
end
end