diff options
Diffstat (limited to 'Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen')
10 files changed, 250 insertions, 0 deletions
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/.CostObjective.xtendbin b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/.CostObjective.xtendbin new file mode 100644 index 00000000..9d4649e5 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/.CostObjective.xtendbin | |||
Binary files differ | |||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/.LocalSearchEngineManager.xtendbin b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/.LocalSearchEngineManager.xtendbin new file mode 100644 index 00000000..9c013962 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/.LocalSearchEngineManager.xtendbin | |||
Binary files differ | |||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/.MetricBasedGuidanceFunction.xtendbin b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/.MetricBasedGuidanceFunction.xtendbin new file mode 100644 index 00000000..456c7785 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/.MetricBasedGuidanceFunction.xtendbin | |||
Binary files differ | |||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/.PatternMatchConstraint.xtendbin b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/.PatternMatchConstraint.xtendbin new file mode 100644 index 00000000..4eaa04bd --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/.PatternMatchConstraint.xtendbin | |||
Binary files differ | |||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/.SatelliteMdeOptimiserMain.xtendbin b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/.SatelliteMdeOptimiserMain.xtendbin new file mode 100644 index 00000000..11cbad32 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/.SatelliteMdeOptimiserMain.xtendbin | |||
Binary files differ | |||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/CostObjective.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/CostObjective.java new file mode 100644 index 00000000..8659913c --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/CostObjective.java | |||
@@ -0,0 +1,16 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.satellite.mdeo; | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.domains.satellite.mdeo.MetricBasedGuidanceFunction; | ||
4 | import hu.bme.mit.inf.dslreasoner.domains.satellite.queries.CostMetric; | ||
5 | |||
6 | @SuppressWarnings("all") | ||
7 | public class CostObjective extends MetricBasedGuidanceFunction { | ||
8 | public CostObjective() { | ||
9 | super(CostMetric.instance()); | ||
10 | } | ||
11 | |||
12 | @Override | ||
13 | public String getName() { | ||
14 | return "Cost"; | ||
15 | } | ||
16 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/LocalSearchEngineManager.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/LocalSearchEngineManager.java new file mode 100644 index 00000000..18708a37 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/LocalSearchEngineManager.java | |||
@@ -0,0 +1,39 @@ | |||
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 java.util.function.Function; | ||
6 | import org.eclipse.emf.ecore.EObject; | ||
7 | import org.eclipse.viatra.query.runtime.api.AdvancedViatraQueryEngine; | ||
8 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
9 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngineOptions; | ||
10 | import org.eclipse.viatra.query.runtime.emf.EMFScope; | ||
11 | import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchHints; | ||
12 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
13 | |||
14 | @SuppressWarnings("all") | ||
15 | public class LocalSearchEngineManager { | ||
16 | public static final LocalSearchEngineManager INSTANCE = new LocalSearchEngineManager(); | ||
17 | |||
18 | private final WeakHashMap<EObject, ViatraQueryEngine> engineMap = new WeakHashMap<EObject, ViatraQueryEngine>(); | ||
19 | |||
20 | private LocalSearchEngineManager() { | ||
21 | } | ||
22 | |||
23 | public ViatraQueryEngine getEngine(final EObject eObject) { | ||
24 | final Function<EObject, ViatraQueryEngine> _function = (EObject it) -> { | ||
25 | ViatraQueryEngine _xblockexpression = null; | ||
26 | { | ||
27 | final EMFScope scope = new EMFScope(it); | ||
28 | final QueryEvaluationHint localSearchHints = LocalSearchHints.getDefault().build(); | ||
29 | final ViatraQueryEngineOptions options = ViatraQueryEngineOptions.defineOptions().withDefaultHint(localSearchHints).withDefaultBackend( | ||
30 | localSearchHints.getQueryBackendFactory()).build(); | ||
31 | final ViatraQueryEngine engine = AdvancedViatraQueryEngine.on(scope, options); | ||
32 | SatelliteQueries.instance().prepare(engine); | ||
33 | _xblockexpression = engine; | ||
34 | } | ||
35 | return _xblockexpression; | ||
36 | }; | ||
37 | return this.engineMap.computeIfAbsent(eObject, _function); | ||
38 | } | ||
39 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/MetricBasedGuidanceFunction.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/MetricBasedGuidanceFunction.java new file mode 100644 index 00000000..f3dae715 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/MetricBasedGuidanceFunction.java | |||
@@ -0,0 +1,72 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.satellite.mdeo; | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.domains.satellite.mdeo.LocalSearchEngineManager; | ||
4 | import java.util.Iterator; | ||
5 | import org.eclipse.emf.ecore.EObject; | ||
6 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
7 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
8 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
9 | import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher; | ||
10 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.IGuidanceFunction; | ||
11 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.interpreter.guidance.Solution; | ||
12 | |||
13 | @SuppressWarnings("all") | ||
14 | public abstract class MetricBasedGuidanceFunction implements IGuidanceFunction { | ||
15 | private final IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> querySpecification; | ||
16 | |||
17 | protected MetricBasedGuidanceFunction(final IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> querySpecification) { | ||
18 | this.querySpecification = querySpecification; | ||
19 | int _size = querySpecification.getParameters().size(); | ||
20 | boolean _notEquals = (_size != 1); | ||
21 | if (_notEquals) { | ||
22 | throw new IllegalArgumentException("Metric must have a single parameter"); | ||
23 | } | ||
24 | } | ||
25 | |||
26 | @Override | ||
27 | public double computeFitness(final Solution model) { | ||
28 | double _xblockexpression = (double) 0; | ||
29 | { | ||
30 | final double value = this.getMetricValue(model); | ||
31 | _xblockexpression = this.computeFitness(value); | ||
32 | } | ||
33 | return _xblockexpression; | ||
34 | } | ||
35 | |||
36 | protected double computeFitness(final double metricValue) { | ||
37 | return metricValue; | ||
38 | } | ||
39 | |||
40 | private double getMetricValue(final Solution solution) { | ||
41 | double _xblockexpression = (double) 0; | ||
42 | { | ||
43 | final EObject model = solution.getModel(); | ||
44 | final ViatraQueryEngine queryEngine = LocalSearchEngineManager.INSTANCE.getEngine(model); | ||
45 | final ViatraQueryMatcher<? extends IPatternMatch> matcher = this.querySpecification.getMatcher(queryEngine); | ||
46 | final Iterator<? extends IPatternMatch> iterator = matcher.getAllMatches().iterator(); | ||
47 | boolean _hasNext = iterator.hasNext(); | ||
48 | boolean _not = (!_hasNext); | ||
49 | if (_not) { | ||
50 | throw new IllegalStateException("Too few matches"); | ||
51 | } | ||
52 | final Object objectValue = iterator.next().get(0); | ||
53 | double _xifexpression = (double) 0; | ||
54 | if ((objectValue instanceof Number)) { | ||
55 | double _xblockexpression_1 = (double) 0; | ||
56 | { | ||
57 | final double doubleValue = ((Number)objectValue).doubleValue(); | ||
58 | boolean _hasNext_1 = iterator.hasNext(); | ||
59 | if (_hasNext_1) { | ||
60 | throw new IllegalStateException("Too many matches"); | ||
61 | } | ||
62 | _xblockexpression_1 = doubleValue; | ||
63 | } | ||
64 | _xifexpression = _xblockexpression_1; | ||
65 | } else { | ||
66 | throw new IllegalStateException("Metric value must be a number"); | ||
67 | } | ||
68 | _xblockexpression = _xifexpression; | ||
69 | } | ||
70 | return _xblockexpression; | ||
71 | } | ||
72 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/PatternMatchConstraint.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/PatternMatchConstraint.java new file mode 100644 index 00000000..f089d469 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/PatternMatchConstraint.java | |||
@@ -0,0 +1,54 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.satellite.mdeo; | ||
2 | |||
3 | import com.google.common.base.Objects; | ||
4 | import com.google.common.collect.ImmutableList; | ||
5 | import hu.bme.mit.inf.dslreasoner.domains.satellite.mdeo.LocalSearchEngineManager; | ||
6 | import hu.bme.mit.inf.dslreasoner.domains.satellite.queries.SatelliteQueries; | ||
7 | import org.eclipse.emf.ecore.EObject; | ||
8 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
9 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
10 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
11 | import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher; | ||
12 | import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; | ||
13 | import org.eclipse.xtext.xbase.lib.Functions.Function1; | ||
14 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
15 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.IGuidanceFunction; | ||
16 | import uk.ac.kcl.inf.mdeoptimiser.libraries.core.optimisation.interpreter.guidance.Solution; | ||
17 | |||
18 | @SuppressWarnings("all") | ||
19 | public class PatternMatchConstraint implements IGuidanceFunction { | ||
20 | private static final String CONSTRAINT_ANNOTATION_NAME = "Constraint"; | ||
21 | |||
22 | private final ImmutableList<IQuerySpecification<?>> queries = ImmutableList.<IQuerySpecification<?>>copyOf(IterableExtensions.<IQuerySpecification<?>>filter(SatelliteQueries.instance().getSpecifications(), ((Function1<IQuerySpecification<?>, Boolean>) (IQuerySpecification<?> it) -> { | ||
23 | final Function1<PAnnotation, Boolean> _function = (PAnnotation it_1) -> { | ||
24 | String _name = it_1.getName(); | ||
25 | return Boolean.valueOf(Objects.equal(_name, PatternMatchConstraint.CONSTRAINT_ANNOTATION_NAME)); | ||
26 | }; | ||
27 | return Boolean.valueOf(IterableExtensions.<PAnnotation>exists(it.getAllAnnotations(), _function)); | ||
28 | }))); | ||
29 | |||
30 | @Override | ||
31 | public String getName() { | ||
32 | return "PatternMatch"; | ||
33 | } | ||
34 | |||
35 | @Override | ||
36 | public double computeFitness(final Solution solution) { | ||
37 | int _xblockexpression = (int) 0; | ||
38 | { | ||
39 | final EObject model = solution.getModel(); | ||
40 | final ViatraQueryEngine queryEngine = LocalSearchEngineManager.INSTANCE.getEngine(model); | ||
41 | int matchCount = 0; | ||
42 | for (final IQuerySpecification<?> query : this.queries) { | ||
43 | { | ||
44 | final ViatraQueryMatcher<? extends IPatternMatch> matcher = query.getMatcher(queryEngine); | ||
45 | int _matchCount = matchCount; | ||
46 | int _countMatches = matcher.countMatches(); | ||
47 | matchCount = (_matchCount + _countMatches); | ||
48 | } | ||
49 | } | ||
50 | _xblockexpression = matchCount; | ||
51 | } | ||
52 | return _xblockexpression; | ||
53 | } | ||
54 | } | ||
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/SatelliteMdeOptimiserMain.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/SatelliteMdeOptimiserMain.java new file mode 100644 index 00000000..6cbb08fc --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.satellite/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/SatelliteMdeOptimiserMain.java | |||
@@ -0,0 +1,69 @@ | |||
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.Collections; | ||
8 | import java.util.Map; | ||
9 | import java.util.Set; | ||
10 | import org.eclipse.emf.ecore.EPackage; | ||
11 | import org.eclipse.emf.ecore.resource.Resource; | ||
12 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; | ||
13 | import org.eclipse.xtext.xbase.lib.CollectionLiterals; | ||
14 | import org.eclipse.xtext.xbase.lib.Exceptions; | ||
15 | import org.eclipse.xtext.xbase.lib.Pair; | ||
16 | import satellite.SatellitePackage; | ||
17 | import uk.ac.kcl.inf.mdeoptimiser.interfaces.cli.Run; | ||
18 | |||
19 | @SuppressWarnings("all") | ||
20 | public class SatelliteMdeOptimiserMain { | ||
21 | private static final String PROJECT_PATH = "."; | ||
22 | |||
23 | private static final String MOPT_PATH = "src/hu/bme/mit/inf/dslreasoner/domains/satellite/mdeo/satellite.mopt"; | ||
24 | |||
25 | private SatelliteMdeOptimiserMain() { | ||
26 | new IllegalStateException("This is a static utility class and should not be instantiated directly."); | ||
27 | } | ||
28 | |||
29 | public static void main(final String[] args) { | ||
30 | Map<String, Object> _extensionToFactoryMap = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap(); | ||
31 | XMIResourceFactoryImpl _xMIResourceFactoryImpl = new XMIResourceFactoryImpl(); | ||
32 | _extensionToFactoryMap.put(Resource.Factory.Registry.DEFAULT_EXTENSION, _xMIResourceFactoryImpl); | ||
33 | EPackage.Registry.INSTANCE.put(SatellitePackage.eNS_URI, SatellitePackage.eINSTANCE); | ||
34 | Pair<String, String> _mappedTo = Pair.<String, String>of("satellite.ecore", SatellitePackage.eNS_URI); | ||
35 | SatelliteMdeOptimiserMain.fixupHenshinModel("model/satellite.henshin", "model/satellite_fixup.henshin", | ||
36 | Collections.<String, String>unmodifiableMap(CollectionLiterals.<String, String>newHashMap(_mappedTo))); | ||
37 | Run.main(new String[] { "-p", SatelliteMdeOptimiserMain.PROJECT_PATH, "-m", SatelliteMdeOptimiserMain.MOPT_PATH }); | ||
38 | } | ||
39 | |||
40 | private static void fixupHenshinModel(final String originalPath, final String outputPath, final Map<String, String> remapMap) { | ||
41 | try { | ||
42 | FileReader _fileReader = new FileReader(originalPath); | ||
43 | final BufferedReader reader = new BufferedReader(_fileReader); | ||
44 | try { | ||
45 | FileWriter _fileWriter = new FileWriter(outputPath); | ||
46 | final BufferedWriter writer = new BufferedWriter(_fileWriter); | ||
47 | try { | ||
48 | String line = null; | ||
49 | while (((line = reader.readLine()) != null)) { | ||
50 | { | ||
51 | Set<Map.Entry<String, String>> _entrySet = remapMap.entrySet(); | ||
52 | for (final Map.Entry<String, String> entry : _entrySet) { | ||
53 | line = line.replace(entry.getKey(), entry.getValue()); | ||
54 | } | ||
55 | writer.write(line); | ||
56 | writer.write("\n"); | ||
57 | } | ||
58 | } | ||
59 | } finally { | ||
60 | writer.close(); | ||
61 | } | ||
62 | } finally { | ||
63 | reader.close(); | ||
64 | } | ||
65 | } catch (Throwable _e) { | ||
66 | throw Exceptions.sneakyThrow(_e); | ||
67 | } | ||
68 | } | ||
69 | } | ||