Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: generation of random multiset permutation with restrictions
Replies: 17   Last Post: Jan 30, 2013 6:41 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bruno Luong

Posts: 8,704
Registered: 7/26/08
Re: generation of random multiset permutation with restrictions
Posted: Aug 21, 2012 9:49 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I will change the generate random permutation with restrictio. D will be different than my first post, but the goal of generaion is respected.

a = [1,1,1,2,2,3,3,3]
s = {[3],[1,2],[1,2,3],[1,2,3],[1,2,3],[1,2,3],[2,3],[2,3]};

%% Covert cell of sets to boolean array
m = max(a(:));
n = length(a);
j = arrayfun(@(j) j+zeros(size(s{j})), 1:n, 'unif', 0);
sbool = accumarray([s{:}; j{:}]',1, [m n])
clear m n j

%% Generate 100 vectors p, a permutation of a, and respecting the set-constraints
% p is ranged in 100 x 8 arrays, working with a and sbool
[m n] = size(sbool); % 3 x 8
[~, ia] = sort(rand(100,n),2);
p = a(ia);
c = m*(0:n-1)';
pp = permute(p, [3 2 1]);
D = 1-sbool(bsxfun(@plus,pp,c));
for k=1:size(p,1) % 100
[i cost] = assignmentoptimal(D(:,:,k));
if any(i==0) || cost>0
error('No solution exists');
end
p(k,:) = p(k,i);
end
disp(p)


%% Some p
p1 = [3,1,1,1,2,2,3,3];
p2 = [1,3,1,1,2,2,3,3];
p = [p1; p2]
clear p1 p2

% Check the validity of p
% working with a and sbool
[m n] = size(sbool);
OK = @(p) all(sbool(bsxfun(@plus,p,m*(0:n-1))) & bsxfun(@eq,sort(p,2),sort(a)),2);
OK(p)

% Bruno


Date Subject Author
8/9/12
Read generation of random multiset permutation with restrictions
Michal Kvasnicka
8/10/12
Read Re: generation of random multiset permutation with restrictions
Bruno Luong
8/10/12
Read Re: generation of random multiset permutation with restrictions
Michal Kvasnicka
8/21/12
Read Re: generation of random multiset permutation with restrictions
Michal Kvasnicka
8/21/12
Read Re: generation of random multiset permutation with restrictions
Bruno Luong
8/21/12
Read Re: generation of random multiset permutation with restrictions
Michal Kvasnicka
8/21/12
Read Re: generation of random multiset permutation with restrictions
Bruno Luong
8/21/12
Read Re: generation of random multiset permutation with restrictions
Michal Kvasnicka
8/21/12
Read Re: generation of random multiset permutation with restrictions
Bruno Luong
8/21/12
Read Re: generation of random multiset permutation with restrictions
Michal Kvasnicka
8/21/12
Read Re: generation of random multiset permutation with restrictions
Bruno Luong
8/23/12
Read Re: generation of random multiset permutation with restrictions
Michal Kvasnicka
1/29/13
Read Re: generation of random multiset permutation with restrictions
Michal Kvasnicka
1/30/13
Read Re: generation of random multiset permutation with restrictions
Michal Kvasnicka
1/30/13
Read Re: generation of random multiset permutation with restrictions
Bruno Luong
1/30/13
Read Re: generation of random multiset permutation with restrictions
Michal Kvasnicka
1/30/13
Read Re: generation of random multiset permutation with restrictions
Bruno Luong
1/30/13
Read Re: generation of random multiset permutation with restrictions
Michal Kvasnicka

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.