diff options
author | 2020-04-28 00:29:00 -0400 | |
---|---|---|
committer | 2020-04-28 00:29:00 -0400 | |
commit | 68a0667e862f0714410aafbb499a95a03f5bee23 (patch) | |
tree | 34b7d690dae5b9dd8f188fc44802a02f8dd9a64a /Tests/MODELS2020-CaseStudies/case.study.pledge.run/src | |
parent | rename Pledge Case Studies and add familyTree case study (diff) | |
download | VIATRA-Generator-68a0667e862f0714410aafbb499a95a03f5bee23.tar.gz VIATRA-Generator-68a0667e862f0714410aafbb499a95a03f5bee23.tar.zst VIATRA-Generator-68a0667e862f0714410aafbb499a95a03f5bee23.zip |
Able to run Pledge Case Study
Diffstat (limited to 'Tests/MODELS2020-CaseStudies/case.study.pledge.run/src')
3 files changed, 622 insertions, 0 deletions
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/queries/NewOCLFileX.ocl b/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/queries/NewOCLFileX.ocl new file mode 100644 index 00000000..66ae728e --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/queries/NewOCLFileX.ocl | |||
@@ -0,0 +1,45 @@ | |||
1 | import 'file:/Users/Aren Babikian/git/VIATRA-Attributes/case.study.a.model/model/Taxation.ecore' | ||
2 | |||
3 | package Taxation | ||
4 | |||
5 | --context Income inv inv8: | ||
6 | --if(not self.income_type.oclIsTypeOf(Employment_Income)) then | ||
7 | --self.details->forAll(d| d.distance = 0) | ||
8 | --else | ||
9 | --self.details->forAll(d| d.distance >= 0.0 and d.distance <= 100) | ||
10 | --endif | ||
11 | -- | ||
12 | --context Legal_Union_Record inv inv490: | ||
13 | --self.individual_A.oclIsKindOf(Tax_Payer) | ||
14 | -- | ||
15 | --context Legal_Union_Record inv inv491: | ||
16 | --self.individual_B->forAll(i | i.oclIsKindOf(Physical_Person) ) | ||
17 | -- | ||
18 | --context Legal_Union_Record inv inv492: | ||
19 | --self.individual_B->forAll(i | not i.oclIsTypeOf(Dependent) ) | ||
20 | -- | ||
21 | --context Legal_Union_Record inv inv493: | ||
22 | --self.individual_A <> self.individual_B | ||
23 | -- | ||
24 | --context Tax_Payer inv inv13: | ||
25 | -- self.addresses->exists( hab_add:Address | hab_add.oclIsTypeOf(Habitual_Address) = true and hab_add.country=Country::ZZ) | ||
26 | --implies | ||
27 | -- self.oclIsTypeOf(Resident_Tax_Payer) | ||
28 | |||
29 | context Income inv inv7: | ||
30 | let val:Real =self.details->asOrderedSet()->first().distance in | ||
31 | self.details->forAll(d: Income_Detail|d.distance = val) | ||
32 | |||
33 | --context External_Allowance inv inv15: | ||
34 | --let child:Dependent = self.person in | ||
35 | --let h:Household = Household.allInstances()->select(children->includes(child))->asOrderedSet()->first() in | ||
36 | --let t1:Set(Physical_Person) = Set{h.parents.individual_A}->union(h.parents.individual_B)->select(oclIsKindOf(Tax_Payer)) in | ||
37 | --if(t1->size()=1) then | ||
38 | --self.reciver = t1->asOrderedSet()->first() | ||
39 | --else | ||
40 | --self.reciver = t1->asOrderedSet()->at(2) or self.reciver = t1->asOrderedSet()->at(1) | ||
41 | --endif | ||
42 | |||
43 | |||
44 | |||
45 | endpackage \ No newline at end of file | ||
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/queries/case_study_A.vql b/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/queries/case_study_A.vql new file mode 100644 index 00000000..f736ec58 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/queries/case_study_A.vql | |||
@@ -0,0 +1,334 @@ | |||
1 | package queries | ||
2 | |||
3 | import "http:///TaxCard.ecore" | ||
4 | |||
5 | //AttributeRemoved -> DF | ||
6 | |||
7 | //inv1-External_Allowance.amount is a derived feature (TODOcheck) | ||
8 | //inv2-Tax_Card.income.taxPayer.taxesDue is a derived feature (TODOcheck) | ||
9 | |||
10 | //inv3-multiplicity adjusted | ||
11 | @Constraint(message = "inv03", severity = "error", key = {dep}) | ||
12 | pattern inv03(dep : Dependent) { | ||
13 | find x_inv03_eligAll(dep); | ||
14 | neg find x_inv03_hasAll(dep); | ||
15 | } or { | ||
16 | Dependent.birth_year(dep, by); | ||
17 | check(2018-by > 21); | ||
18 | Dependent.continued_studies(dep, false); | ||
19 | Dependent.allowances(dep, _); | ||
20 | } | ||
21 | pattern x_inv03_eligAll(dep : Dependent) { | ||
22 | Dependent.birth_year(dep, by); | ||
23 | check(2018-by <= 21); | ||
24 | } or { | ||
25 | Dependent.continued_studies(dep, true); | ||
26 | } | ||
27 | pattern x_inv03_hasAll(dep : Dependent) { | ||
28 | Dependent.allowances(dep, _); | ||
29 | } | ||
30 | |||
31 | //inv5 - oclIsTypeOf - handled here | ||
32 | @Constraint(message = "inv05", severity = "error", key = {inc}) | ||
33 | pattern inv05(inc : Income) { | ||
34 | //income_type: None | ||
35 | neg find x_inv08_noType(inc); | ||
36 | Income.details.worked_days(inc, wd); | ||
37 | check(wd != 0); | ||
38 | } or { | ||
39 | //income_type: Not Employment_Income | ||
40 | Income.income_type(inc, type); | ||
41 | neg find x_inv08_notEI(type); | ||
42 | Income.details.worked_days(inc, wd); | ||
43 | check(wd != 0); | ||
44 | } or { | ||
45 | //income_type: Employment Income | ||
46 | Income.income_type(inc, type); | ||
47 | Employment_Income(type); | ||
48 | find x_inv05_inRange(inc); | ||
49 | } | ||
50 | pattern x_inv05_inRange(inc : Income) { | ||
51 | Income.details.worked_days(inc, wd); | ||
52 | check(wd < 1); | ||
53 | } or { | ||
54 | Income.details.worked_days(inc, wd); | ||
55 | check(wd > 25); | ||
56 | } | ||
57 | |||
58 | //inv6-Does not make sens, but directly from OCL | ||
59 | //first part of or from definition of getAge() | ||
60 | @Constraint(message = "inv06", severity = "error", key = {tp}) | ||
61 | pattern inv06(tp : Tax_Payer) { | ||
62 | Tax_Payer.dependents(tp, _); | ||
63 | Tax_Payer.birth_year(tp, TPBy); | ||
64 | check(2018 - TPBy > 2018-16); | ||
65 | } or { | ||
66 | Tax_Payer.birth_year(tp, TPBy); | ||
67 | Tax_Payer.dependents(tp, dep); | ||
68 | Dependent.birth_year(dep, DepBy); | ||
69 | check(2018-DepBy <= 2018-TPBy-16); | ||
70 | } | ||
71 | |||
72 | //inv7-OrderedSet | ||
73 | @Constraint(message = "inv07", severity = "error", key = {inc}) | ||
74 | pattern inv07(inc : Income) { | ||
75 | Income.details.distance(inc, d1); | ||
76 | Income.details.distance(inc, d2); | ||
77 | check(d1 != d2);//compare values | ||
78 | } | ||
79 | |||
80 | //user_complete_details-AttributeRemoved | ||
81 | |||
82 | //inv8 - oclIsTypeOf - handled here | ||
83 | @Constraint(message = "inv08", severity = "error", key = {inc}) | ||
84 | pattern inv08(inc : Income) { | ||
85 | //income_type: None | ||
86 | neg find x_inv08_noType(inc); | ||
87 | Income.details.distance(inc, dist); | ||
88 | check(dist != 0); | ||
89 | } or { | ||
90 | //income_type: Not Employment_Income | ||
91 | Income.income_type(inc, type); | ||
92 | neg find x_inv08_notEI(type); | ||
93 | Income.details.distance(inc, dist); | ||
94 | check(dist != 0); | ||
95 | } or { | ||
96 | //income_type: Employment Income | ||
97 | Income.income_type(inc, type); | ||
98 | Employment_Income(type); | ||
99 | find x_inv08_inRange(inc); | ||
100 | } | ||
101 | pattern x_inv08_notEI(type : Employment_Income) { | ||
102 | Employment_Income(type); | ||
103 | } | ||
104 | pattern x_inv08_noType(inc : Income) { | ||
105 | Income.income_type(inc, _); | ||
106 | } | ||
107 | pattern x_inv08_inRange(inc : Income) { | ||
108 | Income.details.distance(inc, dist); | ||
109 | check(dist < 0); | ||
110 | } or { | ||
111 | Income.details.distance(inc, dist); | ||
112 | check(dist > 100); | ||
113 | } | ||
114 | //inv9-DerivedFeature | ||
115 | |||
116 | //inv10-Ordered Sets | ||
117 | @Constraint(message = "inv10", severity = "error", key = {inc}) | ||
118 | pattern inv10(inc : Income) { | ||
119 | Income.details.amount(inc, a1); | ||
120 | Income.details.amount(inc, a2); | ||
121 | check(a1 != a2);//compare values | ||
122 | } | ||
123 | |||
124 | //inv11-attributes-handled by multiplicity | ||
125 | @Constraint(message = "inv11", severity = "error", key = {exp}) | ||
126 | pattern inv11(exp : Expense) { | ||
127 | find x_inv11_incOver100(exp); | ||
128 | find x_inv11_incNotOver100(exp); | ||
129 | } | ||
130 | pattern x_inv11_incOver100(exp : Expense) { | ||
131 | Expense.income.income_amount(exp, incVal); | ||
132 | check(incVal / 2 > 50); | ||
133 | |||
134 | } or { | ||
135 | Expense.declared_amount(exp, decl); | ||
136 | check(decl != 50); | ||
137 | } | ||
138 | pattern x_inv11_incNotOver100(exp : Expense) { | ||
139 | Expense.income.income_amount(exp, incVal); | ||
140 | check(incVal / 2 <= 50); | ||
141 | } or { | ||
142 | Expense.declared_amount(exp, decl); | ||
143 | check(decl < 50); | ||
144 | } or { | ||
145 | Expense.income.income_amount(exp, incVal); | ||
146 | Expense.declared_amount(exp, decl); | ||
147 | check(decl > incVal/2); | ||
148 | } | ||
149 | |||
150 | //inv12 | ||
151 | //exists - handled logically | ||
152 | @Constraint(message = "inv12", severity = "error", key = {tp}) | ||
153 | pattern inv12(tp : Tax_Payer) { | ||
154 | Tax_Payer.addresses(tp, hab_add); | ||
155 | Habitual_Address(hab_add); | ||
156 | neg find x_inv12_notZZ(hab_add); | ||
157 | Tax_Payer.incomes(tp, inc); | ||
158 | Local_Income(inc); | ||
159 | neg find x_inv12_notNonRes(tp); | ||
160 | } | ||
161 | pattern x_inv12_notNonRes(tp : Non_Resident_Tax_Payer) { | ||
162 | Non_Resident_Tax_Payer(tp); | ||
163 | } | ||
164 | pattern x_inv12_notZZ(hab_add : Habitual_Address) { | ||
165 | Address.country(hab_add, ::ZZ); | ||
166 | } | ||
167 | |||
168 | //inv13 - Added new containment rel Phys_Pers->Address | ||
169 | //exists - handled logically | ||
170 | @Constraint(message = "inv13", severity = "error", key = {tp}) | ||
171 | pattern inv13(tp : Tax_Payer) { | ||
172 | Tax_Payer.addresses(tp, hab_add); | ||
173 | Habitual_Address(hab_add); | ||
174 | Address.country(hab_add, ::ZZ); | ||
175 | neg find x_inv13(tp); | ||
176 | } | ||
177 | pattern x_inv13(tp : Resident_Tax_Payer) { | ||
178 | Resident_Tax_Payer(tp); | ||
179 | } | ||
180 | |||
181 | //inv14-MultiplicityChanged | ||
182 | |||
183 | //inv15-Ordered Sets in assignment if block | ||
184 | //ERROR if no household object | ||
185 | @Constraint(message = "inv15", severity = "error", key = {ea}) | ||
186 | pattern inv15(ea : External_Allowance) { | ||
187 | neg find x_inv15(ea); | ||
188 | } | ||
189 | pattern x_inv15(ea : External_Allowance) { | ||
190 | External_Allowance.person(ea, child); | ||
191 | Household.children(h, child);//only one due to multiplicity | ||
192 | Household.parents.individual_A(h, iA); | ||
193 | Tax_Payer(iA); | ||
194 | External_Allowance.reciver(ea, iA); | ||
195 | } or { | ||
196 | External_Allowance.person(ea, child); | ||
197 | Household.children(h, child);//only one due to multiplicity | ||
198 | Household.parents.individual_B(h, iB); | ||
199 | Tax_Payer(iB); | ||
200 | External_Allowance.reciver(ea, iB); | ||
201 | } | ||
202 | |||
203 | //inv16-Tax_Card.tax_card_type is a derived feature | ||
204 | |||
205 | //inv17-attribute-handled by multiplicity | ||
206 | @Constraint(message = "inv17", severity = "error", key = {lur}) | ||
207 | pattern inv17(lur : Legal_Union_Record) { | ||
208 | Legal_Union_Record.start_year(lur, sy); | ||
209 | check(sy < 1950); | ||
210 | } or { | ||
211 | Legal_Union_Record.start_year(lur, sy); | ||
212 | check(sy > 2018); | ||
213 | } | ||
214 | |||
215 | //inv18-MultiplicityChecked | ||
216 | //inv19-MultiplicityChecked | ||
217 | |||
218 | //inv20-Useless constraint since both edges are containment (TODOCheck) | ||
219 | //OclIsUndefined-Handled by multiplicity | ||
220 | @Constraint(message = "inv20", severity = "error", key = {lur}) | ||
221 | pattern inv20(lur : Legal_Union_Record) { | ||
222 | Legal_Union_Record.individual_A(lur, iA); | ||
223 | Legal_Union_Record.individual_B(lur, iB); | ||
224 | iA == iB; | ||
225 | } | ||
226 | //inv21-MultiplicityChecked | ||
227 | //inv22-MultiplicityChecked | ||
228 | //inv23-MultiplicityChecked | ||
229 | //inv24-MultiplicityChecked | ||
230 | //inv25-MultiplicityChecked | ||
231 | //inv26-MultiplicityChanged | ||
232 | //inv27-dupOfInv24 | ||
233 | //inv28-dubOfInv23 | ||
234 | //inv29-MultiplicityChanged | ||
235 | //inv30-AttributeRemoved | ||
236 | //inv31-AttributeRemoved | ||
237 | //inv32-AttributeRemoved | ||
238 | |||
239 | //inv33-attribute-handled by multiplicity | ||
240 | @Constraint(message = "inv33", severity = "error", key = {p}) | ||
241 | pattern inv33(p : Physical_Person) { | ||
242 | Physical_Person.birth_year(p, by); | ||
243 | check(2018-by < 0); | ||
244 | } or { | ||
245 | Physical_Person.birth_year(p, by); | ||
246 | check(2018-by > 100); | ||
247 | } | ||
248 | |||
249 | //inv34-attribute-handled by multiplicity | ||
250 | @Constraint(message = "inv34", severity = "error", key = {p}) | ||
251 | pattern inv34(p : Physical_Person) { | ||
252 | Physical_Person.birth_month(p, birthMonth); | ||
253 | check(birthMonth < 1); | ||
254 | } or { | ||
255 | Physical_Person.birth_month(p, birthMonth); | ||
256 | check(birthMonth > 12); | ||
257 | } | ||
258 | |||
259 | //inv35-attribute-handled by multiplicity | ||
260 | @Constraint(message = "inv35", severity = "error", key = {p}) | ||
261 | pattern inv35(p : Physical_Person) { | ||
262 | Physical_Person.birth_day(p, birthDay); | ||
263 | check(birthDay < 1); | ||
264 | } or { | ||
265 | Physical_Person.birth_day(p, birthDay); | ||
266 | check(birthDay > 28); | ||
267 | } | ||
268 | |||
269 | //inv36-AttributeRemoved | ||
270 | //inv37-AttributeRemoved | ||
271 | //inv38-AttributeRemoved | ||
272 | //inv39-AttributeRemoved | ||
273 | //inv40-AttributeRemoved | ||
274 | //inv41-AttributeRemoved | ||
275 | //inv42-AttributeRemoved | ||
276 | //inv43-AttributeRemoved | ||
277 | //inv44-AttributeRemoved | ||
278 | //inv45-AttributeRemoved | ||
279 | //inv46-AttributeRemoved | ||
280 | |||
281 | //inv47-attributes-handled by multiplicity | ||
282 | @Constraint(message = "inv47", severity = "error", key = {lur}) | ||
283 | pattern inv47(lur : Legal_Union_Record) { | ||
284 | Legal_Union_Record.end_year(lur, endY); | ||
285 | Legal_Union_Record.start_year(lur, startY); | ||
286 | neg find x_inv47(lur); | ||
287 | check(startY >= endY); | ||
288 | } | ||
289 | pattern x_inv47(lur : Legal_Union_Record) { | ||
290 | Legal_Union_Record.separation_cause(lur, ::NONE); | ||
291 | Legal_Union_Record.end_year(lur, -1); | ||
292 | } | ||
293 | |||
294 | //inv48-attributes-handled by multiplicity | ||
295 | @Constraint(message = "inv48", severity = "error", key = {p}) | ||
296 | pattern inv48(p : Physical_Person) { | ||
297 | neg find x_inv48_notDis(p); | ||
298 | neg find x_inv48_Dis(p); | ||
299 | } | ||
300 | pattern x_inv48_notDis(p : Physical_Person) { | ||
301 | Physical_Person.disability_type(p, ::NONE); | ||
302 | Physical_Person.disability_percentage(p, 0.0); | ||
303 | } | ||
304 | pattern x_inv48_Dis(p : Physical_Person) { | ||
305 | neg find x_inv48_3(p); | ||
306 | Physical_Person.disability_percentage(p, disPer); | ||
307 | check(disPer > 0.0); | ||
308 | check(disPer <= 1.0); | ||
309 | } | ||
310 | pattern x_inv48_3(p : Physical_Person) { | ||
311 | Physical_Person.disability_type(p, ::NONE); | ||
312 | } | ||
313 | |||
314 | //inv49-OclKindOf-handled by multiplicity | ||
315 | @Constraint(message = "inv49", severity = "error", key = {lur}) | ||
316 | pattern inv49(lur : Legal_Union_Record) { | ||
317 | neg find x_inv49_1(lur); | ||
318 | } | ||
319 | pattern x_inv49_1(lur : Legal_Union_Record) { | ||
320 | Legal_Union_Record.individual_A(lur, iA); | ||
321 | Legal_Union_Record.individual_B(lur, iB); | ||
322 | Tax_Payer(iA); | ||
323 | Physical_Person(iB); | ||
324 | neg find x_inv49_2(iB); | ||
325 | iA != iB; | ||
326 | } | ||
327 | pattern x_inv49_2(iB: Dependent) { | ||
328 | Dependent(iB); | ||
329 | } | ||
330 | |||
331 | //inv50-MultiplicityChecked | ||
332 | //inv51-MultiplicityChecked | ||
333 | //inv52-MultiplicityChecked | ||
334 | //inv53-MultiplicityChecked \ No newline at end of file | ||
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GenerateScenarios.xtend b/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GenerateScenarios.xtend new file mode 100644 index 00000000..8445130a --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GenerateScenarios.xtend | |||
@@ -0,0 +1,243 @@ | |||
1 | package run | ||
2 | |||
3 | import Taxation.TaxationPackage | ||
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | ||
5 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration | ||
6 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace | ||
7 | import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor | ||
8 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput | ||
9 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | ||
10 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem | ||
11 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult | ||
12 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult | ||
13 | import hu.bme.mit.inf.dslreasoner.logic2ecore.Logic2Ecore | ||
14 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2Logic | ||
15 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicConfiguration | ||
16 | import hu.bme.mit.inf.dslreasoner.viatra2logic.ViatraQuerySetDescriptor | ||
17 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.InstanceModel2Logic | ||
18 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
19 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretation2Gml | ||
20 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner | ||
21 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration | ||
22 | import hu.bme.mit.inf.dslreasoner.visualisation.pi2graphviz.GraphvizVisualiser | ||
23 | import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace | ||
24 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace | ||
25 | import java.math.BigDecimal | ||
26 | import java.text.SimpleDateFormat | ||
27 | import java.util.Date | ||
28 | import java.util.HashMap | ||
29 | import java.util.List | ||
30 | import java.util.Map | ||
31 | import java.util.TreeSet | ||
32 | import org.eclipse.emf.ecore.EAttribute | ||
33 | import org.eclipse.emf.ecore.EClass | ||
34 | import org.eclipse.emf.ecore.EEnum | ||
35 | import org.eclipse.emf.ecore.EEnumLiteral | ||
36 | import org.eclipse.emf.ecore.EObject | ||
37 | import org.eclipse.emf.ecore.EPackage | ||
38 | import org.eclipse.emf.ecore.EReference | ||
39 | import org.eclipse.emf.ecore.resource.Resource | ||
40 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl | ||
41 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup | ||
42 | import org.eclipse.viatra.query.runtime.api.IQueryGroup | ||
43 | import org.eclipse.viatra.query.runtime.rete.matcher.ReteEngine | ||
44 | import queries.Case_study_A | ||
45 | |||
46 | class GenerateScenarios { | ||
47 | def static void main(String[] args) { | ||
48 | val x = (new EMFPatternLanguageStandaloneSetup).createInjectorAndDoEMFRegistration | ||
49 | // //PatternLanguageWithRSSetup.createInjectorAndDoEMFRegistration | ||
50 | // ApplicationConfigurationStandaloneSetup.doSetup | ||
51 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("xmi", new XMIResourceFactoryImpl) | ||
52 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("logicproblem", new XMIResourceFactoryImpl) | ||
53 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("partialmodel", new XMIResourceFactoryImpl) | ||
54 | ReteEngine.getClass | ||
55 | |||
56 | val Ecore2Logic ecore2Logic = new Ecore2Logic | ||
57 | val Logic2Ecore logic2Ecore = new Logic2Ecore(ecore2Logic) | ||
58 | val Viatra2Logic viatra2Logic = new Viatra2Logic(ecore2Logic) | ||
59 | val InstanceModel2Logic instanceModel2Logic = new InstanceModel2Logic | ||
60 | |||
61 | // Workspace setup | ||
62 | val Date date = new Date(System.currentTimeMillis) | ||
63 | val SimpleDateFormat format = new SimpleDateFormat("dd-HHmm"); | ||
64 | val formattedDate = format.format(date) | ||
65 | |||
66 | val inputs = new FileSystemWorkspace('''inputs/''', "") | ||
67 | val workspace = new FileSystemWorkspace('''output/''' + formattedDate + '''/''', "") | ||
68 | workspace.initAndClear | ||
69 | |||
70 | println("Input and output workspaces are created") | ||
71 | |||
72 | // print(TaxationPackage.eINSTANCE.getEClassifiers.filter(EClass).toList.get(0)) | ||
73 | |||
74 | //* | ||
75 | val metamodel = loadMetamodel(TaxationPackage.eINSTANCE) | ||
76 | val partialModel = loadPartialModel(inputs, "Household.xmi") | ||
77 | val queries = loadQueries(metamodel, Case_study_A.instance) | ||
78 | /*/ | ||
79 | val metamodel = loadMetamodel(FamilytreePackage.eINSTANCE) | ||
80 | // val partialModel = loadPartialModel(inputs, "yakindu/Yakindu.xmi") | ||
81 | val queries = loadQueries(metamodel, FamilyTreeConstraints.instance) | ||
82 | //*/ | ||
83 | println("DSL loaded") | ||
84 | |||
85 | val SIZE = 10 | ||
86 | var REPS = 1 | ||
87 | val RUNTIME = 600 | ||
88 | |||
89 | // ///////////////////////// | ||
90 | // Prepare Problem | ||
91 | val modelGenerationProblem = ecore2Logic.transformMetamodel(metamodel, new Ecore2LogicConfiguration()) | ||
92 | var problem = modelGenerationProblem.output | ||
93 | |||
94 | // val modelExtensionProblem = instanceModel2Logic.transform(modelGenerationProblem, partialModel) | ||
95 | // problem = modelExtensionProblem.output | ||
96 | |||
97 | val validModelExtensionProblem = viatra2Logic.transformQueries(queries, modelGenerationProblem, | ||
98 | new Viatra2LogicConfiguration) | ||
99 | problem = validModelExtensionProblem.output | ||
100 | |||
101 | workspace.writeModel(problem, "problem.logicproblem") | ||
102 | println("Problem created") | ||
103 | |||
104 | for (var i = 0; i < REPS; i++) { | ||
105 | |||
106 | println("Run #" + i + ":") | ||
107 | |||
108 | var ViatraReasoner reasoner = new ViatraReasoner | ||
109 | |||
110 | // ///////////////////////////////////////////////////// | ||
111 | // Define Config File | ||
112 | val knownIntegers = new TreeSet<Integer> | ||
113 | knownIntegers.addAll(0) | ||
114 | |||
115 | val knownReals = new TreeSet<BigDecimal> | ||
116 | knownReals.addAll(new BigDecimal("0.0")) | ||
117 | |||
118 | val knownStrings = new TreeSet<String> | ||
119 | knownStrings.addAll("r0", "r1", "r2") | ||
120 | |||
121 | |||
122 | val solverConfig = new ViatraReasonerConfiguration => [ | ||
123 | it.runtimeLimit = RUNTIME | ||
124 | it.typeScopes.maxNewElements = SIZE | ||
125 | // it.typeScopes.minNewElements = SIZE | ||
126 | if(!knownIntegers.isEmpty) it.typeScopes.knownIntegers = knownIntegers | ||
127 | if(!knownReals.isEmpty) it.typeScopes.knownReals = knownReals | ||
128 | // if(!knownStrings.isEmpty) it.typeScopes.knownStrings = knownStrings | ||
129 | ] | ||
130 | |||
131 | val startTime = System.currentTimeMillis | ||
132 | var solution = reasoner.solve(problem, solverConfig, workspace) | ||
133 | val totalTime = System.currentTimeMillis-startTime | ||
134 | |||
135 | println(" Problem Solved") | ||
136 | solution.writeStats(totalTime) | ||
137 | |||
138 | if (solution instanceof ModelResult) { | ||
139 | solution.writeRepresentation(workspace, i) | ||
140 | // solution.writeInterpretation(logic2Ecore, workspace, i, reasoner, modelGenerationProblem) | ||
141 | println(" Solution saved and visualised") | ||
142 | } else | ||
143 | println(" Returned: " + solution.class.simpleName.toString) | ||
144 | |||
145 | |||
146 | // println("Stats Created") | ||
147 | // Run Garbage Collector | ||
148 | val Runtime r = Runtime.getRuntime(); | ||
149 | r.gc(); | ||
150 | r.gc(); | ||
151 | r.gc(); | ||
152 | Thread.sleep(3000) | ||
153 | } | ||
154 | println("---End---") | ||
155 | |||
156 | } | ||
157 | |||
158 | def static Map<Type, Integer> getTypeMap(Map<Class, Integer> classMap, EcoreMetamodelDescriptor metamodel, | ||
159 | Ecore2Logic e2l, Ecore2Logic_Trace trace) { | ||
160 | val typeMap = new HashMap<Type, Integer> | ||
161 | val listMap = metamodel.classes.toMap[s|s.name] | ||
162 | |||
163 | for (Class elem : classMap.keySet) { | ||
164 | typeMap.put(e2l.TypeofEClass( | ||
165 | trace, | ||
166 | listMap.get(elem.simpleName) | ||
167 | ), classMap.get(elem)) | ||
168 | } | ||
169 | return typeMap | ||
170 | } | ||
171 | |||
172 | def static loadMetamodel(EPackage pckg) { | ||
173 | val List<EClass> classes = pckg.getEClassifiers.filter(EClass).toList | ||
174 | val List<EEnum> enums = pckg.getEClassifiers.filter(EEnum).toList | ||
175 | val List<EEnumLiteral> literals = enums.map[getELiterals].flatten.toList | ||
176 | val List<EReference> references = classes.map[getEReferences].flatten.toList | ||
177 | val List<EAttribute> attributes = classes.map[getEAttributes].flatten.toList | ||
178 | return new EcoreMetamodelDescriptor(classes, #{}, false, enums, literals, references, attributes) | ||
179 | } | ||
180 | |||
181 | def static loadPartialModel(ReasonerWorkspace inputs, String path) { | ||
182 | Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl()) | ||
183 | inputs.readModel(EObject, path).eResource.contents | ||
184 | // inputs.readModel(EObject,"FamInstance.xmi").eResource.allContents.toList | ||
185 | } | ||
186 | |||
187 | def static loadQueries(EcoreMetamodelDescriptor metamodel, IQueryGroup i) { | ||
188 | val patterns = i.specifications.toList | ||
189 | val wfPatterns = patterns.filter[it.allAnnotations.exists[it.name == "Constraint"]].toSet | ||
190 | val derivedFeatures = emptyMap | ||
191 | // NO DERIVED FEATURES | ||
192 | // val derivedFeatures = new LinkedHashMap | ||
193 | // derivedFeatures.put(i.type,metamodel.attributes.filter[it.name == "type"].head) | ||
194 | // derivedFeatures.put(i.model,metamodel.references.filter[it.name == "model"].head) | ||
195 | val res = new ViatraQuerySetDescriptor( | ||
196 | patterns, | ||
197 | wfPatterns, | ||
198 | derivedFeatures | ||
199 | ) | ||
200 | return res | ||
201 | } | ||
202 | |||
203 | def static writeInterpretation(LogicResult solution, Logic2Ecore logic2Ecore, ReasonerWorkspace workspace, int i, | ||
204 | ViatraReasoner reasoner, TracedOutput<LogicProblem, Ecore2Logic_Trace> mgProb) { | ||
205 | val interpretations = reasoner.getInterpretations(solution as ModelResult) | ||
206 | for (interpIndex : 0 ..< interpretations.size) { | ||
207 | // val extension b = new LogicStructureBuilder | ||
208 | // val extension a = new LogicProblemBuilder | ||
209 | val interpretation = interpretations.get(interpIndex) | ||
210 | val model = logic2Ecore.transformInterpretation(interpretation, mgProb.trace) | ||
211 | workspace.writeModel(model, '''solution«i»_«interpIndex».xmi''') | ||
212 | } | ||
213 | } | ||
214 | |||
215 | def static writeRepresentation(LogicResult solution, ReasonerWorkspace workspace, int i) { | ||
216 | val representations = solution.representation | ||
217 | for (representationIndex : 0 ..< representations.size) { | ||
218 | val representation = representations.get(representationIndex) | ||
219 | if (representation instanceof PartialInterpretation) { | ||
220 | val gml = (new PartialInterpretation2Gml).transform(representation) | ||
221 | workspace.writeText('''solution«i»_«representationIndex».gml''', gml) | ||
222 | |||
223 | val png = (new GraphvizVisualiser).visualiseConcretization(representation) | ||
224 | png.writeToFile(workspace, '''solution«i»_«representationIndex».png''') | ||
225 | |||
226 | // workspace.writeModel(representation, '''solution«representationIndex».partialintrpretation''') | ||
227 | } else { | ||
228 | workspace.writeText('''solution«representationIndex».txt''', representation.toString) | ||
229 | } | ||
230 | } | ||
231 | } | ||
232 | |||
233 | def static writeStats(LogicResult solution, long time) { | ||
234 | val stats = solution.statistics | ||
235 | println(" Statistics:") | ||
236 | // for (e : stats.entries.filter[name.substring(0, 9) == "_Solution"]) { | ||
237 | // println(" " + e.name + ": " + (e as IntStatisticEntry).value + " ms") | ||
238 | // } | ||
239 | println(" \"solve\" time: " + time as double/1000 + " s") | ||
240 | |||
241 | // println("<<End Statistics>>") | ||
242 | } | ||
243 | } | ||