Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
17
Task/Knapsack-problem-0-1/Julia/knapsack-problem-0-1-1.julia
Normal file
17
Task/Knapsack-problem-0-1/Julia/knapsack-problem-0-1-1.julia
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
struct KPDSupply{T<:Integer}
|
||||
item::String
|
||||
weight::T
|
||||
value::T
|
||||
quant::T
|
||||
end
|
||||
|
||||
KPDSupply{T<:Integer}(itm::AbstractString, w::T, v::T, q::T=one(T)) = KPDSupply(itm, w, v, q)
|
||||
Base.show(io::IO, kdps::KPDSupply) = print(io, kdps.quant, " ", kdps.item, " ($(kdps.weight) kg, $(kdps.value) €)")
|
||||
|
||||
using MathProgBase, Cbc
|
||||
function solve(gear::Vector{<:KPDSupply}, capacity::Integer)
|
||||
w = getfield.(gear, :weight)
|
||||
v = getfield.(gear, :value)
|
||||
sol = mixintprog(-v, w', '<', capacity, :Bin, 0, 1, CbcSolver())
|
||||
gear[sol.sol .≈ 1]
|
||||
end
|
||||
27
Task/Knapsack-problem-0-1/Julia/knapsack-problem-0-1-2.julia
Normal file
27
Task/Knapsack-problem-0-1/Julia/knapsack-problem-0-1-2.julia
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
gear = [KPDSupply("map", 9, 150),
|
||||
KPDSupply("compass", 13, 35),
|
||||
KPDSupply("water", 153, 200),
|
||||
KPDSupply("sandwich", 50, 160),
|
||||
KPDSupply("glucose", 15, 60),
|
||||
KPDSupply("tin", 68, 45),
|
||||
KPDSupply("banana", 27, 60),
|
||||
KPDSupply("apple", 39, 40),
|
||||
KPDSupply("cheese", 23, 30),
|
||||
KPDSupply("beer", 52, 10),
|
||||
KPDSupply("suntan cream", 11, 70),
|
||||
KPDSupply("camera", 32, 30),
|
||||
KPDSupply("T-shirt", 24, 15),
|
||||
KPDSupply("trousers", 48, 10),
|
||||
KPDSupply("umbrella", 73, 40),
|
||||
KPDSupply("waterproof trousers", 42, 70),
|
||||
KPDSupply("waterproof overclothes", 43, 75),
|
||||
KPDSupply("note-case", 22, 80),
|
||||
KPDSupply("sunglasses", 7, 20),
|
||||
KPDSupply("towel", 18, 12),
|
||||
KPDSupply("socks", 4, 50),
|
||||
KPDSupply("book", 30, 10)]
|
||||
|
||||
pack = solve(gear, 400)
|
||||
println("The hicker should pack: \n - ", join(pack, "\n - "))
|
||||
println("\nPacked weight: ", mapreduce(x -> x.weight, +, pack), " kg")
|
||||
println("Packed value: ", mapreduce(x -> x.value, +, pack), " €")
|
||||
Loading…
Add table
Add a link
Reference in a new issue