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
85fa9adb
Commit
85fa9adb
authored
May 27, 2026
by
DESKTOP-VKRD9QF\Administration
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://39.100.78.207:1213/tongli/hyh.apsj
parents
59ee6455
8cd195f9
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
1217 additions
and
11 deletions
+1217
-11
pom.xml
pom.xml
+6
-0
ScheduleParams.java
src/main/java/com/aps/entity/Algorithm/ScheduleParams.java
+7
-0
Entry.java
src/main/java/com/aps/entity/basic/Entry.java
+5
-0
CpSatFjspModel.java
src/main/java/com/aps/service/Algorithm/CpSatFjspModel.java
+417
-0
CpSatInitializer.java
...main/java/com/aps/service/Algorithm/CpSatInitializer.java
+268
-0
GeneticDecoder.java
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
+15
-6
HybridAlgorithm.java
src/main/java/com/aps/service/Algorithm/HybridAlgorithm.java
+3
-1
Initialization.java
src/main/java/com/aps/service/Algorithm/Initialization.java
+162
-0
OperationSplitService.java
...java/com/aps/service/Algorithm/OperationSplitService.java
+329
-0
RoutingDataService.java
...in/java/com/aps/service/Algorithm/RoutingDataService.java
+1
-0
PlanResultService.java
src/main/java/com/aps/service/plan/PlanResultService.java
+3
-3
PlanResultServiceTest.java
src/test/java/com/aps/demo/PlanResultServiceTest.java
+1
-1
No files found.
pom.xml
View file @
85fa9adb
...
...
@@ -111,6 +111,12 @@
<artifactId>
hutool-all
</artifactId>
<version>
5.8.16
</version>
</dependency>
<!-- OR-Tools CP-SAT 约束规划求解器 -->
<dependency>
<groupId>
com.google.ortools
</groupId>
<artifactId>
ortools-java
</artifactId>
<version>
9.7.2996
</version>
</dependency>
</dependencies>
<build>
...
...
src/main/java/com/aps/entity/Algorithm/ScheduleParams.java
View file @
85fa9adb
...
...
@@ -74,6 +74,13 @@ public class ScheduleParams {
return
populationSize
;
}
/// <summary>
/// 种群规模
/// </summary>
public
void
setPopulationSize
(
int
populationSize
)
{
populationSize
=
populationSize
;
}
/// <summary>
/// 最大迭代次数
/// </summary>
...
...
src/main/java/com/aps/entity/basic/Entry.java
View file @
85fa9adb
...
...
@@ -64,6 +64,11 @@ public class Entry {
*/
private
String
mainId
;
/**
* 拆分来源ID:当state=1时,记录原始工序的id,用于识别同一原始工序的拆分子工序
*/
private
transient
Integer
splitSourceId
;
/**
* 离散参数
*/
...
...
src/main/java/com/aps/service/Algorithm/CpSatFjspModel.java
0 → 100644
View file @
85fa9adb
This diff is collapsed.
Click to expand it.
src/main/java/com/aps/service/Algorithm/CpSatInitializer.java
0 → 100644
View file @
85fa9adb
This diff is collapsed.
Click to expand it.
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
View file @
85fa9adb
...
...
@@ -597,7 +597,7 @@ public class GeneticDecoder {
//存储锚点时间
if
(
isJit
)
{
orderSchedulingInfo
.
put
(
order
.
getId
(),
new
AbstractMap
.
SimpleEntry
<>(
fals
e
,
end
));
orderSchedulingInfo
.
put
(
order
.
getId
(),
new
AbstractMap
.
SimpleEntry
<>(
tru
e
,
end
));
}
else
{
orderSchedulingInfo
.
put
(
order
.
getId
(),
new
AbstractMap
.
SimpleEntry
<>(
false
,
0
));
...
...
@@ -1408,11 +1408,11 @@ public class GeneticDecoder {
int
bomtime
=
0
;
if
(
needMaterialCheck
&&
islockMachineTime
)
{
bomtime
=
getOperationBOMTime
(
operation
,
chromosome
,
earliestStartTime
,
2
);
if
(!
isJit
)
{
bomtime
=
getOperationBOMTime
(
operation
,
chromosome
,
earliestStartTime
,
2
);
earliestStartTime
=
Math
.
max
(
earliestStartTime
,
bomtime
);
}
}
// 正式落排前,再取一次当前机台最后一道工序,保证换型计算基于最新排程结果。
...
...
@@ -1524,7 +1524,16 @@ public class GeneticDecoder {
// }
//扣库存
if
(
needMaterialCheck
&&
islockMachineTime
)
{
if
(!
isJit
)
{
EditOperationBOMTime
(
operation
,
chromosome
,
startTime
,
machineTasksCache
,
entryIndexById
,
scheduleIndexById
);
}
else
{
int
bomtime1
=
getOperationBOMTime
(
operation
,
chromosome
,
startTime
,
2
);
if
(
bomtime1
<=
startTime
)
{
EditOperationBOMTime
(
operation
,
chromosome
,
startTime
,
machineTasksCache
,
entryIndexById
,
scheduleIndexById
);
}
}
}
//换型时间是否占用设备加工时间
//10:00 开始上班 前面的任务:24:00 结束 开始换型 休息时间 10小时
...
...
src/main/java/com/aps/service/Algorithm/HybridAlgorithm.java
View file @
85fa9adb
...
...
@@ -117,7 +117,9 @@ public class HybridAlgorithm {
// 步骤1:使用构造启发式算法生成初始种群
FileHelper
.
writeLogFile
(
"构造启发式初始化-----------开始-------"
);
List
<
Chromosome
>
population
=
initialization
.
generateHeuristicInitialPopulation
(
param
);
// List<Chromosome> population = initialization.generateHeuristicInitialPopulation(param);
List
<
Chromosome
>
population
=
initialization
.
generateHybridInitialPopulation
(
param
);
FileHelper
.
writeLogFile
(
"构造启发式初始化-----------结束-------"
);
...
...
src/main/java/com/aps/service/Algorithm/Initialization.java
View file @
85fa9adb
package
com
.
aps
.
service
.
Algorithm
;
import
com.aps.common.util.FileHelper
;
import
com.aps.common.util.ProductionDeepCopyUtil
;
import
com.aps.entity.Algorithm.Chromosome
;
import
com.aps.entity.Algorithm.GlobalOperationInfo
;
...
...
@@ -1071,6 +1072,167 @@ public class Initialization {
return
shuffled
;
}
/**
* HybridAlgorithm 专用混合初始种群
* 先用 CP-SAT 生成高质量种子,剩余用原有构造启发式补足
*/
public
List
<
Chromosome
>
generateHybridInitialPopulation
(
ScheduleParams
param
)
{
int
populationSize
=
param
.
getPopulationSize
();
this
.
baseTime
=
param
.
getBaseTime
();
List
<
GlobalOperationInfo
>
sharedGlobalOpList
=
generateGlobalOpList
();
List
<
Chromosome
>
population
=
new
ArrayList
<>(
populationSize
);
int
cpSatTarget
=
Math
.
min
(
Math
.
max
(
populationSize
/
5
,
2
),
6
);
int
timeBudgetSec
=
Math
.
max
(
populationSize
*
2
,
15
);
CpSatInitializer
cpSatInit
=
new
CpSatInitializer
(
allOperations
,
machines
,
orders
,
param
.
getBaseTime
());
List
<
Chromosome
>
cpSatResults
=
cpSatInit
.
generate
(
sharedGlobalOpList
,
cpSatTarget
,
timeBudgetSec
);
if
(!
cpSatResults
.
isEmpty
())
{
for
(
Chromosome
chromo
:
cpSatResults
)
{
chromo
.
setOrders
(
new
CopyOnWriteArrayList
<>(
orders
));
chromo
.
setGlobalOpList
(
deepCopyGlobalOpList
(
sharedGlobalOpList
));
PriorityCheckResult
r
=
Initialization
.
checkPriorityOrder
(
chromo
);
// if (r.isPerfect()) {
// population.add(chromo);
//
// }
}
population
.
addAll
(
cpSatResults
);
FileHelper
.
writeLogFile
(
"[Hybrid初始化] CP-SAT贡献 "
+
cpSatResults
.
size
()
+
" 个高质量种子"
);
}
int
remaining
=
populationSize
-
population
.
size
();
if
(
remaining
>
0
)
{
ScheduleParams
subParam
=
new
ScheduleParams
();
subParam
.
setPopulationSize
(
remaining
);
subParam
.
setBaseTime
(
param
.
getBaseTime
());
List
<
Chromosome
>
heuristicPopulation
=
generateHeuristicInitialPopulation
(
subParam
);
for
(
Chromosome
chromo
:
heuristicPopulation
)
{
chromo
.
setOrders
(
new
CopyOnWriteArrayList
<>(
orders
));
}
population
.
addAll
(
heuristicPopulation
);
}
long
cpSatCount
=
population
.
stream
()
.
filter
(
c
->
c
.
getGsOrls
()
==
4
).
count
();
FileHelper
.
writeLogFile
(
String
.
format
(
"[Hybrid初始化] 总种群=%d, CP-SAT=%d, 启发式=%d"
,
population
.
size
(),
cpSatCount
,
population
.
size
()
-
cpSatCount
));
return
population
;
}
private
List
<
GlobalOperationInfo
>
deepCopyGlobalOpList
(
List
<
GlobalOperationInfo
>
source
)
{
List
<
GlobalOperationInfo
>
copy
=
new
ArrayList
<>(
source
.
size
());
for
(
GlobalOperationInfo
info
:
source
)
{
GlobalOperationInfo
newInfo
=
new
GlobalOperationInfo
();
newInfo
.
setGlobalOpId
(
info
.
getGlobalOpId
());
newInfo
.
setGroupId
(
info
.
getGroupId
());
newInfo
.
setSequence
(
info
.
getSequence
());
newInfo
.
setOp
(
info
.
getOp
());
copy
.
add
(
newInfo
);
}
return
copy
;
}
/**
* 检查染色体的operationSequencing是否遵守Priority排序
* Priority值越小优先级越高(1最先排,99最后排)
*
* @param chromo 待检查的染色体
* @return PriorityCheckResult 包含违反次数、严重度、详细报告
*/
public
static
PriorityCheckResult
checkPriorityOrder
(
Chromosome
chromo
)
{
List
<
GlobalOperationInfo
>
globalOpList
=
chromo
.
getGlobalOpList
();
List
<
Integer
>
os
=
chromo
.
getOperationSequencing
();
if
(
os
==
null
||
os
.
isEmpty
()
||
globalOpList
==
null
||
globalOpList
.
isEmpty
())
{
return
new
PriorityCheckResult
(
0
,
0
,
0
,
"无数据"
);
}
Map
<
Integer
,
Double
>
groupPriority
=
new
HashMap
<>();
Map
<
Integer
,
List
<
Entry
>>
groupOps
=
new
HashMap
<>();
for
(
GlobalOperationInfo
info
:
globalOpList
)
{
int
gid
=
info
.
getGroupId
();
groupPriority
.
putIfAbsent
(
gid
,
info
.
getOp
().
getPriority
());
groupOps
.
computeIfAbsent
(
gid
,
k
->
new
ArrayList
<>()).
add
(
info
.
getOp
());
}
int
violationCount
=
0
;
int
totalSeverity
=
0
;
double
maxSingleSeverity
=
0
;
StringBuilder
detail
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
os
.
size
()
-
1
;
i
++)
{
int
gidA
=
os
.
get
(
i
);
int
gidB
=
os
.
get
(
i
+
1
);
if
(
gidA
==
gidB
)
continue
;
double
priA
=
groupPriority
.
getOrDefault
(
gidA
,
Double
.
MAX_VALUE
);
double
priB
=
groupPriority
.
getOrDefault
(
gidB
,
Double
.
MAX_VALUE
);
if
(
priA
>
priB
)
{
double
severity
=
priA
-
priB
;
violationCount
++;
totalSeverity
+=
severity
;
maxSingleSeverity
=
Math
.
max
(
maxSingleSeverity
,
severity
);
if
(
detail
.
length
()
<
800
)
{
detail
.
append
(
String
.
format
(
" [%d→%d] groupId=%d(优先级%d) 排在 groupId=%d(优先级%d) 之前,差距=%d\n"
,
i
,
i
+
1
,
gidA
,
priA
,
gidB
,
priB
,
severity
));
}
}
}
String
report
=
String
.
format
(
"Priority检查: 违反次数=%d, 总严重度=%d, 最大单次差距=%f, "
+
"工序组数=%d, 不同优先级组数=%d\n%s"
,
violationCount
,
totalSeverity
,
maxSingleSeverity
,
groupPriority
.
size
(),
new
HashSet
<>(
groupPriority
.
values
()).
size
(),
detail
.
toString
());
return
new
PriorityCheckResult
(
violationCount
,
totalSeverity
,
maxSingleSeverity
,
report
);
}
/**
* Priority检查结果
*/
public
static
class
PriorityCheckResult
{
public
final
int
violationCount
;
public
final
int
totalSeverity
;
public
final
double
maxSingleSeverity
;
public
final
String
report
;
PriorityCheckResult
(
int
violationCount
,
int
totalSeverity
,
double
maxSingleSeverity
,
String
report
)
{
this
.
violationCount
=
violationCount
;
this
.
totalSeverity
=
totalSeverity
;
this
.
maxSingleSeverity
=
maxSingleSeverity
;
this
.
report
=
report
;
}
public
boolean
isPerfect
()
{
return
violationCount
==
0
;
}
@Override
public
String
toString
()
{
return
report
;
}
}
/**
* 辅助类:用于权重排序
*/
...
...
src/main/java/com/aps/service/Algorithm/OperationSplitService.java
0 → 100644
View file @
85fa9adb
This diff is collapsed.
Click to expand it.
src/main/java/com/aps/service/Algorithm/RoutingDataService.java
View file @
85fa9adb
...
...
@@ -409,6 +409,7 @@ if(entry.getMachineOptions()!=null)
if
(
machine
.
getCapacityTypeName
()
==
null
)
{
machine
.
setCapacityTypeName
(
equipinfo
.
getCapacityTypeName
());
}
}
else
{
machine
.
setCode
(
PlanResource
.
getReferenceCode
());
machine
.
setName
(
PlanResource
.
getTitle
());
...
...
src/main/java/com/aps/service/plan/PlanResultService.java
View file @
85fa9adb
...
...
@@ -177,7 +177,7 @@ public class PlanResultService {
* 后续会按场景创建人自动回退到可用的策略配置。
*/
public
Chromosome
execute2
(
String
SceneId
)
{
return
execute2
(
SceneId
,
null
,
nul
l
,
null
);
return
execute2
(
SceneId
,
2361
l
,
241
l
,
null
);
}
/**
...
...
@@ -188,7 +188,7 @@ public class PlanResultService {
try
{
ScheduleParams
param
=
InitScheduleParams
();
// param.setBaseTime(LocalDateTime.of(2026, 1, 1, 0, 0, 0));
this
.
baseTime
=
param
.
getBaseTime
();
// 策略读取入口:优先使用前端传入的 userId;没传时用 sceneId 查场景创建人。
Long
effectiveUserId
=
scheduleStrategyService
.
resolveScheduleUserId
(
SceneId
,
userId
);
...
...
@@ -2246,7 +2246,7 @@ if(job.getGeneDetails()!=null)
ApsTimeConfig
apsTimeConfig
=
apsTimeConfigMapper
.
selectOne
(
queryWrapper
);
ScheduleParams
param
=
new
ScheduleParams
();
param
.
setBaseTime
(
LocalDateTime
.
of
(
202
5
,
1
1
,
1
,
0
,
0
,
0
));
param
.
setBaseTime
(
LocalDateTime
.
of
(
202
6
,
1
,
1
,
0
,
0
,
0
));
if
(
apsTimeConfig
!=
null
)
{
if
(
apsTimeConfig
.
getBaseTime
()!=
null
)
{
...
...
src/test/java/com/aps/demo/PlanResultServiceTest.java
View file @
85fa9adb
...
...
@@ -42,7 +42,7 @@ public class PlanResultServiceTest {
// nsgaiiUtils.Test();
// planResultService.execute2("64E64F6B68094AF38CEDC418630C3CC2");//2000
planResultService
.
execute2
(
"
72744D094BAB45948F5172E84C78B260
"
);
//2000
planResultService
.
execute2
(
"
E1448B3C9C8743DEAB39708F2CFE348A
"
);
//2000
// planResultService.execute2("15210B13B88A453F8B84AAC7F16C7541");//2000
...
...
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