# \[MOI / JuMP\] Multiple Result Indexing Bug

**URL:** <https://discourse.julialang.org/t/moi-jump-multiple-result-indexing-bug/35140>\
**Category:** Optimization (Mathematical)\
**Created:** [February 25, 2020, 9:34pm UTC](https://discourse.julialang.org/t/moi-jump-multiple-result-indexing-bug/35140 "2020-02-25T21:34:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pulsipher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pulsipher/32/10461_2.png) [@pulsipher](https://discourse.julialang.org/u/pulsipher)\
**Post date:** [February 25, 2020, 9:34pm UTC](https://discourse.julialang.org/t/moi-jump-multiple-result-indexing-bug/35140/1 "2020-02-25T21:34:50Z")

</div>

While developing tests for my JuMP extension in accordance with the newly supported multiple result indexing, I discovered that the same MOI attribute value is returned irrespective of the result index (returning the value of whatever was set last). This behavior is demonstrated in the following minimum working example using JuMP v0.21.1 and MOI v0.9.11:

```julia
using JuMP, MathOptInterface; const MOI = MathOptInterface; const MOIU = MOI.Utilities
m = Model()
@variable(m, x >= 0.0)
set_optimizer(m, () -> MOIU.MockOptimizer( MOIU.Model{Float64}(), 
                       eval_objective_value = false))
JuMP.optimize!(m)

mock = JuMP.backend(m).optimizer.model
MOI.set(mock, MOI.TerminationStatus(), MOI.OPTIMAL)
MOI.set(mock, MOI.ResultCount(), 2)
MOI.set(mock, MOI.VariablePrimal(1), JuMP.optimizer_index(x), 1.0)
MOI.set(mock, MOI.VariablePrimal(2), JuMP.optimizer_index(x), 0.0)

value1 = value(x, result = 1) # should be 1.0
value2 = value(x, result = 2) # should be 0.0

println("Result 1: ", value1)
println("Result 2: ", value2)

```

```julia
Result 1: 0.0 # not correct
Result 2: 0.0 # correct

```

Is this a bug with MOI and/or JuMP?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [February 25, 2020, 9:58pm UTC](https://discourse.julialang.org/t/moi-jump-multiple-result-indexing-bug/35140/2 "2020-02-25T21:58:21Z")

</div>

It’s an issue with the mock optimizer.

> <https://github.com/jump-dev/MathOptInterface.jl/blob/41ded26911eb3f517537f7134b2e9e2402d337e3/src/Utilities/mockoptimizer.jl#L335>

Please open an issue at MathOptInterface.jl. Pull requests to add result indices to MockOptimizer appreciated.

---

<div class="post-metadata">

**Author:** ![pulsipher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pulsipher/32/10461_2.png) [@pulsipher](https://discourse.julialang.org/u/pulsipher)\
**Post date:** [February 25, 2020, 10:12pm UTC](https://discourse.julialang.org/t/moi-jump-multiple-result-indexing-bug/35140/3 "2020-02-25T22:12:12Z")

</div>

Gotcha. I just opened an issue. [Multiple Results with MockOptimizer · Issue #1036 · jump-dev/MathOptInterface.jl · GitHub](https://github.com/JuliaOpt/MathOptInterface.jl/issues/1036)
