# Piecewise Linearlization of Quadratic functions

**URL:** https://discourse.julialang.org/t/piecewise-linearlization-of-quadratic-functions/10988
**Category:** Optimization (Mathematical)
**Created:** [May 18, 2018, 1:03pm UTC](https://discourse.julialang.org/t/piecewise-linearlization-of-quadratic-functions/10988 "2018-05-18T13:03:54Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![tfk17lstm](https://avatars.discourse-cdn.com/v4/letter/t/f0a364/32.png) [@tfk17lstm](https://discourse.julialang.org/u/tfk17lstm)
#### Post date: [May 18, 2018, 1:03pm UTC](https://discourse.julialang.org/t/piecewise-linearlization-of-quadratic-functions/10988/1 "2018-05-18T13:03:54Z")

</div>

Dear colleagues,

I have managed to implement the unit commitment problem with JuMP adding the time varying constrains that I mentioned in my last post. I was using the Cbc solver and I would like to know if JuMP has a function that automatically linearize a quadratic function, something similar to [https://cran.r-project.org/web/packages/segmented/segmented.pdf](https://cran.r-project.org/web/packages/segmented/segmented.pdf).

Has anyone done this before?

---

<div class="post-metadata">

### Author: ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)
#### Post date: [May 18, 2018, 1:13pm UTC](https://discourse.julialang.org/t/piecewise-linearlization-of-quadratic-functions/10988/2 "2018-05-18T13:13:24Z")

</div>

Maybe this is useful: [GitHub - joehuchette/PiecewiseLinearOpt.jl: Solve optimization problems containing piecewise linear functions](https://github.com/joehuchette/PiecewiseLinearOpt.jl)? The author, @joehuchette, may be able to help you with this.

---

<div class="post-metadata">

### Author: ![ccoffrin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccoffrin/32/400_2.png) [@ccoffrin](https://discourse.julialang.org/u/ccoffrin)
#### Post date: [May 18, 2018, 2:13pm UTC](https://discourse.julialang.org/t/piecewise-linearlization-of-quadratic-functions/10988/3 "2018-05-18T14:13:35Z")

</div>

@tfk17lstm, have you had a look at PowerModels.jl?

[https://github.com/lanl-ansi/PowerModels.jl](https://github.com/lanl-ansi/PowerModels.jl)

An implementation of convex PWL costs, as defined in Matpower, is implemented here,

[https://github.com/lanl-ansi/PowerModels.jl/blob/master/src/core/objective.jl#L195](https://github.com/lanl-ansi/PowerModels.jl/blob/master/src/core/objective.jl#L195)

---

<div class="post-metadata">

### Author: ![tfk17lstm](https://avatars.discourse-cdn.com/v4/letter/t/f0a364/32.png) [@tfk17lstm](https://discourse.julialang.org/u/tfk17lstm)
#### Post date: [May 21, 2018, 1:37pm UTC](https://discourse.julialang.org/t/piecewise-linearlization-of-quadratic-functions/10988/4 "2018-05-21T13:37:19Z")

</div>

Hi @ccoffrin I have checked but the problem is that my function is non-convex so I think that I will get an error.

---

<div class="post-metadata">

### Author: ![ccoffrin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccoffrin/32/400_2.png) [@ccoffrin](https://discourse.julialang.org/u/ccoffrin)
#### Post date: [May 21, 2018, 4:43pm UTC](https://discourse.julialang.org/t/piecewise-linearlization-of-quadratic-functions/10988/5 "2018-05-21T16:43:17Z")

</div>

Good to know your functions are non-convex. I’ve added feature request here,

[https://github.com/lanl-ansi/PowerModels.jl/issues/287](https://github.com/lanl-ansi/PowerModels.jl/issues/287)

Incase you would like to track it.

Note that the primary reason PowerModels does not currently support non-convex functions is that scalability of the model can be a significant challenge.

---

<div class="post-metadata">

### Author: ![tfk17lstm](https://avatars.discourse-cdn.com/v4/letter/t/f0a364/32.png) [@tfk17lstm](https://discourse.julialang.org/u/tfk17lstm)
#### Post date: [May 22, 2018, 7:06am UTC](https://discourse.julialang.org/t/piecewise-linearlization-of-quadratic-functions/10988/6 "2018-05-22T07:06:29Z")

</div>

Yeah I agree with you. But my dispatch model is for less than 10 machines (I am developing a solution from the producer perspective) and the machines are equal (of course the IO curves are different due to degradation and ambient parameters) so I believe the problem can be solved.

I will try with another solver and quadratic objectives and if not I will try to implement this:

[https://github.com/GridMod/RTS-GMLC/blob/master/RTS\_Data/SourceData/HR\_data/Fit\_HRs.R](https://github.com/GridMod/RTS-GMLC/blob/master/RTS_Data/SourceData/HR_data/Fit_HRs.R)
