modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java

In Unfy:
- Bildung des kartesischen Produkts auf secondlevel-Ebene entfernt

In computeCartesianRecursive:
- Vereinigung der Ergebnisse ueber die Schleifen und die Rekursion eingefuegt
- Minimumbestimmung korrigiert
This commit is contained in:
Martin Plümicke 2018-03-01 12:27:38 +01:00
parent 6a9db81981
commit 6256bdfe2e

View File

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