# Efficiently Retrieving Variable Values after Gurobi optimization with JuMP

**URL:** <https://discourse.julialang.org/t/efficiently-retrieving-variable-values-after-gurobi-optimization-with-jump/127049>\
**Category:** Optimization (Mathematical)\
**Tags:** gurobi\
**Created:** [March 17, 2025, 10:51am UTC](https://discourse.julialang.org/t/efficiently-retrieving-variable-values-after-gurobi-optimization-with-jump/127049 "2025-03-17T10:51:06Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![WalterMadelim](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@WalterMadelim](https://discourse.julialang.org/u/WalterMadelim)\
**Post date:** [March 20, 2025, 11:19am UTC](https://discourse.julialang.org/t/efficiently-retrieving-variable-values-after-gurobi-optimization-with-jump/127049/15 "2025-03-20T11:19:37Z")

</div>

Actually I knew this package `Dualization.jl`.  
But my dream is different, being something like a code generator (e.g. ChatGPT).  
If a segment of JuMP **code** of the primal formulation is input into it, then it can print the JuMP **code** of the dual formulation in julia REPL, then I can copy it to my text editor. (Sounds a bit advanced, but it is bound to be way more _flexible_—thus _usable_)  
For example, I input the following **code**

```julia
function stage2_problem_primal(z, d)
    JuMP.@variable(st2, x[i = 1:3, j = 1:3] >= 0)
    JuMP.@constraint(st2, DI[i = 1:3], z[i] >= sum(x[i, :]))
    JuMP.@constraint(st2, DJ[j = 1:3], sum(x[:, j]) >= d[j] )
    JuMP.@objective(st2, Min, sm(C_x, x))
end

```

Then an oracle gives me the following **code** at julia REPL

```julia
function stage2_problem_dual(z, d)
    JuMP.@variable(Dst2, DI[i = 1:3] >= 0)
    JuMP.@variable(Dst2, DJ[j = 1:3] >= 0)
    JuMP.@constraint(Dst2, x[i = 1:3, j = 1:3], C_x[i, j] + DI[i] - DJ[j] >= 0)
    JuMP.@objective(Dst2, Max, sm(DJ, d) - sm(DI, z))
end

```

The `sm` function is `dot`, see [here](https://discourse.julialang.org/t/inner-product-grammar-is-neater-than-sum-index-in-jump-modeling-but-triggers-warning/124528/28).  
As you can see there are strong **correspondence** among the two:

1. The primal is Min, then the dual is Max.
2. The primal’s variables become the dual’s constraint, whereas the primal’s constraint become the dual’s variable
3. If we do not write “\<=” constraint, and do not use “\<= 0” variables in the primal side, then **the same appearance will be** on the dual side.

---

_[View the full topic](https://discourse.julialang.org/t/efficiently-retrieving-variable-values-after-gurobi-optimization-with-jump/127049)._
