diff options
author | 2019-08-14 18:26:33 +0200 | |
---|---|---|
committer | 2019-08-14 18:26:33 +0200 | |
commit | fc84d3fe670331bc89fb1e4c44104bc1fc811438 (patch) | |
tree | 466da8333151c51d2e17075600f9452ed35835da /Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains | |
parent | Be more lenient with rounding IP solver results (diff) | |
download | VIATRA-Generator-fc84d3fe670331bc89fb1e4c44104bc1fc811438.tar.gz VIATRA-Generator-fc84d3fe670331bc89fb1e4c44104bc1fc811438.tar.zst VIATRA-Generator-fc84d3fe670331bc89fb1e4c44104bc1fc811438.zip |
Measurements WIP
Diffstat (limited to 'Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains')
7 files changed, 7 insertions, 211 deletions
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/CostObjective.xtend b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/CostObjective.xtend deleted file mode 100644 index 43b2902f..00000000 --- a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/CostObjective.xtend +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.satellite.mdeo | ||
2 | |||
3 | //import hu.bme.mit.inf.dslreasoner.domains.satellite.queries.CostMetric | ||
4 | // | ||
5 | //class CostObjective extends MetricBasedGuidanceFunction { | ||
6 | // new() { | ||
7 | // super(CostMetric.instance) | ||
8 | // } | ||
9 | // | ||
10 | // override getName() { | ||
11 | // "Cost" | ||
12 | // } | ||
13 | //} | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/LocalSearchEngineManager.xtend b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/LocalSearchEngineManager.xtend deleted file mode 100644 index ee7f0060..00000000 --- a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/LocalSearchEngineManager.xtend +++ /dev/null | |||
@@ -1,31 +0,0 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.satellite.mdeo | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.domains.satellite.queries.SatelliteQueries | ||
4 | import java.util.WeakHashMap | ||
5 | import org.eclipse.emf.ecore.EObject | ||
6 | import org.eclipse.viatra.query.runtime.api.AdvancedViatraQueryEngine | ||
7 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine | ||
8 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngineOptions | ||
9 | import org.eclipse.viatra.query.runtime.emf.EMFScope | ||
10 | import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchHints | ||
11 | |||
12 | class LocalSearchEngineManager { | ||
13 | public static val INSTANCE = new LocalSearchEngineManager | ||
14 | |||
15 | val WeakHashMap<EObject, ViatraQueryEngine> engineMap = new WeakHashMap | ||
16 | |||
17 | private new() { | ||
18 | } | ||
19 | |||
20 | def getEngine(EObject eObject) { | ||
21 | engineMap.computeIfAbsent(eObject) [ | ||
22 | val scope = new EMFScope(it) | ||
23 | val localSearchHints = LocalSearchHints.^default.build | ||
24 | val options = ViatraQueryEngineOptions.defineOptions.withDefaultHint(localSearchHints).withDefaultBackend( | ||
25 | localSearchHints.queryBackendFactory).build | ||
26 | val engine = AdvancedViatraQueryEngine.on(scope, options) | ||
27 | SatelliteQueries.instance.prepare(engine) | ||
28 | engine | ||
29 | ] | ||
30 | } | ||
31 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/MetricBasedGuidanceFunction.xtend b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/MetricBasedGuidanceFunction.xtend deleted file mode 100644 index 1529794f..00000000 --- a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/MetricBasedGuidanceFunction.xtend +++ /dev/null | |||
@@ -1,47 +0,0 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.satellite.mdeo | ||
2 | |||
3 | import org.eclipse.viatra.query.runtime.api.IPatternMatch | ||
4 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification | ||
5 | import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher | ||
6 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.IGuidanceFunction | ||
7 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.interpreter.guidance.Solution | ||
8 | |||
9 | abstract class MetricBasedGuidanceFunction implements IGuidanceFunction { | ||
10 | val IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> querySpecification | ||
11 | |||
12 | protected new(IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> querySpecification) { | ||
13 | this.querySpecification = querySpecification | ||
14 | if (querySpecification.parameters.size != 1) { | ||
15 | throw new IllegalArgumentException("Metric must have a single parameter") | ||
16 | } | ||
17 | } | ||
18 | |||
19 | override computeFitness(Solution model) { | ||
20 | val value = getMetricValue(model) | ||
21 | computeFitness(value) | ||
22 | } | ||
23 | |||
24 | protected def double computeFitness(double metricValue) { | ||
25 | metricValue | ||
26 | } | ||
27 | |||
28 | private def getMetricValue(Solution solution) { | ||
29 | val model = solution.model | ||
30 | val queryEngine = LocalSearchEngineManager.INSTANCE.getEngine(model) | ||
31 | val matcher = querySpecification.getMatcher(queryEngine) | ||
32 | val iterator = matcher.allMatches.iterator | ||
33 | if (!iterator.hasNext) { | ||
34 | throw new IllegalStateException("Too few matches") | ||
35 | } | ||
36 | val objectValue = iterator.next.get(0) | ||
37 | if (objectValue instanceof Number) { | ||
38 | val doubleValue = objectValue.doubleValue | ||
39 | if (iterator.hasNext) { | ||
40 | throw new IllegalStateException("Too many matches") | ||
41 | } | ||
42 | doubleValue | ||
43 | } else { | ||
44 | throw new IllegalStateException("Metric value must be a number") | ||
45 | } | ||
46 | } | ||
47 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/PatternMatchConstraint.xtend b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/PatternMatchConstraint.xtend deleted file mode 100644 index b238e64f..00000000 --- a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/PatternMatchConstraint.xtend +++ /dev/null | |||
@@ -1,29 +0,0 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.satellite.mdeo | ||
2 | |||
3 | import com.google.common.collect.ImmutableList | ||
4 | import hu.bme.mit.inf.dslreasoner.domains.satellite.queries.SatelliteQueries | ||
5 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.IGuidanceFunction | ||
6 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.interpreter.guidance.Solution | ||
7 | |||
8 | class PatternMatchConstraint implements IGuidanceFunction { | ||
9 | static val CONSTRAINT_ANNOTATION_NAME = "Constraint" | ||
10 | |||
11 | val queries = ImmutableList.copyOf(SatelliteQueries.instance.specifications.filter [ | ||
12 | allAnnotations.exists[name == CONSTRAINT_ANNOTATION_NAME] | ||
13 | ]) | ||
14 | |||
15 | override getName() { | ||
16 | "PatternMatch" | ||
17 | } | ||
18 | |||
19 | override computeFitness(Solution solution) { | ||
20 | val model = solution.model | ||
21 | val queryEngine = LocalSearchEngineManager.INSTANCE.getEngine(model) | ||
22 | var int matchCount = 0 | ||
23 | for (query : queries) { | ||
24 | val matcher = query.getMatcher(queryEngine) | ||
25 | matchCount += matcher.countMatches | ||
26 | } | ||
27 | matchCount | ||
28 | } | ||
29 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/SatelliteMdeOptimiserMain.xtend b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/SatelliteMdeOptimiserMain.xtend deleted file mode 100644 index 58034c43..00000000 --- a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/SatelliteMdeOptimiserMain.xtend +++ /dev/null | |||
@@ -1,51 +0,0 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.satellite.mdeo | ||
2 | |||
3 | import java.io.BufferedReader | ||
4 | import java.io.BufferedWriter | ||
5 | import java.io.FileReader | ||
6 | import java.io.FileWriter | ||
7 | import java.util.Map | ||
8 | import org.eclipse.emf.ecore.EPackage | ||
9 | import org.eclipse.emf.ecore.resource.Resource | ||
10 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl | ||
11 | import satellite.SatellitePackage | ||
12 | import uk.ac.kcl.inf.mdeoptimiser.interfaces.cli.Run | ||
13 | |||
14 | class SatelliteMdeOptimiserMain { | ||
15 | static val PROJECT_PATH = "." | ||
16 | static val MOPT_PATH = "src/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/satellite.mopt" | ||
17 | |||
18 | private new() { | ||
19 | new IllegalStateException("This is a static utility class and should not be instantiated directly.") | ||
20 | } | ||
21 | |||
22 | public static def void main(String[] args) { | ||
23 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put(Resource.Factory.Registry.DEFAULT_EXTENSION, | ||
24 | new XMIResourceFactoryImpl) | ||
25 | EPackage.Registry.INSTANCE.put(SatellitePackage.eNS_URI, SatellitePackage.eINSTANCE) | ||
26 | fixupHenshinModel("model/satellite.henshin", "model/satellite_fixup.henshin", | ||
27 | #{"satellite.ecore" -> SatellitePackage.eNS_URI}) | ||
28 | Run.main(#["-p", PROJECT_PATH, "-m", MOPT_PATH]) | ||
29 | } | ||
30 | |||
31 | private def static void fixupHenshinModel(String originalPath, String outputPath, Map<String, String> remapMap) { | ||
32 | val reader = new BufferedReader(new FileReader(originalPath)) | ||
33 | try { | ||
34 | val writer = new BufferedWriter(new FileWriter(outputPath)) | ||
35 | try { | ||
36 | var String line | ||
37 | while ((line = reader.readLine) !== null) { | ||
38 | for (entry : remapMap.entrySet) { | ||
39 | line = line.replace(entry.key, entry.value) | ||
40 | } | ||
41 | writer.write(line) | ||
42 | writer.write("\n") | ||
43 | } | ||
44 | } finally { | ||
45 | writer.close | ||
46 | } | ||
47 | } finally { | ||
48 | reader.close | ||
49 | } | ||
50 | } | ||
51 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/satellite.mopt b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/satellite.mopt deleted file mode 100644 index e9bd1a64..00000000 --- a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/satellite.mopt +++ /dev/null | |||
@@ -1,36 +0,0 @@ | |||
1 | problem { | ||
2 | basepath <model> | ||
3 | metamodel <satellite.SatellitePackage> | ||
4 | model <../inputs/SatelliteInstance.xmi> | ||
5 | } | ||
6 | |||
7 | goal { | ||
8 | objective Cost minimise java { "hu.bme.mit.inf.dslreasoner.domains.satellite.mdeo.CostObjective" } | ||
9 | constraint PatternMatch java { "hu.bme.mit.inf.dslreasoner.domains.satellite.mdeo.PatternMatchConstraint" } | ||
10 | } | ||
11 | |||
12 | search { | ||
13 | // mutate using <satellite_fixup.henshin> unit "addCubeSat3U" | ||
14 | mutate { "CubeSat3U" } | ||
15 | mutate { "CubeSat6U" } | ||
16 | mutate { "SmallSat" } | ||
17 | mutate { "InterferometryPayload" } | ||
18 | mutate { "UHFCommSubsystem" } | ||
19 | mutate { "XCommSubsystem" } | ||
20 | mutate { "KaCommSubsystem" } | ||
21 | } | ||
22 | |||
23 | solver { | ||
24 | optimisation provider moea algorithm NSGAII { | ||
25 | variation: mutation | ||
26 | population: 25 | ||
27 | mutation.step: 3 | ||
28 | mutation.strategy: random | ||
29 | } | ||
30 | |||
31 | termination { | ||
32 | time: 120 | ||
33 | } | ||
34 | |||
35 | batches 1 | ||
36 | } \ No newline at end of file | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains/satellite/queries/SatelliteQueries.vql b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains/satellite/queries/SatelliteQueries.vql index c1d3f7d3..1f83a3b0 100644 --- a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains/satellite/queries/SatelliteQueries.vql +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/src/hu/bme/mit/inf/dslreasoner/domains/satellite/queries/SatelliteQueries.vql | |||
@@ -21,6 +21,13 @@ pattern transmittingGroundStationNetwork(Station : GroundStationNetwork) { | |||
21 | find transmittingCommSubsystem(Station, _); | 21 | find transmittingCommSubsystem(Station, _); |
22 | } | 22 | } |
23 | 23 | ||
24 | @Constraint(severity = "error", key = {Station}, | ||
25 | message = "The ground station network may not have UHF communication subsystems.") | ||
26 | pattern roundStationNetworkUHF(Station : GroundStationNetwork) { | ||
27 | CommunicatingElement.commSubsystem(Station, Comm); | ||
28 | UHFCommSubsystem(Comm); | ||
29 | } | ||
30 | |||
24 | // At least two spacecraft must have the interferometry payload configured | 31 | // At least two spacecraft must have the interferometry payload configured |
25 | 32 | ||
26 | @Constraint(severity = "error", key = {Mission}, | 33 | @Constraint(severity = "error", key = {Mission}, |
@@ -97,10 +104,6 @@ private pattern cubeSat3U(Sat : CubeSat3U) { | |||
97 | CubeSat3U(Sat); | 104 | CubeSat3U(Sat); |
98 | } | 105 | } |
99 | 106 | ||
100 | private pattern cubeSat6U(Sat : CubeSat6U) { | ||
101 | CubeSat6U(Sat); | ||
102 | } | ||
103 | |||
104 | // No communication loops may exist | 107 | // No communication loops may exist |
105 | // No spacecraft may directly communicate with itself | 108 | // No spacecraft may directly communicate with itself |
106 | 109 | ||