diff options
author | 2019-05-21 17:00:01 -0400 | |
---|---|---|
committer | 2019-05-21 17:00:01 -0400 | |
commit | fd3684b5440dacca0c4bf4be15930555a79e2100 (patch) | |
tree | 24120a5c7fdae1532529fa0c4687dc1078cd1cde /Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/RuleBasedCpsSolver.java | |
parent | Interval hull aggregation operator (diff) | |
download | VIATRA-Generator-fd3684b5440dacca0c4bf4be15930555a79e2100.tar.gz VIATRA-Generator-fd3684b5440dacca0c4bf4be15930555a79e2100.tar.zst VIATRA-Generator-fd3684b5440dacca0c4bf4be15930555a79e2100.zip |
VIATRA DSE and COIN-OR CBC implementations of CPS case study
Diffstat (limited to 'Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/RuleBasedCpsSolver.java')
-rw-r--r-- | Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/RuleBasedCpsSolver.java | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/RuleBasedCpsSolver.java b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/RuleBasedCpsSolver.java new file mode 100644 index 00000000..fd348752 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/xtend-gen/hu/bme/mit/inf/dslreasoner/domains/cps/dse/RuleBasedCpsSolver.java | |||
@@ -0,0 +1,93 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.cps.dse; | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.domains.cps.ApplicationInstance; | ||
4 | import hu.bme.mit.inf.dslreasoner.domains.cps.CpsFactory; | ||
5 | import hu.bme.mit.inf.dslreasoner.domains.cps.CpsPackage; | ||
6 | import hu.bme.mit.inf.dslreasoner.domains.cps.CyberPhysicalSystem; | ||
7 | import hu.bme.mit.inf.dslreasoner.domains.cps.HostInstance; | ||
8 | import hu.bme.mit.inf.dslreasoner.domains.cps.dse.CpsStateCoder; | ||
9 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.Allocate; | ||
10 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeHddMetric; | ||
11 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.AverageFreeMemoryMetric; | ||
12 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CostMetric; | ||
13 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.CreateHostInstance; | ||
14 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.GuidanceObjective; | ||
15 | import hu.bme.mit.inf.dslreasoner.domains.cps.queries.RequirementNotSatisfied; | ||
16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.CompositeDirectionalThresholdObjective; | ||
17 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveKind; | ||
18 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveThreshold; | ||
19 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.QueryBasedObjective; | ||
20 | import java.util.Collection; | ||
21 | import java.util.function.Consumer; | ||
22 | import org.eclipse.emf.common.util.EList; | ||
23 | import org.eclipse.viatra.dse.api.DesignSpaceExplorer; | ||
24 | import org.eclipse.viatra.dse.api.Solution; | ||
25 | import org.eclipse.viatra.dse.evolutionary.EvolutionaryStrategy; | ||
26 | import org.eclipse.viatra.dse.evolutionary.EvolutionaryStrategyBuilder; | ||
27 | import org.eclipse.viatra.dse.objectives.Fitness; | ||
28 | import org.eclipse.viatra.transformation.runtime.emf.rules.batch.BatchTransformationRuleFactory; | ||
29 | import org.eclipse.xtext.xbase.lib.Extension; | ||
30 | import org.eclipse.xtext.xbase.lib.InputOutput; | ||
31 | |||
32 | @SuppressWarnings("all") | ||
33 | public class RuleBasedCpsSolver { | ||
34 | @Extension | ||
35 | private final BatchTransformationRuleFactory _batchTransformationRuleFactory = new BatchTransformationRuleFactory(); | ||
36 | |||
37 | @Extension | ||
38 | private final CpsFactory _cpsFactory = CpsFactory.eINSTANCE; | ||
39 | |||
40 | public void solve(final CyberPhysicalSystem problem) { | ||
41 | final DesignSpaceExplorer dse = new DesignSpaceExplorer(); | ||
42 | dse.addMetaModelPackage(CpsPackage.eINSTANCE); | ||
43 | dse.setInitialModel(problem.eResource().getResourceSet()); | ||
44 | final Consumer<RequirementNotSatisfied.Match> _function = (RequirementNotSatisfied.Match it) -> { | ||
45 | final ApplicationInstance app = this._cpsFactory.createApplicationInstance(); | ||
46 | EList<ApplicationInstance> _instances = it.getReq().getType().getInstances(); | ||
47 | _instances.add(app); | ||
48 | EList<ApplicationInstance> _instances_1 = it.getReq().getInstances(); | ||
49 | _instances_1.add(app); | ||
50 | }; | ||
51 | dse.addTransformationRule(this._batchTransformationRuleFactory.<RequirementNotSatisfied.Match, RequirementNotSatisfied.Matcher>createRule(RequirementNotSatisfied.instance()).action(_function).build()); | ||
52 | final Consumer<Allocate.Match> _function_1 = (Allocate.Match it) -> { | ||
53 | ApplicationInstance _app = it.getApp(); | ||
54 | _app.setAllocatedTo(it.getHost()); | ||
55 | }; | ||
56 | dse.addTransformationRule(this._batchTransformationRuleFactory.<Allocate.Match, Allocate.Matcher>createRule(Allocate.instance()).action(_function_1).build()); | ||
57 | final Consumer<CreateHostInstance.Match> _function_2 = (CreateHostInstance.Match it) -> { | ||
58 | EList<HostInstance> _instances = it.getHostType().getInstances(); | ||
59 | HostInstance _createHostInstance = this._cpsFactory.createHostInstance(); | ||
60 | _instances.add(_createHostInstance); | ||
61 | }; | ||
62 | dse.addTransformationRule(this._batchTransformationRuleFactory.<CreateHostInstance.Match, CreateHostInstance.Matcher>createRule(CreateHostInstance.instance()).action(_function_2).build()); | ||
63 | GuidanceObjective _instance = GuidanceObjective.instance(); | ||
64 | ObjectiveThreshold.Inclusive _inclusive = new ObjectiveThreshold.Inclusive(0); | ||
65 | QueryBasedObjective _queryBasedObjective = new QueryBasedObjective(_instance, ObjectiveKind.LOWER_IS_BETTER, _inclusive, 0); | ||
66 | AverageFreeMemoryMetric _instance_1 = AverageFreeMemoryMetric.instance(); | ||
67 | ObjectiveThreshold.Inclusive _inclusive_1 = new ObjectiveThreshold.Inclusive(0.75); | ||
68 | QueryBasedObjective _queryBasedObjective_1 = new QueryBasedObjective(_instance_1, ObjectiveKind.LOWER_IS_BETTER, _inclusive_1, 0); | ||
69 | AverageFreeHddMetric _instance_2 = AverageFreeHddMetric.instance(); | ||
70 | ObjectiveThreshold.Inclusive _inclusive_2 = new ObjectiveThreshold.Inclusive(0.75); | ||
71 | QueryBasedObjective _queryBasedObjective_2 = new QueryBasedObjective(_instance_2, ObjectiveKind.LOWER_IS_BETTER, _inclusive_2, 0); | ||
72 | CompositeDirectionalThresholdObjective _compositeDirectionalThresholdObjective = new CompositeDirectionalThresholdObjective("Composite", _queryBasedObjective, _queryBasedObjective_1, _queryBasedObjective_2); | ||
73 | dse.addObjective(_compositeDirectionalThresholdObjective); | ||
74 | CostMetric _instance_3 = CostMetric.instance(); | ||
75 | QueryBasedObjective _queryBasedObjective_3 = new QueryBasedObjective(_instance_3, ObjectiveKind.LOWER_IS_BETTER, | ||
76 | ObjectiveThreshold.NO_THRESHOLD, 0); | ||
77 | dse.addObjective(_queryBasedObjective_3); | ||
78 | dse.setMaxNumberOfThreads(1); | ||
79 | CpsStateCoder.Factory _factory = new CpsStateCoder.Factory(); | ||
80 | dse.setStateCoderFactory(_factory); | ||
81 | final EvolutionaryStrategy strategy = EvolutionaryStrategyBuilder.createNsga2Strategy(25); | ||
82 | dse.startExplorationWithTimeout(strategy, ((2 * 60) * 1000)); | ||
83 | Collection<Solution> _solutions = dse.getSolutions(); | ||
84 | for (final Solution solution : _solutions) { | ||
85 | Object _stateCode = solution.getStateCode(); | ||
86 | String _plus = ("Found solution: " + _stateCode); | ||
87 | String _plus_1 = (_plus + " "); | ||
88 | Fitness _fitness = solution.getArbitraryTrajectory().getFitness(); | ||
89 | String _plus_2 = (_plus_1 + _fitness); | ||
90 | InputOutput.<String>println(_plus_2); | ||
91 | } | ||
92 | } | ||
93 | } | ||