Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
[fmincon] help with options

Subject: [fmincon] help with options

From: Jason

Date: 15 Nov, 2011 08:26:11

Message: 1 of 8

Dear all

I am trying to solve a Waste Water Treatment problem which involves optimizing the network.

I have tried using fmincon with the initial guess as a reported global minimum of 1.0826E06 but various fmincon algorithms gave me much higher values in the region of 3E06 to 4E06.

Could anyone kindly advise what optimset options should I used?

Currently I have tried
> optimset('Display','off','MaxFunEvals',1000000,'MaxIter',200000,...
         'TolFun',1e-1,'TolX',1e-1,'DiffMinChange',1e-5,'Algorithm','active-set');

>optimset('Display','off','MaxFunEvals',10000,'MaxIter',2000,...
          'TolFun',1e-1,'TolX',1e-1,'DiffMinChange',1e-10,'Algorithm','interior-point','FinDiffType','central');

>optimset('Display','off','MaxFunEvals',1000000,'MaxIter',200000,...
         'TolFun',1e-1,'TolX',1e-1,'DiffMinChange',1e-5,'Algorithm','SQP');

>optimset('Display','off','MaxFunEvals',100000,'MaxIter',20000,...
          'TolFun',1e-1,'TolX',1e-1,'Algorithm','active-set','FinDiffType','central');

Subject: [fmincon] help with options

From: Jason

Date: 15 Nov, 2011 08:35:27

Message: 2 of 8

The main function code is as belows













NVAR=207;
%----Variables Bounds----------
VLB=[zeros(1,177) repmat([50 80 50],1,10)];
VUB=[repmat(400,1,177) repmat([1200 1750 2000],1,10)];

global Ww Rr Cc FW CW RRate CLimit FRC VRC DWR DRR DWS DRS
Ww=7; % Number of waste water sources (Feed)
Rr=10; % Number of regeneration processes (Pools)
% SS=1; % Number of sinks (Products)
Cc=3; % Number of contaminants
FW=[20 50 47.5 28 100 30 25]; % Total flow from each source (w)
% Concentration of contaminants in Waste Water Source (w,c)
CW=[100 500 500; 800 1750 2000; 400 80 100; 1200 1000 400; 500 700 250; 50 100 50; 1000 50 150];
% Regeneration Rate for Regeneration Processes (r,c)
RRate=[0.9 0.95 0; 0.875 0.5 0.5; 0.99 0.9 0.95; 0 0.75 0.75; 0.9 0.9 0.2;...
    0 0 0.95; 0 0.87 0.9; 0.995 0 0; 0.1 0.99 0; 0.7 0.2 0.3];
CLimit=[5 5 10]; % (s,c)
% Fixed Costs for utilising each Regeneration Process (r)
FRC=[48901 36676 13972 48901 48901 48901 36676 36676 13972 13972];
% Variable Costs for utilising each Regenertaion Process per unit flow (r)
VRC=[3860.3 2895.2 1102.9 3860.3 3860.3 3860.3 2895.2 2895.2 1102.9 1102.9];
% Distance Matrix
DWR=[40 65 75 100 120 110 150 210 280 245; 15 40 55 75 90 90 125 180 260 215;...
    40 35 30 65 100 85 115 170 240 220; 85 80 55 100 140 120 140 180 245 245; ...
    95 70 55 45 75 45 40 75 150 150; 80 70 40 90 125 100 120 150 230 230;...
    70 45 30 40 75 50 60 100 175 165]; % (w,r)
DRR=[0 20 40 50 70 70 100 160 230 190; 20 0 30 30 60 50 80 140 215 180;...
    40 30 0 40 80 60 80 140 210 190; 50 30 40 0 40 15 50 110 180 150;...
    70 60 80 40 0 25 50 110 180 120; 70 50 60 15 25 0 30 100 170 130;...
    100 80 80 50 50 30 0 60 130 100; 160 140 140 110 110 100 60 0 70 100;...
    230 215 210 180 180 170 130 70 0 110; 190 180 190 150 120 130 100 100 110 0];
