Fmincon gives Exact the same Answer as the initial guess

조회 수: 20 (최근 30일)
Muhammad Qaisar Fahim
Muhammad Qaisar Fahim 2021년 6월 2일
댓글: Walter Roberson 2021년 6월 2일
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
Muhammad Qaisar Fahim 2021년 6월 2일
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
Muhammad Qaisar Fahim 2021년 6월 2일
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