diff options
author | 2019-05-22 20:38:53 -0400 | |
---|---|---|
committer | 2019-05-22 20:38:53 -0400 | |
commit | b7ed3353ba34dd837bfc15f7e48c30a2cdc7ce75 (patch) | |
tree | 53e966837f2403b47e62f978bc777d6fe93ce10a /Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme | |
parent | VIATRA DSE and COIN-OR CBC implementations of CPS case study (diff) | |
download | VIATRA-Generator-b7ed3353ba34dd837bfc15f7e48c30a2cdc7ce75.tar.gz VIATRA-Generator-b7ed3353ba34dd837bfc15f7e48c30a2cdc7ce75.tar.zst VIATRA-Generator-b7ed3353ba34dd837bfc15f7e48c30a2cdc7ce75.zip |
MDEOptimiser implementation of CPS benchmark
Diffstat (limited to 'Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme')
13 files changed, 414 insertions, 2 deletions
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/cplex/CbcCpsMain.xtend b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/cplex/CbcCpsMain.xtend index 7ec0f84d..0203a6b6 100644 --- a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/cplex/CbcCpsMain.xtend +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/cplex/CbcCpsMain.xtend | |||
@@ -19,11 +19,11 @@ class CbcCpsMain { | |||
19 | new IllegalStateException("This is a static utility class and should not be instantiated directly.") | 19 | new IllegalStateException("This is a static utility class and should not be instantiated directly.") |
20 | } | 20 | } |
21 | 21 | ||
22 | static def void main(String[] args) { | 22 | public static def void main(String[] args) { |
23 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put(Resource.Factory.Registry.DEFAULT_EXTENSION, | 23 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put(Resource.Factory.Registry.DEFAULT_EXTENSION, |
24 | new XMIResourceFactoryImpl) | 24 | new XMIResourceFactoryImpl) |
25 | EPackage.Registry.INSTANCE.put(CpsPackage.eNS_URI, CpsPackage.eINSTANCE) | 25 | EPackage.Registry.INSTANCE.put(CpsPackage.eNS_URI, CpsPackage.eINSTANCE) |
26 | val generator = new CpsGenerator(1, 4, 1) | 26 | val generator = new CpsGenerator(1, 4, 2) |
27 | val problem = generator.generateCpsProblem | 27 | val problem = generator.generateCpsProblem |
28 | val toLp = new CpsToLpTranslator(problem, 10, true) | 28 | val toLp = new CpsToLpTranslator(problem, 10, true) |
29 | val lp = toLp.lpProblem | 29 | val lp = toLp.lpProblem |
@@ -49,5 +49,6 @@ class CbcCpsMain { | |||
49 | } finally { | 49 | } finally { |
50 | reader.close | 50 | reader.close |
51 | } | 51 | } |
52 | println("Additional cost: " + problem.requests.flatMap[requirements.map[count]].reduce[p1, p2|p1 + p2] * 5) | ||
52 | } | 53 | } |
53 | } | 54 | } |
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/CpsMdeOptimiserMain.xtend b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/CpsMdeOptimiserMain.xtend new file mode 100644 index 00000000..628d5963 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/CpsMdeOptimiserMain.xtend | |||
@@ -0,0 +1,31 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.cps.mdeo | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.domains.cps.CpsPackage | ||
4 | import hu.bme.mit.inf.dslreasoner.domains.cps.generator.CpsGenerator | ||
5 | import org.eclipse.emf.common.util.URI | ||
6 | import org.eclipse.emf.ecore.EPackage | ||
7 | import org.eclipse.emf.ecore.resource.Resource | ||
8 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl | ||
9 | import uk.ac.kcl.inf.mdeoptimiser.languages.MoptStandaloneSetup | ||
10 | |||
11 | class CpsMdeOptimiserMain { | ||
12 | static val PROJECT_PATH = "." | ||
13 | static val PROBLEM_PATH = "model/problem.xmi" | ||
14 | static val MOPT_PATH = "src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/cps.mopt" | ||
15 | |||
16 | private new() { | ||
17 | new IllegalStateException("This is a static utility class and should not be instantiated directly.") | ||
18 | } | ||
19 | |||
20 | public static def void main(String[] args) { | ||
21 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put(Resource.Factory.Registry.DEFAULT_EXTENSION, | ||
22 | new XMIResourceFactoryImpl) | ||
23 | EPackage.Registry.INSTANCE.put(CpsPackage.eNS_URI, CpsPackage.eINSTANCE) | ||
24 | val generator = new CpsGenerator(1, 4, 2) | ||
25 | val problem = generator.generateCpsProblem | ||
26 | problem.eResource.URI = URI.createFileURI(PROBLEM_PATH) | ||
27 | problem.eResource.save(emptyMap) | ||
28 | val injector = new MoptStandaloneSetup().createInjectorAndDoEMFRegistration(); | ||
29 | injector.getInstance(ExcludedRun).run(PROJECT_PATH, MOPT_PATH) | ||
30 | } | ||
31 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/ExcludedOptimisationInterpreter.xtend b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/ExcludedOptimisationInterpreter.xtend new file mode 100644 index 00000000..1e9c5adf --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/ExcludedOptimisationInterpreter.xtend | |||
@@ -0,0 +1,85 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.cps.mdeo | ||
2 | |||
3 | import java.util.Properties | ||
4 | import org.moeaframework.Executor | ||
5 | import org.moeaframework.Instrumenter | ||
6 | import org.moeaframework.algorithm.PeriodicAction | ||
7 | import org.moeaframework.core.TerminationCondition | ||
8 | import org.moeaframework.core.spi.AlgorithmFactory | ||
9 | import uk.ac.kcl.inf.mdeoptimiser.interfaces.cli.Run | ||
10 | import uk.ac.kcl.inf.mdeoptimiser.languages.mopt.Optimisation | ||
11 | import uk.ac.kcl.inf.mdeoptimiser.languages.mopt.SolverSpec | ||
12 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.OptimisationInterpreter | ||
13 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.executor.SolutionGenerator | ||
14 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.moea.MoeaOptimisation | ||
15 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.moea.algorithms.MoeaOptimisationAlgorithmProvider | ||
16 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.moea.instrumentation.PopulationCollector | ||
17 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.moea.problem.MoeaOptimisationProblem | ||
18 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.operators.adaptation.MutationStepSizeStrategyFactory | ||
19 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.output.MDEOBatch | ||
20 | |||
21 | class ExcludedMoeaOptimisation extends MoeaOptimisation { | ||
22 | SolutionGenerator solutionGenerator | ||
23 | Instrumenter algorithmStepSizeInstrumenter | ||
24 | |||
25 | override execute(SolverSpec solverSpec, SolutionGenerator solutionGenerator) { | ||
26 | this.solutionGenerator = solutionGenerator | ||
27 | super.execute(solverSpec, solutionGenerator) | ||
28 | } | ||
29 | |||
30 | override Instrumenter runOptimisation(SolverSpec solverSpec, Properties optimisationProperties) { | ||
31 | val algorithmFactory = new AlgorithmFactory | ||
32 | algorithmFactory.addProvider(new MoeaOptimisationAlgorithmProvider) | ||
33 | |||
34 | algorithmStepSizeInstrumenter = new Instrumenter().addExcludedPackage("org.eclipse").withProblemClass( | ||
35 | MoeaOptimisationProblem, solutionGenerator).attachApproximationSetCollector().attachElapsedTimeCollector(). | ||
36 | attachPopulationSizeCollector.attach(new PopulationCollector()).withFrequency(1).withFrequencyType( | ||
37 | PeriodicAction.FrequencyType.STEPS) | ||
38 | |||
39 | var stepSizeStrategy = new MutationStepSizeStrategyFactory(solverSpec.algorithm, algorithmStepSizeInstrumenter). | ||
40 | strategy | ||
41 | |||
42 | solutionGenerator.setMutationStepSizeStrategy(stepSizeStrategy) | ||
43 | |||
44 | // TODO: Place this in a better location. | ||
45 | // Exclude JDK packages from Instrumenter | ||
46 | this.algorithmStepSizeInstrumenter.addExcludedPackage("jdk") | ||
47 | |||
48 | new Executor().usingAlgorithmFactory(algorithmFactory).withAlgorithm(solverSpec.algorithm.name) // Initialize problem with our solution generator | ||
49 | .withProblemClass(MoeaOptimisationProblem, solutionGenerator).withProperties(optimisationProperties). | ||
50 | withInstrumenter(algorithmStepSizeInstrumenter).withTerminationCondition( | ||
51 | optimisationProperties.get("terminationCondition") as TerminationCondition).run() | ||
52 | |||
53 | return algorithmStepSizeInstrumenter | ||
54 | } | ||
55 | } | ||
56 | |||
57 | class ExcludedOptimisationInterpreter extends OptimisationInterpreter { | ||
58 | val Optimisation model | ||
59 | |||
60 | new(String projectPath, Optimisation model) { | ||
61 | super(projectPath, model) | ||
62 | this.model = model | ||
63 | } | ||
64 | |||
65 | override start() { | ||
66 | // This model provider loads the model given by the user in the DSL | ||
67 | var solutionGenerator = new SolutionGenerator(model, getBreedingOperators, getMutationOperators, | ||
68 | getModelProvider, getMetamodel); | ||
69 | |||
70 | return new ExcludedMoeaOptimisation().execute(model.solver, solutionGenerator) | ||
71 | } | ||
72 | |||
73 | } | ||
74 | |||
75 | class ExcludedRun extends Run { | ||
76 | override runBatch(String moptProjectPath, Optimisation optimisationModel, Integer batch, boolean singleBatch) { | ||
77 | val optimisationInterpreter = new ExcludedOptimisationInterpreter(moptProjectPath, optimisationModel); | ||
78 | val startTime = System.nanoTime(); | ||
79 | val optimisationOutcome = optimisationInterpreter.start(); | ||
80 | val endTime = System.nanoTime(); | ||
81 | val experimentDuration = ((endTime - startTime) / 1000000); | ||
82 | val generatedRules = optimisationInterpreter.getRulegenOperators(); | ||
83 | return new MDEOBatch(batch, experimentDuration, optimisationOutcome, generatedRules, singleBatch); | ||
84 | } | ||
85 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/NonRedundantAllocationsConstraint.xtend b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/NonRedundantAllocationsConstraint.xtend new file mode 100644 index 00000000..1a9286b3 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/NonRedundantAllocationsConstraint.xtend | |||
@@ -0,0 +1,29 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.cps.mdeo | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem | ||
4 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.IGuidanceFunction | ||
5 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.interpreter.guidance.Solution | ||
6 | import com.google.common.collect.HashMultiset | ||
7 | |||
8 | class NonRedundantAllocationsConstraint implements IGuidanceFunction { | ||
9 | override getName() { | ||
10 | "NonRedundantAllocations" | ||
11 | } | ||
12 | |||
13 | override computeFitness(Solution solution) { | ||
14 | val cps = solution.model as CyberPhysicalSystem | ||
15 | var int cost = 0 | ||
16 | for (hostType : cps.hostTypes) { | ||
17 | for (host : hostType.instances) { | ||
18 | val bins = HashMultiset.create | ||
19 | for (app : host.applications) { | ||
20 | bins.add(app.requirement) | ||
21 | } | ||
22 | for (entry : bins.entrySet) { | ||
23 | cost += entry.count - 1 | ||
24 | } | ||
25 | } | ||
26 | } | ||
27 | cost | ||
28 | } | ||
29 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/NotAllocatedAppInstancesConstraint.xtend b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/NotAllocatedAppInstancesConstraint.xtend new file mode 100644 index 00000000..663aa26c --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/NotAllocatedAppInstancesConstraint.xtend | |||
@@ -0,0 +1,24 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.cps.mdeo | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem | ||
4 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.IGuidanceFunction | ||
5 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.interpreter.guidance.Solution | ||
6 | |||
7 | class NotAllocatedAppInstancesConstraint implements IGuidanceFunction { | ||
8 | override getName() { | ||
9 | "NotAllocatedAppInstances" | ||
10 | } | ||
11 | |||
12 | override computeFitness(Solution solution) { | ||
13 | val cps = solution.model as CyberPhysicalSystem | ||
14 | var int cost = 0 | ||
15 | for (appType : cps.applicationTypes) { | ||
16 | for (app : appType.instances) { | ||
17 | if (app.allocatedTo === null || !appType.requirements.exists[hostType == app.allocatedTo.type]) { | ||
18 | cost++ | ||
19 | } | ||
20 | } | ||
21 | } | ||
22 | cost | ||
23 | } | ||
24 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/NotSatisfiedRequirementsConstraint.xtend b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/NotSatisfiedRequirementsConstraint.xtend new file mode 100644 index 00000000..e44381ec --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/NotSatisfiedRequirementsConstraint.xtend | |||
@@ -0,0 +1,27 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.cps.mdeo | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem | ||
4 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.IGuidanceFunction | ||
5 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.interpreter.guidance.Solution | ||
6 | |||
7 | class NotSatisfiedRequirementsConstraint implements IGuidanceFunction { | ||
8 | override getName() { | ||
9 | "NotSatisfiedRequirements" | ||
10 | } | ||
11 | |||
12 | override computeFitness(Solution solution) { | ||
13 | val cps = solution.model as CyberPhysicalSystem | ||
14 | var int cost = 0 | ||
15 | for (request : cps.requests) { | ||
16 | for (requirement : request.requirements) { | ||
17 | cost += Math.abs(requirement.count - requirement.instances.size) | ||
18 | for (app : requirement.instances) { | ||
19 | if (app.type != requirement.type) { | ||
20 | cost++ | ||
21 | } | ||
22 | } | ||
23 | } | ||
24 | } | ||
25 | cost | ||
26 | } | ||
27 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/ResourceUtilizationUtil.xtend b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/ResourceUtilizationUtil.xtend new file mode 100644 index 00000000..fc1d666f --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/ResourceUtilizationUtil.xtend | |||
@@ -0,0 +1,31 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.cps.mdeo | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance | ||
4 | |||
5 | class ResourceUtilizationUtil { | ||
6 | private new() { | ||
7 | new IllegalStateException("This is a static utility class and should not be instantiated directly.") | ||
8 | } | ||
9 | |||
10 | static def getMemoryUtilization(HostInstance host) { | ||
11 | var int utilization = 0 | ||
12 | for (app : host.applications) { | ||
13 | val req = app.type.requirements.findFirst[hostType == host.type] | ||
14 | if (req !== null) { | ||
15 | utilization += req.requiredMemory | ||
16 | } | ||
17 | } | ||
18 | utilization | ||
19 | } | ||
20 | |||
21 | static def getHddUtilization(HostInstance host) { | ||
22 | var int utilization = 0 | ||
23 | for (app : host.applications) { | ||
24 | val req = app.type.requirements.findFirst[hostType == host.type] | ||
25 | if (req !== null) { | ||
26 | utilization += req.requiredHdd | ||
27 | } | ||
28 | } | ||
29 | utilization | ||
30 | } | ||
31 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/TooLowAverageHddConstraint.xtend b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/TooLowAverageHddConstraint.xtend new file mode 100644 index 00000000..85cc8115 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/TooLowAverageHddConstraint.xtend | |||
@@ -0,0 +1,33 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.cps.mdeo | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem | ||
4 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.IGuidanceFunction | ||
5 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.interpreter.guidance.Solution | ||
6 | |||
7 | class TooLowAverageHddConstraint implements IGuidanceFunction { | ||
8 | static val THRESHOLD = 0.25 | ||
9 | |||
10 | override getName() { | ||
11 | "TooLowAverageHdd" | ||
12 | } | ||
13 | |||
14 | override computeFitness(Solution solution) { | ||
15 | val cps = solution.model as CyberPhysicalSystem | ||
16 | var double sumUtilization | ||
17 | var int numHosts | ||
18 | for (hostType : cps.hostTypes) { | ||
19 | numHosts += hostType.instances.size | ||
20 | for (host : hostType.instances) { | ||
21 | val utilization = ResourceUtilizationUtil.getHddUtilization(host) | ||
22 | sumUtilization += (utilization as double) / hostType.defaultHdd | ||
23 | } | ||
24 | } | ||
25 | val averageUtilization = sumUtilization / numHosts | ||
26 | val difference = THRESHOLD - averageUtilization | ||
27 | if (difference > 0) { | ||
28 | difference | ||
29 | } else { | ||
30 | 0 | ||
31 | } | ||
32 | } | ||
33 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/TooLowAverageMemoryConstraint.xtend b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/TooLowAverageMemoryConstraint.xtend new file mode 100644 index 00000000..e9b47d4c --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/TooLowAverageMemoryConstraint.xtend | |||
@@ -0,0 +1,33 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.cps.mdeo | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem | ||
4 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.IGuidanceFunction | ||
5 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.interpreter.guidance.Solution | ||
6 | |||
7 | class TooLowAverageMemoryConstraint implements IGuidanceFunction { | ||
8 | static val THRESHOLD = 0.25 | ||
9 | |||
10 | override getName() { | ||
11 | "TooLowAverageMemory" | ||
12 | } | ||
13 | |||
14 | override computeFitness(Solution solution) { | ||
15 | val cps = solution.model as CyberPhysicalSystem | ||
16 | var double sumUtilization | ||
17 | var int numHosts | ||
18 | for (hostType : cps.hostTypes) { | ||
19 | numHosts += hostType.instances.size | ||
20 | for (host : hostType.instances) { | ||
21 | val utilization = ResourceUtilizationUtil.getMemoryUtilization(host) | ||
22 | sumUtilization += (utilization as double) / hostType.defaultMemory | ||
23 | } | ||
24 | } | ||
25 | val averageUtilization = sumUtilization / numHosts | ||
26 | val difference = THRESHOLD - averageUtilization | ||
27 | if (difference > 0) { | ||
28 | difference | ||
29 | } else { | ||
30 | 0 | ||
31 | } | ||
32 | } | ||
33 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/TotalCostFitnessFunction.xtend b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/TotalCostFitnessFunction.xtend new file mode 100644 index 00000000..af65e442 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/TotalCostFitnessFunction.xtend | |||
@@ -0,0 +1,23 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.cps.mdeo | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem | ||
4 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.IGuidanceFunction | ||
5 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.interpreter.guidance.Solution | ||
6 | |||
7 | class TotalCostFitnessFunction implements IGuidanceFunction { | ||
8 | override getName() { | ||
9 | "TotalCost" | ||
10 | } | ||
11 | |||
12 | override computeFitness(Solution solution) { | ||
13 | val cps = solution.model as CyberPhysicalSystem | ||
14 | var int cost = 0 | ||
15 | for (appType : cps.applicationTypes) { | ||
16 | cost += 5 * appType.instances.size | ||
17 | } | ||
18 | for (hostType : cps.hostTypes) { | ||
19 | cost += hostType.cost * hostType.instances.size | ||
20 | } | ||
21 | cost | ||
22 | } | ||
23 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/UnavailableHddConstraint.xtend b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/UnavailableHddConstraint.xtend new file mode 100644 index 00000000..08450f45 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/UnavailableHddConstraint.xtend | |||
@@ -0,0 +1,27 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.cps.mdeo | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem | ||
4 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.IGuidanceFunction | ||
5 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.interpreter.guidance.Solution | ||
6 | |||
7 | class UnavailableHddConstraint implements IGuidanceFunction { | ||
8 | override getName() { | ||
9 | "UnavailableHdd" | ||
10 | } | ||
11 | |||
12 | override computeFitness(Solution solution) { | ||
13 | val cps = solution.model as CyberPhysicalSystem | ||
14 | var int cost = 0 | ||
15 | for (hostType : cps.hostTypes) { | ||
16 | for (host : hostType.instances) { | ||
17 | val utilization = ResourceUtilizationUtil.getHddUtilization(host) | ||
18 | val difference = utilization - hostType.defaultHdd | ||
19 | if (difference > 0) { | ||
20 | cost += difference | ||
21 | } | ||
22 | } | ||
23 | } | ||
24 | cost | ||
25 | } | ||
26 | |||
27 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/UnavailableMemoryConstraint.xtend b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/UnavailableMemoryConstraint.xtend new file mode 100644 index 00000000..e46d59a6 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/UnavailableMemoryConstraint.xtend | |||
@@ -0,0 +1,27 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.cps.mdeo | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem | ||
4 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.IGuidanceFunction | ||
5 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.interpreter.guidance.Solution | ||
6 | |||
7 | class UnavailableMemoryConstraint implements IGuidanceFunction { | ||
8 | override getName() { | ||
9 | "UnavailableMemory" | ||
10 | } | ||
11 | |||
12 | override computeFitness(Solution solution) { | ||
13 | val cps = solution.model as CyberPhysicalSystem | ||
14 | var int cost = 0 | ||
15 | for (hostType : cps.hostTypes) { | ||
16 | for (host : hostType.instances) { | ||
17 | val utilization = ResourceUtilizationUtil.getMemoryUtilization(host) | ||
18 | val difference = utilization - hostType.defaultMemory | ||
19 | if (difference > 0) { | ||
20 | cost += difference | ||
21 | } | ||
22 | } | ||
23 | } | ||
24 | cost | ||
25 | } | ||
26 | |||
27 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/cps.mopt b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/cps.mopt new file mode 100644 index 00000000..4c05939d --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/mdeo/cps.mopt | |||
@@ -0,0 +1,41 @@ | |||
1 | problem { | ||
2 | basepath <model> | ||
3 | metamodel <hu.bme.mit.inf.dslreasoner.domains.cps.CpsPackage> | ||
4 | model <problem.xmi> | ||
5 | } | ||
6 | |||
7 | goal { | ||
8 | objective TotalCost minimise java { "hu.bme.mit.inf.dslreasoner.domains.cps.mdeo.TotalCostFitnessFunction" } | ||
9 | constraint NotSatisfiedRequriements java { "hu.bme.mit.inf.dslreasoner.domains.cps.mdeo.NotSatisfiedRequirementsConstraint" } | ||
10 | constraint NotAllocatedAppInstances java { "hu.bme.mit.inf.dslreasoner.domains.cps.mdeo.NotAllocatedAppInstancesConstraint" } | ||
11 | constraint NonRedundantAllocations java { "hu.bme.mit.inf.dslreasoner.domains.cps.mdeo.NonRedundantAllocationsConstraint" } | ||
12 | constraint UnavailableMemory java { "hu.bme.mit.inf.dslreasoner.domains.cps.mdeo.UnavailableMemoryConstraint" } | ||
13 | constraint UnavailableHdd java { "hu.bme.mit.inf.dslreasoner.domains.cps.mdeo.UnavailableHddConstraint" } | ||
14 | constraint TooLowAverageMemory java { "hu.bme.mit.inf.dslreasoner.domains.cps.mdeo.TooLowAverageMemoryConstraint" } | ||
15 | constraint TooLowAverageHdd java { "hu.bme.mit.inf.dslreasoner.domains.cps.mdeo.TooLowAverageHddConstraint" } | ||
16 | } | ||
17 | |||
18 | search { | ||
19 | // mutate using <cps.henshin> unit "createAppInstance" | ||
20 | // mutate using <cps.henshin> unit "createHostInstance" | ||
21 | // mutate using <cps.henshin> unit "allocate" | ||
22 | // mutate using <cps.henshin> unit "deleteAppInstance" | ||
23 | // mutate using <cps.henshin> unit "unallocate" | ||
24 | mutate { "ApplicationInstance" } | ||
25 | mutate { "HostInstance" } | ||
26 | } | ||
27 | |||
28 | solver { | ||
29 | optimisation provider moea algorithm NSGAII { | ||
30 | variation: mutation | ||
31 | population: 25 | ||
32 | mutation.step: 3 | ||
33 | mutation.strategy: random | ||
34 | } | ||
35 | |||
36 | termination { | ||
37 | time: 120 | ||
38 | } | ||
39 | |||
40 | batches 1 | ||
41 | } | ||