% (r,r)
DWS=[150; 135; 100; 90; 40; 70; 45]; % (w,s)
DRS=[120; 95; 75; 85; 120; 90; 80; 95; 160; 190]; % (r,s)



D=NVAR;
for J=1:NVAR
    XRmin(1,J)=VLB(J);
    XRmax(1,J)=VUB(J);
end

Xbest_old=zeros(207,1);
Xbest_old(10)=20;Xbest_old(17)=50;Xbest_old(23)=47.5;Xbest_old(40)=28;Xbest_old(49)=100;Xbest_old(53)=30;Xbest_old(63)=25;
Xbest_old(134)=26.006;Xbest_old(139)=23.994;Xbest_old(152)=171.994;Xbest_old(167)=48;
Xbest_old(170)=300.5;

Xbest_old(196)=800;Xbest_old(197)=227.5;Xbest_old(198)=200;
Xbest_old(205)=222.5;Xbest_old(206)= 6.333333333333334e+002;Xbest_old(207)=3.091666666666666e+002;
Xbest_old(202)=4.179662081235392e+002;Xbest_old(203)=6.154786504180379;Xbest_old(204)=2.595369605916485e+002;
Xbest_old(184)=4.598751414309485;Xbest_old(185)=4.999983810316140;Xbest_old(186)=9.956738768718800;

% Local Optimizer: Active Set
options=...
optimset('Display','off','MaxFunEvals',1000000,'MaxIter',200000,...
         'TolFun',1e-1,'TolX',1e-1,'DiffMinChange',1e-5,'Algorithm','active-set');
[x,fval,exitflag,output] = fmincon(@WW_ObjFun,Xbest_old,[],[],[],[],XRmin,XRmax,@WW_FunCon,options);
 fval1=fval % for use if multiple local optimizers used
 
% % Local Opimizer: Interior Point
 options=...
 optimset('Display','off','MaxFunEvals',10000,'MaxIter',2000,...
          'TolFun',1e-1,'TolX',1e-1,'DiffMinChange',1e-10,'Algorithm','interior-point','FinDiffType','central');
 [x,fval,exitflag,output] = fmincon(@WW_ObjFun,Xbest_old,[],[],[],[],XRmin,XRmax,@WW_FunCon,options);
  fval2=fval % for use if multiple local optimizers used
% %
% Local Optimizer: SQP
optimset('Display','off','MaxFunEvals',1000000,'MaxIter',200000,...
         'TolFun',1e-1,'TolX',1e-1,'DiffMinChange',1e-5,'Algorithm','SQP');
[x,fval,exitflag,output] = fmincon(@WW_ObjFun,Xbest_old,[],[],[],[],XRmin,XRmax,@WW_FunCon,options);
fval3=fval
% % Local Optimizer: Central Active Set
 options=...
 optimset('Display','off','MaxFunEvals',100000,'MaxIter',20000,...
          'TolFun',1e-1,'TolX',1e-1,'Algorithm','active-set','FinDiffType','central');
 [x,fval,exitflag,output] = fmincon(@WW_ObjFun,Xbest_old,[],[],[],[],XRmin,XRmax,@WW_FunCon,options);
fval4=fval

Subject: [fmincon] help with options

From: Alan Weiss

Date: 15 Nov, 2011 15:42:18

Message: 3 of 8

