Commit 81caef39 authored by Tong Li's avatar Tong Li

bom

parent a8dd2c90
......@@ -1332,7 +1332,7 @@ public class GeneticDecoder {
processingTimeTotal = (int) reslte.get(5);//processingTimeTotal
if (setupTime == 0) {
geneDetails = machineCalculator.getNextAvailableTime(machine, operation, earliestStartTime, -1,
processingTimeTotal, machineTasks, operation.getIsInterrupt() != 1, islockMachineTime, processingTime, operation.getQuantity(), true, isJit);
processingTimeTotal, machineTasks, operation.getIsInterrupt() != 1, true, processingTime, operation.getQuantity(), islockMachineTime, isJit);
} else {
CopyOnWriteArrayList<TimeSegment> AvailableTimeSegment = (CopyOnWriteArrayList<TimeSegment>) reslte.get(6);
......
......@@ -59,6 +59,10 @@ public class GeneticDecoderBom {
Entry firstTargetOp = targetOps.get(0);
if (Entry.SchedulingMode.FORWARD.name().equals(
firstTargetOp.getSchedulingMode())) {
if(targetGroupId==3)
{
int i=0;
}
int rootStart = forwardEstimateToOperation(decoder,targetOpId, targetGroupId,0,
entrysBygroupId, opMachineKeyMap, chromosome,
scheduleIndexById, machineTasksCache,machineIdMap,entryIndexById,false);
......@@ -296,6 +300,7 @@ if(isJit)
int estimatedStartTime,
Map<Integer, List<Entry>> entrysBygroupId,
Chromosome chromosome) {
TreeMap<String, Material> materials = chromosome.getMaterials();
if (materials == null || materials.isEmpty()) return estimatedStartTime;
List<OrderMaterialRequirement> remove=new ArrayList<>();
......
......@@ -267,7 +267,7 @@ public class PlanResultService {
throw new BusinessException("排产计算结果保存失败,请稍后重试或联系管理员");
}
// WriteScheduleSummary(chromosome);
WriteScheduleSummary(chromosome);
return chromosome;
......
......@@ -12,10 +12,14 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;
import java.util.stream.Collectors;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
/**
* 场景结果文件读写服务
......@@ -25,6 +29,15 @@ public class SceneService {
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(SceneService.class);
/**
* 是否使用 GZIP 压缩,默认 true
*/
private boolean useCompression = false;
public void setUseCompression(boolean useCompression) {
this.useCompression = useCompression;
}
@Autowired
private RedisUtils redisUtils;
......@@ -51,15 +64,19 @@ public class SceneService {
return resultDir;
}
private String getFileExtension() {
return useCompression ? ".json.gz" : ".json";
}
private File getChromosomeFile(String sceneId) {
File resultDir = getResultDirectory();
String fileName = "chromosome_result_" + sceneId + ".json";
String fileName = "chromosome_result_" + sceneId + getFileExtension();
return new File(resultDir, fileName);
}
private File getChromosomeFile(String sceneId, String version) {
File resultDir = getResultDirectory();
String fileName = "chromosome_result_" + sceneId + "_" + version + "_.json";
String fileName = "chromosome_result_" + sceneId + "_" + version + "_" + getFileExtension();
return new File(resultDir, fileName);
}
......@@ -98,17 +115,23 @@ public class SceneService {
logger.info("正在从文件加载染色体: {}, sceneId={}, fileSize={} bytes",
file.getAbsolutePath(), sceneId, fileSize);
long fileReadStart = System.nanoTime();
byte[] fileBytes = Files.readAllBytes(file.toPath());
long fileReadMs = (System.nanoTime() - fileReadStart) / 1_000_000;
long deserializeStart = System.nanoTime();
Chromosome chromosome = objectMapper.readValue(fileBytes, Chromosome.class);
Chromosome chromosome;
if (useCompression) {
try (FileInputStream fis = new FileInputStream(file);
GZIPInputStream gzis = new GZIPInputStream(fis)) {
chromosome = objectMapper.readValue(gzis, Chromosome.class);
}
} else {
try (FileInputStream fis = new FileInputStream(file)) {
chromosome = objectMapper.readValue(fis, Chromosome.class);
}
}
long deserializeMs = (System.nanoTime() - deserializeStart) / 1_000_000;
long totalMs = (System.nanoTime() - totalStart) / 1_000_000;
logger.info("染色体加载成功,场景ID: {}, fileSize={} bytes, fileRead={} ms, deserialize={} ms, total={} ms",
sceneId, fileSize, fileReadMs, deserializeMs, totalMs);
logger.info("染色体加载成功,场景ID: {}, fileSize={} bytes, deserialize={} ms, total={} ms",
sceneId, fileSize, deserializeMs, totalMs);
return chromosome;
} catch (Exception e) {
......@@ -163,7 +186,14 @@ public class SceneService {
File tempFile = new File(file.getParentFile(), file.getName() + ".tmp");
chromosome.setVersion(sceneChromsome.getVersion());
if (useCompression) {
try (FileOutputStream fos = new FileOutputStream(tempFile);
GZIPOutputStream gzos = new GZIPOutputStream(fos)) {
objectMapper.writeValue(gzos, chromosome);
}
} else {
objectMapper.writeValue(tempFile, chromosome);
}
if (tempFile.length() == 0) {
logger.error("写入的临时文件为空: {}", tempFile.getAbsolutePath());
......@@ -171,6 +201,15 @@ public class SceneService {
return false;
}
if (useCompression) {
try (FileInputStream fis = new FileInputStream(tempFile);
GZIPInputStream gzis = new GZIPInputStream(fis)) {
Chromosome verifyChromosome = objectMapper.readValue(gzis, Chromosome.class);
if (verifyChromosome == null) {
throw new IOException("验证读取失败");
}
}
} else {
try {
Chromosome verifyChromosome = objectMapper.readValue(tempFile, Chromosome.class);
if (verifyChromosome == null) {
......@@ -181,6 +220,7 @@ public class SceneService {
Files.deleteIfExists(tempFile.toPath());
return false;
}
}
if (file.exists()) {
Files.deleteIfExists(file.toPath());
......
package com.aps.demo;
import com.aps.ApsApplication;
import com.aps.common.util.FileHelper;
import com.aps.common.util.RangeSubtractUtil;
import com.aps.entity.Algorithm.Chromosome;
import com.aps.entity.Algorithm.ObjectiveWeights;
......@@ -40,7 +41,7 @@ public class PlanResultServiceTest {
// sortService.test1();
// nsgaiiUtils.Test();
// planResultService.execute2("6D7C59CF2576457EBCB5F6CCDF5AF342");//2000
planResultService.execute2("4990F98F300549F384A754AAE7486BD9");//2000
// planResultService.execute2("15210B13B88A453F8B84AAC7F16C7541");//2000
......@@ -48,7 +49,7 @@ public class PlanResultServiceTest {
// planResultService.execute2("E2CD1FC6FF9B4B19A59FEC7F846D4952");//600
// planResultService.execute2("EAF3C94B8F3345278F226C94FB0FED86");//bom
// planResultService.execute2("6D63146BE5C84A78B5AB044327BA55BD");//2000
planResultService.execute2("6D63146BE5C84A78B5AB044327BA55BD");//5000
// planResultService.execute2("6D63146BE5C84A78B5AB044327BA55BD");//5000
// planResultService.execute2("C8B533BD8944405B9A2F8823C575C204");//500
// planResultService.execute2("EFDD34E4B5BC434BAEAE6A84DFCD4E7B");//20
// planResultService.execute2("00E0C5D3E4AD4F36B56C39395906618D");
......@@ -75,7 +76,7 @@ public class PlanResultServiceTest {
public void testExecute2() {
// 这里需要一个有效的SceneId来测试
// 在实际测试中,您需要提供一个数据库中存在的SceneId
String sceneId = "E9C72513F48D44188C7989EEAEE85D3E";
String sceneId = "6D63146BE5C84A78B5AB044327BA55BD";
try {
// Chromosome result = planResultService.execute2(sceneId);
......@@ -104,9 +105,13 @@ public class PlanResultServiceTest {
//
// planResultService.SpiltOrder(sceneId,"2f24e563-1337-422b-a0ba-92da7e8c6584",splitCountsArray);
planResultService.schedule(sceneId);
// planResultService.schedule(sceneId);
long Start = System.nanoTime();
Chromosome schedule = sceneService.loadChromosomeFromFile(sceneId);
//
FileHelper.writeLogFile("[PERF] loadChromosomeFromFile 总耗时=" + fmtMs(System.nanoTime() - Start) );
// // 转换为 ProductGanttVO 格式
// List<ProductGanttVO> productGanttVOList= new ArrayList<>();
// List<ProductGanttVO> resourceGanttVOs = planResultService.convertToProductGanttVO1(schedule);
......@@ -121,4 +126,9 @@ public class PlanResultServiceTest {
e.printStackTrace();
}
}
private static String fmtMs(long nano) {
if (nano < 1000000L) return (nano / 1000L) + "μs";
if (nano < 1000000000L) return (nano / 1000000L) + "ms";
return String.format("%.2fs", nano / 1_000_000_000.0);
}
}
\ No newline at end of file
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