diff options
Diffstat (limited to 'Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf')
5 files changed, 67 insertions, 11 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 0203a6b6..1a07e26e 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 | |||
@@ -6,14 +6,16 @@ import java.io.BufferedReader | |||
6 | import java.io.BufferedWriter | 6 | import java.io.BufferedWriter |
7 | import java.io.FileReader | 7 | import java.io.FileReader |
8 | import java.io.FileWriter | 8 | import java.io.FileWriter |
9 | import java.util.concurrent.TimeUnit | ||
10 | import java.util.regex.Pattern | ||
9 | import org.eclipse.emf.ecore.EPackage | 11 | import org.eclipse.emf.ecore.EPackage |
10 | import org.eclipse.emf.ecore.resource.Resource | 12 | import org.eclipse.emf.ecore.resource.Resource |
11 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl | 13 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl |
12 | import java.util.concurrent.TimeUnit | ||
13 | 14 | ||
14 | class CbcCpsMain { | 15 | class CbcCpsMain { |
15 | static val PROBLEM_FILE = "problem.lp" | 16 | static val PROBLEM_FILE = "problem.lp" |
16 | static val SOLUTION_FILE = "solution.txt" | 17 | static val SOLUTION_FILE = "solution.txt" |
18 | static val VALUE_REGEX = Pattern.compile("Optimal - objective value\\s*([0-9]+(\\.[0-9]+)?)") | ||
17 | 19 | ||
18 | private new() { | 20 | private new() { |
19 | new IllegalStateException("This is a static utility class and should not be instantiated directly.") | 21 | new IllegalStateException("This is a static utility class and should not be instantiated directly.") |
@@ -23,7 +25,7 @@ class CbcCpsMain { | |||
23 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put(Resource.Factory.Registry.DEFAULT_EXTENSION, | 25 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put(Resource.Factory.Registry.DEFAULT_EXTENSION, |
24 | new XMIResourceFactoryImpl) | 26 | new XMIResourceFactoryImpl) |
25 | EPackage.Registry.INSTANCE.put(CpsPackage.eNS_URI, CpsPackage.eINSTANCE) | 27 | EPackage.Registry.INSTANCE.put(CpsPackage.eNS_URI, CpsPackage.eINSTANCE) |
26 | val generator = new CpsGenerator(1, 4, 2) | 28 | val generator = new CpsGenerator(1, 4, 1) |
27 | val problem = generator.generateCpsProblem | 29 | val problem = generator.generateCpsProblem |
28 | val toLp = new CpsToLpTranslator(problem, 10, true) | 30 | val toLp = new CpsToLpTranslator(problem, 10, true) |
29 | val lp = toLp.lpProblem | 31 | val lp = toLp.lpProblem |
@@ -44,11 +46,22 @@ class CbcCpsMain { | |||
44 | System.exit(-1) | 46 | System.exit(-1) |
45 | } | 47 | } |
46 | val reader = new BufferedReader(new FileReader(SOLUTION_FILE)) | 48 | val reader = new BufferedReader(new FileReader(SOLUTION_FILE)) |
49 | var double value = Double.NaN | ||
47 | try { | 50 | try { |
48 | reader.lines.forEach[println(it)] | 51 | var String line |
52 | while ((line = reader.readLine) !== null) { | ||
53 | println(line) | ||
54 | val matcher = VALUE_REGEX.matcher(line) | ||
55 | if (matcher.matches) { | ||
56 | value = Double.parseDouble(matcher.group(1)) | ||
57 | } | ||
58 | } | ||
49 | } finally { | 59 | } finally { |
50 | reader.close | 60 | reader.close |
51 | } | 61 | } |
52 | println("Additional cost: " + problem.requests.flatMap[requirements.map[count]].reduce[p1, p2|p1 + p2] * 5) | 62 | val applicationCost = problem.requests.flatMap[requirements.map[count]].reduce[p1, p2|p1 + p2] * 5 |
63 | val cost = applicationCost + value | ||
64 | println | ||
65 | println("Cost: " + cost) | ||
53 | } | 66 | } |
54 | } | 67 | } |
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/dse/RuleBasedCpsMain.xtend b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/dse/RuleBasedCpsMain.xtend index b2cc0063..35b3b1df 100644 --- a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/dse/RuleBasedCpsMain.xtend +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/dse/RuleBasedCpsMain.xtend | |||
@@ -20,7 +20,7 @@ class RuleBasedCpsMain { | |||
20 | new IllegalStateException("This is a static utility class and should not be instantiated directly.") | 20 | new IllegalStateException("This is a static utility class and should not be instantiated directly.") |
21 | } | 21 | } |
22 | 22 | ||
23 | static def void main(String[] args) { | 23 | public static def void main(String[] args) { |
24 | DesignSpaceExplorer.turnOnLogging(DseLoggingLevel.VERBOSE_FULL) | 24 | DesignSpaceExplorer.turnOnLogging(DseLoggingLevel.VERBOSE_FULL) |
25 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put(Resource.Factory.Registry.DEFAULT_EXTENSION, | 25 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put(Resource.Factory.Registry.DEFAULT_EXTENSION, |
26 | new XMIResourceFactoryImpl) | 26 | new XMIResourceFactoryImpl) |
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/generator/CpsGenerator.xtend b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/generator/CpsGenerator.xtend index 390d13d3..e8d29949 100644 --- a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/generator/CpsGenerator.xtend +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/generator/CpsGenerator.xtend | |||
@@ -22,11 +22,17 @@ class CpsGenerator { | |||
22 | val Random random | 22 | val Random random |
23 | val int applicationTypeCount | 23 | val int applicationTypeCount |
24 | val int demandFactor | 24 | val int demandFactor |
25 | val boolean populateAppInstances | ||
25 | 26 | ||
26 | new(long randomSeed, int applicationTypeCount, int demandFactor) { | 27 | new(long randomSeed, int applicationTypeCount, int demandFactor) { |
28 | this(randomSeed, applicationTypeCount, demandFactor, false) | ||
29 | } | ||
30 | |||
31 | new(long randomSeed, int applicationTypeCount, int demandFactor, boolean populateAppInstances) { | ||
27 | this.random = new Random(randomSeed) | 32 | this.random = new Random(randomSeed) |
28 | this.applicationTypeCount = applicationTypeCount | 33 | this.applicationTypeCount = applicationTypeCount |
29 | this.demandFactor = demandFactor | 34 | this.demandFactor = demandFactor |
35 | this.populateAppInstances = populateAppInstances | ||
30 | } | 36 | } |
31 | 37 | ||
32 | def generateCpsProblem() { | 38 | def generateCpsProblem() { |
@@ -50,6 +56,14 @@ class CpsGenerator { | |||
50 | requirements += createRequirement => [ | 56 | requirements += createRequirement => [ |
51 | count = nextInt(CpsGenerator.MIN_REPLICAS, CpsGenerator.MAX_REPLICAS) | 57 | count = nextInt(CpsGenerator.MIN_REPLICAS, CpsGenerator.MAX_REPLICAS) |
52 | type = appType | 58 | type = appType |
59 | if (populateAppInstances) { | ||
60 | for (j : 0 ..< count) { | ||
61 | val app = createApplicationInstance | ||
62 | app.type = appType | ||
63 | appType.instances += app | ||
64 | instances += app | ||
65 | } | ||
66 | } | ||
53 | ] | 67 | ] |
54 | } | 68 | } |
55 | ] | 69 | ] |
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 index 628d5963..459c6ab7 100644 --- 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 | |||
@@ -2,6 +2,11 @@ package hu.bme.mit.inf.dslreasoner.domains.cps.mdeo | |||
2 | 2 | ||
3 | import hu.bme.mit.inf.dslreasoner.domains.cps.CpsPackage | 3 | import hu.bme.mit.inf.dslreasoner.domains.cps.CpsPackage |
4 | import hu.bme.mit.inf.dslreasoner.domains.cps.generator.CpsGenerator | 4 | import hu.bme.mit.inf.dslreasoner.domains.cps.generator.CpsGenerator |
5 | import java.io.BufferedReader | ||
6 | import java.io.BufferedWriter | ||
7 | import java.io.FileReader | ||
8 | import java.io.FileWriter | ||
9 | import java.util.Map | ||
5 | import org.eclipse.emf.common.util.URI | 10 | import org.eclipse.emf.common.util.URI |
6 | import org.eclipse.emf.ecore.EPackage | 11 | import org.eclipse.emf.ecore.EPackage |
7 | import org.eclipse.emf.ecore.resource.Resource | 12 | import org.eclipse.emf.ecore.resource.Resource |
@@ -21,11 +26,33 @@ class CpsMdeOptimiserMain { | |||
21 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put(Resource.Factory.Registry.DEFAULT_EXTENSION, | 26 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put(Resource.Factory.Registry.DEFAULT_EXTENSION, |
22 | new XMIResourceFactoryImpl) | 27 | new XMIResourceFactoryImpl) |
23 | EPackage.Registry.INSTANCE.put(CpsPackage.eNS_URI, CpsPackage.eINSTANCE) | 28 | EPackage.Registry.INSTANCE.put(CpsPackage.eNS_URI, CpsPackage.eINSTANCE) |
24 | val generator = new CpsGenerator(1, 4, 2) | 29 | val generator = new CpsGenerator(1, 4, 1) |
25 | val problem = generator.generateCpsProblem | 30 | val problem = generator.generateCpsProblem |
26 | problem.eResource.URI = URI.createFileURI(PROBLEM_PATH) | 31 | problem.eResource.URI = URI.createFileURI(PROBLEM_PATH) |
27 | problem.eResource.save(emptyMap) | 32 | problem.eResource.save(emptyMap) |
33 | fixupHenshinModel("model/cps.henshin", "model/cps_fixup.henshin", #{"cps.ecore" -> CpsPackage.eNS_URI}) | ||
28 | val injector = new MoptStandaloneSetup().createInjectorAndDoEMFRegistration(); | 34 | val injector = new MoptStandaloneSetup().createInjectorAndDoEMFRegistration(); |
29 | injector.getInstance(ExcludedRun).run(PROJECT_PATH, MOPT_PATH) | 35 | injector.getInstance(ExcludedRun).run(PROJECT_PATH, MOPT_PATH) |
30 | } | 36 | } |
37 | |||
38 | private def static void fixupHenshinModel(String originalPath, String outputPath, Map<String, String> remapMap) { | ||
39 | val reader = new BufferedReader(new FileReader(originalPath)) | ||
40 | try { | ||
41 | val writer = new BufferedWriter(new FileWriter(outputPath)) | ||
42 | try { | ||
43 | var String line | ||
44 | while ((line = reader.readLine) !== null) { | ||
45 | for (entry : remapMap.entrySet) { | ||
46 | line = line.replace(entry.key, entry.value) | ||
47 | } | ||
48 | writer.write(line) | ||
49 | writer.write("\n") | ||
50 | } | ||
51 | } finally { | ||
52 | writer.close | ||
53 | } | ||
54 | } finally { | ||
55 | reader.close | ||
56 | } | ||
57 | } | ||
31 | } | 58 | } |
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 index 4c05939d..67fe7508 100644 --- 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 | |||
@@ -16,11 +16,13 @@ goal { | |||
16 | } | 16 | } |
17 | 17 | ||
18 | search { | 18 | search { |
19 | // mutate using <cps.henshin> unit "createAppInstance" | 19 | // mutate using <cps_fixup.henshin> unit "createAppInstance" |
20 | // mutate using <cps.henshin> unit "createHostInstance" | 20 | // mutate using <cps_fixup.henshin> unit "deleteAppInstance" |
21 | // mutate using <cps.henshin> unit "allocate" | 21 | // mutate using <cps_fixup.henshin> unit "createHostInstance" |
22 | // mutate using <cps.henshin> unit "deleteAppInstance" | 22 | // mutate using <cps_fixup.henshin> unit "deleteHostInstance" |
23 | // mutate using <cps.henshin> unit "unallocate" | 23 | // mutate using <cps_fixup.henshin> unit "allocate" |
24 | // mutate using <cps_fixup.henshin> unit "unallocate" | ||
25 | // mutate using <cps_fixup.henshin> unit "reallocate" | ||
24 | mutate { "ApplicationInstance" } | 26 | mutate { "ApplicationInstance" } |
25 | mutate { "HostInstance" } | 27 | mutate { "HostInstance" } |
26 | } | 28 | } |