Please does anybody knows the answer for my tree problem

I want to travese tree en get all the combinations of the tree elements from a tree, i've allready discussed it in this group but suddenly ii encountered a probelm when the tree hierarch get to deep my algoritme failt to work, and at the end i'll get an out of memory problem , so i tried to put everything in a file but its seems to be the same , maybe i write it on the wrong place to the file or i'm not clearing memory .

the strange thing i have also is that when printing the result i'll get 2 [[ , this can also be the result of out-off-memory problem.

here is the algoritme together with the tree

[code]

root

ALL

4 DEURS

DUMPATCH

DUMPATCH LH

DUMPATCH RH

2 DEURS

STANDAARD

STANDAARD VERWARMING

SPORT

VERWARMING SPORT

LEDER/COSMO

LORDOSE

LORDOSE LH

LORDOSE RH

ARMSTEUN

ARMSTEUN LH

ARMSTEUN RH

NIET AKTIEVE KOPSTEUN

NAK LORDOSE LH

NAK LORDOSE RH

NAK NIET LORDOSE LH

NAK NIET LORDOSE RH

DUMMY TRIMBOX

CONTAINMENT

public static void dumpTreeModel(TreeModel tm, Object node, String tab,

String step) {

System.out.println(tab + node);

for (int i = 0; i < tm.getChildCount(node); i++) {

dumpTreeModel(tm, tm.getChild(node, i), tab + step, step);

}

}

public static Set getAllSets( RandomAccessFile file , TreeModel model, Object node) {

Set result = new HashSet();

int child = (int) Math.pow(2, model.getChildCount(node));

for (int i = 0; i < child; i++) {

// foreach powerset of the immediate children

Set set = new HashSet();

for (int j = 0; j < model.getChildCount(node); j++) {

if ( (i & 1 << j) != 0) {

set.add(getAllSets(file , model, model.getChild(node, j)));

}

}

result.addAll(magicProduct(set));

}

for (Iterator k = result.iterator(); k.hasNext(); ) {

//( (Set) k.next()).add(node);

( (Set) k.next()).add( node.toString());

}

try {

System.out.println( result.toString() );

file.writeBytes(result.toString());

}

catch (IOException ex) {

}

return result;

}

public static final Set magicProduct(Set sets) {

Set result = new HashSet();

result.add(new HashSet());

for (Iterator i = sets.iterator(); i.hasNext(); ) {

result = magicProduct(result, (Set) i.next());

}

return result;

}

private static final Set magicProduct(Set a, Set b) {

Set result = new HashSet();

for (Iterator i = a.iterator(); i.hasNext(); ) {

Set setA = (Set) i.next();

for (Iterator j = b.iterator(); j.hasNext(); ) {

Set setB = (Set) j.next();

Set sss = new HashSet(setA);

sss.addAll(setB);

result.add(sss);

}

}

return result;

}

[\code]

[2943 byte] By [scifo] at [2007-9-30 20:46:27]
# 1

Honestly said, I am still a bit baffled on the exploding nature of those many sets.

(I am wondering about the sense partly.)

Try to trace your algorith for a limited input A, B, C, and look.

1. You could implement the Set interface with your own class, that derives the product set dynamically.

2. (!!) Create less sets by not using "Set function (Set inp)" but "void procedure (Set result, Set inp)."

3. You could consider numbering all strings and use BitSets. They are optimized.

4. Use java -Xms600m -Xmx600m ... (http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/java.html).

Good luck

joop_eggen at 2007-7-7 2:19:39 > top of Java-index,Other Topics,Algorithms...
# 2

hi txs for answering , but can you be more specified because i don't understand it not very good

the code works perfect with less input but goes crazy with a larger input

what you mean by item 2 ?

any chance for a snippet so i can see what you mean

what about numbering the strings?

link 4 is not reachable

hope you can help me

thans Sven

scifo at 2007-7-7 2:19:39 > top of Java-index,Other Topics,Algorithms...
# 3
A brief look here - but since you always return a set the recursion will go on infinitely. Hence the out of memory error?/k1
komone at 2007-7-7 2:19:39 > top of Java-index,Other Topics,Algorithms...
# 4
but its stops with less tree- items , do you have other suggestion?tia Sven
scifo at 2007-7-7 2:19:39 > top of Java-index,Other Topics,Algorithms...
# 5
hi Joop,can you be clearder what you mean about the void procedure because i'm still fighting with my problem and i'm getting out of timeSVen
scifo at 2007-7-7 2:19:39 > top of Java-index,Other Topics,Algorithms...