9 Commits

Author SHA1 Message Date
NoName11234
3951b8451b made constraintsetrepository volatile 2024-05-29 18:07:08 +02:00
NoName11234
a04be1336a fixed matrixk2 test 2024-05-23 19:30:22 +02:00
NoName11234
dee55f0b0f fixed missing oderConstraints 2024-05-23 10:50:23 +02:00
NoName11234
c58897f5ba implemented scalark3 test 2024-05-23 09:40:19 +02:00
NoName11234
c938e69c76 implemented scalark2test 2024-05-15 17:41:40 +02:00
NoName11234
1475661b84 Revert "added volatile for testing"
This reverts commit e397375d2a.
2024-05-02 17:57:29 +02:00
NoName11234
e397375d2a added volatile for testing 2024-05-02 17:33:00 +02:00
NoName11234
3bb7f38805 implemented ConstraintSetRepository 2024-05-01 20:05:28 +02:00
NoName11234
6a92b0f194 added class ConstraintSetRepository 2024-05-01 19:42:24 +02:00
5 changed files with 2067 additions and 18 deletions

View File

@@ -0,0 +1,21 @@
package de.dhbwstuttgart.typeinference.unify;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import java.util.HashSet;
import java.util.Set;
public class ConstraintSetRepository {
private Set<Integer> sets = new HashSet<>();
public boolean containsSet(Set<Set<UnifyPair>> set){
Integer hash = Integer.valueOf(set.hashCode());
if(sets.contains(hash)){
return true;
}else{
sets.add(hash);
return false;
}
}
}

View File

@@ -29,7 +29,7 @@ public class TypeUnify {
* @return
*/
public Set<Set<UnifyPair>> unify(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> 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<Set<UnifyPair>> res = unifyTask.join();
@@ -55,7 +55,7 @@ public class TypeUnify {
* @return
*/
public UnifyResultModel unifyAsync(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> 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<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> 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<Set<UnifyPair>> res = unifyTask.join();
@@ -109,7 +109,7 @@ public class TypeUnify {
* @return
*/
public Set<Set<UnifyPair>> unifyOderConstraints(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> 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<Set<UnifyPair>> res = unifyTask.compute();
try {

View File

@@ -24,13 +24,13 @@ public class TypeUnify2Task extends TypeUnifyTask {
List<Set<Constraint<UnifyPair>>> oderConstraints,
Set<UnifyPair> nextSetElement,
IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks,
Set<UnifyPair> methodSignatureConstraintUebergabe, Writer statistics) {
this(setToFlatten, eq, oderConstraints, nextSetElement, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraintUebergabe );
Set<UnifyPair> methodSignatureConstraintUebergabe, ConstraintSetRepository constraintSetRepository, Writer statistics) {
this(setToFlatten, eq, oderConstraints, nextSetElement, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraintUebergabe, constraintSetRepository);
}
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, Set<UnifyPair> methodSignatureConstraintUebergabe) {
super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, Set<UnifyPair> 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<Set<UnifyPair>> res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField, methodSignatureConstraintUebergabe);
Set<Set<UnifyPair>> res = new HashSet<>();
if(!constraintSetRepository.containsSet(setToFlatten)){
res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField, methodSignatureConstraintUebergabe);
}
/*if (isUndefinedPairSetSet(res)) {
return new HashSet<>(); }
else

View File

@@ -130,6 +130,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
volatile UnifyTaskModel usedTasks;
static Writer statistics;
protected volatile ConstraintSetRepository constraintSetRepository;
public TypeUnifyTask() {
rules = new RuleSet();
@@ -150,11 +151,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
*/
//statistics
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> 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<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> 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<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) {
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> 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<Set<Set<UnifyPair>>> {
this.urm = urm;
this.usedTasks = usedTasks;
this.usedTasks.add(this);
this.constraintSetRepository = constraintSetRepository;
}
}
@@ -819,8 +821,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
List<Set<Constraint<UnifyPair>>> 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<Set<UnifyPair>>> {
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
List<Set<Constraint<UnifyPair>>> 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<Set<Set<UnifyPair>>> {
}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.

File diff suppressed because it is too large Load Diff