Fmincon gives Exact the same Answer as the initial guess

24 次查看(过去 30 天)
This is how I defined fmincon options
fminoptions = optimoptions('fmincon','Display','iter','Algorithm','interior-point');
problem.options = fminoptions;
problem.solver = 'fmincon';
%problem.nonlcon = @Constraints;
problem.objective = @obj;
problem.ub = [200,40];
problem.lb = [190,30];
[x,sln2.objective] = fmincon(problem);
x(1)
x(2)
This is the objective function:
ob = Ext.W22.*(Ext.TC1 - (round(x(1)))*(round(x(2)))).^2

采纳的回答

Matt J
Matt J 2021-6-2
编辑:Matt J 2021-6-2
Because of the round() operations, your objective function is locally flat (i.e., has zero gradient) almost everywhere. Therefore, almost every initial point you can choose is a local minimum.
Be mindful also that fmincon is a derivative based solver. It assumes you have a continuously differentiable objective function and nonlinear constraints. The discontinuous nautre of round() operations ruin that as well.
  6 个评论
Matt J
Matt J 2021-6-2
Your posted problem has x1 in the range [190,200] and x2 in the range [30,40], which contain 11^2 integer values. Five unknowns with similar bounds would contain 11^5 values, which is also not too bad. It's hard to give advice without seeing the real problem.
Muhammad Qaisar Fahim
yes that is helpful. But If I need to expand the problem and later I need to include many other design parameters then it woyulb become bery tough to solve with it. But for the problem in hand its one of the best and easy solution.

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2021-6-2
fmincon() is never suitable for discrete parameters.
If you have mixed integer work that has a scalar output then your options are:
  • ga -- supports anonymous functions; supports nonlinear constraints
  • abusing patternsearch() -- supports anonymous functions; supports nonlinear constraints
  • intlinprog() -- supports matrix objectives only; does not support nonlinear
  • surrogate optimization -- supports anonymous functions; supports nonlinear constraints; https://www.mathworks.com/help/gads/surrogateopt.html
In order to use integer constraints with ga(), you have to write your own functions to handle cross-over and mutation and initial population -- functions that just happen to obey the required integer constraints. The more obvious integer constraints for ga() are incompatible with providing nonlinear contraints.
Surrogate optimization provides obvious integer constraints, but does not provide obvious nonlinear constraints. However, instead of your objective function returning a numeric scalar, it can instead return a struct with a particular form, and surrogate optimization will follow the nonlinear constraints expressed in the structure.
  2 个评论
Muhammad Qaisar Fahim
Thankuou very much for such help. What is meant by obvious ininteger constraints ? Can you please help me to understand What you want say in the last 2 paragraphs more explicitly?
Walter Roberson
Walter Roberson 2021-6-2
ga has a calling form which is
x = ga(fun,nvars,A,b,[],[],lb,ub,nonlcon,IntCon)
However:
"When there are integer constraints, ga does not accept linear or nonlinear equality constraints, only inequality constraints."
so when the IntCon parameter is not empty, then it is okay for A and b and lb and ub to be non-empty, but Aeq, beq, and nonlcon would have to be empty.
ga() handles integer constraints internally by providing its own crossover and mutation and population construction functions that enforce the integer constraints. If you need both nonlinear constraints (nonlcon not empty) and integer constraints, then what you need to do is pass IntCon as empty, and supply your own crossover and mutation and popopulation construction functions that "just happen" to return values that follow the desired integer constraints.
surrogateopt() supports a syntax of
x = surrogateopt(objconstr,lb,ub,intcon,A,b,Aeq,beq)
which has a position for integer constraints. But notice that there is no position there for nonlinear constraints. surrogateopt() does not use a separate function that is in charge of testing for nonlinear inequalities. Instead,
objconstr returns one of the following:
  • Real scalar fval = objconstr(x).
  • Structure. If the structure contains the field Fval, then surrogateopt attempts to minimize objconstr(x).Fval. If the structure contains the field Ineq, then surrogateopt attempts to make all components of that field nonpositive: objconstr(x).Ineq <= 0 for all entries. objconstr(x) must include either the Fval or Ineq fields, or both. surrogateopt ignores other fields.
So you can implement nonlinear constraints by having the function return a struct that has an Ineq field.
surrogateopt does not support nonlinear equality constraints directly. You could, however, have the Ineq field return both a constraint value and its negative: surrogateopt would try to make both of the entries <= 0 and except for tolerance ranges, the only way for both of them to be <= 0 would be if the entry was 0.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surrogate Optimization 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by