How can i implement a second decision variable which is not in the objective function?
Show older comments
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
Azime Beyza Ari
on 27 Mar 2022
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.
Azime Beyza Ari
on 28 Mar 2022
Edited: Azime Beyza Ari
on 28 Mar 2022
Torsten
on 28 Mar 2022
[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 ?
Azime Beyza Ari
on 28 Mar 2022
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).
Azime Beyza Ari
on 28 Mar 2022
Answers (0)
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!