From 1b7bded3c365c50ca3f00b83ed372803d085485a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 11 Oct 2018 12:40:20 +0200 Subject: [PATCH] =?UTF-8?q?=09modified:=20=20=20../../src/de/dhbwstuttgart?= =?UTF-8?q?/typeinference/unify/TypeUnifyTask.java=20=09modified:=20=20=20?= =?UTF-8?q?../../src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.?= =?UTF-8?q?java=201.=20Version=20l=C3=A4uft=20aber=20nicht=20schnell?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../typeinference/unify/TypeUnifyTask.java | 79 +++++++++++-------- .../typeinference/unify/model/UnifyPair.java | 6 +- 2 files changed, 48 insertions(+), 37 deletions(-) diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index b1cbbe7b..5980d29f 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -31,6 +31,7 @@ import de.dhbwstuttgart.typeinference.unify.model.Unifier; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import de.dhbwstuttgart.typeinference.unify.model.UnifyType; import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair; +import de.dhbwstuttgart.typeinference.unify.model.Pair; import java.io.File; import java.io.FileWriter; @@ -553,8 +554,9 @@ public class TypeUnifyTask extends RecursiveTask>> { } } /* auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */ - + if (isUndefinedPairSetSet(res)) { + int nofstred= 0; Set abhSubst = res.stream() .map(b -> b.stream() @@ -569,35 +571,41 @@ public class TypeUnifyTask extends RecursiveTask>> { //Set vars = durchschnitt.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new)); int len = nextSetasList.size(); if (!durchschnitt.isEmpty()) { - UnifyPair groundBasepair = res.iterator().next().iterator().next().getGroundBasePair().get(); - Set undefRes = res.stream().reduce((y,z) -> { y.addAll(z); return y;}).get(); - Set> reducedUndefResSubstGroundedBasePair = undefRes.stream() - .map(x -> { Set su = x.getAllSubstitutions(); su.add(x.getGroundBasePair().get()); return su;}) - .map(y -> { y.removeAll(durchschnitt); return y;}) + //UnifyPair groundBasepair = res.iterator().next().iterator().next().getGroundBasePair().get(); + Set undefRes = res.stream().reduce((y,z) -> { y.addAll(z); return y;}).get(); //flatten aller undef results + Set, UnifyPair>> reducedUndefResSubstGroundedBasePair = undefRes.stream() + .map(x -> { Set su = x.getAllSubstitutions(); //alle benutzten Substitutionen + 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)); - Set resGroundBasepairs = undefRes.stream().map(x -> x.getGroundBasePair().get()).collect(Collectors.toCollection(HashSet::new)); + //Set resGroundBasepairs = undefRes.stream().map(x -> x.getGroundBasePair().get()).collect(Collectors.toCollection(HashSet::new)); if (res.size() > 1) { System.out.println(); } - Set reducedAbhSubst = new HashSet<>(abhSubst); - reducedAbhSubst.removeAll(durchschnitt); + //Set reducedAbhSubst = new HashSet<>(abhSubst); + //reducedAbhSubst.removeAll(durchschnitt); nextSetasList = nextSetasList.stream().filter(x -> { //Boolean ret = false; //for (PlaceholderType var : vars) { // ret = ret || x.stream().map(b -> b.getLhsType().equals(var)).reduce((c,d) -> c || d).get(); //} 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)); + nofstred = nextSetasList.size(); + //nextSetasList = nextSetasList.stream().filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y)) + // .collect(Collectors.toCollection(ArrayList::new)); } writeLog("abhSubst: " + abhSubst.toString()); writeLog("a: " + a.toString()); writeLog("Durchschnitt: " + durchschnitt.toString()); writeLog("nextSet: " + nextSet.toString()); writeLog("nextSetasList: " + nextSetasList.toString()); + writeLog("Number first erased Elements (undef): " + (len - nofstred)); writeLog("Number erased Elements (undef): " + (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++; writeLog("Number of Backtracking: " + noBacktracking); System.out.println(""); @@ -613,32 +621,35 @@ public class TypeUnifyTask extends RecursiveTask>> { return result; } - protected boolean couldBecorrect(Set reducedAbhSubst, UnifyPair groundBasepair, Set nextElem) { - reducedAbhSubst.add(groundBasepair); - reducedAbhSubst.addAll(nextElem); - Optional> substRes = rules.subst(reducedAbhSubst); - if (!substRes.isPresent()) { - return true; - } - else { - UnifyPair checkPair = substRes.get().stream().filter(x -> x.getGroundBasePair().get().equals(groundBasepair)).findFirst().get(); - if ((checkPair.getLhsType() instanceof PlaceholderType) || (checkPair.getRhsType() instanceof PlaceholderType)) { - Set up = new HashSet<>(); - up.add(checkPair); - Set undef = new HashSet<>(); - calculatePairSets(up, fc, undef); - if (undef.isEmpty()) { - return true; - } - else { - return false; - } + protected boolean couldBecorrect(Set, UnifyPair>> reducedUndefResSubstGroundedBasePair, Set nextElem) { + return reducedUndefResSubstGroundedBasePair.stream() + .map(pair -> { + Set reducedAbhSubst = pair.getKey(); + reducedAbhSubst.addAll(nextElem); + Optional> substRes = rules.subst(reducedAbhSubst); + if (!substRes.isPresent()) { + return true; } 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 up = new HashSet<>(); + up.add(checkPair); + Set 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; + return true;}).reduce((xx, yy) -> xx || yy).get(); } protected boolean isUndefinedPairSet(Set s) { diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java index dd185836..d69138a7 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java @@ -152,12 +152,12 @@ public class UnifyPair { return ret; } - public Optional getGroundBasePair () { + public UnifyPair getGroundBasePair () { if (basePair == null) { - return Optional.empty(); + return this; } if (basePair.getBasePair() == null) { - return Optional.of(basePair); + return basePair; } else { return basePair.getGroundBasePair();