diff options
author | Kristóf Marussy <kris7topher@gmail.com> | 2019-05-21 17:00:01 -0400 |
---|---|---|
committer | Kristóf Marussy <kris7topher@gmail.com> | 2019-05-21 17:00:01 -0400 |
commit | fd3684b5440dacca0c4bf4be15930555a79e2100 (patch) | |
tree | 24120a5c7fdae1532529fa0c4687dc1078cd1cde /Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/cplex/CpsToLpTranslator.java | |
parent | Interval hull aggregation operator (diff) | |
download | VIATRA-Generator-fd3684b5440dacca0c4bf4be15930555a79e2100.tar.gz VIATRA-Generator-fd3684b5440dacca0c4bf4be15930555a79e2100.tar.zst VIATRA-Generator-fd3684b5440dacca0c4bf4be15930555a79e2100.zip |
VIATRA DSE and COIN-OR CBC implementations of CPS case study
Diffstat (limited to 'Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/cplex/CpsToLpTranslator.java')
-rw-r--r-- | Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/cplex/CpsToLpTranslator.java | 505 |
1 files changed, 505 insertions, 0 deletions
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/cplex/CpsToLpTranslator.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/cplex/CpsToLpTranslator.java new file mode 100644 index 00000000..20afeee6 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/cplex/CpsToLpTranslator.java | |||
@@ -0,0 +1,505 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.cps.cplex; | ||
2 | |||
3 | import com.google.common.base.Objects; | ||
4 | import com.google.common.collect.ImmutableList; | ||
5 | import com.google.common.collect.ImmutableMap; | ||
6 | import hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationType; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem; | ||
8 | import hu.bme.mit.inf.dslreasoner.domains.cps.HostType; | ||
9 | import hu.bme.mit.inf.dslreasoner.domains.cps.Request; | ||
10 | import hu.bme.mit.inf.dslreasoner.domains.cps.Requirement; | ||
11 | import hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement; | ||
12 | import java.util.Collection; | ||
13 | import java.util.List; | ||
14 | import java.util.Map; | ||
15 | import org.eclipse.emf.common.util.EList; | ||
16 | import org.eclipse.xtend2.lib.StringConcatenation; | ||
17 | import org.eclipse.xtext.xbase.lib.CollectionLiterals; | ||
18 | import org.eclipse.xtext.xbase.lib.ExclusiveRange; | ||
19 | import org.eclipse.xtext.xbase.lib.Functions.Function1; | ||
20 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
21 | import org.eclipse.xtext.xbase.lib.ListExtensions; | ||
22 | import org.eclipse.xtext.xbase.lib.Pair; | ||
23 | |||
24 | @SuppressWarnings("all") | ||
25 | public class CpsToLpTranslator { | ||
26 | private static final double MINIMUM_MEMORY_USAGE = 0.25; | ||
27 | |||
28 | private static final double MINIMUM_HDD_USAGE = 0.25; | ||
29 | |||
30 | private final CyberPhysicalSystem cps; | ||
31 | |||
32 | private final Map<Requirement, ? extends List<String>> appInstances; | ||
33 | |||
34 | private final Map<HostType, ? extends List<String>> hostInstances; | ||
35 | |||
36 | private final boolean breakSymmetry; | ||
37 | |||
38 | public CpsToLpTranslator(final CyberPhysicalSystem cps, final int hostInstanceCount, final boolean breakSymmetry) { | ||
39 | this.cps = cps; | ||
40 | this.appInstances = this.createAppInstances(); | ||
41 | this.hostInstances = this.createHostInstances(hostInstanceCount); | ||
42 | this.breakSymmetry = breakSymmetry; | ||
43 | } | ||
44 | |||
45 | private ImmutableMap<Requirement, ImmutableList<String>> createAppInstances() { | ||
46 | ImmutableMap<Requirement, ImmutableList<String>> _xblockexpression = null; | ||
47 | { | ||
48 | final ImmutableMap.Builder<Requirement, ImmutableList<String>> builder = ImmutableMap.<Requirement, ImmutableList<String>>builder(); | ||
49 | int i = 0; | ||
50 | Iterable<Requirement> _requirements = this.getRequirements(); | ||
51 | for (final Requirement req : _requirements) { | ||
52 | { | ||
53 | final ImmutableList.Builder<String> listBuilder = ImmutableList.<String>builder(); | ||
54 | for (int j = 0; (j < req.getCount()); j++) { | ||
55 | StringConcatenation _builder = new StringConcatenation(); | ||
56 | _builder.append("r"); | ||
57 | _builder.append(i); | ||
58 | _builder.append("a"); | ||
59 | _builder.append(j); | ||
60 | listBuilder.add(_builder.toString()); | ||
61 | } | ||
62 | builder.put(req, listBuilder.build()); | ||
63 | i++; | ||
64 | } | ||
65 | } | ||
66 | _xblockexpression = builder.build(); | ||
67 | } | ||
68 | return _xblockexpression; | ||
69 | } | ||
70 | |||
71 | private ImmutableMap<HostType, ImmutableList<String>> createHostInstances(final int hostInstanceCount) { | ||
72 | ImmutableMap<HostType, ImmutableList<String>> _xblockexpression = null; | ||
73 | { | ||
74 | final ImmutableMap.Builder<HostType, ImmutableList<String>> builder = ImmutableMap.<HostType, ImmutableList<String>>builder(); | ||
75 | int i = 0; | ||
76 | EList<HostType> _hostTypes = this.cps.getHostTypes(); | ||
77 | for (final HostType hostType : _hostTypes) { | ||
78 | { | ||
79 | final ImmutableList.Builder<String> listBuilder = ImmutableList.<String>builder(); | ||
80 | for (int j = 0; (j < hostInstanceCount); j++) { | ||
81 | StringConcatenation _builder = new StringConcatenation(); | ||
82 | _builder.append("h"); | ||
83 | _builder.append(i); | ||
84 | _builder.append("i"); | ||
85 | _builder.append(j); | ||
86 | listBuilder.add(_builder.toString()); | ||
87 | } | ||
88 | builder.put(hostType, listBuilder.build()); | ||
89 | i++; | ||
90 | } | ||
91 | } | ||
92 | _xblockexpression = builder.build(); | ||
93 | } | ||
94 | return _xblockexpression; | ||
95 | } | ||
96 | |||
97 | public CharSequence getLpProblem() { | ||
98 | StringConcatenation _builder = new StringConcatenation(); | ||
99 | _builder.append("Minimize"); | ||
100 | _builder.newLine(); | ||
101 | _builder.append("\t"); | ||
102 | _builder.append("total_cost: "); | ||
103 | CharSequence _objective = this.getObjective(); | ||
104 | _builder.append(_objective, "\t"); | ||
105 | _builder.newLineIfNotEmpty(); | ||
106 | _builder.append("Subject To"); | ||
107 | _builder.newLine(); | ||
108 | _builder.append("\t"); | ||
109 | CharSequence _constraints = this.getConstraints(); | ||
110 | _builder.append(_constraints, "\t"); | ||
111 | _builder.newLineIfNotEmpty(); | ||
112 | _builder.append("Bounds"); | ||
113 | _builder.newLine(); | ||
114 | _builder.append("\t"); | ||
115 | CharSequence _bounds = this.getBounds(); | ||
116 | _builder.append(_bounds, "\t"); | ||
117 | _builder.newLineIfNotEmpty(); | ||
118 | _builder.append("Binary"); | ||
119 | _builder.newLine(); | ||
120 | _builder.append("\t"); | ||
121 | CharSequence _binaryVariables = this.getBinaryVariables(); | ||
122 | _builder.append(_binaryVariables, "\t"); | ||
123 | _builder.newLineIfNotEmpty(); | ||
124 | _builder.append("End"); | ||
125 | _builder.newLine(); | ||
126 | return _builder; | ||
127 | } | ||
128 | |||
129 | private CharSequence getObjective() { | ||
130 | StringConcatenation _builder = new StringConcatenation(); | ||
131 | { | ||
132 | Iterable<Pair<HostType, String>> _hostInstancesWithType = this.getHostInstancesWithType(); | ||
133 | boolean _hasElements = false; | ||
134 | for(final Pair<HostType, String> pair : _hostInstancesWithType) { | ||
135 | if (!_hasElements) { | ||
136 | _hasElements = true; | ||
137 | } else { | ||
138 | _builder.appendImmediate(" + ", ""); | ||
139 | } | ||
140 | int _cost = pair.getKey().getCost(); | ||
141 | _builder.append(_cost); | ||
142 | _builder.append(" "); | ||
143 | CharSequence _existsVariable = this.getExistsVariable(pair.getValue()); | ||
144 | _builder.append(_existsVariable); | ||
145 | } | ||
146 | } | ||
147 | return _builder; | ||
148 | } | ||
149 | |||
150 | private CharSequence getConstraints() { | ||
151 | StringConcatenation _builder = new StringConcatenation(); | ||
152 | { | ||
153 | Iterable<Pair<ApplicationType, String>> _appInstancesWithType = this.getAppInstancesWithType(); | ||
154 | for(final Pair<ApplicationType, String> appPair : _appInstancesWithType) { | ||
155 | String _value = appPair.getValue(); | ||
156 | _builder.append(_value); | ||
157 | _builder.append("_allocated: "); | ||
158 | { | ||
159 | Iterable<String> _possibleHostInstances = this.getPossibleHostInstances(appPair.getKey()); | ||
160 | boolean _hasElements = false; | ||
161 | for(final String host : _possibleHostInstances) { | ||
162 | if (!_hasElements) { | ||
163 | _hasElements = true; | ||
164 | } else { | ||
165 | _builder.appendImmediate(" + ", ""); | ||
166 | } | ||
167 | CharSequence _allocatedToVariable = this.getAllocatedToVariable(appPair.getValue(), host); | ||
168 | _builder.append(_allocatedToVariable); | ||
169 | } | ||
170 | } | ||
171 | _builder.append(" = 1"); | ||
172 | _builder.newLineIfNotEmpty(); | ||
173 | { | ||
174 | Iterable<String> _possibleHostInstances_1 = this.getPossibleHostInstances(appPair.getKey()); | ||
175 | for(final String host_1 : _possibleHostInstances_1) { | ||
176 | String _value_1 = appPair.getValue(); | ||
177 | _builder.append(_value_1); | ||
178 | _builder.append("_to_"); | ||
179 | _builder.append(host_1); | ||
180 | _builder.append("_exists: "); | ||
181 | CharSequence _existsVariable = this.getExistsVariable(host_1); | ||
182 | _builder.append(_existsVariable); | ||
183 | _builder.append(" - "); | ||
184 | CharSequence _allocatedToVariable_1 = this.getAllocatedToVariable(appPair.getValue(), host_1); | ||
185 | _builder.append(_allocatedToVariable_1); | ||
186 | _builder.append(" >= 0"); | ||
187 | _builder.newLineIfNotEmpty(); | ||
188 | } | ||
189 | } | ||
190 | } | ||
191 | } | ||
192 | { | ||
193 | Iterable<Pair<HostType, String>> _hostInstancesWithType = this.getHostInstancesWithType(); | ||
194 | for(final Pair<HostType, String> hostPair : _hostInstancesWithType) { | ||
195 | String _value_2 = hostPair.getValue(); | ||
196 | _builder.append(_value_2); | ||
197 | _builder.append("_mem_use: "); | ||
198 | { | ||
199 | Iterable<Pair<ResourceRequirement, String>> _possibleAppInstancesWithRequirements = this.getPossibleAppInstancesWithRequirements(hostPair.getKey()); | ||
200 | boolean _hasElements_1 = false; | ||
201 | for(final Pair<ResourceRequirement, String> appPair_1 : _possibleAppInstancesWithRequirements) { | ||
202 | if (!_hasElements_1) { | ||
203 | _hasElements_1 = true; | ||
204 | } else { | ||
205 | _builder.appendImmediate(" + ", ""); | ||
206 | } | ||
207 | int _requiredMemory = appPair_1.getKey().getRequiredMemory(); | ||
208 | _builder.append(_requiredMemory); | ||
209 | _builder.append(" "); | ||
210 | CharSequence _allocatedToVariable_2 = this.getAllocatedToVariable(appPair_1.getValue(), hostPair.getValue()); | ||
211 | _builder.append(_allocatedToVariable_2); | ||
212 | } | ||
213 | } | ||
214 | _builder.append(" - "); | ||
215 | int _defaultMemory = hostPair.getKey().getDefaultMemory(); | ||
216 | _builder.append(_defaultMemory); | ||
217 | _builder.append(" "); | ||
218 | CharSequence _memoryUsageVariable = this.getMemoryUsageVariable(hostPair.getValue()); | ||
219 | _builder.append(_memoryUsageVariable); | ||
220 | _builder.append(" = 0"); | ||
221 | _builder.newLineIfNotEmpty(); | ||
222 | String _value_3 = hostPair.getValue(); | ||
223 | _builder.append(_value_3); | ||
224 | _builder.append("_hdd_use: "); | ||
225 | { | ||
226 | Iterable<Pair<ResourceRequirement, String>> _possibleAppInstancesWithRequirements_1 = this.getPossibleAppInstancesWithRequirements(hostPair.getKey()); | ||
227 | boolean _hasElements_2 = false; | ||
228 | for(final Pair<ResourceRequirement, String> appPair_2 : _possibleAppInstancesWithRequirements_1) { | ||
229 | if (!_hasElements_2) { | ||
230 | _hasElements_2 = true; | ||
231 | } else { | ||
232 | _builder.appendImmediate(" + ", ""); | ||
233 | } | ||
234 | int _requiredHdd = appPair_2.getKey().getRequiredHdd(); | ||
235 | _builder.append(_requiredHdd); | ||
236 | _builder.append(" "); | ||
237 | CharSequence _allocatedToVariable_3 = this.getAllocatedToVariable(appPair_2.getValue(), hostPair.getValue()); | ||
238 | _builder.append(_allocatedToVariable_3); | ||
239 | } | ||
240 | } | ||
241 | _builder.append(" - "); | ||
242 | int _defaultHdd = hostPair.getKey().getDefaultHdd(); | ||
243 | _builder.append(_defaultHdd); | ||
244 | _builder.append(" "); | ||
245 | CharSequence _hddUsageVariable = this.getHddUsageVariable(hostPair.getValue()); | ||
246 | _builder.append(_hddUsageVariable); | ||
247 | _builder.append(" = 0"); | ||
248 | _builder.newLineIfNotEmpty(); | ||
249 | } | ||
250 | } | ||
251 | _builder.append("average_mem: "); | ||
252 | { | ||
253 | Iterable<String> _allHostInstances = this.getAllHostInstances(); | ||
254 | boolean _hasElements_3 = false; | ||
255 | for(final String host_2 : _allHostInstances) { | ||
256 | if (!_hasElements_3) { | ||
257 | _hasElements_3 = true; | ||
258 | } else { | ||
259 | _builder.appendImmediate(" + ", ""); | ||
260 | } | ||
261 | CharSequence _memoryUsageVariable_1 = this.getMemoryUsageVariable(host_2); | ||
262 | _builder.append(_memoryUsageVariable_1); | ||
263 | _builder.append(" - "); | ||
264 | _builder.append(CpsToLpTranslator.MINIMUM_MEMORY_USAGE); | ||
265 | _builder.append(" "); | ||
266 | CharSequence _existsVariable_1 = this.getExistsVariable(host_2); | ||
267 | _builder.append(_existsVariable_1); | ||
268 | } | ||
269 | } | ||
270 | _builder.append(" >= 0"); | ||
271 | _builder.newLineIfNotEmpty(); | ||
272 | _builder.append("average_hdd: "); | ||
273 | { | ||
274 | Iterable<String> _allHostInstances_1 = this.getAllHostInstances(); | ||
275 | boolean _hasElements_4 = false; | ||
276 | for(final String host_3 : _allHostInstances_1) { | ||
277 | if (!_hasElements_4) { | ||
278 | _hasElements_4 = true; | ||
279 | } else { | ||
280 | _builder.appendImmediate(" + ", ""); | ||
281 | } | ||
282 | CharSequence _memoryUsageVariable_2 = this.getMemoryUsageVariable(host_3); | ||
283 | _builder.append(_memoryUsageVariable_2); | ||
284 | _builder.append(" - "); | ||
285 | _builder.append(CpsToLpTranslator.MINIMUM_HDD_USAGE); | ||
286 | _builder.append(" "); | ||
287 | CharSequence _existsVariable_2 = this.getExistsVariable(host_3); | ||
288 | _builder.append(_existsVariable_2); | ||
289 | } | ||
290 | } | ||
291 | _builder.append(" >= 0"); | ||
292 | _builder.newLineIfNotEmpty(); | ||
293 | { | ||
294 | final Function1<Requirement, Boolean> _function = (Requirement it) -> { | ||
295 | int _count = it.getCount(); | ||
296 | return Boolean.valueOf((_count > 1)); | ||
297 | }; | ||
298 | Iterable<Pair<Integer, Requirement>> _indexed = IterableExtensions.<Requirement>indexed(IterableExtensions.<Requirement>filter(this.getRequirements(), _function)); | ||
299 | for(final Pair<Integer, Requirement> reqPair : _indexed) { | ||
300 | { | ||
301 | final Function1<ResourceRequirement, List<String>> _function_1 = (ResourceRequirement it) -> { | ||
302 | return this.hostInstances.get(it.getHostType()); | ||
303 | }; | ||
304 | Iterable<String> _flatMap = IterableExtensions.<ResourceRequirement, String>flatMap(reqPair.getValue().getType().getRequirements(), _function_1); | ||
305 | for(final String host_4 : _flatMap) { | ||
306 | _builder.append("r"); | ||
307 | Integer _key = reqPair.getKey(); | ||
308 | _builder.append(_key); | ||
309 | _builder.append("_"); | ||
310 | _builder.append(host_4); | ||
311 | _builder.append("_redundant: "); | ||
312 | { | ||
313 | List<String> _get = this.appInstances.get(reqPair.getValue()); | ||
314 | boolean _hasElements_5 = false; | ||
315 | for(final String app : _get) { | ||
316 | if (!_hasElements_5) { | ||
317 | _hasElements_5 = true; | ||
318 | } else { | ||
319 | _builder.appendImmediate(" + ", ""); | ||
320 | } | ||
321 | CharSequence _allocatedToVariable_4 = this.getAllocatedToVariable(app, host_4); | ||
322 | _builder.append(_allocatedToVariable_4); | ||
323 | } | ||
324 | } | ||
325 | _builder.append(" <= 1"); | ||
326 | _builder.newLineIfNotEmpty(); | ||
327 | } | ||
328 | } | ||
329 | } | ||
330 | } | ||
331 | { | ||
332 | if (this.breakSymmetry) { | ||
333 | { | ||
334 | Collection<? extends List<String>> _values = this.hostInstances.values(); | ||
335 | for(final List<String> hosts : _values) { | ||
336 | { | ||
337 | int _size = hosts.size(); | ||
338 | int _minus = (_size - 1); | ||
339 | ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _minus, true); | ||
340 | for(final Integer i : _doubleDotLessThan) { | ||
341 | String _get_1 = hosts.get(((i).intValue() + 1)); | ||
342 | _builder.append(_get_1); | ||
343 | _builder.append("_after_"); | ||
344 | String _get_2 = hosts.get((i).intValue()); | ||
345 | _builder.append(_get_2); | ||
346 | _builder.append(": "); | ||
347 | CharSequence _existsVariable_3 = this.getExistsVariable(hosts.get((i).intValue())); | ||
348 | _builder.append(_existsVariable_3); | ||
349 | _builder.append(" - "); | ||
350 | CharSequence _existsVariable_4 = this.getExistsVariable(hosts.get(((i).intValue() + 1))); | ||
351 | _builder.append(_existsVariable_4); | ||
352 | _builder.append(" >= 0"); | ||
353 | _builder.newLineIfNotEmpty(); | ||
354 | } | ||
355 | } | ||
356 | } | ||
357 | } | ||
358 | } | ||
359 | } | ||
360 | return _builder; | ||
361 | } | ||
362 | |||
363 | private CharSequence getBounds() { | ||
364 | StringConcatenation _builder = new StringConcatenation(); | ||
365 | { | ||
366 | Iterable<String> _allHostInstances = this.getAllHostInstances(); | ||
367 | for(final String host : _allHostInstances) { | ||
368 | _builder.append("0 <= "); | ||
369 | CharSequence _memoryUsageVariable = this.getMemoryUsageVariable(host); | ||
370 | _builder.append(_memoryUsageVariable); | ||
371 | _builder.append(" <= 1"); | ||
372 | _builder.newLineIfNotEmpty(); | ||
373 | _builder.append("0 <= "); | ||
374 | CharSequence _hddUsageVariable = this.getHddUsageVariable(host); | ||
375 | _builder.append(_hddUsageVariable); | ||
376 | _builder.append(" <= 1"); | ||
377 | _builder.newLineIfNotEmpty(); | ||
378 | } | ||
379 | } | ||
380 | return _builder; | ||
381 | } | ||
382 | |||
383 | private CharSequence getBinaryVariables() { | ||
384 | StringConcatenation _builder = new StringConcatenation(); | ||
385 | { | ||
386 | Iterable<String> _allHostInstances = this.getAllHostInstances(); | ||
387 | for(final String host : _allHostInstances) { | ||
388 | CharSequence _existsVariable = this.getExistsVariable(host); | ||
389 | _builder.append(_existsVariable); | ||
390 | _builder.newLineIfNotEmpty(); | ||
391 | } | ||
392 | } | ||
393 | { | ||
394 | Iterable<Pair<ApplicationType, String>> _appInstancesWithType = this.getAppInstancesWithType(); | ||
395 | for(final Pair<ApplicationType, String> appPair : _appInstancesWithType) { | ||
396 | { | ||
397 | Iterable<String> _possibleHostInstances = this.getPossibleHostInstances(appPair.getKey()); | ||
398 | for(final String host_1 : _possibleHostInstances) { | ||
399 | CharSequence _allocatedToVariable = this.getAllocatedToVariable(appPair.getValue(), host_1); | ||
400 | _builder.append(_allocatedToVariable); | ||
401 | _builder.newLineIfNotEmpty(); | ||
402 | } | ||
403 | } | ||
404 | } | ||
405 | } | ||
406 | return _builder; | ||
407 | } | ||
408 | |||
409 | private Iterable<Requirement> getRequirements() { | ||
410 | final Function1<Request, EList<Requirement>> _function = (Request it) -> { | ||
411 | return it.getRequirements(); | ||
412 | }; | ||
413 | return IterableExtensions.<Request, Requirement>flatMap(this.cps.getRequests(), _function); | ||
414 | } | ||
415 | |||
416 | private Iterable<String> getAllHostInstances() { | ||
417 | final Function1<List<String>, List<String>> _function = (List<String> it) -> { | ||
418 | return it; | ||
419 | }; | ||
420 | return IterableExtensions.flatMap(this.hostInstances.values(), _function); | ||
421 | } | ||
422 | |||
423 | private Iterable<Pair<HostType, String>> getHostInstancesWithType() { | ||
424 | final Function1<Map.Entry<HostType, ? extends List<String>>, List<Pair<HostType, String>>> _function = (Map.Entry<HostType, ? extends List<String>> pair) -> { | ||
425 | final Function1<String, Pair<HostType, String>> _function_1 = (String it) -> { | ||
426 | HostType _key = pair.getKey(); | ||
427 | return Pair.<HostType, String>of(_key, it); | ||
428 | }; | ||
429 | return ListExtensions.<String, Pair<HostType, String>>map(pair.getValue(), _function_1); | ||
430 | }; | ||
431 | return IterableExtensions.flatMap(this.hostInstances.entrySet(), _function); | ||
432 | } | ||
433 | |||
434 | private Iterable<Pair<ApplicationType, String>> getAppInstancesWithType() { | ||
435 | final Function1<Map.Entry<Requirement, ? extends List<String>>, List<Pair<ApplicationType, String>>> _function = (Map.Entry<Requirement, ? extends List<String>> pair) -> { | ||
436 | final Function1<String, Pair<ApplicationType, String>> _function_1 = (String it) -> { | ||
437 | ApplicationType _type = pair.getKey().getType(); | ||
438 | return Pair.<ApplicationType, String>of(_type, it); | ||
439 | }; | ||
440 | return ListExtensions.<String, Pair<ApplicationType, String>>map(pair.getValue(), _function_1); | ||
441 | }; | ||
442 | return IterableExtensions.flatMap(this.appInstances.entrySet(), _function); | ||
443 | } | ||
444 | |||
445 | private Iterable<String> getPossibleHostInstances(final ApplicationType appType) { | ||
446 | final Function1<ResourceRequirement, List<String>> _function = (ResourceRequirement req) -> { | ||
447 | return this.hostInstances.get(req.getHostType()); | ||
448 | }; | ||
449 | return IterableExtensions.<ResourceRequirement, String>flatMap(appType.getRequirements(), _function); | ||
450 | } | ||
451 | |||
452 | private Iterable<Pair<ResourceRequirement, String>> getPossibleAppInstancesWithRequirements(final HostType hostType) { | ||
453 | final Function1<Map.Entry<Requirement, ? extends List<String>>, List<Pair<ResourceRequirement, String>>> _function = (Map.Entry<Requirement, ? extends List<String>> pair) -> { | ||
454 | List<Pair<ResourceRequirement, String>> _xblockexpression = null; | ||
455 | { | ||
456 | final Function1<ResourceRequirement, Boolean> _function_1 = (ResourceRequirement it) -> { | ||
457 | HostType _hostType = it.getHostType(); | ||
458 | return Boolean.valueOf(Objects.equal(_hostType, hostType)); | ||
459 | }; | ||
460 | final ResourceRequirement resourceReq = IterableExtensions.<ResourceRequirement>findFirst(pair.getKey().getType().getRequirements(), _function_1); | ||
461 | List<Pair<ResourceRequirement, String>> _xifexpression = null; | ||
462 | if ((resourceReq == null)) { | ||
463 | _xifexpression = CollectionLiterals.<Pair<ResourceRequirement, String>>emptyList(); | ||
464 | } else { | ||
465 | final Function1<String, Pair<ResourceRequirement, String>> _function_2 = (String it) -> { | ||
466 | return Pair.<ResourceRequirement, String>of(resourceReq, it); | ||
467 | }; | ||
468 | _xifexpression = ListExtensions.<String, Pair<ResourceRequirement, String>>map(pair.getValue(), _function_2); | ||
469 | } | ||
470 | _xblockexpression = _xifexpression; | ||
471 | } | ||
472 | return _xblockexpression; | ||
473 | }; | ||
474 | return IterableExtensions.flatMap(this.appInstances.entrySet(), _function); | ||
475 | } | ||
476 | |||
477 | private CharSequence getExistsVariable(final String hostInstance) { | ||
478 | StringConcatenation _builder = new StringConcatenation(); | ||
479 | _builder.append(hostInstance); | ||
480 | _builder.append("_exists"); | ||
481 | return _builder; | ||
482 | } | ||
483 | |||
484 | private CharSequence getMemoryUsageVariable(final String hostInstance) { | ||
485 | StringConcatenation _builder = new StringConcatenation(); | ||
486 | _builder.append(hostInstance); | ||
487 | _builder.append("_mem"); | ||
488 | return _builder; | ||
489 | } | ||
490 | |||
491 | private CharSequence getHddUsageVariable(final String hostInstance) { | ||
492 | StringConcatenation _builder = new StringConcatenation(); | ||
493 | _builder.append(hostInstance); | ||
494 | _builder.append("_hdd"); | ||
495 | return _builder; | ||
496 | } | ||
497 | |||
498 | private CharSequence getAllocatedToVariable(final String appInstance, final String hostInstance) { | ||
499 | StringConcatenation _builder = new StringConcatenation(); | ||
500 | _builder.append(appInstance); | ||
501 | _builder.append("_to_"); | ||
502 | _builder.append(hostInstance); | ||
503 | return _builder; | ||
504 | } | ||
505 | } | ||