How can I set a goal as constraint in optimization
3 views (last 30 days)
Show older comments
I have a vector X of 408 road gradients (decision variables) that I am trying to optimize to minimize slope variability while limiting Fuel Consumption to a certain value (fraction of the initial Fuel Consumption). I did it with Excel, but takes a lot of time with less post processing capabilities and easiness. The problem is as follow: The starting point x0 is the 408 road gradients (G) already converted (the percent % is calculated as G./100). For each gradient, I have a corresponding length in meter stored in vector L. The corresponding Fuel Consumption (at fixed speed) is given as a vector of Factors (FCfac) for a set of gradients (Slope). For brevity, I provide only Slope and FCfac (see below). The problem has 2 type of constraints which are bounds and equalities. All constraints are linear!
G = Gradients; L = Distances; x0 = G; N = length(G); Slope = -6/100:2/100:6/100; FCfac = [3,3.5,20,200,500,800,1000];
I derive some other variables of interest as follow: VP = L.*G; El = cumsum(VP); % To obtain the elevation for the initial alignment (the one to optimize) M = Length(FCfac); TotFCinit = sum(L.*(interp1(Slope ,FCfac,G,'pchip'))); % Total fuel consumption with initial alignment.
Constraints s = 6/100; 1) -s <= X <= s % The lower and upper bounds. 2) The First elevation in optimizied alignment must be the same as in the initial one. 3) The last elevation in the optimized alignment must be the same as in the initial one. 4) TotFCnew = Lambda*TotFCinit;
TotFCnew would be calculated as sum(L.*(interp1(Slope ,FCfac,X,'pchip'))).
This is what I cannot add in the Aeq and beq matrices sinces I am using interp1 to extract corresponding Factors, multiply by distance and sum them!!! How can I formulate it? The rest are: LB = -s*ones(N,1); UB = s*ones(N,1); Aeq = zeros(2,N); Aeq(1,1) = L(1); Aeq(end,end) = L(end); beq = zeros(2,1); beq(1) = El(1); beq(2) = El(end);
Modeling objFun I used symbolic math toolbox to model my objective function X = sym('x',[N,1]); % Road Gradients (expected) S = sym('s',[N,1]); % Initial road gradients I proceed as follow: DeltaSlope = (S - X).^2; % Difference between the initial and expected gradients TotDelta = sum(DeltaSlope); % Overall difference
Then I substitue to obtain a function of x only, and create a function handle as follow: TotDelta = subs(TotDelta,S,G); matlabFunction(TotDelta,'vars',{X},'file','objFcn');
Lastly I call the optimization routine as follow: options = optimset('MaxFunEvals',Inf,'MaxIter',5000,... 'Algorithm','interior-point','Display','iter'); tic [xopt, fval] = fmincon(@objFcn,x0,[],[],Aeq,beq,LB,UB,[],options); toc
IF fixing fuel consumption with the new (xopt) is not possible, how can I set it as a second objfun knowing that I am using interp1? Other ideas?
Thanks a lot.
0 Comments
Answers (0)
See Also
Categories
Find more on Linear Programming and Mixed-Integer Linear Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!