Problem with Linear inequality constraints
2 views (last 30 days)
Show older comments
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 Comments
Matt J
on 30 Mar 2022
Edited: Matt J
on 30 Mar 2022
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/947004/image.png)
Accepted Answer
Matt J
on 30 Mar 2022
Edited: Matt J
on 30 Mar 2022
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 Comments
Matt J
on 30 Mar 2022
Edited: Matt J
on 30 Mar 2022
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
on 30 Mar 2022
Edited: Torsten
on 30 Mar 2022
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.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!