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
254b5ff2
Commit
254b5ff2
authored
Jan 14, 2026
by
Tong Li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
多线程
parent
028384c3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
28 deletions
+19
-28
Chromosome.java
src/main/java/com/aps/entity/Algorithm/Chromosome.java
+2
-1
Machine.java
src/main/java/com/aps/entity/basic/Machine.java
+1
-0
GeneticAlgorithm.java
...main/java/com/aps/service/Algorithm/GeneticAlgorithm.java
+15
-26
MachineCalculator.java
...ain/java/com/aps/service/Algorithm/MachineCalculator.java
+1
-1
No files found.
src/main/java/com/aps/entity/Algorithm/Chromosome.java
View file @
254b5ff2
...
...
@@ -12,6 +12,7 @@ import java.time.LocalDateTime;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.UUID
;
import
java.util.concurrent.CopyOnWriteArrayList
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -113,7 +114,7 @@ public class Chromosome {
/// <summary>
/// 解码后的调度结果
/// </summary>
private
List
<
GAScheduleResult
>
ResultOld
=
new
ArrayList
<>();
private
List
<
GAScheduleResult
>
ResultOld
=
new
CopyOnWrite
ArrayList
<>();
/// <summary>
/// 最早完工时间
...
...
src/main/java/com/aps/entity/basic/Machine.java
View file @
254b5ff2
...
...
@@ -5,6 +5,7 @@ import lombok.Data;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.concurrent.CopyOnWriteArrayList
;
import
java.util.function.Consumer
;
@Data
...
...
src/main/java/com/aps/service/Algorithm/GeneticAlgorithm.java
View file @
254b5ff2
...
...
@@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
java.time.LocalDateTime
;
import
java.util.*
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.concurrent.CopyOnWriteArrayList
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.stream.Collectors
;
...
...
@@ -328,29 +329,16 @@ public class GeneticAlgorithm {
FileHelper
.
writeLogFile
(
"解码---------------"
+
population
.
size
()
);
GeneticDecoder
decoder
=
new
GeneticDecoder
(
_GlobalParam
,
param
.
getBaseTime
(),
machines
,
orders
,
materials
,
machineScheduler
,
orderMaterials
);
if
(
1
==
2
)
{
CompletableFuture
.
allOf
(
population
.
stream
()
.
map
(
chromosome
->
CompletableFuture
.
runAsync
(()
->
decode
(
decoder
,
chromosome
,
param
,
allOperations
,
globalOpList
),
decodeExecutor
))
.
toArray
(
CompletableFuture
[]::
new
))
.
join
();
}
population
.
forEach
(
chromosome
->
{
chromosome
.
setResult
(
new
ArrayList
<>());
// 假设Machine类有拷贝方法,或使用MapStruct等工具进行映射
chromosome
.
setMachines
(
ProductionDeepCopyUtil
.
deepCopyList
(
machines
,
Machine
.
class
));
// 简单拷贝,实际可能需要深拷贝
chromosome
.
setAllOperations
(
allOperations
);
// 简单拷贝,实际可能需要深拷贝
chromosome
.
setGlobalOpList
(
globalOpList
);
// 简单拷贝,实际可能需要深拷贝
//chromosome.setObjectiveWeights(_objectiveWeights);
chromosome
.
setBaseTime
(
param
.
getBaseTime
());
// chromosome.setInitMachines(ProductionDeepCopyUtil.deepCopyList(machines,Machine.class)); // 简单拷贝,实际可能需要深拷贝
// _sceneService.saveChromosomeToFile(chromosome, "12345679");
});
if
(
1
==
2
)
{
if
(
population
!=
null
&&
population
.
size
()
>
0
)
{
population
.
parallelStream
().
forEach
(
chromosome
->
{
decode
(
decoder
,
chromosome
,
param
,
allOperations
,
globalOpList
);
...
...
@@ -358,22 +346,23 @@ public class GeneticAlgorithm {
}
}
}
private
void
decode
(
GeneticDecoder
decoder
,
Chromosome
chromosome
,
ScheduleParams
param
,
List
<
Entry
>
allOperations
,
List
<
GlobalOperationInfo
>
globalOpList
)
{
// chromosome.setResult(new
ArrayList<>());
//
//
// 假设Machine类有拷贝方法,或使用MapStruct等工具进行映射
//
chromosome.setMachines(ProductionDeepCopyUtil.deepCopyList(machines,Machine.class)); // 简单拷贝,实际可能需要深拷贝
//
//
chromosome.setAllOperations(allOperations); // 简单拷贝,实际可能需要深拷贝
//
chromosome.setGlobalOpList(globalOpList); // 简单拷贝,实际可能需要深拷贝
//
//chromosome.setObjectiveWeights(_objectiveWeights);
//
chromosome.setBaseTime(param.getBaseTime());
//
// chromosome.setInitMachines(ProductionDeepCopyUtil.deepCopyList(machines,Machine.class)); // 简单拷贝,实际可能需要深拷贝
//
// _sceneService.saveChromosomeToFile(chromosome, "12345679");
chromosome
.
setResult
(
new
CopyOnWrite
ArrayList
<>());
// 假设Machine类有拷贝方法,或使用MapStruct等工具进行映射
chromosome
.
setMachines
(
ProductionDeepCopyUtil
.
deepCopyList
(
machines
,
Machine
.
class
));
// 简单拷贝,实际可能需要深拷贝
chromosome
.
setAllOperations
(
allOperations
);
// 简单拷贝,实际可能需要深拷贝
chromosome
.
setGlobalOpList
(
globalOpList
);
// 简单拷贝,实际可能需要深拷贝
//chromosome.setObjectiveWeights(_objectiveWeights);
chromosome
.
setBaseTime
(
param
.
getBaseTime
());
// chromosome.setInitMachines(ProductionDeepCopyUtil.deepCopyList(machines,Machine.class)); // 简单拷贝,实际可能需要深拷贝
// _sceneService.saveChromosomeToFile(chromosome, "12345679");
decoder
.
decodeChromosomeWithCache
(
chromosome
);
if
(
chromosome
.
getFitness
()
==
0
)
{
...
...
src/main/java/com/aps/service/Algorithm/MachineCalculator.java
View file @
254b5ff2
...
...
@@ -65,7 +65,7 @@ public class MachineCalculator {
Machine
machine
,
int
processingTime
,
LocalDateTime
currentTime
,
String
prevtime
,
List
<
GAScheduleResult
>
existingTasks
,
double
oneTime
,
double
quantity
,
boolean
checkprevtime
,
boolean
islockMachineTime
,
boolean
isInterrupt
)
{
List
<
GAScheduleResult
>
machineTasks
=
new
ArrayList
<>(
existingTasks
)
.
stream
()
List
<
GAScheduleResult
>
machineTasks
=
existingTasks
.
stream
()
.
filter
(
t
->
t
.
getMachineId
()
==
machine
.
getId
())
.
sorted
(
Comparator
.
comparingInt
(
GAScheduleResult:
:
getStartTime
))
.
collect
(
Collectors
.
toList
());
...
...
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