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
9389ef11
Commit
9389ef11
authored
Dec 29, 2025
by
Tong Li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
遗传算法-优化编译逻辑
parent
c925515f
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
51 additions
and
40 deletions
+51
-40
GeneticAlgorithm.java
...main/java/com/aps/service/Algorithm/GeneticAlgorithm.java
+9
-4
GeneticDecoder.java
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
+3
-6
GeneticOperations.java
...ain/java/com/aps/service/Algorithm/GeneticOperations.java
+20
-8
NSGAIIUtils.java
src/main/java/com/aps/service/Algorithm/NSGAIIUtils.java
+3
-0
PlanResultService.java
src/main/java/com/aps/service/plan/PlanResultService.java
+13
-20
PlanResultServiceTest.java
src/test/java/com/aps/demo/PlanResultServiceTest.java
+3
-2
No files found.
src/main/java/com/aps/service/Algorithm/GeneticAlgorithm.java
View file @
9389ef11
...
...
@@ -76,7 +76,7 @@ public class GeneticAlgorithm {
// 预生成全局工序列表(所有初始化方法共享同一顺序)
List
<
GlobalOperationInfo
>
globalOpList
=
initialization
.
generateGlobalOpList
();
FileHelper
.
writeLogFile
(
"初始化种群-----------开始-------"
);
FileHelper
.
writeLogFile
(
"初始化种群-----------开始-------"
+
allOperations
.
get
(
0
).
getSceneId
()
);
// 步骤1:初始化种群
List
<
Chromosome
>
population
=
initialization
.
generateInitialPopulation
(
param
,
globalOpList
);
...
...
@@ -99,8 +99,9 @@ public class GeneticAlgorithm {
.
sorted
((
c1
,
c2
)
->
Double
.
compare
(
c2
.
getWeightedObjective
(),
c1
.
getWeightedObjective
()))
.
findFirst
()
.
orElse
(
null
);
FileHelper
.
writeLogFile
(
String
.
format
(
"KPI---%f-----初始-----%s----"
,
best
.
getWeightedObjective
(),
best
.
getID
()));
double
bestFitness
=
0
;
double
bestFitness
=
best
.
getWeightedObjective
()
;
int
Iteration
=
0
;
// 步骤2:迭代进化
FileHelper
.
writeLogFile
(
"迭代进化-----------开始-------"
+
param
.
getMaxIterations
());
...
...
@@ -185,15 +186,19 @@ public class GeneticAlgorithm {
.
sorted
((
c1
,
c2
)
->
Double
.
compare
(
c2
.
getWeightedObjective
(),
c1
.
getWeightedObjective
()))
.
findFirst
()
.
orElse
(
null
);
FileHelper
.
writeLogFile
(
String
.
format
(
"KPI---%f-----"
+
iter
+
"-----%s----"
,
best
.
getWeightedObjective
(),
best
.
getID
()));
if
(
bestFitness
<
best
.
getWeightedObjective
())
{
bestFitness
=
best
.
getWeightedObjective
();
Iteration
=
1
;
}
else
{
Iteration
++;
}
if
(
Iteration
>
10
)
if
(
Iteration
>
5
)
{
break
;
}
...
...
@@ -209,7 +214,7 @@ public class GeneticAlgorithm {
LocalDateTime
endtime
=
LocalDateTime
.
now
();
FileHelper
.
writeLogFile
(
String
.
format
(
"排产-----------结束---
----耗时%d----"
,
DateTimeUtil
.
diffDuration
(
starttime
,
endtime
).
getSeconds
())
);
FileHelper
.
writeLogFile
(
String
.
format
(
"排产-----------结束---
%s----耗时%d----"
,
allOperations
.
get
(
0
).
getSceneId
()
,
DateTimeUtil
.
diffDuration
(
starttime
,
endtime
).
getSeconds
())
);
// 步骤3:返回最优解
return
best
;
...
...
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
View file @
9389ef11
...
...
@@ -339,10 +339,7 @@ if(finishedOrder==null||finishedOrder.size()==0)
.
filter
(
m
->
m
.
getId
()
==
machineId
)
.
findFirst
()
.
orElse
(
null
);
if
(
machine
==
null
)
{
int
i
=
1
+
2
;
}
// int changeoverTime =0; //(lastDiscreteParameter.isEmpty() ||
// lastDiscreteParameter.equals(currentOp.getDiscreteParameter())) ? 0 : 0;
...
...
@@ -374,8 +371,8 @@ if(finishedOrder==null||finishedOrder.size()==0)
int
preTime
=
machineOption
.
getPreTime
();
int
setupTime
=
calculateSetupTime
(
chromosome
.
getResult
(),
operation
,
machine
,
machineOption
);
//
FileHelper.writeLogFile (" 处理时间: " + processingTime + ", 后处理: " + teardownTime +
//
", 前处理: " + preTime + ", 换型: " + setupTime+ ", 数量: " + operation.getQuantity());
FileHelper
.
writeLogFile
(
" 处理时间: "
+
processingTime
+
", 后处理: "
+
teardownTime
+
", 前处理: "
+
preTime
+
", 换型: "
+
setupTime
+
", 数量: "
+
operation
.
getQuantity
());
// 确定任务的最早开始时间(基于前一道工序的完整结束时间,包含后处理)
...
...
src/main/java/com/aps/service/Algorithm/GeneticOperations.java
View file @
9389ef11
...
...
@@ -8,6 +8,7 @@ import com.aps.entity.basic.MachineOption;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
java.util.stream.IntStream
;
/**
* 作者:佟礼
...
...
@@ -240,18 +241,29 @@ public class GeneticOperations {
private
void
mutateMachineSelection
(
Chromosome
chromosome
,
List
<
GlobalOperationInfo
>
globalOpList
,
double
baseMutationProb
)
{
// 计算变异位置数量
int
r
=
Math
.
max
(
1
,
(
int
)
(
chromosome
.
getMachineSelection
().
size
()
*
baseMutationProb
));
List
<
Entry
>
entrys
=
allOperations
.
stream
().
filter
(
t
->
t
.
getMachineOptions
().
size
()>
1
).
collect
(
Collectors
.
toList
());
if
(
entrys
==
null
||
entrys
.
size
()==
0
)
{
return
;
}
Integer
count
=
entrys
.
size
();
int
r
=
Math
.
max
(
1
,
(
int
)
(
count
*
baseMutationProb
));
int
i
=
0
;
while
(
i
<
r
)
{
int
pos
=
rnd
.
nextInt
(
chromosome
.
getMachineSelection
().
size
()
);
int
pos
1
=
rnd
.
nextInt
(
count
);
// 获取对应工序
GlobalOperationInfo
opInfo
=
globalOpList
.
get
(
pos
);
Entry
operation
=
opInfo
.
getOp
();
Entry
operation
=
entrys
.
get
(
pos1
);
int
pos
=
IntStream
.
range
(
0
,
globalOpList
.
size
())
.
filter
(
h
->
operation
.
getId
()==
globalOpList
.
get
(
h
).
getOp
().
getId
())
.
findFirst
().
orElse
(
0
);
int
machineSeq
=
chromosome
.
getMachineSelection
().
get
(
pos
);
if
(
operation
.
getMachineOptions
().
size
()
==
1
)
{
continue
;
}
else
{
// 选择当前所选设备外最短加工时间的机器
List
<
MachineOption
>
optionalMachines
=
operation
.
getMachineOptions
();
// 找到当前选中的机器
...
...
@@ -265,7 +277,7 @@ public class GeneticOperations {
machineSeq
=
optionalMachines
.
indexOf
(
minLoadMachine
)
+
1
;
chromosome
.
getMachineSelection
().
set
(
pos
,
machineSeq
);
i
++;
}
}
}
...
...
src/main/java/com/aps/service/Algorithm/NSGAIIUtils.java
View file @
9389ef11
...
...
@@ -40,6 +40,9 @@ public class NSGAIIUtils {
*/
public
List
<
List
<
Chromosome
>>
parallelFastNonDominatedSort
(
List
<
Chromosome
>
population
)
{
int
popSize
=
population
.
size
();
// 步骤1:预处理 - 计算归一化目标值和加权目标值
preprocessObjectives
(
population
);
if
(
popSize
<=
taskCount
*
10
)
{
// 小规模种群直接串行
return
fastNonDominatedSort
(
population
);
}
...
...
src/main/java/com/aps/service/plan/PlanResultService.java
View file @
9389ef11
...
...
@@ -766,20 +766,17 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
// List<Machine> machines = _routingDataService.InitCalendarToAllMachines(SceneId, ProdEquipments, machineScheduler, IsUseCalendar);
List
<
Machine
>
machines
=
(
List
<
Machine
>)
GlobalCacheUtil
.
get
(
"machines"
);
if
(
machines
!=
null
)
{
if
(
machines
==
null
||
machines
.
size
()==
0
)
{
return
machines
;
}
machines
=
(
List
<
Machine
>)
redisUtils
.
get
(
"machines"
);
if
(
machines
!=
null
)
{
machines
=
(
List
<
Machine
>)
redisUtils
.
get
(
"machines"
);
if
(
machines
==
null
||
machines
.
size
()==
0
)
{
return
machines
;
machines
=
InitCalendarToAllMachines
()
;
}
machines
=
InitCalendarToAllMachines
();
}
FileHelper
.
writeLogFile
(
"初始化设备日历-----------结束-------"
);
GlobalCacheUtil
.
put
(
"machines"
,
machines
,
10
,
TimeUnit
.
MINUTES
);
...
...
@@ -1040,22 +1037,18 @@ private GlobalParam InitGlobalParam()
// .eq(MaterialInfo::getIsdeleted,0)
// .list();
List
<
Material
>
cmaterials
=
(
List
<
Material
>)
GlobalCacheUtil
.
get
(
"material"
);
if
(
cmaterials
!=
null
)
{
materials
=
(
List
<
Material
>)
GlobalCacheUtil
.
get
(
"material"
);
if
(
materials
==
null
||
materials
.
size
()==
0
)
{
return
cmaterials
;
}
cmaterials
=
(
List
<
Material
>)
redisUtils
.
get
(
"material"
);
if
(
cmaterials
!=
null
)
{
return
cmaterials
;
materials
=
(
List
<
Material
>)
redisUtils
.
get
(
"material"
);
if
(
materials
==
null
||
materials
.
size
()==
0
)
{
}
materials
=
getMaterials
();
materials
=
getMaterials
();
}
}
GlobalCacheUtil
.
put
(
"material"
,
materials
,
10
,
TimeUnit
.
MINUTES
);
FileHelper
.
writeLogFile
(
"初始化物料-----------结束-------"
);
...
...
src/test/java/com/aps/demo/PlanResultServiceTest.java
View file @
9389ef11
...
...
@@ -28,10 +28,11 @@ public class PlanResultServiceTest {
public
void
testExecute
()
{
// planResultService.getMaterials();
// RangeSubtractUtil.test();
planResultService
.
testSceneChromsome
(
"qwerty"
);
//
planResultService.testSceneChromsome("qwerty");
// Chromosome chromosome= planResultService.moveChromosome("qwerty",3);
//
planResultService.execute2("8835EF6E1C8A491D99B16DE59160ED64");
planResultService
.
execute2
(
"8835EF6E1C8A491D99B16DE59160ED64"
);
// planResultService.execute2("BE037838EF074B07B87D7DE763107398");
// planResultService.execute2("31EC5BAF7F6B41DFB79AB031D81C53C0");
// LocalDateTime t= LocalDateTime.of(2025, 11, 15, 6, 51, 11);
// List<Integer> opids=new ArrayList<>();
// opids.add(1);
...
...
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