# Optimization (Mathematical)

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

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

**Page:** 21

---

## [How to produce sparse array with conditional array comprehension](https://discourse.julialang.org/t/how-to-produce-sparse-array-with-conditional-array-comprehension/118996)

<div class="topic-metadata">

**Author:** [@juan\_hb](https://discourse.julialang.org/u/juan_hb)\
**Replies:** 6\
**Last updated:** [September 4, 2024, 7:46am UTC](https://discourse.julialang.org/t/how-to-produce-sparse-array-with-conditional-array-comprehension/118996 "2024-09-04T07:46:57Z")

</div>

When creating variable or constraint containers in JuMP, one can use conditionals and a sparse array is produced, where the entries that do not met the conditions are left empty. For example: typeof(@variable(model, \[i …

---

## [Taking the intersection of Semialgebraic Sets for Sum of Squares Optimization](https://discourse.julialang.org/t/taking-the-intersection-of-semialgebraic-sets-for-sum-of-squares-optimization/118826)

<div class="topic-metadata">

**Author:** [@Xifan\_Yu](https://discourse.julialang.org/u/Xifan_Yu)\
**Replies:** 3\
**Last updated:** [September 3, 2024, 2:00pm UTC](https://discourse.julialang.org/t/taking-the-intersection-of-semialgebraic-sets-for-sum-of-squares-optimization/118826 "2024-09-03T14:00:18Z")

</div>

Hi, I am trying to construct a semialgebraic set using package SumOfSquares, which involves a mixture of equality and inequality that would be easier to describe by a for loop. Is there an easy way for me to take the in…

---

## [Multiple shooting with multiple trajectories: how to properly implement this?](https://discourse.julialang.org/t/multiple-shooting-with-multiple-trajectories-how-to-properly-implement-this/118715)

<div class="topic-metadata">

**Author:** [@PyJulia](https://discourse.julialang.org/u/PyJulia)\
**Replies:** 2\
**Last updated:** [September 3, 2024, 1:00pm UTC](https://discourse.julialang.org/t/multiple-shooting-with-multiple-trajectories-how-to-properly-implement-this/118715 "2024-09-03T13:00:25Z")

</div>

DiffEq has a tutorial on multiple shooting for neural ode’s. It works for a single trajectory. I have a dataset with several trajectories, each trajectory being a solution to a differential equation with different initia…

---

## [Difference between m = function(m) and function!(m) where m is a JuMP Model instance](https://discourse.julialang.org/t/difference-between-m-function-m-and-function-m-where-m-is-a-jump-model-instance/118831)

<div class="topic-metadata">

**Author:** [@Betristor](https://discourse.julialang.org/u/Betristor)\
**Replies:** 10\
**Last updated:** [September 2, 2024, 11:59pm UTC](https://discourse.julialang.org/t/difference-between-m-function-m-and-function-m-where-m-is-a-jump-model-instance/118831 "2024-09-02T23:59:04Z")

</div>

I’ve read the performance tips about building models using juMP and it suggests to use exclamatory mark instead of return value. Is there any performance difference between these two ways in terms of memory usage?

---

## [How to work with JuMP and Graphs.jl](https://discourse.julialang.org/t/how-to-work-with-jump-and-graphs-jl/118948)

<div class="topic-metadata">

**Author:** [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Replies:** 2\
**Last updated:** [September 2, 2024, 9:33pm UTC](https://discourse.julialang.org/t/how-to-work-with-jump-and-graphs-jl/118948 "2024-09-02T21:33:46Z")

</div>

I try to build a flow model using JuMP and (Meta)Graphs.jl. In particular I fail to index the variables. Here is an MWE: using Graphs using JuMP g = SimpleDiGraph(4) for i in 1:3 add\_edge!(g, i, i+1) end model = M…

---

## [Detecting problems with numerically challenging models](https://discourse.julialang.org/t/detecting-problems-with-numerically-challenging-models/118592)

<div class="topic-metadata">

**Author:** [@sstroemer](https://discourse.julialang.org/u/sstroemer)\
**Replies:** 4\
**Last updated:** [September 2, 2024, 4:28pm UTC](https://discourse.julialang.org/t/detecting-problems-with-numerically-challenging-models/118592 "2024-09-02T16:28:47Z")

</div>

Consider loading and solving a model using using JuMP import Gurobi mwe = read\_from\_file("mwe.mps"; format = MOI.FileFormats.FORMAT\_MPS) set\_optimizer(mwe, Gurobi.Optimizer) set\_attribute(mwe, "Method", 2) set\_attribut…

---

## [Examodels: Dealing with empty constraints and data](https://discourse.julialang.org/t/examodels-dealing-with-empty-constraints-and-data/118669)

<div class="topic-metadata">

**Author:** [@KSepetanc](https://discourse.julialang.org/u/KSepetanc)\
**Replies:** 4\
**Last updated:** [August 31, 2024, 9:25pm UTC](https://discourse.julialang.org/t/examodels-dealing-with-empty-constraints-and-data/118669 "2024-08-31T21:25:59Z")

</div>

@sshin23 , @frapac I am solving AC OPF with extended modeled features. In particular my issue is that I may have actively controlled transformers in data, but also there could be no actively controlled transformers and …

---

## [Bug in write\_to\_file for max-type problems in bilinear terms?](https://discourse.julialang.org/t/bug-in-write-to-file-for-max-type-problems-in-bilinear-terms/118781)

<div class="topic-metadata">

**Author:** [@anogaja](https://discourse.julialang.org/u/anogaja)\
**Replies:** 2\
**Last updated:** [August 29, 2024, 9:16pm UTC](https://discourse.julialang.org/t/bug-in-write-to-file-for-max-type-problems-in-bilinear-terms/118781 "2024-08-29T21:16:50Z")

</div>

The max objective problem in JuMP when written to an mps file is converted to a min type objective by flipping the signs. However, it didn’t do it for the bilinear terms in the objective. Am I missing something? Follow…

---

## [Matrix multiplication time with JuMP variables](https://discourse.julialang.org/t/matrix-multiplication-time-with-jump-variables/118650)

<div class="topic-metadata">

**Author:** [@mhar](https://discourse.julialang.org/u/mhar)\
**Replies:** 5\
**Last updated:** [August 29, 2024, 7:59pm UTC](https://discourse.julialang.org/t/matrix-multiplication-time-with-jump-variables/118650 "2024-08-29T19:59:40Z")

</div>

I am using JuMP to solve some large problems. A bottleneck right now is computing a matrix-vector product. M is a short and fat matrix of floats, and x is a variable vector. Mx will be a vector of moderate length, but f…

---

## [Excessively long TTFX with Optimization and OptimizationOptimJL](https://discourse.julialang.org/t/excessively-long-ttfx-with-optimization-and-optimizationoptimjl/118457)

<div class="topic-metadata">

**Author:** [@aris](https://discourse.julialang.org/u/aris)\
**Replies:** 22\
**Last updated:** [August 24, 2024, 1:27pm UTC](https://discourse.julialang.org/t/excessively-long-ttfx-with-optimization-and-optimizationoptimjl/118457 "2024-08-24T13:27:28Z")

</div>

Suppose we would like to solve the following problem : min ||Ax - b||\_2^2, s.t. x.\>0 using OptimizationOptimJl. One way to write it would be as follows: using Optimization, OptimizationOptimJL function obj\_f(x,p)…

---

## [Mixed-integer quadratic programming doesn't seem to be working correctly](https://discourse.julialang.org/t/mixed-integer-quadratic-programming-doesnt-seem-to-be-working-correctly/118551)

<div class="topic-metadata">

**Author:** [@Tarny\_GG\_Channie](https://discourse.julialang.org/u/Tarny_GG_Channie)\
**Replies:** 1\
**Last updated:** [August 24, 2024, 9:30am UTC](https://discourse.julialang.org/t/mixed-integer-quadratic-programming-doesnt-seem-to-be-working-correctly/118551 "2024-08-24T09:30:50Z")

</div>

DAQP was supposedly solving convex mixed-binary quadratic programming until I tried. The GitHub page said that the matrix must be positive semi-definite, which it is. (The objective expression literally cannot be less…

---

## [To confirm: The sign of the dual variable on a constraint of \`JuMP\` model](https://discourse.julialang.org/t/to-confirm-the-sign-of-the-dual-variable-on-a-constraint-of-jump-model/114292)

<div class="topic-metadata">

**Author:** [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Replies:** 7\
**Last updated:** [August 22, 2024, 5:50pm UTC](https://discourse.julialang.org/t/to-confirm-the-sign-of-the-dual-variable-on-a-constraint-of-jump-model/114292 "2024-08-22T17:50:30Z")

</div>

To make it more clear, let’s consider an optimization problem of the following standard form: \\begin{equation} \\begin{array}{cl} {\\min} & {f\_0(x)}\\\\ {\\mathrm{s.t.}} & {f\_i(x)\\leqslant 0,\\quad i=1,\\c…

---

## [Recommendations for solver and options to solve a MIQP, just looking for a feasible solution](https://discourse.julialang.org/t/recommendations-for-solver-and-options-to-solve-a-miqp-just-looking-for-a-feasible-solution/107024)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 5\
**Last updated:** [August 22, 2024, 10:03am UTC](https://discourse.julialang.org/t/recommendations-for-solver-and-options-to-solve-a-miqp-just-looking-for-a-feasible-solution/107024 "2024-08-22T10:03:24Z")

</div>

I formulated a mixed-integer quadratic program (MIQP) using MathOptInterface.jl to solve a problem for a student competition. It’s got some continuous variables that are the solution I’m looking for, and I also had to in…

---

## [Attempting to Warm start causes errors](https://discourse.julialang.org/t/attempting-to-warm-start-causes-errors/118450)

<div class="topic-metadata">

**Author:** [@fimiller](https://discourse.julialang.org/u/fimiller)\
**Replies:** 2\
**Last updated:** [August 22, 2024, 1:45am UTC](https://discourse.julialang.org/t/attempting-to-warm-start-causes-errors/118450 "2024-08-22T01:45:52Z")

</div>

I am trying to warm start my problem using a sparse matrix. The following code produces an error: model = Model(Mosek.Optimizer) @variable(model, Z\[1:size(cost)\[1\],1:size(cost)\[2\]\], PSD) set\_start\_value(Z, warm\_start\_v…

---

## [Nonlinear (trilinear) terms in Gurobi not supported through JuMP?](https://discourse.julialang.org/t/nonlinear-trilinear-terms-in-gurobi-not-supported-through-jump/118438)

<div class="topic-metadata">

**Author:** [@math\_opt](https://discourse.julialang.org/u/math_opt)\
**Replies:** 2\
**Last updated:** [August 21, 2024, 4:16am UTC](https://discourse.julialang.org/t/nonlinear-trilinear-terms-in-gurobi-not-supported-through-jump/118438 "2024-08-21T04:16:03Z")

</div>

Here, I have two sets of codes with some trilinear terms. The first one calls Gurobi directly, and the second one is through GAMS.jl. The first one fails, while the second one returns the optimal value: using JuMP, Guro…

---

## [Which package is suitable for matrix-free partial SVD?](https://discourse.julialang.org/t/which-package-is-suitable-for-matrix-free-partial-svd/118419)

<div class="topic-metadata">

**Author:** [@MAChiyu](https://discourse.julialang.org/u/MAChiyu)\
**Replies:** 2\
**Last updated:** [August 20, 2024, 8:15pm UTC](https://discourse.julialang.org/t/which-package-is-suitable-for-matrix-free-partial-svd/118419 "2024-08-20T20:15:57Z")

</div>

Hi! I am new to Julia. I used to use MATLAB. Within MATLAB, I use lansvd in PROPACK to do partial SVD of some linear operator (needs Afunpar to input other parameters of the matrix free operator). I notice there is PROPA…

---

## [Limiting step size in optimization variable between optimization steps of nonlinear constrained optimization problem](https://discourse.julialang.org/t/limiting-step-size-in-optimization-variable-between-optimization-steps-of-nonlinear-constrained-optimization-problem/117732)

<div class="topic-metadata">

**Author:** [@psuskin](https://discourse.julialang.org/u/psuskin)\
**Replies:** 4\
**Last updated:** [August 20, 2024, 2:19pm UTC](https://discourse.julialang.org/t/limiting-step-size-in-optimization-variable-between-optimization-steps-of-nonlinear-constrained-optimization-problem/117732 "2024-08-20T14:19:11Z")

</div>

Hi, I am trying to limit the step size of an optimization variable between optimization steps for a nonlinear constrained optimization problem using JuMP and Ipopt. In case this goal or the motivation behind it is uncl…

---

## [Help setting SCIP parameters to increase use of heuristics](https://discourse.julialang.org/t/help-setting-scip-parameters-to-increase-use-of-heuristics/107801)

<div class="topic-metadata">

**Author:** [@convexhull](https://discourse.julialang.org/u/convexhull)\
**Replies:** 4\
**Last updated:** [August 20, 2024, 1:36pm UTC](https://discourse.julialang.org/t/help-setting-scip-parameters-to-increase-use-of-heuristics/107801 "2024-08-20T13:36:36Z")

</div>

I’m working on an optimization problem using SCIP and I’ve noticed that it takes a very long time to find a primal solution. I don’t need to find optimal solutions and I’d prefer to find feasible solutions early on. I wo…

---

## [Lazy constraint doesn't seem to work?](https://discourse.julialang.org/t/lazy-constraint-doesnt-seem-to-work/118333)

<div class="topic-metadata">

**Author:** [@jack\_lee](https://discourse.julialang.org/u/jack_lee)\
**Replies:** 1\
**Last updated:** [August 18, 2024, 8:56pm UTC](https://discourse.julialang.org/t/lazy-constraint-doesnt-seem-to-work/118333 "2024-08-18T20:56:40Z")

</div>

Here is my call\_back function,it mainly used to elimilate sub-circle in route function call\_back(cb\_data) status = callback\_node\_status(cb\_data, model) x\_val = callback\_value.(cb\_data, model\[:x\]) for i ∈ 1:m d…

---

## [How to link a JuMP model and a general algorithm together?](https://discourse.julialang.org/t/how-to-link-a-jump-model-and-a-general-algorithm-together/118356)

<div class="topic-metadata">

**Author:** [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Replies:** 4\
**Last updated:** [August 20, 2024, 2:59am UTC](https://discourse.julialang.org/t/how-to-link-a-jump-model-and-a-general-algorithm-together/118356 "2024-08-20T02:59:51Z")

</div>

Suppose there is a general algorithm for some kind of optimization problem in a standard form, and then there is an instance of this kind of problem which is however not written in the standard form. Both of the algorit…

---

## [Erf function is not supported](https://discourse.julialang.org/t/erf-function-is-not-supported/118251)

<div class="topic-metadata">

**Author:** [@Simran\_Lakhani](https://discourse.julialang.org/u/Simran_Lakhani)\
**Replies:** 6\
**Last updated:** [August 20, 2024, 1:11am UTC](https://discourse.julialang.org/t/erf-function-is-not-supported/118251 "2024-08-20T01:11:17Z")

</div>

I have a MINLP that involves error cdf and pdf of normal distribution in the objective function. I used erf from SpecialFunctions it is not supported. I also tried approximations of erf, even that does not work. I used K…

---

## [Is there a way to delete old solutions from a JuMP model?](https://discourse.julialang.org/t/is-there-a-way-to-delete-old-solutions-from-a-jump-model/118394)

<div class="topic-metadata">

**Author:** [@dlcole3](https://discourse.julialang.org/u/dlcole3)\
**Replies:** 1\
**Last updated:** [August 20, 2024, 1:05am UTC](https://discourse.julialang.org/t/is-there-a-way-to-delete-old-solutions-from-a-jump-model/118394 "2024-08-20T01:05:01Z")

</div>

I am working on a problem where I am solving a model and then trying to get an additional feasible solution for the model by reseting the objective function (there are more details behind this, but the general idea will …

---

## [Minimize constraint function](https://discourse.julialang.org/t/minimize-constraint-function/118120)

<div class="topic-metadata">

**Author:** [@trasor](https://discourse.julialang.org/u/trasor)\
**Replies:** 5\
**Last updated:** [August 18, 2024, 2:52pm UTC](https://discourse.julialang.org/t/minimize-constraint-function/118120 "2024-08-18T14:52:18Z")

</div>

Hello, im struggling to get one of the julia optimization packages (optim, NLopt, Jump etc…) to work to minimize a constrained function. In particular, im interested to find the minimum distance between a point and a c…

---

## [Surrogates.jl: How to get the effect of "forgetting" or decaying importance of old observations?](https://discourse.julialang.org/t/surrogates-jl-how-to-get-the-effect-of-forgetting-or-decaying-importance-of-old-observations/118178)

<div class="topic-metadata">

**Author:** [@A112s](https://discourse.julialang.org/u/A112s)\
**Replies:** 0\
**Last updated:** [August 14, 2024, 11:55am UTC](https://discourse.julialang.org/t/surrogates-jl-how-to-get-the-effect-of-forgetting-or-decaying-importance-of-old-observations/118178 "2024-08-14T11:55:05Z")

</div>

I want to use Surrogates.jl to select hyperparameters for a function, which I know that behaves its behavior significantly over time. Is there a built-in way to model such process with Surrogates.jl?

---

## [DiffOpt - differentiating through a QP/different from manual](https://discourse.julialang.org/t/diffopt-differentiating-through-a-qp-different-from-manual/118141)

<div class="topic-metadata">

**Author:** [@blob](https://discourse.julialang.org/u/blob)\
**Replies:** 3\
**Last updated:** [August 14, 2024, 9:34am UTC](https://discourse.julialang.org/t/diffopt-differentiating-through-a-qp-different-from-manual/118141 "2024-08-14T09:34:30Z")

</div>

I want to differentiate through a QP following the tutorial from DiffOpt. The QP in question: I would like to differentiate wrt to h, q, and G. I do that in three ways: Using the paper cited on DiffOpt website: dwh,…

---

## [Block triangular matrix in Convex.jl](https://discourse.julialang.org/t/block-triangular-matrix-in-convex-jl/118147)

<div class="topic-metadata">

**Author:** [@jens-rataczak](https://discourse.julialang.org/u/jens-rataczak)\
**Replies:** 2\
**Last updated:** [August 13, 2024, 10:27pm UTC](https://discourse.julialang.org/t/block-triangular-matrix-in-convex-jl/118147 "2024-08-13T22:27:53Z")

</div>

Hello, Is there a straightforward way to constrain a variable in Convex.jl to be block triangular (either upper or lower)? I am looking for something like YALMIP’s blkvar command. It seems rather tedious to constrain th…

---

## [ERROR: The objective function (erf) is not supported by JuMP](https://discourse.julialang.org/t/error-the-objective-function-erf-is-not-supported-by-jump/48302)

<div class="topic-metadata">

**Author:** [@BuRanran](https://discourse.julialang.org/u/BuRanran)\
**Replies:** 6\
**Last updated:** [August 13, 2024, 10:17pm UTC](https://discourse.julialang.org/t/error-the-objective-function-erf-is-not-supported-by-jump/48302 "2024-08-13T22:17:46Z")

</div>

I have a non-linear optimization problem to be solved with JuMP and IPOPT solver. The objective function is a probability distribution function of a normal distribution. It can be optimized by IPOPT directly, but not sup…

---

## [Extending JuMP @variable](https://discourse.julialang.org/t/extending-jump-variable/118094)

<div class="topic-metadata">

**Author:** [@shawn\_T](https://discourse.julialang.org/u/shawn_T)\
**Replies:** 7\
**Last updated:** [August 13, 2024, 9:41am UTC](https://discourse.julialang.org/t/extending-jump-variable/118094 "2024-08-13T09:41:59Z")

</div>

Hi, I am planning to extend JuMP @variable macro by defining a new struct to replace the VariableInfo struct defined in JuMP, the code below is following the extension page: struct My\_var \<: JuMP.AbstractVariable …

---

## [Nested optimization - matrix multiplication and internal functions](https://discourse.julialang.org/t/nested-optimization-matrix-multiplication-and-internal-functions/118098)

<div class="topic-metadata">

**Author:** [@blob](https://discourse.julialang.org/u/blob)\
**Replies:** 9\
**Last updated:** [August 13, 2024, 9:25am UTC](https://discourse.julialang.org/t/nested-optimization-matrix-multiplication-and-internal-functions/118098 "2024-08-13T09:25:41Z")

</div>

I have a nested optimization problem in JuMP that fails to run because of Dual going through. In my original problem the lower level problem is a convex QP so it is possible to compute correct gradients but first the cod…

---

## [Auto-gradient with Symbolics for JuMP constraints](https://discourse.julialang.org/t/auto-gradient-with-symbolics-for-jump-constraints/117953)

<div class="topic-metadata">

**Author:** [@vguy-deroubaix](https://discourse.julialang.org/u/vguy-deroubaix)\
**Replies:** 6\
**Last updated:** [August 11, 2024, 8:13pm UTC](https://discourse.julialang.org/t/auto-gradient-with-symbolics-for-jump-constraints/117953 "2024-08-11T20:13:23Z")

</div>

Hello, for a project of optimal approximation of functions, I need the expression of the gradient of the function I need to approximate, so I can put these expressions in constraints in a JuMP model (with Ipopt as the so…

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

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