On 11/15/2011 3:35 AM, Jason wrote:
> The main function code is as belows
>
***snip***
> % Local Optimizer: Active Set
> options=...
> optimset('Display','off','MaxFunEvals',1000000,'MaxIter',200000,...
> 'TolFun',1e-1,'TolX',1e-1,'DiffMinChange',1e-5,'Algorithm','active-set');
> [x,fval,exitflag,output] =
> fmincon(@WW_ObjFun,Xbest_old,[],[],[],[],XRmin,XRmax,@WW_FunCon,options); fval1=fval
> % for use if multiple local optimizers used
>
> % % Local Opimizer: Interior Point
> options=...
> optimset('Display','off','MaxFunEvals',10000,'MaxIter',2000,...
> 'TolFun',1e-1,'TolX',1e-1,'DiffMinChange',1e-10,'Algorithm','interior-point','FinDiffType','central');
> [x,fval,exitflag,output] =
> fmincon(@WW_ObjFun,Xbest_old,[],[],[],[],XRmin,XRmax,@WW_FunCon,options);
> fval2=fval % for use if multiple local optimizers used
> % % % Local Optimizer: SQP
> optimset('Display','off','MaxFunEvals',1000000,'MaxIter',200000,...
> 'TolFun',1e-1,'TolX',1e-1,'DiffMinChange',1e-5,'Algorithm','SQP');
> [x,fval,exitflag,output] =
> fmincon(@WW_ObjFun,Xbest_old,[],[],[],[],XRmin,XRmax,@WW_FunCon,options);
> fval3=fval
> % % Local Optimizer: Central Active Set options=...
> optimset('Display','off','MaxFunEvals',100000,'MaxIter',20000,...
> 'TolFun',1e-1,'TolX',1e-1,'Algorithm','active-set','FinDiffType','central');
>
> [x,fval,exitflag,output] =
> fmincon(@WW_ObjFun,Xbest_old,[],[],[],[],XRmin,XRmax,@WW_FunCon,options);
> fval4=fval

Without seeing your objective function, I cannot understand what you are
doing, or why you are using such large values of TolFun and TolX. If
this is an optimization among discrete choices, something that fmincon
does not really address, your objective function should at least
interpolate between adjacent values, not take discrete levels.

At this point I am just guessing. Can you tell us a bit about your
objective and nonlinear constraint functions?

Alan Weiss
MATLAB mathematical toolbox documentation

Subject: [fmincon] help with options

From: Jason

Date: 16 Nov, 2011 02:44:29

Message: 4 of 8

Alan Weiss <aweiss@mathworks.com> wrote in message
> Without seeing your objective function, I cannot understand what you are
> doing, or why you are using such large values of TolFun and TolX. If
> this is an optimization among discrete choices, something that fmincon
> does not really address, your objective function should at least
> interpolate between adjacent values, not take discrete levels.
>
> At this point I am just guessing. Can you tell us a bit about your
> objective and nonlinear constraint functions?
>
> Alan Weiss
> MATLAB mathematical toolbox documentation



This is my Objective Function




function TotalCost=WW_ObjFun(x)

global Ww Rr FRC VRC DWR DRR DWS DRS

FWR=[x(1) x(2) x(3) x(4) x(5) x(6) x(7) x(8) x(9) x(10);...
    x(11) x(12) x(13) x(14) x(15) x(16) x(17) x(18) x(19) x(20);...
    x(21) x(22) x(23) x(24) x(25) x(26) x(27) x(28) x(29) x(30);...
    x(31) x(32) x(33) x(34) x(35) x(36) x(37) x(38) x(39) x(40);...
    x(41) x(42) x(43) x(44) x(45) x(46) x(47) x(48) x(49) x(50);...
    x(51) x(52) x(53) x(54) x(55) x(56) x(57) x(58) x(59) x(60);...
    x(61) x(62) x(63) x(64) x(65) x(66) x(67) x(68) x(69) x(70)];
