Problem with Linear inequality constraints
6 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I am trying to do an optimization using genetic algorithm solver. I have linear inequality constraints and i am having trouble properly defining them.
First of all, although my objective function gives not enough input argument error, it works(colud not solve this error i have tried everything). Next step is defining the constraints. I have several constraints, to be more exact including the domain constraints(2) i have 6.
My problem has variables and paremeters with (mostly) dimensions 36x36. I have choosed one constraint to test before proceeding with the rest of the constraints. i have choosed this one ;
sum(over j)(xij)<=1 for each i
what i did was;
i have created A matrix and b vector since this is an inequality constraint. In the A matrix i wrote 1's and 0's. in the b matrix i wrote 1 since that is what i desire.
But it does not assign any values to my variables (xij), and best solution returns as 0.
I will attch the file, if you can have a look i would be appreacited.
Thank you in advance.
Beyza.
10 个评论
Matt J
2022-3-30
编辑:Matt J
2022-3-30
What are you trying to do? Are you just trying to see the objective function value? If so, just write,
objectiveValue
I did not write that line. And can not delete it, it does not allow me.
Just for reference, you can convert the Live Task to editable code using the drop down menu in the upper right corner of the task
采纳的回答
Matt J
2022-3-30
编辑:Matt J
2022-3-30
sum(over j)(xij)<=1 for each i
This constraint can be written,
x=rand(36);
[m,n]=size(x);
A=kron(ones(1,n),speye(m)); b=ones(m,1);
You can check the equivalence as follows:
difference=sum(x,2) - A*x(:)
17 个评论
Matt J
2022-3-30
编辑:Matt J
2022-3-30
It would not be easier with a different solver since in all MATLAB solvers for optimization, you would have to set up A and b.
No, if you were to use intlinprog, but through the problem-based workflow, there would be no need to explicitly create A and b. This would be done for you internally by optimproblem().
So it all ends with how i set up A, b, and (of course) objfunc Which all three i am currently failing to do properly.
So far, nothing has been found to be incorrect in your objective function.
Torsten
2022-3-30
编辑:Torsten
2022-3-30
It would not be easier with a different solver since in all MATLAB solvers for optimization, you would have to set up A and b.
I should have added: if you use the solver-based approach.
The problem-based approach looks simple, but I have the feeling that one looses too much control over the problem. Checking how settings are internally translated (kind of debugging possibility) is impossible (at least as far as I can see). But as so many things: it's a matter of taste.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!