Conversion to logical from optim.problemdef.OptimizationConstraint is not possible. Expressing a condition for a parameter.
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I am trying to formulate an mixed integer optimization problem and one of my parameters (say A) depends on my optimization variable (say x), which is a binary variable.
I would like that when x=1, A=a and when x=0, A=b;
I realized that I couldn't express it with an "If function" after getting the error Conversion to logical from optim.problemdef.OptimizationConstraint is not possible.
Going through Matlab resources I found solutions using big M constraints for cases where A is expected to be above a superior value when x takes a certain value. However I couldn't find the case where A has to be equal to a specific value.
Can someone help me expressing this condition?
Thank you! :)
0 个评论
采纳的回答
Walter Roberson
2019-9-17
A = b + x*(a-b)
2 个评论
NN
2021-5-2
how can i use the same Pbatt which is calculated from optimisation variables depending on its sign in objective function?
Like if Pbatt is positive i have to multiply with cost and if its negative i have to multiply it with another cost .How do i specify Pbatt in objective function accordingly ?
I am also getting the error
Conversion to logical from optim.problemdef.OptimizationConstraint is not possible.
i have used below code.
for i = 1:N
if PbattV == 200
Cost1 = Costa;
elseif PbattV == -200
Cost2 = Costb;
end
end
prob.Objective = dt*Cost1'*PbattV +Cost2'*PbattV;
Kindly help
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!