generate combinations of binary variables
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Walter Roberson
le 24 Juil 2019
bins = dec2bin(0:(2^10-1), 10) - '0';
bins(sum(bins,2) ~= 2, :) = []; %first constraint, that exactly 2 must be on.
7 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Quantum Chemistry dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

