-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsolver-demo.sysml
More file actions
188 lines (149 loc) · 5 KB
/
Copy pathsolver-demo.sysml
File metadata and controls
188 lines (149 loc) · 5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// A rover's power, mass and configuration budget, written so that each solver
// command has something to answer: see SOLVER-DEMO.md for the walkthrough.
package SolverDemo {
private import ScalarValues::*;
public import SI::*;
public import ISQ::*;
private import TradeStudies::*;
doc /* Power is in watts, mass in kilograms. */
enum def Radio {
enum lowGain;
enum highGain;
}
// Conditions a solver can satisfy: `%check` answers sat and `%solve` fills in
// the powers, keeping the capacity the model already states.
part def Rover {
attribute batteryCapacity : Integer = 1500;
attribute drivePower : Integer;
attribute sciencePower : Integer;
attribute radio : Radio;
assert constraint powerFitsBudget {
drivePower + sciencePower <= 220
}
assert constraint driveIsUseful {
drivePower >= 60
}
assert constraint scienceIsUseful {
sciencePower >= 40
}
assert constraint highGainCostsPower {
radio == Radio::highGain implies sciencePower >= 120
}
}
// A requirement states several conditions at once, so one query is about all
// of them: `%check` and `%solve` answer for the budget as a whole.
requirement def PowerBudgetRequirement {
subject rover : Rover;
require constraint {
rover.drivePower + rover.sciencePower <= 220
}
require constraint {
rover.drivePower >= 60
}
require constraint {
rover.sciencePower >= 40
}
}
// Conditions that cannot hold together: `%check` answers unsat and `%explain`
// names the three of them that conflict.
requirement def OverbookedBudget {
subject rover : Rover;
require constraint {
rover.drivePower + rover.sciencePower <= 200
}
require constraint {
rover.drivePower >= 150
}
require constraint {
rover.sciencePower >= 90
}
}
// A satisfaction assertion is a query too: `%check` asks whether the object
// can satisfy the requirement asserted of it.
part rover1 : Rover {
attribute :>> drivePower = 90;
attribute :>> sciencePower = 100;
attribute :>> radio = Radio::lowGain;
assert satisfy requirement powerIsBudgeted : PowerBudgetRequirement;
}
attribute def Chassis;
attribute def Antenna;
part def RoverPlatform {
attribute chassis : Chassis;
attribute antenna : Antenna;
}
// Two variation points whose choices interact, so `%configure … all` reports
// three consistent selections of the four combinations.
part roverFamily : RoverPlatform {
variation attribute :>> chassis {
variant attribute light;
variant attribute rugged;
}
variation attribute :>> antenna {
variant attribute fixed;
variant attribute steerable;
}
assert constraint steerableNeedsRugged {
antenna == antenna::steerable implies chassis == chassis::rugged
}
}
// An objective `%optimize` improves within the conditions the case requires.
analysis def PowerBudget {
attribute drivePower : Integer;
attribute sciencePower : Integer;
assert constraint {
drivePower + sciencePower <= 220
}
assert constraint {
drivePower >= 60
}
assert constraint {
sciencePower >= 40
}
objective mostScience : MaximizeObjective {
subject :>> selectedAlternative;
in calc :>> eval { sciencePower }
}
}
// A quantity-valued objective, whose optimum is reported in the unit the
// conditions are written in.
analysis def MassBudget {
attribute mass : ISQ::MassValue;
assert constraint {
mass >= 780 [kg]
}
assert constraint {
mass <= 950 [kg]
}
objective lightest : MinimizeObjective {
subject :>> selectedAlternative;
in calc :>> eval { mass }
}
}
// Two objectives, improved lexicographically in the order declared: the least
// mass first, and among the platforms achieving it the most science power.
analysis def MassThenScience {
attribute mass : Integer;
attribute sciencePower : Integer;
assert constraint {
mass >= 780
}
assert constraint {
mass <= 950
}
assert constraint {
sciencePower >= 40
}
assert constraint {
sciencePower <= mass / 4
}
objective lightest : MinimizeObjective {
subject :>> selectedAlternative;
in calc :>> eval { mass }
}
objective mostScience : MaximizeObjective {
subject :>> selectedAlternative;
in calc :>> eval { sciencePower }
}
}
}