How can i implement a second decision variable which is not in the objective function?

hello everyone,
I am working on an optimization problem where i have 2 decision variable. One of the variable is xij, which is directly in the objective function, other one is yj, which is not in the objective function, it is in my constraints. yj is dependent to xij.
xij is an binary variable where i want solver to decide if xij is 1 or 0, and yj is the row summation of xij. here is an example;
lets say that the solver gave me a solution for xij like this;
x = [ 1 0 1 1; 0 0 1 0; 1 1 0 0]
i want yj to be column or a row vector it does not matter (preferably column)
yj = [ (1 +0 +1=) 2 ; (0 + 0+ 1=) 1; (1+1+0=)2 ; (1+0+0=)1]
I have other constraints where i use yj.
here is my model; (p=67) (M is some large number like 1000)
My first question is that; can i do this kind of an operation?
second Q : how can i do this?
Ps: I am using genetic algorithm solver!
thak you in advance!
Best,
Beyza.

9 Comments

Where do you set up your constraints ?
Since they are linear, I guess in A, b, Aeq and beq ?
If the above equations are the complete problem you try to solve, use intlinprog instead of ga.
Yeah I know they are linear but, i need to use genetic algorithm, it is a must, so nonlinear constraint section looked like a more wise choice since it lets me choose a function.
I set them up in the constraints section in the live editor (I mean local function section).
I guess in A, b, Aeq and beq ? -- what do you mean by this? (I am new to matlab)
I guess in A, b, Aeq and beq ? -- what do you mean by this? (I am new to matlab)
Linear inequality constraints are set as
A*x <= b
linear equality constraints are set as
Aeq*x = beq.
These 4 inputs (A,b,Aeq,beq) suffice to describe your problem, and this facility is also available in ga.
If later in time you want to include nonlinear constraints, you can use the nonlinear functionality of ga.
Ah yes, ı remembered what they were. But since ı have summation on the left side of the inequalities i was not sure how to write Aeq and A. Still not sure. i and j are both 36.
[1 1 0 0 0 0; 0 0 1 1 0 0;0 0 0 0 1 1]*[x11; x12 ;x21; x22 ;x31 ;x32] <= [1;1;1]
gives you the conditions
x11 + x12 <= 1
x21 + x22 <= 1
x31 + x32 <= 1
Thus if I ={1,2,3} and J={1,2}, this would be condition (4).
Can you take it from here ?
Isn't there a much easier way to do this? Since I and J has 36 elements each.
Another question is ; I have 4 constraints so what i need to do is i need to write them all in open form and left sides will be Aeq and right sides will be Beq.
Another Question is since the ga solver only allows to input 1 linear constraint i should write each of my constriants in that matrix right?
finally where should i write this; in the constraints section of the live editor or where?
[1 1 0 0 0 0; 0 0 1 1 0 0;0 0 0 0 1 1]*[x11; x12 ;x21; x22 ;x31 ;x32] <= [1;1;1]
Isn't there a much easier way to do this? Since I and J has 36 elements each.
You can use a loop to build the matrices if you know where the "ones" have to be placed.
Another question is ; I have 4 constraints so what i need to do is i need to write them all in open form and left sides will be Aeq and right sides will be Beq.
You must create two big matrices A and Aeq. The number of rows of A and Aeq gives the total number of inequality and equality constraints. The number of columns is equal to the total number of unknowns.
Another Question is since the ga solver only allows to input 1 linear constraint i should write each of my constriants in that matrix right?
Yes, all in two big matrices and two big vectors.
finally where should i write this; in the constraints section of the live editor or where?
[1 1 0 0 0 0; 0 0 1 1 0 0;0 0 0 0 1 1]*[x11; x12 ;x21; x22 ;x31 ;x32] <= [1;1;1]
You don't write the inequalities as I did above. You only write a script in which you specify the matrices and vectors just as you specify other variables. But you will have to put all variables in one vector. So for your case the vector could be arranged as
x = [x11; x21;...;x36,1;x12;x22;...,x36,2,...,x1,36, x2,36, ..., x36,36, y1,y2,...,y36]
with a size of (36*36 + 36,1).
I understood what you are saying. Thank you this is the answer.
i do not have equality constraints so Aeq and Beq will be empty. However, A and b, will be very big matrix and vector.
A will have an dimension of approxiametly 125x1332, so this is very unlogical to write manuelly. I will try to write them with a for loop if i can.
Again thank you!
My pleasure.
And use "intlinprog" instead of "ga" if the problem remains unchanged.
Setting up the matrix A and the vector b is the same for both solvers.

Sign in to comment.

Answers (0)

Products

Release

R2021b

Asked:

on 27 Mar 2022

Edited:

on 28 Mar 2022

Community Treasure Hunt

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

Start Hunting!