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
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
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.
As you can see there are strong correspondence among the two:
- The primal is Min, then the dual is Max.
- The primal’s variables become the dual’s constraint, whereas the primal’s constraint become the dual’s variable
- 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.