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

modified:   ../../src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java
1. Version läuft aber nicht schnell
This commit is contained in:
Martin Plümicke 2018-10-11 12:40:20 +02:00
parent bda7dcb5c1
commit 1b7bded3c3
2 changed files with 48 additions and 37 deletions

View File

@ -31,6 +31,7 @@ import de.dhbwstuttgart.typeinference.unify.model.Unifier;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType; import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair; import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair;
import de.dhbwstuttgart.typeinference.unify.model.Pair;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
@ -553,8 +554,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
} }
} }
/* auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */ /* auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */
if (isUndefinedPairSetSet(res)) { if (isUndefinedPairSetSet(res)) {
int nofstred= 0;
Set<UnifyPair> abhSubst = res.stream() Set<UnifyPair> abhSubst = res.stream()
.map(b -> .map(b ->
b.stream() b.stream()
@ -569,35 +571,41 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
//Set<PlaceholderType> vars = durchschnitt.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); //Set<PlaceholderType> vars = durchschnitt.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new));
int len = nextSetasList.size(); int len = nextSetasList.size();
if (!durchschnitt.isEmpty()) { if (!durchschnitt.isEmpty()) {
UnifyPair groundBasepair = res.iterator().next().iterator().next().getGroundBasePair().get(); //UnifyPair groundBasepair = res.iterator().next().iterator().next().getGroundBasePair().get();
Set<UnifyPair> undefRes = res.stream().reduce((y,z) -> { y.addAll(z); return y;}).get(); Set<UnifyPair> undefRes = res.stream().reduce((y,z) -> { y.addAll(z); return y;}).get(); //flatten aller undef results
Set<Set<UnifyPair>> reducedUndefResSubstGroundedBasePair = undefRes.stream() Set<Pair<Set<UnifyPair>, UnifyPair>> reducedUndefResSubstGroundedBasePair = undefRes.stream()
.map(x -> { Set<UnifyPair> su = x.getAllSubstitutions(); su.add(x.getGroundBasePair().get()); return su;}) .map(x -> { Set<UnifyPair> su = x.getAllSubstitutions(); //alle benutzten Substitutionen
.map(y -> { y.removeAll(durchschnitt); return y;}) su.add(x.getGroundBasePair()); // urspruengliches Paar
su.removeAll(durchschnitt); //alle aktuell genänderten Paare entfernen
return new Pair<>(su, x.getGroundBasePair());})
.collect(Collectors.toCollection(HashSet::new)); .collect(Collectors.toCollection(HashSet::new));
Set<UnifyPair> resGroundBasepairs = undefRes.stream().map(x -> x.getGroundBasePair().get()).collect(Collectors.toCollection(HashSet::new)); //Set<UnifyPair> resGroundBasepairs = undefRes.stream().map(x -> x.getGroundBasePair().get()).collect(Collectors.toCollection(HashSet::new));
if (res.size() > 1) { if (res.size() > 1) {
System.out.println(); System.out.println();
} }
Set<UnifyPair> reducedAbhSubst = new HashSet<>(abhSubst); //Set<UnifyPair> reducedAbhSubst = new HashSet<>(abhSubst);
reducedAbhSubst.removeAll(durchschnitt); //reducedAbhSubst.removeAll(durchschnitt);
nextSetasList = nextSetasList.stream().filter(x -> { nextSetasList = nextSetasList.stream().filter(x -> {
//Boolean ret = false; //Boolean ret = false;
//for (PlaceholderType var : vars) { //for (PlaceholderType var : vars) {
// ret = ret || x.stream().map(b -> b.getLhsType().equals(var)).reduce((c,d) -> c || d).get(); // ret = ret || x.stream().map(b -> b.getLhsType().equals(var)).reduce((c,d) -> c || d).get();
//} //}
return (!x.containsAll(durchschnitt)); return (!x.containsAll(durchschnitt));
}).filter(y -> couldBecorrect(reducedAbhSubst, groundBasepair, y)) })//.filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y)) fuer testzwecke auskommentiert um nofstred zu bestimmen PL 2018-10-10
.collect(Collectors.toCollection(ArrayList::new)); .collect(Collectors.toCollection(ArrayList::new));
nofstred = nextSetasList.size();
//nextSetasList = nextSetasList.stream().filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y))
// .collect(Collectors.toCollection(ArrayList::new));
} }
writeLog("abhSubst: " + abhSubst.toString()); writeLog("abhSubst: " + abhSubst.toString());
writeLog("a: " + a.toString()); writeLog("a: " + a.toString());
writeLog("Durchschnitt: " + durchschnitt.toString()); writeLog("Durchschnitt: " + durchschnitt.toString());
writeLog("nextSet: " + nextSet.toString()); writeLog("nextSet: " + nextSet.toString());
writeLog("nextSetasList: " + nextSetasList.toString()); writeLog("nextSetasList: " + nextSetasList.toString());
writeLog("Number first erased Elements (undef): " + (len - nofstred));
writeLog("Number erased Elements (undef): " + (len - nextSetasList.size())); writeLog("Number erased Elements (undef): " + (len - nextSetasList.size()));
noAllErasedElements = noAllErasedElements + (len - nextSetasList.size()); noAllErasedElements = noAllErasedElements + (len - nextSetasList.size());
writeLog("Number erased Elements (undef): " + noAllErasedElements.toString()); writeLog("Number of all erased Elements (undef): " + noAllErasedElements.toString());
noBacktracking++; noBacktracking++;
writeLog("Number of Backtracking: " + noBacktracking); writeLog("Number of Backtracking: " + noBacktracking);
System.out.println(""); System.out.println("");
@ -613,32 +621,35 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
return result; return result;
} }
protected boolean couldBecorrect(Set<UnifyPair> reducedAbhSubst, UnifyPair groundBasepair, Set<UnifyPair> nextElem) { protected boolean couldBecorrect(Set<Pair<Set<UnifyPair>, UnifyPair>> reducedUndefResSubstGroundedBasePair, Set<UnifyPair> nextElem) {
reducedAbhSubst.add(groundBasepair); return reducedUndefResSubstGroundedBasePair.stream()
reducedAbhSubst.addAll(nextElem); .map(pair -> {
Optional<Set<UnifyPair>> substRes = rules.subst(reducedAbhSubst); Set<UnifyPair> reducedAbhSubst = pair.getKey();
if (!substRes.isPresent()) { reducedAbhSubst.addAll(nextElem);
return true; Optional<Set<UnifyPair>> substRes = rules.subst(reducedAbhSubst);
} if (!substRes.isPresent()) {
else { return true;
UnifyPair checkPair = substRes.get().stream().filter(x -> x.getGroundBasePair().get().equals(groundBasepair)).findFirst().get();
if ((checkPair.getLhsType() instanceof PlaceholderType) || (checkPair.getRhsType() instanceof PlaceholderType)) {
Set<UnifyPair> up = new HashSet<>();
up.add(checkPair);
Set<UnifyPair> undef = new HashSet<>();
calculatePairSets(up, fc, undef);
if (undef.isEmpty()) {
return true;
}
else {
return false;
}
} }
else { else {
//Pair type <. type' betrachten TODO PL 2018-10-09 UnifyPair checkPair = substRes.get().stream()
.filter(x -> x.getGroundBasePair().equals(pair.getValue().get())).findFirst().get();
if ((checkPair.getLhsType() instanceof PlaceholderType) || (checkPair.getRhsType() instanceof PlaceholderType)) {
Set<UnifyPair> up = new HashSet<>();
up.add(checkPair);
Set<UnifyPair> undef = new HashSet<>();
calculatePairSets(up, fc, undef);
if (undef.isEmpty()) {
return true;
}
else {
return false;
}
}
else {
//Pair type <. type' betrachten TODO PL 2018-10-09
}
} }
} return true;}).reduce((xx, yy) -> xx || yy).get();
return true;
} }
protected boolean isUndefinedPairSet(Set<UnifyPair> s) { protected boolean isUndefinedPairSet(Set<UnifyPair> s) {

View File

@ -152,12 +152,12 @@ public class UnifyPair {
return ret; return ret;
} }
public Optional<UnifyPair> getGroundBasePair () { public UnifyPair getGroundBasePair () {
if (basePair == null) { if (basePair == null) {
return Optional.empty(); return this;
} }
if (basePair.getBasePair() == null) { if (basePair.getBasePair() == null) {
return Optional.of(basePair); return basePair;
} }
else { else {
return basePair.getGroundBasePair(); return basePair.getGroundBasePair();