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.
* 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<Set<Set<UnifyPair>>> secondLevelSet : secondLevelSets) {
/* for(Set<Set<Set<UnifyPair>>> secondLevelSet : secondLevelSets) {
//System.out.println("secondLevelSet "+secondLevelSet.size());
List<Set<Set<UnifyPair>>> secondLevelSetList = new ArrayList<>(secondLevelSet);
Set<List<Set<UnifyPair>>> cartResult = setOps.cartesianProduct(secondLevelSetList);
@ -183,7 +183,15 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
flat1.addAll(s1);
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();
@ -291,36 +299,41 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
* 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<Set<UnifyPair>> computeCartesianRecursive(Set<Set<UnifyPair>> fstElems, ArrayList<Set<Set<UnifyPair>>> sets, Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel) {
ArrayList<Set<Set<UnifyPair>>> newSets = new ArrayList<>(sets);
Set<Set<UnifyPair>> set = newSets.remove(0);
ArrayList<Set<UnifyPair>> newSet = new ArrayList<>(set);
Set<Set<UnifyPair>> result = null;
Set<Set<UnifyPair>> computeCartesianRecursive(Set<Set<UnifyPair>> fstElems, ArrayList<Set<Set<UnifyPair>>> topLevelSets, Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel) {
ArrayList<Set<Set<UnifyPair>>> remainingSets = new ArrayList<>(topLevelSets);
Set<Set<UnifyPair>> nextSet = remainingSets.remove(0);
ArrayList<Set<UnifyPair>> nextSetasList = new ArrayList<>(nextSet);
Set<Set<UnifyPair>> result = new HashSet<>();
int i = 0;
Set<UnifyPair> a_next = oup.min(newSet.iterator());
while (newSet.size() != 0) {
Set<UnifyPair> a_next = oup.min(nextSetasList.iterator());
while (nextSetasList.size() != 0) {
Set<UnifyPair> 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<UnifyPair> a : newSet) {
i++;
Set<Set<UnifyPair>> elems = new HashSet<Set<UnifyPair>>(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;
}