Hi all,
I have a matrix, let's call it A, as an input which has the following characteristics:
Total number of rows=n
Total number of columns=m
n<m
we also have a binary variable, x, and its index is m. it means we have:
x(1), x(2),....,x(m).
during the optimization process n out of m "x" should be equal to one and other x's are zero.
For those x's which are equal to one the corresponding column of matrix A should be distracted and be placed in a new matrix.
For instance if m=4 and x(1) and x(2) are equal to 1 then columns 1 and 2 from matrix A should be placed in a new matrix and columns 3 and 4 of Matrix A should be placed in another matrix.
How can I do this process?
Again, we know the number of x's that should be equal to one.
How to adjust a Matrix in the process of solving a model.

 User
 Posts: 56
 Joined: 1 year ago
 Location: Rosario  Argentina
Re: How to adjust a Matrix in the process of solving a model.
Hi,
Is this process done after a resolution?
Or should they be model constraints?
Is this process done after a resolution?
Or should they be model constraints?

 User
 Posts: 56
 Joined: 1 year ago
 Location: Rosario  Argentina
Re: How to adjust a Matrix in the process of solving a model.
I think that a column assignment can work.
Try this:
sets
m /1*4/
n /1*2/
p mn /1*2/
;
alias(n,np)
table A(n,m)
1 2 3 4
1 1 4 7 10
2 2 5 8 11
;
binary variable
x(m)
y(m,n) column m of matrix A is assigned to column n of matrix B
z(m,p) column m of matrix A is assigned to column p of matrix C
;
Variable
B(n,n),C(n,p),mute,Bd(np,m,n),Cd(np,m,p)
;
equation
eq1
eq2 if x(m) is equal to 1 is assigned to matrix B
eq3 only one column can be assigned to B
eq4 if x(m) is equal to 0 is assigned to matrix C
eq5 only one column can be assigned to C
eq6,eq7,eq8,eq9,eq10,eq11,eq12
;
eq1.. sum(m,x(m)) =e= card(n);
eq2(m).. 1x(m) + sum(n,y(m,n)) =g= 1;
eq3(n).. sum(m,y(m,n)) =e= 1;
eq4(m).. x(m) + sum(p,z(m,p)) =g= 1;
eq5(p).. sum(m,z(m,p)) =e= 1;
eq6(np,m,n).. Bd(np,m,n) =l= A(np,m)*y(m,n);
eq7(np,m,n).. Bd(np,m,n) =g= A(np,m)*y(m,n);
eq8(np,n).. B(np,n) =e= sum(m,Bd(np,m,n));
eq9(np,m,p).. Cd(np,m,p) =l= A(np,m)*z(m,p);
eq10(np,m,p).. Cd(np,m,p) =g= A(np,m)*z(m,p);
eq11(np,p).. C(np,p) =e= sum(m,Cd(np,m,p));
eq12.. mute =e= 1;
model test /all/
solve test using mip minimizing mute;
Try this:
sets
m /1*4/
n /1*2/
p mn /1*2/
;
alias(n,np)
table A(n,m)
1 2 3 4
1 1 4 7 10
2 2 5 8 11
;
binary variable
x(m)
y(m,n) column m of matrix A is assigned to column n of matrix B
z(m,p) column m of matrix A is assigned to column p of matrix C
;
Variable
B(n,n),C(n,p),mute,Bd(np,m,n),Cd(np,m,p)
;
equation
eq1
eq2 if x(m) is equal to 1 is assigned to matrix B
eq3 only one column can be assigned to B
eq4 if x(m) is equal to 0 is assigned to matrix C
eq5 only one column can be assigned to C
eq6,eq7,eq8,eq9,eq10,eq11,eq12
;
eq1.. sum(m,x(m)) =e= card(n);
eq2(m).. 1x(m) + sum(n,y(m,n)) =g= 1;
eq3(n).. sum(m,y(m,n)) =e= 1;
eq4(m).. x(m) + sum(p,z(m,p)) =g= 1;
eq5(p).. sum(m,z(m,p)) =e= 1;
eq6(np,m,n).. Bd(np,m,n) =l= A(np,m)*y(m,n);
eq7(np,m,n).. Bd(np,m,n) =g= A(np,m)*y(m,n);
eq8(np,n).. B(np,n) =e= sum(m,Bd(np,m,n));
eq9(np,m,p).. Cd(np,m,p) =l= A(np,m)*z(m,p);
eq10(np,m,p).. Cd(np,m,p) =g= A(np,m)*z(m,p);
eq11(np,p).. C(np,p) =e= sum(m,Cd(np,m,p));
eq12.. mute =e= 1;
model test /all/
solve test using mip minimizing mute;
Re: How to adjust a Matrix in the process of solving a model.
Thank you for your reply. What if the following information is not given:
n out of m "x" should be equal to one and other x's are zero.
I mean what if we don't know how many x(m) will be equal to 1. Can we still solve the problem?
n out of m "x" should be equal to one and other x's are zero.
I mean what if we don't know how many x(m) will be equal to 1. Can we still solve the problem?