% Flow from Waste Sources to Waste Sinks (w,s)
FWS=[x(71); x(72); x(73); x(74); x(75); x(76); x(77)];
% Flow from Regeneration Processes to other Regneration Processes (r1-r2)
FRR=[0 x(78) x(79) x(80) x(81) x(82) x(83) x(84) x(85) x(86);
    x(87) 0 x(88) x(89) x(90) x(91) x(92) x(93) x(94) x(95);
    x(96) x(97) 0 x(98) x(99) x(100) x(101) x(102) x(103) x(104);
    x(105) x(106) x(107) 0 x(108) x(109) x(110) x(111) x(112) x(113);
    x(114) x(115) x(116) x(117) 0 x(118) x(119) x(120) x(121) x(122);
    x(123) x(124) x(125) x(126) x(127) 0 x(128) x(129) x(130) x(131);
    x(132) x(133) x(134) x(135) x(136) x(137) 0 x(138) x(139) x(140);
    x(141) x(142) x(143) x(144) x(145) x(146) x(147) 0 x(148) x(149);
    x(150) x(151) x(152) x(153) x(154) x(155) x(156) x(157) 0 x(158);
    x(159) x(160) x(161) x(162) x(163) x(164) x(165) x(166) x(167) 0];
% Flow from Regeneration Processes to Waste Sinks
FRS=[x(168); x(169); x(170); x(171); x(172); x(173); x(174); x(175); x(176); x(177)]; % (r,s

%----------------------- Objective Function -----------------------------
%-- Calculation of Costing Parameters--
% To caculate fixed and variable costs for flow from Waste to Regeneration
for w=1:Ww % for all Waste Sources
    for r=1:Rr % for all Regeneration Processes
        if FWR(w,r)>1e-4 % if there is flow from W to R(binary)
        FWRC(w,r)=124.6*DWR(w,r); % obtain fixed cost
        VWRC(w,r)=1.001*DWR(w,r); % obtain variable cost
        else FWRC(w,r)=0; % if no flow, cost is 0
             VWRC(w,r)=0;
        end % if
    end % for
end % for
% To caculate fixed and variable costs for flow from Waste to Sink
for w=1:Ww % for all Waste Sources
    if FWS(w,1)>1e-4 % if there is flow from W to S(binary)
       FWSC(w,1)=124.6*DWS(w,1); % obtain fixed cost
       VWSC(w,1)=1.001*DWS(w,1); % obtain variable cost
       else FWSC(w,1)=0; % if no flow, cost is 0
            VWSC(w,1)=0;
    end % if
end % for
% To caculate fixed and variable costs for flow from Regeneration to Regeneration
for r1=1:Rr % for all Regeneration Processes
    for r2=1:Rr % to all Regeneration Processes
        if FRR(r1,r2)>1e-4 % if there is flow from R to R(binary)
        FRRC(r1,r2)=124.6*DRR(r1,r2); % obtain fixed cost
        VRRC(r1,r2)=1.001*DRR(r1,r2); % obtain variable cost
        else FRRC(r1,r2)=0; % if no flow, cost is 0
             VRRC(r1,r2)=0;
        end % if
    end % for
end % for
% To caculate fixed and variable costs for flow from Regeneration to Sink
for r=1:Rr % for all Regeneration Processes
    if FRS(r,1)>1e-4 % if there is flow from R to R(binary)
    FRSC(r,1)=124.6*DRS(r,1); % obtain fixed cost
    VRSC(r,1)=1.001*DRS(r,1); % obtain variable cost
    else FRSC(r,1)=0; % if no flow, cost is 0
         VRSC(r,1)=0;
    end % if
end % for
%-- Objective Function--
% Waste Source to Regneration Process Cost
WRC=0;
for w=1:Ww % for all waste sinks
    for r=1:Rr % and for all regeneration processes
        WRC=WRC+FWRC(w,r)+VWRC(w,r)*FWR(w,r); % add in fixed cost and variable
                                              % cost * flow rate
    end % for r
end % for w
% Waste Source to Sink Cost
WSC=0;
for w=1:Ww
    WSC=WSC+FWSC(w,1)+VWSC(w,1)*FWS(w,1); % add in fixed cost and variable
                                              % cost * flow rate
end % for w
% Regeneration Process Operation Cost
RC=0;
for r1=1:Rr
    FR(r1)=0; % define flowrate out of regeneration process
    for r2=1:Rr % across all regen processes
        FR(r1)=FR(r1)+FRR(r1,r2); % sum flow to other regen
    end % for r3
    FR(r1)=FR(r1)+FRS(r1,1); % add flow to sink
    if FR(r1)>1e-4
        RC=RC+FRC(r1)+VRC(r1)*FR(r1);
    end
end
% Regeneration Process to Regneration Process Cost
RRC=0;
for r1=1:Rr
    for r2=1:Rr
        RRC=RRC+FRRC(r1,r2)+VRRC(r1,r2)*FRR(r1,r2); % add in fixed cost and varia
                                              % cost * flow rate
    end % for r1
end % for r2
% Regeneration Process to Sink Cost
RSC=0;
for r=1:Rr
    RSC=RSC+FRSC(r,1)+VRSC(r,1)*FRS(r,1); % add in fixed cost and variable
                                              % cost * flow rate
end % for w
TotalCost=WRC+WSC+RC+RRC+RSC;

Subject: [fmincon] help with options

From: Jason

Date: 16 Nov, 2011 02:46:29

Message: 5 of 8

Alan Weiss <aweiss@mathworks.com> wrote in message
> Without seeing your objective function, I cannot understand what you are
> doing, or why you are using such large values of TolFun and TolX. If
> this is an optimization among discrete choices, something that fmincon
> does not really address, your objective function should at least
> interpolate between adjacent values, not take discrete levels.
>
> At this point I am just guessing. Can you tell us a bit about your
> objective and nonlinear constraint functions?
>
> Alan Weiss
> MATLAB mathematical toolbox documentation

This are my Constraints. I initially used a very large TolX and TolFun because fmincon takes very long to obtain an answer. I have since changed that to 1e-3 for both but it still takes hours to reach the optimal. Any advice on choice of optimset?

Thank you




function [c,ceq]=WW_FunCon(x)

global Ww Rr Cc FW CW RRate CLimit
% Flow from Waste Sources to Regeneration Processes (w,r)
FWR=[x(1) x(2) x(3) x(4) x(5) x(6) x(7) x(8) x(9) x(10);...
    x(11) x(12) x(13) x(14) x(15) x(16) x(17) x(18) x(19) x(20);...
    x(21) x(22) x(23) x(24) x(25) x(26) x(27) x(28) x(29) x(30);...
    x(31) x(32) x(33) x(34) x(35) x(36) x(37) x(38) x(39) x(40);...
    x(41) x(42) x(43) x(44) x(45) x(46) x(47) x(48) x(49) x(50);...
    x(51) x(52) x(53) x(54) x(55) x(56) x(57) x(58) x(59) x(60);...
    x(61) x(62) x(63) x(64) x(65) x(66) x(67) x(68) x(69) x(70)];
% Flow from Waste Sources to Waste Sinks (w,s)
FWS=[x(71); x(72); x(73); x(74); x(75); x(76); x(77)];
% Flow from Regeneration Processes to other Regneration Processes (r1-r2)
FRR=[0 x(78) x(79) x(80) x(81) x(82) x(83) x(84) x(85) x(86);
    x(87) 0 x(88) x(89) x(90) x(91) x(92) x(93) x(94) x(95);
    x(96) x(97) 0 x(98) x(99) x(100) x(101) x(102) x(103) x(104);
    x(105) x(106) x(107) 0 x(108) x(109) x(110) x(111) x(112) x(113);
    x(114) x(115) x(116) x(117) 0 x(118) x(119) x(120) x(121) x(122);
    x(123) x(124) x(125) x(126) x(127) 0 x(128) x(129) x(130) x(131);
    x(132) x(133) x(134) x(135) x(136) x(137) 0 x(138) x(139) x(140);
    x(141) x(142) x(143) x(144) x(145) x(146) x(147) 0 x(148) x(149);
    x(150) x(151) x(152) x(153) x(154) x(155) x(156) x(157) 0 x(158);
    x(159) x(160) x(161) x(162) x(163) x(164) x(165) x(166) x(167) 0];
% Flow from Regeneration Processes to Waste Sinks
FRS=[x(168); x(169); x(170); x(171); x(172); x(173); x(174); x(175); x(176); x(177)]; % (r,s)
CRout=[x(178) x(179) x(180); x(181) x(182) x(183); x(184) x(185) x(186);
    x(187) x(188) x(189); x(190) x(191) x(192); x(193) x(194) x(195);
    x(196) x(197) x(198); x(199) x(200) x(201); x(202) x(203) x(204);
    x(205) x(206) x(207)];
% Outlet Concentration of Regeneration Processes (r,c)

%----------------------------- Constraints -------------------------------

%---- Equality Constraints ---
SumC=0;
%--- Mass Balances ---
%-- about Waste --
for w=1:Ww % for each waste source
    wasteflow=0; % define flowrate from waste source
    for r=1:Rr % sum across all regeneration for each source
        wasteflow=wasteflow+FWR(w,r); % total flowrate to all regeneration
    end % for r
    wasteflow=wasteflow+FWS(w,1); % total flowrate too regneration and sink
    Ce(w)=FW(w)-wasteflow; % total flowrate must be equal
    SumC=SumC+abs(Ce(w)); % add to overall constraint violation
end % for w
%-- about Regeneration --
for r1=1:Rr % for each Regeneration process
    regenflowin=0; % define flowrate into regeneration process
    for w=1:Ww % across all waste sources
        regenflowin=regenflowin+FWR(w,r1); % sum flow from waste to regen
    end % for w
    for r2=1:Rr % across all regen processes
        regenflowin=regenflowin+FRR(r2,r1); % sum flow from other regen
    end % for r2
    regenflowout=0; % define flowrate out of regeneration process
    for r3=1:Rr % across all regen processes
        regenflowout=regenflowout+FRR(r1,r3); % sum flow to other regen
    end % for r3
    regenflowout=regenflowout+FRS(r1,1);% add to flow to sink
    Ce(Ww+r1)=regenflowin-regenflowout; % flow in must equal flow out
    SumC=SumC+abs(Ce(Ww+r1)); % add to overall constraint violation
end % for r1

%-- Component Balances --
    
for c=1:Cc
    % Define Matrix for Mass Flow Rate of Contaminants
    for r1=1:Rr
        for r2=1:Rr
        ZRR(r1,r2,c)=FRR(r1,r2)*CRout(r1,c); % mass from r1 to r2 = flow from r1
                                         % to r2 * concentration of r1
        end % for r2
    end % for r1
end
for c=1:Cc
    % Obtain Mass Flow in of Contaminants
    for r1=1:Rr
        ZRin(r1,c)=0;
        for w=1:Ww
            ZRin(r1,c)=ZRin(r1,c)+CW(w,c)*FWR(w,r1);
        end % for w
        for r2=1:Rr
            ZRin(r1,c)=ZRin(r1,c)+ZRR(r2,r1,c);
        end % for r2
    end % for r1
    % Obtain Mass Flow out of Contaminants
    for r1=1:Rr
        ZRout(r1,c)=0;
        for r2=1:Rr
            ZRout(r1,c)=ZRout(r1,c)+ZRR(r1,r2,c);
        end % for r4
        ZRout(r1,c)=ZRout(r1,c)+FRS(r1,1)*CRout(r1,c);
    end % for r3
end % for c

%-- Component Balance about Regeneration Process --
for c=1:Cc
    for r=1:Rr
        Ce(Ww+Rr+r*c)=ZRout(r,c)-(1-RRate(r,c))*ZRin(r,c);
        SumC=SumC+abs(Ce(Ww+Rr+r*c));
    end % for r
end % for c


%---- Inequality Constraints ----
%--Discharge Limits--
for c=1:Cc
    ZSin=0;
    for w=1:Ww
        ZSin=ZSin+FWS(w,1)*CW(w,c);
    end
    for r=1:Rr
        ZSin=ZSin+FRS(r,1)*CRout(r,c);
    end
    ZSLimit=CLimit(1,c)*(sum(FWS)+sum(FRS));
    Ine(c)=(ZSin-ZSLimit);
    if Ine(c)>0
        SumC=SumC+Ine(c);
    end
end

%---Output Result as column vector-----
c=Ine';
ceq=Ce';
%-----End of Function----------

Subject: [fmincon] help with options

From: Alan Weiss

Date: 16 Nov, 2011 14:55:03

Message: 6 of 8

On 11/15/2011 9:46 PM, Jason wrote:
> Alan Weiss <aweiss@mathworks.com> wrote in message
>> Without seeing your objective function, I cannot understand what you
>> are doing, or why you are using such large values of TolFun and TolX.
>> If this is an optimization among discrete choices, something that
>> fmincon does not really address, your objective function should at
>> least interpolate between adjacent values, not take discrete levels.
>>
>> At this point I am just guessing. Can you tell us a bit about your
>> objective and nonlinear constraint functions?
>>
>> Alan Weiss
>> MATLAB mathematical toolbox documentation
>
> This are my Constraints. I initially used a very large TolX and TolFun
> because fmincon takes very long to obtain an answer. I have since
> changed that to 1e-3 for both but it still takes hours to reach the
> optimal. Any advice on choice of optimset?
>
> Thank you
>
>
>
>
> function [c,ceq]=WW_FunCon(x)
**snip**

Your problem looks to me like a linear programming problem, or at least
I think it could be modified slightly to become a linear programming
problem. I wonder if you can formulate your problem in the syntax that
linprog accepts. For some help in formulating the problem this way, see
the following:
http://www.mathworks.com/help/toolbox/optim/ug/bsmt5ib.html
Also, for help in formulating a binary constraint, see
http://www.mathworks.com/help/toolbox/optim/ug/brn4nmy.html

Alan Weiss
MATLAB mathematical toolbox documentation

Subject: [fmincon] help with options

From: Jason

Date: 18 Nov, 2011 02:06:08

Message: 7 of 8

Alan Weiss <aweiss@mathworks.com> wrote in message
>
> Your problem looks to me like a linear programming problem, or at least
> I think it could be modified slightly to become a linear programming
> problem. I wonder if you can formulate your problem in the syntax that
> linprog accepts. For some help in formulating the problem this way, see
> the following:
> http://www.mathworks.com/help/toolbox/optim/ug/bsmt5ib.html
> Also, for help in formulating a binary constraint, see
> http://www.mathworks.com/help/toolbox/optim/ug/brn4nmy.html
>
> Alan Weiss
> MATLAB mathematical toolbox documentation

Hi,

Thank you for your help! My problem is a nonlinear problem and cannot be linearized. I'm actually working on solving non-linear problems. I have found that my bounds were previously incorrect and thereafter, this setting works, but TolFun and TolX needs to be this high or fmincon will take very long.
options=...
optimset('Display','off','MaxFunEvals',100000,'MaxIter',20000,...
         'TolFun',1e-3,'TolX',1e-3,'DiffMinChange',1e-5,'Algorithm','active-set');
[x,fval,exitflag,output] = fmincon(@WW_ObjFun,Xbest_old,[],[],[],[],XRmin,XRmax,@WW_FunCon,options);
 fval1=fval



Additionally, these two do not work. Is there any advice on the choice of optimset that you can give me?


% options=...
% optimset('Display','off','MaxFunEvals',10000,'MaxIter',2000,...
% 'TolFun',1e-10,'TolX',1e-10,'DiffMinChange',1e-10,'Algorithm','interior-point','FinDiffType','central');
% [x,fval,exitflag,output] = fmincon(@WW_ObjFun,x,[],[],[],[],XRmin,XRmax,@WW_FunCon,options);
% x2=fval % for use if multiple lcoal optimizers used
% %
% % Local Optimizer: Central Active Set
% options=...
% optimset('Display','off','MaxFunEvals',100000,'MaxIter',20000,...
% 'TolFun',1e-10,'TolX',1e-10,'Algorithm','active-set','FinDiffType','central');
% [x,fval,exitflag,output] = fmincon(@WW_ObjFun,x,[],[],[],[],XRmin,XRmax,@WW_FunCon,options);

Subject: [fmincon] help with options

From: Alan Weiss

Date: 18 Nov, 2011 15:44:36

Message: 8 of 8

On 11/17/2011 9:06 PM, Jason wrote:
> Alan Weiss <aweiss@mathworks.com> wrote in message
>>
>> Your problem looks to me like a linear programming problem, or at
>> least I think it could be modified slightly to become a linear
>> programming problem. I wonder if you can formulate your problem in the
>> syntax that linprog accepts. For some help in formulating the problem
>> this way, see the following:
>> http://www.mathworks.com/help/toolbox/optim/ug/bsmt5ib.html
>> Also, for help in formulating a binary constraint, see
>> http://www.mathworks.com/help/toolbox/optim/ug/brn4nmy.html
>>
>> Alan Weiss
>> MATLAB mathematical toolbox documentation
>
> Hi,
>
> Thank you for your help! My problem is a nonlinear problem and cannot be
> linearized. I'm actually working on solving non-linear problems. I have
> found that my bounds were previously incorrect and thereafter, this
> setting works, but TolFun and TolX needs to be this high or fmincon will
> take very long.
> options=...
> optimset('Display','off','MaxFunEvals',100000,'MaxIter',20000,...
> 'TolFun',1e-3,'TolX',1e-3,'DiffMinChange',1e-5,'Algorithm','active-set');
> [x,fval,exitflag,output] =
> fmincon(@WW_ObjFun,Xbest_old,[],[],[],[],XRmin,XRmax,@WW_FunCon,options);
> fval1=fval
>
>
> Additionally, these two do not work. Is there any advice on the choice
> of optimset that you can give me?
>
>
> % options=...
> % optimset('Display','off','MaxFunEvals',10000,'MaxIter',2000,...
> %
> 'TolFun',1e-10,'TolX',1e-10,'DiffMinChange',1e-10,'Algorithm','interior-point','FinDiffType','central');
> % [x,fval,exitflag,output] =
> fmincon(@WW_ObjFun,x,[],[],[],[],XRmin,XRmax,@WW_FunCon,options);
> % x2=fval % for use if multiple lcoal optimizers used
> % % % % Local Optimizer: Central Active Set % options=...
> % optimset('Display','off','MaxFunEvals',100000,'MaxIter',20000,...
> %
> 'TolFun',1e-10,'TolX',1e-10,'Algorithm','active-set','FinDiffType','central');
>
> % [x,fval,exitflag,output] =
> fmincon(@WW_ObjFun,x,[],[],[],[],XRmin,XRmax,@WW_FunCon,options);

I am afraid that your objective function is not smooth, so you really
cannot expect fmincon to work well. Your objective has lines such as

    for r=1:Rr % for all Regeneration Processes
        if FWR(w,r)>1e-4 % if there is flow from W to R(binary)
        FWRC(w,r)=124.6*DWR(w,r); % obtain fixed cost
        VWRC(w,r)=1.001*DWR(w,r); % obtain variable cost
        else FWRC(w,r)=0; % if no flow, cost is 0
             VWRC(w,r)=0;
        end % if
    end % for

The inclusion of a fixed cost means that the objective can jump when
there is a small change in an input. fmincon is not designed to solve
this type of problem.

If you find that the active-set algorithm sometimes works, you are not
alone (there have been other reported successes with fmincon on
nonsmooth problems). But I have no advice on tuning options for
nonsmooth problems with fmincon.

Perhaps this link can give you some ideas on formulating your problem
without incorporating jumps:
http://www.mathworks.com/help/toolbox/optim/ug/brn4nmy.html

Good luck,

Alan Weiss
MATLAB mathematical toolbox documentation

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us