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
dd36e456
Commit
dd36e456
authored
Jan 15, 2026
by
Tong Li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化非分配排序
parent
4965288c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
188 additions
and
29 deletions
+188
-29
GeneticAlgorithm.java
...main/java/com/aps/service/Algorithm/GeneticAlgorithm.java
+9
-16
NSGAIIUtils.java
src/main/java/com/aps/service/Algorithm/NSGAIIUtils.java
+178
-12
PlanResultServiceTest.java
src/test/java/com/aps/demo/PlanResultServiceTest.java
+1
-1
No files found.
src/main/java/com/aps/service/Algorithm/GeneticAlgorithm.java
View file @
dd36e456
...
@@ -110,12 +110,12 @@ public class GeneticAlgorithm {
...
@@ -110,12 +110,12 @@ public class GeneticAlgorithm {
FileHelper
.
writeLogFile
(
"初始化批量解码-----------开始-------"
);
FileHelper
.
writeLogFile
(
"初始化批量解码-----------开始-------"
);
Chromosomedecode
(
param
,
allOperations
,
globalOpList
,
population
);
Chromosomedecode
(
param
,
allOperations
,
globalOpList
,
population
);
FileHelper
.
writeLogFile
(
"初始化批量解码-----------结束-------"
);
FileHelper
.
writeLogFile
(
"初始化批量解码-----------结束-------"
);
List
<
List
<
Chromosome
>>
f
ronts
=
_nsgaIIUtils
.
parallelFastNonDominatedSort
(
population
);
List
<
List
<
Chromosome
>>
combinedF
ronts
=
_nsgaIIUtils
.
parallelFastNonDominatedSort
(
population
);
int
ordercount
=
globalOpList
.
stream
()
int
ordercount
=
globalOpList
.
stream
()
.
mapToInt
(
GlobalOperationInfo:
:
getGroupId
)
.
mapToInt
(
GlobalOperationInfo:
:
getGroupId
)
.
max
()
.
max
()
.
orElse
(
0
);
.
orElse
(
0
);
Chromosome
best
=
GetBest
(
f
ronts
,
"初始"
);
Chromosome
best
=
GetBest
(
combinedF
ronts
,
"初始"
);
// best=fronts.get(0).stream()
// best=fronts.get(0).stream()
// .max(Comparator.comparingDouble(Chromosome::getFitness))
// .max(Comparator.comparingDouble(Chromosome::getFitness))
...
@@ -165,6 +165,7 @@ public class GeneticAlgorithm {
...
@@ -165,6 +165,7 @@ public class GeneticAlgorithm {
List
<
Chromosome
>
nextPopulation
=
new
ArrayList
<>();
List
<
Chromosome
>
nextPopulation
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
selected
.
size
();
i
+=
2
)
{
for
(
int
i
=
0
;
i
<
selected
.
size
();
i
+=
2
)
{
if
(
i
+
1
>=
selected
.
size
())
{
if
(
i
+
1
>=
selected
.
size
())
{
selected
.
get
(
i
).
setID
(
UUID
.
randomUUID
().
toString
());
nextPopulation
.
add
(
selected
.
get
(
i
));
nextPopulation
.
add
(
selected
.
get
(
i
));
break
;
break
;
}
}
...
@@ -188,6 +189,7 @@ public class GeneticAlgorithm {
...
@@ -188,6 +189,7 @@ public class GeneticAlgorithm {
for
(
Chromosome
chromosome
:
nextPopulation
)
{
for
(
Chromosome
chromosome
:
nextPopulation
)
{
if
(
rnd
.
nextDouble
()
<
param
.
getMutationProb
())
{
if
(
rnd
.
nextDouble
()
<
param
.
getMutationProb
())
{
Chromosome
chromosome1
=
ProductionDeepCopyUtil
.
deepCopy
(
chromosome
,
Chromosome
.
class
);
Chromosome
chromosome1
=
ProductionDeepCopyUtil
.
deepCopy
(
chromosome
,
Chromosome
.
class
);
chromosome1
.
setID
(
UUID
.
randomUUID
().
toString
());
geneticOps
.
mutate
(
chromosome1
,
globalOpList
);
geneticOps
.
mutate
(
chromosome1
,
globalOpList
);
nextPopulation1
.
add
(
chromosome1
);
nextPopulation1
.
add
(
chromosome1
);
}
}
...
@@ -209,12 +211,15 @@ public class GeneticAlgorithm {
...
@@ -209,12 +211,15 @@ public class GeneticAlgorithm {
// List<Chromosome> elites = population1.subList(0, param.getElitismCount());
// List<Chromosome> elites = population1.subList(0, param.getElitismCount());
List
<
Chromosome
>
newPopulation
=
new
ArrayList
<>();
List
<
Chromosome
>
newPopulation
=
new
ArrayList
<>();
newPopulation
.
addAll
(
population
);
//保留一定数量的上一代
List
<
Chromosome
>
populationcopy
=
_nsgaIIUtils
.
selectNextPopulation
(
combinedFronts
,
param
.
getPopulationSize
()/
5
);
newPopulation
.
addAll
(
populationcopy
);
newPopulation
.
addAll
(
nextPopulation
);
newPopulation
.
addAll
(
nextPopulation
);
newPopulation
=
chromosomeDistinct1
(
newPopulation
);
newPopulation
=
chromosomeDistinct1
(
newPopulation
);
FileHelper
.
writeLogFile
(
"非支配排序-----------开始-------"
);
FileHelper
.
writeLogFile
(
"非支配排序-----------开始-------"
);
// 2.7 非支配排序
// 2.7 非支配排序
List
<
List
<
Chromosome
>>
combinedFronts
=
_nsgaIIUtils
.
parallelFastNonDominatedSort
(
newPopulation
);
combinedFronts
=
_nsgaIIUtils
.
parallelFastNonDominatedSort
(
newPopulation
);
FileHelper
.
writeLogFile
(
"非支配排序-----------结束-------"
);
FileHelper
.
writeLogFile
(
"非支配排序-----------结束-------"
);
// 2.8 选择下一代种群
// 2.8 选择下一代种群
population
=
_nsgaIIUtils
.
selectNextPopulation
(
combinedFronts
,
param
.
getPopulationSize
());
population
=
_nsgaIIUtils
.
selectNextPopulation
(
combinedFronts
,
param
.
getPopulationSize
());
...
@@ -291,14 +296,9 @@ return population;
...
@@ -291,14 +296,9 @@ return population;
}
}
FileHelper
.
writeLogFile
(
String
.
format
(
"排产-----------方案数量---%d-------"
,
population
.
size
()
));
List
<
Chromosome
>
population1
=
population
.
stream
().
filter
(
t
->
t
.
getGeneStr
()==
null
).
collect
(
Collectors
.
toList
());
List
<
Chromosome
>
population1
=
population
.
stream
().
filter
(
t
->
t
.
getGeneStr
()==
null
).
collect
(
Collectors
.
toList
());
if
(
population1
!=
null
&&
population1
.
size
()>
0
)
{
FileHelper
.
writeLogFile
(
String
.
format
(
"排产-----------方案GeneStrnull数量---%d-------"
,
population1
.
size
()
));
}
population
=
population
.
stream
()
population
=
population
.
stream
()
.
collect
(
Collectors
.
toMap
(
.
collect
(
Collectors
.
toMap
(
Chromosome:
:
getGeneStr
,
// key:去重的字段(GeneStr)
Chromosome:
:
getGeneStr
,
// key:去重的字段(GeneStr)
...
@@ -308,7 +308,6 @@ if(population1!=null&&population1.size()>0)
...
@@ -308,7 +308,6 @@ if(population1!=null&&population1.size()>0)
.
values
()
// 获取去重后的
.
values
()
// 获取去重后的
.
stream
()
.
stream
()
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
FileHelper
.
writeLogFile
(
String
.
format
(
"排产-----------方案数量---%d-------"
,
population
.
size
()
));
return
population
;
return
population
;
}
}
...
@@ -321,14 +320,9 @@ if(population1!=null&&population1.size()>0)
...
@@ -321,14 +320,9 @@ if(population1!=null&&population1.size()>0)
}
}
FileHelper
.
writeLogFile
(
String
.
format
(
"排产-----------方案数量---%d-------"
,
population
.
size
()
));
List
<
Chromosome
>
population1
=
population
.
stream
().
filter
(
t
->
t
.
getGeneStr
()==
null
).
collect
(
Collectors
.
toList
());
List
<
Chromosome
>
population1
=
population
.
stream
().
filter
(
t
->
t
.
getGeneStr
()==
null
).
collect
(
Collectors
.
toList
());
if
(
population1
!=
null
&&
population1
.
size
()>
0
)
{
FileHelper
.
writeLogFile
(
String
.
format
(
"排产-----------方案GeneStrnull数量---%d-------"
,
population1
.
size
()
));
}
population
=
population
.
stream
()
population
=
population
.
stream
()
.
collect
(
Collectors
.
toMap
(
.
collect
(
Collectors
.
toMap
(
Chromosome:
:
getGeneStr
,
// key:去重的字段(GeneStr)
Chromosome:
:
getGeneStr
,
// key:去重的字段(GeneStr)
...
@@ -338,7 +332,6 @@ if(population1!=null&&population1.size()>0)
...
@@ -338,7 +332,6 @@ if(population1!=null&&population1.size()>0)
.
values
()
// 获取去重后的
.
values
()
// 获取去重后的
.
stream
()
.
stream
()
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
FileHelper
.
writeLogFile
(
String
.
format
(
"排产-----------方案数量---%d-------"
,
population
.
size
()
));
return
population
;
return
population
;
}
}
...
...
src/main/java/com/aps/service/Algorithm/NSGAIIUtils.java
View file @
dd36e456
This diff is collapsed.
Click to expand it.
src/test/java/com/aps/demo/PlanResultServiceTest.java
View file @
dd36e456
...
@@ -39,7 +39,7 @@ public class PlanResultServiceTest {
...
@@ -39,7 +39,7 @@ public class PlanResultServiceTest {
// nsgaiiUtils.Test();
// nsgaiiUtils.Test();
//planResultService.execute2("C5FB5EF2A7334A0A92F826F4937E1008");
//planResultService.execute2("C5FB5EF2A7334A0A92F826F4937E1008");
// planResultService.execute2("726D4C1A712B4B1393175BD44B775B66");
// planResultService.execute2("726D4C1A712B4B1393175BD44B775B66");
planResultService
.
execute2
(
"
13CC1CF783CE40D7AE3264D09FAA6378
"
);
planResultService
.
execute2
(
"
265F24B6DF3C40E4B17D193B0CC8AAF2
"
);
// LocalDateTime t= LocalDateTime.of(2025, 11, 15, 6, 51, 11);
// LocalDateTime t= LocalDateTime.of(2025, 11, 15, 6, 51, 11);
// List<Integer> opids=new ArrayList<>();BCA6FA43FFA444D3952CF8F6E1EA291B
// List<Integer> opids=new ArrayList<>();BCA6FA43FFA444D3952CF8F6E1EA291B
// opids.add(1);
// 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