How can I solve the error: (linprog): Length of lower bounds l is too long; ignoring extra bounds
P_t_pv = ones(1, 24);
P_tmin_pv = ones(1, 24);
P_t_el = ones(1, 24);
P_t_hl = ones(1, 24);
P_tmin_cl = ones(1, 24);
P_tmax_cl = ones(1, 24);
P_t_net5 = optimvar("P_t_net",1,24,"LowerBound",0);
P_gt_CHP5 = optimvar("P_gt_CHP",1,24,"LowerBound",0);
P_t_cha5 = optimvar("P_t_cha",1,24,"LowerBound",0,"UpperBound",50);
P_t_dis5 = optimvar("P_t_dis",1,24,"LowerBound",0,"UpperBound",50);
u_t_cha5 = optimvar("u_t_cha",1,24,"Type","integer","LowerBound",0,…
"UpperBound",1);
u_t_dis5 = optimvar("u_t_dis",1,24,"Type","integer","LowerBound",0,…
"UpperBound",1);
P_et_EB5 = optimvar("P_et_EB",1,24,"LowerBound",0);
P_et_EC5 = optimvar("P_et_EC",1,24,"LowerBound",0);
P_ht_AC5 = optimvar("P_ht_AC",1,24,"LowerBound",0);
P_gt_GB5 = optimvar("P_gt_GB",1,24,"LowerBound",0);
E_t_f5 = optimvar("E_t_f",1,24,"LowerBound",0);
dP_t_pv5 = optimvar("dP_t_pv",1,24,"LowerBound",0);
dP_t_el5 = optimvar("dP_t_el",1,24,"LowerBound",0);
dP_t_hl5 = optimvar("dP_t_hl",1,24,"LowerBound",0);
dP_t_cl5 = optimvar("dP_t_cl",1,24,"LowerBound",0);
% 设置求解器的初始起点
initialPoint5.P_t_net = zeros(size(P_t_net5));
initialPoint5.P_gt_CHP = zeros(size(P_gt_CHP5));
initialPoint5.P_t_cha = zeros(size(P_t_cha5));
initialPoint5.P_t_dis = zeros(size(P_t_dis5));
initialPoint5.u_t_cha = zeros(size(u_t_cha5));
initialPoint5.u_t_dis = zeros(size(u_t_dis5));
initialPoint5.P_et_EB = zeros(size(P_et_EB5));
initialPoint5.P_et_EC = zeros(size(P_et_EC5));
initialPoint5.P_ht_AC = zeros(size(P_ht_AC5));
initialPoint5.P_gt_GB = zeros(size(P_gt_GB5));
initialPoint5.E_t_f = zeros(size(E_t_f5));
initialPoint5.dP_t_pv = zeros(size(dP_t_pv5));
initialPoint5.dP_t_el = zeros(size(dP_t_el5));
initialPoint5.dP_t_hl = zeros(size(dP_t_hl5));
initialPoint5.dP_t_cl = zeros(size(dP_t_cl5));
% 创建问题
problem = optimproblem;
% 定义问题目标
problem.Objective = fcn2optimexpr(@objectiveFcn,P_t_net5,P_gt_CHP5,P_t_cha5,…
P_et_EB5,P_et_EC5,P_ht_AC5,P_gt_GB5,E_t_f5,dP_t_pv5,dP_t_el5,dP_t_hl5,dP_t_cl5);
% 定义问题约束
problem.Constraints.constraint1 = P_t_net5+0.38*P_gt_CHP5+P_t_pv-dP_t_pv5 == P_t_el-dP_t_el5+P_et_EB5+P_et_EC5+P_t_cha5;
problem.Constraints.constraint2 = P_gt_CHP5*0.45+P_gt_GB5*0.95+P_et_EB5*0.98 == P_t_hl+P_ht_AC5-dP_t_hl5;
problem.Constraints.constraint3 = P_ht_AC5*1.1+P_et_EC5*3.1 >= P_tmin_cl-dP_t_cl5;
problem.Constraints.constraint4 = P_ht_AC5*1.1+P_et_EC5*3.1 <= P_tmax_cl;
problem.Constraints.constraint5 = 0.38*P_gt_CHP5 <= 300 * ones(1, 24);
problem.Constraints.constraint6 = (circshift(P_gt_CHP5,…
1) – P_gt_CHP5) * 0.38 <= ones(1, 24) * 65;
problem.Constraints.constraint7 = (circshift(P_gt_CHP5,…
-1) – P_gt_CHP5) * 0.38 <= ones(1, 24) * 85;
problem.Constraints.constraint8 = P_t_cha5 <= u_t_cha5 .* 50;
problem.Constraints.constraint9 = P_t_dis5 <= u_t_dis5 .* 50;
problem.Constraints.constraint10 = u_t_cha5 + u_t_dis5 <= ones(1, 24);
% 设置非默认求解器选项
options5 = optimoptions("ga","Display","iter","PlotFcn",["gaplotscores",…
"gaplotbestf","gaplotbestindiv","gaplotexpectation","gaplotrange"]);
% 求解问题
[solution,objectiveValue] = solve(problem,initialPoint5,"Solver","ga",…
"Options",options5);
% 显示结果
solution
objectiveValue
the output is:
将使用 ga 求解问题。
ERROR – (linprog): Incorrect number of columns in A (inequalities)
ERROR – (linprog): Incorrect number of columns in B (equalities)
警告: (linprog): Length of lower bounds l is too long; ignoring extra bounds
警告: (linprog): Length of upper bounds u is too long; ignoring extra bounds
Output argument "x" (and possibly others) not assigned a value in the execution with "linprog" function.
出错 globaloptim.internal.preProcessLinearConstr (第 166 行)
[XOUT,~,success] = linprog([],Aineq,Bineq,Aeq,Beq,LB,UB, …
出错 gacommon (第 150 行)
globaloptim.internal.preProcessLinearConstr(Iterate.x,Aineq,bineq, …
出错 ga (第 377 行)
NonconFcn,options,Iterate,type] = gacommon(nvars,fun,Aineq,bineq,Aeq,beq,lb,ub, …
出错 optim.problemdef.OptimizationProblem/callSolver
出错 optim.internal.problemdef.ProblemImpl/solveImpl
出错 optim.problemdef.OptimizationProblem/solveP_t_pv = ones(1, 24);
P_tmin_pv = ones(1, 24);
P_t_el = ones(1, 24);
P_t_hl = ones(1, 24);
P_tmin_cl = ones(1, 24);
P_tmax_cl = ones(1, 24);
P_t_net5 = optimvar("P_t_net",1,24,"LowerBound",0);
P_gt_CHP5 = optimvar("P_gt_CHP",1,24,"LowerBound",0);
P_t_cha5 = optimvar("P_t_cha",1,24,"LowerBound",0,"UpperBound",50);
P_t_dis5 = optimvar("P_t_dis",1,24,"LowerBound",0,"UpperBound",50);
u_t_cha5 = optimvar("u_t_cha",1,24,"Type","integer","LowerBound",0,…
"UpperBound",1);
u_t_dis5 = optimvar("u_t_dis",1,24,"Type","integer","LowerBound",0,…
"UpperBound",1);
P_et_EB5 = optimvar("P_et_EB",1,24,"LowerBound",0);
P_et_EC5 = optimvar("P_et_EC",1,24,"LowerBound",0);
P_ht_AC5 = optimvar("P_ht_AC",1,24,"LowerBound",0);
P_gt_GB5 = optimvar("P_gt_GB",1,24,"LowerBound",0);
E_t_f5 = optimvar("E_t_f",1,24,"LowerBound",0);
dP_t_pv5 = optimvar("dP_t_pv",1,24,"LowerBound",0);
dP_t_el5 = optimvar("dP_t_el",1,24,"LowerBound",0);
dP_t_hl5 = optimvar("dP_t_hl",1,24,"LowerBound",0);
dP_t_cl5 = optimvar("dP_t_cl",1,24,"LowerBound",0);
% 设置求解器的初始起点
initialPoint5.P_t_net = zeros(size(P_t_net5));
initialPoint5.P_gt_CHP = zeros(size(P_gt_CHP5));
initialPoint5.P_t_cha = zeros(size(P_t_cha5));
initialPoint5.P_t_dis = zeros(size(P_t_dis5));
initialPoint5.u_t_cha = zeros(size(u_t_cha5));
initialPoint5.u_t_dis = zeros(size(u_t_dis5));
initialPoint5.P_et_EB = zeros(size(P_et_EB5));
initialPoint5.P_et_EC = zeros(size(P_et_EC5));
initialPoint5.P_ht_AC = zeros(size(P_ht_AC5));
initialPoint5.P_gt_GB = zeros(size(P_gt_GB5));
initialPoint5.E_t_f = zeros(size(E_t_f5));
initialPoint5.dP_t_pv = zeros(size(dP_t_pv5));
initialPoint5.dP_t_el = zeros(size(dP_t_el5));
initialPoint5.dP_t_hl = zeros(size(dP_t_hl5));
initialPoint5.dP_t_cl = zeros(size(dP_t_cl5));
% 创建问题
problem = optimproblem;
% 定义问题目标
problem.Objective = fcn2optimexpr(@objectiveFcn,P_t_net5,P_gt_CHP5,P_t_cha5,…
P_et_EB5,P_et_EC5,P_ht_AC5,P_gt_GB5,E_t_f5,dP_t_pv5,dP_t_el5,dP_t_hl5,dP_t_cl5);
% 定义问题约束
problem.Constraints.constraint1 = P_t_net5+0.38*P_gt_CHP5+P_t_pv-dP_t_pv5 == P_t_el-dP_t_el5+P_et_EB5+P_et_EC5+P_t_cha5;
problem.Constraints.constraint2 = P_gt_CHP5*0.45+P_gt_GB5*0.95+P_et_EB5*0.98 == P_t_hl+P_ht_AC5-dP_t_hl5;
problem.Constraints.constraint3 = P_ht_AC5*1.1+P_et_EC5*3.1 >= P_tmin_cl-dP_t_cl5;
problem.Constraints.constraint4 = P_ht_AC5*1.1+P_et_EC5*3.1 <= P_tmax_cl;
problem.Constraints.constraint5 = 0.38*P_gt_CHP5 <= 300 * ones(1, 24);
problem.Constraints.constraint6 = (circshift(P_gt_CHP5,…
1) – P_gt_CHP5) * 0.38 <= ones(1, 24) * 65;
problem.Constraints.constraint7 = (circshift(P_gt_CHP5,…
-1) – P_gt_CHP5) * 0.38 <= ones(1, 24) * 85;
problem.Constraints.constraint8 = P_t_cha5 <= u_t_cha5 .* 50;
problem.Constraints.constraint9 = P_t_dis5 <= u_t_dis5 .* 50;
problem.Constraints.constraint10 = u_t_cha5 + u_t_dis5 <= ones(1, 24);
% 设置非默认求解器选项
options5 = optimoptions("ga","Display","iter","PlotFcn",["gaplotscores",…
"gaplotbestf","gaplotbestindiv","gaplotexpectation","gaplotrange"]);
% 求解问题
[solution,objectiveValue] = solve(problem,initialPoint5,"Solver","ga",…
"Options",options5);
% 显示结果
solution
objectiveValue
the output is:
将使用 ga 求解问题。
ERROR – (linprog): Incorrect number of columns in A (inequalities)
ERROR – (linprog): Incorrect number of columns in B (equalities)
警告: (linprog): Length of lower bounds l is too long; ignoring extra bounds
警告: (linprog): Length of upper bounds u is too long; ignoring extra bounds
Output argument "x" (and possibly others) not assigned a value in the execution with "linprog" function.
出错 globaloptim.internal.preProcessLinearConstr (第 166 行)
[XOUT,~,success] = linprog([],Aineq,Bineq,Aeq,Beq,LB,UB, …
出错 gacommon (第 150 行)
globaloptim.internal.preProcessLinearConstr(Iterate.x,Aineq,bineq, …
出错 ga (第 377 行)
NonconFcn,options,Iterate,type] = gacommon(nvars,fun,Aineq,bineq,Aeq,beq,lb,ub, …
出错 optim.problemdef.OptimizationProblem/callSolver
出错 optim.internal.problemdef.ProblemImpl/solveImpl
出错 optim.problemdef.OptimizationProblem/solve P_t_pv = ones(1, 24);
P_tmin_pv = ones(1, 24);
P_t_el = ones(1, 24);
P_t_hl = ones(1, 24);
P_tmin_cl = ones(1, 24);
P_tmax_cl = ones(1, 24);
P_t_net5 = optimvar("P_t_net",1,24,"LowerBound",0);
P_gt_CHP5 = optimvar("P_gt_CHP",1,24,"LowerBound",0);
P_t_cha5 = optimvar("P_t_cha",1,24,"LowerBound",0,"UpperBound",50);
P_t_dis5 = optimvar("P_t_dis",1,24,"LowerBound",0,"UpperBound",50);
u_t_cha5 = optimvar("u_t_cha",1,24,"Type","integer","LowerBound",0,…
"UpperBound",1);
u_t_dis5 = optimvar("u_t_dis",1,24,"Type","integer","LowerBound",0,…
"UpperBound",1);
P_et_EB5 = optimvar("P_et_EB",1,24,"LowerBound",0);
P_et_EC5 = optimvar("P_et_EC",1,24,"LowerBound",0);
P_ht_AC5 = optimvar("P_ht_AC",1,24,"LowerBound",0);
P_gt_GB5 = optimvar("P_gt_GB",1,24,"LowerBound",0);
E_t_f5 = optimvar("E_t_f",1,24,"LowerBound",0);
dP_t_pv5 = optimvar("dP_t_pv",1,24,"LowerBound",0);
dP_t_el5 = optimvar("dP_t_el",1,24,"LowerBound",0);
dP_t_hl5 = optimvar("dP_t_hl",1,24,"LowerBound",0);
dP_t_cl5 = optimvar("dP_t_cl",1,24,"LowerBound",0);
% 设置求解器的初始起点
initialPoint5.P_t_net = zeros(size(P_t_net5));
initialPoint5.P_gt_CHP = zeros(size(P_gt_CHP5));
initialPoint5.P_t_cha = zeros(size(P_t_cha5));
initialPoint5.P_t_dis = zeros(size(P_t_dis5));
initialPoint5.u_t_cha = zeros(size(u_t_cha5));
initialPoint5.u_t_dis = zeros(size(u_t_dis5));
initialPoint5.P_et_EB = zeros(size(P_et_EB5));
initialPoint5.P_et_EC = zeros(size(P_et_EC5));
initialPoint5.P_ht_AC = zeros(size(P_ht_AC5));
initialPoint5.P_gt_GB = zeros(size(P_gt_GB5));
initialPoint5.E_t_f = zeros(size(E_t_f5));
initialPoint5.dP_t_pv = zeros(size(dP_t_pv5));
initialPoint5.dP_t_el = zeros(size(dP_t_el5));
initialPoint5.dP_t_hl = zeros(size(dP_t_hl5));
initialPoint5.dP_t_cl = zeros(size(dP_t_cl5));
% 创建问题
problem = optimproblem;
% 定义问题目标
problem.Objective = fcn2optimexpr(@objectiveFcn,P_t_net5,P_gt_CHP5,P_t_cha5,…
P_et_EB5,P_et_EC5,P_ht_AC5,P_gt_GB5,E_t_f5,dP_t_pv5,dP_t_el5,dP_t_hl5,dP_t_cl5);
% 定义问题约束
problem.Constraints.constraint1 = P_t_net5+0.38*P_gt_CHP5+P_t_pv-dP_t_pv5 == P_t_el-dP_t_el5+P_et_EB5+P_et_EC5+P_t_cha5;
problem.Constraints.constraint2 = P_gt_CHP5*0.45+P_gt_GB5*0.95+P_et_EB5*0.98 == P_t_hl+P_ht_AC5-dP_t_hl5;
problem.Constraints.constraint3 = P_ht_AC5*1.1+P_et_EC5*3.1 >= P_tmin_cl-dP_t_cl5;
problem.Constraints.constraint4 = P_ht_AC5*1.1+P_et_EC5*3.1 <= P_tmax_cl;
problem.Constraints.constraint5 = 0.38*P_gt_CHP5 <= 300 * ones(1, 24);
problem.Constraints.constraint6 = (circshift(P_gt_CHP5,…
1) – P_gt_CHP5) * 0.38 <= ones(1, 24) * 65;
problem.Constraints.constraint7 = (circshift(P_gt_CHP5,…
-1) – P_gt_CHP5) * 0.38 <= ones(1, 24) * 85;
problem.Constraints.constraint8 = P_t_cha5 <= u_t_cha5 .* 50;
problem.Constraints.constraint9 = P_t_dis5 <= u_t_dis5 .* 50;
problem.Constraints.constraint10 = u_t_cha5 + u_t_dis5 <= ones(1, 24);
% 设置非默认求解器选项
options5 = optimoptions("ga","Display","iter","PlotFcn",["gaplotscores",…
"gaplotbestf","gaplotbestindiv","gaplotexpectation","gaplotrange"]);
% 求解问题
[solution,objectiveValue] = solve(problem,initialPoint5,"Solver","ga",…
"Options",options5);
% 显示结果
solution
objectiveValue
the output is:
将使用 ga 求解问题。
ERROR – (linprog): Incorrect number of columns in A (inequalities)
ERROR – (linprog): Incorrect number of columns in B (equalities)
警告: (linprog): Length of lower bounds l is too long; ignoring extra bounds
警告: (linprog): Length of upper bounds u is too long; ignoring extra bounds
Output argument "x" (and possibly others) not assigned a value in the execution with "linprog" function.
出错 globaloptim.internal.preProcessLinearConstr (第 166 行)
[XOUT,~,success] = linprog([],Aineq,Bineq,Aeq,Beq,LB,UB, …
出错 gacommon (第 150 行)
globaloptim.internal.preProcessLinearConstr(Iterate.x,Aineq,bineq, …
出错 ga (第 377 行)
NonconFcn,options,Iterate,type] = gacommon(nvars,fun,Aineq,bineq,Aeq,beq,lb,ub, …
出错 optim.problemdef.OptimizationProblem/callSolver
出错 optim.internal.problemdef.ProblemImpl/solveImpl
出错 optim.problemdef.OptimizationProblem/solve ga, optimization MATLAB Answers — New Questions