# Optimization (Mathematical)

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

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

**Page:** 54

---

## [Workaround for: Sum of binary Matrix as Index for Input Matrix](https://discourse.julialang.org/t/workaround-for-sum-of-binary-matrix-as-index-for-input-matrix/90769)

<div class="topic-metadata">

**Author:** [@JNSDVD](https://discourse.julialang.org/u/JNSDVD)\
**Replies:** 3\
**Last updated:** [November 24, 2022, 7:18pm UTC](https://discourse.julialang.org/t/workaround-for-sum-of-binary-matrix-as-index-for-input-matrix/90769 "2022-11-24T19:18:13Z")

</div>

Hey people, I am new here, any help is much appreciated!! @variable( bilap, X\[1:2,u=1:4,1:3\], Bin) I want to use the sum of all 1s per each u in X as an Input (Index) for the matrix shown above. @constraint( bilap…

---

## [How to model a 2 dimensional drone using JUMP, and lpopt](https://discourse.julialang.org/t/how-to-model-a-2-dimensional-drone-using-jump-and-lpopt/90703)

<div class="topic-metadata">

**Author:** [@elliot000319](https://discourse.julialang.org/u/elliot000319)\
**Replies:** 4\
**Last updated:** [November 24, 2022, 6:39pm UTC](https://discourse.julialang.org/t/how-to-model-a-2-dimensional-drone-using-jump-and-lpopt/90703 "2022-11-24T18:39:10Z")

</div>

I want to model a drone? (consider a drone) that has a fixed thrust. It needs to control its body angle and thrust value to balance itself against the gravity to arrive at the desired destination. I might have made some …

---

## [Incorrect objective type when using MA57 with Ipopt in JuMP](https://discourse.julialang.org/t/incorrect-objective-type-when-using-ma57-with-ipopt-in-jump/90578)

<div class="topic-metadata">

**Author:** [@this\_josh](https://discourse.julialang.org/u/this_josh)\
**Replies:** 14\
**Last updated:** [November 24, 2022, 8:38am UTC](https://discourse.julialang.org/t/incorrect-objective-type-when-using-ma57-with-ipopt-in-jump/90578 "2022-11-24T08:38:27Z")

</div>

I’d like minimise the sum of a variable using JuMP, here is a MWE: UB= rand(1:9, (67,24)) # not really necessary model = Model() @variable(model, 0 ≤ x\[i= 1:67, j=1:24\] ≤ UB\[i,j\]) @objective(model, Min, sum(x\[ii, jj\] f…

---

## [Unstable performance of MILP with JuMP](https://discourse.julialang.org/t/unstable-performance-of-milp-with-jump/90715)

<div class="topic-metadata">

**Author:** [@Shuhua](https://discourse.julialang.org/u/Shuhua)\
**Replies:** 2\
**Last updated:** [November 24, 2022, 2:47am UTC](https://discourse.julialang.org/t/unstable-performance-of-milp-with-jump/90715 "2022-11-24T02:47:07Z")

</div>

It occasionally happens that the running time in solving a fixed MILP problem varies between a few seconds and a few minutes. The scenario remains the same regardless of the solver: I have tried Gurobi, Cbc, and HiGHS. T…

---

## [@NLexpression involving multilinear algebra](https://discourse.julialang.org/t/nlexpression-involving-multilinear-algebra/90656)

<div class="topic-metadata">

**Author:** [@Thomas](https://discourse.julialang.org/u/Thomas)\
**Replies:** 3\
**Last updated:** [November 22, 2022, 6:12pm UTC](https://discourse.julialang.org/t/nlexpression-involving-multilinear-algebra/90656 "2022-11-22T18:12:25Z")

</div>

What is the recommended way to implement @NLexpression(model, tr(kron(A,B)\*kron(C,D,E)) where A,B,C,D,E are (references of) matrices of JuMP variables created by @variable of compatible sizes (so matrix multiplication …

---

## [JuMP constraint building with dot call: how to use @dot](https://discourse.julialang.org/t/jump-constraint-building-with-dot-call-how-to-use-dot/90632)

<div class="topic-metadata">

**Author:** [@Shuhua](https://discourse.julialang.org/u/Shuhua)\
**Replies:** 1\
**Last updated:** [November 22, 2022, 4:35pm UTC](https://discourse.julialang.org/t/jump-constraint-building-with-dot-call-how-to-use-dot/90632 "2022-11-22T16:35:27Z")

</div>

julia\> using JuMP julia\> model = JuMP.Model() julia\> @variable(model, x\[1:3\]) julia\> @variable(model, y\[1:3\]) julia\> @. @constraint(model, x \<= y) gives error: ERROR: At REPL\[19\]:1: @constraint(model, (\<=).(x, y)): …

---

## [Speed up Ipopt solver](https://discourse.julialang.org/t/speed-up-ipopt-solver/89984)

<div class="topic-metadata">

**Author:** [@Katti](https://discourse.julialang.org/u/Katti)\
**Replies:** 12\
**Last updated:** [November 22, 2022, 10:32am UTC](https://discourse.julialang.org/t/speed-up-ipopt-solver/89984 "2022-11-22T10:32:55Z")

</div>

Hello, I have a non-linear problem which I am solving with Ipopt and JuMP. The problem originally spans over around 70 days (divided in quarter-hourly periods), but I have started to solve the model for less periods. Th…

---

## [Gurobi solution quality attributes prints "nothing"](https://discourse.julialang.org/t/gurobi-solution-quality-attributes-prints-nothing/90612)

<div class="topic-metadata">

**Author:** [@MirelEce](https://discourse.julialang.org/u/MirelEce)\
**Replies:** 2\
**Last updated:** [November 22, 2022, 1:20am UTC](https://discourse.julialang.org/t/gurobi-solution-quality-attributes-prints-nothing/90612 "2022-11-22T01:20:38Z")

</div>

Hi all! I am trying to solve a nonconvex feasibility problem with 1 quadratic constraint in Gurobi and when the model is infeasible, it doesn’t say it is infeasible and instead, it says the solution is optimal but with …

---

## [Save Model Outputs](https://discourse.julialang.org/t/save-model-outputs/90465)

<div class="topic-metadata">

**Author:** [@Yuri\_Masakazu\_Mizusa](https://discourse.julialang.org/u/Yuri_Masakazu_Mizusa)\
**Replies:** 2\
**Last updated:** [November 21, 2022, 11:27pm UTC](https://discourse.julialang.org/t/save-model-outputs/90465 "2022-11-21T23:27:49Z")

</div>

Hi, I am running a small model several times (1000 to be more precise) and for each run I need to store the results. Usually I turn it to a DataFrame and save as a csv. But in this case I do not want to save 1000 csvs. …

---

## [How to add constant value to a simple MPC Problem](https://discourse.julialang.org/t/how-to-add-constant-value-to-a-simple-mpc-problem/90575)

<div class="topic-metadata">

**Author:** [@elliot000319](https://discourse.julialang.org/u/elliot000319)\
**Replies:** 3\
**Last updated:** [November 21, 2022, 6:09pm UTC](https://discourse.julialang.org/t/how-to-add-constant-value-to-a-simple-mpc-problem/90575 "2022-11-21T18:09:21Z")

</div>

The following is a code that takes the current position & velocity of a box and returns the optimized trajectory of position, velocity, and acceleration. The box is placed in a 2D frictionless map. I want to add a gravit…

---

## [Question about LP format file generation](https://discourse.julialang.org/t/question-about-lp-format-file-generation/90460)

<div class="topic-metadata">

**Author:** [@kevinqiao](https://discourse.julialang.org/u/kevinqiao)\
**Replies:** 5\
**Last updated:** [November 21, 2022, 7:14am UTC](https://discourse.julialang.org/t/question-about-lp-format-file-generation/90460 "2022-11-21T07:14:32Z")

</div>

I’m using JuMP v1.4.0 and I want to generate an LP format file of the following model, but it doesn’t work, the file is not generated, and I don’t know why. Thanks in advance. using JuMP using Gurobi model = Model(Gur…

---

## [JuMP set start values in new model with solution of smaller model](https://discourse.julialang.org/t/jump-set-start-values-in-new-model-with-solution-of-smaller-model/90482)

<div class="topic-metadata">

**Author:** [@nlaws](https://discourse.julialang.org/u/nlaws)\
**Replies:** 1\
**Last updated:** [November 20, 2022, 6:20pm UTC](https://discourse.julialang.org/t/jump-set-start-values-in-new-model-with-solution-of-smaller-model/90482 "2022-11-20T18:20:20Z")

</div>

In the JuMP docs it shows how to efficiently set start values using one model: x = all\_variables(model) x\_solution = value.(x) set\_start\_value.(x, x\_solution) However, I am looking for an efficient way to do this with …

---

## [Differences between NLsolve and Optim in solving system of equations](https://discourse.julialang.org/t/differences-between-nlsolve-and-optim-in-solving-system-of-equations/60467)

<div class="topic-metadata">

**Author:** [@amrods](https://discourse.julialang.org/u/amrods)\
**Replies:** 24\
**Last updated:** [November 16, 2022, 4:04am UTC](https://discourse.julialang.org/t/differences-between-nlsolve-and-optim-in-solving-system-of-equations/60467 "2022-11-16T04:04:46Z")

</div>

I am solving a system of equations using 2 methods. Solving it “directly” with NLsolve, and solving it by minimizing the norm of the residuals of the system. Here’s an example: using NLsolve using Optim using LinearAlge…

---

## [Lagragian multipliers in JuMP](https://discourse.julialang.org/t/lagragian-multipliers-in-jump/90234)

<div class="topic-metadata">

**Author:** [@this\_josh](https://discourse.julialang.org/u/this_josh)\
**Replies:** 6\
**Last updated:** [November 15, 2022, 8:58am UTC](https://discourse.julialang.org/t/lagragian-multipliers-in-jump/90234 "2022-11-15T08:58:47Z")

</div>

I appreciate questions about Lagrange multipliers in Jump have been discussed before, here the sign change is described. However, I’m having trouble reproducing example 6.32 (page 163) in Nonlinear and mixed-integer opti…

---

## [Gurobi v10 and Julia](https://discourse.julialang.org/t/gurobi-v10-and-julia/90220)

<div class="topic-metadata">

**Author:** [@MirelEce](https://discourse.julialang.org/u/MirelEce)\
**Replies:** 2\
**Last updated:** [November 14, 2022, 2:59am UTC](https://discourse.julialang.org/t/gurobi-v10-and-julia/90220 "2022-11-14T02:59:38Z")

</div>

Hi there! I saw on Github that support for the version 10 of Gurobi is added and I just updated to that release of Gurobi; however couldn’t manage to use it in Julia (v1.7.2). I removed the package and added it again aft…

---

## [Creating a new variable in JuMP with other variables already existing](https://discourse.julialang.org/t/creating-a-new-variable-in-jump-with-other-variables-already-existing/90138)

<div class="topic-metadata">

**Author:** [@afazevedo](https://discourse.julialang.org/u/afazevedo)\
**Replies:** 4\
**Last updated:** [November 12, 2022, 10:02pm UTC](https://discourse.julialang.org/t/creating-a-new-variable-in-jump-with-other-variables-already-existing/90138 "2022-11-12T22:02:09Z")

</div>

Hi there. Can anyone help me? I’m doing sort of implementation of a column generation model and after finding a new pattern I want to add a new variable from a existing set of existing variables. Example: This is my ma…

---

## [Error escaping a variable in a module using JuMP](https://discourse.julialang.org/t/error-escaping-a-variable-in-a-module-using-jump/89998)

<div class="topic-metadata">

**Author:** [@Mitch\_Phillipson](https://discourse.julialang.org/u/Mitch_Phillipson)\
**Replies:** 4\
**Last updated:** [November 9, 2022, 9:34pm UTC](https://discourse.julialang.org/t/error-escaping-a-variable-in-a-module-using-jump/89998 "2022-11-09T21:34:47Z")

</div>

I’m working to update a module compatible with JuMP v1.1.1 to the newest version of JuMP. Within the module is code similar to: module HoldBug using JuMP export @mytest macro mytest(m,F) m = esc(m) x = esc(F…

---

## [JuMP in julia](https://discourse.julialang.org/t/jump-in-julia/89945)

<div class="topic-metadata">

**Author:** [@thiagoselias](https://discourse.julialang.org/u/thiagoselias)\
**Replies:** 9\
**Last updated:** [November 9, 2022, 9:05pm UTC](https://discourse.julialang.org/t/jump-in-julia/89945 "2022-11-09T21:05:42Z")

</div>

Link: https://gist.githubusercontent.com/thiagoselias/65dd09e675493443493b394bcc136784/raw/c81339907844c6bfb296353ed22269706d46b497/minimizacao.jl I have this problem But specifically in the constraint @constraint(mo…

---

## [Posing constraints on component array optimizations](https://discourse.julialang.org/t/posing-constraints-on-component-array-optimizations/90007)

<div class="topic-metadata">

**Author:** [@RuoyuWang72](https://discourse.julialang.org/u/RuoyuWang72)\
**Replies:** 0\
**Last updated:** [November 9, 2022, 8:33pm UTC](https://discourse.julialang.org/t/posing-constraints-on-component-array-optimizations/90007 "2022-11-09T20:33:06Z")

</div>

I have a component array p I want to optimize, p.ps\_τ and p.ps\_J are parameters of neural nets, and p.ps\_F1 and p.ps\_F2 are two floats (I followed this example: Simultaneous Fitting of Multiple Neural Networks ) The con…

---

## [Conditional constraint if else in JuMP](https://discourse.julialang.org/t/conditional-constraint-if-else-in-jump/6795)

<div class="topic-metadata">

**Author:** [@UserMorocco](https://discourse.julialang.org/u/UserMorocco)\
**Replies:** 14\
**Last updated:** [November 9, 2022, 6:43pm UTC](https://discourse.julialang.org/t/conditional-constraint-if-else-in-jump/6795 "2022-11-09T18:43:33Z")

</div>

Hello, How I can model the conditional constraint if else with JuMP in Julia ? Thank you

---

## [Print optimization problem using Ipopt](https://discourse.julialang.org/t/print-optimization-problem-using-ipopt/89786)

<div class="topic-metadata">

**Author:** [@Katti](https://discourse.julialang.org/u/Katti)\
**Replies:** 6\
**Last updated:** [November 9, 2022, 1:18pm UTC](https://discourse.julialang.org/t/print-optimization-problem-using-ipopt/89786 "2022-11-09T13:18:57Z")

</div>

Hello all, I am building a pretty complex optimization problem with the Ipopt solver (NLP). Since the results are not as I expected, I guess that I made a mistake in the model definition. Therefore, I would like to prin…

---

## [JuMP kmeans with constraints](https://discourse.julialang.org/t/jump-kmeans-with-constraints/89906)

<div class="topic-metadata">

**Author:** [@monty](https://discourse.julialang.org/u/monty)\
**Replies:** 4\
**Last updated:** [November 8, 2022, 8:03pm UTC](https://discourse.julialang.org/t/jump-kmeans-with-constraints/89906 "2022-11-08T20:03:47Z")

</div>

I am solving k-means using JuMP. X = \[ 2.0 2.0; 2.5 2.1; 7.0 7.0; 2.2 2.3; 6.8 7.0; 7.2 7.5;\] k=2 m, n = size(X) W = exp.(-Distances.pairwise(Distances.Euclidean(), X')) I = Matrix(1.0 \* LinearAlgebra.I, m, m) mo…

---

## [Set\_optimizer\_attribute does not work in newer versions of JuMP, Julia, etc.?](https://discourse.julialang.org/t/set-optimizer-attribute-does-not-work-in-newer-versions-of-jump-julia-etc/89727)

<div class="topic-metadata">

**Author:** [@fksayaci](https://discourse.julialang.org/u/fksayaci)\
**Replies:** 8\
**Last updated:** [November 7, 2022, 9:14pm UTC](https://discourse.julialang.org/t/set-optimizer-attribute-does-not-work-in-newer-versions-of-jump-julia-etc/89727 "2022-11-07T21:14:10Z")

</div>

Hello all, I have an optimization model. I run it on my computer without any problem. I have the following for loop to assign values to Gurobi parameters: for paramrow in eachrow(solver\_params) if paramrow.Type == …

---

## [MethodError: no method matching Float64 when using ForwardDiff.jl despite me pre-allocating arrays to take floating point](https://discourse.julialang.org/t/methoderror-no-method-matching-float64-when-using-forwarddiff-jl-despite-me-pre-allocating-arrays-to-take-floating-point/89859)

<div class="topic-metadata">

**Author:** [@sumant28](https://discourse.julialang.org/u/sumant28)\
**Replies:** 4\
**Last updated:** [November 7, 2022, 7:07pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-float64-when-using-forwarddiff-jl-despite-me-pre-allocating-arrays-to-take-floating-point/89859 "2022-11-07T19:07:31Z")

</div>

using Optimization, OptimizationOptimJL, OptimizationBBO, OptimizationMOI, ForwardDiff, ModelingToolkit, Random, OptimizationOptimisers, Statistics, Plots function MSEg(u, p) X = p.X y = p.y h = u\[1\] beta = u\[2:…

---

## [Differentiable optimization / BigFloat - does DiffOpt.jl work with SDPAFamily.jl?](https://discourse.julialang.org/t/differentiable-optimization-bigfloat-does-diffopt-jl-work-with-sdpafamily-jl/89771)

<div class="topic-metadata">

**Author:** [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Replies:** 1\
**Last updated:** [November 4, 2022, 7:29pm UTC](https://discourse.julialang.org/t/differentiable-optimization-bigfloat-does-diffopt-jl-work-with-sdpafamily-jl/89771 "2022-11-04T19:29:22Z")

</div>

I’m interested in solving semidefinite optimization problems and compute the derivatives of the solutions w.r.t. input parameters. BigFloat may be needed for some of the more demanding problems. Does the differentiable o…

---

## [Get all solution found by CPLEX.jl](https://discourse.julialang.org/t/get-all-solution-found-by-cplex-jl/89780)

<div class="topic-metadata">

**Author:** [@Luca](https://discourse.julialang.org/u/Luca)\
**Replies:** 1\
**Last updated:** [November 4, 2022, 6:16pm UTC](https://discourse.julialang.org/t/get-all-solution-found-by-cplex-jl/89780 "2022-11-04T18:16:45Z")

</div>

Dear all, I’m using CPLEX.jl to solve a MILP. I would like to retrieve all the solutions found by the solver. Do you have any advise or suggestion? Thanks very much. Bests.

---

## [Optimization using JuMP](https://discourse.julialang.org/t/optimization-using-jump/89720)

<div class="topic-metadata">

**Author:** [@JUL1A](https://discourse.julialang.org/u/JUL1A)\
**Replies:** 12\
**Last updated:** [November 3, 2022, 9:18pm UTC](https://discourse.julialang.org/t/optimization-using-jump/89720 "2022-11-03T21:18:12Z")

</div>

I’m trying to code an optimization problem in Julia using JuMP. The objective function has two matrix multiplications. First, multiply the vector of w with size (10) by the matrix of arr\_C with size (20, 10). So the w s…

---

## [The objective function sparse is not supported by JuMP in julia](https://discourse.julialang.org/t/the-objective-function-sparse-is-not-supported-by-jump-in-julia/89726)

<div class="topic-metadata">

**Author:** [@thiagoselias](https://discourse.julialang.org/u/thiagoselias)\
**Replies:** 9\
**Last updated:** [November 3, 2022, 8:28pm UTC](https://discourse.julialang.org/t/the-objective-function-sparse-is-not-supported-by-jump-in-julia/89726 "2022-11-03T20:28:22Z")

</div>

model = Model(Gurobi.Optimizer) @objective(model, Min, DRect + 0.6DBlad + 0.6DBO) The objective function sparse(\[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, …

---

## [Result and summary files not generated with BARON.jl](https://discourse.julialang.org/t/result-and-summary-files-not-generated-with-baron-jl/89722)

<div class="topic-metadata">

**Author:** [@math\_opt](https://discourse.julialang.org/u/math_opt)\
**Replies:** 6\
**Last updated:** [November 3, 2022, 8:16pm UTC](https://discourse.julialang.org/t/result-and-summary-files-not-generated-with-baron-jl/89722 "2022-11-03T20:16:12Z")

</div>

I solved the following tutorial problem on JuMP’s documentation page, but the result and summary file are not generated (I do set the result and summary parameters to 1): using JuMP, BARON rocket = Model(BARON.Optimize…

---

## [Multidimensional non-linear root search?](https://discourse.julialang.org/t/multidimensional-non-linear-root-search/89680)

<div class="topic-metadata">

**Author:** [@gleyland](https://discourse.julialang.org/u/gleyland)\
**Replies:** 3\
**Last updated:** [November 3, 2022, 7:00pm UTC](https://discourse.julialang.org/t/multidimensional-non-linear-root-search/89680 "2022-11-03T19:00:26Z")

</div>

Hi, Does anyone have any guidance on what’s best practice for non-linear root search? (in this case, relatively small, smooth systems of equations expressed as code that should be AD-able) It looks like NLsolve.jl is …

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

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