I need to generate subsets that do not violate the precedence relationships. I have tasks numbered from 1 to 10. For example, task 4 cannot be done without doing task 1 and 2. I wrote a function to generate those sets for inputs of tasks, precedence matrix, and size of the subset(n):
function [ e ] = subsets( tasks, pre, n ) poss = combntns(tasks, n) [r c] = size(poss); e = zeros(size(poss)); for i = 1:r for j = 1:n if(any(pre(poss(i,j),:))~=0) vec = find(pre(poss(i,j),:)) if(ismember(poss(i,:), vec)==length(vec)) e(i,j) = 1; end end end end end
There is a problem up to now. If I resolve it, I will use the "e" matrix to write the valid subsets to another variable.
You can consider pre matrix as something like below:
pre = 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 1 0 1 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 0
Thanks for your help in advance.
Best Answer