Optimization problem gets stuck before going into solver

5 次查看(过去 30 天)
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 个评论
Nima
Nima 2023-11-28
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.

请先登录,再进行评论。

回答(1 个)

Alan Weiss
Alan Weiss 2023-11-20
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

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by