diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/SolutionStoreWithDiversityDescriptor.xtend')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/SolutionStoreWithDiversityDescriptor.xtend | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/SolutionStoreWithDiversityDescriptor.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/SolutionStoreWithDiversityDescriptor.xtend new file mode 100644 index 00000000..ca39cada --- /dev/null +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/SolutionStoreWithDiversityDescriptor.xtend | |||
@@ -0,0 +1,77 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.AbstractNodeDescriptor | ||
4 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.NeighbourhoodWithTraces | ||
5 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.PartialInterpretation2ImmutableTypeLattice | ||
6 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.DiversityDescriptor | ||
8 | import java.util.LinkedList | ||
9 | import java.util.List | ||
10 | import java.util.Map | ||
11 | import org.eclipse.viatra.dse.base.ThreadContext | ||
12 | |||
13 | class SolutionStoreWithDiversityDescriptor { | ||
14 | val DiversityDescriptor descriptor | ||
15 | val PartialInterpretation2ImmutableTypeLattice solutionCoder = new PartialInterpretation2ImmutableTypeLattice | ||
16 | val List<NeighbourhoodWithTraces<Map<? extends AbstractNodeDescriptor, Integer>, AbstractNodeDescriptor>> solutionCodeList = new LinkedList | ||
17 | |||
18 | var long runtime | ||
19 | var int allCheck | ||
20 | var int successfulCheck | ||
21 | |||
22 | public new(DiversityDescriptor descriptor) { | ||
23 | this.descriptor = descriptor | ||
24 | } | ||
25 | |||
26 | def public isActive() { | ||
27 | descriptor!==null | ||
28 | } | ||
29 | |||
30 | def getSumRuntime() { | ||
31 | return runtime | ||
32 | } | ||
33 | def getSuccessRate() { | ||
34 | return successfulCheck as double / allCheck | ||
35 | } | ||
36 | |||
37 | def isDifferent(ThreadContext context) { | ||
38 | if(active) { | ||
39 | val start = System.nanoTime | ||
40 | val model = context.model as PartialInterpretation | ||
41 | val code = solutionCoder.createRepresentation(model, | ||
42 | descriptor.range, | ||
43 | descriptor.parallels, | ||
44 | descriptor.maxNumber, | ||
45 | descriptor.relevantTypes, | ||
46 | descriptor.relevantRelations) | ||
47 | val isDifferent = solutionCodeList.forall[previous | ! code.equals(previous)] | ||
48 | runtime += System.nanoTime - start | ||
49 | allCheck++ | ||
50 | if(isDifferent) { successfulCheck++ } | ||
51 | return isDifferent | ||
52 | } else { | ||
53 | allCheck++ | ||
54 | successfulCheck++ | ||
55 | return true | ||
56 | } | ||
57 | } | ||
58 | |||
59 | def canBeDifferent(ThreadContext context) { | ||
60 | return true | ||
61 | } | ||
62 | |||
63 | def newSolution(ThreadContext context) { | ||
64 | if(active) { | ||
65 | val start = System.nanoTime | ||
66 | val model = context.model as PartialInterpretation | ||
67 | val code = solutionCoder.createRepresentation(model, | ||
68 | descriptor.range, | ||
69 | descriptor.parallels, | ||
70 | descriptor.maxNumber, | ||
71 | descriptor.relevantTypes, | ||
72 | descriptor.relevantRelations) | ||
73 | solutionCodeList += code | ||
74 | runtime += System.nanoTime - start | ||
75 | } | ||
76 | } | ||
77 | } \ No newline at end of file | ||