Random and unique number generation with constraints.
이전 댓글 표시
Please help me. Here is given my given code where random number generation of 0 and 1 and find the unique solutions with given matrix 119*9.
pop_size = 119;
x = randi([0,1],pop_size,9);
chk = true;
while chk
[~,idx] = unique(x,'rows');
idy = setdiff(1:pop_size,idx);
x(idy,:) = randi([0,1],numel(idy),9);
chk = numel(idy)>0;
end
I want apply some constraints.
1. alternative values in c1 (first column) and c2 (second column) such as
c1 c2 c3 c4 c5 c6 c7 c8 c9
0 1 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0
2. alternative values in c3, c4, c5 and c6 such as
c1 c2 c3 c4 c5 c6 c7 c8 c9
0 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0 0
3. at least 1 among c7, c8 and c9
c1 c2 c3 c4 c5 c6 c7 c8 c9
0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 1 0
0 0 0 0 0 0 1 1 1
0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 1 1 1
Please help me How i can code these constraints.
After getting all my upper constraints my final task is to combine all as given bellow.
there are three groups
1. c1 and c2
2. c3,c4,c5 and c6
3. c7,c8 and c9
Between groups there is OR operation. as given below
c1 c2 c3 c4 c5 c6 c7 c8 c9
1 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0
0 0 0 0 1 0 0 0 0
0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 1 0
0 0 0 0 0 0 1 0 1
1 0 0 1 0 0 1 1 0
Something like this
If I compute all possible solutions in this way. I get 119 unique combinations
댓글 수: 4
John D'Errico
2016년 9월 6일
편집: John D'Errico
2016년 9월 6일
I'm trying to read your mind, but it is a very confusing place. Impossible to know what you want from these confusing directions.
Are you trying to compute all possible solutions? You DO say "...and find the unique solutions..."
Are you trying to compute a random matrix given some set of constraints?
Asad Abbas
2016년 9월 6일
@Asad Abbas: your output does not seem to follow your constraints. You show that either c1 or c2 should have a 1, but most rows of your example this is not true, e.g. the third row 0 0 1 0 0 0 0 0 0. How your constraints relate to your output is not clear.
Asad Abbas
2016년 9월 6일
편집: Asad Abbas
2016년 9월 6일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Univariate Discrete Distributions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!