# How to understand the optimization behavior JuMP?

**URL:** https://discourse.julialang.org/t/how-to-understand-the-optimization-behavior-jump/76736
**Category:** Optimization (Mathematical)
**Tags:** jump
**Created:** [February 19, 2022, 11:48am UTC](https://discourse.julialang.org/t/how-to-understand-the-optimization-behavior-jump/76736 "2022-02-19T11:48:04Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Jian\_ZUO](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jian_zuo/32/33738_2.png) [@Jian\_ZUO](https://discourse.julialang.org/u/Jian_ZUO)
#### Post date: [February 19, 2022, 11:48am UTC](https://discourse.julialang.org/t/how-to-understand-the-optimization-behavior-jump/76736/1 "2022-02-19T11:48:04Z")

</div>

Hi, I am new to Julia and JuMP package. Recently I am trying to use JuMP  
to solve similar optimization problems like _Power Systems_ posted in JuMP’s tutorial.  
I read through the page, find the section unit commitment is amazing! Following is the code from  
the JuMP website:

> using JuMP  
> import DataFrames  
> import GLPK  
> import Plots  
> import StatsPlots  
> function ThermalGenerator(  
> min::Float64,  
> max::Float64,  
> fixed\_cost::Float64,  
> variable\_cost::Float64,  
> )  
> return (  
> min = min,  
> max = max,  
> fixed\_cost = fixed\_cost,  
> variable\_cost = variable\_cost,  
> )  
> end
> 
> generators = [  
> ThermalGenerator(0.0, 1000.0, 1000.0, 50.0),  
> ThermalGenerator(300.0, 1000.0, 0.0, 100.0),  
> ]  
> WindGenerator(variable\_cost::Float64) = (variable\_cost = variable\_cost,)
> 
> wind\_generator = WindGenerator(50.0)  
> function Scenario(demand::Float64, wind::Float64)  
> return (demand = demand, wind = wind)  
> end
> 
> scenario = Scenario(1500.0, 200.0)  
> function solve\_uc(generators::Vector, wind, scenario)  
> uc = Model(GLPK.Optimizer)  
> N = length(generators)  
> @variable(uc, generators[i].min \<= g[i = 1:N] \<= generators[i].max)  
> @variable(uc, 0 \<= w \<= scenario.wind)  
> @constraint(uc, sum(g[i] for i in 1:N) + w == scenario.demand)  
> # !!! New: add binary on-off variables for each generator  
> @variable(uc, u[i = 1:N], Bin)  
> @constraint(uc, [i = 1:N], g[i] \<= generators[i].max \* u[i])  
> @constraint(uc, [i = 1:N], g[i] \>= generators[i].min \* u[i])  
> @objective(  
> uc,  
> Min,  
> sum(generators[i].variable\_cost \* g[i] for i in 1:N) +  
> wind.variable\_cost \* w +  
> # !!! new  
> sum(generators[i].fixed\_cost \* u[i] for i in 1:N)  
> )  
> optimize!(uc)  
> status = termination\_status(uc)  
> if status != OPTIMAL  
> return (status = status,)  
> end  
> return (  
> status = status,  
> g = value.(g),  
> w = value(w),  
> wind\_spill = scenario.wind - value(w),  
> u = value.(u),  
> total\_cost = objective\_value(uc),  
> )  
> end

> solution = solve\_uc(generators, wind\_generator, scenario)
> 
> println("Dispatch of Generators: “, solution.g, " MW”)  
> println("Commitments of Generators: ", solution.u)  
> println("Dispatch of Wind: “, solution.w, " MW”)  
> println("Wind spillage: “, solution.wind\_spill, " MW”)  
> println(“Total cost: $”, solution.total\_cost)

Here, the unit commit is achieved by introducing the binary variable **u**.  
Can we think of this case as a mix-integer optimization problem? So JuMP can be directly used to  
solve a mix-integer optimization problem? Because I was expecting a mix-integer solve to solve this kind of problem where the decision variables include integer and real numbers (float).  
Thank you very much for your time!

---

<div class="post-metadata">

### Author: ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)
#### Post date: [February 19, 2022, 1:33pm UTC](https://discourse.julialang.org/t/how-to-understand-the-optimization-behavior-jump/76736/2 "2022-02-19T13:33:07Z")

</div>

> [@Jian\_ZUO](#):
>
> Can we think of this case as a mix-integer optimization problem?

Yes? I mean there are binary and continuous variables. And both are relevant to the solution (will not be optimized out).

> [@Jian\_ZUO](#):
>
> So JuMP can be directly used to solve a mix-integer optimization problem?

What exactly do you mean by that? JuMP is an abstraction layer that allow you to create mathematical models and then choose between many solvers available changing just one or two lines. JuMP does not solve anything by itself, in this example it is using the GLPK solver to do the optimization.

---

<div class="post-metadata">

### Author: ![Jian\_ZUO](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jian_zuo/32/33738_2.png) [@Jian\_ZUO](https://discourse.julialang.org/u/Jian_ZUO)
#### Post date: [February 19, 2022, 1:55pm UTC](https://discourse.julialang.org/t/how-to-understand-the-optimization-behavior-jump/76736/3 "2022-02-19T13:55:28Z")

</div>

Yes. I see. I will check more with the GLPK solver. Thanks!

---

<div class="post-metadata">

### Author: ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)
#### Post date: [February 19, 2022, 2:00pm UTC](https://discourse.julialang.org/t/how-to-understand-the-optimization-behavior-jump/76736/4 "2022-02-19T14:00:45Z")

</div>

I can already say to you that GLPK is open source, automatically installed, and, in general, a great choice for toy models. But for really big models, you want an academic license of either Gurobi, CPLEX, or Xpress. For these you need a commercial or academic license from their official site. I use Gurobi, so each 2~3 months I need to call a command from inside my university’s network with a new license code that I get from their site to re-validate the Gurobi installation in my machine.

---

<div class="post-metadata">

### Author: ![Jian\_ZUO](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jian_zuo/32/33738_2.png) [@Jian\_ZUO](https://discourse.julialang.org/u/Jian_ZUO)
#### Post date: [February 19, 2022, 2:19pm UTC](https://discourse.julialang.org/t/how-to-understand-the-optimization-behavior-jump/76736/5 "2022-02-19T14:19:47Z")

</div>

Thank you for the information! I think I will need more powerful solvers. I have installed Gurobi and CPLEX with academic licenses.
