diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 79c0f329..d79da628 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -165,9 +165,9 @@ public class TypeUnifyTask extends RecursiveTask>> { /* Up to here, no cartesian products are calculated. * filters for pairs and sets can be applied here */ - // Sub cartesian products of the second level (pattern matched) sets + // Alternative: Sub cartesian products of the second level (pattern matched) sets // "the big (x)" - for(Set>> secondLevelSet : secondLevelSets) { + /* for(Set>> secondLevelSet : secondLevelSets) { //System.out.println("secondLevelSet "+secondLevelSet.size()); List>> secondLevelSetList = new ArrayList<>(secondLevelSet); Set>> cartResult = setOps.cartesianProduct(secondLevelSetList); @@ -183,7 +183,15 @@ public class TypeUnifyTask extends RecursiveTask>> { flat1.addAll(s1); flat.add(flat1); } - topLevelSets.add(flat); + //topLevelSets.add(flat); + } + */ + + //Alternative KEIN KARTESISCHES PRODUKT der secondlevel Ebene bilden + for(Set>> secondLevelSet : secondLevelSets) { + for (Set> secondlevelelem : secondLevelSet) { + topLevelSets.add(secondlevelelem); + } } //System.out.println(topLevelSets); //System.out.println(); @@ -291,36 +299,41 @@ public class TypeUnifyTask extends RecursiveTask>> { * Step 7: Filter empty sets; */ eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x)).collect(Collectors.toCollection(HashSet::new)); + if (!eqPrimePrimeSet.isEmpty()) + System.out.println(""); return eqPrimePrimeSet; } - Set> computeCartesianRecursive(Set> fstElems, ArrayList>> sets, Set eq, IFiniteClosure fc, boolean parallel) { - ArrayList>> newSets = new ArrayList<>(sets); - Set> set = newSets.remove(0); - ArrayList> newSet = new ArrayList<>(set); - Set> result = null; + Set> computeCartesianRecursive(Set> fstElems, ArrayList>> topLevelSets, Set eq, IFiniteClosure fc, boolean parallel) { + ArrayList>> remainingSets = new ArrayList<>(topLevelSets); + Set> nextSet = remainingSets.remove(0); + ArrayList> nextSetasList = new ArrayList<>(nextSet); + Set> result = new HashSet<>(); int i = 0; - Set a_next = oup.min(newSet.iterator()); - while (newSet.size() != 0) { + Set a_next = oup.min(nextSetasList.iterator()); + while (nextSetasList.size() != 0) { Set a = a_next; - writeLog("NewSet: " + newSet.toString()+ "\n"); - newSet.remove(a); - if (newSet.size() > 0) a_next = oup.min(newSet.iterator()); + writeLog("nextSet: " + nextSetasList.toString()+ "\n"); + nextSetasList.remove(a); + if (nextSetasList.size() > 0) + a_next = oup.min(nextSetasList.iterator()); //for(Set a : newSet) { i++; Set> elems = new HashSet>(fstElems); elems.add(a); - if (newSets.isEmpty()) { - result = unify2(elems, eq, fc, parallel); + if (remainingSets.isEmpty()) { + result.addAll(unify2(elems, eq, fc, parallel)); System.out.println(""); } else { - result = computeCartesianRecursive(elems,newSets, eq, fc, parallel); + result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); } if (!result.isEmpty()) //&& (oup.compare(a, a_next) == -1)) break; - if (oup.compare(a, a_next) == -1) break; + if (a.equals(a_next) || + (oup.compare(a, a_next) == -1)) + break; } return result; }