# Formulating a customized optimization problem in JuliaOpt

**URL:** <https://discourse.julialang.org/t/formulating-a-customized-optimization-problem-in-juliaopt/76260>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [February 11, 2022, 4:20pm UTC](https://discourse.julialang.org/t/formulating-a-customized-optimization-problem-in-juliaopt/76260 "2022-02-11T16:20:15Z")\
**Posts on this page:** 3\
**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 11, 2022, 4:20pm UTC](https://discourse.julialang.org/t/formulating-a-customized-optimization-problem-in-juliaopt/76260/1 "2022-02-11T16:20:16Z")

</div>

Hello everyone,  
I have clear modeling requirements, but not sure **how to** (or **is it possible to** ) implement my problem with Julia optimization packages, like JuMP.  
**General optimization problem:**

> Objective function: obj(x, y, z)  
> Decision variables: (x, y, z)  
> Constraints: x + y + z = 1 (as an example)

Main **requirements** for the optimization:

1. I needed to do a **sequential optimization** , i.e. repeatedly solve the above optimization problem.
2. The variables x, y, z are related to actual systems, for example, related to three batteries, x for battery 1, y for battery 2, and z for battery 3.
3. Thus for the sequential optimization problems, there will be a case at **some stage** (we do know it in advance, but during the simulation there will be an index value ( **updated** ) for each battery to indicate whether a battery is functioning), some **batteries may fail** due to performance aging.
4. To adapt to this situation, I need the **decision variables to be able to change** : for example, if battery 1 fails, I need to "_get rid of_ " decision variable x and continue the optimization with decision variables y, z.

**My problem** :  
Is it possible to implement such varying variables optimization in Julia?  
Thank you very much for checking!

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [February 11, 2022, 10:30pm UTC](https://discourse.julialang.org/t/formulating-a-customized-optimization-problem-in-juliaopt/76260/2 "2022-02-11T22:30:52Z")

</div>

Sure, you can do all of this in JuMP. However, your question is a little too broad to get a good answer. (It’s easier to provide advice if you have a first attempt at coding that we can offer suggestions to improve, rather than asking generic questions.)

- Have you formulated this on paper first?
- Are you trying to find an optimal policy? Or are you okay using a myopic one? For example, do you intend to take into account when the battery will fail in earlier actions?

If you want to formulate this as a multistage stochastic program, check out: [https://github.com/odow/SDDP.jl](https://github.com/odow/SDDP.jl).

Otherwise, you should take a look at some of the examples in the JuMP documentation: [Power Systems · JuMP](https://jump.dev/JuMP.jl/stable/tutorials/applications/power_systems/)

---

<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 11, 2022, 11:40pm UTC](https://discourse.julialang.org/t/formulating-a-customized-optimization-problem-in-juliaopt/76260/3 "2022-02-11T23:40:28Z")

</div>

Thanks, Odow.  
Actually, this is the problem I have already implemented in Python and I didn’t  
find a suitable solution. And recently I am learning Julia, so I tried to implement  
my problem with Julia.  
I will read the materials you provide and then repost a specific problem.

For the two questions you posed,

1. I will recheck (formulate) my problem and ask with a specific example.
2. You are right, I was doing something like optimal control and my goal is to find an optimal policy.  
I think I will need to consider various optimization horizons, both short-term and long-term.
