generate combinations of binary variables
조회 수: 12 (최근 30일)
이전 댓글 표시
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
채택된 답변
Walter Roberson
2019년 7월 24일
bins = dec2bin(0:(2^10-1), 10) - '0';
bins(sum(bins,2) ~= 2, :) = []; %first constraint, that exactly 2 must be on.
댓글 수: 7
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Quantum Chemistry에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

