Tricky restriction in an optimization problem

조회 수: 4 (최근 30일)
I will keep the question as general as possible.
I am solving a system of differential-algebraic equations with ode15s and I have an optimization problem, for which I employ the fmincon function. Consider that some parameters of the DAE's will maximize an objective function. This one happens to be the integral of one of the integrated variables across time, say y(17). Thus, we can use the trapz function to calculate the objective function
obj_function = trapz(t, y(:, 17)) % Output of the function given to fmincon
Now comes the tricky part. fmincon can place some restrictions but I want the following one. I would like that, after solving the DAE's, an integral of, consider for example the 4th output variable of the solver y(4) across time is bounded. So we would write
restriction = trapz(t, y(:, 4)); % Restriction that can be calculated only after ode15s is done
And I would like that restriction was bounded, e.g., that it was between 1 and 2.
Is it possible to add this type of restriction so that the parameters to be optimized within fmincon, move as to (1) minimize the objective function, but also (2) keep restriction between said bounds?
Thanks in advance.

채택된 답변

Mrutyunjaya Hiremath
Mrutyunjaya Hiremath 2023년 8월 17일
'fmincon' is equipped to handle such constraints by accepting a function that provides both equality and inequality constraints. In your case, you want an inequality constraint that keeps the restriction (integral of y(4)) within certain bounds.
Let's break it down:
  1. Objective Function: This remains the same. It would be a function that returns:
  2. Nonlinear Constraints: You'd create another function, say 'myConstraints', that when given the same inputs as your objective function, returns: This is the upper bound. This is the lower bound.
Where c should be less than or equal to 0 for the optimization constraints to be satisfied.
Let's draft the constraints function:
function [c, ceq] = myConstraints(parameters)
% Solve the DAE using the given parameters
% Assuming the DAE's are solved using a function named solveDAE
[t, y] = solveDAE(parameters);
% Inequality constraints
c(1) = trapz(t, y(:, 4)) - 2;
c(2) = 1 - trapz(t, y(:, 4));
% No equality constraints
ceq = [];
end
Call to fmincon:
x0 = initial_parameters; % starting point
A = []; b = []; % No linear inequality constraints
Aeq = []; beq = []; % No linear equality constraints
lb = lower_bounds; % Lower bounds on parameters
ub = upper_bounds; % Upper bounds on parameters
nonlcon = @myConstraints; % Nonlinear constraints function
[x_optimal, fval] = fmincon(@objectiveFunction, x0, A, b, Aeq, beq, lb, ub, nonlcon);
Where 'objectiveFunction' is another function similar to 'myConstraints' but only returns the value of 'obj_function'.
With this, fmincon will optimize your parameters such that the integral of y(17) is minimized while ensuring that the integral of y(4) remains between 1 and 2.
  댓글 수: 5
Bruno Luong
Bruno Luong 2023년 8월 17일
AI surprises me from day to day, but no @Mrutyunjaya Hiremath answer is too good to be AI generated IMO.
I posted much shorter answer but I deleted since @Mrutyunjaya Hiremath answer is much elaborated and helpful.
Julio Maximiliano Ramirez Oyanarte
@Mrutyunjaya Hiremath Thanks for the great response, really sorry for doubting of the AI response, but it was so fast and good.. Also, @Bruno Luong thanks for the information!

댓글을 달려면 로그인하십시오.

추가 답변 (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