I am new to programming, so I hope that the description of my probleme is accurate:
Based on knapsack, I used JuMP and GLPK to come up with a solution for the unbounded knapsack problem.:
function unbounded_knapsack(validparam::Vector::{Float64})
weight = [validparam[i]^2 for i in 1:length(validparam)]
model = Model(GLPK.Optimizer)
@variable(model, x[1:(length(validparam))],Int)
@objective(model, Max, weight' * x)
@constraint(model, paramlist'*x == 20)
@constraint(model,x.>=0)
Jump.optimize!(model)
unbounded_knapsack([1.0,2.0,3.0,4.0,5.0])
The Function returns the Vector [0.0,0.0,0.0,0.0,4.0].
For my purpose the code works fine.
Now I want to have additional constraints:
@constraint(model,paramlist'*x==20)
@constraint(model,paramlist'*x==30)
@constraint(model,paramlist'*x==40)
...
I am getting this error:
ERROR: LoadError: Result index of attribute MathOptInterface.VariablePrimal(1) out of bounds. There are currently 0 solution(s) in the model.
The constraints represent additional knapsacks with weight constrictions = 20,30,40,…
The code should return the number of items of the parameterlist to fill the 3 knapsacks effectively.
Is there a way to implement these addtional constraints?
Do I even use the right Package for the varied unbounded knapsack problem?
Thanks.