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.queries/xtend-gen | |
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.queries/xtend-gen')
3 files changed, 0 insertions, 169 deletions
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/xtend-gen/run/.RunGenerator.xtendbin b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/xtend-gen/run/.RunGenerator.xtendbin deleted file mode 100644 index e2021169..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/xtend-gen/run/.RunGenerator.xtendbin +++ /dev/null | |||
Binary files differ | |||
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/xtend-gen/run/.gitignore b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/xtend-gen/run/.gitignore deleted file mode 100644 index 8e503b4a..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/xtend-gen/run/.gitignore +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | /.GenerateScenarios.java._trace | ||
2 | /.checkQueries.java._trace | ||
3 | /.RunGenerator.xtendbin | ||
4 | /GenerateScenarios.java | ||
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/xtend-gen/run/GenerateScenarios.java b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/xtend-gen/run/GenerateScenarios.java deleted file mode 100644 index 7ec45124..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/xtend-gen/run/GenerateScenarios.java +++ /dev/null | |||
@@ -1,165 +0,0 @@ | |||
1 | package run; | ||
2 | |||
3 | import Taxation.TaxationPackage; | ||
4 | import com.google.common.base.Objects; | ||
5 | import com.google.common.collect.Iterables; | ||
6 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic; | ||
7 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration; | ||
8 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace; | ||
9 | import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor; | ||
10 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput; | ||
11 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type; | ||
12 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem; | ||
13 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult; | ||
14 | import hu.bme.mit.inf.dslreasoner.viatra2logic.ViatraQuerySetDescriptor; | ||
15 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner; | ||
16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration; | ||
17 | import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace; | ||
18 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace; | ||
19 | import java.text.SimpleDateFormat; | ||
20 | import java.util.Collections; | ||
21 | import java.util.Date; | ||
22 | import java.util.HashMap; | ||
23 | import java.util.List; | ||
24 | import java.util.Map; | ||
25 | import java.util.Set; | ||
26 | import org.eclipse.emf.common.util.EList; | ||
27 | import org.eclipse.emf.ecore.EAttribute; | ||
28 | import org.eclipse.emf.ecore.EClass; | ||
29 | import org.eclipse.emf.ecore.EEnum; | ||
30 | import org.eclipse.emf.ecore.EEnumLiteral; | ||
31 | import org.eclipse.emf.ecore.EObject; | ||
32 | import org.eclipse.emf.ecore.EPackage; | ||
33 | import org.eclipse.emf.ecore.EReference; | ||
34 | import org.eclipse.emf.ecore.EStructuralFeature; | ||
35 | import org.eclipse.emf.ecore.resource.Resource; | ||
36 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; | ||
37 | import org.eclipse.viatra.query.runtime.api.IQueryGroup; | ||
38 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; | ||
40 | import org.eclipse.xtend2.lib.StringConcatenation; | ||
41 | import org.eclipse.xtext.xbase.lib.CollectionLiterals; | ||
42 | import org.eclipse.xtext.xbase.lib.Exceptions; | ||
43 | import org.eclipse.xtext.xbase.lib.Functions.Function1; | ||
44 | import org.eclipse.xtext.xbase.lib.InputOutput; | ||
45 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
46 | import org.eclipse.xtext.xbase.lib.ListExtensions; | ||
47 | import org.eclipse.xtext.xbase.lib.ObjectExtensions; | ||
48 | import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; | ||
49 | |||
50 | @SuppressWarnings("all") | ||
51 | public class GenerateScenarios { | ||
52 | public static void main(final String[] args) { | ||
53 | try { | ||
54 | final Ecore2Logic ecore2Logic = new Ecore2Logic(); | ||
55 | long _currentTimeMillis = System.currentTimeMillis(); | ||
56 | final Date date = new Date(_currentTimeMillis); | ||
57 | final SimpleDateFormat format = new SimpleDateFormat("dd-HHmm"); | ||
58 | final String formattedDate = format.format(date); | ||
59 | StringConcatenation _builder = new StringConcatenation(); | ||
60 | _builder.append("output/"); | ||
61 | String _plus = (_builder.toString() + formattedDate); | ||
62 | StringConcatenation _builder_1 = new StringConcatenation(); | ||
63 | _builder_1.append("/"); | ||
64 | String _plus_1 = (_plus + _builder_1); | ||
65 | final FileSystemWorkspace workspace = new FileSystemWorkspace(_plus_1, ""); | ||
66 | workspace.initAndClear(); | ||
67 | final Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE; | ||
68 | final Map<String, Object> map = reg.getExtensionToFactoryMap(); | ||
69 | XMIResourceFactoryImpl _xMIResourceFactoryImpl = new XMIResourceFactoryImpl(); | ||
70 | map.put("logicproblem", _xMIResourceFactoryImpl); | ||
71 | InputOutput.<String>println("Input and output workspaces are created"); | ||
72 | InputOutput.<EClass>print(IterableExtensions.<EClass>toList(Iterables.<EClass>filter(TaxationPackage.eINSTANCE.getEClassifiers(), EClass.class)).get(0)); | ||
73 | final EcoreMetamodelDescriptor metamodel = GenerateScenarios.loadMetamodel(TaxationPackage.eINSTANCE); | ||
74 | InputOutput.<String>println("DSL loaded"); | ||
75 | final int SIZE = 10; | ||
76 | int REPS = 1; | ||
77 | final int RUNTIME = 300; | ||
78 | Ecore2LogicConfiguration _ecore2LogicConfiguration = new Ecore2LogicConfiguration(); | ||
79 | final TracedOutput<LogicProblem, Ecore2Logic_Trace> modelGenerationProblem = ecore2Logic.transformMetamodel(metamodel, _ecore2LogicConfiguration); | ||
80 | LogicProblem problem = modelGenerationProblem.getOutput(); | ||
81 | workspace.writeModel(problem, "scenario.logicproblem"); | ||
82 | InputOutput.<String>println("Problem created"); | ||
83 | for (int i = 0; (i <= REPS); i++) { | ||
84 | { | ||
85 | ViatraReasoner reasoner = new ViatraReasoner(); | ||
86 | ViatraReasonerConfiguration _viatraReasonerConfiguration = new ViatraReasonerConfiguration(); | ||
87 | final Procedure1<ViatraReasonerConfiguration> _function = (ViatraReasonerConfiguration it) -> { | ||
88 | it.runtimeLimit = RUNTIME; | ||
89 | it.typeScopes.maxNewElements = SIZE; | ||
90 | it.typeScopes.minNewElements = SIZE; | ||
91 | }; | ||
92 | final ViatraReasonerConfiguration solverConfig = ObjectExtensions.<ViatraReasonerConfiguration>operator_doubleArrow(_viatraReasonerConfiguration, _function); | ||
93 | LogicResult solution = reasoner.solve(problem, solverConfig, workspace); | ||
94 | InputOutput.<String>print("Problem Solved"); | ||
95 | final Runtime r = Runtime.getRuntime(); | ||
96 | r.gc(); | ||
97 | r.gc(); | ||
98 | r.gc(); | ||
99 | Thread.sleep(3000); | ||
100 | } | ||
101 | } | ||
102 | } catch (Throwable _e) { | ||
103 | throw Exceptions.sneakyThrow(_e); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | public static Map<Type, Integer> getTypeMap(final Map<Class, Integer> classMap, final EcoreMetamodelDescriptor metamodel, final Ecore2Logic e2l, final Ecore2Logic_Trace trace) { | ||
108 | final HashMap<Type, Integer> typeMap = new HashMap<Type, Integer>(); | ||
109 | final Function1<EClass, String> _function = (EClass s) -> { | ||
110 | return s.getName(); | ||
111 | }; | ||
112 | final Map<String, EClass> listMap = IterableExtensions.<String, EClass>toMap(metamodel.getClasses(), _function); | ||
113 | Set<Class> _keySet = classMap.keySet(); | ||
114 | for (final Class elem : _keySet) { | ||
115 | typeMap.put( | ||
116 | e2l.TypeofEClass(trace, | ||
117 | listMap.get(elem.getSimpleName())), classMap.get(elem)); | ||
118 | } | ||
119 | return typeMap; | ||
120 | } | ||
121 | |||
122 | public static EcoreMetamodelDescriptor loadMetamodel(final EPackage pckg) { | ||
123 | final List<EClass> classes = IterableExtensions.<EClass>toList(Iterables.<EClass>filter(pckg.getEClassifiers(), EClass.class)); | ||
124 | final List<EEnum> enums = IterableExtensions.<EEnum>toList(Iterables.<EEnum>filter(pckg.getEClassifiers(), EEnum.class)); | ||
125 | final Function1<EEnum, EList<EEnumLiteral>> _function = (EEnum it) -> { | ||
126 | return it.getELiterals(); | ||
127 | }; | ||
128 | final List<EEnumLiteral> literals = IterableExtensions.<EEnumLiteral>toList(Iterables.<EEnumLiteral>concat(ListExtensions.<EEnum, EList<EEnumLiteral>>map(enums, _function))); | ||
129 | final Function1<EClass, EList<EReference>> _function_1 = (EClass it) -> { | ||
130 | return it.getEReferences(); | ||
131 | }; | ||
132 | final List<EReference> references = IterableExtensions.<EReference>toList(Iterables.<EReference>concat(ListExtensions.<EClass, EList<EReference>>map(classes, _function_1))); | ||
133 | final Function1<EClass, EList<EAttribute>> _function_2 = (EClass it) -> { | ||
134 | return it.getEAttributes(); | ||
135 | }; | ||
136 | final List<EAttribute> attributes = IterableExtensions.<EAttribute>toList(Iterables.<EAttribute>concat(ListExtensions.<EClass, EList<EAttribute>>map(classes, _function_2))); | ||
137 | return new EcoreMetamodelDescriptor(classes, Collections.<EClass>unmodifiableSet(CollectionLiterals.<EClass>newHashSet()), false, enums, literals, references, attributes); | ||
138 | } | ||
139 | |||
140 | public static EList<EObject> loadPartialModel(final ReasonerWorkspace inputs, final String path) { | ||
141 | EList<EObject> _xblockexpression = null; | ||
142 | { | ||
143 | Map<String, Object> _extensionToFactoryMap = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap(); | ||
144 | XMIResourceFactoryImpl _xMIResourceFactoryImpl = new XMIResourceFactoryImpl(); | ||
145 | _extensionToFactoryMap.put("*", _xMIResourceFactoryImpl); | ||
146 | _xblockexpression = inputs.<EObject>readModel(EObject.class, path).eResource().getContents(); | ||
147 | } | ||
148 | return _xblockexpression; | ||
149 | } | ||
150 | |||
151 | public static ViatraQuerySetDescriptor loadQueries(final EcoreMetamodelDescriptor metamodel, final IQueryGroup i) { | ||
152 | final List<IQuerySpecification<?>> patterns = IterableExtensions.<IQuerySpecification<?>>toList(i.getSpecifications()); | ||
153 | final Function1<IQuerySpecification<?>, Boolean> _function = (IQuerySpecification<?> it) -> { | ||
154 | final Function1<PAnnotation, Boolean> _function_1 = (PAnnotation it_1) -> { | ||
155 | String _name = it_1.getName(); | ||
156 | return Boolean.valueOf(Objects.equal(_name, "Constraint")); | ||
157 | }; | ||
158 | return Boolean.valueOf(IterableExtensions.<PAnnotation>exists(it.getAllAnnotations(), _function_1)); | ||
159 | }; | ||
160 | final Set<IQuerySpecification<?>> wfPatterns = IterableExtensions.<IQuerySpecification<?>>toSet(IterableExtensions.<IQuerySpecification<?>>filter(patterns, _function)); | ||
161 | final Map<IQuerySpecification<?>, EStructuralFeature> derivedFeatures = CollectionLiterals.<IQuerySpecification<?>, EStructuralFeature>emptyMap(); | ||
162 | final ViatraQuerySetDescriptor res = new ViatraQuerySetDescriptor(patterns, wfPatterns, derivedFeatures); | ||
163 | return res; | ||
164 | } | ||
165 | } | ||