MATLAB Answers

Query about simulanneal.m Function (Simulated Annealing Optimization).

3 views (last 30 days)
Muhammad Umair Javed
Muhammad Umair Javed on 9 Jun 2020
I have minimization problem which got a nonlinear objective function, a couple of equality constraints, and dozens of nonlinear constraints. There is a very simple given in MATLAB which does not contian any constraints other than objective function and starting point.
In this example inputs are only two things a function and strating points.
[x,fval,exitFlag,output] = simulannealbnd(ObjectiveFunction,x0)
Whereas I want to use following kind of function
function [x, fval, exitflag, output] = simulanneal(FUN, x0, Aineq, bineq, Aeq, beq, lb, ub, options)
which is given in the MATLAB documentations with the name of "simulanneal.m" file. Since, I want to give Aineq, bineq, lb, ub as well along with FUN and x0.
How can I implement such kind problem in MATLAB Simulated Annealig Optimization Toolbox?
Thanks

  0 Comments

Sign in to comment.

Answers (3)

Alan Weiss
Alan Weiss on 10 Jun 2020
Global Optimization Toolbox provides the simulannealbnd funciton, which does not provide linear constraints, though it does allow bounds.
My question would be, why do you need simulated annealing? If what you are trying to do is optimize something, then I suggest that you follow the guidance in Table for Choosing a Solver, which does not suggest using simulannealbnd.
Alan Weiss
MATLAB mathematical toolbox documentation

  5 Comments

Show 2 older comments
Muhammad Umair Javed
Muhammad Umair Javed on 12 Jun 2020
Thank you so much Sir.
I am already looking at surrogateopt.
Sir what If I got nonlinear constraints as well along with the nonlinear objective function?
Thanking you in anticipation.
Alan Weiss
Alan Weiss on 12 Jun 2020
surrogateopt ganed nonlinear constraint handling in R2020a. If you don't have that version, then look in your version of the documentation for an example tiitled Surrogate Optimization with Nonlinear Constraint.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

Sign in to comment.


