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

modified:   test/javFiles/Matrix.jav
Rekursive Berechnung des Kartesischen Produkts
This commit is contained in:
Martin Plümicke 2018-02-08 00:02:27 +01:00
parent 1f269918fb
commit e4fbd17a55
2 changed files with 32 additions and 9 deletions

View File

@ -155,9 +155,32 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
}
topLevelSets.add(flat);
}
return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets));
}
Set<Set<UnifyPair>> computeCartesianRecursive(Set<Set<UnifyPair>> fstElems, ArrayList<Set<Set<UnifyPair>>> sets) {
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;
for(Set<UnifyPair> a : newSet) {
Set<Set<UnifyPair>> elems = new HashSet<Set<UnifyPair>>(fstElems);
elems.add(a);
if (newSets.isEmpty()) {
result = unify2(elems);
}
else {
result = computeCartesianRecursive(elems,newSets);
}
if (!result.isEmpty()) break;
}
return result;
}
Set<Set<UnifyPair>> unify2(Set<Set<UnifyPair>> setToFlatten) {
//Set<Set<UnifyPair>> setToFlatten = topLevelSets.stream().map(x -> x.iterator().next()).collect(Collectors.toCollection(HashSet::new));
Set<Set<UnifyPair>> setToFlatten = topLevelSets.stream().map(x -> x.iterator().next()).collect(Collectors.toCollection(HashSet::new));
// Cartesian product over all (up to 10) top level sets
//Set<Set<Set<UnifyPair>>> eqPrimeSet = setOps.cartesianProduct(topLevelSets)
//.stream().map(x -> new HashSet<>(x))

View File

@ -11,13 +11,13 @@ class Matrix extends Vector<Vector<Integer>> {
var v2 = new Vector<Integer>();
var j = 0;
while(j < v1.size()) {
var erg = 0;
var k = 0;
while(k < v1.size()) {
erg = erg + v1.elementAt(k)
* m.elementAt(k).elementAt(j);
k++; }
v2.addElement(new Integer(erg));
//var erg = 0;
//var k = 0;
//while(k < v1.size()) {
//erg = erg + v1.elementAt(k)
// * m.elementAt(k).elementAt(j);
//k++; }
//v2.addElement(new Integer(erg));
j++; }
ret.addElement(v2);
i++; }