Dependent Variable operations?

Hello Everyone,
I am working on an optimization problem using genetic algorithm solver. I have 2 decision variables (x with 36x36 dimensions and y with 36x1 dimensions ). y is dependent to x. Like;
column sum of x is equal to row of y.
I introduced x and y like;
x = optimvar('x', [36,36], 'Type', 'integer', 'LowerBound',0,'UpperBound',1);
y = optimvar('y', [36,1]);
But i have a hard time doing the operation i want to do. How can i implement this (column sum of x is equal to row of y. ) into my code?
Any suggestions and opinions are welcome.
Thank you in advance!
Best,
Beyza.

7 Comments

Torsten
Torsten on 3 Apr 2022
Edited: Torsten on 3 Apr 2022
Did you look at the examples provided here:
?
You can even display the constraints after you defined them to see if you made something worng.
Thank you @Torsten! i have tried one of the methods exemplified in the document and got somewhere. İ have created an optimizationexpression. The formulation is correct but as a result it gives 0.
I want it to sum the rows of x (fisrt it was columsn but i changed it to the rows).
It gives me 0 as i told. I am thinking that the problem is caused by this; Since the solver returns me a solution2 matrix storing the values for the problem what i try to do with x should be done by the solution2 matrix. Is there a way where i can manipulate solution2 into making it equal to x. or is this the way?
The file is attached!
Could you write out the code as Matt showed you and attach the .m file ?
I have tried writing it in the way Matt suggested. like;
con.sumrows=(sum(x,1)<=1);
con.sumrows=(sum(x,2)== y);
p=prob2matrices({x},'Constraints',con);
The first constraint works exactly how i want it. but when i write the second constraint i get an error: The optimvars input did not contain ALL problem variables.
y values must be determined before i write constraints which includes y variables. if y values are not equal to the row sums of x variable i do not see any logical calculation will happening.
maybe you might think then y should not be a decision variable but in the future study i am thinking of converting this one objective to multiobjective problem where i will directly use y to calculate cost.
Sorry, but I'm not familiar with the problem-based approach.
If you tell me the vector of unknowns, how it is ordered and what constraints you want to impose, I can help you setting up the A, Aeq, b and beq.
If you want to use the problem-based approach, maybe someone else will help.
So this is what i am trying to achive;
I have 2 decision variables (x with dimensions 36*36 and y with 36*1). The objective function only has x (binary) in it. y should be equal to the row summation of x values. If i can make this then i will use y's in my constraints. like;
if summation of first row of x is equal to 2
then the following inequality would be correct.
y(1,1) <= 3
so my constraint will be met.
PS. The x matrix rows should not be higher than some values becasue there are demands for each row (each row has different demand). If we place more than demand then there is unnecessary cost. So, i want to make sure we do not exceed the demand.
Aeq = zeros(36,36*36+36);
for i = 1:36
Aeq(i,(i-1)*36+1:i*36) = ones(1,36);
Aeq(i,36*36+i) = -1;
end
This gives the contribution of the constraint sum_i (xij) - y(j) = 0 for j=1,...,36 to Aeq if the vector of unknowns Z is ordered as
Z = [x11,x21,x31,...,x(36,1),x12,x22,x32,...,x(36,2),...,x(1,36),x(2,36),...,x(36,36),y1,y2,...,y36]
The corresponding part of the vector beq is
beq(1:36,1) = zeros(36,1)

Sign in to comment.

Answers (0)

Products

Release

R2021b

Asked:

on 3 Apr 2022

Edited:

on 4 Apr 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!