Muhammad Umair Javed
Muhammad Umair Javed on 23 Jun 2020
Sir Alan Weiss
I am trying to solve my problem with surrogate optimization as you suggested. There are 119 variables in the problem in which eleven variables are integers. And I got dozens of inequality constraints.
I am getting following eror
Reference to non-existent field 'trialData'.
The script of the problem is given below
%% main
ObF = @(x)x(119);
intcon = [109 110 111 112 113 114 115 116 117 118 119] ;
objconstr = packfcn(ObF,@unitdisk);
%% Intentially I have not given here the vector of lb and ub, as these are very long vectors.
options = optimoptions('surrogateopt','Display','iter',MaxFunctionEvaluations',10000);
[x,fval,exitflag,output,trials] = surrogateopt(objconstr,lb,ub,intcon,options)
Umair

  2 Comments

Alan Weiss
Alan Weiss on 23 Jun 2020
Perhaps you could try to fit your problem into the MILP framework. Your objective is linear and the constraints I see are bounds, though I do not see the code for your unitdisk constraint function. Is it possible that you could use a set of linear inequalities for the nonlinear inequality constraint, along the lines of this example? Then you could use intlinprog to solver your problem.
To answer your question though, I don't know where the 'trialData' variable might be referenced. To find out for sure, you could use the debugger.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
Muhammad Umair Javed
Muhammad Umair Javed on 23 Jun 2020
Sir , you are abosulutely right my problem type is MINP, and I haved solved sucessfully this problem with the SCIP solver, and got an optimal result. The purpose to try here weather surrogate optimization can work for me or not? Because actually I want to solve a problem which got a nonlinear objuective function along with nonlinear constraints.
Sir details of the error is as follows
Reference to non-existent field 'trialData'.
Error in globaloptim.bmo.BlackboxModelOptimizer/solution
(line 245)
trials = self.results.trialData;
Error in surrogateopt (line 298)
[xmin,fmin,exitflag,output,trials] = controller.solution();
Error in main (line 14)
[x,fval,exitflag,output,trials] =
surrogateopt(objconstr,lb,ub,intcon,options)
My thought this error may be resolved by increasing the 'MaxFunctionEvaluations', however it don't work.
The unitdisk constraint function is :
function [c,ceq] = unitdisk(x)
c = [ x(2)-x(3)+x(4)-x(5)+x(6)-x(7) <= 0;
-x(2)+x(3)-x(4)+x(5)-x(6)+x(7) <= 0;
-x(2)+x(3)+x(8)-x(9)+1<=0;
x(2)-x(3)-x(8)+x(9)-1<=0;
-x(4)+x(5)+x(10)-x(11)+x(14)*x(109)+x(15)*x(112)<=0;
x(4)-x(5)-x(10)+x(11)-x(14)*x(109)-x(15)*x(112)<=0;
x(12)-x(13)+x(14)*x(110)+x(15)*x(113)-1<=0;
-x(12)+x(13)-x(14)*x(110)-x(15)*x(113)+1<=0;
x(1)+2*x(7)+2*x(9)+2*x(11)+2*x(13)+x(14)*x(111)+x(15)*x(114)-x(119)<=0;
-x(1)-2*x(7)-2*x(9)-2*x(11)-2*x(13)-x(14)*x(111)-x(15)*x(114)+x(119)<=0;
x(17)-x(18)+x(19)-x(20)+x(21)-x(22) <= 0;
-x(17)+x(18)-x(19)+x(20)-x(21)+x(22) <= 0;
-x(17)+x(18)+x(23)-x(24)-1<=0;
x(17)-x(18)-x(23)+x(24)+1<=0;
-x(19)+x(20)+x(25)-x(26)+x(29)*x(109)+x(30)*x(112)<=0;
x(19)-x(20)-x(25)+x(26)-x(29)*x(109)-x(30)*x(112)<=0;
x(27)-x(28)+x(29)*x(110)+x(30)*x(113)+1<=0;
-x(27)+x(28)-x(29)*x(110)-x(30)*x(113)-1<=0;
x(16)+2*x(22)+2*x(24)+2*x(26)+2*x(28)+x(29)*x(111)+x(30)*x(114)-x(119)<=0;
-x(16)-2*x(22)-2*x(24)-2*x(26)-2*x(28)-x(29)*x(111)-x(30)*x(114)+x(119)<=0;
x(32)-x(33)+x(34)-x(35)+x(36)-x(37)+x(42)*x(115)-x(43)*x(115)<=0;
-x(32)+x(33)-x(34)+x(35)-x(36)+x(37)-x(42)*x(115)+x(43)*x(115)<=0;
-x(32)+x(33)+x(38)-x(39)+x(42)*x(116)-x(43)*x(116)<=0;
x(32)-x(33)-x(38)+x(39)-x(42)*x(116)+x(43)*x(116)<=0;
-x(34)+x(35)+x(40)-x(41)+x(42)*x(117)-x(43)*x(117)<=0;
x(34)-x(35)-x(40)+x(41)-x(42)*x(117)+x(43)*x(117)<=0;
-x(42)+x(43)-1<=0;
x(42)-x(43)+1<=0;
x(31)+2*x(37)+2*x(39)+2*x(41)+x(42)*x(118)-x(43)*x(118)<=0;
-x(31)-2*x(37)-2*x(39)-2*x(41)-x(42)*x(118)+x(43)*x(118)<=0;
x(45)-x(46)+x(47)-x(48)+x(49)-x(50)+x(55)*x(115)-x(56)*x(115)<=0;
-x(45)+x(46)-x(47)+x(48)-x(49)+x(50)-x(55)*x(115)+x(56)*x(115)<=0;
-x(45)+x(46)+x(51)-x(52)+x(55)*x(116)-x(56)*x(116)<=0;
x(45)-x(46)-x(51)+x(52)-x(55)*x(116)+x(56)*x(116)<=0;
-x(47)+x(48)+x(53)-x(54)+x(55)*x(117)-x(56)*x(117)<=0;
x(47)-x(48)-x(53)+x(54)-x(55)*x(117)+x(56)*x(117)<=0;
-x(55)+x(56)+1<=0;
x(55)-x(56)-1<=0;
x(44)+2*x(50)+2*x(52)+2*x(54)+x(55)*x(118)-x(56)*x(118)-2<=0;
-x(44)-2*x(50)-2*x(52)-2*x(54)-x(55)*x(118)+x(56)*x(118)+2<=0;
x(58)-x(59)+x(60)-x(61)+x(62)-x(63)+x(68)*x(115)-x(69)*x(115)<=0;
-x(58)+x(59)-x(60)+x(61)-x(62)+x(63)-x(68)*x(115)+x(69)*x(115)<=0;
-x(58)+x(59)+x(64)-x(65)+x(68)*x(116)-x(69)*x(116)<=0;
x(58)-x(59)-x(64)+x(65)-x(68)*x(116)+x(69)*x(116)<=0;
-x(60)+x(61)+x(66)-x(67)+x(68)*x(117)-x(69)*x(117)-x(109)<=0;
x(60)-x(61)-x(66)+x(67)-x(68)*x(117)+x(69)*x(117)+x(109)<=0;
-x(68)+x(69)-x(110)<=0;
x(68)-x(69)+x(110)<=0;
x(57)+2*x(63)+2*x(65)+2*x(67)+x(68)*x(118)-x(69)*x(118)-x(111)<=0;
-x(57)-2*x(63)-2*x(65)-2*x(67)-x(68)*x(118)+x(69)*x(118)+x(111)<=0;
x(71)-x(72)+x(73)-x(74)+x(75)-x(76)+x(81)*x(115)-x(82)*x(115)<=0;
-x(71)+x(72)-x(73)+x(74)-x(75)+x(76)-x(81)*x(115)+x(82)*x(115)<=0;
-x(71)+x(72)+x(77)-x(78)+x(81)*x(116)-x(82)*x(116)<=0;
x(71)-x(72)-x(77)+x(78)-x(81)*x(116)+x(82)*x(116)<=0;
-x(73)+x(74)+x(79)-x(80)+x(81)*x(117)-x(82)*x(117)-x(112)<=0;
x(73)-x(74)-x(79)+x(80)-x(81)*x(117)+x(82)*x(117)+x(112)<=0;
-x(81)+x(82)-x(113)<=0;
x(81)-x(82)+x(113)<=0;
x(70)+2*x(76)+2*x(78)+2*x(80)+x(81)*x(118)-x(82)*x(118)-x(114)<=0;
-x(70)-2*x(76)-2*x(78)-2*x(80)-x(81)*x(118)+x(82)*x(118)+x(114)<=0;
x(84)-x(85)+x(86)-x(87)+x(88)-x(89)+x(94)*x(115)-x(95)*x(115)<=0;
-x(84)+x(85)-x(86)+x(87)-x(88)+x(89)-x(94)*x(115)+x(95)*x(115)<=0;
-x(84)+x(85)+x(90)-x(91)+x(94)*x(116)-x(95)*x(116)-1<=0;
x(84)-x(85)-x(90)+x(91)-x(94)*x(116)+x(95)*x(116)+1<=0;
-x(86)+x(87)+x(92)-x(93)+x(94)*x(117)-x(95)*x(117)<=0;
x(86)-x(87)-x(92)+x(93)-x(94)*x(117)+x(95)*x(117)<=0;
-x(94)+x(95)-1<=0;
x(94)-x(95)+1<=0;
x(83)+2*x(89)+2*x(91)+2*x(93)+x(94)*x(118)-x(95)*x(118)-x(119)<=0;
-x(83)-2*x(89)-2*x(91)-2*x(93)-x(94)*x(118)+x(95)*x(118)+x(119)<=0;
x(97)-x(98)+x(99)-x(100)+x(101)-x(102)+x(107)*x(115)-x(108)*x(115)<=0;
-x(97)+x(98)-x(99)+x(100)-x(101)+x(102)-x(107)*x(115)+x(108)*x(115)<=0;
-x(97)+x(98)+x(103)-x(104)+x(107)*x(116)-x(108)*x(116)+1<=0;
x(97)-x(98)-x(103)+x(104)-x(107)*x(116)+x(108)*x(116)-1<=0;
-x(99)+x(100)+x(105)-x(106)+x(107)*x(117)-x(108)*x(117)<=0;
x(99)-x(100)-x(105)+x(106)-x(107)*x(117)+x(108)*x(117)<=0;
-x(107)+x(108)+1<=0;
x(107)-x(108)-1<=0;
x(96)+2*x(102)+2*x(104)+2*x(106)+x(107)*x(118)-x(108)*x(118)-x(119)<=0;
-x(96)-2*x(102)-2*x(104)-2*x(106)-x(107)*x(118)+x(108)*x(118)+x(119)<=0
];
ceq = [];
end

Sign in to comment.


Muhammad Umair Javed
Muhammad Umair Javed on 23 Jun 2020
Sir, I forgot to mention here that actually the MINLP tools are not accepting this kind of objective function.
I am using https://www.inverseproblem.co.nz/OPTI/index.php/Probs/MINLP along with the MATLAB plateform. However, there is no such option to deal with kind of problem. That's why I am looking for some alternative.

  2 Comments

Alan Weiss
Alan Weiss on 23 Jun 2020
I suspect that your integer variables x(9) through x(118) are binary. In that case, I believe that you can reformulate your entire problem as MILP, not nonlinear at all, and use intlinprog to solve your problem.
The objective function vector f for intlinprog is a vector of 118 zero entries, and entry 119 = 1.
That said, your current nonlinear constraint function is written incorrectly. All of the "<= 0" ASCII characters should be removed. surrogateopt will not throw an error after you remove those fallacious characters.
But I believe that you will have much better luck formulating your problem as a MILP. All of your constraints are nearly linear constraints. The only things that are nonlinear are of the form x(94)*x(117)-x(95)*x(117) or the like, where x(117) is (I strongly suspect) a binary variable, and is integer in any case. You can probably turn this into a strictly linear inequality by incorporating some extra indicator variables using a big-M formulation such as in this example.
I urge you to consider using MILP rather than a nonlinear solver to solve this nearly-linear mixed-integer problem. It requires some thought, but the solver speed will be well worthwhile.
Alan Weiss
MATLAB mathematical toolbox documentation
Muhammad Umair Javed
Muhammad Umair Javed on 25 Jun 2020
Respected Sir
In this running problem the variables x(0) through x(108) are real; 0 <= x(0),...,x(108) <=1. And x(109) through x(118) are integers; -inf <= x(109),...,x(118)<=inf . Whereas x(119) is also an integer whose bounds are 0 to 2.
Sir, I have already solved this problem with the MINLP framework by using SCIP solver. I was just trying this problem here for testing purpose.The actual purpose to ask question at this forum is different. I would give another try here to illustrate the problem which I want to solve.
My problem is a minimization problem and I want to minimize the maximum of p. However, my objective function is not a simple linear, nonlinear, or quadratic expression, rather it involves summation and max on top of that, and max comes inside of summation.
Let's say, the set of t and p has 2 elements each; t = {0, 1} and p = {0,1}. Since for t = 0, I have to find which p gets max value among 0 and 1, and then for t = 1 which p gets max value among 0 and 1, and then sum over these two max values in the end.
This is a complex objective function, and I not sure weather the mixed integer linear or nonlinear programming solver can deal this function or not? That's why I start looking at some heuristic tecniques like simulated annealing etc. If some linear or nonlinear programming solver can tackle with my problem that would make my life easier. Sir please suggest me if you think some solver help me in this regard. Otherwise I would have to go for some heuristic technique I guess.
Umair

Sign in to comment.


Translated by