1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
package hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse
import com.google.common.collect.ImmutableList
import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation
import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration
import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.IThreeValuedObjective
import java.util.Comparator
import java.util.List
import org.eclipse.viatra.dse.base.ThreadContext
import org.eclipse.viatra.dse.objectives.Comparators
import org.eclipse.viatra.dse.objectives.IObjective
import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PrimitiveElement
class ModelGenerationCompositeObjective implements IThreeValuedObjective {
val IObjective scopeObjective
val List<UnfinishedMultiplicityObjective> unfinishedMultiplicityObjectives
val UnfinishedWFObjective unfinishedWFObjective
var PartialInterpretation model = null
val int scopeWeight
val int conaintmentWeight
val int nonContainmentWeight
val int unfinishedWFWeight
new(
IObjective scopeObjective,
List<UnfinishedMultiplicityObjective> unfinishedMultiplicityObjectives,
UnfinishedWFObjective unfinishedWFObjective,
ViatraReasonerConfiguration configuration)
{
this(
scopeObjective, unfinishedMultiplicityObjectives, unfinishedWFObjective,
configuration.scopeWeight, configuration.conaintmentWeight, configuration.nonContainmentWeight,
configuration.unfinishedWFWeight
)
}
new(
IObjective scopeObjective,
List<UnfinishedMultiplicityObjective> unfinishedMultiplicityObjectives,
UnfinishedWFObjective unfinishedWFObjective,
int scopeWeight, int conaintmentWeight, int nonContainmentWeight, int unfinishedWFWeight)
{
this.scopeObjective = scopeObjective
this.unfinishedMultiplicityObjectives = unfinishedMultiplicityObjectives
this.unfinishedWFObjective = unfinishedWFObjective
this.scopeWeight = scopeWeight
this.conaintmentWeight = conaintmentWeight
this.nonContainmentWeight = nonContainmentWeight
this.unfinishedWFWeight = unfinishedWFWeight
}
override init(ThreadContext context) {
model = context.model as PartialInterpretation
this.scopeObjective.init(context)
this.unfinishedMultiplicityObjectives.forEach[it.init(context)]
this.unfinishedWFObjective.init(context)
}
override createNew() {
return new ModelGenerationCompositeObjective(
scopeObjective.createNew,
ImmutableList.copyOf(unfinishedMultiplicityObjectives.map[createNew as UnfinishedMultiplicityObjective]),
unfinishedWFObjective.createNew as UnfinishedWFObjective,
scopeWeight, conaintmentWeight, nonContainmentWeight, unfinishedWFWeight
)
}
override getComparator() { Comparators.LOWER_IS_BETTER }
override getFitness(ThreadContext context) {
val scopeFitnes = scopeObjective.getFitness(context)
val unfinishedWFsFitness = unfinishedWFObjective.getFitness(context)
var containmentMultiplicity = 0.0
var nonContainmentMultiplicity = 0.0
for(multiplicityObjective : unfinishedMultiplicityObjectives) {
val multiplicity = multiplicityObjective.getFitness(context)
// println(multiplicityObjective.name + "=" + multiplicity)
if(multiplicityObjective.containment) {
containmentMultiplicity+=multiplicity
} else {
nonContainmentMultiplicity+=multiplicity
}
}
var sum = 0.0
sum += scopeFitnes*scopeWeight
sum += containmentMultiplicity*conaintmentWeight
sum += nonContainmentMultiplicity*nonContainmentWeight
sum += unfinishedWFsFitness*unfinishedWFWeight
// println('''scope=«scopeFitnes», containment=«containmentMultiplicity», nonContainment=«nonContainmentMultiplicity», wf=«unfinishedWFsFitness», sum=«sum»''')
return sum
}
override getWorstPossibleFitness(ThreadContext threadContext) {
Double.POSITIVE_INFINITY
}
override getBestPossibleFitness(ThreadContext threadContext) {
0.0
}
override getLevel() { 2 }
override getName() { "CompositeUnfinishednessObjective" }
override isHardObjective() { true }
override satisifiesHardObjective(Double fitness) { fitness < 0.01 }
override setComparator(Comparator<Double> comparator) {
throw new UnsupportedOperationException("Model generation objective comparator cannot be set.")
}
override setLevel(int level) {
throw new UnsupportedOperationException("Model generation objective level cannot be set.")
}
}
|