diff options
author | OszkarSemerath <oszkar.semerath@gmail.com> | 2018-11-07 15:26:33 +0100 |
---|---|---|
committer | OszkarSemerath <oszkar.semerath@gmail.com> | 2018-11-07 15:26:33 +0100 |
commit | 0120fd08f1a87e2793d886f9e2f581c45f80c3c0 (patch) | |
tree | 8dae5351b6fad73b96a30faf987f2881590e8b04 /Solvers | |
parent | Fix boolean element mapping handling in logic structures for VS (diff) | |
download | VIATRA-Generator-0120fd08f1a87e2793d886f9e2f581c45f80c3c0.tar.gz VIATRA-Generator-0120fd08f1a87e2793d886f9e2f581c45f80c3c0.tar.zst VIATRA-Generator-0120fd08f1a87e2793d886f9e2f581c45f80c3c0.zip |
Nodewise and graphwise diversity added
Diffstat (limited to 'Solvers')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/SolutionStoreWithDiversityDescriptor.xtend | 61 |
1 files changed, 54 insertions, 7 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 index bcdc8423..a6e49d53 100644 --- 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 | |||
@@ -6,18 +6,31 @@ import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.DiversityDescriptor | |||
6 | import java.util.LinkedList | 6 | import java.util.LinkedList |
7 | import java.util.List | 7 | import java.util.List |
8 | import org.eclipse.viatra.dse.base.ThreadContext | 8 | import org.eclipse.viatra.dse.base.ThreadContext |
9 | import java.util.HashSet | ||
10 | import java.util.Set | ||
11 | |||
12 | enum DiversityGranularity { | ||
13 | Nodewise, Graphwise | ||
14 | } | ||
9 | 15 | ||
10 | class SolutionStoreWithDiversityDescriptor { | 16 | class SolutionStoreWithDiversityDescriptor { |
11 | val DiversityDescriptor descriptor | 17 | val DiversityDescriptor descriptor |
18 | DiversityGranularity granularity | ||
12 | val PartialInterpretation2ImmutableTypeLattice solutionCoder = new PartialInterpretation2ImmutableTypeLattice | 19 | val PartialInterpretation2ImmutableTypeLattice solutionCoder = new PartialInterpretation2ImmutableTypeLattice |
13 | val List<Integer> solutionCodeList = new LinkedList | 20 | val Set<Integer> solutionCodeList = new HashSet |
14 | 21 | ||
15 | var long runtime | 22 | var long runtime |
16 | var int allCheck | 23 | var int allCheck |
17 | var int successfulCheck | 24 | var int successfulCheck |
18 | 25 | ||
19 | public new(DiversityDescriptor descriptor) { | 26 | new(DiversityDescriptor descriptor) { |
20 | this.descriptor = descriptor | 27 | if(descriptor.ensureDiversity) { |
28 | this.descriptor = descriptor | ||
29 | this.granularity = DiversityGranularity::Nodewise | ||
30 | } else { | ||
31 | this.descriptor = null | ||
32 | this.granularity = DiversityGranularity::Nodewise | ||
33 | } | ||
21 | } | 34 | } |
22 | 35 | ||
23 | def public isActive() { | 36 | def public isActive() { |
@@ -35,13 +48,32 @@ class SolutionStoreWithDiversityDescriptor { | |||
35 | if(active) { | 48 | if(active) { |
36 | val start = System.nanoTime | 49 | val start = System.nanoTime |
37 | val model = context.model as PartialInterpretation | 50 | val model = context.model as PartialInterpretation |
38 | val code = solutionCoder.createRepresentation(model, | 51 | var boolean isDifferent |
52 | if(this.granularity == DiversityGranularity::Graphwise) { | ||
53 | val code = solutionCoder.createRepresentation(model, | ||
39 | descriptor.range, | 54 | descriptor.range, |
40 | descriptor.parallels, | 55 | descriptor.parallels, |
41 | descriptor.maxNumber, | 56 | descriptor.maxNumber, |
42 | descriptor.relevantTypes, | 57 | descriptor.relevantTypes, |
43 | descriptor.relevantRelations).modelRepresentation.hashCode | 58 | descriptor.relevantRelations).modelRepresentation.hashCode |
44 | val isDifferent = solutionCodeList.forall[previous | ! code.equals(previous)] | 59 | |
60 | isDifferent = !solutionCodeList.contains(code) | ||
61 | } else if(this.granularity == DiversityGranularity::Nodewise){ | ||
62 | val codes = solutionCoder.createRepresentation(model, | ||
63 | descriptor.range, | ||
64 | descriptor.parallels, | ||
65 | descriptor.maxNumber, | ||
66 | descriptor.relevantTypes, | ||
67 | descriptor.relevantRelations).modelRepresentation.keySet.map[hashCode].toList | ||
68 | val differentCodes = codes.filter[!solutionCodeList.contains(it)] | ||
69 | //println(differentCodes.size) | ||
70 | |||
71 | isDifferent = differentCodes.size>=3 | ||
72 | if(isDifferent)println(differentCodes.size) | ||
73 | } else { | ||
74 | throw new UnsupportedOperationException('''Unsupported diversity type: «this.granularity»''') | ||
75 | } | ||
76 | |||
45 | runtime += System.nanoTime - start | 77 | runtime += System.nanoTime - start |
46 | allCheck++ | 78 | allCheck++ |
47 | if(isDifferent) { successfulCheck++ } | 79 | if(isDifferent) { successfulCheck++ } |
@@ -61,13 +93,28 @@ class SolutionStoreWithDiversityDescriptor { | |||
61 | if(active) { | 93 | if(active) { |
62 | val start = System.nanoTime | 94 | val start = System.nanoTime |
63 | val model = context.model as PartialInterpretation | 95 | val model = context.model as PartialInterpretation |
64 | val code = solutionCoder.createRepresentation(model, | 96 | if(this.granularity == DiversityGranularity::Graphwise) { |
97 | val code = solutionCoder.createRepresentation(model, | ||
65 | descriptor.range, | 98 | descriptor.range, |
66 | descriptor.parallels, | 99 | descriptor.parallels, |
67 | descriptor.maxNumber, | 100 | descriptor.maxNumber, |
68 | descriptor.relevantTypes, | 101 | descriptor.relevantTypes, |
69 | descriptor.relevantRelations).modelRepresentation.hashCode | 102 | descriptor.relevantRelations).modelRepresentation.hashCode |
70 | solutionCodeList += code | 103 | |
104 | solutionCodeList += code.hashCode | ||
105 | } else if(this.granularity == DiversityGranularity::Nodewise){ | ||
106 | val codes = solutionCoder.createRepresentation(model, | ||
107 | descriptor.range, | ||
108 | descriptor.parallels, | ||
109 | descriptor.maxNumber, | ||
110 | descriptor.relevantTypes, | ||
111 | descriptor.relevantRelations).modelRepresentation.keySet.map[hashCode].toList | ||
112 | |||
113 | solutionCodeList += codes.map[it.hashCode] | ||
114 | } else { | ||
115 | throw new UnsupportedOperationException('''Unsupported diversity type: «this.granularity»''') | ||
116 | } | ||
117 | |||
71 | runtime += System.nanoTime - start | 118 | runtime += System.nanoTime - start |
72 | } | 119 | } |
73 | } | 120 | } |