image.domain\self_evolve\strategy_combo.mbt

85.3% · 29 / 34 points · 136 lines

Background color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.

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