From 3bb7f38805ee3f1598069da7f3583bba735edf1a Mon Sep 17 00:00:00 2001 From: NoName11234 <47484268+NoName11234@users.noreply.github.com> Date: Wed, 1 May 2024 20:05:28 +0200 Subject: [PATCH] implemented ConstraintSetRepository --- .../typeinference/unify/TypeUnify.java | 8 ++++---- .../typeinference/unify/TypeUnify2Task.java | 14 +++++++++----- .../typeinference/unify/TypeUnifyTask.java | 18 ++++++++++-------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index f988235..83be39e 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -29,7 +29,7 @@ public class TypeUnify { * @return */ public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks, new ConstraintSetRepository()); ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true); pool.invoke(unifyTask); Set> res = unifyTask.join(); @@ -55,7 +55,7 @@ public class TypeUnify { * @return */ public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks, new ConstraintSetRepository()); ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true); pool.invoke(unifyTask); return ret; @@ -74,7 +74,7 @@ public class TypeUnify { */ public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { TypeUnifyTask unifyTask = //new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); - new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks, statistics); + new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks, new ConstraintSetRepository(), statistics); ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true); pool.invoke(unifyTask); Set> res = unifyTask.join(); @@ -109,7 +109,7 @@ public class TypeUnify { * @return */ public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret, usedTasks); + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret, usedTasks, new ConstraintSetRepository()); unifyTask.statistics = statistics; Set> res = unifyTask.compute(); try { diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index 61d6ce8..edab1ca 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -24,13 +24,13 @@ public class TypeUnify2Task extends TypeUnifyTask { List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, - Set methodSignatureConstraintUebergabe, Writer statistics) { - this(setToFlatten, eq, oderConstraints, nextSetElement, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraintUebergabe ); + Set methodSignatureConstraintUebergabe, ConstraintSetRepository constraintSetRepository, Writer statistics) { + this(setToFlatten, eq, oderConstraints, nextSetElement, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraintUebergabe, constraintSetRepository); } - public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, Set methodSignatureConstraintUebergabe) { - super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); + public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, Set methodSignatureConstraintUebergabe, ConstraintSetRepository constraintSetRepository) { + super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, constraintSetRepository); this.setToFlatten = setToFlatten; this.nextSetElement = nextSetElement; this.methodSignatureConstraintUebergabe = methodSignatureConstraintUebergabe; @@ -46,7 +46,11 @@ public class TypeUnify2Task extends TypeUnifyTask { System.out.println("two"); } one = true; - Set> res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField, methodSignatureConstraintUebergabe); + Set> res = new HashSet<>(); + + if(!constraintSetRepository.containsSet(setToFlatten)){ + res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField, methodSignatureConstraintUebergabe); + } /*if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } else diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 9efd728..54b07cb 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -130,6 +130,7 @@ public class TypeUnifyTask extends RecursiveTask>> { volatile UnifyTaskModel usedTasks; static Writer statistics; + protected ConstraintSetRepository constraintSetRepository; public TypeUnifyTask() { rules = new RuleSet(); @@ -150,11 +151,11 @@ public class TypeUnifyTask extends RecursiveTask>> { */ //statistics - public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, Writer statistics) { - this(eq,oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); + public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, ConstraintSetRepository constraintSetRepository, Writer statistics) { + this(eq,oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, constraintSetRepository); this.statistics = statistics; } - public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) { + public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, ConstraintSetRepository constraintSetRepository) { synchronized (this) { if(statistics==null){ statistics = new NullWriter(); @@ -209,6 +210,7 @@ public class TypeUnifyTask extends RecursiveTask>> { this.urm = urm; this.usedTasks = usedTasks; this.usedTasks.add(this); + this.constraintSetRepository = constraintSetRepository; } } @@ -819,8 +821,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElemsOrig = new HashSet<>(elems); List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); newElemsOrig.add(a); - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraint); - //Überprüfen, ob das Set bereits berechnet wurde + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraint, constraintSetRepository); forkOrig.fork(); while (!nextSetasList.isEmpty()) { @@ -834,9 +835,8 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, new HashSet<>(methodSignatureConstraint)); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, new HashSet<>(methodSignatureConstraint), constraintSetRepository); forks.add(fork); - //Überprüfen, ob das Set bereits berechnet wurde fork.fork(); } @@ -854,7 +854,9 @@ public class TypeUnifyTask extends RecursiveTask>> { }else{ elems.add(a); //Überprüfen ob das Set bereits berechnet wurde - res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe, new HashSet<>(methodSignatureConstraint)); + if(!constraintSetRepository.containsSet(elems)){ + res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe, new HashSet<>(methodSignatureConstraint)); + } } //Ab hier alle parallele Berechnungen wieder zusammengeführt.