Determinant Encoding

Hi,

I'm doing research on MST using GA. I have a problem with the encoding to represent the allele. I'm using Determinant Encoding and i don;t know how to get all the combination of determinant code.

My problem:

i have an array(2D) as below

1231 22

3453nullnull

65null4nullnull

7null nullnullnullnull

and combinations of my determinant codes should listed as below

1st determinant code 123122

2nd det. code123322

3rd det. code123422

4th det. code125122

5th det. code125322

and so on(until 72 combinations)

Anybody can solve my prob.?

[633 byte] By [n_azmana] at [2007-10-2 19:50:48]
# 1
Even if a bioscientist were to read it, I still don't think you've given enough information; if you've got an array that you know the algorithm for filling, but there are null values in it, it's more likely a coding error than an algorthmic one.
pm_kirkhama at 2007-7-13 22:29:46 > top of Java-index,Other Topics,Algorithms...
# 2

6 nested for loops. Each one chooses a non null value from its column, stuffs in into the appropriate column of a result and then moves to the next for loop which fills the next column with all possibilities.

If you understand recursion, you save typing by building a recursive routine the fills an entire result array by first filling a single column of the result(with a for loop) and then recursing to fill the rest of the array.

marlin314a at 2007-7-13 22:29:46 > top of Java-index,Other Topics,Algorithms...
# 3

> i have an array(2D) as below

That's a really bad structure. I suggest restructuring it as int[][] alleles = new int[][]

{

{1, 3, 6, 7},

{2, 4, 5},

{3, 5},

{1, 3, 4},

{2},

{2},

};

(Yes, 2D arrays don't have to be rectangular).

Then you can basically think in terms of multibasic numbers, where the bases are the array lengths. I think the code (warning: untested) would be public int[] select(int n)

{

int[] rv = new int[alleles.length];

for (int idx = rv.length - 1; idx >= 0; idx--)

{

int len = alleles[idx].length;

rv[idx] = alleles[idx][n % len];

n /= len;

}

if (n > 0)

{

throw new IllegalArgumentException("There aren't that many possibilies");

}

return rv;

}

YAT_Archivista at 2007-7-13 22:29:46 > top of Java-index,Other Topics,Algorithms...
# 4
Thanks to Yat Archivist, your code very helpful.
n_azmana at 2007-7-13 22:29:46 > top of Java-index,Other Topics,Algorithms...