Reorganize package; add macros

This commit is contained in:
2021-04-09 07:16:06 -05:00
parent 96f7243d4c
commit eb7f7034a9
24 changed files with 824 additions and 290 deletions

25
src/problems/knapsack.jl Normal file
View 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