Using different solvers in Optimization Problem
显示 更早的评论
Hi,
I am using problem based optimization problem and i am getting same optimized values for ga, patternsearch and particle swarm .but time taken is different.
Please advice what could be the mistake
采纳的回答
If you are getting exactly the same results, then there are a few possibilities:
- you might have a mistake in your equation implementation that causes it to return the same values all of the time;
- you might have a mistake in how you specify the solver, causing it to always be set the same;
- you might have specified options such as integer constraints that are leading Problem Based Solver to override your solver request because the other solvers cannot handle the options / request
If you are getting the same results to within round-off error but not bit-for-bit identical:
- you might be using a simple linear equation or quadratic equation; all of the functions should converge for those kinds of function
- the result you are getting might be right at one of the constraint boundaries, so all of the solvers might end up at much the same solution
12 个评论
% Minimise the cost of power
prob.ObjectiveSense = 'minimize';
prob.Objective =dt *Cost'*PESSV;
showproblem(prob)
options = optimoptions('ga',prob.optimoptions,'Display','iter');
%options = optimoptions('patternsearch',prob.optimoptions,'Display','iter');
%options = optimoptions('ga',prob.optimoptions,'Display','iter');
%options = optimoptions(aprticleswarm',prob.optimoptions,'Display','iter');
[values,~,exitflag] = solve(prob,'Options',options);
fval = evaluate(prob.Objective,values);
Kindly review this code and plz let me know if there is a correction.
I have specified my constraints as below:
% Satisfy power load with power from PV, grid and ESS
prob.Constraints.loadBalance = Ppv + windV+ PgridV + PESSV == Pload;
prob.Constraints.grid = PgridV <=3e6;
prob.Constraints.solar = Ppv <=1e6;
Can you post your complete code for testing ?
function [Pgrid,Pess,Eess] = battSolarOptimizetrial3(N,dt,Ppv,Pwind,Pload,Einit,Cost,FinalWeight,batteryMinMax)
% Minimize the cost of power from the grid
prob = optimproblem;
% Decision variables
PgridV = optimvar('PgridV',N);
PessV = optimvar('PesssV',N,'LowerBound',batteryMinMax.Pmin,'UpperBound',batteryMinMax.Pmax);
EessV = optimvar('EesssV',N,'LowerBound',batteryMinMax.Emin,'UpperBound',batteryMinMax.Emax);
% Maximise the profit from the usage of battery and PV
prob.ObjectiveSense = 'minimize';
prob.Objective =dt *Cost'*PessV;
% Satisfy power load with power from PV, grid and battery
prob.Constraints.loadBalance = Ppv + Pwind+ PgridV + PessV == Pload;
prob.Constraints.grid = PgridV <=3e6;
prob.Constraints.solar = Ppv <=1e6;
showproblem(prob)
options = optimoptions('ga',prob.optimoptions,'Display','iter');
[values,~,exitflag] = solve(prob,'Options',options);
fval = evaluate(prob.Objective,values);
tb1=struct2table(values)
% Parse optmization results
if exitflag <= 0
Pgrid = zeros(N,1);
Pess = zeros(N,1);
Eess = zeros(N,1);
else
Pgrid = values.PgridV;
Pess = values.PessV;
Eess = values.EessV;
end
- you might have a mistake in how you specify the solver, causing it to always be set the same;--- I just changed the solver name in the solve command below:
options = optimoptions('ga',prob.optimoptions,'Display','iter');
- you might have specified options such as integer constraints that are leading Problem Based Solver to override your solver request because the other solvers cannot handle the options / request
How do i correct it without modifying the constraints?what is the possible solution ?
Please let me know what it means by moving the comment
You posted content as an Answer, but the content was not a solution to your question and was instead a reply to what I had posted. I used moderation facilities to move your content to be a Comment rather than an Answer
Ok Now understood I was actually asking what is the solution Please let me know if there are any solution after reviewing the code.
I haven't had time to test it yet.
Ok, please check if you are free .
When i used patternsearch, i got a warning like below:
You have passed PATTERNSEARCH options to LINPROG. LINPROG will use the common options and ignore the PATTERNSEARCH options that do not apply.
To avoid this warning, convert the PATTERNSEARCH options using OPTIMOPTIONS.
Hi,
Can you please chekc on the above problem and suggest a solution please
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Surrogate Optimization 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
