2
$\begingroup$

As part of our constraints, we have \begin{align*} &\sum_{i=1}^{I}c_ix_i\ge y, \\ &\sum_{i=1}^{I}c_{i-1}x_i\le y, \end{align*} where $y\ge0,x_i\in\{0,1\}, \forall i$.

I am trying to code these two constraints in Julia and solve the problem using gurobi or cplex but we cannot define index $i=0$ so we don't have $c_0$ there.

How can I code this? I tried this

c = zeros(I+1)
for i = 1:I+1
    c[i] = value
end
@variable(model, x[1:I], Bin)
@variable(model, y>=0)

But then there's a mismatch between variable and parameter index.

How should I correct this?

$\endgroup$

1 Answer 1

3
$\begingroup$

Just use c[i+1] when indexing c?

@constraint(model, sum(c[i+1] * x[i] for i in 1:I) >= y)
@constraint(model, sum(c[i] * x[i] for i in 1:I) <= y)

P.s. feel free to post on the JuMP community forum with these questions. Not sure how many Julia people hang out here: https://discourse.julialang.org/c/domain/opt/13

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.