1
votes

I'm using Julia's JuMP solver to try to find an optimal path.

My problem is that the objective function is a sum of the elements of a matrix whose indices are variables from my optimization problem.

nb_dem, nb_prod, nb_mag, nb_noeuds, S, Q, R = read_data_24(inputfilepath, inputfilename)
@variable(model, produits[1:nb_mag,1:nb_prod,1:nb_dem] >= 0, Int)
@variable(model, chemins[1:nb_noeuds+1, 1:nb_mag], Int)
@variable(model, binaires[1:nb_mag,1:nb_dem], Bin)

# define objective function
@objective(model, Min, sum(sum(R[chemins[k,i],chemins[k+1,i]] for k in 1:nb_noeuds) for i in 1:nb_mag))

I've added some constraint but when I try to run, I get an error message telling me that I cannot use VariablesRef as indices.

ArgumentError: invalid index: chemins[1,1] of type VariableRef

Is there anyway of converting VariablesRef into useable index?

1
It would be nice if you could edit your question to contain only the lines that are problem specific so this is usable for others.Przemyslaw Szufel

1 Answers

3
votes

You need to create a binary vector to represent the indices and than multiply by it, for an example:

x = [2,5,7]
@variable(m, x_indices[1:length(x)])
@variable(m, y)
@constraint(m, y >= sum(x .* x_indices))
@constraint(m, sum(x_indices) == 1)