diff options
Diffstat (limited to 'Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse')
7 files changed, 458 insertions, 0 deletions
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/.CpsStateCoder.xtendbin b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/.CpsStateCoder.xtendbin new file mode 100644 index 00000000..cdfe3921 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/.CpsStateCoder.xtendbin | |||
Binary files differ | |||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/.RuleBasedCpsMain.xtendbin b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/.RuleBasedCpsMain.xtendbin new file mode 100644 index 00000000..9be64b30 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/.RuleBasedCpsMain.xtendbin | |||
Binary files differ | |||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/.RuleBasedCpsSolver.xtendbin b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/.RuleBasedCpsSolver.xtendbin new file mode 100644 index 00000000..02fb74ef --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/.RuleBasedCpsSolver.xtendbin | |||
Binary files differ | |||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/.gitignore b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/.gitignore new file mode 100644 index 00000000..e24f10f4 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/.gitignore | |||
@@ -0,0 +1,3 @@ | |||
1 | /.RuleBasedCpsSolver.java._trace | ||
2 | /.RuleBasedCpsMain.java._trace | ||
3 | /.CpsStateCoder.java._trace | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/CpsStateCoder.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/CpsStateCoder.java new file mode 100644 index 00000000..3ae8e828 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/CpsStateCoder.java | |||
@@ -0,0 +1,316 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.cps.dse; | ||
2 | |||
3 | import com.google.common.base.Objects; | ||
4 | import hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance; | ||
5 | import hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem; | ||
6 | import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.HostType; | ||
8 | import hu.bme.mit.inf.dslreasoner.domains.cps.Request; | ||
9 | import hu.bme.mit.inf.dslreasoner.domains.cps.Requirement; | ||
10 | import java.util.Arrays; | ||
11 | import org.eclipse.emf.common.notify.Notifier; | ||
12 | import org.eclipse.emf.common.util.EList; | ||
13 | import org.eclipse.emf.ecore.EObject; | ||
14 | import org.eclipse.emf.ecore.resource.Resource; | ||
15 | import org.eclipse.emf.ecore.resource.ResourceSet; | ||
16 | import org.eclipse.viatra.dse.statecode.IStateCoder; | ||
17 | import org.eclipse.viatra.dse.statecode.IStateCoderFactory; | ||
18 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
19 | import org.eclipse.xtend2.lib.StringConcatenation; | ||
20 | import org.eclipse.xtend2.lib.StringConcatenationClient; | ||
21 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
22 | |||
23 | @SuppressWarnings("all") | ||
24 | public class CpsStateCoder implements IStateCoder { | ||
25 | public static class Factory implements IStateCoderFactory { | ||
26 | @Override | ||
27 | public IStateCoder createStateCoder() { | ||
28 | return new CpsStateCoder(); | ||
29 | } | ||
30 | } | ||
31 | |||
32 | private CyberPhysicalSystem cps; | ||
33 | |||
34 | protected CpsStateCoder() { | ||
35 | } | ||
36 | |||
37 | @Override | ||
38 | public void init(final Notifier notifier) { | ||
39 | CyberPhysicalSystem _switchResult = null; | ||
40 | boolean _matched = false; | ||
41 | if (notifier instanceof ResourceSet) { | ||
42 | _matched=true; | ||
43 | _switchResult = this.getCpsFromResourceSet(((ResourceSet)notifier)); | ||
44 | } | ||
45 | if (!_matched) { | ||
46 | if (notifier instanceof Resource) { | ||
47 | _matched=true; | ||
48 | _switchResult = this.getCpsFromResource(((Resource)notifier)); | ||
49 | } | ||
50 | } | ||
51 | if (!_matched) { | ||
52 | if (notifier instanceof CyberPhysicalSystem) { | ||
53 | _matched=true; | ||
54 | _switchResult = ((CyberPhysicalSystem)notifier); | ||
55 | } | ||
56 | } | ||
57 | if (!_matched) { | ||
58 | throw new IllegalArgumentException("notifier is not a CyberPhysicalSystem"); | ||
59 | } | ||
60 | this.cps = _switchResult; | ||
61 | } | ||
62 | |||
63 | private CyberPhysicalSystem getCpsFromResourceSet(final ResourceSet resourceSet) { | ||
64 | CyberPhysicalSystem _xblockexpression = null; | ||
65 | { | ||
66 | boolean _isEmpty = resourceSet.getResources().isEmpty(); | ||
67 | if (_isEmpty) { | ||
68 | throw new IllegalArgumentException("No Resource in ResourceSet"); | ||
69 | } | ||
70 | final Resource resource = IterableExtensions.<Resource>head(resourceSet.getResources()); | ||
71 | _xblockexpression = this.getCpsFromResource(resource); | ||
72 | } | ||
73 | return _xblockexpression; | ||
74 | } | ||
75 | |||
76 | private CyberPhysicalSystem getCpsFromResource(final Resource resource) { | ||
77 | CyberPhysicalSystem _xblockexpression = null; | ||
78 | { | ||
79 | boolean _isEmpty = resource.getContents().isEmpty(); | ||
80 | if (_isEmpty) { | ||
81 | throw new IllegalArgumentException("No EObject in Resource"); | ||
82 | } | ||
83 | final EObject cps = IterableExtensions.<EObject>head(resource.getContents()); | ||
84 | CyberPhysicalSystem _xifexpression = null; | ||
85 | if ((cps instanceof CyberPhysicalSystem)) { | ||
86 | _xifexpression = ((CyberPhysicalSystem)cps); | ||
87 | } else { | ||
88 | throw new IllegalArgumentException("EObject in Resource is not a CyberPhysicalSystem"); | ||
89 | } | ||
90 | _xblockexpression = _xifexpression; | ||
91 | } | ||
92 | return _xblockexpression; | ||
93 | } | ||
94 | |||
95 | @Override | ||
96 | public String createStateCode() { | ||
97 | StringConcatenation _builder = new StringConcatenation(); | ||
98 | StringConcatenationClient _createRequestsCode = this.createRequestsCode(); | ||
99 | _builder.append(_createRequestsCode); | ||
100 | CharSequence _createHostTypesCode = this.createHostTypesCode(); | ||
101 | _builder.append(_createHostTypesCode); | ||
102 | return _builder.toString(); | ||
103 | } | ||
104 | |||
105 | private StringConcatenationClient createRequestsCode() { | ||
106 | StringConcatenationClient _client = new StringConcatenationClient() { | ||
107 | @Override | ||
108 | protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { | ||
109 | { | ||
110 | EList<Request> _requests = CpsStateCoder.this.cps.getRequests(); | ||
111 | for(final Request request : _requests) { | ||
112 | StringConcatenationClient _createRequestCode = CpsStateCoder.this.createRequestCode(request); | ||
113 | _builder.append(_createRequestCode); | ||
114 | } | ||
115 | } | ||
116 | } | ||
117 | }; | ||
118 | return _client; | ||
119 | } | ||
120 | |||
121 | private StringConcatenationClient createRequestCode(final Request request) { | ||
122 | StringConcatenationClient _client = new StringConcatenationClient() { | ||
123 | @Override | ||
124 | protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { | ||
125 | _builder.append("["); | ||
126 | { | ||
127 | EList<Requirement> _requirements = request.getRequirements(); | ||
128 | for(final Requirement requirement : _requirements) { | ||
129 | StringConcatenationClient _createRequirementCode = CpsStateCoder.this.createRequirementCode(requirement); | ||
130 | _builder.append(_createRequirementCode); | ||
131 | } | ||
132 | } | ||
133 | _builder.append("]"); | ||
134 | } | ||
135 | }; | ||
136 | return _client; | ||
137 | } | ||
138 | |||
139 | private StringConcatenationClient createRequirementCode(final Requirement requirement) { | ||
140 | StringConcatenationClient _client = new StringConcatenationClient() { | ||
141 | @Override | ||
142 | protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { | ||
143 | _builder.append("["); | ||
144 | { | ||
145 | EList<ApplicationInstance> _instances = requirement.getInstances(); | ||
146 | boolean _hasElements = false; | ||
147 | for(final ApplicationInstance app : _instances) { | ||
148 | if (!_hasElements) { | ||
149 | _hasElements = true; | ||
150 | } else { | ||
151 | _builder.appendImmediate(",", ""); | ||
152 | } | ||
153 | String _createAppCode = CpsStateCoder.this.createAppCode(app); | ||
154 | _builder.append(_createAppCode); | ||
155 | } | ||
156 | } | ||
157 | _builder.append("]"); | ||
158 | } | ||
159 | }; | ||
160 | return _client; | ||
161 | } | ||
162 | |||
163 | private String createAppCode(final ApplicationInstance app) { | ||
164 | String _xifexpression = null; | ||
165 | HostInstance _allocatedTo = app.getAllocatedTo(); | ||
166 | boolean _tripleEquals = (_allocatedTo == null); | ||
167 | if (_tripleEquals) { | ||
168 | _xifexpression = "-"; | ||
169 | } else { | ||
170 | _xifexpression = this.createMatchArgumentCode(app.getAllocatedTo()); | ||
171 | } | ||
172 | return _xifexpression; | ||
173 | } | ||
174 | |||
175 | private CharSequence createHostTypesCode() { | ||
176 | StringConcatenation _builder = new StringConcatenation(); | ||
177 | _builder.append("("); | ||
178 | { | ||
179 | EList<HostType> _hostTypes = this.cps.getHostTypes(); | ||
180 | boolean _hasElements = false; | ||
181 | for(final HostType hostType : _hostTypes) { | ||
182 | if (!_hasElements) { | ||
183 | _hasElements = true; | ||
184 | } else { | ||
185 | _builder.appendImmediate(",", ""); | ||
186 | } | ||
187 | int _size = hostType.getInstances().size(); | ||
188 | _builder.append(_size); | ||
189 | } | ||
190 | } | ||
191 | _builder.append(")"); | ||
192 | return _builder; | ||
193 | } | ||
194 | |||
195 | @Override | ||
196 | public String createActivationCode(final IPatternMatch match) { | ||
197 | StringConcatenation _builder = new StringConcatenation(); | ||
198 | String _simpleName = match.specification().getSimpleName(); | ||
199 | _builder.append(_simpleName); | ||
200 | _builder.append("("); | ||
201 | { | ||
202 | Object[] _array = match.toArray(); | ||
203 | boolean _hasElements = false; | ||
204 | for(final Object arg : _array) { | ||
205 | if (!_hasElements) { | ||
206 | _hasElements = true; | ||
207 | } else { | ||
208 | _builder.appendImmediate(",", ""); | ||
209 | } | ||
210 | String _createMatchArgumentCode = this.createMatchArgumentCode(arg); | ||
211 | _builder.append(_createMatchArgumentCode); | ||
212 | } | ||
213 | } | ||
214 | _builder.append(")"); | ||
215 | return _builder.toString(); | ||
216 | } | ||
217 | |||
218 | protected String _createMatchArgumentCode(final Requirement requirement) { | ||
219 | String _xblockexpression = null; | ||
220 | { | ||
221 | final EObject request = requirement.eContainer(); | ||
222 | String _xifexpression = null; | ||
223 | if ((request instanceof Request)) { | ||
224 | String _xblockexpression_1 = null; | ||
225 | { | ||
226 | EObject _eContainer = ((Request)request).eContainer(); | ||
227 | boolean _notEquals = (!Objects.equal(_eContainer, this.cps)); | ||
228 | if (_notEquals) { | ||
229 | throw new IllegalArgumentException("Request is not contained in the CPS"); | ||
230 | } | ||
231 | final int requestIndex = this.cps.getRequests().indexOf(request); | ||
232 | final int requirementIndex = ((Request)request).getRequirements().indexOf(requirement); | ||
233 | String _plus = (Integer.valueOf(requestIndex) + "."); | ||
234 | _xblockexpression_1 = (_plus + Integer.valueOf(requirementIndex)); | ||
235 | } | ||
236 | _xifexpression = _xblockexpression_1; | ||
237 | } else { | ||
238 | throw new IllegalArgumentException("Requirement is not contained in a request"); | ||
239 | } | ||
240 | _xblockexpression = _xifexpression; | ||
241 | } | ||
242 | return _xblockexpression; | ||
243 | } | ||
244 | |||
245 | protected String _createMatchArgumentCode(final ApplicationInstance app) { | ||
246 | String _xblockexpression = null; | ||
247 | { | ||
248 | final Requirement requirement = app.getRequirement(); | ||
249 | if ((requirement == null)) { | ||
250 | throw new IllegalArgumentException("Application instance is not associated with a requirement"); | ||
251 | } | ||
252 | final int instanceIndex = requirement.getInstances().indexOf(app); | ||
253 | String _createMatchArgumentCode = this.createMatchArgumentCode(requirement); | ||
254 | String _plus = (_createMatchArgumentCode + "."); | ||
255 | _xblockexpression = (_plus + Integer.valueOf(instanceIndex)); | ||
256 | } | ||
257 | return _xblockexpression; | ||
258 | } | ||
259 | |||
260 | protected String _createMatchArgumentCode(final HostInstance host) { | ||
261 | String _xblockexpression = null; | ||
262 | { | ||
263 | final EObject hostType = host.eContainer(); | ||
264 | String _xifexpression = null; | ||
265 | if ((hostType instanceof HostType)) { | ||
266 | String _xblockexpression_1 = null; | ||
267 | { | ||
268 | final int hostIndex = ((HostType)hostType).getInstances().indexOf(host); | ||
269 | String _createMatchArgumentCode = this.createMatchArgumentCode(hostType); | ||
270 | String _plus = (_createMatchArgumentCode + "."); | ||
271 | _xblockexpression_1 = (_plus + Integer.valueOf(hostIndex)); | ||
272 | } | ||
273 | _xifexpression = _xblockexpression_1; | ||
274 | } else { | ||
275 | throw new IllegalArgumentException("Host is not contained in a host type"); | ||
276 | } | ||
277 | _xblockexpression = _xifexpression; | ||
278 | } | ||
279 | return _xblockexpression; | ||
280 | } | ||
281 | |||
282 | protected String _createMatchArgumentCode(final HostType hostType) { | ||
283 | String _xblockexpression = null; | ||
284 | { | ||
285 | EObject _eContainer = hostType.eContainer(); | ||
286 | boolean _notEquals = (!Objects.equal(_eContainer, this.cps)); | ||
287 | if (_notEquals) { | ||
288 | throw new IllegalArgumentException("Host type is not contained in the CPS"); | ||
289 | } | ||
290 | final int hostTypeIndex = this.cps.getHostTypes().indexOf(hostType); | ||
291 | _xblockexpression = Integer.valueOf(hostTypeIndex).toString(); | ||
292 | } | ||
293 | return _xblockexpression; | ||
294 | } | ||
295 | |||
296 | protected String _createMatchArgumentCode(final Object object) { | ||
297 | throw new IllegalArgumentException("Unknown match argument: "); | ||
298 | } | ||
299 | |||
300 | protected String createMatchArgumentCode(final Object app) { | ||
301 | if (app instanceof ApplicationInstance) { | ||
302 | return _createMatchArgumentCode((ApplicationInstance)app); | ||
303 | } else if (app instanceof HostInstance) { | ||
304 | return _createMatchArgumentCode((HostInstance)app); | ||
305 | } else if (app instanceof HostType) { | ||
306 | return _createMatchArgumentCode((HostType)app); | ||
307 | } else if (app instanceof Requirement) { | ||
308 | return _createMatchArgumentCode((Requirement)app); | ||
309 | } else if (app != null) { | ||
310 | return _createMatchArgumentCode(app); | ||
311 | } else { | ||
312 | throw new IllegalArgumentException("Unhandled parameter types: " + | ||
313 | Arrays.<Object>asList(app).toString()); | ||
314 | } | ||
315 | } | ||
316 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/RuleBasedCpsMain.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/RuleBasedCpsMain.java new file mode 100644 index 00000000..7d81f84b --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/RuleBasedCpsMain.java | |||
@@ -0,0 +1,46 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.cps.dse; | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.domains.cps.CpsPackage; | ||
4 | import hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem; | ||
5 | import hu.bme.mit.inf.dslreasoner.domains.cps.dse.RuleBasedCpsSolver; | ||
6 | import hu.bme.mit.inf.dslreasoner.domains.cps.generator.CpsGenerator; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CpsQueries; | ||
8 | import java.util.Map; | ||
9 | import org.eclipse.emf.ecore.EPackage; | ||
10 | import org.eclipse.emf.ecore.EStructuralFeature; | ||
11 | import org.eclipse.emf.ecore.resource.Resource; | ||
12 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; | ||
13 | import org.eclipse.viatra.addon.querybasedfeatures.runtime.QueryBasedFeatureSettingDelegateFactory; | ||
14 | import org.eclipse.viatra.addon.querybasedfeatures.runtime.handler.QueryBasedFeatures; | ||
15 | import org.eclipse.viatra.dse.api.DesignSpaceExplorer; | ||
16 | import org.eclipse.viatra.query.runtime.extensibility.SingletonQueryGroupProvider; | ||
17 | import org.eclipse.viatra.query.runtime.registry.IQuerySpecificationRegistry; | ||
18 | import org.eclipse.viatra.query.runtime.registry.QuerySpecificationRegistry; | ||
19 | import org.eclipse.viatra.query.runtime.registry.connector.QueryGroupProviderSourceConnector; | ||
20 | |||
21 | @SuppressWarnings("all") | ||
22 | public class RuleBasedCpsMain { | ||
23 | private RuleBasedCpsMain() { | ||
24 | new IllegalStateException("This is a static utility class and should not be instantiated directly."); | ||
25 | } | ||
26 | |||
27 | public static void main(final String[] args) { | ||
28 | DesignSpaceExplorer.turnOnLogging(DesignSpaceExplorer.DseLoggingLevel.VERBOSE_FULL); | ||
29 | Map<String, Object> _extensionToFactoryMap = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap(); | ||
30 | XMIResourceFactoryImpl _xMIResourceFactoryImpl = new XMIResourceFactoryImpl(); | ||
31 | _extensionToFactoryMap.put(Resource.Factory.Registry.DEFAULT_EXTENSION, _xMIResourceFactoryImpl); | ||
32 | QueryBasedFeatureSettingDelegateFactory _queryBasedFeatureSettingDelegateFactory = new QueryBasedFeatureSettingDelegateFactory(); | ||
33 | EStructuralFeature.Internal.SettingDelegate.Factory.Registry.INSTANCE.put(QueryBasedFeatures.ANNOTATION_SOURCE, _queryBasedFeatureSettingDelegateFactory); | ||
34 | EPackage.Registry.INSTANCE.put(CpsPackage.eNS_URI, CpsPackage.eINSTANCE); | ||
35 | IQuerySpecificationRegistry _instance = QuerySpecificationRegistry.getInstance(); | ||
36 | CpsQueries _instance_1 = CpsQueries.instance(); | ||
37 | SingletonQueryGroupProvider _singletonQueryGroupProvider = new SingletonQueryGroupProvider(_instance_1); | ||
38 | QueryGroupProviderSourceConnector _queryGroupProviderSourceConnector = new QueryGroupProviderSourceConnector("CpsQueries", _singletonQueryGroupProvider, | ||
39 | true); | ||
40 | _instance.addSource(_queryGroupProviderSourceConnector); | ||
41 | final CpsGenerator generator = new CpsGenerator(1, 4, 1); | ||
42 | final CyberPhysicalSystem problem = generator.generateCpsProblem(); | ||
43 | final RuleBasedCpsSolver solver = new RuleBasedCpsSolver(); | ||
44 | solver.solve(problem); | ||
45 | } | ||
46 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/RuleBasedCpsSolver.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/RuleBasedCpsSolver.java new file mode 100644 index 00000000..fd348752 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/RuleBasedCpsSolver.java | |||
@@ -0,0 +1,93 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.cps.dse; | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance; | ||
4 | import hu.bme.mit.inf.dslreasoner.domains.cps.CpsFactory; | ||
5 | import hu.bme.mit.inf.dslreasoner.domains.cps.CpsPackage; | ||
6 | import hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance; | ||
8 | import hu.bme.mit.inf.dslreasoner.domains.cps.dse.CpsStateCoder; | ||
9 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.Allocate; | ||
10 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeHddMetric; | ||
11 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeMemoryMetric; | ||
12 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CostMetric; | ||
13 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CreateHostInstance; | ||
14 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.GuidanceObjective; | ||
15 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RequirementNotSatisfied; | ||
16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CompositeDirectionalThresholdObjective; | ||
17 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveKind; | ||
18 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveThreshold; | ||
19 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.QueryBasedObjective; | ||
20 | import java.util.Collection; | ||
21 | import java.util.function.Consumer; | ||
22 | import org.eclipse.emf.common.util.EList; | ||
23 | import org.eclipse.viatra.dse.api.DesignSpaceExplorer; | ||
24 | import org.eclipse.viatra.dse.api.Solution; | ||
25 | import org.eclipse.viatra.dse.evolutionary.EvolutionaryStrategy; | ||
26 | import org.eclipse.viatra.dse.evolutionary.EvolutionaryStrategyBuilder; | ||
27 | import org.eclipse.viatra.dse.objectives.Fitness; | ||
28 | import org.eclipse.viatra.transformation.runtime.emf.rules.batch.BatchTransformationRuleFactory; | ||
29 | import org.eclipse.xtext.xbase.lib.Extension; | ||
30 | import org.eclipse.xtext.xbase.lib.InputOutput; | ||
31 | |||
32 | @SuppressWarnings("all") | ||
33 | public class RuleBasedCpsSolver { | ||
34 | @Extension | ||
35 | private final BatchTransformationRuleFactory _batchTransformationRuleFactory = new BatchTransformationRuleFactory(); | ||
36 | |||
37 | @Extension | ||
38 | private final CpsFactory _cpsFactory = CpsFactory.eINSTANCE; | ||
39 | |||
40 | public void solve(final CyberPhysicalSystem problem) { | ||
41 | final DesignSpaceExplorer dse = new DesignSpaceExplorer(); | ||
42 | dse.addMetaModelPackage(CpsPackage.eINSTANCE); | ||
43 | dse.setInitialModel(problem.eResource().getResourceSet()); | ||
44 | final Consumer<RequirementNotSatisfied.Match> _function = (RequirementNotSatisfied.Match it) -> { | ||
45 | final ApplicationInstance app = this._cpsFactory.createApplicationInstance(); | ||
46 | EList<ApplicationInstance> _instances = it.getReq().getType().getInstances(); | ||
47 | _instances.add(app); | ||
48 | EList<ApplicationInstance> _instances_1 = it.getReq().getInstances(); | ||
49 | _instances_1.add(app); | ||
50 | }; | ||
51 | dse.addTransformationRule(this._batchTransformationRuleFactory.<RequirementNotSatisfied.Match, RequirementNotSatisfied.Matcher>createRule(RequirementNotSatisfied.instance()).action(_function).build()); | ||
52 | final Consumer<Allocate.Match> _function_1 = (Allocate.Match it) -> { | ||
53 | ApplicationInstance _app = it.getApp(); | ||
54 | _app.setAllocatedTo(it.getHost()); | ||
55 | }; | ||
56 | dse.addTransformationRule(this._batchTransformationRuleFactory.<Allocate.Match, Allocate.Matcher>createRule(Allocate.instance()).action(_function_1).build()); | ||
57 | final Consumer<CreateHostInstance.Match> _function_2 = (CreateHostInstance.Match it) -> { | ||
58 | EList<HostInstance> _instances = it.getHostType().getInstances(); | ||
59 | HostInstance _createHostInstance = this._cpsFactory.createHostInstance(); | ||
60 | _instances.add(_createHostInstance); | ||
61 | }; | ||
62 | dse.addTransformationRule(this._batchTransformationRuleFactory.<CreateHostInstance.Match, CreateHostInstance.Matcher>createRule(CreateHostInstance.instance()).action(_function_2).build()); | ||
63 | GuidanceObjective _instance = GuidanceObjective.instance(); | ||
64 | ObjectiveThreshold.Inclusive _inclusive = new ObjectiveThreshold.Inclusive(0); | ||
65 | QueryBasedObjective _queryBasedObjective = new QueryBasedObjective(_instance, ObjectiveKind.LOWER_IS_BETTER, _inclusive, 0); | ||
66 | AverageFreeMemoryMetric _instance_1 = AverageFreeMemoryMetric.instance(); | ||
67 | ObjectiveThreshold.Inclusive _inclusive_1 = new ObjectiveThreshold.Inclusive(0.75); | ||
68 | QueryBasedObjective _queryBasedObjective_1 = new QueryBasedObjective(_instance_1, ObjectiveKind.LOWER_IS_BETTER, _inclusive_1, 0); | ||
69 | AverageFreeHddMetric _instance_2 = AverageFreeHddMetric.instance(); | ||
70 | ObjectiveThreshold.Inclusive _inclusive_2 = new ObjectiveThreshold.Inclusive(0.75); | ||
71 | QueryBasedObjective _queryBasedObjective_2 = new QueryBasedObjective(_instance_2, ObjectiveKind.LOWER_IS_BETTER, _inclusive_2, 0); | ||
72 | CompositeDirectionalThresholdObjective _compositeDirectionalThresholdObjective = new CompositeDirectionalThresholdObjective("Composite", _queryBasedObjective, _queryBasedObjective_1, _queryBasedObjective_2); | ||
73 | dse.addObjective(_compositeDirectionalThresholdObjective); | ||
74 | CostMetric _instance_3 = CostMetric.instance(); | ||
75 | QueryBasedObjective _queryBasedObjective_3 = new QueryBasedObjective(_instance_3, ObjectiveKind.LOWER_IS_BETTER, | ||
76 | ObjectiveThreshold.NO_THRESHOLD, 0); | ||
77 | dse.addObjective(_queryBasedObjective_3); | ||
78 | dse.setMaxNumberOfThreads(1); | ||
79 | CpsStateCoder.Factory _factory = new CpsStateCoder.Factory(); | ||
80 | dse.setStateCoderFactory(_factory); | ||
81 | final EvolutionaryStrategy strategy = EvolutionaryStrategyBuilder.createNsga2Strategy(25); | ||
82 | dse.startExplorationWithTimeout(strategy, ((2 * 60) * 1000)); | ||
83 | Collection<Solution> _solutions = dse.getSolutions(); | ||
84 | for (final Solution solution : _solutions) { | ||
85 | Object _stateCode = solution.getStateCode(); | ||
86 | String _plus = ("Found solution: " + _stateCode); | ||
87 | String _plus_1 = (_plus + " "); | ||
88 | Fitness _fitness = solution.getArbitraryTrajectory().getFitness(); | ||
89 | String _plus_2 = (_plus_1 + _fitness); | ||
90 | InputOutput.<String>println(_plus_2); | ||
91 | } | ||
92 | } | ||
93 | } | ||