Commit 25c58c5b authored by Tong Li's avatar Tong Li

算法优化

parent 9d08cc4f
...@@ -465,7 +465,7 @@ public class ResourceGanttController { ...@@ -465,7 +465,7 @@ public class ResourceGanttController {
ParamValidator.validateSceneExists(sceneService, sceneId); ParamValidator.validateSceneExists(sceneService, sceneId);
planResultService.InsertOrderAuto(sceneId, newOrderData); // planResultService.InsertOrderAuto(sceneId, newOrderData);
return R.ok("自动插单成功"); return R.ok("自动插单成功");
} }
......
...@@ -17,7 +17,7 @@ public class ScheduleParams { ...@@ -17,7 +17,7 @@ public class ScheduleParams {
private static final int MIN_POPULATION_SIZE = 10; private static final int MIN_POPULATION_SIZE = 10;
private static final int MAX_POPULATION_SIZE = 50; private static final int MAX_POPULATION_SIZE = 50;
private static final int MIN_MAX_ITERATIONS = 50; private static final int MIN_MAX_ITERATIONS = 50;
private static final int MAX_MAX_ITERATIONS = 250; private static final int MAX_MAX_ITERATIONS = 100;
private static final float MIN_CROSSOVER_PROB = 0.6f; private static final float MIN_CROSSOVER_PROB = 0.6f;
private static final float MAX_CROSSOVER_PROB = 0.9f; private static final float MAX_CROSSOVER_PROB = 0.9f;
private static final float MIN_MUTATION_PROB = 0.2f; private static final float MIN_MUTATION_PROB = 0.2f;
......
...@@ -417,13 +417,13 @@ public class GeneticAlgorithm { ...@@ -417,13 +417,13 @@ public class GeneticAlgorithm {
} }
// 加载锁定工单到ResultOld // 加载锁定工单到ResultOld
List<GAScheduleResult> lockedOrders = GlobalCacheUtil.get("locked_orders_" + sceneId); // List<GAScheduleResult> lockedOrders = GlobalCacheUtil.get("locked_orders_" + sceneId);
if (lockedOrders != null && !lockedOrders.isEmpty()) { // if (lockedOrders != null && !lockedOrders.isEmpty()) {
chromosome.setResultOld(ProductionDeepCopyUtil.deepCopyList(lockedOrders, GAScheduleResult.class)); // chromosome.setResultOld(ProductionDeepCopyUtil.deepCopyList(lockedOrders, GAScheduleResult.class));
FileHelper.writeLogFile("将 " + lockedOrders.size() + " 个锁定工单加载到初始种群中"); // FileHelper.writeLogFile("将 " + lockedOrders.size() + " 个锁定工单加载到初始种群中");
} else { // } else {
chromosome.setResultOld(new CopyOnWriteArrayList<>()); // chromosome.setResultOld(new CopyOnWriteArrayList<>());
} // }
decoder.decodeChromosomeWithCache(chromosome); decoder.decodeChromosomeWithCache(chromosome);
if (chromosome.getFitness() == 0) { if (chromosome.getFitness() == 0) {
......
...@@ -111,7 +111,7 @@ int opcount=allOperations.size(); ...@@ -111,7 +111,7 @@ int opcount=allOperations.size();
// 初始化变邻域搜索 // 初始化变邻域搜索
_vns = new VariableNeighborhoodSearch(_GlobalParam, allOperations, globalOpList, _fitnessCalculator, _objectiveWeights); _vns = new VariableNeighborhoodSearch(_GlobalParam, allOperations, globalOpList, _fitnessCalculator, _objectiveWeights);
_hillClimbing = new HillClimbing(allOperations); _hillClimbing = new HillClimbing(allOperations);
_simulatedAnnealing = new SimulatedAnnealing(_GlobalParam, allOperations, globalOpList, _fitnessCalculator, _objectiveWeights); _simulatedAnnealing = new SimulatedAnnealing( allOperations);
_parallelLocalSearch = new ParallelLocalSearch(_GlobalParam, allOperations, globalOpList, _fitnessCalculator, _objectiveWeights); _parallelLocalSearch = new ParallelLocalSearch(_GlobalParam, allOperations, globalOpList, _fitnessCalculator, _objectiveWeights);
_tabuSearch = new TabuSearch(_GlobalParam, allOperations, globalOpList, _fitnessCalculator, _objectiveWeights); _tabuSearch = new TabuSearch(_GlobalParam, allOperations, globalOpList, _fitnessCalculator, _objectiveWeights);
_tabuSearchWithSA = new TabuSearchWithSA(_GlobalParam, allOperations, globalOpList, _fitnessCalculator, _objectiveWeights); _tabuSearchWithSA = new TabuSearchWithSA(_GlobalParam, allOperations, globalOpList, _fitnessCalculator, _objectiveWeights);
...@@ -142,7 +142,7 @@ int opcount=allOperations.size(); ...@@ -142,7 +142,7 @@ int opcount=allOperations.size();
// 步骤2:对初始种群进行爬山法局部优化 // 步骤2:对初始种群进行爬山法局部优化
if(population.size()<5||opcount<10 ) { if(opcount<20 ) {
FileHelper.writeLogFile("爬山法局部优化-----------开始-------"); FileHelper.writeLogFile("爬山法局部优化-----------开始-------");
GeneticDecoder hillClimbingDecoder = new GeneticDecoder(_GlobalParam, param.getBaseTime(), machines, orders, materials, machineScheduler, materialRequirementService, sceneId); GeneticDecoder hillClimbingDecoder = new GeneticDecoder(_GlobalParam, param.getBaseTime(), machines, orders, materials, machineScheduler, materialRequirementService, sceneId);
...@@ -156,7 +156,7 @@ int opcount=allOperations.size(); ...@@ -156,7 +156,7 @@ int opcount=allOperations.size();
// 步骤2:对初始种群进行模拟退火+爬山法优化 // 步骤2:对初始种群进行模拟退火+爬山法优化
GeneticDecoder saDecoder1 = new GeneticDecoder(_GlobalParam, param.getBaseTime(), machines, orders, materials, machineScheduler, materialRequirementService, sceneId); GeneticDecoder saDecoder1 = new GeneticDecoder(_GlobalParam, param.getBaseTime(), machines, orders, materials, machineScheduler, materialRequirementService, sceneId);
if(population.size()>5||opcount<2000 ) { if(opcount<800 ) {
FileHelper.writeLogFile("模拟退火+爬山法优化-----------开始-------"); FileHelper.writeLogFile("模拟退火+爬山法优化-----------开始-------");
Chromosome saHcOptimized = _simulatedAnnealing.batchSearchGetMax(population, saDecoder1, machines); Chromosome saHcOptimized = _simulatedAnnealing.batchSearchGetMax(population, saDecoder1, machines);
FileHelper.writeLogFile("模拟退火+爬山法优化-----------结束-------"); FileHelper.writeLogFile("模拟退火+爬山法优化-----------结束-------");
......
...@@ -934,6 +934,9 @@ public class MachineCalculator { ...@@ -934,6 +934,9 @@ public class MachineCalculator {
LocalDateTime end) { LocalDateTime end) {
CopyOnWriteArrayList<TimeSegment> conflictIntervals = new CopyOnWriteArrayList<>(); CopyOnWriteArrayList<TimeSegment> conflictIntervals = new CopyOnWriteArrayList<>();
// 1. 维护窗口冲突(优化重叠判断,更严谨) // 1. 维护窗口冲突(优化重叠判断,更严谨)
if (machine.getMaintenanceWindows() != null && !machine.getMaintenanceWindows().isEmpty()) { if (machine.getMaintenanceWindows() != null && !machine.getMaintenanceWindows().isEmpty()) {
// 过滤重叠的维护窗口并转换为TimeSegment // 过滤重叠的维护窗口并转换为TimeSegment
......
...@@ -474,18 +474,18 @@ public class OrderSortService { ...@@ -474,18 +474,18 @@ public class OrderSortService {
if (!Objects.equals(prev.getSerie(), order.getSerie())) flags.append("serie变 "); if (!Objects.equals(prev.getSerie(), order.getSerie())) flags.append("serie变 ");
if (!Objects.equals(prev.getMaterialCode(), order.getMaterialCode())) flags.append("material变"); if (!Objects.equals(prev.getMaterialCode(), order.getMaterialCode())) flags.append("material变");
} }
costLog.append(String.format(" %2d. %s, routingId=%s, serie=%s, materialCode=%s, cost=%.0f %s\n", // costLog.append(String.format(" %2d. %s, routingId=%s, serie=%s, materialCode=%s, cost=%.0f %s\n",
(i + 1), // (i + 1),
order.getOrderCode(), // order.getOrderCode(),
order.getRoutingId(), // order.getRoutingId(),
order.getSerie(), // order.getSerie(),
order.getMaterialCode(), // order.getMaterialCode(),
costToPrev, // costToPrev,
flags.toString())); // flags.toString()));
totalCost += costToPrev; totalCost += costToPrev;
} }
costLog.append(String.format("[换线明细] 总换线成本 = %.0f\n", totalCost)); // costLog.append(String.format("[换线明细] 总换线成本 = %.0f\n", totalCost));
log.debug(costLog.toString()); // log.debug(costLog.toString());
// ================================== // ==================================
// 为最小化换线后的订单分配层级序号 // 为最小化换线后的订单分配层级序号
......
...@@ -29,6 +29,8 @@ public class TabuSearch { ...@@ -29,6 +29,8 @@ public class TabuSearch {
this.fitnessCalculator = fitnessCalculator; this.fitnessCalculator = fitnessCalculator;
this.objectiveWeights = objectiveWeights; this.objectiveWeights = objectiveWeights;
this.tabuList = new ArrayList<>(); this.tabuList = new ArrayList<>();
// 工序越多,禁忌表越长(适配1000+工序)
this.tabuListSize = Math.min(50, allOperations.size() / 30);
} }
/** /**
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -39,9 +39,9 @@ public class PlanResultServiceTest { ...@@ -39,9 +39,9 @@ public class PlanResultServiceTest {
// TestSortService sortService=new TestSortService(); // TestSortService sortService=new TestSortService();
// sortService.test1(); // sortService.test1();
// nsgaiiUtils.Test(); // nsgaiiUtils.Test();
// planResultService.execute2("0428340BB4F540938F1FB5599F03E8A4");//2000 planResultService.execute2("0428340BB4F540938F1FB5599F03E8A4");//2000
planResultService.execute2("C8B533BD8944405B9A2F8823C575C204");//500 // planResultService.execute2("C8B533BD8944405B9A2F8823C575C204");//500
// planResultService.execute2("EFDD34E4B5BC434BAEAE6A84DFCD4E7B");//20 // planResultService.execute2("EFDD34E4B5BC434BAEAE6A84DFCD4E7B");//20
// planResultService.execute2("00E0C5D3E4AD4F36B56C39395906618D"); // planResultService.execute2("00E0C5D3E4AD4F36B56C39395906618D");
// planResultService.execute2("92BB773E1E2447C99D8176C991D5C9D2"); // planResultService.execute2("92BB773E1E2447C99D8176C991D5C9D2");
......
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