diff options
author | 2019-05-15 13:46:38 -0400 | |
---|---|---|
committer | 2019-05-15 13:46:38 -0400 | |
commit | e904f9d4b1d2d15ab4ec6d72ee881f4c7de34eef (patch) | |
tree | 42cb23ff8839308345c0859cdf99469c930af03b /Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql | |
parent | Merge remote-tracking branch 'origin/master' into kris (diff) | |
download | VIATRA-Generator-e904f9d4b1d2d15ab4ec6d72ee881f4c7de34eef.tar.gz VIATRA-Generator-e904f9d4b1d2d15ab4ec6d72ee881f4c7de34eef.tar.zst VIATRA-Generator-e904f9d4b1d2d15ab4ec6d72ee881f4c7de34eef.zip |
Formalize CPS case study for optimization
Diffstat (limited to 'Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql')
-rw-r--r-- | Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql new file mode 100644 index 00000000..7f7cc5a4 --- /dev/null +++ b/Domains/hu.bme.mit.inf.dslreasoner.domains.cps/src/hu/bme/mit/inf/dslreasoner/domains/cps/queries/CpsQueries.vql | |||
@@ -0,0 +1,132 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.domains.cps.queries | ||
2 | |||
3 | import "http://www.eclipse.org/emf/2002/Ecore" | ||
4 | import "http://www.example.org/cps" | ||
5 | |||
6 | @QueryBasedFeature(feature = "applications") | ||
7 | pattern cpsApplications(Cps : CyberPhysicalSystem, AppInstance : ApplicationInstance) { | ||
8 | CyberPhysicalSystem.applicationTypes.instances(Cps, AppInstance); | ||
9 | } | ||
10 | |||
11 | @QueryBasedFeature(feature = "hosts") | ||
12 | pattern cpsHosts(Cps : CyberPhysicalSystem, HostInstance : HostInstance) { | ||
13 | CyberPhysicalSystem.hostTypes.instances(Cps, HostInstance); | ||
14 | } | ||
15 | |||
16 | @QueryBasedFeature(feature = "totalMemory") | ||
17 | pattern totalMemory(Host : HostInstance, Memory : EInt) { | ||
18 | HostInstance.type.defaultMemory(Host, Memory); | ||
19 | } | ||
20 | |||
21 | @QueryBasedFeature(feature = "totalHdd") | ||
22 | pattern totalHdd(Host : HostInstance, Hdd : EInt) { | ||
23 | HostInstance.type.defaultHdd(Host, Hdd); | ||
24 | } | ||
25 | |||
26 | @QueryBasedFeature(feature = "availableMemory") | ||
27 | pattern availableMemory(Host : HostInstance, Memory : java Integer) { | ||
28 | find totalMemory(Host, TotalMemory); | ||
29 | RequiredMemory == sum find memoryRequirement(Host, _, #_); | ||
30 | Memory == eval(TotalMemory - RequiredMemory); | ||
31 | } | ||
32 | |||
33 | private pattern memoryRequirement(Host : HostInstance, App : ApplicationInstance, Memory : EInt) { | ||
34 | find resourceRequirement(Host, App, Req); | ||
35 | ResourceRequirement.requiredMemory(Req, Memory); | ||
36 | } | ||
37 | |||
38 | @QueryBasedFeature(feature = "availableHdd") | ||
39 | pattern availableHdd(Host : HostInstance, Hdd : java Integer) { | ||
40 | find totalHdd(Host, TotalHdd); | ||
41 | RequiredHdd == sum find hddRequirement(Host, _, #_); | ||
42 | Hdd == eval(TotalHdd - RequiredHdd); | ||
43 | } | ||
44 | |||
45 | private pattern hddRequirement(Host : HostInstance, App : ApplicationInstance, Hdd : EInt) { | ||
46 | find resourceRequirement(Host, App, Req); | ||
47 | ResourceRequirement.requiredHdd(Req, Hdd); | ||
48 | } | ||
49 | |||
50 | private pattern resourceRequirement(Host : HostInstance, App : ApplicationInstance, Req : ResourceRequirement) { | ||
51 | ApplicationInstance.allocatedTo(App, Host); | ||
52 | ApplicationInstance.type.requirements(App, Req); | ||
53 | HostInstance.type(Host, HostType); | ||
54 | ResourceRequirement.hostType(Req, HostType); | ||
55 | } | ||
56 | |||
57 | @Constraint(severity = "error", key = {Host, App}, | ||
58 | message = "Application instance must be allocated to a supported host type.") | ||
59 | pattern allocationWithoutResourceRequirement(Host : HostInstance, App : ApplicationInstance) { | ||
60 | ApplicationInstance.allocatedTo(App, Host); | ||
61 | neg find resourceRequirement(Host, App, _); | ||
62 | } | ||
63 | |||
64 | @Constraint(severity = "error", key = {Host}, | ||
65 | message = "Insufficient memory available on host.") | ||
66 | pattern notEnoughAvailableMemory(Host : HostInstance) { | ||
67 | find availableMemory(Host, Memory); | ||
68 | check(Memory < 0); | ||
69 | } | ||
70 | |||
71 | @Constraint(severity = "error", key = {Host}, | ||
72 | message = "Insufficient HDD available on host.") | ||
73 | pattern notEnoughAvailableHdd(Host : HostInstance) { | ||
74 | find availableHdd(Host, Hdd); | ||
75 | check(Hdd < 0); | ||
76 | } | ||
77 | |||
78 | @Constraint(severity = "error", key = {Req, App}, | ||
79 | message = "Requirement must be satisfied by the required application type.") | ||
80 | pattern instanceDoesNotSatisfyRequirement(Req : Requirement, App : ApplicationInstance) { | ||
81 | Requirement.instances(Req, App); | ||
82 | neg find satisfyingInstance(Req, App); | ||
83 | } | ||
84 | |||
85 | private pattern satisfyingInstance(Req : Requirement, App : ApplicationInstance) { | ||
86 | Requirement.instances(Req, App); | ||
87 | Requirement.type(Req, Type); | ||
88 | ApplicationInstance.type(App, Type); | ||
89 | } | ||
90 | |||
91 | @Constraint(severity = "error", key = {Req}, | ||
92 | message = "Requirement is not satisfied by enough application instances.") | ||
93 | pattern requirementNotSatisfied(Req : Requirement) { | ||
94 | Instances == count find satisfyingInstance(Req, _); | ||
95 | Requirement.count(Req, RequiredCount); | ||
96 | check(Instances < RequiredCount); | ||
97 | } | ||
98 | |||
99 | pattern averageFreeMemoryMetric(Average : java Double) { | ||
100 | Average == avg find freeMemoryPercentage(_, #_); | ||
101 | } | ||
102 | |||
103 | private pattern freeMemoryPercentage(Host : HostInstance, Free : java Double) { | ||
104 | find totalMemory(Host, Total); | ||
105 | find availableMemory(Host, Available); | ||
106 | Free == eval((Available as double) / Total); | ||
107 | } | ||
108 | |||
109 | pattern averageFreeHddMetric(Average : java Double) { | ||
110 | Average == avg find freeHddPercentage(_, #_); | ||
111 | } | ||
112 | |||
113 | private pattern freeHddPercentage(Host : HostInstance, Free : java Double) { | ||
114 | find totalHdd(Host, Total); | ||
115 | find availableHdd(Host, Available); | ||
116 | Free == eval((Available as double) / Total); | ||
117 | } | ||
118 | |||
119 | pattern costMetric(Cost : java Integer) { | ||
120 | Cost == sum find cpsCost(_, #_); | ||
121 | } | ||
122 | |||
123 | pattern cpsCost(Cps : CyberPhysicalSystem, Cost : java Integer) { | ||
124 | AppCount == count find cpsApplications(Cps, _); | ||
125 | HostCost == sum find hostInstanceCost(Cps, _, #_); | ||
126 | Cost == eval(5 * AppCount + HostCost); | ||
127 | } | ||
128 | |||
129 | private pattern hostInstanceCost(Cps : CyberPhysicalSystem, Host : HostInstance, Cost : EInt) { | ||
130 | find cpsHosts(Cps, Host); | ||
131 | HostInstance.type.cost(Host, Cost); | ||
132 | } | ||