Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
HYH.APSJ
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
佟礼
HYH.APSJ
Commits
6f7aeeba
Commit
6f7aeeba
authored
May 08, 2026
by
Tong Li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
倒排
parent
ef3a51e0
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
966 additions
and
245 deletions
+966
-245
Entry.java
src/main/java/com/aps/entity/basic/Entry.java
+9
-0
GlobalParam.java
src/main/java/com/aps/entity/basic/GlobalParam.java
+5
-0
GeneticDecoder.java
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
+196
-104
GeneticDecoderBom.java
...ain/java/com/aps/service/Algorithm/GeneticDecoderBom.java
+147
-0
MachineCalculator.java
...ain/java/com/aps/service/Algorithm/MachineCalculator.java
+574
-123
MachineSchedulerService.java
...in/java/com/aps/service/plan/MachineSchedulerService.java
+11
-0
PlanResultService.java
src/main/java/com/aps/service/plan/PlanResultService.java
+16
-12
application.yml
src/main/resources/application.yml
+3
-3
PlanResultServiceTest.java
src/test/java/com/aps/demo/PlanResultServiceTest.java
+5
-3
No files found.
src/main/java/com/aps/entity/basic/Entry.java
View file @
6f7aeeba
...
...
@@ -157,6 +157,7 @@ private Long isInterrupt = 1l;
private
String
equipName
;
//设备编码
@Schema
(
description
=
"指定开始时间"
)
@JsonInclude
(
JsonInclude
.
Include
.
ALWAYS
)
private
LocalDateTime
designatedStartTime
;
...
...
@@ -164,4 +165,12 @@ private Long isInterrupt = 1l;
private
LocalDateTime
jitPreferredStartTime
;
private
boolean
jitTemporary
=
false
;
private
String
schedulingMode
=
SchedulingMode
.
FORWARD
.
name
();
private
int
anchorTimeSecond
=
0
;
public
enum
SchedulingMode
{
FORWARD
,
BACKWARD
}
}
src/main/java/com/aps/entity/basic/GlobalParam.java
View file @
6f7aeeba
...
...
@@ -39,6 +39,11 @@ public class GlobalParam {
/// </summary>
private
boolean
IsOverlap
=
false
;
/// <summary>
/// 是否全局倒排
/// </summary>
private
boolean
isJit
=
true
;
private
boolean
_smoothSetup
=
false
;
// 设置时间平滑 工序的前处理是否提前
private
boolean
_smoothChangeOver
=
true
;
// 默认true,设置时间 是否考虑换型时间
...
...
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
View file @
6f7aeeba
This diff is collapsed.
Click to expand it.
src/main/java/com/aps/service/Algorithm/GeneticDecoderBom.java
0 → 100644
View file @
6f7aeeba
package
com
.
aps
.
service
.
Algorithm
;
import
com.aps.entity.Algorithm.Chromosome
;
import
com.aps.entity.Algorithm.GAScheduleResult
;
import
com.aps.entity.Algorithm.OperationDependency
;
import
com.aps.entity.Algorithm.OrderMaterialRequirement
;
import
com.aps.entity.basic.Entry
;
import
com.aps.entity.basic.Machine
;
import
java.time.LocalDateTime
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.CopyOnWriteArrayList
;
/**
* 作者:佟礼
* 时间:2026-04-28
*/
public
class
GeneticDecoderBom
{
/**
* 计算成品可用时间(用于半成品排程)
*
* @param semiFinishedOperation 半成品工序
* @param chromosome 染色体
* @param baseTime 基准时间
* @param machineTasksCache 设备任务缓存
* @param entryIndexById 工序索引
* @param scheduleIndexById 排程索引
* @return 成品可用时间(秒)
*/
public
int
calculateFinishedAvailableTime
(
Entry
semiFinishedOperation
,
Chromosome
chromosome
,
LocalDateTime
baseTime
,
Map
<
Long
,
CopyOnWriteArrayList
<
GAScheduleResult
>>
machineTasksCache
,
Map
<
Integer
,
Entry
>
entryIndexById
,
Map
<
Integer
,
GAScheduleResult
>
scheduleIndexById
)
{
// 如果没有关联的成品工序,返回0
if
(
semiFinishedOperation
.
getTargetFinishedOperationId
()
==
null
||
semiFinishedOperation
.
getTargetFinishedOperationId
().
isEmpty
())
{
return
0
;
}
int
maxFinishedTime
=
0
;
// 遍历所有关联的成品工序,计算每个的可用时间,取最大值
for
(
Integer
finishedOperationId
:
semiFinishedOperation
.
getTargetFinishedOperationId
())
{
Entry
finishedOperation
=
entryIndexById
.
get
(
finishedOperationId
);
if
(
finishedOperation
==
null
)
{
continue
;
}
// 计算该成品工序的可用时间
int
finishedAvailableTime
=
calculateSingleFinishedAvailableTime
(
finishedOperation
,
chromosome
,
baseTime
,
machineTasksCache
,
entryIndexById
,
scheduleIndexById
);
maxFinishedTime
=
Math
.
min
(
maxFinishedTime
,
finishedAvailableTime
);
}
return
maxFinishedTime
;
}
/**
* 计算单个成品工序的可用时间
*
* @param finishedOperation 成品工序
* @param chromosome 染色体
* @param baseTime 基准时间
* @param machineTasksCache 设备任务缓存
* @param entryIndexById 工序索引
* @param scheduleIndexById 排程索引
* @return 成品工序可用时间(秒)
*/
private
int
calculateSingleFinishedAvailableTime
(
Entry
finishedOperation
,
Chromosome
chromosome
,
LocalDateTime
baseTime
,
Map
<
Long
,
CopyOnWriteArrayList
<
GAScheduleResult
>>
machineTasksCache
,
Map
<
Integer
,
Entry
>
entryIndexById
,
Map
<
Integer
,
GAScheduleResult
>
scheduleIndexById
)
{
int
maxTime
=
0
;
// 1. 计算成品前一序时间
int
prevOperationEndTime
=
0
;
if
(!
finishedOperation
.
getPrevEntryIds
().
isEmpty
())
{
for
(
OperationDependency
prevOp
:
finishedOperation
.
getPrevEntryIds
())
{
GAScheduleResult
prevResult
=
scheduleIndexById
.
get
(
prevOp
.
getPrevOperationId
());
if
(
prevResult
!=
null
)
{
prevOperationEndTime
=
Math
.
max
(
prevOperationEndTime
,
prevResult
.
getEndTime
());
}
}
}
//成品时间一定晚于prevOperationEndTime
//半成品库存只能用
maxTime
=
Math
.
max
(
maxTime
,
prevOperationEndTime
);
// 2. 计算成品当前序所用设备最后一个任务的结束时间
Long
machineId
=
finishedOperation
.
getSelectMachineID
();
if
(
machineId
==
null
&&
finishedOperation
.
getMachineOptions
()
!=
null
&&
!
finishedOperation
.
getMachineOptions
().
isEmpty
())
{
// 如果设备还未选择,使用第一个可用设备
machineId
=
finishedOperation
.
getMachineOptions
().
get
(
0
).
getMachineId
();
}
if
(
machineId
!=
null
)
{
Long
machineId1
=
machineId
;
Machine
machine
=
chromosome
.
getMachines
().
stream
().
filter
(
t
->
t
.
getId
()==
machineId1
).
findFirst
().
orElse
(
null
);
GAScheduleResult
machineTask
=
machine
.
getLastGene
();
if
(
machineTask
!=
null
)
{
int
lastEndTime
=
machineTask
.
getEndTime
();
maxTime
=
Math
.
max
(
maxTime
,
lastEndTime
);
}
}
// 3. 原材料0库存计算齐套最大时间(只计算原材料,不计算半成品)
int
rawMaterialBomTime
=
calculateRawMaterialBomTimeForFinished
(
finishedOperation
,
chromosome
);
maxTime
=
Math
.
max
(
maxTime
,
rawMaterialBomTime
);
return
maxTime
;
}
/**
* 计算成品工序的原材料齐套时间(只计算原材料MP,不计算半成品)
*/
private
int
calculateRawMaterialBomTimeForFinished
(
Entry
finishedOperation
,
Chromosome
chromosome
)
{
List
<
OrderMaterialRequirement
>
materialReqs
=
finishedOperation
.
getMaterialRequirements
();
if
(
materialReqs
==
null
)
{
return
0
;
}
int
maxTime
=
0
;
for
(
OrderMaterialRequirement
req
:
materialReqs
)
{
if
(
"MP"
.
equals
(
req
.
getMaterialTypeName
()))
{
// 只计算原材料
// 计算原材料采购提前期
int
purchaseTime
=
req
.
getPurchaseTime
()
!=
null
?
req
.
getPurchaseTime
()
:
0
;
int
checkLeadTime
=
req
.
getCheckLeadTime
()
!=
null
?
req
.
getCheckLeadTime
()
:
0
;
int
totalDays
=
purchaseTime
+
checkLeadTime
;
int
totalSeconds
=
totalDays
*
24
*
3600
;
maxTime
=
Math
.
max
(
maxTime
,
totalSeconds
);
}
}
return
maxTime
;
}
}
src/main/java/com/aps/service/Algorithm/MachineCalculator.java
View file @
6f7aeeba
This diff is collapsed.
Click to expand it.
src/main/java/com/aps/service/plan/MachineSchedulerService.java
View file @
6f7aeeba
...
...
@@ -58,6 +58,17 @@ public class MachineSchedulerService {
}
public
MachineTimeline
getOrCreateTimeline
(
Machine
machine
)
{
return
getOrCreateTimeline
(
machine
,
true
);
}
public
LocalDateTime
GetEndTime
(
Long
machineId
)
{
MachineTimeline
timeline
=
timelineCache
.
get
(
machineId
);
if
(
timeline
!=
null
)
{
return
timeline
.
getValidTo
();
}
return
null
;
}
private
MachineTimeline
generateTimeline
(
Machine
machine
)
{
...
...
src/main/java/com/aps/service/plan/PlanResultService.java
View file @
6f7aeeba
...
...
@@ -149,6 +149,7 @@ public class PlanResultService {
ScheduleParams
param
=
InitScheduleParams
();
this
.
baseTime
=
param
.
getBaseTime
();
// 1. 读取数据
// List<Machine> machines = loadData("machines.json", Machine.class);
...
...
@@ -240,7 +241,7 @@ public class PlanResultService {
_sceneService
.
saveChromosomeToFile
(
chromosome
,
SceneId
);
//
WriteScheduleSummary(chromosome);
WriteScheduleSummary
(
chromosome
);
return
chromosome
;
...
...
@@ -1909,18 +1910,21 @@ public class PlanResultService {
TargetFinishedOperationIds
));
if
(
job
.
getGeneDetails
()!=
null
)
{
for
(
ScheduleResultDetail
d
:
job
.
getGeneDetails
())
{
sb
.
append
(
String
.
format
(
"\n\t\t\t\t\t\t\t\t\t\t [%d-%d]:[%s-%s] %d"
,
d
.
getStartTime
(),
d
.
getEndTime
(),
ConvertTime
(
d
.
getStartTime
()),
ConvertTime
(
d
.
getEndTime
()),
d
.
getEndTime
()
-
d
.
getStartTime
()
));
}
}
// 追加基因详情
for
(
ScheduleResultDetail
d
:
job
.
getGeneDetails
())
{
sb
.
append
(
String
.
format
(
"\n\t\t\t\t\t\t\t\t\t\t [%d-%d]:[%s-%s] %d"
,
d
.
getStartTime
(),
d
.
getEndTime
(),
ConvertTime
(
d
.
getStartTime
()),
ConvertTime
(
d
.
getEndTime
()),
d
.
getEndTime
()
-
d
.
getStartTime
()
));
}
FileHelper
.
writeLogFile
(
sb
.
toString
());
...
...
src/main/resources/application.yml
View file @
6f7aeeba
...
...
@@ -56,11 +56,11 @@ spring:
oracle
:
driver-class-name
:
oracle.jdbc.OracleDriver
url
:
jdbc:oracle:thin:@//39.100.77.7:1522/ORCLPDB1
# ORCL为你的Oracle实例名
# username: mes # 替换为你的Oracle用户名
# password: root_mes123456 # 替换为你的Oracle密码
# url: jdbc:oracle:thin:@//39.100.78.207:7002/ORCLPDB1 # ORCL为你的Oracle实例名
username
:
mes
# 替换为你的Oracle用户名
password
:
root_mes123456
# 替换为你的Oracle密码
# url: jdbc:oracle:thin:@//39.100.78.207:7002/ORCLPDB1 # ORCL为你的Oracle实例名
# username: mes # 替换为你的Oracle用户名
# password: root_mes123456 # 替换为你的Oracle密码
# sqlserver:
# driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
# url: jdbc:sqlserver://192.168.0.181:1434;databaseName=mes;encrypt=false
...
...
src/test/java/com/aps/demo/PlanResultServiceTest.java
View file @
6f7aeeba
...
...
@@ -40,12 +40,14 @@ public class PlanResultServiceTest {
// sortService.test1();
// nsgaiiUtils.Test();
planResultService
.
execute2
(
"AD62106303684459949A7323D114BF60"
);
//2000
//
planResultService.execute2("AD62106303684459949A7323D114BF60");//2000
// planResultService.execute2("E29F2B3ADA8149F6B916B5119296A92B");//2000
planResultService
.
execute2
(
"15210B13B88A453F8B84AAC7F16C7541"
);
//2000
// planResultService.execute2("E29F2B3ADA8149F6B916B5119296A92B");//2000
// planResultService.execute2("E2CD1FC6FF9B4B19A59FEC7F846D4952");//600
// planResultService.execute2("EAF3C94B8F3345278F226C94FB0FED86");//bom
//
planResultService.execute2("6D63146BE5C84A78B5AB044327BA55BD");//2000
//
planResultService.execute2("6D63146BE5C84A78B5AB044327BA55BD");//2000
// planResultService.execute2("6D63146BE5C84A78B5AB044327BA55BD");//5000
// planResultService.execute2("C8B533BD8944405B9A2F8823C575C204");//500
// planResultService.execute2("EFDD34E4B5BC434BAEAE6A84DFCD4E7B");//20
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment