gevni
Novice
Nov 23, 2012, 4:33 AM
Post #1 of 3
(2092 views)

How to reduce redundant permutations?

Can't Post


Hi I have this function that will exclude the redundant permutations. If processes are adjacent and belongs to same group it will exclude this permutation order. I need to change it like it will check all the processes that belongs to same group and skip all these combination weather they are adjacent or not but belongs to the same group For example : Let we have 4 processes. Total No of permutations are 4!=24 <b> 0 1 2 3 (here 0,1,3 belongs to same group) </b> This function will exclude the permutation that interchange 0 with 1 and i want to modify it like it will exclude all the permutations order that have same group weather they are adjacent or not like it may exclude 0 with 3 permutation order too . Function is
sub Apply_on_index(&@) { my $func = shift; my $array = shift; my $group = shift; return undef unless (defined $func and defined $array); my $rest; my $i; my $j; my @array; my $size = $#{$array}+1; my $card = factorial($size); my $res; for($j=0;$j<$card;$j++){ @array = @{$array}; $res = []; $rest = $j; $i = 0; for($i = 0; $i <= $#{$array}; $i++){ ${$res}[$i] = splice @array, $rest % ($#array + 1), 1; $rest = int($rest / ($#array + 2)); if ($i > 0 and ${$res}[$i] < ${$res}[$i1] and ${$group}[${$res}[$i]] == ${$group}[${$res}[$i1]]){ $res = undef; last; } } &$func($j) if defined $res; } return 0; } Plz let me know how I can modify it?
