image.domain\self_evolve\strategy_combo.mbt
85.3% · 29 / 34 points · 136 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// # 策略组合 self_evolve/strategy_combo - 3
/// - 4
/// 图像处理库子模块 - 5
/// 图像处理库子模块 Image processing library submodule - 6
// 演化策略组合 — 组合多种演化策略 - 7
// Evolution strategy combination: combine multiple evolution strategies - 8
// - 9
// Phase 10 v307: 将演化从"自主决策"推向"策略组合" — 多策略协同演化。 - 10
- 11
///| - 12
/// 策略类型。 - 13
/// 描述 Strategy kind. - 14
/// `#non_exhaustive` 表示未来可能添加新构造器 - 15
#derive(Eq, @debug.Debug) - 16
#non_exhaustive - 17
pub(all) enum StrategyKind { - 18
FixFirst - 19
TestFirst - 20
OptimizeFirst - 21
ParallelFix - 22
SequentialFix - 23
} - 24
- 25
///| - 26
pub extend StrategyKind with @debug.Debug::{to_repr} - 27
- 28
///| - 29
pub extend StrategyKind with Eq::{not_equal, equal} - 30
- 31
///| - 32
/// 策略组合。 - 33
/// 描述 Strategy combination. - 34
#derive(Eq, @debug.Debug) - 35
pub(all) struct StrategyCombo { - 36
strategies : Array[StrategyKind] - 37
op_tag : String - 38
estimated_time : Int32 - 39
description : String - 40
} - 41
- 42
///| - 43
pub extend StrategyCombo with @debug.Debug::{to_repr} - 44
- 45
///| - 46
pub extend StrategyCombo with Eq::{not_equal, equal} - 47
- 48
///| - 49
/// 策略组合报告。 - 50
/// 描述 Strategy combination report. - 51
#derive(Eq, @debug.Debug) - 52
pub(all) struct ComboReport { - 53
combos : Array[StrategyCombo] - 54
total : Int32 - 55
parallel_count : Int32 - 56
summary : String - 57
} - 58
- 59
///| - 60
pub extend ComboReport with @debug.Debug::{to_repr} - 61
- 62
///| - 63
pub extend ComboReport with Eq::{not_equal, equal} - 64
- 65
///| - 66
/// 为单个算子组合演化策略。 - 67
/// 合并 Combine evolution strategies for a single op. - 68
pub fn combine_strategies(op : @imgir.IROp) -> StrategyCombo { - 69●
let tag = op.tag() - 70●
let degs = detect_degradation(op) - 71
let strategies : Array[StrategyKind] = [] - 72
let mut est_time = 0 - 73●
if degs.length() > 0 { - 74●
strategies.push(FixFirst) - 75
est_time = est_time + 10 - 76●
if degs.length() > 1 { - 77○
strategies.push(ParallelFix) - 78
est_time = est_time + 5 - 79
} else { - 80●
strategies.push(SequentialFix) - 81
est_time = est_time + 3 - 82
} - 83
} - 84●
let cov = coverage_percentage(op) - 85
if cov < 80 { - 86●
strategies.push(TestFirst) - 87
est_time = est_time + 8 - 88
} - 89●
let score = score_op(op) - 90
if score.score > 50 { - 91○
strategies.push(OptimizeFirst) - 92
est_time = est_time + 6 - 93
} - 94●
if strategies.length() == 0 { - 95●
strategies.push(OptimizeFirst) - 96
est_time = 2 - 97
} - 98
let desc = tag + - 99
": " + - 100●
strategies.length().to_string() + - 101
" 策略, 预计 " + - 102●
est_time.to_string() + - 103
" 单位时间" - 104
{ strategies, op_tag: tag, estimated_time: est_time, description: desc, } - 105
} - 106
- 107
///| - 108
/// 为所有算子组合演化策略。 - 109
/// 合并 Combine evolution strategies for all ops. - 110
pub fn combine_all_strategies() -> ComboReport { - 111●
let combos : Array[StrategyCombo] = [] - 112
let mut parallel_count = 0 - 113●
for op in all_ops() { - 114●
let combo = combine_strategies(op) - 115
for s in combo.strategies { - 116●
if s is ParallelFix { - 117○
parallel_count = parallel_count + 1 - 118
} - 119
} - 120●
combos.push(combo) - 121
} - 122●
let total = combos.length() - 123
let summary = "策略组合: " + - 124●
total.to_string() + - 125
" 算子, " + - 126●
parallel_count.to_string() + - 127
" 可并行" - 128
{ combos, total, parallel_count, summary, } - 129
} - 130
- 131
///| - 132
/// 策略组合报告是否有可并行策略。 - 133
/// 描述 Whether combo report has parallel strategies. - 134
pub fn ComboReport::has_parallel(self : ComboReport) -> Bool { - 135●
self.parallel_count > 0 - 136
}