Optimization problem gets stuck before going into solver

7 views (last 30 days)
I have defined my constraints and objective function for my optimization problem and I have selected fmincon as the solver using the command
opt = optimoptions('fmincon', 'MaxIterations', 1000, 'Algorithm', 'sqp');
However, the command window does even show the classical message "Solving problem using fmincon" after 30 minutes. So I think that matlab gets stuck even before that. Meanwhile the system is under "busy" condition. Then, when I stop it manually I get the following error:
Operation terminated by user during optim.internal.problemdef.visitor.CompileNonlinearFunction/getArgumentName In optim.internal.problemdef.visitor.CompileReverseADReversePass/getParentJacArgumentName In optim.internal.problemdef.visitor.CompileReverseADReversePass/visitOperatorTimes In optim.internal.problemdef.Times/acceptVisitor In optim.internal.problemdef.visitor.CompileReverseADReversePass/visitBinaryExpressionImpl In optim.internal.problemdef.BinaryExpressionImpl/acceptVisitor In optim.internal.problemdef.visitor.CompileReverseADReversePass/visitTree In optim.internal.problemdef.visitor.CompileReverseADReversePass/visitForest In optim.internal.problemdef.ExpressionForest/compileReverseAD In optim.problemdef.OptimizationExpression/compileReverseAD In optim.internal.problemdef.compile.compileNonlinearExprOrConstrWithAD In optim.internal.problemdef.compile.compileNonlinearObjective In optim.problemdef.OptimizationProblem/compileObjectives In optim.internal.problemdef.ProblemImpl/prob2structImpl In optim.internal.problemdef.ProblemImpl/solveImpl In optim.problemdef.OptimizationProblem/solve In routingGame (line 92) sol = solve(sysProb,x_init,'options',opt);
Does anybody have any idea?
Thanks in advance!
  2 Comments
Torsten
Torsten on 20 Nov 2023
And setting
sol = solve(sysProb)
does not produce this behaviour ?
Nima
Nima on 28 Nov 2023
If this is happenning at the "define objective" step, I have exactly faced the same issue recently with the surrogate optimization. It takes quite a while until MATLAB gets to the "solve" step and I haven't found any solution for that yet.

Sign in to comment.

Answers (1)

Alan Weiss
Alan Weiss on 20 Nov 2023
It is apparent that solve is taking too long to calculate constraint derivatives using reverse-mode autodifferentiation. This might not happen in a new version of MATLAB, where internally there are smarter AD algorithms. However, you can lkely avoid this issue in all versions by turning off AD:
sol = solve(prob,ConstraintDerivative="finite-differences") % Maybe also ObjectiveDerivative="finite-differences"
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

Products


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!