Does anyone know how to get the values of the variables?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hossam Mosbah
il 3 Mar 2021
Commentato: Alan Weiss
il 3 Mar 2021
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/537571/image.png)
%***************************************************************************************************************
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')
0 Commenti
Risposta accettata
Alan Weiss
il 3 Mar 2021
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 Commenti
Alan Weiss
il 3 Mar 2021
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
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Get Started with Optimization Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!