See this example. The expression y looks correct, but when used in the objective it substitutes y[i] -> x[i] instead of y[i] -> x[p[I]]:
julia> using ExaModels, NLPModelsIpopt
julia> begin
core = ExaModels.ExaCore(; concrete = Val(true))
p = [3, 1, 2]
x0 = [1, 2, 3]
core, x = ExaModels.add_var(core, 3; lvar = x0, uvar = x0)
core, y = ExaModels.add_expr(core, x[p_i] for p_i in p)
core, _ = ExaModels.add_obj(core, i * y[i] for i in 1:3)
m = ExaModels.ExaModel(core)
result = NLPModelsIpopt.ipopt(m; print_level = 0)
result.objective, sum(i * x0[p[i]] for i in 1:3)
end
(14.0, 11)
julia> y
Subexpression (reduced)
s ∈ R^{3}
s(x,i) = x[i]
julia> y[1], y[2], y[3]
(x[3], x[1], x[2])
See this example. The expression
ylooks correct, but when used in the objective it substitutesy[i] -> x[i]instead ofy[i] -> x[p[I]]: