Commit c5fa84a8 authored by Tong Li's avatar Tong Li

Merge remote-tracking branch 'origin/tl'

parents f0abbd39 f0fc8121
......@@ -101,7 +101,9 @@ public class Chromosome {
private ObjectiveWeights objectiveWeights;
List<Material> materials;
private List<Material> materials;
private List<String> materialIds;
/*
* 最早完工时间(最小化) 最小化总加工时间 最小总换型时间
*/
......
......@@ -29,6 +29,9 @@ public class GeneticAlgorithm {
private final MachineSchedulerService machineScheduler;
private final List<Order> orders;
private final List<Material> materials;
private final List<String> materialIds;
private static GlobalParam _GlobalParam;
private List<GroupResult> _entryRel;
......@@ -49,7 +52,7 @@ public class GeneticAlgorithm {
private String sceneId;
public GeneticAlgorithm(GlobalParam globalParam,List<Machine> machines, List<Order> orders,
List<Material> materials, MachineSchedulerService machineScheduler,List<GroupResult> entryRel,MaterialRequirementService _materialRequirementService,SceneService sceneService,String _sceneId) {
List<Material> materials,List<String> _materialIds, MachineSchedulerService machineScheduler,List<GroupResult> entryRel,MaterialRequirementService _materialRequirementService,SceneService sceneService,String _sceneId) {
this.machines = machines;
this.orders = orders;
this.materials = materials;
......@@ -59,6 +62,7 @@ public class GeneticAlgorithm {
materialRequirementService=_materialRequirementService;
_sceneService=sceneService;
sceneId=_sceneId;
materialIds=_materialIds;
}
public void Init(double[] customWeights, boolean pureNSGAIIMode) {
......@@ -127,7 +131,9 @@ public class GeneticAlgorithm {
if(population.size()<param.getTournamentSize())
{
best.setBaseTime(param.getBaseTime());
best.setOrderMaterials(orderMaterials);
// best.setOrderMaterials(orderMaterials);
best.setMaterialIds(materialIds);
best.setMaterials(null);
// best.setOperatRel(_entryRel);
if(best.getInitMachines()==null)
......@@ -267,7 +273,8 @@ public class GeneticAlgorithm {
FileHelper.writeLogFile("迭代进化-----------结束-------");
best.setBaseTime(param.getBaseTime());
best.setOrderMaterials(orderMaterials);
best.setMaterialIds(materialIds);
best.setMaterials(null);
// best.setOperatRel(_entryRel);
if(best.getInitMachines()==null)
......
......@@ -499,6 +499,22 @@ if(finishedOrder==null||finishedOrder.size()==0)
// _globalParam.set_smoothChangeOver(false);
CopyOnWriteArrayList<ScheduleResultDetail> geneDetails=new CopyOnWriteArrayList<>();
int bomtime=0;
if(machine.getId()==2063)
{
int i=0;
}
LocalDateTime startTime1 = baseTime.plus(earliestStartTime, ChronoUnit.SECONDS);
TimeSegment slot = machineCalculator.GetCurrentOrNextShift(machine, startTime1, "", false);
if(slot!=null)
{
earliestStartTime = slot.getStart().isAfter(startTime1)
?(int) ChronoUnit.SECONDS.between(baseTime, slot.getStart())
: earliestStartTime;
}
if((operation.getMaterialRequirements()!=null&&operation.getTargetFinishedOperationId()==null)||calbom) {
int earliestStartTimeold=earliestStartTime;
if (_globalParam.is_smoothChangeOver()) {
......@@ -518,6 +534,10 @@ if(finishedOrder==null||finishedOrder.size()==0)
earliestStartTime=bomtime;
}
}
if(machine.getId()==2063)
{
int i=0;
}
......
......@@ -519,6 +519,13 @@ public class MachineCalculator {
// 计算有效时间
CopyOnWriteArrayList<TimeSegment> timeSegments2= new CopyOnWriteArrayList<>(timeSegments.subList(1,timeSegments.size()-1));
if(timeSegments2==null||timeSegments2.size()==0)
{
int i=0;
}
LocalDateTime effectiveStart=timeSegments2.get(0).getStart();
LocalDateTime effectiveend=timeSegments2.get(timeSegments2.size()-1).getEnd();
......@@ -1032,7 +1039,7 @@ public class MachineCalculator {
/**
* 获取设备当前或下一个有效班次
*/
private TimeSegment GetCurrentOrNextShift(Machine machine, LocalDateTime time, String prevtime, boolean checkprevtime) {
public TimeSegment GetCurrentOrNextShift(Machine machine, LocalDateTime time, String prevtime, boolean checkprevtime) {
TimeSegment start = null;
if (!machine.getAvailability().isEmpty())
......
......@@ -831,7 +831,7 @@ if(headers1==null)
if (MaterialRequirements != null&&MaterialRequirements.size()>0) {
for (OrderMaterialRequirement orderMaterial : MaterialRequirements) {
double allneeded = parentQuantity * orderMaterial.getRequiredQuantity();
double allneeded = orderMaterial.getRequiredQuantity();
double needed = allneeded;
......@@ -1276,7 +1276,7 @@ if(headers1==null)
Long CkeckLeadTime= material.getCkeckLeadTime();
List<MaterialSupply> sortedInTransit = material.getInTransit().stream()
.filter(t -> t.getQuantity() > 0&&t.getArrivalTime().compareTo(earliestStartTime)<=0 )
.sorted(Comparator.comparing(MaterialSupply::getArrivalTime))
.sorted(Comparator.comparing(MaterialSupply::getArrivalTime).reversed())
.collect(Collectors.toList());
for (MaterialSupply supply : sortedInTransit) {
......@@ -1417,7 +1417,7 @@ if(headers1==null)
return RoutingDiscreteParams;
}
private List<Material> GetMaterials(String sceneId) {
public List<Material> GetMaterials(String sceneId) {
List<Material> materials=(List<Material>)GlobalCacheUtil.get(sceneId+materialsCacheKey);
if(materials==null)
{
......
......@@ -23,6 +23,13 @@ import java.util.stream.IntStream;
*/
public class ScheduleOperationService {
private MaterialRequirementService materialRequirementService;
public ScheduleOperationService(MaterialRequirementService _materialRequirementService) {
materialRequirementService=_materialRequirementService;
}
/**
* 移动工序方法
* @param chromosome 染色体对象
......@@ -1214,7 +1221,7 @@ if(targetOp.getSequence()>1) {
chromosome.setMachines(ProductionDeepCopyUtil.deepCopyList(chromosome.getInitMachines(),Machine.class) );
GeneticDecoder decoder = new GeneticDecoder(globalParam,baseTime, chromosome.getMachines(),
chromosome.getOrders(), null, machineScheduler,null,chromosome.getScenarioID());
chromosome.getOrders(), null, machineScheduler,materialRequirementService,chromosome.getScenarioID());
chromosome.setResultOld(ProductionDeepCopyUtil.deepCopyList(chromosome.getResult(),GAScheduleResult.class));
chromosome.getResult().clear();
......
......@@ -161,6 +161,8 @@ public class PlanResultService {
List<Machine> machines= InitCalendarToAllMachines(SceneId, ProdEquipments,machineScheduler,globalParam.isIsUseCalendar());
// 3. 构建订单-工序数据
List<Order> orders=InitOrder(ProdLaunchOrders);
List<Material> Materials= InitMaterial();
......@@ -202,8 +204,13 @@ public class PlanResultService {
);
List<String> materialIds = Materials1.stream()
.map(Material::getId)
.distinct()
.collect(Collectors.toList());
// 5. 执行调度算法
GeneticAlgorithm scheduler =new GeneticAlgorithm(globalParam,machines,orders,Materials1,machineScheduler,entryRel,materialRequirementService,_sceneService,SceneId); //new GeneticAlgorithm(products, machines, orders, machineScheduler);
GeneticAlgorithm scheduler =new GeneticAlgorithm(globalParam,machines,orders,Materials1,materialIds,machineScheduler,entryRel,materialRequirementService,_sceneService,SceneId); //new GeneticAlgorithm(products, machines, orders, machineScheduler);
param.initAdaptiveParams(entrys.size());
double[] customWeights = new double[] { 0.4, 0.1, 0.1, 0.1, 0.3 }; // 延迟时间权重提升到0.5
//完工时间、总流程时间、总换型时间、机器负载标准差、延迟时间
......@@ -253,7 +260,7 @@ public class PlanResultService {
// WriteScheduleSummary(chromosome);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleOperationService ScheduleOperation=new ScheduleOperationService(materialRequirementService);
WriteScheduleSummary(chromosome);
ScheduleOperation.editMachineOption(chromosome,operation,newMachineId,globalParam);
WriteScheduleSummary(chromosome);
......@@ -344,7 +351,7 @@ public class PlanResultService {
.forEach(opInfo -> opInfo.setOp(operation));
}
GlobalParam globalParam=new GlobalParam();
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleOperationService ScheduleOperation=new ScheduleOperationService(materialRequirementService);
ScheduleOperation.editMachineOption(chromosome,operation,operation.getSelectMachineID(),globalParam);
......@@ -376,7 +383,7 @@ public class PlanResultService {
public void UnlockStartTime(String sceneId, int opId) {
Chromosome chromosome = _sceneService.loadChromosomeFromFile(sceneId);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleOperationService ScheduleOperation=new ScheduleOperationService(materialRequirementService);
ScheduleOperation.UnlockStartTime(chromosome, opId);
_sceneService.saveChromosomeToFile(chromosome, sceneId);
......@@ -385,7 +392,7 @@ public class PlanResultService {
public void unlockStartTime(Chromosome chromosome, int opId) {
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleOperationService ScheduleOperation=new ScheduleOperationService(materialRequirementService);
ScheduleOperation.UnlockStartTime(chromosome, opId);
}
......@@ -423,7 +430,7 @@ public class PlanResultService {
*/
private Chromosome redecodeChromosome(Chromosome chromosome,String SceneId) {
GlobalParam globalParam = new GlobalParam();
ScheduleOperationService scheduleOperation = new ScheduleOperationService();
ScheduleOperationService scheduleOperation = new ScheduleOperationService(materialRequirementService);
scheduleOperation.redecode(chromosome, chromosome.getBaseTime(), globalParam);
// _sceneService.saveChromosomeToFile(chromosome, SceneId);
return chromosome;
......@@ -436,7 +443,7 @@ public class PlanResultService {
}
chromosome.setBaseTime(BaseTime);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleOperationService ScheduleOperation=new ScheduleOperationService(materialRequirementService);
GlobalParam globalParam=new GlobalParam();
ScheduleOperation.redecode(chromosome,chromosome.getBaseTime(), globalParam);
......@@ -452,7 +459,7 @@ public class PlanResultService {
// WriteScheduleSummary(chromosome);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleOperationService ScheduleOperation=new ScheduleOperationService(materialRequirementService);
// WriteScheduleSummary(chromosome);
ScheduleOperation.dragOperation(chromosome,opId,targetopId,isfront,newMachineId, globalParam);
// WriteScheduleSummary(chromosome);
......@@ -469,7 +476,7 @@ public class PlanResultService {
// WriteScheduleSummary(chromosome);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleOperationService ScheduleOperation=new ScheduleOperationService(materialRequirementService);
// WriteScheduleSummary(chromosome);
ScheduleOperation.moveOperation(chromosome,opId, (int)ChronoUnit.SECONDS.between(chromosome.getBaseTime(), newStartTime),newMachineId, globalParam, lockStartTime);
// WriteScheduleSummary(chromosome);
......@@ -490,7 +497,7 @@ public class PlanResultService {
// WriteScheduleSummary(chromosome);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleOperationService ScheduleOperation=new ScheduleOperationService(materialRequirementService);
// WriteScheduleSummary(chromosome);
ScheduleOperation.moveOperation(chromosome,opId, (int)ChronoUnit.SECONDS.between(chromosome.getBaseTime(), newStartTime),newMachineId, globalParam, lockStartTime);
// WriteScheduleSummary(chromosome);
......@@ -502,9 +509,22 @@ public class PlanResultService {
public void Redecode(String SceneId)
{
Chromosome chromosome= _sceneService.loadChromosomeFromFile(SceneId);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleOperationService ScheduleOperation=new ScheduleOperationService(materialRequirementService);
// WriteScheduleSummary(chromosome);
List<Material> UseMaterials= materialRequirementService.GetMaterials(SceneId);
if(UseMaterials==null) {
if (chromosome.getMaterialIds() != null && chromosome.getMaterialIds().size() > 0) {
List<Material> Materials = InitMaterial();
UseMaterials = Materials.stream()
.filter(t -> chromosome.getMaterialIds()
.contains(t.getId())).collect(Collectors.toList());
chromosome.setMaterials(UseMaterials);
}
}else {
chromosome.setMaterials(UseMaterials);
}
GlobalParam globalParam=new GlobalParam();
ScheduleOperation.redecode(chromosome, chromosome.getBaseTime(), globalParam);
// WriteScheduleSummary(chromosome);
......@@ -520,7 +540,7 @@ public class PlanResultService {
//this.baseTime=param.getBaseTime();
// WriteScheduleSummary(chromosome);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleOperationService ScheduleOperation=new ScheduleOperationService(materialRequirementService);
ScheduleOperation.SpiltOperation(chromosome,opId,splitCounts, globalParam);
WriteScheduleSummary(chromosome);
......@@ -537,7 +557,7 @@ public class PlanResultService {
//this.baseTime=param.getBaseTime();
// WriteScheduleSummary(chromosome);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleOperationService ScheduleOperation=new ScheduleOperationService(materialRequirementService);
ScheduleOperation.DelOperation(chromosome,opId, globalParam);
// WriteScheduleSummary(chromosome);
......@@ -554,7 +574,7 @@ public class PlanResultService {
//this.baseTime=param.getBaseTime();
// WriteScheduleSummary(chromosome);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleOperationService ScheduleOperation=new ScheduleOperationService(materialRequirementService);
ScheduleOperation.DelOrder(chromosome,orderId, globalParam);
// WriteScheduleSummary(chromosome);
......@@ -574,7 +594,7 @@ public class PlanResultService {
//this.baseTime=param.getBaseTime();
// WriteScheduleSummary(chromosome);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleOperationService ScheduleOperation=new ScheduleOperationService(materialRequirementService);
ScheduleOperation.LockOperation(chromosome,opId,isLocked, globalParam);
//WriteScheduleSummary(chromosome);
......@@ -591,7 +611,7 @@ public class PlanResultService {
//this.baseTime=param.getBaseTime();
// WriteScheduleSummary(chromosome);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleOperationService ScheduleOperation=new ScheduleOperationService(materialRequirementService);
ScheduleOperation.SpiltOrder(chromosome,orderId,splitCounts, globalParam);
WriteScheduleSummary(chromosome);
......@@ -607,7 +627,7 @@ public class PlanResultService {
//this.baseTime=param.getBaseTime();
// WriteScheduleSummary(chromosome);
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleOperationService ScheduleOperation=new ScheduleOperationService(materialRequirementService);
ScheduleOperation.MergeOrder(chromosome,sourceorderId,targetorderId, globalParam);
WriteScheduleSummary(chromosome);
......@@ -623,7 +643,7 @@ public class PlanResultService {
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleOperationService ScheduleOperation=new ScheduleOperationService(materialRequirementService);
ScheduleOperation.AddMaintenanceWindow(chromosome,machineId,maintenanceWindow, globalParam);
// WriteScheduleSummary(chromosome);
......@@ -640,7 +660,7 @@ public class PlanResultService {
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleOperationService ScheduleOperation=new ScheduleOperationService(materialRequirementService);
ScheduleOperation.DelMaintenanceWindow(chromosome,machineId,maintenanceId, globalParam);
// WriteScheduleSummary(chromosome);
......@@ -653,7 +673,7 @@ public class PlanResultService {
GlobalParam globalParam = new GlobalParam();
Chromosome chromosome = _sceneService.loadChromosomeFromFile(SceneId);
ScheduleOperationService ScheduleOperation = new ScheduleOperationService();
ScheduleOperationService ScheduleOperation = new ScheduleOperationService(materialRequirementService);
ScheduleOperation.DelMaintenanceWindowBatch(chromosome, machineId, maintenanceIds, globalParam);
// WriteScheduleSummary(chromosome);
......@@ -670,7 +690,7 @@ public class PlanResultService {
ScheduleOperationService ScheduleOperation=new ScheduleOperationService();
ScheduleOperationService ScheduleOperation=new ScheduleOperationService(materialRequirementService);
List<MaintenanceWindow> maintenanceWindowList= ScheduleOperation.GetMaintenanceWindow(chromosome,machineId);
// WriteScheduleSummary(chromosome);
......@@ -758,7 +778,7 @@ public class PlanResultService {
machines= machines.stream().filter(t->machineIds.contains(t.getId())).collect(Collectors.toList());
// 5. 执行调度算法
GeneticAlgorithm scheduler =new GeneticAlgorithm(globalParam,machines,orders,Materials,machineScheduler,entryRel,materialRequirementService,_sceneService,SceneId); //new GeneticAlgorithm(products, machines, orders, machineScheduler);
GeneticAlgorithm scheduler =new GeneticAlgorithm(globalParam,machines,orders,Materials,null,machineScheduler,entryRel,materialRequirementService,_sceneService,SceneId); //new GeneticAlgorithm(products, machines, orders, machineScheduler);
param.initAdaptiveParams(entrys.size());
double[] customWeights = new double[] { 0.4, 0.1, 0.1, 0.1, 0.3 }; // 延迟时间权重提升到0.5
//完工时间、总流程时间、总换型时间、机器负载标准差、延迟时间
......
......@@ -39,7 +39,9 @@ public class PlanResultServiceTest {
// TestSortService sortService=new TestSortService();
// sortService.test1();
// nsgaiiUtils.Test();
planResultService.execute2("18E5F8BE09B14EAE822651BFEF100900");
// planResultService.execute2("1BC8FFD1A7D54AE7AA75D2CBC7C08080");
// planResultService.execute2("00E0C5D3E4AD4F36B56C39395906618D");
// planResultService.execute2("726D4C1A712B4B1393175BD44B775B66");
// planResultService.execute2("265F24B6DF3C40E4B17D193B0CC8AAF2");
// LocalDateTime t= LocalDateTime.of(2026, 02, 14, 1, 25, 52);
......@@ -47,7 +49,7 @@ public class PlanResultServiceTest {
// opids.add(7);
// planResultService.Move("27065EA0ECD14A81B7FAAFEF52273F93",opids,t,1265l,0);
// planResultService.Redecode("27065EA0ECD14A81B7FAAFEF52273F93");
// planResultService.Redecode("CA71321FE55B4437A3900315692F9220");
planResultService.Redecode("00E0C5D3E4AD4F36B56C39395906618D");
// planResultService.Drag("27065EA0ECD14A81B7FAAFEF52273F93",opids,6,false,0l);
// MaintenanceWindow maintenanceWindow=new MaintenanceWindow();
// maintenanceWindow.setStartTime(LocalDateTime.of(2025, 10, 21, 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