Search code examples
juliagurobijulia-jump

Error with adding a variable that has repeated indices using Gurobi in Julia


I am using Gurobi with Julia to create a linear program, and I am having trouble adding a variable if it is indexed by a list with repeated elements. Specifically, I am trying to do the following command:

@variable(model, materialResources[[1, 1]])

where model is the model I initialized in Gurobi by

model = Model(with_optimizer(Gurobi.Optimizer, OutputFlag=0));

The program spits back the following error message:

ERROR: LoadError: Repeated index 1. Index sets must have unique elements.

How do I add an entry to my materialResources variable-vector if it is indexed by repeated elements?


Solution

  • You cannot add variables indexed by a set with repeated elements.

    Otherwise, if you could, which variable would materialResources[1] refer to?

    If you want a set with vectors as elements, use:

    model = Model()
    S = [[1, 1], [2, 2]]
    @variable(model, x[S])
    x[[1, 1]]