diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index e2dd56a1..4b2e8c9c 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -101,8 +101,8 @@ public class JavaTXCompiler { } System.out.println(xConsSet); - //Set> result = unify.unifySequential(xConsSet, finiteClosure); - Set> result = unify.unify(xConsSet, finiteClosure); + Set> result = unify.unifySequential(xConsSet, finiteClosure); + //Set> result = unify.unify(xConsSet, finiteClosure); System.out.println("RESULT: " + result); results.addAll(result); } diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index ef197e5e..4c559a63 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -161,44 +161,36 @@ public class TypeUnifyTask extends RecursiveTask>> { } //System.out.println(topLevelSets); System.out.println(); - return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, fc, parallel); + + + //Aufruf von computeCartesianRecursive ANFANG + //return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, fc, parallel); - } + //} - 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; - int i = 0; - for(Set a : newSet) { - i++; - Set> elems = new HashSet>(fstElems); - elems.add(a); - if (newSets.isEmpty()) { - result = unify2(elems, eq, fc, parallel); - } - else { - result = computeCartesianRecursive(elems,newSets, eq, fc, parallel); - } - if (!result.isEmpty()) break; - } - return result; - } - Set> unify2(Set> setToFlatten, Set eq, IFiniteClosure fc, boolean parallel) { + + //Set> unify2(Set> setToFlatten, Set eq, IFiniteClosure fc, boolean parallel) { + //Aufruf von computeCartesianRecursive ENDE + + //Set> setToFlatten = topLevelSets.stream().map(x -> x.iterator().next()).collect(Collectors.toCollection(HashSet::new)); + //Muss auskommentiert werden, wenn computeCartesianRecursive ANFANG // Cartesian product over all (up to 10) top level sets - //Set>> eqPrimeSet = setOps.cartesianProduct(topLevelSets) - //.stream().map(x -> new HashSet<>(x)) - //.collect(Collectors.toCollection(HashSet::new)); + Set>> eqPrimeSet = setOps.cartesianProduct(topLevelSets) + .stream().map(x -> new HashSet<>(x)) + .collect(Collectors.toCollection(HashSet::new)); + //Muss auskommentiert werden, wenn computeCartesianRecursive ENDE Set> eqPrimePrimeSet = new HashSet<>(); Set forks = new HashSet<>(); - //for(Set> setToFlatten : eqPrimeSet) { + + //Muss auskommentiert werden, wenn computeCartesianRecursive ANFANG + for(Set> setToFlatten : eqPrimeSet) { // Flatten the cartesian product + //Muss auskommentiert werden, wenn computeCartesianRecursive ENDE Set eqPrime = new HashSet<>(); setToFlatten.stream().forEach(x -> eqPrime.addAll(x)); @@ -242,7 +234,9 @@ public class TypeUnifyTask extends RecursiveTask>> { else eqPrimePrimeSet.addAll(unify(eqPrime, fc, false)); } - //} + //Muss auskommentiert werden, wenn computeCartesianRecursive ANFANG + } + //Muss auskommentiert werden, wenn computeCartesianRecursive ENDE /* * Step 6 b) Build the union over everything. @@ -259,6 +253,29 @@ public class TypeUnifyTask extends RecursiveTask>> { } + + + 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; + int i = 0; + for(Set a : newSet) { + i++; + Set> elems = new HashSet>(fstElems); + elems.add(a); + if (newSets.isEmpty()) { + //BEI BENUTZUNG EIKOMMENTIEREN result = unify2(elems, eq, fc, parallel); + } + else { + result = computeCartesianRecursive(elems,newSets, eq, fc, parallel); + } + if (!result.isEmpty()) break; + } + return result; + } + /** * Checks whether a set of pairs is in solved form. * @param eqPrimePrime The set of pair