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]

