# Optimization (Mathematical)

**URL:** https://discourse.julialang.org/c/domain/opt/13.md?page=101

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

**Page:** 102

---

## [Convex.jl: slow in creating constraints?](https://discourse.julialang.org/t/convex-jl-slow-in-creating-constraints/34775)

<div class="topic-metadata">

**Author:** [@riccardomurri](https://discourse.julialang.org/u/riccardomurri)\
**Replies:** 34\
**Last updated:** [March 21, 2020, 11:57am UTC](https://discourse.julialang.org/t/convex-jl-slow-in-creating-constraints/34775 "2020-03-21T11:57:25Z")

</div>

Hello, I have code that builds constraints for Convex.jl in a loop; each iteration of the loop takes ~5 minutes (on fairly recent hardware). Is this expected or am I doing something wrong? # solution vector X = Variab…

---

## [Problem with cost function in JuMP](https://discourse.julialang.org/t/problem-with-cost-function-in-jump/36173)

<div class="topic-metadata">

**Author:** [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Replies:** 3\
**Last updated:** [March 20, 2020, 9:43pm UTC](https://discourse.julialang.org/t/problem-with-cost-function-in-jump/36173 "2020-03-20T21:43:20Z")

</div>

Hello everyone, I am interested in the following optimization problem that I would like to solve with JuMP: \\begin{split} \\min\_{x \\in \\mathbb{R}^n} & (z^Tx)^2 - \\log(b^T x\[l:\\mbox{end}\])\\\\ \\mbox{ subject to }& x\[l:\\mbo…

---

## [CPLEX model answer \`has\_duals\` differently if variables were integer](https://discourse.julialang.org/t/cplex-model-answer-has-duals-differently-if-variables-were-integer/36276)

<div class="topic-metadata">

**Author:** [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Replies:** 1\
**Last updated:** [March 20, 2020, 7:10pm UTC](https://discourse.julialang.org/t/cplex-model-answer-has-duals-differently-if-variables-were-integer/36276 "2020-03-20T19:10:47Z")

</div>

Hey it is me again, XD, I would want to know if this behavior is expected (i.e., if this behavior is expected to be solver-dependent): import CPLEX, Gurobi, GLPK using JuMP function test\_duals(solver\_sym, relaxed\_mip)…

---

## [Benchmarking Optimization Heuristics](https://discourse.julialang.org/t/benchmarking-optimization-heuristics/36265)

<div class="topic-metadata">

**Author:** [@Phillip\_Sutton](https://discourse.julialang.org/u/Phillip_Sutton)\
**Replies:** 2\
**Last updated:** [March 20, 2020, 6:28pm UTC](https://discourse.julialang.org/t/benchmarking-optimization-heuristics/36265 "2020-03-20T18:28:06Z")

</div>

Does anyone have benchmarks/success stories in running Heuristics in Julia vice other Languages (Python, R, etc.)? I’m on a new team (so I don’t want to make too many bold changes) and a firm believer in Julia, looking f…

---

## [Name JuMP constraints in loop for use in writing .lp file](https://discourse.julialang.org/t/name-jump-constraints-in-loop-for-use-in-writing-lp-file/36220)

<div class="topic-metadata">

**Author:** [@ccampaigne](https://discourse.julialang.org/u/ccampaigne)\
**Replies:** 2\
**Last updated:** [March 19, 2020, 9:45pm UTC](https://discourse.julialang.org/t/name-jump-constraints-in-loop-for-use-in-writing-lp-file/36220 "2020-03-19T21:45:47Z")

</div>

Newb here (I’m a Python “user”). In JuMP 0.21.1, I want to create multiple named constraints either through vectorization or looping, and write LP files with those names so that I can easily search them for debugging pur…

---

## [Warm Starts in JuMP 0.21 & GLPK 0.12.1](https://discourse.julialang.org/t/warm-starts-in-jump-0-21-glpk-0-12-1/36223)

<div class="topic-metadata">

**Author:** [@azberman](https://discourse.julialang.org/u/azberman)\
**Replies:** 1\
**Last updated:** [March 19, 2020, 9:33pm UTC](https://discourse.julialang.org/t/warm-starts-in-jump-0-21-glpk-0-12-1/36223 "2020-03-19T21:33:17Z")

</div>

When I run a version of the code below, I receive the following error: Warning: MathOptInterface.VariablePrimalStart() is not supported by MathOptInterface.Bridges.LazyBridgeOptimizer{GLPK.Optimizer}. This information w…

---

## [Warning, invalid warm-start basis discarded](https://discourse.julialang.org/t/warning-invalid-warm-start-basis-discarded/26403)

<div class="topic-metadata">

**Author:** [@Qun](https://discourse.julialang.org/u/Qun)\
**Replies:** 18\
**Last updated:** [March 19, 2020, 8:02pm UTC](https://discourse.julialang.org/t/warning-invalid-warm-start-basis-discarded/26403 "2020-03-19T20:02:26Z")

</div>

I just learned how to use Julia 3 weeks ago. I used to use AIMMS to solve MIP problems. The considered MIP problem is about vehicle route problem. It involves over 50,000 binary variable. Without giving initial solution,…

---

## [Behaviour of sparse array variables in JuMP](https://discourse.julialang.org/t/behaviour-of-sparse-array-variables-in-jump/36185)

<div class="topic-metadata">

**Author:** [@martincornejo](https://discourse.julialang.org/u/martincornejo)\
**Replies:** 6\
**Last updated:** [March 19, 2020, 4:53pm UTC](https://discourse.julialang.org/t/behaviour-of-sparse-array-variables-in-jump/36185 "2020-03-19T16:53:17Z")

</div>

Take as an example a vector v which is of type Boolean and has n elements. Based on this vector we build a variable array x of the same length of v , but from which only the indices corresponding with the non-zero elemen…

---

## [Repeatedly optimizing an LP with different data (changing coefficients/constraints)](https://discourse.julialang.org/t/repeatedly-optimizing-an-lp-with-different-data-changing-coefficients-constraints/36125)

<div class="topic-metadata">

**Author:** [@Smith](https://discourse.julialang.org/u/Smith)\
**Replies:** 7\
**Last updated:** [March 19, 2020, 8:57am UTC](https://discourse.julialang.org/t/repeatedly-optimizing-an-lp-with-different-data-changing-coefficients-constraints/36125 "2020-03-19T08:57:08Z")

</div>

Hi, I would like to solve an LP model for different sets of data and then write results to a CSV file. For illustration, assume the following code for one particular instance using JuMP using GLPK c = \[1,1\] A = \[1,1\] b …

---

## [Indexing Nonlinear Expressions with nested indices in JuMP](https://discourse.julialang.org/t/indexing-nonlinear-expressions-with-nested-indices-in-jump/36140)

<div class="topic-metadata">

**Author:** [@shoshievass](https://discourse.julialang.org/u/shoshievass)\
**Replies:** 3\
**Last updated:** [March 18, 2020, 1:51pm UTC](https://discourse.julialang.org/t/indexing-nonlinear-expressions-with-nested-indices-in-jump/36140 "2020-03-18T13:51:11Z")

</div>

I’m trying to define a JuMP @NLexpression with embedded indexing and I need to use numerical indices instead of collections. I would have thought that the below would work but I’m getting an error saying that F was alrea…

---

## [JuMPv0.21 and deepcopy](https://discourse.julialang.org/t/jumpv0-21-and-deepcopy/36051)

<div class="topic-metadata">

**Author:** [@dmetivie](https://discourse.julialang.org/u/dmetivie)\
**Replies:** 7\
**Last updated:** [March 17, 2020, 5:03pm UTC](https://discourse.julialang.org/t/jumpv0-21-and-deepcopy/36051 "2020-03-17T17:03:17Z")

</div>

Hi, In JuMP Version 0.21 it says Calling deepcopy(::AbstractModel) now throws an error. Is there a new way to do deepcopy()? As far as I understand copy() is not what I want because the copied and original model are…

---

## [How to call nonlinear solver in MathOptInterface](https://discourse.julialang.org/t/how-to-call-nonlinear-solver-in-mathoptinterface/36001)

<div class="topic-metadata">

**Author:** [@zxjroger](https://discourse.julialang.org/u/zxjroger)\
**Replies:** 3\
**Last updated:** [March 17, 2020, 3:06pm UTC](https://discourse.julialang.org/t/how-to-call-nonlinear-solver-in-mathoptinterface/36001 "2020-03-17T15:06:53Z")

</div>

I am trying to move from MathProgBase to MathOptInterface. My code works for the former package, but after I rewrote it using the latter package, I got an error saying Ipopt: Failed to construct problem. I believe it is …

---

## [\`empty!\` for JuMP.Model or JuMP.direct\_model?](https://discourse.julialang.org/t/empty-for-jump-model-or-jump-direct-model/35673)

<div class="topic-metadata">

**Author:** [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Replies:** 12\
**Last updated:** [March 17, 2020, 3:03am UTC](https://discourse.julialang.org/t/empty-for-jump-model-or-jump-direct-model/35673 "2020-03-17T03:03:19Z")

</div>

I did not found a way of emptying a model (created with either JuMP.model or JuMP.direct\_model). There is a MathOptInterface.empty!, but it seems I need to call it over backend(model) and after I do that, I cannot add a…

---

## [JuMP-dev 2020](https://discourse.julialang.org/t/jump-dev-2020/33158)

<div class="topic-metadata">

**Author:** [@odow](https://discourse.julialang.org/u/odow)\
**Replies:** 2\
**Last updated:** [March 16, 2020, 7:43pm UTC](https://discourse.julialang.org/t/jump-dev-2020/33158 "2020-03-16T19:43:00Z")

</div>

Dear all, We are pleased to announce that we are now inviting talk submissions for JuMP-dev 2020, to be held June 15-17, 2020 in Louvain-la-Neuve, Belgium, in conjunction with UCLouvain. For more information on JuMP-de…

---

## [Write large Least Square like problems in JuMP](https://discourse.julialang.org/t/write-large-least-square-like-problems-in-jump/35931)

<div class="topic-metadata">

**Author:** [@dmetivie](https://discourse.julialang.org/u/dmetivie)\
**Replies:** 2\
**Last updated:** [March 16, 2020, 5:43pm UTC](https://discourse.julialang.org/t/write-large-least-square-like-problems-in-jump/35931 "2020-03-16T17:43:08Z")

</div>

Hi, Here is a small code showing the issue I am facing when trying to form large problem (least square like) with JuMP using JuMP, Ipopt, BenchmarkTools p = 500 n = 200 solver = with\_optimizer(Ipopt.Optimizer); ML = …

---

## [Does automatic differentiation work for function with discrete argument?](https://discourse.julialang.org/t/does-automatic-differentiation-work-for-function-with-discrete-argument/35947)

<div class="topic-metadata">

**Author:** [@zxjroger](https://discourse.julialang.org/u/zxjroger)\
**Replies:** 8\
**Last updated:** [March 16, 2020, 1:10am UTC](https://discourse.julialang.org/t/does-automatic-differentiation-work-for-function-with-discrete-argument/35947 "2020-03-16T01:10:13Z")

</div>

I am trying to find the minimizer \\theta of the following nonlinear and non-differentiable function: g(H(X | \\theta),X). Here, X is known and imported from dataset; \\theta=(\\theta\_1,\\theta\_2,\\theta\_3) are the parameters …

---

## [Problem forming a least squares solution](https://discourse.julialang.org/t/problem-forming-a-least-squares-solution/27563)

<div class="topic-metadata">

**Author:** [@scottstanie](https://discourse.julialang.org/u/scottstanie)\
**Replies:** 13\
**Last updated:** [March 14, 2020, 4:22pm UTC](https://discourse.julialang.org/t/problem-forming-a-least-squares-solution/27563 "2020-03-14T16:22:25Z")

</div>

I’m having trouble formulating a model to minimize ||Ax - b|| Ideally I’m looking to minimize the 1 norm, but in trying to get there I ran into errors that I’m not sure I understand: using JuMP using ECOS model = Mode…

---

## [Convex.jl: variables "disappearing" in cumulative constraint](https://discourse.julialang.org/t/convex-jl-variables-disappearing-in-cumulative-constraint/35958)

<div class="topic-metadata">

**Author:** [@riccardomurri](https://discourse.julialang.org/u/riccardomurri)\
**Replies:** 2\
**Last updated:** [March 14, 2020, 3:52pm UTC](https://discourse.julialang.org/t/convex-jl-variables-disappearing-in-cumulative-constraint/35958 "2020-03-14T15:52:04Z")

</div>

Hello, I am trying to build a sort of L\_2-norm constraint piecewise, using code like this (simplified form of the actual code): x = \[Convex.Variable(m\*s+2r, m\*s+2r) for \_ in 1:N\]; for t in 1:N @debug "…

---

## [Convex.jl: How to print full variable ID](https://discourse.julialang.org/t/convex-jl-how-to-print-full-variable-id/35917)

<div class="topic-metadata">

**Author:** [@riccardomurri](https://discourse.julialang.org/u/riccardomurri)\
**Replies:** 1\
**Last updated:** [March 13, 2020, 9:50am UTC](https://discourse.julialang.org/t/convex-jl-how-to-print-full-variable-id/35917 "2020-03-13T09:50:14Z")

</div>

I’m trying to debug an issue with the formulation of an optimization problem using Convex.jl, and I got the following tree print of a constraint (using Convex.MAXDEPTH\[\] = 12 and Convex.MAXWIDTH\[\] = 120), but all the “…

---

## [What type of optimization problem is this?](https://discourse.julialang.org/t/what-type-of-optimization-problem-is-this/35882)

<div class="topic-metadata">

**Author:** [@marcus](https://discourse.julialang.org/u/marcus)\
**Replies:** 5\
**Last updated:** [March 12, 2020, 4:25pm UTC](https://discourse.julialang.org/t/what-type-of-optimization-problem-is-this/35882 "2020-03-12T16:25:20Z")

</div>

Hi all. I have a constrained optimization problem which looks like it might belong to a known class. The problem is to maximize the quotient \\dfrac{x^T A x}{x^T B x} w.r.t real vector x, subject to the constraint x^T x …

---

## [Does Ipopt have the option to do numerical derivatives for non-differentiable function?](https://discourse.julialang.org/t/does-ipopt-have-the-option-to-do-numerical-derivatives-for-non-differentiable-function/35887)

<div class="topic-metadata">

**Author:** [@zxjroger](https://discourse.julialang.org/u/zxjroger)\
**Replies:** 0\
**Last updated:** [March 12, 2020, 3:56pm UTC](https://discourse.julialang.org/t/does-ipopt-have-the-option-to-do-numerical-derivatives-for-non-differentiable-function/35887 "2020-03-12T15:56:26Z")

</div>

I am trying to compare different solvers/routines on minimizing the objective function of simulated method of moments. This objective function is non-differentiable. I wonder if there is a setting in Ipopt to do numerica…

---

## [Add variables in a container](https://discourse.julialang.org/t/add-variables-in-a-container/35798)

<div class="topic-metadata">

**Author:** [@remi-garcia](https://discourse.julialang.org/u/remi-garcia)\
**Replies:** 11\
**Last updated:** [March 12, 2020, 7:06am UTC](https://discourse.julialang.org/t/add-variables-in-a-container/35798 "2020-03-12T07:06:10Z")

</div>

Hello, I’ve found a workaround to my problem but I wonder if there is a better way to solve it. This is what I do: using JuMP model = JuMP.Model() n = 10 @variable(model, -5 \<= x0 \<= 5, Int) @variable(model, -5 \<= x\[1…

---

## [Explicitly defining dependent variables vs allowing solver to figure it out](https://discourse.julialang.org/t/explicitly-defining-dependent-variables-vs-allowing-solver-to-figure-it-out/35114)

<div class="topic-metadata">

**Author:** [@gobs](https://discourse.julialang.org/u/gobs)\
**Replies:** 10\
**Last updated:** [March 11, 2020, 3:20pm UTC](https://discourse.julialang.org/t/explicitly-defining-dependent-variables-vs-allowing-solver-to-figure-it-out/35114 "2020-03-11T15:20:53Z")

</div>

I have an energy system optimisation model with storage. The energy balance for the storage technology looks something like this: e\[t\] = e\[t-1\] + eff \* c\[t\] - d\[t\] The only real decision variables are the charging and…

---

## [CBC and CLP solver version with JuMP](https://discourse.julialang.org/t/cbc-and-clp-solver-version-with-jump/35795)

<div class="topic-metadata">

**Author:** [@bandaya](https://discourse.julialang.org/u/bandaya)\
**Replies:** 2\
**Last updated:** [March 10, 2020, 9:17pm UTC](https://discourse.julialang.org/t/cbc-and-clp-solver-version-with-jump/35795 "2020-03-10T21:17:33Z")

</div>

I am running an optimization problem with CBC solver but it is taking forever with around 1100 binary variables. The same problem is solved in about 2 minutes if I reduce the number of variables to 900. I suspect that t…

---

## [Simplest way to have numerical FOC of a function?](https://discourse.julialang.org/t/simplest-way-to-have-numerical-foc-of-a-function/35754)

<div class="topic-metadata">

**Author:** [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Replies:** 1\
**Last updated:** [March 9, 2020, 3:22pm UTC](https://discourse.julialang.org/t/simplest-way-to-have-numerical-foc-of-a-function/35754 "2020-03-09T15:22:37Z")

</div>

I have the following function for which I need to find the First Order Conditions with respect to one parameter, let’s say \\mathbb{u}: J(u,v,Y,λ) = sum(skipmissing((Y-(u \* v')) .^ 2))/2 + (λ/2) \* (norm(u)^2 + norm(v)^2…

---

## [How to solve this error while installing SCENRED2](https://discourse.julialang.org/t/how-to-solve-this-error-while-installing-scenred2/35413)

<div class="topic-metadata">

**Author:** [@SAH](https://discourse.julialang.org/u/SAH)\
**Replies:** 2\
**Last updated:** [March 9, 2020, 2:41pm UTC](https://discourse.julialang.org/t/how-to-solve-this-error-while-installing-scenred2/35413 "2020-03-09T14:41:29Z")

</div>

I am trying to add a scenario reduction package \[available here\] in Julia and getting an error. In fact, I run these 2 lines as discribed in the link: julia\> Pkg.clone("https://github.com/trigaut/Scenred2.jl.git") julia\>…

---

## [Need help with 'Accelerating optimization via machine learning with surrogate models'](https://discourse.julialang.org/t/need-help-with-accelerating-optimization-via-machine-learning-with-surrogate-models/35717)

<div class="topic-metadata">

**Author:** [@viralnatani](https://discourse.julialang.org/u/viralnatani)\
**Replies:** 2\
**Last updated:** [March 8, 2020, 12:41pm UTC](https://discourse.julialang.org/t/need-help-with-accelerating-optimization-via-machine-learning-with-surrogate-models/35717 "2020-03-08T12:41:30Z")

</div>

Hello everyone! I am a student and willing to participate in Google Summer Of Code 2020. I am interested in working on project “Accelerating optimization via machine learning with surrogate models”. But I am unable to fi…

---

## [Recursive call with ForwardDiff](https://discourse.julialang.org/t/recursive-call-with-forwarddiff/35678)

<div class="topic-metadata">

**Author:** [@edljk](https://discourse.julialang.org/u/edljk)\
**Replies:** 0\
**Last updated:** [March 7, 2020, 8:34am UTC](https://discourse.julialang.org/t/recursive-call-with-forwarddiff/35678 "2020-03-07T08:34:05Z")

</div>

Dear all, I considered the following piece of code. The Forward package is impressive in its flexibility! Nevertheless, I wonder if I am not missing some obvious optimization? Any suggestion are welcome. using ForwardD…

---

## [Julia breaks down when using JuMP through Atom](https://discourse.julialang.org/t/julia-breaks-down-when-using-jump-through-atom/35658)

<div class="topic-metadata">

**Author:** [@Ksun46](https://discourse.julialang.org/u/Ksun46)\
**Replies:** 1\
**Last updated:** [March 6, 2020, 7:51pm UTC](https://discourse.julialang.org/t/julia-breaks-down-when-using-jump-through-atom/35658 "2020-03-06T19:51:41Z")

</div>

Hi all, I am using Julia through Juno/Atom on a Mac, and got the following error today I can run my code through the terminal through. I am not sure what’s going on here. Any suggestions? Thanks.

---

## [Optimization of time-dependent parameters with time-series in chemical model](https://discourse.julialang.org/t/optimization-of-time-dependent-parameters-with-time-series-in-chemical-model/35550)

<div class="topic-metadata">

**Author:** [@Newton-Climate](https://discourse.julialang.org/u/Newton-Climate)\
**Replies:** 0\
**Last updated:** [March 5, 2020, 1:35am UTC](https://discourse.julialang.org/t/optimization-of-time-dependent-parameters-with-time-series-in-chemical-model/35550 "2020-03-05T01:35:14Z")

</div>

Hello All, I have a coupled set of differential equations with some-time-dependent parameters that I would like to optimize. In the code at the bottom of this post, the k\_i terms are fixed kinetic constants, the c\[inde…

[Previous page](https://discourse.julialang.org/c/domain/opt/13.md?page=100)

[Next page](https://discourse.julialang.org/c/domain/opt/13.md?page=102)
