mirror of
https://github.com/ANL-CEEESA/MIPLearn.jl.git
synced 2025-12-08 01:08:51 -06:00
Reorganize package; add macros
This commit is contained in:
25
src/problems/knapsack.jl
Normal file
25
src/problems/knapsack.jl
Normal file
@@ -0,0 +1,25 @@
|
||||
# MIPLearn: Extensible Framework for Learning-Enhanced Mixed-Integer Optimization
|
||||
# Copyright (C) 2020-2021, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
using JuMP
|
||||
|
||||
function knapsack_model(
|
||||
weights::Array{Float64, 1},
|
||||
prices::Array{Float64, 1},
|
||||
capacity::Float64,
|
||||
)
|
||||
model = Model()
|
||||
n = length(weights)
|
||||
@variable(model, x[0:(n-1)], Bin)
|
||||
@objective(model, Max, sum(x[i] * prices[i+1] for i in 0:(n-1)))
|
||||
@constraint(
|
||||
model,
|
||||
eq_capacity,
|
||||
sum(
|
||||
x[i] * weights[i+1]
|
||||
for i in 0:(n-1)
|
||||
) <= capacity,
|
||||
)
|
||||
return model
|
||||
end
|
||||
Reference in New Issue
Block a user