# Cost for reactive power in PowerModels?

**URL:** https://discourse.julialang.org/t/cost-for-reactive-power-in-powermodels/16441
**Category:** Optimization (Mathematical)
**Created:** [October 17, 2018, 1:13pm UTC](https://discourse.julialang.org/t/cost-for-reactive-power-in-powermodels/16441 "2018-10-17T13:13:21Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![timueh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/timueh/32/12379_2.png) [@timueh](https://discourse.julialang.org/u/timueh)
#### Post date: [October 17, 2018, 1:13pm UTC](https://discourse.julialang.org/t/cost-for-reactive-power-in-powermodels/16441/1 "2018-10-17T13:13:21Z")

</div>

Hi there,

I am using `PowerModels` quite a bit – thanks @ccoffrin for this nice tool!

Usually, the cost function for optimal power flow problems depends solely on the _active_ power. For several reasons, I would like to add a term that assigns a cost for the _reactive_ power. In `objective.jl` of `PowerModels` I could not find any expression related to dictionary entries `:qg`.

My question is: is it implemented and I have simply overlooked it?

If it is not implemented, how could I fix it? My suggestion: to the dictionary returned by `PowerModels.parse_file()` I add an entry `cost_q` to each entry `gen`, and then I modify the function `objective_min_gen_polynomial_fuel_cost()` (assuming I have polynomial costs for the reactive power).

Any help is appreciated, thanks.

---

<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: [October 17, 2018, 3:27pm UTC](https://discourse.julialang.org/t/cost-for-reactive-power-in-powermodels/16441/2 "2018-10-17T15:27:38Z")

</div>

Hi @timueh, great to hear that you have found PowerModels useful!

In the base of PowerModels there are no objective functions that have reactive power.

My recommendation would be to play around with one of the models implemented in [PowerModelsAnnex](https://github.com/lanl-ansi/PowerModelsAnnex.jl/blob/master/src/model). You should be able to add your `cost_q` data to the Matpower files using [this feature](https://lanl-ansi.github.io/PowerModels.jl/stable/network-data.html#Working-with-Matpower-Data-Files-1) in PowerModels, so that you can access that data when building the objective function.

Once you have a working example using a PowerModelsAnnex model, then we can discuss how that can be translated into a PowerModels objective function.
