forked from i21017/JavaTypeUnify
Compare commits
12 Commits
performanc
...
performanc
Author | SHA1 | Date | |
---|---|---|---|
|
8264dde8a2 | ||
|
e0709c9064 | ||
|
68db5f2b93 | ||
|
c723cbc566 | ||
|
de29192e09 | ||
|
678b2c9c96 | ||
|
30c6c5649a | ||
|
75e0504fee | ||
|
996ef1a735 | ||
|
2bb2f1a898 | ||
|
cf8653567c | ||
|
72908f6fb4 |
@@ -9,6 +9,7 @@ import java.util.Optional;
|
|||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
import java.util.concurrent.ForkJoinPool;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -35,6 +36,7 @@ import java.io.Writer;
|
|||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
|
|
||||||
import org.apache.commons.io.output.NullOutputStream;
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
|
import org.apache.commons.io.output.NullWriter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of the type inference rules.
|
* Implementation of the type inference rules.
|
||||||
@@ -43,14 +45,14 @@ import org.apache.commons.io.output.NullOutputStream;
|
|||||||
*/
|
*/
|
||||||
public class RuleSet implements IRuleSet{
|
public class RuleSet implements IRuleSet{
|
||||||
|
|
||||||
Writer logFile;
|
WriterActiveObject logFile;
|
||||||
|
|
||||||
public RuleSet() {
|
public RuleSet() {
|
||||||
super();
|
super();
|
||||||
logFile = new OutputStreamWriter(new NullOutputStream());
|
logFile = new WriterActiveObject(new NullWriter(), ForkJoinPool.commonPool());
|
||||||
}
|
}
|
||||||
|
|
||||||
RuleSet(Writer logFile) {
|
RuleSet(WriterActiveObject logFile) {
|
||||||
this.logFile = logFile;
|
this.logFile = logFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -866,14 +868,8 @@ public class RuleSet implements IRuleSet{
|
|||||||
UnifyType r = x.getRhsType();
|
UnifyType r = x.getRhsType();
|
||||||
if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
|
if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
|
||||||
} );
|
} );
|
||||||
try {
|
logFile.write("FUNgreater: " + pair + "\n");
|
||||||
logFile.write("FUNgreater: " + pair + "\n");
|
logFile.write("FUNred: " + result + "\n");
|
||||||
logFile.write("FUNred: " + result + "\n");
|
|
||||||
logFile.flush();
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
System.out.println("logFile-Error");
|
|
||||||
}
|
|
||||||
return Optional.of(result);
|
return Optional.of(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -916,14 +912,9 @@ public class RuleSet implements IRuleSet{
|
|||||||
UnifyType r = x.getRhsType();
|
UnifyType r = x.getRhsType();
|
||||||
if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
|
if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
|
||||||
} );
|
} );
|
||||||
try {
|
|
||||||
logFile.write("FUNgreater: " + pair + "\n");
|
logFile.write("FUNgreater: " + pair + "\n");
|
||||||
logFile.write("FUNgreater: " + result + "\n");
|
logFile.write("FUNgreater: " + result + "\n");
|
||||||
logFile.flush();
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
System.out.println("lofFile-Error");
|
|
||||||
}
|
|
||||||
return Optional.of(result);
|
return Optional.of(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -966,14 +957,9 @@ public class RuleSet implements IRuleSet{
|
|||||||
UnifyType r = x.getRhsType();
|
UnifyType r = x.getRhsType();
|
||||||
if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
|
if (r instanceof PlaceholderType) { ((PlaceholderType)r).disableWildcardtable(); }
|
||||||
} );
|
} );
|
||||||
try {
|
logFile.write("FUNgreater: " + pair + "\n");
|
||||||
logFile.write("FUNgreater: " + pair + "\n");
|
logFile.write("FUNsmaller: " + result + "\n");
|
||||||
logFile.write("FUNsmaller: " + result + "\n");
|
|
||||||
logFile.flush();
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
System.out.println("lofFile-Error");
|
|
||||||
}
|
|
||||||
return Optional.of(result);
|
return Optional.of(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -29,8 +29,8 @@ public class TypeUnify {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<Set<UnifyPair>> unify(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
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);
|
|
||||||
ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true);
|
ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true);
|
||||||
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, 0, ret, usedTasks);
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
Set<Set<UnifyPair>> res = unifyTask.join();
|
Set<Set<UnifyPair>> res = unifyTask.join();
|
||||||
try {
|
try {
|
||||||
@@ -55,8 +55,8 @@ public class TypeUnify {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public UnifyResultModel unifyAsync(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
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);
|
|
||||||
ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true);
|
ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true);
|
||||||
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, 0, ret, usedTasks);
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -73,9 +73,9 @@ public class TypeUnify {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public UnifyResultModel unifyParallel(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
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);
|
|
||||||
ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true);
|
ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true);
|
||||||
|
TypeUnifyTask unifyTask = //new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
||||||
|
new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, 0, ret, usedTasks, new WriterActiveObject(statistics, pool));
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
Set<Set<UnifyPair>> res = unifyTask.join();
|
Set<Set<UnifyPair>> res = unifyTask.join();
|
||||||
try {
|
try {
|
||||||
@@ -109,8 +109,7 @@ public class TypeUnify {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<Set<UnifyPair>> unifyOderConstraints(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
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, new WriterActiveObject(logFile, ForkJoinPool.commonPool()), log, 0, ret, usedTasks, new WriterActiveObject(statistics, ForkJoinPool.commonPool()));
|
||||||
unifyTask.statistics = statistics;
|
|
||||||
Set<Set<UnifyPair>> res = unifyTask.compute();
|
Set<Set<UnifyPair>> res = unifyTask.compute();
|
||||||
try {
|
try {
|
||||||
logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements +"\n");
|
logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements +"\n");
|
||||||
|
@@ -23,13 +23,13 @@ public class TypeUnify2Task extends TypeUnifyTask {
|
|||||||
TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq,
|
TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq,
|
||||||
List<Set<Constraint<UnifyPair>>> oderConstraints,
|
List<Set<Constraint<UnifyPair>>> oderConstraints,
|
||||||
Set<UnifyPair> nextSetElement,
|
Set<UnifyPair> nextSetElement,
|
||||||
IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks,
|
IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks,
|
||||||
Set<UnifyPair> methodSignatureConstraintUebergabe, Writer statistics) {
|
Set<UnifyPair> methodSignatureConstraintUebergabe, WriterActiveObject statistics) {
|
||||||
this(setToFlatten, eq, oderConstraints, nextSetElement, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraintUebergabe );
|
this(setToFlatten, eq, oderConstraints, nextSetElement, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraintUebergabe );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, Set<UnifyPair> methodSignatureConstraintUebergabe) {
|
||||||
super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
||||||
this.setToFlatten = setToFlatten;
|
this.setToFlatten = setToFlatten;
|
||||||
this.nextSetElement = nextSetElement;
|
this.nextSetElement = nextSetElement;
|
||||||
@@ -64,13 +64,6 @@ public class TypeUnify2Task extends TypeUnifyTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void closeLogFile() {
|
public void closeLogFile() {
|
||||||
|
logFile.close();
|
||||||
try {
|
|
||||||
logFile.close();
|
|
||||||
}
|
|
||||||
catch (IOException ioE) {
|
|
||||||
System.err.println("no log-File" + thNo);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,6 +13,7 @@ import java.util.List;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ForkJoinPool;
|
||||||
import java.util.concurrent.RecursiveTask;
|
import java.util.concurrent.RecursiveTask;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.BinaryOperator;
|
import java.util.function.BinaryOperator;
|
||||||
@@ -79,7 +80,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
protected boolean one = false;
|
protected boolean one = false;
|
||||||
|
|
||||||
public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/";
|
public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/";
|
||||||
Writer logFile;
|
protected WriterActiveObject logFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The implementation of setOps that will be used during the unification
|
* The implementation of setOps that will be used during the unification
|
||||||
@@ -129,7 +130,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
volatile UnifyTaskModel usedTasks;
|
volatile UnifyTaskModel usedTasks;
|
||||||
|
|
||||||
static Writer statistics;
|
static WriterActiveObject statistics;
|
||||||
|
|
||||||
public TypeUnifyTask() {
|
public TypeUnifyTask() {
|
||||||
rules = new RuleSet();
|
rules = new RuleSet();
|
||||||
@@ -150,14 +151,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
//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, Writer statistics) {
|
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, WriterActiveObject statistics) {
|
||||||
this(eq,oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
this(eq,oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
||||||
this.statistics = statistics;
|
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, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) {
|
||||||
synchronized (this) {
|
|
||||||
if(statistics==null){
|
if(statistics==null){
|
||||||
statistics = new NullWriter();
|
statistics = new WriterActiveObject(new NullWriter(), ForkJoinPool.commonPool());
|
||||||
}
|
}
|
||||||
this.eq = eq;
|
this.eq = eq;
|
||||||
//this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new));
|
//this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new));
|
||||||
@@ -183,9 +183,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
thNo = totalnoOfThread;
|
thNo = totalnoOfThread;
|
||||||
writeLog("thNo2 " + thNo);
|
writeLog("thNo2 " + thNo);
|
||||||
try {
|
try {
|
||||||
this.logFile = log ? new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "Thread_"+thNo))
|
if(log){
|
||||||
: new OutputStreamWriter(new NullOutputStream());
|
this.logFile = new WriterActiveObject(new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "Thread_"+thNo)), ForkJoinPool.commonPool());
|
||||||
logFile.write("");
|
}else{
|
||||||
|
this.logFile = new WriterActiveObject(new NullWriter(), ForkJoinPool.commonPool());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
System.err.println("log-File nicht vorhanden");
|
System.err.println("log-File nicht vorhanden");
|
||||||
@@ -209,7 +211,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
this.urm = urm;
|
this.urm = urm;
|
||||||
this.usedTasks = usedTasks;
|
this.usedTasks = usedTasks;
|
||||||
this.usedTasks.add(this);
|
this.usedTasks.add(this);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -266,12 +267,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
.filter(x -> x.size()>1)
|
.filter(x -> x.size()>1)
|
||||||
.collect(Collectors.toCollection(ArrayList::new));
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
Set<Set<UnifyPair>> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField, new HashSet<>());
|
Set<Set<UnifyPair>> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField, new HashSet<>());
|
||||||
try {
|
logFile.close();
|
||||||
logFile.close();
|
|
||||||
}
|
|
||||||
catch (IOException ioE) {
|
|
||||||
System.err.println("no log-File");
|
|
||||||
}
|
|
||||||
if (isUndefinedPairSetSet(res)) {
|
if (isUndefinedPairSetSet(res)) {
|
||||||
//fuer debug-Zwecke
|
//fuer debug-Zwecke
|
||||||
ArrayList al = res.stream().map(x -> x.stream().collect(Collectors.toCollection(ArrayList::new)))
|
ArrayList al = res.stream().map(x -> x.stream().collect(Collectors.toCollection(ArrayList::new)))
|
||||||
@@ -686,14 +683,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||||
int variance = 0;
|
|
||||||
|
|
||||||
/* Varianzbestimmung Anfang
|
|
||||||
* Oderconstraint, wenn entweder kein Basepair oder unterschiedliche Basepairs => oderConstraint = true;
|
|
||||||
* Varianz = 1 => Argumentvariable
|
|
||||||
* Varianz = -1 => Rückgabevariable
|
|
||||||
* Varianz = 0 => unklar
|
|
||||||
* Varianz = 2 => Operatoren oderConstraints */
|
|
||||||
ArrayList<UnifyPair> zeroNextElem = new ArrayList<>(nextSetasList.get(0));
|
ArrayList<UnifyPair> zeroNextElem = new ArrayList<>(nextSetasList.get(0));
|
||||||
UnifyPair fstBasePair = zeroNextElem.remove(0).getBasePair();
|
UnifyPair fstBasePair = zeroNextElem.remove(0).getBasePair();
|
||||||
Boolean oderConstraint = false;
|
Boolean oderConstraint = false;
|
||||||
@@ -711,9 +701,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
.filter(d -> d.isPresent())
|
.filter(d -> d.isPresent())
|
||||||
.map(e -> e.get())
|
.map(e -> e.get())
|
||||||
.findAny();
|
.findAny();
|
||||||
if (xi.isPresent()) {
|
|
||||||
variance = xi.get();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
oderConstraint = true;
|
oderConstraint = true;
|
||||||
@@ -723,29 +710,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
oderConstraint = true;
|
oderConstraint = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Varianz-Bestimmung Oder-Constraints
|
|
||||||
if (oderConstraint) {
|
|
||||||
if (printtag) System.out.println("nextSetasList " + nextSetasList);
|
|
||||||
Optional<Integer> optVariance =
|
|
||||||
nextSetasList.iterator()
|
|
||||||
.next()
|
|
||||||
.stream()
|
|
||||||
.filter(x -> x.getGroundBasePair().getLhsType() instanceof PlaceholderType &&
|
|
||||||
! (x.getRhsType() instanceof PlaceholderType) &&
|
|
||||||
x.getPairOp() == PairOperator.EQUALSDOT)
|
|
||||||
.map(x ->
|
|
||||||
((PlaceholderType)x.getGroundBasePair().getLhsType()).getVariance())
|
|
||||||
.reduce((n,m) -> { if ((n == 0) && (m==0)) return 0;
|
|
||||||
else if (n !=0) return n; //es muss mindestens eine Variance != 0 sein
|
|
||||||
else return m;
|
|
||||||
});
|
|
||||||
//Fuer Operatorenaufrufe wird variance auf 2 gesetzt.
|
|
||||||
//da kein Receiver existiert also kein x.getGroundBasePair().getLhsType() instanceof PlaceholderType
|
|
||||||
//Bei Varianz = 2 werden alle Elemente des Kartesischen Produkts abgearbeitet
|
|
||||||
variance = optVariance.isPresent() ? optVariance.get() : 2;
|
|
||||||
}
|
|
||||||
/* Varianzbestimmung Ende */
|
|
||||||
|
|
||||||
//writeLog("nextSetasList: " + nextSetasList.toString());
|
//writeLog("nextSetasList: " + nextSetasList.toString());
|
||||||
Set<UnifyPair> nextSetElem = nextSetasList.get(0);
|
Set<UnifyPair> nextSetElem = nextSetasList.get(0);
|
||||||
//writeLog("BasePair1: " + nextSetElem + " " + nextSetElem.iterator().next().getBasePair());
|
//writeLog("BasePair1: " + nextSetElem + " " + nextSetElem.iterator().next().getBasePair());
|
||||||
@@ -812,79 +776,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
writeLog("nextSet: " + nextSet.toString());
|
writeLog("nextSet: " + nextSet.toString());
|
||||||
writeLog("nextSetasList: " + nextSetasList.toString());
|
writeLog("nextSetasList: " + nextSetasList.toString());
|
||||||
|
|
||||||
/* staistics Nextvar an Hand Varianzbestimmung auskommentieren Anfang
|
|
||||||
if (variance == 1) {
|
|
||||||
a = oup.max(nextSetasList.iterator());
|
|
||||||
nextSetasList.remove(a);
|
|
||||||
if (oderConstraint) {
|
|
||||||
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)a).getExtendConstraint());
|
|
||||||
}
|
|
||||||
writeLog("nextSetasListOderConstraints 1: " + nextSetasListOderConstraints);
|
|
||||||
nextSetasListRest = new ArrayList<>(nextSetasList);
|
|
||||||
Iterator<Set<UnifyPair>> nextSetasListItRest = new ArrayList<Set<UnifyPair>>(nextSetasListRest).iterator();
|
|
||||||
while (nextSetasListItRest.hasNext()) {
|
|
||||||
Set<UnifyPair> a_next = nextSetasListItRest.next();
|
|
||||||
if (//a.equals(a_next) ||
|
|
||||||
(oup.compare(a, a_next) == 1)) {
|
|
||||||
nextSetasListRest.remove(a_next);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Alle maximale Elemente in nextSetasListRest bestimmen
|
|
||||||
//nur für diese wird parallele Berechnung angestossen.
|
|
||||||
nextSetasListRest = oup.maxElements(nextSetasListRest);
|
|
||||||
}
|
|
||||||
else if (variance == -1) {
|
|
||||||
a = oup.min(nextSetasList.iterator());
|
|
||||||
writeLog("Min: a in " + variance + " "+ a);
|
|
||||||
if (oderConstraint) {
|
|
||||||
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)a).getExtendConstraint());
|
|
||||||
}
|
|
||||||
writeLog("nextSetasListOderConstraints -1: " + nextSetasListOderConstraints);
|
|
||||||
nextSetasList.remove(a);
|
|
||||||
nextSetasListRest = new ArrayList<>(nextSetasList);
|
|
||||||
Iterator<Set<UnifyPair>> nextSetasListItRest = new ArrayList<Set<UnifyPair>>(nextSetasListRest).iterator();
|
|
||||||
while (nextSetasListItRest.hasNext()) {
|
|
||||||
Set<UnifyPair> a_next = nextSetasListItRest.next();
|
|
||||||
if (//a.equals(a_next) ||
|
|
||||||
(oup.compare(a, a_next) == -1)) {
|
|
||||||
nextSetasListRest.remove(a_next);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//Alle minimalen Elemente in nextSetasListRest bestimmen
|
|
||||||
//nur für diese wird parallele Berechnung angestossen.
|
|
||||||
nextSetasListRest = oup.minElements(nextSetasListRest);
|
|
||||||
}
|
|
||||||
else if (variance == 2) {
|
|
||||||
a = nextSetasList.remove(0);
|
|
||||||
|
|
||||||
//Fuer alle Elemente wird parallele Berechnung angestossen.
|
|
||||||
nextSetasListRest = new ArrayList<>(nextSetasList);
|
|
||||||
}
|
|
||||||
else if (variance == 0) {
|
|
||||||
//wenn a <. theta dann ist ein maximales Element sehr wahrscheinlich
|
|
||||||
//wenn theta <. a dann ist ein minimales Element sehr wahrscheinlich
|
|
||||||
if (!oderConstraint && optOrigPair != null && optOrigPair.isPresent()) {
|
|
||||||
if (optOrigPair.get().getBasePair().getLhsType() instanceof PlaceholderType) {
|
|
||||||
a = oup.max(nextSetasList.iterator());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
a = oup.min(nextSetasList.iterator());
|
|
||||||
}
|
|
||||||
nextSetasList.remove(a);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (oderConstraint) {
|
|
||||||
a = oup.max(nextSetasList.iterator());
|
|
||||||
nextSetasList.remove(a);
|
|
||||||
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)a).getExtendConstraint());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
a = nextSetasList.remove(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Nextvar an Hand Varianzbestimmung auskommentieren Ende */
|
|
||||||
a = nextSetasList.remove(0); //statisticsList
|
a = nextSetasList.remove(0); //statisticsList
|
||||||
|
|
||||||
//writeStatistics(a.toString());
|
//writeStatistics(a.toString());
|
||||||
@@ -895,7 +786,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
i++;
|
i++;
|
||||||
Set<Set<UnifyPair>> elems = new HashSet<Set<UnifyPair>>(oneElems);
|
Set<Set<UnifyPair>> elems = new HashSet<Set<UnifyPair>>(oneElems);
|
||||||
writeLog("a1: " + rekTiefe + " "+ "variance: "+ variance + " " + a.toString()+ "\n");
|
|
||||||
|
|
||||||
//Ergebnisvariable für den aktuelle Thread
|
//Ergebnisvariable für den aktuelle Thread
|
||||||
Set<Set<UnifyPair>> res = new HashSet<>();
|
Set<Set<UnifyPair>> res = new HashSet<>();
|
||||||
@@ -920,286 +810,49 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
/* Wenn parallel gearbeitet wird, wird je nach Varianz ein neuer Thread
|
/* Wenn parallel gearbeitet wird, wird je nach Varianz ein neuer Thread
|
||||||
* gestartet, der parallel weiterarbeitet.
|
* gestartet, der parallel weiterarbeitet.
|
||||||
*/
|
*/
|
||||||
if(parallel && (variance == 1)) {
|
if(parallel){
|
||||||
Set<TypeUnify2Task> forks = new HashSet<>();
|
Set<TypeUnify2Task> forks = new HashSet<>();
|
||||||
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
||||||
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
||||||
List<Set<Constraint<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
List<Set<Constraint<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
||||||
newElemsOrig.add(a);
|
newElemsOrig.add(a);
|
||||||
|
|
||||||
/* FORK ANFANG */
|
|
||||||
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraint);
|
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraint);
|
||||||
//forks.add(forkOrig);
|
//Überprüfen, ob das Set bereits berechnet wurde
|
||||||
synchronized(usedTasks) {
|
forkOrig.fork();
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
forkOrig.fork();
|
|
||||||
}
|
|
||||||
/* FORK ENDE */
|
|
||||||
|
|
||||||
synchronized (this) {
|
|
||||||
writeLog("a in " + variance + " "+ a);
|
|
||||||
writeLog("nextSetasListRest: " + nextSetasListRest.toString());
|
|
||||||
}
|
|
||||||
while (!nextSetasList.isEmpty()) {
|
while (!nextSetasList.isEmpty()) {
|
||||||
Set<UnifyPair> nSaL = nextSetasList.remove(0);
|
Set<UnifyPair> nSaL = nextSetasList.removeFirst();
|
||||||
synchronized (this) { //nextSetasList.remove(nSaL);
|
|
||||||
writeLog("1 RM" + nSaL.toString());
|
if (oderConstraint) {
|
||||||
|
nextSetasListOderConstraints.add(((Constraint<UnifyPair>) nSaL).getExtendConstraint());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!oderConstraint) {
|
|
||||||
|
|
||||||
/* statistics sameEq wird nicht betrachtet ANGFANG
|
|
||||||
//ueberpruefung ob zu a =. ty \in nSaL in sameEqSet ein Widerspruch besteht
|
|
||||||
if (!sameEqSet.isEmpty() && !checkNoContradiction(nSaL, sameEqSet, result)) {
|
|
||||||
nSaL = null;
|
|
||||||
noShortendElements++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
statistics sameEq wird nicht betrachtet ENDE */
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)nSaL).getExtendConstraint());
|
|
||||||
}
|
|
||||||
Set<UnifyPair> newEq = new HashSet<>(eq);
|
Set<UnifyPair> newEq = new HashSet<>(eq);
|
||||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||||
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||||
newElems.add(nSaL);
|
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));
|
||||||
forks.add(fork);
|
forks.add(fork);
|
||||||
synchronized(usedTasks) {
|
//Überprüfen, ob das Set bereits berechnet wurde
|
||||||
if (this.myIsCancelled()) {
|
fork.fork();
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
fork.fork();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
|
|
||||||
|
|
||||||
/* FORK ANFANG */
|
res = forkOrig.join();
|
||||||
synchronized (this) {
|
|
||||||
writeLog("wait "+ forkOrig.thNo);
|
|
||||||
res = forkOrig.join();
|
|
||||||
synchronized (usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//noOfThread++;
|
|
||||||
forkOrig.writeLog("final Orig 1");
|
|
||||||
forkOrig.closeLogFile();
|
|
||||||
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
|
|
||||||
writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString());
|
|
||||||
//noOfThread--; an das Ende von compute verschoben
|
|
||||||
//add_res.add(fork_res);
|
|
||||||
};
|
|
||||||
/* FORK ENDE */
|
|
||||||
|
|
||||||
forks.forEach(x -> writeLog("wait: " + x.thNo));
|
forks.forEach(x -> writeLog("wait: " + x.thNo));
|
||||||
for(TypeUnify2Task fork : forks) {
|
for (TypeUnify2Task fork : forks) {
|
||||||
synchronized (this) {
|
Set<Set<UnifyPair>> fork_res = new HashSet<>();
|
||||||
Set<Set<UnifyPair>> fork_res = fork.join();
|
fork_res = fork.join();
|
||||||
synchronized (usedTasks) {
|
add_res.add(fork_res);
|
||||||
if (this.myIsCancelled()) {
|
if (!isUndefinedPairSetSet(fork_res)) {
|
||||||
return new HashSet<>();
|
aParDef.add(fork.getNextSetElement());
|
||||||
}
|
|
||||||
}
|
|
||||||
//noOfThread++;
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
fork.writeLog("final 1");
|
|
||||||
fork.closeLogFile();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
//noOfThread++;
|
|
||||||
} else {
|
|
||||||
if(parallel && (variance == -1)) {
|
|
||||||
Set<TypeUnify2Task> forks = new HashSet<>();
|
|
||||||
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
|
||||||
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
|
||||||
List<Set<Constraint<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
|
||||||
newElemsOrig.add(a);
|
|
||||||
|
|
||||||
/* FORK ANFANG */
|
|
||||||
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, new HashSet<>(methodSignatureConstraint));
|
|
||||||
//forks.add(forkOrig);
|
|
||||||
synchronized(usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
forkOrig.fork();
|
|
||||||
}
|
|
||||||
/* FORK ENDE */
|
|
||||||
|
|
||||||
synchronized (this) {
|
|
||||||
writeLog("a in " + variance + " "+ a);
|
|
||||||
writeLog("nextSetasListRest: " + nextSetasListRest.toString());
|
|
||||||
}
|
|
||||||
while (!nextSetasList.isEmpty()) {
|
|
||||||
Set<UnifyPair> nSaL = nextSetasList.remove(0);
|
|
||||||
synchronized (this) { //nextSetasList.remove(nSaL);
|
|
||||||
writeLog("-1 RM" + nSaL.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!oderConstraint) {
|
|
||||||
/* statistics sameEq wird nicht betrachtet ANGFANG
|
|
||||||
//ueberpruefung ob zu a =. ty \in nSaL in sameEqSet ein Widerspruch besteht
|
|
||||||
if (!sameEqSet.isEmpty() && !checkNoContradiction(nSaL, sameEqSet, result)) {
|
|
||||||
nSaL = null;
|
|
||||||
noShortendElements++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
statistics sameEq wird nicht betrachtet ENDE */
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
nextSetasListOderConstraints.add(((Constraint<UnifyPair>)nSaL).getExtendConstraint());
|
|
||||||
}
|
|
||||||
Set<UnifyPair> newEq = new HashSet<>(eq);
|
|
||||||
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));
|
|
||||||
forks.add(fork);
|
|
||||||
synchronized(usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
fork.fork();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
|
}else{
|
||||||
|
elems.add(a);
|
||||||
/* FORK ANFANG */
|
//Überprüfen ob das Set bereits berechnet wurde
|
||||||
synchronized (this) {
|
|
||||||
writeLog("wait "+ forkOrig.thNo);
|
|
||||||
res = forkOrig.join();
|
|
||||||
synchronized (usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//noOfThread++;
|
|
||||||
forkOrig.writeLog("final Orig -1");
|
|
||||||
forkOrig.closeLogFile();
|
|
||||||
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
|
|
||||||
writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString());
|
|
||||||
//noOfThread--; an das Ende von compute verschoben
|
|
||||||
//add_res.add(fork_res);
|
|
||||||
};
|
|
||||||
/* FORK ENDE */
|
|
||||||
|
|
||||||
forks.forEach(x -> writeLog("wait: " + x.thNo));
|
|
||||||
for(TypeUnify2Task fork : forks) {
|
|
||||||
synchronized (this) {
|
|
||||||
Set<Set<UnifyPair>> fork_res = fork.join();
|
|
||||||
synchronized (usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//noOfThread++;
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
fork.writeLog("final -1");
|
|
||||||
fork.closeLogFile();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
//noOfThread++;
|
|
||||||
} else {
|
|
||||||
if(parallel && (variance == 2)) {
|
|
||||||
writeLog("var2einstieg");
|
|
||||||
Set<TypeUnify2Task> forks = new HashSet<>();
|
|
||||||
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
|
||||||
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
|
||||||
List<Set<Constraint<UnifyPair>>> newOderConstraintsOrig = new ArrayList<>(oderConstraints);
|
|
||||||
newElemsOrig.add(a);
|
|
||||||
|
|
||||||
/* FORK ANFANG */
|
|
||||||
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, new HashSet<>(methodSignatureConstraint));
|
|
||||||
//forks.add(forkOrig);
|
|
||||||
synchronized(usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
forkOrig.fork();
|
|
||||||
}
|
|
||||||
/* FORK ENDE */
|
|
||||||
|
|
||||||
synchronized (this) {
|
|
||||||
writeLog("a in " + variance + " "+ a);
|
|
||||||
writeLog("nextSetasListRest: " + nextSetasListRest.toString());
|
|
||||||
}
|
|
||||||
while (!nextSetasList.isEmpty()) {
|
|
||||||
Set<UnifyPair> nSaL = nextSetasList.remove(0);
|
|
||||||
//nextSetasList.remove(nSaL); //PL einkommentiert 20-02-03
|
|
||||||
Set<UnifyPair> newEq = new HashSet<>(eq);
|
|
||||||
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, methodSignatureConstraint);
|
|
||||||
forks.add(fork);
|
|
||||||
synchronized(usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
fork.fork();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
|
|
||||||
|
|
||||||
/* FORK ANFANG */
|
|
||||||
synchronized (this) {
|
|
||||||
writeLog("wait "+ forkOrig.thNo);
|
|
||||||
res = forkOrig.join();
|
|
||||||
synchronized (usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//noOfThread++;
|
|
||||||
forkOrig.writeLog("final Orig 2");
|
|
||||||
forkOrig.closeLogFile();
|
|
||||||
//Set<Set<UnifyPair>> fork_res = forkOrig.join();
|
|
||||||
writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString());
|
|
||||||
//noOfThread--; an das Ende von compute verschoben
|
|
||||||
//add_res.add(fork_res); //vermutlich falsch
|
|
||||||
};
|
|
||||||
/* FORK ENDE */
|
|
||||||
forks.forEach(x -> writeLog("wait: " + x.thNo));
|
|
||||||
for(TypeUnify2Task fork : forks) {
|
|
||||||
synchronized (this) {
|
|
||||||
Set<Set<UnifyPair>> fork_res = fork.join();
|
|
||||||
synchronized (usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//noOfThread++;
|
|
||||||
writeLog("Join " + new Integer(fork.thNo).toString());
|
|
||||||
//noOfThread--; an das Ende von compute verschoben
|
|
||||||
add_res.add(fork_res);
|
|
||||||
fork.writeLog("final 2");
|
|
||||||
fork.closeLogFile();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
//noOfThread++;
|
|
||||||
} else {//parallel = false oder MaxNoOfThreads ist erreicht, sequentiell weiterarbeiten
|
|
||||||
elems.add(a); //PL 2019-01-16 muss das wirklich hin steht schon in Zeile 859 ja braucht man siehe Zeile 859
|
|
||||||
res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe, new HashSet<>(methodSignatureConstraint));
|
res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe, new HashSet<>(methodSignatureConstraint));
|
||||||
}}}
|
}
|
||||||
|
|
||||||
//Ab hier alle parallele Berechnungen wieder zusammengeführt.
|
//Ab hier alle parallele Berechnungen wieder zusammengeführt.
|
||||||
//if (hilf == 1)
|
//if (hilf == 1)
|
||||||
@@ -2598,33 +2251,15 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void writeLog(String str) {
|
void writeLog(String str) {
|
||||||
synchronized ( this ) {
|
|
||||||
if (log && finalresult) {
|
if (log && finalresult) {
|
||||||
try {
|
logFile.write("Thread no.:" + thNo + "\n" + "parallel:" + parallel + "\n" + str+"\n\n");
|
||||||
logFile.write("Thread no.:" + thNo + "\n");
|
}
|
||||||
logFile.write("parallel:" + parallel + "\n");
|
|
||||||
logFile.write(str+"\n\n");
|
|
||||||
logFile.flush();
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
System.err.println("kein LogFile");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeStatistics(String str) {
|
void writeStatistics(String str) {
|
||||||
if (finalresult) {
|
if (finalresult) {
|
||||||
synchronized ( this ) {
|
statistics.write("Thread No. " + thNo + ": " + str + "\n");
|
||||||
try {
|
}
|
||||||
statistics.write("Thread No. " + thNo + ": " + str + "\n");
|
|
||||||
statistics.flush();
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
System.err.println("kein StatisticsFile");
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,53 @@
|
|||||||
|
package de.dhbwstuttgart.typeinference.unify;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.util.concurrent.ForkJoinPool;
|
||||||
|
|
||||||
|
public class WriterActiveObject {
|
||||||
|
private Writer writer;
|
||||||
|
private ForkJoinPool pool;
|
||||||
|
|
||||||
|
public WriterActiveObject(Writer writer, ForkJoinPool pool){
|
||||||
|
this.writer = writer;
|
||||||
|
this.pool = pool;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close(){
|
||||||
|
pool.execute(()->{
|
||||||
|
try {
|
||||||
|
writer.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write(String message){
|
||||||
|
pool.execute(()->{
|
||||||
|
try {
|
||||||
|
writer.write(message);
|
||||||
|
writer.flush();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeNonThreaded(String message){
|
||||||
|
try {
|
||||||
|
writer.write(message);
|
||||||
|
writer.flush();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeNonThreaded(){
|
||||||
|
try {
|
||||||
|
writer.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,13 +1,10 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify.model;
|
package de.dhbwstuttgart.typeinference.unify.model;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
|
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
|
||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
@@ -23,7 +20,7 @@ public final class PlaceholderType extends UnifyType{
|
|||||||
* Static list containing the names of all existing placeholders.
|
* Static list containing the names of all existing placeholders.
|
||||||
* Used for generating fresh placeholders.
|
* Used for generating fresh placeholders.
|
||||||
*/
|
*/
|
||||||
public static final ArrayList<String> EXISTING_PLACEHOLDERS = new ArrayList<String>();
|
public static final Set<String> EXISTING_PLACEHOLDERS = ConcurrentHashMap.newKeySet();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prefix of auto-generated placeholder names.
|
* Prefix of auto-generated placeholder names.
|
||||||
@@ -96,7 +93,7 @@ public final class PlaceholderType extends UnifyType{
|
|||||||
* A user could later instantiate a type using the same name that is equivalent to this type.
|
* A user could later instantiate a type using the same name that is equivalent to this type.
|
||||||
* @return A fresh placeholder type.
|
* @return A fresh placeholder type.
|
||||||
*/
|
*/
|
||||||
public synchronized static PlaceholderType freshPlaceholder() {
|
public static PlaceholderType freshPlaceholder() {
|
||||||
String name = nextName + (char) (rnd.nextInt(22) + 97); // Returns random char between 'a' and 'z'
|
String name = nextName + (char) (rnd.nextInt(22) + 97); // Returns random char between 'a' and 'z'
|
||||||
// Add random chars while the name is in use.
|
// Add random chars while the name is in use.
|
||||||
while(EXISTING_PLACEHOLDERS.contains(name)) {
|
while(EXISTING_PLACEHOLDERS.contains(name)) {
|
||||||
|
Reference in New Issue
Block a user