# Optimization problem with Julia - Launch sequence

**URL:** <https://discourse.julialang.org/t/optimization-problem-with-julia-launch-sequence/42311>\
**Category:** Optimization (Mathematical)\
**Tags:** jump, optimization\
**Created:** [June 30, 2020, 4:03pm UTC](https://discourse.julialang.org/t/optimization-problem-with-julia-launch-sequence/42311 "2020-06-30T16:03:58Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![beske](https://avatars.discourse-cdn.com/v4/letter/b/77aa72/32.png) [@beske](https://discourse.julialang.org/u/beske)\
**Post date:** [June 30, 2020, 4:03pm UTC](https://discourse.julialang.org/t/optimization-problem-with-julia-launch-sequence/42311/1 "2020-06-30T16:03:58Z")

</div>

Say you have _n_ different shops in which you want to launch a product for _n_ different months, and you want to maximize profits. The problem is determining the order of the launch sequence of the product when the price in shop\__i_ refers to the average price for the product in some given set of the shops. It is only possible to launch in one shop for every month, and it is only possible to launch one time in each shop. For every shop there is an initial price of the product, some given customer size, and baskets referring prices. Look at the following example:

> initial\_price = [1,2,4],

> customer\_size = [20, 15, 10]

> referring\_basket\_shop\_1 = {price\_shop\_2,price\_shop\_3}

> referring\_basket\_shop\_2 = {price\_shop\_3}

> referring\_basket\_shop\_3 = {price\_shop\_1, price\_shop\_2}

The first shop to launch the product initiates the price with the initial\_price parameter. If referring\_basket\_shop\ __i_ contains no launched shops, price\_shop\__ i_ = initial\_price\ __i_. If referring\_basket\_shop\__ i_ contains launched shops, price\_shop\ __i_ will be the average price of the launched prices in referring\_basket\_shop\__ i_.

Calculating all possible outcomes and determining the best one is a _n!_ problem, so I want to use Julia optimization (I don’t know which solver is the best, but in the following example I used Ipopt).

I **tried** to formulate the problem like this:

**x** is a _n_ by _n_ matrix containing the price for shop\_i and month\_i for i, j = 1:_n_.

**y** is a _n_ by _n_ matrix containing binary elements as decision variables i.e. if shop\__i_ launches in month\_j for i,j = 1:_n_.

**nr** is a _n_ by _n_ matrix containing only integer elements and it’s used to calculate the average i.e. ensuring that we divide with the correct number.

Here is my code:

```
using JuMP
using Ipopt
using MathOptInterface
using Juniper

n = 3

optimizer = Juniper.Optimizer
nl_solver = optimizer_with_attributes(Ipopt.Optimizer, "print_level" => 0)

m = Model(optimizer_with_attributes(optimizer, "nl_solver"=>nl_solver))

@variable(m, x[i = 1:n, j = 1:n] >= 0)
@variable(m, y[i = 1:n, j = 1:n], Bin)
@variable(m, nr[i = 1:n, j = 1:n], Int)

start = [1,2,4]
pop = [20,15,10]

@objective(m, Max, sum(x[i,j]*y[i,j] * pop[j] for i =1:n, j = 1:n) )

#Launch one time per shop
for j = 1:n
    @constraint(m, sum(y[i,j] for i = 1:n) == 1 )
end
#Launch one time per month
for i = 1:n
    @constraint(m, sum(y[i,j] for j = 1:n) == 1 )
end

#Initial price
for i = 1:n
    @constraint(m, x[i,1]*y[i,1] <= start[i] )
end

#Constraining nr
for i = 1:n
    for j = 1:n
        @constraint(m, nr[i,j] >= 1 )
        @constraint(m, nr[i,j] <= n )
    end
end

#Calculating launch sequence
for j = 2:n
    @constraint(m, nr[1,j] >= sum(y[2,i] + y[3,i] for i = 1:j-1) )
    @NLconstraint(m, x[1,j] == sum(y[2,i]*x[2,i] + y[3,i]*x[3,i] for i = 1:j-1) / nr[1,j] )

    @constraint(m, nr[2,j] >= sum(y[3,i] for i = 1:j-1) )
    @NLconstraint(m, x[2,j] == sum(y[3,i]*x[3,i] for i = 1:j-1) / nr[2,j] )

    @constraint(m, nr[3,j] >= sum(y[2,i] + y[1,i] for i = 1:j-1) )
    @NLconstraint(m, x[3,j] == sum(y[2,i]*x[2,i] + y[1,i]*x[1,i] for i = 1:j-1) / nr[3,j] )
end

optimize!(m)
println(JuMP.value.(x))
println(JuMP.value.(y))
println(JuMP.value.(nr))
println(JuMP.objective_value(m))
println(JuMP.termination_status(m))

```

My code does not give any useful results, and I am stuck. Any suggestions?

---

<div class="post-metadata">

**Author:** ![Wikunia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wikunia/32/2180_2.png) [@Wikunia](https://discourse.julialang.org/u/Wikunia)\
**Post date:** [June 30, 2020, 7:56pm UTC](https://discourse.julialang.org/t/optimization-problem-with-julia-launch-sequence/42311/2 "2020-06-30T19:56:19Z")

</div>

Can you clarify what you mean by: “Does not give any useful results”?

Juniper only solves the problem locally and your problem seems to be non-convex.

---

<div class="post-metadata">

**Author:** ![beske](https://avatars.discourse-cdn.com/v4/letter/b/77aa72/32.png) [@beske](https://discourse.julialang.org/u/beske)\
**Post date:** [June 30, 2020, 9:43pm UTC](https://discourse.julialang.org/t/optimization-problem-with-julia-launch-sequence/42311/3 "2020-06-30T21:43:25Z")

</div>

My results are not a feasible solution to the problem, I get:  
x = [100000.0 6.0 2.0; 1.78582e8 1.33333 4.0; 4.0 2.0 8.0]  
y = [0.0 1.0 5.38607e-9; 1.11994e-8 0.0 1.0; 1.0 1.58657e-8 0.0]

Does Julia have any non-convex solvers and what kind of problems do they solve?

---

<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:** [June 30, 2020, 10:10pm UTC](https://discourse.julialang.org/t/optimization-problem-with-julia-launch-sequence/42311/4 "2020-06-30T22:10:47Z")

</div>

There are very few MINLP solvers, and Juniper happens to be very good. You’ve just picked a very hard problem.

I suggest you step back and reconsider the formulation.

For example, if `x` has bounds `l` and `u`, such that `l <= x <= u`, then you can replace `x * y` with a new variable `z` and constraints `l * y <= z` and `z <= u * y`.

You should also declare `nr` as

```nohighlight
@variable(model, 1 <= nr[1:n, 1:n] <= n)

```

instead of adding the linear constraints.

If you do all of that, it should be representable as a mixed-integer _linear_ program, which is “easy” to solve.

---

<div class="post-metadata">

**Author:** ![beske](https://avatars.discourse-cdn.com/v4/letter/b/77aa72/32.png) [@beske](https://discourse.julialang.org/u/beske)\
**Post date:** [July 1, 2020, 6:17pm UTC](https://discourse.julialang.org/t/optimization-problem-with-julia-launch-sequence/42311/5 "2020-07-01T18:17:18Z")

</div>

Thank you for a good answer. I just don’t see how it can be expressed as a MILP, since we still have to divide with **nr** , and variable-division is non-linear.  
Also I tried to implement your approach with Juniper, but I’m producing NaN’s. Without Juniper and Ipopt I cannot make any non linear constraints, so I have not been able to implement the linear program that you mentioned.

> using JuMP  
> using Ipopt  
> using GLPK  
> using MathOptInterface  
> using Juniper  
> using GLPKMathProgInterface  
> using Statistics  
> using Cbc
> 
> n = 3
> 
> optimizer = Juniper.Optimizer  
> nl\_solver = optimizer\_with\_attributes(Ipopt.Optimizer, “print\_level” =\> 0)
> 
> m = Model(optimizer\_with\_attributes(optimizer, “nl\_solver”=\>nl\_solver))
> 
> @variable(m, x[i = 1:n, j = 1:n] \>= 0)  
> @variable(m, y[i = 1:n, j = 1:n], Bin)  
> @variable(m, z[i = 1:n, j = 1:n] \>= 0)  
> @variable(m, 1 \<= nr[i = 1:n, j = 1:n] \<= n, Int)
> 
> start = [8,7,6]  
> pop = [10,15,20]
> 
> l = 6 #min of start  
> u = 8 #max of start
> 
> @objective(m, Max, sum(z[i,j] \* pop[j] for i =1:n, j = 1:n) )
> 
> for j = 1:n  
> @constraint(m, sum(y[i,j] for i = 1:n) == 1 )  
> end
> 
> for i = 1:n  
> @constraint(m, sum(y[i,j] for j = 1:n) == 1 )  
> end
> 
> for i = 1:n  
> for j = 1:n  
> @constraint(m, z[i,j] == x[i,j]\*y[i,j])  
> end  
> end
> 
> #Initial price  
> for i = 1:n  
> @constraint(m, z[i,1] \<= start[i] )  
> end
> 
> for i = 1:n  
> for j = 1:n  
> @constraint(m, l \* y[i,j] \<= z[i,j])  
> @constraint(m, z[i,j] \<= u \* y[i,j])  
> end  
> end
> 
> for j = 2:n  
> @constraint(m, nr[1,j] \>= sum(y[2,i] + y[3,i] for i = 1:j-1) )  
> @NLconstraint(m, x[1,j] == sum(z[2,i] + z[3,i] for i = 1:j-1) / nr[1,j] )
> 
> ```
> @constraint(m, nr[2,j] >= sum(y[3,i] for i = 1:j-1) )
> @NLconstraint(m, x[2,j] == sum(z[3,i] for i = 1:j-1) / nr[2,j] )
> 
> @constraint(m, nr[3,j] >= sum(y[2,i] + y[1,i] for i = 1:j-1) )
> @NLconstraint(m, x[3,j] == sum(z[2,i] + z[1,i] for i = 1:j-1) / nr[3,j] )
> 
> ```
> 
> end
> 
> optimize!(m)  
> println(JuMP.value.(x))  
> println(JuMP.value.(y))  
> println(JuMP.value.(nr))  
> println(JuMP.objective\_value(m))  
> println(JuMP.termination\_status(m))

What am I doing wrong?

---

<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:** [July 1, 2020, 6:33pm UTC](https://discourse.julialang.org/t/optimization-problem-with-julia-launch-sequence/42311/6 "2020-07-01T18:33:33Z")

</div>

Multiply both sides by `nr` to remove the division, then expand out `nr` to the sum of the binary variables `y`.

---

<div class="post-metadata">

**Author:** ![beske](https://avatars.discourse-cdn.com/v4/letter/b/77aa72/32.png) [@beske](https://discourse.julialang.org/u/beske)\
**Post date:** [July 1, 2020, 11:30pm UTC](https://discourse.julialang.org/t/optimization-problem-with-julia-launch-sequence/42311/7 "2020-07-01T23:30:03Z")

</div>

I tried to follow your hint, but I keep getting NaNs and errors. What do you mean by expand out `nr`, when `nr` is defined as a sum of `y` just above?  
The GLPK solver is supposed to support MIPs, but it refuses to deal with some of the constraints i.e. `z = x * y` and the constraints where I multiplied with `nr` to avoid division prompting that “constraints of type MathOptInterface.ScalarQuadraticFunction.EqualTo{Float64} are not supported by the solver”. Am I supposed to use GLPK or Ipopt/Juniper and what about `nr`? Thank you very much for your help.

> using JuMP  
> using GLPK  
> using MathOptInterface  
> using GLPKMathProgInterface
> 
> n = 3
> 
> m = Model(optimizer\_with\_attributes(GLPK.Optimizer, “tm\_lim” =\> 60000))
> 
> @variable(m, x[i = 1:n, j = 1:n] \>= 0)  
> @variable(m, y[i = 1:n, j = 1:n], Bin)  
> @variable(m, z[i = 1:n, j = 1:n] \>= 0)  
> @variable(m, 1 \<= nr[i = 1:n, j = 1:n] \<= n, Int)
> 
> start = [8,7,6]  
> pop = [10,15,20]
> 
> l = 6 #min of start  
> u = 8 #max of start
> 
> @objective(m, Max, sum(z[i,j] \* pop[j] for i =1:n, j = 1:n) )
> 
> for j = 1:n
> 
> ```
> @constraint(m, sum(y[i,j] for i = 1:n) == 1 )
> 
> ```
> 
> end
> 
> for i = 1:n
> 
> ```
> @constraint(m, sum(y[i,j] for j = 1:n) == 1 )
> 
> ```
> 
> end
> 
> for i = 1:n  
> for j = 1:n
> 
> ```
> @constraint(m, z[i,j] == x[i,j] * y[i,j] )
> end
> 
> ```
> 
> end
> 
> #Initial price  
> for i = 1:n
> 
> ```
> @constraint(m, z[i,1] <= start[i] )
> 
> ```
> 
> end
> 
> for i = 1:n  
> for j = 1:n
> 
> ```
> @constraint(m, l * y[i,j] <= z[i,j])
> @constraint(m, z[i,j] <= u * y[i,j])
> end
> 
> ```
> 
> end
> 
> for j = 2:n
> 
> ```
> @constraint(m, nr[1,j] >= sum(y[2,i] + y[3,i] for i = 1:j-1) )
> @constraint(m, nr[1,j] * x[1,j] == sum(z[2,i] + z[3,i] for i = 1:j-1) )
> 
> @constraint(m, nr[2,j] >= sum(y[3,i] for i = 1:j-1) )
> @constraint(m, nr[2,j] * x[2,j] == sum(z[3,i] for i = 1:j-1) )
> 
> @constraint(m, nr[3,j] >= sum(y[2,i] + y[1,i] for i = 1:j-1) )
> @constraint(m, nr[3,j] * x[3,j] == sum(z[2,i] + z[1,i] for i = 1:j-1) )
> 
> ```
> 
> end
> 
> optimize!(m)  
> println(JuMP.value.(x))  
> println(JuMP.value.(y))  
> println(JuMP.value.(nr))  
> println(JuMP.objective\_value(m))  
> println(JuMP.termination\_status(m))

---

<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:** [July 2, 2020, 12:01am UTC](https://discourse.julialang.org/t/optimization-problem-with-julia-launch-sequence/42311/8 "2020-07-02T00:01:59Z")

</div>

1. Remove the `z = x * y` constraint.
2. `nr[1,j] * x[1,j]` is equivalent to `x[1, j] * y[2, i] + x[1, j] * y[3, i] + ...` you you can apply the same trick. For the inequality, if `nr >=`, then when it was on the denominator, increasing it acts to make the right-hand side smaller. Therefore, you can replace

```nohighlight
@constraint(m, x[1,j] == sum(z[2,i] + z[3,i] for i = 1:j-1) / nr[1,j])

```

with something like

```nohighlight
@constraint(m, x[1, j] * y[2, i] + x[1, j] * y[3, i] + ... >= sum(z[2,i] + z[3,i] for i = 1:j-1))

```

Alternatively, just use a solver like `Gurobi.jl`, and you can write `x * y` directly and it will do this reformulation for you.

---

<div class="post-metadata">

**Author:** ![beske](https://avatars.discourse-cdn.com/v4/letter/b/77aa72/32.png) [@beske](https://discourse.julialang.org/u/beske)\
**Post date:** [July 2, 2020, 9:30pm UTC](https://discourse.julialang.org/t/optimization-problem-with-julia-launch-sequence/42311/9 "2020-07-02T21:30:39Z")

</div>

Okay, I used the Gurobi solver and the code is running! Thank you a lot for your help, you really got me out of the rabbit hole. Do you by any chance know the complexity of the algorithm for the launch problem of `n` shops with the Gurobi solver? And it is possible to make changes that will minimize the run time? (I’m currently at 7 hours for `n = 12` and it is still running, which worries me a bit since I figure that I would be done by now for `n = 12` with a brute force approach.)

---

<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:** [July 2, 2020, 10:04pm UTC](https://discourse.julialang.org/t/optimization-problem-with-julia-launch-sequence/42311/10 "2020-07-02T22:04:25Z")

</div>

What’s your new model? MIP solve time can be very sensitive to formulation. Make sure you put good bounds on `x`.

For complexity, see: [Integer programming - Wikipedia](https://en.wikipedia.org/wiki/Integer_programming#Proof_of_NP-hardness)

---

<div class="post-metadata">

**Author:** ![beske](https://avatars.discourse-cdn.com/v4/letter/b/77aa72/32.png) [@beske](https://discourse.julialang.org/u/beske)\
**Post date:** [July 2, 2020, 11:33pm UTC](https://discourse.julialang.org/t/optimization-problem-with-julia-launch-sequence/42311/11 "2020-07-02T23:33:26Z")

</div>

It looks like this:

```julia
using JuMP
using GLPK
using MathOptInterface
using GLPKMathProgInterface
using Gurobi

n = 12

env = Gurobi.Env()

m = Model(Gurobi.Optimizer)
set_optimizer_attribute(m, "NonConvex", 2)

@variable(m, x[i = 1:n, j = 1:n] >= 0)
@variable(m, y[i = 1:n, j = 1:n], Bin)
@variable(m, 1 <= nr[i = 1:n, j = 1:n] <= n, Int)

start = [18, 15, 17, 17, 20, 13, 15, 17, 17, 21, 18, 15]
pop = [100, 80, 130, 90, 1500, 1200, 200, 250, 800, 1000, 1100, 750]
growth = [0.2, 0.15, 0.22, 0.24, 0.12, 0.42, 0.1, 0.11, 0.14, 0.2, 0.05, 0.05]
mgrowth = zeros(n,n)

for i = 1:n
    for j = 1:n
        mgrowth[i,j] = (1 + growth[i])^(n-j)
    end
end

@objective(m, Max, sum(x[i,j]*y[i,j] * pop[j] * mgrowth[i,j] for i =1:n, j = 1:n) )

for j = 1:n
    @constraint(m, sum(y[i,j] for i = 1:n) == 1 )
end

for i = 1:n
    @constraint(m, sum(y[i,j] for j = 1:n) == 1 )
end

for i = 1:n
    @constraint(m, x[i,1]*y[i,1] <= start[i] )
end

for j = 2:n
    @constraint(m, nr[1,j] >= sum(y[2,i] + y[3,i] for i = 1:j-1) )
    @constraint(m, nr[1,j] * x[1,j] == sum(y[2,i]*x[2,i] + y[3,i]*x[3,i] for i = 1:j-1) )

    @constraint(m, nr[2,j] >= sum(y[3,i] + y[1,i] + y[12,i] for i = 1:j-1) )
    @constraint(m, nr[2,j] * x[2,j] == sum(y[3,i]*x[3,i] + y[1,i]*x[1,i] + y[12,i]*x[12,i] for i = 1:j-1) )

    @constraint(m, nr[3,j] >= sum(y[2,i] + y[1,i] + y[4,i] + y[5,i] for i = 1:j-1) )
    @constraint(m, nr[3,j] * x[3,j] == sum(y[2,i]*x[2,i] + y[1,i]*x[1,i] + y[4,i]*x[4,i] + y[5,i]*x[5,i] for i = 1:j-1) )

    @constraint(m, nr[4,j] >= sum(y[1,i] + y[2,i] + y[3,i] for i = 1:j-1) )
    @constraint(m, nr[4,j] * x[4,j] == sum(y[1,i]*x[1,i] + y[2,i]*x[2,i] + y[3,i]*x[3,i] for i = 1:j-1) )

    @constraint(m, nr[5,j] >= sum(y[1,i] + y[2,i] + y[3,i] + y[4,i] + y[10,i] + y[11,i] + y[12,i] for i = 1:j-1) )
    @constraint(m, nr[5,j] * x[5,j] == sum(y[1,i]*x[1,i] + y[2,i]*x[2,i] + y[3,i]*x[3,i] + y[4,i]*x[4,i]
     + y[10,i]*x[10,i] + y[11,i]*x[11,i] + y[12,i]*x[12,i] for i = 1:j-1) )

    @constraint(m, nr[6,j] >= sum(y[2,i] + y[12,i] for i = 1:j-1) )
    @constraint(m, nr[6,j] * x[6,j] == sum(y[2,i]*x[2,i] + y[12,i]*x[12,i] for i = 1:j-1) )

    @constraint(m, nr[7,j] >= sum(y[8,i] for i = 1:j-1) )
    @constraint(m, nr[7,j] * x[7,j] == sum(y[8,i]*x[8,i] for i = 1:j-1) )

    @constraint(m, nr[8,j] >= sum(y[7,i] for i = 1:j-1) )
    @constraint(m, nr[8,j] * x[8,j] == sum(y[7,i]*x[7,i] for i = 1:j-1) )

    @constraint(m, nr[9,j] >= sum(y[10,i] + y[11,i] + y[12,i] for i = 1:j-1) )
    @constraint(m, nr[9,j] * x[9,j] == sum(y[10,i]*x[10,i] + y[11,i]*x[11,i] + y[12,i]*x[12,i] for i = 1:j-1) )

    @constraint(m, nr[10,j] >= sum(y[9,i] + y[11,i] for i = 1:j-1) )
    @constraint(m, nr[10,j] * x[10,j] == sum(y[9,i]*x[9,i] + y[11,i]*x[11,i] for i = 1:j-1) )

    @constraint(m, nr[11,j] >= sum(y[7,i] + y[8,i] + y[9,i] + y[10,i] + y[12,i] for i = 1:j-1) )
    @constraint(m, nr[11,j] * x[11,j] == sum(y[7,i]*x[7,i] + y[8,i]*x[8,i] + y[9,i]*x[9,i] + y[10,i]*x[10,i] + y[12,i]*x[12,i] for i = 1:j-1) )

    @constraint(m, nr[12,j] >= sum(y[1,i] + y[2,i] + y[3,i] + y[4,i] + y[5,i] + y[6,i] + y[7,i] + y[8,i] + y[9,i] for i = 1:j-1) )
    @constraint(m, nr[12,j] * x[12,j] == sum(y[1,i]*x[1,i] + y[2,i]*x[2,i] + y[3,i]*x[3,i] + y[4,i]*x[4,i]
     + y[5,i]*x[5,i] + y[6,i]*x[6,i] + y[7,i]*x[7,i] + y[8,i]*x[8,i] + y[9,i]*x[9,i] for i = 1:j-1) )
end

optimize!(m)
println(JuMP.value.(x))
println(JuMP.value.(y))
println(JuMP.value.(nr))
println(JuMP.objective_value(m))
println(JuMP.termination_status(m))

```

As you can see, I added a `mgrowth` to the objective which is a shop-specific monthly growth in the customer size.

---

<div class="post-metadata">

**Author:** ![beske](https://avatars.discourse-cdn.com/v4/letter/b/77aa72/32.png) [@beske](https://discourse.julialang.org/u/beske)\
**Post date:** [July 3, 2020, 4:22pm UTC](https://discourse.julialang.org/t/optimization-problem-with-julia-launch-sequence/42311/12 "2020-07-03T16:22:09Z")

</div>

Can I do anything to make the code run more efficient, so that I can obtain the results?

---

<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:** [July 3, 2020, 5:24pm UTC](https://discourse.julialang.org/t/optimization-problem-with-julia-launch-sequence/42311/13 "2020-07-03T17:24:01Z")

</div>

You probably still need to do the same trick of expanding out the `nr` into a sum of `y` terms, so that you only have `x * y`, not `nr * x`. The reformulation only works if one of the terms is binary.

The other thing you should do is add good initial bounds on `x`. For example, `13 <= x <= 21`.

---

<div class="post-metadata">

**Author:** ![joaquimg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joaquimg/32/223_2.png) [@joaquimg](https://discourse.julialang.org/u/joaquimg)\
**Post date:** [July 3, 2020, 6:37pm UTC](https://discourse.julialang.org/t/optimization-problem-with-julia-launch-sequence/42311/14 "2020-07-03T18:37:11Z")

</div>

You can use: [https://github.com/joaquimg/QuadraticToBinary.jl](https://github.com/joaquimg/QuadraticToBinary.jl) if you have (good) bounds on all variables that appear in products. It will perform automatic binary expansion for all products.  
However, it might lead to a hard MIP problem. Also the resulting problem is a relaxation, and as you increase the precision (the package allows that) the problem get much more difficult to solve.

---

<div class="post-metadata">

**Author:** ![beske](https://avatars.discourse-cdn.com/v4/letter/b/77aa72/32.png) [@beske](https://discourse.julialang.org/u/beske)\
**Post date:** [July 3, 2020, 11:01pm UTC](https://discourse.julialang.org/t/optimization-problem-with-julia-launch-sequence/42311/15 "2020-07-03T23:01:58Z")

</div>

I rewrote the code with good bounds on all variables and with expansion of `nr`; it is fast now, and I’m thankful for your help.
