| | |
| | | |
| | | public final class AutoTuneRuleDefinition { |
| | | |
| | | private static final String DEFAULT_RULE_NOTE = "单次调整幅度不能超过 maxStep。"; |
| | | private static final String STATION_OUT_TASK_LIMIT_DYNAMIC_MAX_SOURCE = |
| | | "currentParameterSnapshot.stationOutBufferCapacities[targetId]"; |
| | | private static final String STATION_OUT_TASK_LIMIT_NOTE = |
| | | "单次调整幅度不能超过 maxStep;增大时不得超过对应站点 outBufferCapacity。"; |
| | | |
| | | private static final Map<String, Rule> RULE_MAP = buildRuleMap(); |
| | | |
| | | private AutoTuneRuleDefinition() { |
| | |
| | | |
| | | private static Map<String, Rule> buildRuleMap() { |
| | | LinkedHashMap<String, Rule> ruleMap = new LinkedHashMap<>(); |
| | | add(ruleMap, AutoTuneTargetType.SYS_CONFIG, "aiAutoTuneIntervalMinutes", 5, 60, 5, 30, false); |
| | | add(ruleMap, AutoTuneTargetType.SYS_CONFIG, "conveyorStationTaskLimit", 5, 200, 5, 20, false); |
| | | add(ruleMap, AutoTuneTargetType.SYS_CONFIG, "crnOutBatchRunningLimit", 1, 20, 3, 20, false); |
| | | add(ruleMap, AutoTuneTargetType.STATION, "outTaskLimit", 0, null, 3, 10, true); |
| | | add(ruleMap, AutoTuneTargetType.CRN, "maxOutTask", 0, 10, 3, 10, false); |
| | | add(ruleMap, AutoTuneTargetType.CRN, "maxInTask", 0, 10, 3, 10, false); |
| | | add(ruleMap, AutoTuneTargetType.DUAL_CRN, "maxOutTask", 0, 10, 3, 10, false); |
| | | add(ruleMap, AutoTuneTargetType.DUAL_CRN, "maxInTask", 0, 10, 3, 10, false); |
| | | add(ruleMap, rule(AutoTuneTargetType.SYS_CONFIG, "aiAutoTuneIntervalMinutes") |
| | | .minValue(5) |
| | | .maxValue(60) |
| | | .maxStep(5) |
| | | .cooldownMinutes(30)); |
| | | add(ruleMap, rule(AutoTuneTargetType.SYS_CONFIG, "conveyorStationTaskLimit") |
| | | .minValue(5) |
| | | .maxValue(200) |
| | | .maxStep(5) |
| | | .cooldownMinutes(20)); |
| | | add(ruleMap, rule(AutoTuneTargetType.SYS_CONFIG, "crnOutBatchRunningLimit") |
| | | .minValue(1) |
| | | .maxValue(20) |
| | | .maxStep(3) |
| | | .cooldownMinutes(20)); |
| | | add(ruleMap, rule(AutoTuneTargetType.STATION, "outTaskLimit") |
| | | .minValue(0) |
| | | .maxStep(3) |
| | | .cooldownMinutes(10) |
| | | .dynamicMaxSource(STATION_OUT_TASK_LIMIT_DYNAMIC_MAX_SOURCE) |
| | | .note(STATION_OUT_TASK_LIMIT_NOTE)); |
| | | add(ruleMap, rule(AutoTuneTargetType.CRN, "maxOutTask") |
| | | .minValue(0) |
| | | .maxValue(10) |
| | | .maxStep(3) |
| | | .cooldownMinutes(10)); |
| | | add(ruleMap, rule(AutoTuneTargetType.CRN, "maxInTask") |
| | | .minValue(0) |
| | | .maxValue(10) |
| | | .maxStep(3) |
| | | .cooldownMinutes(10)); |
| | | add(ruleMap, rule(AutoTuneTargetType.DUAL_CRN, "maxOutTask") |
| | | .minValue(0) |
| | | .maxValue(10) |
| | | .maxStep(3) |
| | | .cooldownMinutes(10)); |
| | | add(ruleMap, rule(AutoTuneTargetType.DUAL_CRN, "maxInTask") |
| | | .minValue(0) |
| | | .maxValue(10) |
| | | .maxStep(3) |
| | | .cooldownMinutes(10)); |
| | | |
| | | return Collections.unmodifiableMap(ruleMap); |
| | | } |
| | | |
| | | private static void add(LinkedHashMap<String, Rule> ruleMap, |
| | | AutoTuneTargetType targetType, |
| | | String targetKey, |
| | | Integer minValue, |
| | | Integer maxValue, |
| | | int maxStep, |
| | | int cooldownMinutes, |
| | | boolean dynamicMaxValue) { |
| | | Rule rule = new Rule(targetType, targetKey, minValue, maxValue, maxStep, cooldownMinutes, dynamicMaxValue); |
| | | ruleMap.put(buildKey(targetType.getCode(), targetKey), rule); |
| | | private static RuleSpec rule(AutoTuneTargetType targetType, String targetKey) { |
| | | return new RuleSpec(targetType, targetKey); |
| | | } |
| | | |
| | | private static void add(LinkedHashMap<String, Rule> ruleMap, RuleSpec ruleSpec) { |
| | | Rule rule = ruleSpec.toRule(); |
| | | ruleMap.put(buildKey(rule.getTargetType().getCode(), rule.getTargetKey()), rule); |
| | | } |
| | | |
| | | private static String buildKey(String targetType, String targetKey) { |
| | |
| | | private final int maxStep; |
| | | private final int cooldownMinutes; |
| | | private final boolean dynamicMaxValue; |
| | | private final String dynamicMaxSource; |
| | | private final String note; |
| | | |
| | | private Rule(AutoTuneTargetType targetType, |
| | | String targetKey, |
| | |
| | | Integer maxValue, |
| | | int maxStep, |
| | | int cooldownMinutes, |
| | | boolean dynamicMaxValue) { |
| | | boolean dynamicMaxValue, |
| | | String dynamicMaxSource, |
| | | String note) { |
| | | this.targetType = targetType; |
| | | this.targetKey = targetKey; |
| | | this.minValue = minValue; |
| | |
| | | this.maxStep = maxStep; |
| | | this.cooldownMinutes = cooldownMinutes; |
| | | this.dynamicMaxValue = dynamicMaxValue; |
| | | this.dynamicMaxSource = dynamicMaxSource; |
| | | this.note = note; |
| | | } |
| | | |
| | | public AutoTuneTargetType getTargetType() { |
| | |
| | | public boolean isDynamicMaxValue() { |
| | | return dynamicMaxValue; |
| | | } |
| | | |
| | | public String getDynamicMaxSource() { |
| | | return dynamicMaxSource; |
| | | } |
| | | |
| | | public String getNote() { |
| | | return note; |
| | | } |
| | | } |
| | | |
| | | private static final class RuleSpec { |
| | | private final AutoTuneTargetType targetType; |
| | | private final String targetKey; |
| | | private Integer minValue; |
| | | private Integer maxValue; |
| | | private int maxStep; |
| | | private int cooldownMinutes; |
| | | private String dynamicMaxSource; |
| | | private String note = DEFAULT_RULE_NOTE; |
| | | |
| | | private RuleSpec(AutoTuneTargetType targetType, String targetKey) { |
| | | this.targetType = targetType; |
| | | this.targetKey = targetKey; |
| | | } |
| | | |
| | | private RuleSpec minValue(Integer minValue) { |
| | | this.minValue = minValue; |
| | | return this; |
| | | } |
| | | |
| | | private RuleSpec maxValue(Integer maxValue) { |
| | | this.maxValue = maxValue; |
| | | return this; |
| | | } |
| | | |
| | | private RuleSpec maxStep(int maxStep) { |
| | | this.maxStep = maxStep; |
| | | return this; |
| | | } |
| | | |
| | | private RuleSpec cooldownMinutes(int cooldownMinutes) { |
| | | this.cooldownMinutes = cooldownMinutes; |
| | | return this; |
| | | } |
| | | |
| | | private RuleSpec dynamicMaxSource(String dynamicMaxSource) { |
| | | this.dynamicMaxSource = dynamicMaxSource; |
| | | return this; |
| | | } |
| | | |
| | | private RuleSpec note(String note) { |
| | | this.note = note; |
| | | return this; |
| | | } |
| | | |
| | | private Rule toRule() { |
| | | return new Rule( |
| | | targetType, |
| | | targetKey, |
| | | minValue, |
| | | maxValue, |
| | | maxStep, |
| | | cooldownMinutes, |
| | | dynamicMaxSource != null, |
| | | dynamicMaxSource, |
| | | note |
| | | ); |
| | | } |
| | | } |
| | | } |