# Optimization (Mathematical)

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

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

**Page:** 44

---

## [What strategy to allocate resources while respecting many constraints](https://discourse.julialang.org/t/what-strategy-to-allocate-resources-while-respecting-many-constraints/99484)

<div class="topic-metadata">

**Author:** [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Replies:** 16\
**Last updated:** [May 29, 2023, 10:22pm UTC](https://discourse.julialang.org/t/what-strategy-to-allocate-resources-while-respecting-many-constraints/99484 "2023-05-29T22:22:46Z")

</div>

Suppose we have a table with 8 rows and 30 (or 31) columns. We have to label each cell with G and N, respecting the following rules (sometimes some other constraint is added :slight\_smile: ) Each column (i.e. each day…

---

## [SciML Optimization - algorithms and convergence speed](https://discourse.julialang.org/t/sciml-optimization-algorithms-and-convergence-speed/99170)

<div class="topic-metadata">

**Author:** [@sob](https://discourse.julialang.org/u/sob)\
**Replies:** 10\
**Last updated:** [May 29, 2023, 9:20pm UTC](https://discourse.julialang.org/t/sciml-optimization-algorithms-and-convergence-speed/99170 "2023-05-29T21:20:44Z")

</div>

I’m currently working on a minimization problem where the loss function is of dimensions n by p, with both n and p ~100 (but not necessarily equal, although in some cases they may be). I started with a naive implementati…

---

## [Help with SparseArrays/ChainRules error](https://discourse.julialang.org/t/help-with-sparsearrays-chainrules-error/99425)

<div class="topic-metadata">

**Author:** [@ElOceanografo](https://discourse.julialang.org/u/ElOceanografo)\
**Replies:** 0\
**Last updated:** [May 26, 2023, 6:07am UTC](https://discourse.julialang.org/t/help-with-sparsearrays-chainrules-error/99425 "2023-05-26T06:07:01Z")

</div>

Ran into this error running code similar to this MWE, and was hoping someone who knows more about the AD ecosystem could help point me where to file an issue–is this a missing ChainRule, or overly-strict typing in Sparse…

---

## [Modelling arbitrary non-linear expression (returned by a function) in JuMP](https://discourse.julialang.org/t/modelling-arbitrary-non-linear-expression-returned-by-a-function-in-jump/99419)

<div class="topic-metadata">

**Author:** [@pkoir](https://discourse.julialang.org/u/pkoir)\
**Replies:** 4\
**Last updated:** [May 26, 2023, 3:23am UTC](https://discourse.julialang.org/t/modelling-arbitrary-non-linear-expression-returned-by-a-function-in-jump/99419 "2023-05-26T03:23:43Z")

</div>

Hi, I’m new to Julia and JuMP so please forgive me if this is a trivial problem. I have a constraint function of the form: function g(x) \[ exp(x\[1\]) + exp(x\[2\]), x\[1\]^4 + x\[2\]^4 \] end I’m trying to mo…

---

## [Add local and purgeable cuts in CPLEX](https://discourse.julialang.org/t/add-local-and-purgeable-cuts-in-cplex/99378)

<div class="topic-metadata">

**Author:** [@Zacharie\_ALES](https://discourse.julialang.org/u/Zacharie_ALES)\
**Replies:** 4\
**Last updated:** [May 25, 2023, 7:48pm UTC](https://discourse.julialang.org/t/add-local-and-purgeable-cuts-in-cplex/99378 "2023-05-25T19:48:43Z")

</div>

I am using CPLEX.jl and I add cuts in a callback with this syntax: con = @build\_constraint(x \<= 0) MOI.submit(myModel, MOI.UserCut(cb\_data), con) CPLEX library normally has several parameters when addin…

---

## [Adding NL expressions to an AffExpr type Vector](https://discourse.julialang.org/t/adding-nl-expressions-to-an-affexpr-type-vector/99279)

<div class="topic-metadata">

**Author:** [@PatrickeTownsend](https://discourse.julialang.org/u/PatrickeTownsend)\
**Replies:** 5\
**Last updated:** [May 25, 2023, 8:32am UTC](https://discourse.julialang.org/t/adding-nl-expressions-to-an-affexpr-type-vector/99279 "2023-05-25T08:32:23Z")

</div>

Hello again everybody, I’m trying to generate a Vector where which element is a NL expression, here is the code where I’m trying to implement it. register(rocket2d\_hs\_2, :StateFunc, 10, StateFunc; autodiff=true) x\_c = …

---

## [Using CPLEX (solver dependent) callbacks for custom branching strategy in Julia](https://discourse.julialang.org/t/using-cplex-solver-dependent-callbacks-for-custom-branching-strategy-in-julia/99054)

<div class="topic-metadata">

**Author:** [@valdemarsoegaard](https://discourse.julialang.org/u/valdemarsoegaard)\
**Replies:** 6\
**Last updated:** [May 23, 2023, 7:01pm UTC](https://discourse.julialang.org/t/using-cplex-solver-dependent-callbacks-for-custom-branching-strategy-in-julia/99054 "2023-05-23T19:01:18Z")

</div>

Greetings! I am working on my master thesis on a large-scale flow problem, where I have implemented a surrogate model derived from a neural network in the form of a set of mixed integer linear constraints which replaces…

---

## [Getter that returns all optimizer attributes](https://discourse.julialang.org/t/getter-that-returns-all-optimizer-attributes/99113)

<div class="topic-metadata">

**Author:** [@raphaelsaavedra](https://discourse.julialang.org/u/raphaelsaavedra)\
**Replies:** 2\
**Last updated:** [May 23, 2023, 12:28pm UTC](https://discourse.julialang.org/t/getter-that-returns-all-optimizer-attributes/99113 "2023-05-23T12:28:05Z")

</div>

I couldn’t find in the JuMP docs how to get all optimizer attributes from a solver. There’s the following, which allows you to get one particular attribute: get\_attribute(model::Model, attr::MOI.AbstractModelAttribute) …

---

## [Dual vs shadow price: Which one to use?](https://discourse.julialang.org/t/dual-vs-shadow-price-which-one-to-use/99260)

<div class="topic-metadata">

**Author:** [@math\_opt](https://discourse.julialang.org/u/math_opt)\
**Replies:** 8\
**Last updated:** [May 23, 2023, 7:54am UTC](https://discourse.julialang.org/t/dual-vs-shadow-price-which-one-to-use/99260 "2023-05-23T07:54:29Z")

</div>

I want to make sure I understand correctly the difference between the dual/shadow\_price returned by JuMP. Let’s consider the following primal problem: using JuMP, Gurobi begin model = Model(Gurobi.Optimizer) @va…

---

## [Multi-thread Variable Creation](https://discourse.julialang.org/t/multi-thread-variable-creation/93300)

<div class="topic-metadata">

**Author:** [@A\_M](https://discourse.julialang.org/u/A_M)\
**Replies:** 8\
**Last updated:** [May 22, 2023, 7:27pm UTC](https://discourse.julialang.org/t/multi-thread-variable-creation/93300 "2023-05-22T19:27:43Z")

</div>

I have a large problem; even model creation will take a long time, and I was thinking of using a thread-safe approach to speed up the process. Here is the code: using Random using JuMP using HiGHS using ThreadSafeDicts …

---

## [How to create an user-defined function with multiple vector as inputs](https://discourse.julialang.org/t/how-to-create-an-user-defined-function-with-multiple-vector-as-inputs/99068)

<div class="topic-metadata">

**Author:** [@PatrickeTownsend](https://discourse.julialang.org/u/PatrickeTownsend)\
**Replies:** 1\
**Last updated:** [May 18, 2023, 8:40pm UTC](https://discourse.julialang.org/t/how-to-create-an-user-defined-function-with-multiple-vector-as-inputs/99068 "2023-05-18T20:40:21Z")

</div>

Hello, I’m new to JuMP module and also Julia. I’m trying to perform a trajectory optimization with Hermite-Simpson direct collocation method. I’ve trying to create a function for the dynamic equations, but I’m still get…

---

## [How to include the iteration number of a loop in variable names?](https://discourse.julialang.org/t/how-to-include-the-iteration-number-of-a-loop-in-variable-names/90840)

<div class="topic-metadata">

**Author:** [@Alex\_ricci](https://discourse.julialang.org/u/Alex_ricci)\
**Replies:** 4\
**Last updated:** [May 18, 2023, 7:19am UTC](https://discourse.julialang.org/t/how-to-include-the-iteration-number-of-a-loop-in-variable-names/90840 "2023-05-18T07:19:29Z")

</div>

I have a loop iterating on r and want to define the variable x^r in every iteration. I know one possibility is defining an anonymous variable, but it is not what I need. m=Model() for r in 1:4 x = @variable(m, \[r…

---

## [How to vectorize a JuMP solver](https://discourse.julialang.org/t/how-to-vectorize-a-jump-solver/99010)

<div class="topic-metadata">

**Author:** [@Longblackcoffee](https://discourse.julialang.org/u/Longblackcoffee)\
**Replies:** 2\
**Last updated:** [May 18, 2023, 12:16am UTC](https://discourse.julialang.org/t/how-to-vectorize-a-jump-solver/99010 "2023-05-18T00:16:07Z")

</div>

Hi everyone, Is it possible to vectorize a JuMP solver? I want to solve a maximization problem for different draws of a random variable (X in the example below, drawn from a log-normal distribution). So for a vector of …

---

## [Which solvers have dual solutions available for MINLPs?](https://discourse.julialang.org/t/which-solvers-have-dual-solutions-available-for-minlps/98859)

<div class="topic-metadata">

**Author:** [@vineetjnair9](https://discourse.julialang.org/u/vineetjnair9)\
**Replies:** 2\
**Last updated:** [May 17, 2023, 7:04pm UTC](https://discourse.julialang.org/t/which-solvers-have-dual-solutions-available-for-minlps/98859 "2023-05-17T19:04:13Z")

</div>

Which solvers (out of the ones here - Installation Guide · JuMP) can I extract dual values for, specifically for MINLPs? I was able to extract them while running Ipopt for NLPs but now I’m working on an MINLP (nonconvex)…

---

## [Adding cuts iteratively](https://discourse.julialang.org/t/adding-cuts-iteratively/98902)

<div class="topic-metadata">

**Author:** [@Saba\_ghasemi](https://discourse.julialang.org/u/Saba_ghasemi)\
**Replies:** 8\
**Last updated:** [May 17, 2023, 2:40am UTC](https://discourse.julialang.org/t/adding-cuts-iteratively/98902 "2023-05-17T02:40:50Z")

</div>

I am attempting to incorporate perspective cuts into a non-linear model for linearization using the JuMP package. My aim is to utilize the SCIP solver and introduce a cut every 5 seconds, utilizing a feasible point to ad…

---

## [Avoiding for Loop in JuMP](https://discourse.julialang.org/t/avoiding-for-loop-in-jump/98920)

<div class="topic-metadata">

**Author:** [@Gagan\_Meena](https://discourse.julialang.org/u/Gagan_Meena)\
**Replies:** 3\
**Last updated:** [May 16, 2023, 9:35pm UTC](https://discourse.julialang.org/t/avoiding-for-loop-in-jump/98920 "2023-05-16T21:35:04Z")

</div>

Is it possible to avoid for loop for the code given below. @expression(JSTEP, Inj\[i=1:n, j=1:s\], Pg\[i,j\] - Pdmax\[i,j\] + PD\[i,j\] - PC\[i,j\]) for i = 1:r f = from\[i\] t = to\[i\] for k =1:s Inj\[f,k\] = Inj\[f,k\] …

---

## [Nelder-Mead or other optimization](https://discourse.julialang.org/t/nelder-mead-or-other-optimization/98853)

<div class="topic-metadata">

**Author:** [@papar](https://discourse.julialang.org/u/papar)\
**Replies:** 5\
**Last updated:** [May 16, 2023, 9:28pm UTC](https://discourse.julialang.org/t/nelder-mead-or-other-optimization/98853 "2023-05-16T21:28:42Z")

</div>

I am trying to use Optim to find parameters of a vector valued function using the Nelder-Mead algorithm, but open to considering other algorithms or packages. The problem is to find parameters of a function by minimizing…

---

## [Creating three dimensional variable using JuMP](https://discourse.julialang.org/t/creating-three-dimensional-variable-using-jump/98870)

<div class="topic-metadata">

**Author:** [@Gagan\_Meena](https://discourse.julialang.org/u/Gagan_Meena)\
**Replies:** 6\
**Last updated:** [May 15, 2023, 9:26pm UTC](https://discourse.julialang.org/t/creating-three-dimensional-variable-using-jump/98870 "2023-05-15T21:26:13Z")

</div>

I have created a two dimensional variable using the following code. fnew = Vector{Vector{VariableRef}}(undef, c) eta = Vector{Vector{VariableRef}}(undef, c) for i = 1:c newlines = nm\_new\[i\] if newline…

---

## [Simplify a nonlinear expression](https://discourse.julialang.org/t/simplify-a-nonlinear-expression/98772)

<div class="topic-metadata">

**Author:** [@VPBML](https://discourse.julialang.org/u/VPBML)\
**Replies:** 6\
**Last updated:** [May 15, 2023, 5:35pm UTC](https://discourse.julialang.org/t/simplify-a-nonlinear-expression/98772 "2023-05-15T17:35:51Z")

</div>

Hi, Is there any way we can simplify a nonlinear expression automatically in JuMP. For example, if we have: using JuMP, MadNLP model = Model(MadNLP.Optimizer) @variable(model, CA) @variable(model, CB) expr\_str = :($(CA…

---

## [Speeding-up the construction of a second order cone JuMP model](https://discourse.julialang.org/t/speeding-up-the-construction-of-a-second-order-cone-jump-model/98311)

<div class="topic-metadata">

**Author:** [@cgois](https://discourse.julialang.org/u/cgois)\
**Replies:** 6\
**Last updated:** [May 15, 2023, 12:42pm UTC](https://discourse.julialang.org/t/speeding-up-the-construction-of-a-second-order-cone-jump-model/98311 "2023-05-15T12:42:16Z")

</div>

Hi everyone. I need to solve tens of thousands of second order cone problems, so I need my code to be as fast as possible. Currently, my main bottleneck is actually building the problem in JuMP and I would appreciate any…

---

## [Out-of-memory errors using Ipopt to solve very large-scale trajectory optimization problems](https://discourse.julialang.org/t/out-of-memory-errors-using-ipopt-to-solve-very-large-scale-trajectory-optimization-problems/98840)

<div class="topic-metadata">

**Author:** [@zornsllama](https://discourse.julialang.org/u/zornsllama)\
**Replies:** 4\
**Last updated:** [May 15, 2023, 5:43am UTC](https://discourse.julialang.org/t/out-of-memory-errors-using-ipopt-to-solve-very-large-scale-trajectory-optimization-problems/98840 "2023-05-15T05:43:18Z")

</div>

Hi, I’m trying to use Ipopt via NLPModelsIpopt.jl in order to solve large trajectory optimization problems. It is essentially an optimal control problem, to minimize \\int\_{0}^{T} g(x, u(t)) \\, dt subject to the constrai…

---

## [Problem installing SigmoidalProgramming](https://discourse.julialang.org/t/problem-installing-sigmoidalprogramming/98731)

<div class="topic-metadata">

**Author:** [@meet.saiya](https://discourse.julialang.org/u/meet.saiya)\
**Replies:** 1\
**Last updated:** [May 14, 2023, 11:12pm UTC](https://discourse.julialang.org/t/problem-installing-sigmoidalprogramming/98731 "2023-05-14T23:12:36Z")

</div>

I tried installing SigmoidalProgramming in Julia 1.8.5 and it gave the following error. julia\> using SigmoidalProgramming \[ Info: Precompiling SigmoidalProgramming \[ce2a0656-6bed-5c64-9e01-e7b1ac833b80\] ERROR: LoadError…

---

## [JuMP.jl vs MatLab's Optimization Toolbox](https://discourse.julialang.org/t/jump-jl-vs-matlabs-optimization-toolbox/61674)

<div class="topic-metadata">

**Author:** [@TheLateKronos](https://discourse.julialang.org/u/TheLateKronos)\
**Replies:** 3\
**Last updated:** [May 14, 2023, 11:14am UTC](https://discourse.julialang.org/t/jump-jl-vs-matlabs-optimization-toolbox/61674 "2023-05-14T11:14:47Z")

</div>

I am an undergrad, and I am considering taking an optional course on Optimization Engineering next semester. In my engineering faculty, MatLab is the default programming language, and I have heard that the subject relies…

---

## [JuMP model unregister action](https://discourse.julialang.org/t/jump-model-unregister-action/98784)

<div class="topic-metadata">

**Author:** [@Betristor](https://discourse.julialang.org/u/Betristor)\
**Replies:** 1\
**Last updated:** [May 13, 2023, 10:50pm UTC](https://discourse.julialang.org/t/jump-model-unregister-action/98784 "2023-05-13T22:50:39Z")

</div>

I got a question about how JuMP expressions are constructed. Like I got an expression named :a defined on some variables :x and :y and some constants :c in the way like a = x+y+c. But later I want to do some modification…

---

## [Quadratic Expression in JuMP](https://discourse.julialang.org/t/quadratic-expression-in-jump/98601)

<div class="topic-metadata">

**Author:** [@Gagan\_Meena](https://discourse.julialang.org/u/Gagan_Meena)\
**Replies:** 15\
**Last updated:** [May 13, 2023, 2:28am UTC](https://discourse.julialang.org/t/quadratic-expression-in-jump/98601 "2023-05-13T02:28:24Z")

</div>

ESS\_cost = CRF\*(CapES\*max\_Eb\*100 + CapPS\*max\_Pb\*100) + FOM\*max\_Pb\*100 + VOM\*sum(PD\[s\]\*dur\[s\] for s in scenar)\*100\*365 cost\_genvar = sum(PgenT\[j,i\]\*cov\[i,k\]\*Pgen\[k,j\] for i in bus\_key for j in scenar for k in bus\_ke…

---

## [SimplePDLP: a directory to illustrate how to implement a Julia optimization solver for teaching purpose](https://discourse.julialang.org/t/simplepdlp-a-directory-to-illustrate-how-to-implement-a-julia-optimization-solver-for-teaching-purpose/98763)

<div class="topic-metadata">

**Author:** [@HaihaoLu](https://discourse.julialang.org/u/HaihaoLu)\
**Replies:** 0\
**Last updated:** [May 12, 2023, 8:38pm UTC](https://discourse.julialang.org/t/simplepdlp-a-directory-to-illustrate-how-to-implement-a-julia-optimization-solver-for-teaching-purpose/98763 "2023-05-12T20:38:23Z")

</div>

Dear friends, SimplePDLP (BUSN-36919-Modern-Large-Scale-Optimization--Theory-and-Computation-2023/SimplePDLP at main · haihaolu/BUSN-36919-Modern-Large-Scale-Optimization--Theory-and-Computation-2023 · GitHub) is a dire…

---

## [Working with Multiple Vectors of Parameters](https://discourse.julialang.org/t/working-with-multiple-vectors-of-parameters/98685)

<div class="topic-metadata">

**Author:** [@astrobc1](https://discourse.julialang.org/u/astrobc1)\
**Replies:** 2\
**Last updated:** [May 11, 2023, 8:37pm UTC](https://discourse.julialang.org/t/working-with-multiple-vectors-of-parameters/98685 "2023-05-11T20:37:33Z")

</div>

I’m working with the SciML Optimization framework trying to optimize several Vectors of parameters with ReverseDiff.jl. I understand the Vector that’s passed to my objective function is flattened, so I’m also passing the…

---

## [Is it possible to solve problem for subset of parameters?](https://discourse.julialang.org/t/is-it-possible-to-solve-problem-for-subset-of-parameters/98645)

<div class="topic-metadata">

**Author:** [@Optimization](https://discourse.julialang.org/u/Optimization)\
**Replies:** 3\
**Last updated:** [May 11, 2023, 8:53am UTC](https://discourse.julialang.org/t/is-it-possible-to-solve-problem-for-subset-of-parameters/98645 "2023-05-11T08:53:26Z")

</div>

I have a dataset which is big and I already have written the model whith the following format: @constraint(model, f in F\], sum(x\[(i,j,k)\] for (i,j,k) in families\[f\] if i == pref\[f\]) == 1) # families\[f\] is a diction…

---

## [\`dualize()\` cannot take \`ignore\_objective\` argument](https://discourse.julialang.org/t/dualize-cannot-take-ignore-objective-argument/98650)

<div class="topic-metadata">

**Author:** [@g001234](https://discourse.julialang.org/u/g001234)\
**Replies:** 5\
**Last updated:** [May 10, 2023, 11:35pm UTC](https://discourse.julialang.org/t/dualize-cannot-take-ignore-objective-argument/98650 "2023-05-10T23:35:23Z")

</div>

When using Dualization.jl to dualize an LP, I used the ignore\_objective argument to turn off the objective. However, I received the following error: ERROR: MethodError: no method matching dualize(::Model, ::Nothing; dua…

---

## [ERROR: The provided \`optimizer\_constructor\` is invalid](https://discourse.julialang.org/t/error-the-provided-optimizer-constructor-is-invalid/98607)

<div class="topic-metadata">

**Author:** [@Gianmarco\_Montillo](https://discourse.julialang.org/u/Gianmarco_Montillo)\
**Replies:** 1\
**Last updated:** [May 10, 2023, 11:12pm UTC](https://discourse.julialang.org/t/error-the-provided-optimizer-constructor-is-invalid/98607 "2023-05-10T23:12:13Z")

</div>

Hello everyone, I am trying to solve a math model using Alpine.jl. Given n arrays of different dimension, n constraint of strict equalities (one for each sum of the whole array i.e. sum(x)==X, sum(y)==Y, sum(z)==Z), one …

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

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