Does anyone know how to get the values of the variables?

조회 수: 2 (최근 30일)
Hossam Mosbah
Hossam Mosbah 2021년 3월 3일
댓글: Alan Weiss 2021년 3월 3일
I implemented the optimization problem below and I want to know the optimal values for c, P_shave, P_ess, soc, and P_grid. These are variables but I need to get the optimal values.
%***************************************************************************************************************
p=[250;227;206;220;197;203;210;191;353;464;518;544;588;565;562;606;576;494;409;322;301;288;268;228];
T=24;
w_1=0.5;
w_2=500;
w_3=0.015;
w_4=0.0008;
P_max=max(p);
soc_min=0.1;
soc_max=0.9;
E_c=120;
ESS_Cmax=120;
alpha=3;
sigma=0.95;
P_peak=100*ones(24,1); % tunning parameter
%***********************************************************************************************************************
c= optimvar('c');
P_shave = optimvar('P_shave',T);
P_ess = optimvar('P_ess',T);
soc = optimvar('soc',T,'LowerBound',0,'UpperBound',ESS_Cmax);
P_grid = optimvar('P_grid',T);
prob = optimproblem;
%************************************************************************************************************************
prob.Objective =sum(w_1*c*(P_shave-P_ess)+ w_2*(soc-soc(T-1)).^2+w_3*(P_grid-P_peak).^2+w_4*(P_ess-P_ess(T-1)).^2);
%*************************************************************************************************************************
prob.Constraints.cons1 = P_grid== p+P_ess;
prob.Constraints.cons2 = P_grid >= 0;
% constraint #3
if p >= P_peak
P_shave=p-P_peak;
else
P_shave=0;
end
prob.Constraints.cons5 = P_shave+P_ess >= 0;
prob.Constraints.cons6 =soc== soc(T-1)+(sigma./alpha)*P_ess;
prob.Constraints.cons7 = P_ess>=-P_max;
prob.Constraints.cons8 = P_ess <= -P_max;
prob.Constraints.cons9 = soc >= soc_min;
prob.Constraints.cons10 = soc <= soc_max;
prob.Constraints.cons11 = alpha>= P_ess;
prob.ObjectiveSense = 'minimize';
options = optimoptions(prob,'Algorithm','active-set')
% sol = solve(prob)
**********************************************************
options =
quadprog options:
Options used by current Algorithm ('active-set'):
(Other available algorithms: 'interior-point-convex', 'trust-region-reflective')
Set properties:
Algorithm: 'active-set'
Default properties:
ConstraintTolerance: 1.0000e-08
Display: 'final'
MaxIterations: '10*(numberOfVariables + numberOfConstraints)'
ObjectiveLimit: -1.0000e+20
OptimalityTolerance: 1.0000e-08
StepTolerance: 1.0000e-08
Show options not used by current Algorithm ('active-set')

채택된 답변

Alan Weiss
Alan Weiss 2021년 3월 3일
Well, you have to solve the problem first by calling solve, as in your commented-out last line.
Then you will have a solution structure sol and you can examine, for example, sol.c and sol.P_shave and any other variable value in the solution.
Alan Weiss
MATLAB mathematical toolbox documentation
  댓글 수: 2
Hossam Mosbah
Hossam Mosbah 2021년 3월 3일
I appreciate your comment. But this is what happened when i use solve (prob)
**********************************************************************************************************
Solving problem using quadprog.
Your Hessian is not symmetric. Resetting H=(H+H')/2.
The problem is infeasible.
During presolve, quadprog found the constraints to be inconsistent
to within the constraint tolerance.
sol =
struct with fields:
P_ess: []
P_grid: []
P_shave: []
c: []
soc: []
Any recomandations would be highly appreciated.
Alan Weiss
Alan Weiss 2021년 3월 3일
Well, your problem is infeasible. Your constraints cannot all be met.
I suggest that you investigate why. Give a set of values that you think should be feasible and then see which of the constraints are violated. For example,
x0.P_shave = ones(T,1);
x0.P_ess = 2*ones(T,1);
% etc., with your values here, not just ones
infeas1 = infeasibility(prob.Constraints.cons1,x0);
infeas2 = infeasibility(prob.Constraints.cons2,x0);
% etc. See where the constraints are not met.
Then you can see whether your problem formulation is incorrect.
Alan Weiss
MATLAB mathematical toolbox documentation

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by