generate combinations of binary variables
12 views (last 30 days)
Show older comments
Hello,
I have a list of 10 materials (eg. A, B, C, ..., J), and I have to choose 2 materials from the set to form a mixture.
Their presence in the mixture are represented by the binary variable
(first material in the mixture) and
(second material in the mixture).
For example, a mixture would consist of A as the first material, and C as the second material. The result I would like to generate would be in such form:
The binary variable for A in 'first material' will take the value of 1, while the remainder in 'first material' will be 0.
y(m1, A) = 1
y(m1, B) = 0
...
y(m1, J) = 0
The binary variable for C in 'second material' will take the value of 1, while the remainder in 'second material' will be 0.
y(m2, A) = 0
y(m2, B) = 0
y(m2, C) = 1
...
y(m2, J) = 0
There is only one condition (which sometimes I will have to impose on certain material(s) and sometimes I don't):
For example in this particular case study, binary variable for material E and F have to be zero in both first and second material, i.e. y(m1, E) = y(m1, F) = y(m2, E) = y(m2, F) = 0.
I have to generate all possible combinations - i.e. 10C2 = 45 combinations (when without restriction) or will become 8C2 =28 combinations (when WITH restrictions, using the example above).
How do I do this...?
Thank you!!
0 Comments
Accepted Answer
Walter Roberson
on 24 Jul 2019
bins = dec2bin(0:(2^10-1), 10) - '0';
bins(sum(bins,2) ~= 2, :) = []; %first constraint, that exactly 2 must be on.
7 Comments
More Answers (0)
See Also
Categories
Find more on Quantum Chemistry 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!
