From c0a758eedd457a5d8eb9f1a6c17fc24143aabb3e Mon Sep 17 00:00:00 2001 From: ArenBabikian Date: Sun, 26 Apr 2020 18:23:13 -0400 Subject: Add PLEDGE case study files --- .../src/queries/NewOCLFileX.ocl | 45 +++ .../src/queries/case_study_A.vql | 334 +++++++++++++++++++++ .../src/run/RunGenerator.xtend | 151 ++++++++++ 3 files changed, 530 insertions(+) create mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/queries/NewOCLFileX.ocl create mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/queries/case_study_A.vql create mode 100644 Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/run/RunGenerator.xtend (limited to 'Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src') diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/queries/NewOCLFileX.ocl b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/queries/NewOCLFileX.ocl new file mode 100644 index 00000000..66ae728e --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/queries/NewOCLFileX.ocl @@ -0,0 +1,45 @@ +import 'file:/Users/Aren Babikian/git/VIATRA-Attributes/case.study.a.model/model/Taxation.ecore' + +package Taxation + +--context Income inv inv8: +--if(not self.income_type.oclIsTypeOf(Employment_Income)) then +--self.details->forAll(d| d.distance = 0) +--else +--self.details->forAll(d| d.distance >= 0.0 and d.distance <= 100) +--endif +-- +--context Legal_Union_Record inv inv490: +--self.individual_A.oclIsKindOf(Tax_Payer) +-- +--context Legal_Union_Record inv inv491: +--self.individual_B->forAll(i | i.oclIsKindOf(Physical_Person) ) +-- +--context Legal_Union_Record inv inv492: +--self.individual_B->forAll(i | not i.oclIsTypeOf(Dependent) ) +-- +--context Legal_Union_Record inv inv493: +--self.individual_A <> self.individual_B +-- +--context Tax_Payer inv inv13: +-- self.addresses->exists( hab_add:Address | hab_add.oclIsTypeOf(Habitual_Address) = true and hab_add.country=Country::ZZ) +--implies +-- self.oclIsTypeOf(Resident_Tax_Payer) + + context Income inv inv7: +let val:Real =self.details->asOrderedSet()->first().distance in +self.details->forAll(d: Income_Detail|d.distance = val) + +--context External_Allowance inv inv15: +--let child:Dependent = self.person in +--let h:Household = Household.allInstances()->select(children->includes(child))->asOrderedSet()->first() in +--let t1:Set(Physical_Person) = Set{h.parents.individual_A}->union(h.parents.individual_B)->select(oclIsKindOf(Tax_Payer)) in +--if(t1->size()=1) then +--self.reciver = t1->asOrderedSet()->first() +--else +--self.reciver = t1->asOrderedSet()->at(2) or self.reciver = t1->asOrderedSet()->at(1) +--endif + + + +endpackage \ No newline at end of file diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/queries/case_study_A.vql b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/queries/case_study_A.vql new file mode 100644 index 00000000..5d46bf42 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/queries/case_study_A.vql @@ -0,0 +1,334 @@ +package queries + +import "http:///TaxCard.ecore" + +//AttributeRemoved -> DF + +//inv1-External_Allowance.amount is a derived feature (TODOcheck) +//inv2-Tax_Card.income.taxPayer.taxesDue is a derived feature (TODOcheck) + +//inv3-multiplicity adjusted +@Constraint(message = "inv03", severity = "error", key = {dep}) +pattern inv03(dep : Dependent) { + find x_inv03_eligAll(dep); + neg find x_inv03_hasAll(dep); +} or { + Dependent.birth_year(dep, by); + check(2018-by > 21); + Dependent.continued_studies(dep, false); + Dependent.allowances(dep, _); +} +pattern x_inv03_eligAll(dep : Dependent) { + Dependent.birth_year(dep, by); + check(2018-by <= 21); +} or { + Dependent.continued_studies(dep, true); +} +pattern x_inv03_hasAll(dep : Dependent) { + Dependent.allowances(dep, _); +} + +//inv5 - oclIsTypeOf - handled here +@Constraint(message = "inv05", severity = "error", key = {inc}) +pattern inv05(inc : Income) { + //income_type: None + neg find x_inv08_noType(inc); + Income.details.worked_days(inc, wd); + check(wd != 0); +} or { + //income_type: Not Employment_Income + Income.income_type(inc, type); + neg find x_inv08_notEI(type); + Income.details.worked_days(inc, wd); + check(wd != 0); +} or { + //income_type: Employment Income + Income.income_type(inc, type); + Employment_Income(type); + find x_inv05_inRange(inc); +} +pattern x_inv05_inRange(inc : Income) { + Income.details.worked_days(inc, wd); + check(wd < 1); +} or { + Income.details.worked_days(inc, wd); + check(wd > 25); +} + +//inv6-Does not make sens, but directly from OCL +//first part of or from definition of getAge() +@Constraint(message = "inv06", severity = "error", key = {tp}) +pattern inv06(tp : Tax_Payer) { + Tax_Payer.dependents(tp, _); + Tax_Payer.birth_year(tp, TPBy); + check(2018 - TPBy > 2018-16); +} or { + Tax_Payer.birth_year(tp, TPBy); + Tax_Payer.dependents(tp, dep); + Dependent.birth_year(dep, DepBy); + check(2018-DepBy <= 2018-TPBy-16); +} + +//inv7-OrderedSet +@Constraint(message = "inv07", severity = "error", key = {inc}) +pattern inv07(inc : Income) { + Income.details.distance(inc, d1); + Income.details.distance(inc, d2); + check(d1 != d2);//compare values +} + +//user_complete_details-AttributeRemoved + +//inv8 - oclIsTypeOf - handled here +@Constraint(message = "inv08", severity = "error", key = {inc}) +pattern inv08(inc : Income) { + //income_type: None + neg find x_inv08_noType(inc); + Income.details.distance(inc, dist); + check(dist != 0); +} or { + //income_type: Not Employment_Income + Income.income_type(inc, type); + neg find x_inv08_notEI(type); + Income.details.distance(inc, dist); + check(dist != 0); +} or { + //income_type: Employment Income + Income.income_type(inc, type); + Employment_Income(type); + find x_inv08_inRange(inc); +} +pattern x_inv08_notEI(type : Employment_Income) { + Employment_Income(type); +} +pattern x_inv08_noType(inc : Income) { + Income.income_type(inc, _); +} +pattern x_inv08_inRange(inc : Income) { + Income.details.distance(inc, dist); + check(dist < 0); +} or { + Income.details.distance(inc, dist); + check(dist > 100); +} +//inv9-DerivedFeature + +//inv10-Ordered Sets +@Constraint(message = "inv10", severity = "error", key = {inc}) +pattern inv10(inc : Income) { + Income.details.amount(inc, a1); + Income.details.amount(inc, a2); + check(a1 != a2);//compare values +} + +//inv11-attributes-handled by multiplicity +@Constraint(message = "inv11", severity = "error", key = {exp}) +pattern inv11(exp : Expense) { + find x_inv11_incOver100(exp); + find x_inv11_incNotOver100(exp); +} +pattern x_inv11_incOver100(exp : Expense) { + Expense.income.income_amount(exp, incVal); + check(incVal / 2 > 50); + +} or { + Expense.declared_amount(exp, decl); + check(decl != 50); +} +pattern x_inv11_incNotOver100(exp : Expense) { + Expense.income.income_amount(exp, incVal); + check(incVal / 2 <= 50); +} or { + Expense.declared_amount(exp, decl); + check(decl < 50); +} or { + Expense.income.income_amount(exp, incVal); + Expense.declared_amount(exp, decl); + check(decl > incVal/2); +} + +//inv12 +//exists - handled logically +@Constraint(message = "inv12", severity = "error", key = {tp}) +pattern inv12(tp : Tax_Payer) { + Tax_Payer.addresses(tp, hab_add); + Habitual_Address(hab_add); + neg find x_inv12_notZZ(hab_add); + Tax_Payer.incomes(tp, inc); + Local_Income(inc); + neg find x_inv12_notNonRes(tp); +} +pattern x_inv12_notNonRes(tp : Non_Resident_Tax_Payer) { + Non_Resident_Tax_Payer(tp); +} +pattern x_inv12_notZZ(hab_add : Habitual_Address) { + Address.country(hab_add, ::ZZ); +} + +//inv13 - Added new containment rel Phys_Pers->Address +//exists - handled logically +@Constraint(message = "inv13", severity = "error", key = {tp}) +pattern inv13(tp : Tax_Payer) { + Tax_Payer.addresses(tp, hab_add); + Habitual_Address(hab_add); + Address.country(hab_add, ::ZZ); + neg find x_inv13(tp); +} +pattern x_inv13(tp : Resident_Tax_Payer) { + Resident_Tax_Payer(tp); +} + +//inv14-MultiplicityChanged + +//inv15-Ordered Sets in assignment if block +//ERROR if no household object +@Constraint(message = "inv15", severity = "error", key = {ea}) +pattern inv15(ea : External_Allowance) { + neg find x_inv15(ea); +} +pattern x_inv15(ea : External_Allowance) { + External_Allowance.person(ea, child); + Household.children(h, child);//only one due to multiplicity + Household.parents.individual_A(h, iA); + Tax_Payer(iA); + External_Allowance.reciver(ea, iA); +} or { + External_Allowance.person(ea, child); + Household.children(h, child);//only one due to multiplicity + Household.parents.individual_B(h, iB); + Tax_Payer(iB); + External_Allowance.reciver(ea, iB); +} + +//inv16-Tax_Card.tax_card_type is a derived feature + +//inv17-attribute-handled by multiplicity +@Constraint(message = "inv17", severity = "error", key = {lur}) +pattern inv17(lur : Legal_Union_Record) { + Legal_Union_Record.start_year(lur, sy); + check(sy < 1950); +} or { + Legal_Union_Record.start_year(lur, sy); + check(sy > 2018); +} + +//inv18-MultiplicityChecked +//inv19-MultiplicityChecked + +//inv20-Useless constraint since both edges are containment (TODOCheck) +//OclIsUndefined-Handled by multiplicity +@Constraint(message = "inv20", severity = "error", key = {lur}) +pattern inv20(lur : Legal_Union_Record) { + Legal_Union_Record.individual_A(lur, iA); + Legal_Union_Record.individual_B(lur, iB); + iA == iB; +} +//inv21-MultiplicityChecked +//inv22-MultiplicityChecked +//inv23-MultiplicityChecked +//inv24-MultiplicityChecked +//inv25-MultiplicityChecked +//inv26-MultiplicityChanged +//inv27-dupOfInv24 +//inv28-dubOfInv23 +//inv29-MultiplicityChanged +//inv30-AttributeRemoved +//inv31-AttributeRemoved +//inv32-AttributeRemoved + +//inv33-attribute-handled by multiplicity +@Constraint(message = "inv33", severity = "error", key = {p}) +pattern inv33(p : Physical_Person) { + Physical_Person.birth_year(p, by); + check(2018-by < 0); +} or { + Physical_Person.birth_year(p, by); + check(2018-by > 100); +} + +//inv34-attribute-handled by multiplicity +@Constraint(message = "inv34", severity = "error", key = {p}) +pattern inv34(p : Physical_Person) { + Physical_Person.birth_month(p, birthMonth); + check(birthMonth < 1); +} or { + Physical_Person.birth_month(p, birthMonth); + check(birthMonth > 12); +} + +//inv35-attribute-handled by multiplicity +@Constraint(message = "inv35", severity = "error", key = {p}) +pattern inv35(p : Physical_Person) { + Physical_Person.birth_day(p, birthDay); + check(birthDay < 1); +} or { + Physical_Person.birth_day(p, birthDay); + check(birthDay > 28); +} + +//inv36-AttributeRemoved +//inv37-AttributeRemoved +//inv38-AttributeRemoved +//inv39-AttributeRemoved +//inv40-AttributeRemoved +//inv41-AttributeRemoved +//inv42-AttributeRemoved +//inv43-AttributeRemoved +//inv44-AttributeRemoved +//inv45-AttributeRemoved +//inv46-AttributeRemoved + +//inv47-attributes-handled by multiplicity +@Constraint(message = "inv47", severity = "error", key = {lur}) +pattern inv47(lur : Legal_Union_Record) { + Legal_Union_Record.end_year(lur, endY); + Legal_Union_Record.start_year(lur, startY); + neg find x_inv47(lur); + check(startY >= endY); +} +pattern x_inv47(lur : Legal_Union_Record) { + Legal_Union_Record.separation_cause(lur, ::NONE); + Legal_Union_Record.end_year(lur, -1); +} + +//inv48-attributes-handled by multiplicity +@Constraint(message = "inv48", severity = "error", key = {p}) +pattern inv48(p : Physical_Person) { + neg find x_inv48_notDis(p); + neg find x_inv48_Dis(p); +} +pattern x_inv48_notDis(p : Physical_Person) { + Physical_Person.disability_type(p, ::NONE); + Physical_Person.disability_percentage(p, 0.0); +} +pattern x_inv48_Dis(p : Physical_Person) { + neg find x_inv48_3(p); + Physical_Person.disability_percentage(p, disPer); + check(disPer > 0.0); + check(disPer <= 1.0); +} +pattern x_inv48_3(p : Physical_Person) { + Physical_Person.disability_type(p, ::NONE); +} + +//inv49-OclKindOf-handled by multiplicity +@Constraint(message = "inv49", severity = "error", key = {lur}) +pattern inv49(lur : Legal_Union_Record) { + neg find x_inv49_1(lur); +} +pattern x_inv49_1(lur : Legal_Union_Record) { + Legal_Union_Record.individual_A(lur, iA); + Legal_Union_Record.individual_B(lur, iB); + Tax_Payer(iA); + Physical_Person(iB); + neg find x_inv49_2(iB); + iA != iB; +} +pattern x_inv49_2(iB: Dependent) { + Dependent(iB); +} + +//inv50-MultiplicityChecked +//inv51-MultiplicityChecked +//inv52-MultiplicityChecked +//inv53-MultiplicityChecked \ No newline at end of file diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/run/RunGenerator.xtend b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/run/RunGenerator.xtend new file mode 100644 index 00000000..8bd70919 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/run/RunGenerator.xtend @@ -0,0 +1,151 @@ +package run + +import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic +import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration +import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace +import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor +import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type +import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult +import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.impl.ModelResultImpl +import hu.bme.mit.inf.dslreasoner.logic2ecore.Logic2Ecore +import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2Logic +import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicConfiguration +import hu.bme.mit.inf.dslreasoner.viatra2logic.ViatraQuerySetDescriptor +import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.InstanceModel2Logic +import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner +import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration +import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace +import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace +import java.io.PrintWriter +import java.text.SimpleDateFormat +import java.util.Date +import java.util.HashMap +import java.util.List +import java.util.Map +import org.eclipse.emf.ecore.EAttribute +import org.eclipse.emf.ecore.EClass +import org.eclipse.emf.ecore.EEnum +import org.eclipse.emf.ecore.EEnumLiteral +import org.eclipse.emf.ecore.EObject +import org.eclipse.emf.ecore.EPackage +import org.eclipse.emf.ecore.EReference +import org.eclipse.emf.ecore.resource.Resource +import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl +import org.eclipse.viatra.query.runtime.api.IQueryGroup +import Taxation.TaxationPackage + +class GenerateScenarios { + def static void main(String[] args) { + val Ecore2Logic ecore2Logic = new Ecore2Logic +// val Logic2Ecore logic2Ecore = new Logic2Ecore(ecore2Logic) +// val Viatra2Logic viatra2Logic = new Viatra2Logic(ecore2Logic) +// val InstanceModel2Logic instanceModel2Logic = new InstanceModel2Logic + // Workspace setup + val Date date = new Date(System.currentTimeMillis) + val SimpleDateFormat format = new SimpleDateFormat("dd-HHmm"); + val formattedDate = format.format(date) + + val workspace = new FileSystemWorkspace('''output/''' + formattedDate + '''/''', "") + workspace.initAndClear + + // Logicproblem writing setup + val reg = Resource.Factory.Registry.INSTANCE + val map = reg.extensionToFactoryMap + map.put("logicproblem", new XMIResourceFactoryImpl) + + println("Input and output workspaces are created") + + print(TaxationPackage.eINSTANCE.getEClassifiers.filter(EClass).toList.get(0)) + + val metamodel = loadMetamodel(TaxationPackage.eINSTANCE) +// val partialModel = loadPartialModel(inputs, "yakindu/Yakindu.xmi") +// val queries = loadQueries(metamodel, Patterns.instance) + println("DSL loaded") + + val SIZE = 10 + var REPS = 1 + + val RUNTIME = 300 + + val modelGenerationProblem = ecore2Logic.transformMetamodel(metamodel, new Ecore2LogicConfiguration()) +// var modelExtensionProblem = instanceModel2Logic.transform(modelGenerationProblem, partialModel) +// var validModelExtensionProblem = viatra2Logic.transformQueries(queries, modelExtensionProblem, +// new Viatra2LogicConfiguration) + var problem = modelGenerationProblem.output + workspace.writeModel(problem, "scenario.logicproblem") + println("Problem created") + + for (var i = 0; i <= REPS; i++) { + + var ViatraReasoner reasoner = new ViatraReasoner + + // ///////////////////////////////////////////////////// + // Define Config File + val solverConfig = new ViatraReasonerConfiguration => [ + // add configuration things, in config file first +// it.documentationLevel = DocumentationLevel::FULL +// it.iteration = iter + it.runtimeLimit = RUNTIME + it.typeScopes.maxNewElements = SIZE + it.typeScopes.minNewElements = SIZE + ] + + var solution = reasoner.solve(problem, solverConfig, workspace) + print("Problem Solved") + + // Run Garbage Collector + val Runtime r = Runtime.getRuntime(); + r.gc(); + r.gc(); + r.gc(); + Thread.sleep(3000) + } + + } + + def static Map getTypeMap(Map classMap, EcoreMetamodelDescriptor metamodel, + Ecore2Logic e2l, Ecore2Logic_Trace trace) { + val typeMap = new HashMap + val listMap = metamodel.classes.toMap[s|s.name] + + for (Class elem : classMap.keySet) { + typeMap.put(e2l.TypeofEClass( + trace, + listMap.get(elem.simpleName) + ), classMap.get(elem)) + } + return typeMap + } + + def static loadMetamodel(EPackage pckg) { + val List classes = pckg.getEClassifiers.filter(EClass).toList + val List enums = pckg.getEClassifiers.filter(EEnum).toList + val List literals = enums.map[getELiterals].flatten.toList + val List references = classes.map[getEReferences].flatten.toList + val List attributes = classes.map[getEAttributes].flatten.toList + return new EcoreMetamodelDescriptor(classes, #{}, false, enums, literals, references, attributes) + } + + def static loadPartialModel(ReasonerWorkspace inputs, String path) { + Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl()) + inputs.readModel(EObject, path).eResource.contents +// inputs.readModel(EObject,"FamInstance.xmi").eResource.allContents.toList + } + + def static loadQueries(EcoreMetamodelDescriptor metamodel, IQueryGroup i) { + val patterns = i.specifications.toList + val wfPatterns = patterns.filter[it.allAnnotations.exists[it.name == "Constraint"]].toSet + val derivedFeatures = emptyMap + // NO DERIVED FEATURES +// val derivedFeatures = new LinkedHashMap +// derivedFeatures.put(i.type,metamodel.attributes.filter[it.name == "type"].head) +// derivedFeatures.put(i.model,metamodel.references.filter[it.name == "model"].head) + val res = new ViatraQuerySetDescriptor( + patterns, + wfPatterns, + derivedFeatures + ) + return res + } + +} -- cgit v1.2.3-54-g00ecf