Commit eb9004a2 authored by Tong Li's avatar Tong Li

换型,拖动

parent 18420541
......@@ -142,7 +142,9 @@ public class Entry {
private BigDecimal runtime;//持续时间
private BigDecimal singleOut;//单件产出
private double changeLineTime;//换模时间
private BigDecimal setupTime;
private BigDecimal setupTime;//准备时间
private int teardownTime; // 收尾时间(后处理时间)
//常数时间
private int constTime;
private String equipCode;//设备编码
private String equipName;//设备编码
......
......@@ -38,5 +38,9 @@ public class GlobalParam {
/// </summary>
private boolean IsOverlap = false;
private boolean _smoothSetup = false; // 默认true,不占用设备时长
private boolean _smoothSetup = false; // 设置时间平滑 工序的前处理是否提前
private boolean _smoothChangeOver = true; // 默认true,设置时间 是否考虑换型时间
private boolean _smoothChangeOverInWeek = true; // 默认true,后台任务设置 休息时间是否换型
}
......@@ -13,10 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.*;
import java.util.stream.Collectors;
/**
......@@ -361,29 +358,33 @@ return population;
FileHelper.writeLogFile(String.format(" KPI---%f-------",d));
}
}
private ExecutorService decodeExecutor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
//private ExecutorService decodeExecutor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
private final ExecutorService decodeExecutor = new ThreadPoolExecutor(
Runtime.getRuntime().availableProcessors() - 1, // 核心线程数=CPU-1,无切换开销
Runtime.getRuntime().availableProcessors() - 1, // 最大线程数=核心数
0L, TimeUnit.MILLISECONDS,
new ArrayBlockingQueue<>(200), // 有界队列,避免内存溢出
new ThreadPoolExecutor.CallerRunsPolicy() // 任务满了主线程执行,不丢失任务
);
private void Chromosomedecode(ScheduleParams param, List<Entry> allOperations,List<GlobalOperationInfo> globalOpList,List<Chromosome> population)
{
FileHelper.writeLogFile("解码---------------"+population.size() );
GeneticDecoder decoder = new GeneticDecoder(_GlobalParam, param.getBaseTime(), machines, orders, materials, machineScheduler,orderMaterials);
boolean ismore=true;
if(ismore) {
CompletableFuture.allOf(population.stream()
.map(chromosome -> CompletableFuture.runAsync(() -> decode(decoder, chromosome, param, allOperations, globalOpList), decodeExecutor))
.toArray(CompletableFuture[]::new))
.join();
if(1==2) {
} else {
if (population != null && population.size() > 0) {
population.parallelStream().forEach(chromosome -> {
decode(decoder, chromosome, param, allOperations, globalOpList);
});
}
}
......
......@@ -37,7 +37,7 @@ public class GeneticOperations {
if (population == null || population.isEmpty()) {
return new ArrayList<>();
}
int populationSize = population.size();
int populationSize = population.size()>100?((int)(population.size()*0.8)):population.size();
// 预计算需要选中的个体数量,避免动态判断
int needSelectCount = populationSize - Math.max(1, Math.min(tournamentSize, populationSize));
List<Chromosome> selected = new ArrayList<>(needSelectCount); // 预初始化容量
......
package com.aps.service.Algorithm;
import com.aps.common.util.FileHelper;
import com.aps.entity.Algorithm.Chromosome;
import com.aps.entity.Algorithm.ObjectiveWeights;
......@@ -48,7 +49,10 @@ public class NSGAIIUtils {
* 并行快速非支配排序(大规模种群提速50%+)
*/
public List<List<Chromosome>> parallelFastNonDominatedSort(List<Chromosome> population) {
int popSize = population.size();
FileHelper.writeLogFile("非支配排序---------------"+popSize );
List<List<Chromosome>> fronts = new ArrayList<>();
// 步骤1:预处理 - 计算归一化目标值和加权目标值
......
......@@ -213,7 +213,10 @@ public class RoutingDataService {
entry.setEquipTypeCode(op.getEquipTypeCode());
entry.setRuntime(op.getRuntime());
entry.setSingleOut(op.getSingleOut());
//生产准备
entry.setSetupTime(op.getSetupTime());
//后处理
entry.setTeardownTime(op.getPostprocessingTime());
entry.setConstTime(op.getConstTime());
entry.setOrderId(op.getOrderId());
entry.setOrderCode(op.getOrderCode());
......@@ -248,6 +251,7 @@ public class RoutingDataService {
machineIds.replace(e.getEquipId(),totalprocessTime);
}
}else {
//大概记录要用到的设备的加工时间,用于生成设备日历
machineIds.put(e.getEquipId(),totalprocessTime);
}
......
......@@ -540,6 +540,23 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
return chromosome;
}
public Chromosome Drag(String SceneId,List<Integer> opId, int targetopId,Boolean isfront,
Long newMachineId) {
GlobalParam globalParam=new GlobalParam();
Chromosome chromosome= _sceneService.loadChromosomeFromFile(SceneId);
// WriteScheduleSummary(chromosome);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
// WriteScheduleSummary(chromosome);
ScheduleOperation.dragOperation(chromosome,opId,targetopId,isfront,newMachineId, globalParam);
// WriteScheduleSummary(chromosome);
_sceneService.saveChromosomeToFile(chromosome, SceneId);
return chromosome;
}
public Chromosome Move(String SceneId,List<Integer> opId, LocalDateTime newStartTime,
Long newMachineId,int lockStartTime) {
......@@ -583,11 +600,11 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
{
Chromosome chromosome= _sceneService.loadChromosomeFromFile(SceneId);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
WriteScheduleSummary(chromosome);
// WriteScheduleSummary(chromosome);
GlobalParam globalParam=new GlobalParam();
ScheduleOperation.redecode(chromosome, chromosome.getBaseTime(), globalParam);
WriteScheduleSummary(chromosome);
// WriteScheduleSummary(chromosome);
}
......
......@@ -37,14 +37,16 @@ public class PlanResultServiceTest {
// NSGAIIUtils nsgaiiUtils=new NSGAIIUtils();
// nsgaiiUtils.Test();
planResultService.execute2("C5FB5EF2A7334A0A92F826F4937E1008");
// planResultService.execute2("FFAC5AA2E0B943D292933B28BDAB9068");
// planResultService.execute2("726D4C1A712B4B1393175BD44B775B66");
// planResultService.execute2("265F24B6DF3C40E4B17D193B0CC8AAF2");
// LocalDateTime t= LocalDateTime.of(2026, 02, 14, 1, 25, 52);
// List<Integer> opids=new ArrayList<>();//BCA6FA43FFA444D3952CF8F6E1EA291B
// opids.add(9);
List<Integer> opids=new ArrayList<>();//BCA6FA43FFA444D3952CF8F6E1EA291B
opids.add(7);
// planResultService.Move("27065EA0ECD14A81B7FAAFEF52273F93",opids,t,1265l,0);
// planResultService.Redecode("27065EA0ECD14A81B7FAAFEF52273F93");
// planResultService.Redecode("CA71321FE55B4437A3900315692F9220");
planResultService.Drag("27065EA0ECD14A81B7FAAFEF52273F93",opids,6,false,0l);
// MaintenanceWindow maintenanceWindow=new MaintenanceWindow();
// maintenanceWindow.setStartTime(LocalDateTime.of(2025, 10, 21, 0, 0, 0));
// maintenanceWindow.setEndTime(LocalDateTime.of(2025, 10, 31, 0, 0, 0));
......
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