diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index a556546b..24c1b8f4 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -16,9 +16,14 @@ public class TypeUnify2Task extends TypeUnifyTask { Set> setToFlatten; - public TypeUnify2Task(Set> setToFlatten, Set eq, List,OrderingUnifyPair>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ConstraintSet cons) { + public TypeUnify2Task(Set> setToFlatten, Set eq, List,OrderingUnifyPair>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ConstraintSet cons) { super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); this.setToFlatten = setToFlatten; + this.nextSetElement = nextSetElement; + } + + Set getNextSetElement() { + return nextSetElement; } @Override diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index dba50be1..7eb6408c 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -59,6 +59,11 @@ public class TypeUnifyTask extends RecursiveTask>> { private boolean printtag = false; Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll? + /** + * Element, das aus dem nextSet den Gleichunen dieses Threads hinzugefuegt wurde + */ + Set nextSetElement; + /** * Fuer die Threads */ @@ -142,6 +147,7 @@ public class TypeUnifyTask extends RecursiveTask>> { */ //x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new)); + this.nextSetElement = nextSetElement; this.fc = fc; this.oup = new OrderingUnifyPair(fc); this.parallel = parallel; @@ -686,15 +692,14 @@ public class TypeUnifyTask extends RecursiveTask>> { //PL 2017-09-29 dies ersetzt //(!eqPrimePrime.isPresent()) //PL 2018-05-18 beide Bedingungen muessen gelten, da eqPrime Veränderungen in allem ausser subst //eqPrimePrime Veraenderungen in subst repraesentieren. - try { + //try { if (isSolvedForm(eqPrime)) { - logFile.write("eqPrime:" + eqPrime.toString()+"\n"); - logFile.flush(); + writeLog("eqPrime:" + eqPrime.toString()+"\n"); } - } - catch (IOException e) { + //} + //catch (IOException e) { System.err.println("log-File nicht vorhanden"); - } + //} eqPrimePrimeSet.add(eqPrime); Set> eqPrimePrimeSetRet = eqPrimePrimeSet.stream().map(x -> { Optional> res = new RuleSet().subst(x.stream().map(y -> { @@ -920,15 +925,16 @@ public class TypeUnifyTask extends RecursiveTask>> { //writeLog("Vor unify2 Aufruf: " + elems.toString()); Set> res = new HashSet<>(); Set>> add_res = new HashSet<>(); + Set> aParDef = new HashSet<>(); if(parallel && (variance == 1) && noOfThread <= MaxNoOfThreads) { - Set forks = new HashSet<>(); + Set forks = new HashSet<>(); Set newEqOrig = new HashSet<>(eq); Set> newElemsOrig = new HashSet<>(elems); List,OrderingUnifyPair>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, cons); //forks.add(forkOrig); forkOrig.fork(); /* FORK ENDE */ @@ -946,7 +952,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List,OrderingUnifyPair>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, cons); forks.add(fork); fork.fork(); } @@ -962,24 +968,29 @@ public class TypeUnifyTask extends RecursiveTask>> { }; /* FORK ENDE */ - for(TypeUnifyTask fork : forks) { + for(TypeUnify2Task fork : forks) { synchronized (this) { Set> fork_res = fork.join(); writeLog("Join " + new Integer(fork.thNo).toString()); - //noOfThread--; an das Ende von compute verschoben + //noOfThread--; an das Ende von compute verschoben + writeLog("fork_res: " + fork_res.toString()); + writeLog(new Boolean((isUndefinedPairSetSet(fork_res))).toString()); add_res.add(fork_res); + if (!isUndefinedPairSetSet(fork_res)) { + aParDef.add(fork.getNextSetElement()); + } }; } } else { if(parallel && (variance == -1) && noOfThread <= MaxNoOfThreads) { - Set forks = new HashSet<>(); + Set forks = new HashSet<>(); Set newEqOrig = new HashSet<>(eq); Set> newElemsOrig = new HashSet<>(elems); List,OrderingUnifyPair>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, cons); //forks.add(forkOrig); forkOrig.fork(); /* FORK ENDE */ @@ -997,7 +1008,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List,OrderingUnifyPair>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, cons); forks.add(fork); fork.fork(); } @@ -1013,12 +1024,17 @@ public class TypeUnifyTask extends RecursiveTask>> { }; /* FORK ENDE */ - for(TypeUnifyTask fork : forks) { + for(TypeUnify2Task fork : forks) { synchronized (this) { Set> fork_res = fork.join(); writeLog("Join " + new Integer(fork.thNo).toString()); //noOfThread--; an das Ende von compute verschoben + writeLog("fork_res: " + fork_res.toString()); + writeLog(new Boolean((isUndefinedPairSetSet(fork_res))).toString()); add_res.add(fork_res); + if (!isUndefinedPairSetSet(fork_res)) { + aParDef.add(fork.getNextSetElement()); + } }; } } else { @@ -1031,7 +1047,7 @@ public class TypeUnifyTask extends RecursiveTask>> { newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, cons); //forks.add(forkOrig); forkOrig.fork(); /* FORK ENDE */ @@ -1047,7 +1063,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List,OrderingUnifyPair>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, cons); forks.add(fork); fork.fork(); } @@ -1198,7 +1214,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } /* auskommentiert um alle Max und min Betrachtung auszuschalten ANFANG */ - if (!result.isEmpty() && !isUndefinedPairSetSet(res)) { + if (!result.isEmpty() && (!isUndefinedPairSetSet(res) || !aParDef.isEmpty())) { if (nextSetasList.iterator().hasNext() && nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("B")).findFirst().isPresent() && nextSetasList.size()>1) System.out.print(""); Iterator> nextSetasListIt = new ArrayList>(nextSetasList).iterator(); @@ -1232,18 +1248,24 @@ public class TypeUnifyTask extends RecursiveTask>> { System.out.println(""); writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); - while (nextSetasListIt.hasNext()) { - Set a_next = nextSetasListIt.next(); - if (a.equals(a_next) || - (oup.compare(a, a_next) == 1)) { - writeLog("Removed: " + a_next.toString()); - nextSetasList.remove(a_next); + writeLog("aParDef: " + aParDef.toString()); + aParDef.add(a); + Iterator> aParDefIt = aParDef.iterator(); + while(aParDefIt.hasNext()) { + Set a_new = aParDefIt.next(); + while (nextSetasListIt.hasNext()) { + Set a_next = nextSetasListIt.next(); + if (a_new.equals(a_next) || + (oup.compare(a_new, a_next) == 1)) { + writeLog("Removed: " + a_next.toString()); + nextSetasList.remove(a_next); + } + else { + writeLog("Not Removed: " + a_next.toString()); + System.out.println(""); + } } - else { - writeLog("Not Removed: " + a_next.toString()); - System.out.println(""); - } - } + } } else { if (variance == -1) { /* vorgezogen vor das if @@ -1274,19 +1296,25 @@ public class TypeUnifyTask extends RecursiveTask>> { System.out.println(""); writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); - while (nextSetasListIt.hasNext()) { - Set a_next = nextSetasListIt.next(); - if (a.equals(a_next) || - (oup.compare(a, a_next) == -1)) { - writeLog("Removed: " + a_next.toString()); - nextSetasList.remove(a_next); //PL geaendert 2019-01-09 - } - else { - System.out.println(""); - writeLog("Not Removed: " + a_next.toString()); + writeLog("aParDef: " + aParDef.toString()); + aParDef.add(a); + Iterator> aParDefIt = aParDef.iterator(); + while(aParDefIt.hasNext()) { + Set a_new = aParDefIt.next(); + while (nextSetasListIt.hasNext()) { + Set a_next = nextSetasListIt.next(); + if (a_new.equals(a_next) || + (oup.compare(a_new, a_next) == -1)) { + writeLog("Removed: " + a_next.toString()); + nextSetasList.remove(a_next); //PL geaendert 2019-01-09 + } + else { + System.out.println(""); + writeLog("Not Removed: " + a_next.toString()); } } } + } else { if (variance == 0) { writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); break; } @@ -1320,7 +1348,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } /* auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */ - if (isUndefinedPairSetSet(res)) { + if (isUndefinedPairSetSet(res) && aParDef.isEmpty()) { int nofstred= 0; Set abhSubst = res.stream() .map(b -> diff --git a/src/test/resources/bytecode/javFiles/Matrix.jav b/src/test/resources/bytecode/javFiles/Matrix.jav index 29505161..9e87c1e6 100644 --- a/src/test/resources/bytecode/javFiles/Matrix.jav +++ b/src/test/resources/bytecode/javFiles/Matrix.jav @@ -1,6 +1,6 @@ import java.util.Vector; import java.lang.Integer; -import java.lang.Float; +//import java.lang.Float; //import java.lang.Byte; //import java.lang.Boolean; diff --git a/src/test/resources/bytecode/javFiles/MatrixOP.jav b/src/test/resources/bytecode/javFiles/MatrixOP.jav index 828a270b..c78c42c7 100644 --- a/src/test/resources/bytecode/javFiles/MatrixOP.jav +++ b/src/test/resources/bytecode/javFiles/MatrixOP.jav @@ -1,6 +1,6 @@ import java.util.Vector; import java.lang.Integer; -//import java.lang.Byte; +import java.lang.Byte; import java.lang.Boolean; public class MatrixOP extends Vector> {