模块 7:分析与权衡
如何组织定量分析、定义目标函数与计算,并运用权衡研究模式比较设计备选方案 — 全部都在 SysML v2 的形式化分析框架之内完成。
KerML → SysML:分析概念
SysML v2 的分析建模建立在 KerML 的函数(Function)与用例(Case)抽象之上。本模块中的每个分析关键字,都映射到一个为其提供形式化语义的 KerML 构造。
| SysML v2 概念(L2) | 底层 KerML 构造(L1) | SysML 增加了什么 |
|---|---|---|
calc def | Function(一种返回值的 Behavior) | 具名、可复用的数学表达式,带类型化参数与返回类型 |
calc(使用) | 由 Function 定型的 Expression | 在具体上下文中对函数求值,把实参绑定到参数上 |
analysis def | CaseDefinition(特化自 CalculationDefinition) | 用主题、目标与返回值组织一次完整的分析 |
analysis(使用) | CaseUsage | 把该分析施加到某个具体设计上下文的一个实例 |
objective | 作用域限定在该用例内的 RequirementUsage | 定义该分析必须满足或评估的成功判据 |
subject | SubjectMembership(一个参数) | 标识正在被分析的是哪个系统元素 |
return | ReturnParameterMembership | 该分析或计算得到的结果值 |
require constraint | RequirementConstraintMembership | 为达成目标而必须成立的布尔约束 |
在 KerML 中,Function 是一种会计算并返回值的 Behavior — 它在 Behavior 基础上特化出一个 result 参数。CaseDefinition 又进一步特化自 CalculationDefinition(后者本身特化自 Function),并补充了主题与目标这两个结构化概念。也就是说,在 KerML 层面上,每个分析用例都是一个返回值的函数。
分析用例详解
KerML 起源:analysis def → CaseDefinition(特化自 CalculationDefinition)
分析用例是 SysML v2 为各类定量评估提供的结构化容器。它把主题(被分析的元素)、目标(成功判据)和返回值(计算结果)打包成一个可复用的定义。与一堆松散的约束不同,分析用例是一等模型元素,可以被实例化、被特化,也可以追溯到需求。
可以把它想成一份实验报告:写明测的是什么(主题)、什么算成功(目标)、实验步骤(主体),并记录结果(返回值)。分析用例就是它在建模中的对应物 — 一个自洽、可重复的实验定义。
基本结构
1 analysis def MassAnalysis {
2 subject vehicle : Vehicle; // what we are analysing
3
4 objective massObjective {
5 doc /* Total mass shall not exceed 2000 kg */
6 require constraint { vehicle.totalMass <= 2000 [kg] }
7 }
8
9 return totalMass : ISQ::MassValue = vehicle.totalMass;
10 }
主题与范围
subject 关键字声明被研究的元素。在 KerML 层面它是一个带方向的 in 参数 — 分析用例从它被使用的上下文中接收主题。主题可以是任意零件、连接或条目定义:
1 analysis def ThermalAnalysis {
2 subject heatExchanger : HeatExchanger; // scoped to one component
3 // ... objective, calculations, return
4 }
5
6 // Instantiation: apply analysis to a specific design element
7 analysis thermalCheck : ThermalAnalysis {
8 subject heatExchanger = mainRadiator; // binds to a specific part
9 }
返回值
每个分析用例都可以声明一个 return 参数 — 即分析计算得到的输出。由于 CaseDefinition 特化自 CalculationDefinition(后者又特化自 Function),每个分析用例本质上都是一个返回值的函数:
1 analysis def PowerBudgetAnalysis {
2 subject sys : ElectricalSystem;
3 objective { require constraint { sys.totalDraw <= sys.capacity } }
4 return margin : ISQ::PowerValue = sys.capacity - sys.totalDraw;
5 }
返回值不只是文档 — 它是一个带类型的 Feature,可以被下游引用。其他分析用例、需求或权衡研究都可以读取某个已完成分析用例的返回值,用于进一步决策。
目标函数
KerML 起源:objective → 作用域限定在 CaseDefinition 内的 RequirementUsage
目标是分析用例的核心 — 它陈述分析要成功必须满足什么。在 KerML 层面,目标是该用例拥有的一个 RequirementUsage,因此它具备需求的全套机制:约束、文档与可追溯性。
简单的约束型目标
最常见的写法是用 require constraint 给出一个布尔条件:
1 analysis def VibrationAnalysis {
2 subject structure : AircraftWing;
3 objective vibrationLimit {
4 doc /* First natural frequency must exceed 25 Hz */
5 require constraint {
6 structure.firstNaturalFrequency >= 25 [Hz]
7 }
8 }
9 return fn1 : ISQ::FrequencyValue = structure.firstNaturalFrequency;
10 }
复合目标
目标中可以包含多个 require constraint 块。只有全部约束同时成立,目标才算被满足:
1 objective performanceGoals {
2 doc /* The sensor must meet all three criteria */
3 require constraint { sensor.range >= 200 [m] }
4 require constraint { sensor.accuracy <= 0.05 [m] }
5 require constraint { sensor.updateRate >= 20 [Hz] }
6 }
效能度量
在权衡研究中,目标常常会定义效能度量(MOE) — 用来把各备选方案放在同一尺度上比较的量化指标。它们通常是被目标引用的计算:
1 objective sensorEffectiveness {
2 doc /* Maximise the composite effectiveness score */
3 require constraint {
4 computeEffectiveness(sensor) >= 0.7 // minimum threshold
5 }
6 }
目标应保持声明式 — 只陈述什么必须成立,而不写如何计算。把计算步骤交给 calc def(见第 3 节)。这种分离让目标保持可读,也让同一个计算能在多个分析用例中复用。
计算定义
KerML 起源:calc def → Function(一种返回值的 Behavior)
计算定义(calc def)定义一个可复用的数学关系。它是 SysML v2 用来表达公式、单位换算、评分函数以及任何可计算表达式的机制。在 KerML 层面,calc def 映射到 Function,即在 Behavior 上特化出 result 参数的构造。
基本的计算定义
1 calc def KineticEnergy {
2 in mass : ISQ::MassValue;
3 in velocity : ISQ::SpeedValue;
4 return energy : ISQ::EnergyValue = 0.5 * mass * velocity ** 2;
5 }
使用计算
calc 使用把实参绑定到已声明的参数上,从而在具体上下文中对 calc def 求值:
1 part def Projectile {
2 attribute mass : ISQ::MassValue;
3 attribute speed : ISQ::SpeedValue;
4 attribute ke : ISQ::EnergyValue = KineticEnergy(mass, speed);
5 }
带 ISQ 单位的计算
SysML v2 集成了国际量制(ISQ)库,提供基于 SI 的单位类型。计算会自然地把单位带入表达式,从而支持量纲一致性检查:
1 calc def ThermalResistance {
2 in thickness : ISQ::LengthValue;
3 in conductivity : ISQ::ThermalConductivityValue;
4 in area : ISQ::AreaValue;
5 return resistance : ISQ::ThermalResistanceValue
6 = thickness / (conductivity * area);
7 }
组合计算
计算定义可以调用其他计算,用简单而经过检验的部件搭建出复杂表达式:
1 calc def WeightedScore {
2 in rawScore : Real;
3 in weight : Real;
4 return : Real = rawScore * weight;
5 }
6
7 calc def CompositeScore {
8 in scores : Real[*]; // array of raw scores
9 in weights : Real[*]; // corresponding weights
10 return : Real = sum(WeightedScore(scores, weights));
11 }
calc def 不是命令式函数。它是一个声明式的数学关系 — 表达式定义的是结果等于什么,而不是求值的步骤序列。SysML v2 工具可以按分析场景选择及早求值、惰性求值或符号求值。
权衡研究模式
综合运用:analysis def、calc def、objective 与变体点
权衡研究用一组共同的评估准则比较多个设计备选方案,并选出最优者。SysML v2 用分析用例、计算定义和变体点为此提供了结构化模式。该模式分四步:定义备选方案、定义评估准则、为每个方案打分、选出优胜者。
第 1 步:定义备选方案
每个备选方案都建模为主题类型的一个独立使用或变体:
1 part def Sensor {
2 attribute range : ISQ::LengthValue;
3 attribute accuracy : ISQ::LengthValue;
4 attribute updateRate : ISQ::FrequencyValue;
5 attribute unitCost : Real; // in USD
6 attribute mass : ISQ::MassValue;
7 attribute powerDraw : ISQ::PowerValue;
8 }
9
10 part radarSensor : Sensor {
11 attribute :>> range = 250 [m];
12 attribute :>> accuracy = 0.10 [m];
13 attribute :>> updateRate = 15 [Hz];
14 attribute :>> unitCost = 1200;
15 attribute :>> mass = 0.8 [kg];
16 attribute :>> powerDraw = 12 [W];
17 }
18
19 part lidarSensor : Sensor {
20 attribute :>> range = 150 [m];
21 attribute :>> accuracy = 0.02 [m];
22 attribute :>> updateRate = 10 [Hz];
23 attribute :>> unitCost = 4500;
24 attribute :>> mass = 1.2 [kg];
25 attribute :>> powerDraw = 18 [W];
26 }
27
28 part cameraSensor : Sensor {
29 attribute :>> range = 100 [m];
30 attribute :>> accuracy = 0.15 [m];
31 attribute :>> updateRate = 30 [Hz];
32 attribute :>> unitCost = 350;
33 attribute :>> mass = 0.3 [kg];
34 attribute :>> powerDraw = 5 [W];
35 }
第 2 步:定义评估准则
每条准则都是一个 calc def,把原始属性归一化到 0–1 区间,从而让不同物理量之间也能公平比较:
1 calc def NormaliseRange {
2 in range : ISQ::LengthValue;
3 return : Real = range / 300 [m]; // max expected range
4 }
5
6 calc def NormaliseAccuracy {
7 in accuracy : ISQ::LengthValue;
8 return : Real = 1.0 - (accuracy / 0.20 [m]); // lower is better
9 }
10
11 calc def NormaliseCost {
12 in cost : Real;
13 return : Real = 1.0 - (cost / 5000); // lower cost is better
14 }
第 3 步:建立评分模型
一个综合评分计算为每条归一化准则赋予权重:
1 calc def SensorScore {
2 in sensor : Sensor;
3 return : Real =
4 0.30 * NormaliseRange(sensor.range) +
5 0.25 * NormaliseAccuracy(sensor.accuracy) +
6 0.20 * NormaliseCost(sensor.unitCost) +
7 0.15 * (sensor.updateRate / 30 [Hz]) +
8 0.10 * (1.0 - sensor.mass / 2.0 [kg]);
9 }
这些权重(0.30、0.25、0.20、0.15、0.10)反映利益相关方的优先级,总和必须为 1.0。调整权重即可做敏感性分析 — 观察优先级变化时各方案排名如何移动。
评估与结果
综合运用:analysis 使用、结果比较与决策记录
备选方案与评分模型就位后,最后一步是评估每个方案、比较得分并记录决策。做法是为每个方案实例化一次分析用例。
评估每个备选方案
1 analysis def SensorTradeStudy {
2 subject sensor : Sensor;
3 objective { require constraint { SensorScore(sensor) >= 0.5 } }
4 return score : Real = SensorScore(sensor);
5 }
6
7 // Instantiate for each alternative
8 analysis radarEval : SensorTradeStudy { subject sensor = radarSensor; }
9 analysis lidarEval : SensorTradeStudy { subject sensor = lidarSensor; }
10 analysis cameraEval : SensorTradeStudy { subject sensor = cameraSensor; }
比较结果
各项得分可以列成决策矩阵。按第 4 节定义的评分模型,计算结果如下:
| 备选方案 | 探测距离(0.30) | 精度(0.25) | 成本(0.20) | 刷新率(0.15) | 质量(0.10) | 总分 |
|---|---|---|---|---|---|---|
| 毫米波雷达 | 0.250 | 0.125 | 0.152 | 0.075 | 0.060 | 0.662 |
| 激光雷达 | 0.150 | 0.225 | 0.020 | 0.050 | 0.040 | 0.485 |
| 摄像头 | 0.100 | 0.063 | 0.186 | 0.150 | 0.085 | 0.584 |
在这组权重下,毫米波雷达得分最高(0.662),其次是摄像头(0.584)和激光雷达(0.485)。激光雷达未达到目标中设定的 0.5 最低门槛。
记录决策
分析用例的返回值与目标满足情况会成为模型的永久记录。这样的可追溯性让日后的评审者能够理解某个设计选择为什么被作出,以及它建立在哪些假设(权重、归一化函数)之上:
1 // Decision record: select radar as primary perception sensor
2 part autonomousVehicle : Vehicle {
3 part primarySensor : Sensor = radarSensor;
4 // Justified by: radarEval.score = 0.662 (highest)
5 // Rationale: best balance of range, cost, and mass
6 }
通过调整权重来做敏感性分析。如果权重的小幅变动就使排名大幅改变,说明该决策比较脆弱,可能需要补充准则或数据来加强。SysML v2 让这件事很容易:用不同权重组合新建若干分析用例使用,再比较各自的返回值。
完整示例
下面的模型把本模块的全部概念整合成一次完整的传感器选型权衡研究,面向自动驾驶车辆的感知系统。它定义了备选方案、计算、带目标的分析用例,并对各方案进行评估。
1 package SensorTradeStudyPackage {
2 private import ISQ::*;
3 private import SI::*;
4 private import ScalarValues::*;
5
6 // ── Sensor definition ────────────────────────────────────
7 part def Sensor {
8 attribute range : ISQ::LengthValue;
9 attribute accuracy : ISQ::LengthValue;
10 attribute updateRate : ISQ::FrequencyValue;
11 attribute unitCost : Real;
12 attribute mass : ISQ::MassValue;
13 attribute powerDraw : ISQ::PowerValue;
14 }
15
16 // ── Alternatives ─────────────────────────────────────────
17 part radarSensor : Sensor {
18 attribute :>> range = 250 [m];
19 attribute :>> accuracy = 0.10 [m];
20 attribute :>> updateRate = 15 [Hz];
21 attribute :>> unitCost = 1200;
22 attribute :>> mass = 0.8 [kg];
23 attribute :>> powerDraw = 12 [W];
24 }
25
26 part lidarSensor : Sensor {
27 attribute :>> range = 150 [m];
28 attribute :>> accuracy = 0.02 [m];
29 attribute :>> updateRate = 10 [Hz];
30 attribute :>> unitCost = 4500;
31 attribute :>> mass = 1.2 [kg];
32 attribute :>> powerDraw = 18 [W];
33 }
34
35 part cameraSensor : Sensor {
36 attribute :>> range = 100 [m];
37 attribute :>> accuracy = 0.15 [m];
38 attribute :>> updateRate = 30 [Hz];
39 attribute :>> unitCost = 350;
40 attribute :>> mass = 0.3 [kg];
41 attribute :>> powerDraw = 5 [W];
42 }
43
44 // ── Normalisation calculations ────────────────────────────
45 calc def NormRange {
46 in r : ISQ::LengthValue;
47 return : Real = r / 300 [m];
48 }
49
50 calc def NormAccuracy {
51 in a : ISQ::LengthValue;
52 return : Real = 1.0 - (a / 0.20 [m]);
53 }
54
55 calc def NormCost {
56 in c : Real;
57 return : Real = 1.0 - (c / 5000);
58 }
59
60 calc def NormRate {
61 in f : ISQ::FrequencyValue;
62 return : Real = f / 30 [Hz];
63 }
64
65 calc def NormMass {
66 in m : ISQ::MassValue;
67 return : Real = 1.0 - (m / 2.0 [kg]);
68 }
69
70 // ── Composite scoring calculation ────────────────────────
71 calc def SensorScore {
72 in sensor : Sensor;
73 return : Real =
74 0.30 * NormRange(sensor.range) +
75 0.25 * NormAccuracy(sensor.accuracy) +
76 0.20 * NormCost(sensor.unitCost) +
77 0.15 * NormRate(sensor.updateRate) +
78 0.10 * NormMass(sensor.mass);
79 }
80
81 // ── Analysis case definition ─────────────────────────────
82 analysis def SensorTradeStudy {
83 subject sensor : Sensor;
84
85 objective suitability {
86 doc /* Sensor must achieve a minimum composite score */
87 require constraint { SensorScore(sensor) >= 0.5 }
88 }
89
90 return score : Real = SensorScore(sensor);
91 }
92
93 // ── Evaluate each alternative ─────────────────────────────
94 analysis radarEval : SensorTradeStudy {
95 subject sensor = radarSensor; // score = 0.662
96 }
97
98 analysis lidarEval : SensorTradeStudy {
99 subject sensor = lidarSensor; // score = 0.485 (fails objective)
100 }
101
102 analysis cameraEval : SensorTradeStudy {
103 subject sensor = cameraSensor; // score = 0.584
104 }
105
106 // ── Decision: apply best alternative ──────────────────────
107 part def AutonomousVehicle {
108 part perceptionSuite {
109 // Selected: radar (highest score, meets objective)
110 part primarySensor : Sensor = radarSensor;
111 // Complementary: camera (second highest, low cost)
112 part secondarySensor : Sensor = cameraSensor;
113 }
114 }
115 }
该模型演示了:用 calc def 编写归一化与评分函数、带主题和目标的 analysis def、用 require constraint 设定最低门槛、为每个备选方案实例化分析用例,以及把最终设计决策追溯回权衡研究结果。
在真实项目中,你还应为这次权衡研究补充敏感性分析(调整权重)、追加约束(功耗预算、集成复杂度),并链接到验证用例,以确认所选传感器满足模块 5 中的系统级需求。
模块总结
| SysML v2 概念 | KerML 起源 | 关键规则 |
|---|---|---|
calc def | Function(特化自 Behavior) | 声明式的数学关系,带类型化参数与返回值 |
calc(使用) | 由 Function 定型的 Expression | 在上下文中对 calc def 求值;把实参绑定到参数 |
analysis def | CaseDefinition | 带主题、目标与返回值的结构化容器 |
analysis(使用) | CaseUsage | 施加于某个具体设计元素的分析实例 |
objective | RequirementUsage | 作用域限定在该分析用例内的成功判据;承载约束 |
subject | SubjectMembership | 标识被分析的元素;充当输入参数 |
return | ReturnParameterMembership | 计算得到的结果值;可被下游元素引用 |
require constraint | RequirementConstraintMembership | 为满足目标而必须成立的布尔条件 |
| 权衡研究模式 | 以上构造的组合 | 定义备选方案、归一化准则、加权评分、比较、决策 |