diff options
Diffstat (limited to 'Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/generator')
2 files changed, 154 insertions, 0 deletions
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/generator/.CpsGenerator.xtendbin b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/generator/.CpsGenerator.xtendbin new file mode 100644 index 00000000..d975ffab --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/generator/.CpsGenerator.xtendbin | |||
Binary files differ | |||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/generator/CpsGenerator.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/generator/CpsGenerator.java new file mode 100644 index 00000000..e59ef004 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/generator/CpsGenerator.java | |||
@@ -0,0 +1,154 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.cps.generator; | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationType; | ||
4 | import hu.bme.mit.inf.dslreasoner.domains.cps.CpsFactory; | ||
5 | import hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem; | ||
6 | import hu.bme.mit.inf.dslreasoner.domains.cps.HostType; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.Request; | ||
8 | import hu.bme.mit.inf.dslreasoner.domains.cps.Requirement; | ||
9 | import hu.bme.mit.inf.dslreasoner.domains.cps.ResourceRequirement; | ||
10 | import java.util.Collection; | ||
11 | import java.util.Collections; | ||
12 | import java.util.List; | ||
13 | import java.util.Random; | ||
14 | import org.eclipse.emf.common.util.EList; | ||
15 | import org.eclipse.emf.common.util.URI; | ||
16 | import org.eclipse.emf.ecore.EObject; | ||
17 | import org.eclipse.emf.ecore.resource.Resource; | ||
18 | import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; | ||
19 | import org.eclipse.xtext.xbase.lib.CollectionLiterals; | ||
20 | import org.eclipse.xtext.xbase.lib.Extension; | ||
21 | import org.eclipse.xtext.xbase.lib.ObjectExtensions; | ||
22 | import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; | ||
23 | |||
24 | @SuppressWarnings("all") | ||
25 | public class CpsGenerator { | ||
26 | @Extension | ||
27 | private final CpsFactory _cpsFactory = CpsFactory.eINSTANCE; | ||
28 | |||
29 | private static final int MIN_MEMORY = 1; | ||
30 | |||
31 | private static final int MAX_MEMORY = 6; | ||
32 | |||
33 | private static final int MIN_HDD = 1; | ||
34 | |||
35 | private static final int MAX_HDD = 30; | ||
36 | |||
37 | private static final int HIGH_CPU_FRACTION = 4; | ||
38 | |||
39 | private static final int MIN_REPLICAS = 1; | ||
40 | |||
41 | private static final int MAX_REPLICAS = 4; | ||
42 | |||
43 | private final Random random; | ||
44 | |||
45 | private final int applicationTypeCount; | ||
46 | |||
47 | private final int demandFactor; | ||
48 | |||
49 | public CpsGenerator(final long randomSeed, final int applicationTypeCount, final int demandFactor) { | ||
50 | Random _random = new Random(randomSeed); | ||
51 | this.random = _random; | ||
52 | this.applicationTypeCount = applicationTypeCount; | ||
53 | this.demandFactor = demandFactor; | ||
54 | } | ||
55 | |||
56 | public CyberPhysicalSystem generateCpsProblem() { | ||
57 | CyberPhysicalSystem _xblockexpression = null; | ||
58 | { | ||
59 | final ResourceSetImpl resourceSet = new ResourceSetImpl(); | ||
60 | final Resource resource = resourceSet.createResource(URI.createFileURI("dummy.dummyext")); | ||
61 | CyberPhysicalSystem _createCyberPhysicalSystem = this._cpsFactory.createCyberPhysicalSystem(); | ||
62 | final Procedure1<CyberPhysicalSystem> _function = (CyberPhysicalSystem it) -> { | ||
63 | final CyberPhysicalSystem cps = it; | ||
64 | EList<EObject> _contents = resource.getContents(); | ||
65 | _contents.add(cps); | ||
66 | this.createLowCpuHostTypes(it); | ||
67 | final List<HostType> highCpuHostTypes = this.createHighCpuHostTypes(it); | ||
68 | for (int i = 0; (i < this.applicationTypeCount); i++) { | ||
69 | if (((i % CpsGenerator.HIGH_CPU_FRACTION) == 0)) { | ||
70 | this.createRandomApplicationType(it, highCpuHostTypes); | ||
71 | } else { | ||
72 | this.createRandomApplicationType(it, it.getHostTypes()); | ||
73 | } | ||
74 | } | ||
75 | for (int i = 0; (i < this.demandFactor); i++) { | ||
76 | EList<Request> _requests = it.getRequests(); | ||
77 | Request _createRequest = this._cpsFactory.createRequest(); | ||
78 | final Procedure1<Request> _function_1 = (Request it_1) -> { | ||
79 | EList<ApplicationType> _applicationTypes = cps.getApplicationTypes(); | ||
80 | for (final ApplicationType appType : _applicationTypes) { | ||
81 | EList<Requirement> _requirements = it_1.getRequirements(); | ||
82 | Requirement _createRequirement = this._cpsFactory.createRequirement(); | ||
83 | final Procedure1<Requirement> _function_2 = (Requirement it_2) -> { | ||
84 | it_2.setCount(this.nextInt(CpsGenerator.MIN_REPLICAS, CpsGenerator.MAX_REPLICAS)); | ||
85 | it_2.setType(appType); | ||
86 | }; | ||
87 | Requirement _doubleArrow = ObjectExtensions.<Requirement>operator_doubleArrow(_createRequirement, _function_2); | ||
88 | _requirements.add(_doubleArrow); | ||
89 | } | ||
90 | }; | ||
91 | Request _doubleArrow = ObjectExtensions.<Request>operator_doubleArrow(_createRequest, _function_1); | ||
92 | _requests.add(_doubleArrow); | ||
93 | } | ||
94 | }; | ||
95 | _xblockexpression = ObjectExtensions.<CyberPhysicalSystem>operator_doubleArrow(_createCyberPhysicalSystem, _function); | ||
96 | } | ||
97 | return _xblockexpression; | ||
98 | } | ||
99 | |||
100 | private void createRandomApplicationType(final CyberPhysicalSystem it, final Collection<HostType> allowedHostTypes) { | ||
101 | final ApplicationType appType = this._cpsFactory.createApplicationType(); | ||
102 | final int memory = this.nextInt(CpsGenerator.MIN_MEMORY, CpsGenerator.MAX_MEMORY); | ||
103 | final int hdd = this.nextInt(CpsGenerator.MIN_HDD, CpsGenerator.MAX_HDD); | ||
104 | for (final HostType hostType : allowedHostTypes) { | ||
105 | EList<ResourceRequirement> _requirements = appType.getRequirements(); | ||
106 | ResourceRequirement _createResourceRequirement = this._cpsFactory.createResourceRequirement(); | ||
107 | final Procedure1<ResourceRequirement> _function = (ResourceRequirement it_1) -> { | ||
108 | it_1.setHostType(hostType); | ||
109 | it_1.setRequiredMemory(memory); | ||
110 | it_1.setRequiredHdd(hdd); | ||
111 | }; | ||
112 | ResourceRequirement _doubleArrow = ObjectExtensions.<ResourceRequirement>operator_doubleArrow(_createResourceRequirement, _function); | ||
113 | _requirements.add(_doubleArrow); | ||
114 | } | ||
115 | EList<ApplicationType> _applicationTypes = it.getApplicationTypes(); | ||
116 | _applicationTypes.add(appType); | ||
117 | } | ||
118 | |||
119 | private List<HostType> createLowCpuHostTypes(final CyberPhysicalSystem it) { | ||
120 | HostType _createHostType = this.createHostType(it, 2, 8, 75); | ||
121 | HostType _createHostType_1 = this.createHostType(it, 4, 16, 150); | ||
122 | HostType _createHostType_2 = this.createHostType(it, 3, 16, 75); | ||
123 | HostType _createHostType_3 = this.createHostType(it, 6, 32, 150); | ||
124 | return Collections.<HostType>unmodifiableList(CollectionLiterals.<HostType>newArrayList(_createHostType, _createHostType_1, _createHostType_2, _createHostType_3)); | ||
125 | } | ||
126 | |||
127 | private List<HostType> createHighCpuHostTypes(final CyberPhysicalSystem it) { | ||
128 | HostType _createHostType = this.createHostType(it, 2, 4, 50); | ||
129 | HostType _createHostType_1 = this.createHostType(it, 4, 8, 100); | ||
130 | return Collections.<HostType>unmodifiableList(CollectionLiterals.<HostType>newArrayList(_createHostType, _createHostType_1)); | ||
131 | } | ||
132 | |||
133 | private HostType createHostType(final CyberPhysicalSystem it, final int cost, final int memory, final int hdd) { | ||
134 | HostType _xblockexpression = null; | ||
135 | { | ||
136 | HostType _createHostType = this._cpsFactory.createHostType(); | ||
137 | final Procedure1<HostType> _function = (HostType it_1) -> { | ||
138 | it_1.setCost(cost); | ||
139 | it_1.setDefaultMemory(memory); | ||
140 | it_1.setDefaultHdd(hdd); | ||
141 | }; | ||
142 | final HostType hostType = ObjectExtensions.<HostType>operator_doubleArrow(_createHostType, _function); | ||
143 | EList<HostType> _hostTypes = it.getHostTypes(); | ||
144 | _hostTypes.add(hostType); | ||
145 | _xblockexpression = hostType; | ||
146 | } | ||
147 | return _xblockexpression; | ||
148 | } | ||
149 | |||
150 | private int nextInt(final int lower, final int upper) { | ||
151 | int _nextInt = this.random.nextInt(((upper - lower) + 1)); | ||
152 | return (lower + _nextInt); | ||
153 | } | ||
154 | } | ||