优化器启用

parent f366bb13
......@@ -44,6 +44,8 @@ public class GlobalParam {
/// </summary>
private boolean isJit = false;
private boolean isOptimizer = true;
private boolean _smoothSetup = false; // 设置时间平滑 工序的前处理是否提前
private boolean _smoothChangeOver = true; // 默认true,设置时间 是否考虑换型时间
......@@ -220,6 +222,7 @@ public class GlobalParam {
target.IsCheckSf = this.IsCheckSf;
target.IsOverlap = this.IsOverlap;
target.isJit = this.isJit;
target.isOptimizer = this.isOptimizer;
target._smoothSetup = this._smoothSetup;
target._smoothChangeOver = this._smoothChangeOver;
target._smoothChangeOverInWeek = this._smoothChangeOverInWeek;
......@@ -230,6 +233,22 @@ public class GlobalParam {
return target;
}
public boolean isOptimizer() {
return isOptimizer;
}
public boolean getIsOptimizer() {
return isOptimizer;
}
public void setOptimizer(boolean optimizer) {
isOptimizer = optimizer;
}
public void setIsOptimizer(boolean optimizer) {
isOptimizer = optimizer;
}
private List<?> extractKpiList(Object rawConfig) {
if (rawConfig instanceof List) {
return (List<?>) rawConfig;
......
......@@ -101,7 +101,9 @@ public class HybridAlgorithm {
LocalDateTime starttime=LocalDateTime.now();
FileHelper.writeLogFile("排产-----------开始-----"+ (_GlobalParam.isJit()?"倒排":"正排")+"------"+allOperations.get(0).getSceneId());
FileHelper.writeLogFile("排产-----------开始-----" + (_GlobalParam.isJit() ? "倒排" : "正排")
+ "-----优化器" + (_GlobalParam.isOptimizer() ? "启用" : "关闭")
+ "------" + allOperations.get(0).getSceneId());
// 在整个流程开始时创建一个全局 shared decoder,所有阶段共享解码缓存
GeneticDecoder sharedDecoder = new GeneticDecoder(_GlobalParam, param.getBaseTime(), machines, orders, materials, machineScheduler, materialRequirementService, sceneId);
......@@ -121,8 +123,9 @@ public class HybridAlgorithm {
// 步骤1:使用构造启发式算法生成初始种群
FileHelper.writeLogFile("构造启发式初始化-----------开始-------");
// List<Chromosome> population = initialization.generateHeuristicInitialPopulation(param);
List<Chromosome> population = initialization.generateHybridInitialPopulation(param);
List<Chromosome> population = _GlobalParam.isOptimizer()
? initialization.generateHybridInitialPopulation(param)
: initialization.generateHeuristicInitialPopulation(param,param.getPopulationSize());
FileHelper.writeLogFile("构造启发式初始化-----------结束-------");
......
......@@ -216,7 +216,8 @@ public class UserStrategyRuleServiceImpl extends ServiceImpl<UserStrategyRuleMap
item.put("globalRuleId", rule.getId());
item.put("globalRuleName", rule.getName());
item.put("forwardScheduling", parseForwardScheduling(rule.getForwardScheduling()));
item.put("isjit", extractIsJit(rule.getForwardScheduling(), false));
item.put("isjit", toFrontendIsJit(extractIsJit(rule.getForwardScheduling(), false)));
item.put("isOptimizer", extractIsOptimizer(rule.getForwardScheduling(), true));
return item;
}
......@@ -231,7 +232,8 @@ public class UserStrategyRuleServiceImpl extends ServiceImpl<UserStrategyRuleMap
item.put("globalRuleId", globalRule.getId());
item.put("globalRuleName", globalRule.getName());
item.put("forwardScheduling", parseForwardScheduling(rule.getForwardScheduling()));
item.put("isjit", extractIsJit(rule.getForwardScheduling(), false));
item.put("isjit", toFrontendIsJit(extractIsJit(rule.getForwardScheduling(), false)));
item.put("isOptimizer", extractIsOptimizer(rule.getForwardScheduling(), true));
return item;
}
......@@ -335,7 +337,8 @@ public class UserStrategyRuleServiceImpl extends ServiceImpl<UserStrategyRuleMap
result.put("name", rule.getName());
result.put("forwardScheduling", parseForwardScheduling(rule.getForwardScheduling()));
result.put("kpiConfig", parseJson(rule.getKpiConfig()));
result.put("isjit", extractIsJit(rule.getForwardScheduling(), false));
result.put("isjit", toFrontendIsJit(extractIsJit(rule.getForwardScheduling(), false)));
result.put("isOptimizer", extractIsOptimizer(rule.getForwardScheduling(), true));
return result;
}
......@@ -349,7 +352,8 @@ public class UserStrategyRuleServiceImpl extends ServiceImpl<UserStrategyRuleMap
result.put("name", rule == null ? null : rule.getName());
result.put("forwardScheduling", rule == null ? new ArrayList<StrategyScheduling>() : parseForwardScheduling(rule.getForwardScheduling()));
result.put("kpiConfig", new ArrayList<>());
result.put("isjit", rule != null && extractIsJit(rule.getForwardScheduling(), false));
result.put("isjit", toFrontendIsJit(rule != null && extractIsJit(rule.getForwardScheduling(), false)));
result.put("isOptimizer", rule == null || extractIsOptimizer(rule.getForwardScheduling(), true));
return result;
}
......@@ -400,18 +404,24 @@ public class UserStrategyRuleServiceImpl extends ServiceImpl<UserStrategyRuleMap
Object forwardScheduling = params.get("forwardScheduling");
String defaultValue = globalRule == null ? null : globalRule.getForwardScheduling();
Object rawIsJit = firstValue(params, "isjit", "isJit", "jit");
Object rawIsOptimizer = firstValue(params, "isOptimizer");
Boolean isJit = rawIsJit == null ? extractIsJitObject(userRule.getForwardScheduling()) : asBoolean(rawIsJit, false);
Boolean isJit = rawIsJit == null ? extractIsJitObject(userRule.getForwardScheduling()) : !asBoolean(rawIsJit, true);
if (isJit == null) {
isJit = extractIsJitObject(defaultValue);
}
if (isJit == null) {
return toJson(forwardScheduling, defaultValue);
Boolean isOptimizer = rawIsOptimizer == null ? extractIsOptimizerObject(userRule.getForwardScheduling()) : asBoolean(rawIsOptimizer, true);
if (isOptimizer == null) {
isOptimizer = extractIsOptimizerObject(defaultValue);
}
if (isOptimizer == null) {
isOptimizer = true;
}
Map<String, Object> payload = new LinkedHashMap<>();
payload.put("forwardScheduling", forwardScheduling == null ? parseForwardScheduling(defaultValue) : forwardScheduling);
payload.put("isjit", isJit == null ? false : isJit);
payload.put("isOptimizer", isOptimizer);
return toJson(payload, defaultValue);
}
......@@ -447,6 +457,28 @@ public class UserStrategyRuleServiceImpl extends ServiceImpl<UserStrategyRuleMap
return value == null ? defaultValue : value;
}
private boolean toFrontendIsJit(boolean backendIsJit) {
return !backendIsJit;
}
private Boolean extractIsOptimizerObject(String json) {
if (!StringUtils.hasText(json)) {
return null;
}
try {
JsonNode root = objectMapper.readTree(json);
JsonNode value = firstJsonValue(root, "isOptimizer");
return value == null ? null : asBoolean(value.isValueNode() ? value.asText() : value.toString(), true);
} catch (Exception e) {
return null;
}
}
private boolean extractIsOptimizer(String json, boolean defaultValue) {
Boolean value = extractIsOptimizerObject(json);
return value == null ? defaultValue : value;
}
private JsonNode firstJsonValue(JsonNode root, String... keys) {
if (root == null || root.isNull()) {
return null;
......
......@@ -2409,6 +2409,7 @@ if(job.getGeneDetails()!=null)
Object kpiConfig = scheduleStrategyService.loadEffectiveKpiConfig(userId, baseRuleId, sceneId, userRuleId);
globalParam.applyKpiConfig(kpiConfig);
globalParam.setJit(scheduleStrategyService.loadEffectiveIsJit(userId, baseRuleId, sceneId, userRuleId));
globalParam.setIsOptimizer(scheduleStrategyService.loadEffectiveIsOptimizer(userId, baseRuleId, sceneId, userRuleId));
return globalParam;
}
......
......@@ -105,7 +105,7 @@ public class ScheduleStrategyService {
}
Map<String, Object> effectiveRule = userStrategyRuleService.getEffectiveRule(params);
return effectiveRule != null && asBoolean(effectiveRule.get("isjit"), false);
return effectiveRule != null && !asBoolean(effectiveRule.get("isjit"), true);
} catch (Exception e) {
log.warn("Load JIT strategy failed, use GlobalParam default isJit=false. sceneId={}, userId={}, baseRuleId={}, userRuleId={}",
sceneId, userId, baseRuleId, userRuleId, e);
......@@ -113,6 +113,29 @@ public class ScheduleStrategyService {
}
}
public boolean loadEffectiveIsOptimizer(Long userId, Long baseRuleId, String sceneId, String userRuleId) {
try {
Map<String, Object> params = new HashMap<>();
Long effectiveUserId = resolveScheduleUserId(sceneId, userId);
if (effectiveUserId != null) {
params.put("userId", effectiveUserId);
}
if (baseRuleId != null) {
params.put("baseRuleId", baseRuleId);
}
if (userRuleId != null && !userRuleId.trim().isEmpty()) {
params.put("userRuleId", userRuleId);
}
Map<String, Object> effectiveRule = userStrategyRuleService.getEffectiveRule(params);
return effectiveRule == null || asBoolean(effectiveRule.get("isOptimizer"), true);
} catch (Exception e) {
log.warn("Load optimizer strategy failed, use GlobalParam default isOptimizer=true. sceneId={}, userId={}, baseRuleId={}, userRuleId={}",
sceneId, userId, baseRuleId, userRuleId, e);
return true;
}
}
public OrderSortRule createMultiConditionRule(List<Order> orders) {
return createMultiConditionRule(orders, Collections.emptyList());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment