# Mopdify OBBT in PowerModels.jl to be applicable on model constructor in PowerModelsAnnex

**URL:** https://discourse.julialang.org/t/mopdify-obbt-in-powermodels-jl-to-be-applicable-on-model-constructor-in-powermodelsannex/19047
**Category:** Optimization (Mathematical)
**Created:** [December 28, 2018, 2:04am UTC](https://discourse.julialang.org/t/mopdify-obbt-in-powermodels-jl-to-be-applicable-on-model-constructor-in-powermodelsannex/19047 "2018-12-28T02:04:38Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Rasoul](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@Rasoul](https://discourse.julialang.org/u/Rasoul)
#### Post date: [December 28, 2018, 2:04am UTC](https://discourse.julialang.org/t/mopdify-obbt-in-powermodels-jl-to-be-applicable-on-model-constructor-in-powermodelsannex/19047/1 "2018-12-28T02:04:38Z")

</div>

Hi All,

I have developed a new model constructor in PowerModelsAnnex and want to apply the OBBT.jl in PowerModels to the model. Can you please guide me how can I do that? In other words, is it possible to call the model constructor(i.e., implemented in PowerModelsAnnex) in OBBT.jl? Any help would be appreciated.

All the best,  
Rasoul

---

<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: [December 28, 2018, 2:46am UTC](https://discourse.julialang.org/t/mopdify-obbt-in-powermodels-jl-to-be-applicable-on-model-constructor-in-powermodelsannex/19047/2 "2018-12-28T02:46:58Z")

</div>

`model_constructor` is a keyword argument of the function `run_obbt_opf`. For models that define the correct variables it should work fine with a model defined in another package.

---

<div class="post-metadata">

### Author: ![Rasoul](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@Rasoul](https://discourse.julialang.org/u/Rasoul)
#### Post date: [January 8, 2019, 8:26pm UTC](https://discourse.julialang.org/t/mopdify-obbt-in-powermodels-jl-to-be-applicable-on-model-constructor-in-powermodelsannex/19047/3 "2019-01-08T20:26:25Z")

</div>

> [@Rasoul](#):
>
> o the model. Can you please guide me how can I do that? In other words, is it possible to call the model constructor(i.e., implemented in PowerModelsAnnex) in OBBT.jl? Any help would be appreciated.
> 
> All the best,

Thanks for the response!  
There are different functions in PowerModelsAnnex (e.g., post\_qc\_opf) that solve the OPF problem. I wanna use one of these functions as a model\_constructor to do the optimization based bound tightening (OBBT). Can you please let me know what should I do to make the “post\_qc\_opf” compatible with OBBT.jl code in PowerModels. In other words, how can I call or use “post\_qc\_opf” function in OBBT.jl? Thanks in advance!

All the best,  
Rasoul

---

<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: [January 9, 2019, 9:24pm UTC](https://discourse.julialang.org/t/mopdify-obbt-in-powermodels-jl-to-be-applicable-on-model-constructor-in-powermodelsannex/19047/4 "2019-01-09T21:24:19Z")

</div>

The the OBBT function and its `model_constructor` argument are designed to work with the models defined in PowerModels. Not the stand alone models in PowerModelsAnnex. You can try making a copy of the OBBT function in PowerModels.jl and adapting it to work with the model constructors functions in PowerModelsAnnex.

---

<div class="post-metadata">

### Author: ![Rasoul](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@Rasoul](https://discourse.julialang.org/u/Rasoul)
#### Post date: [January 10, 2019, 6:01pm UTC](https://discourse.julialang.org/t/mopdify-obbt-in-powermodels-jl-to-be-applicable-on-model-constructor-in-powermodelsannex/19047/5 "2019-01-10T18:01:03Z")

</div>

Thanks for the response!

I am trying to adapt the OBBT code with one of model\_constructor functions (e.g., post\_qc\_opf) in PowerModels Annex. Can you please give me some hints about building the model\_relaxation by model\_constructor functions (e.g., post\_qc\_opf) in PowerModelsAnnex.

Without having a model\_relaxation I cannot use solve\_generic\_model for solving relaxation model. I am also not able to change the objective function (e.g., @objective(model\_bt.model, Max, vm[bus])) when I need to change them. I will really appreciate your comments.

All the best,

Rasoul

---

<div class="post-metadata">

### Author: ![Rasoul](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@Rasoul](https://discourse.julialang.org/u/Rasoul)
#### Post date: [January 16, 2019, 1:37am UTC](https://discourse.julialang.org/t/mopdify-obbt-in-powermodels-jl-to-be-applicable-on-model-constructor-in-powermodelsannex/19047/6 "2019-01-16T01:37:13Z")

</div>

Thanks for the response!

I have a question about the JuMP model in my modified OBBT code and I am not sure here is the right place to ask it. I took your word about adapting OBBT code with the model constructor in PowerModelsAnnex. I added the model constructor in PowerModelsAnnex as a function to the OBBT code and passed several flags into the function (i.e., modelconstructor) to select which objective at which direction to be optimized.  
The adapted OBBT code works properly and obtains the same solution that original OBBT obtains. However, the code gets super sluggish as it goes forward. Every time that the function (i.e., modelconstructor) gets called in the code, following warning shows up for all variables in the model:

```julia
Warning: A variable or constraint named va is already attached to this model. If creating variables programmatically, use the anonymous variable syntax x = @variable(m, [1:N], ...).

```

After each iteration variable’s bound get updated and there is no need to old model. Is there any way to get rid of the older model and build a new one for the next iteration in order to prevent the issue. I will appreciate your response!

All the best,  
Rasoul

---

<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: [January 16, 2019, 4:04pm UTC](https://discourse.julialang.org/t/mopdify-obbt-in-powermodels-jl-to-be-applicable-on-model-constructor-in-powermodelsannex/19047/7 "2019-01-16T16:04:05Z")

</div>

Yes. This is what the code in PowerModels does. It is not clear to me why your code would not do the same.
