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
fc778193
Commit
fc778193
authored
Dec 19, 2025
by
Tong Li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
遗传算法-移动多工单,删除订单
parent
bb843694
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
599 additions
and
66623 deletions
+599
-66623
chromosome_result_B571EF6682DB463AB2977B1055A74112.json
...t/chromosome_result_B571EF6682DB463AB2977B1055A74112.json
+407
-271
schedule_log.txt
schedule_log.txt
+78
-66299
ParamValidator.java
src/main/java/com/aps/common/util/ParamValidator.java
+22
-0
ResourceGanttController.java
...ava/com/aps/controller/gantt/ResourceGanttController.java
+4
-2
GeneticAlgorithm.java
...main/java/com/aps/service/Algorithm/GeneticAlgorithm.java
+2
-3
GeneticDecoder.java
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
+1
-1
GeneticOperations.java
...ain/java/com/aps/service/Algorithm/GeneticOperations.java
+2
-0
Initialization.java
src/main/java/com/aps/service/Algorithm/Initialization.java
+7
-6
KpiCalculator.java
src/main/java/com/aps/service/Algorithm/KpiCalculator.java
+2
-1
ScheduleOperationService.java
...a/com/aps/service/Algorithm/ScheduleOperationService.java
+63
-35
PlanResultService.java
src/main/java/com/aps/service/plan/PlanResultService.java
+4
-3
PlanResultServiceTest.java
src/test/java/com/aps/demo/PlanResultServiceTest.java
+7
-2
No files found.
result/chromosome_result_B571EF6682DB463AB2977B1055A74112.json
View file @
fc778193
This diff is collapsed.
Click to expand it.
schedule_log.txt
View file @
fc778193
This diff is collapsed.
Click to expand it.
src/main/java/com/aps/common/util/ParamValidator.java
View file @
fc778193
...
...
@@ -12,6 +12,7 @@ import java.time.format.DateTimeFormatter;
import
java.time.format.DateTimeParseException
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
@Slf4j
@UtilityClass
...
...
@@ -241,4 +242,25 @@ public class ParamValidator {
})
.
toArray
(
Double
[]::
new
);
}
public
static
List
<
Integer
>
convertToIntArray
(
List
<?>
sourceList
,
String
fieldName
)
{
requireNotEmpty
(
sourceList
,
fieldName
);
return
sourceList
.
stream
()
.
map
(
item
->
{
if
(
item
instanceof
Number
)
{
return
((
Integer
)
item
);
}
else
if
(
item
instanceof
String
)
{
try
{
return
Integer
.
parseInt
(((
String
)
item
).
trim
());
}
catch
(
NumberFormatException
e
)
{
throw
new
IllegalArgumentException
(
fieldName
+
"包含无效的数字: "
+
item
);
}
}
else
{
throw
new
IllegalArgumentException
(
fieldName
+
"包含不支持的数据类型: "
+
(
item
!=
null
?
item
.
getClass
().
getSimpleName
()
:
"null"
));
}
})
.
collect
(
Collectors
.
toList
());
}
}
\ No newline at end of file
src/main/java/com/aps/controller/gantt/ResourceGanttController.java
View file @
fc778193
...
...
@@ -144,15 +144,17 @@ public class ResourceGanttController {
// 1. 提取参数
String
sceneId
=
ParamValidator
.
getString
(
params
,
"sceneId"
,
"场景ID"
);
Integer
opid
=
ParamValidator
.
getInteger
(
params
,
"id"
,
"操作ID"
);
List
<?>
opid
=
ParamValidator
.
getList
(
params
,
"id"
,
"操作ID"
);
LocalDateTime
newStartTime
=
ParamValidator
.
getDateTime
(
params
,
"newStartTime"
,
"新的开始时间"
);
Long
newMachineId
=
ParamValidator
.
getLong
(
params
,
"newMachineId"
,
"新机器ID"
);
// 2. 验证场景
ParamValidator
.
validateSceneExists
(
sceneService
,
sceneId
);
List
<
Integer
>
opids
=
ParamValidator
.
convertToIntArray
(
opid
,
"操作IDS"
);
// 3. 执行业务
Chromosome
result
=
planResultService
.
Move
(
sceneId
,
opid
,
newStartTime
,
newMachineId
);
Chromosome
result
=
planResultService
.
Move
(
sceneId
,
opid
s
,
newStartTime
,
newMachineId
);
return
R
.
ok
(
result
);
}
...
...
src/main/java/com/aps/service/Algorithm/GeneticAlgorithm.java
View file @
fc778193
...
...
@@ -66,7 +66,7 @@ public class GeneticAlgorithm {
}
System
.
out
.
println
(
"开始"
);
Initialization
initialization
=
new
Initialization
(
_GlobalParam
,
allOperations
,
orders
);
Initialization
initialization
=
new
Initialization
(
_GlobalParam
,
allOperations
,
orders
,
machines
);
GeneticOperations
geneticOps
=
new
GeneticOperations
(
_GlobalParam
,
allOperations
,
param
);
...
...
@@ -183,8 +183,7 @@ public class GeneticAlgorithm {
}
}
best
.
setBaseTime
(
param
.
getBaseTime
());
best
.
setInitMachines
(
ProductionDeepCopyUtil
.
deepCopyList
(
machines
));
best
.
setOrders
(
orders
);
best
.
setOrderMaterials
(
orderMaterials
);
best
.
setOperatRel
(
_entryRel
);
// 步骤3:返回最优解
...
...
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
View file @
fc778193
...
...
@@ -78,7 +78,7 @@ public class GeneticDecoder {
chromosome
.
setTotalChangeoverTime
(
cachedResult
.
getTotalChangeoverTime
());
chromosome
.
setMachineLoadStd
(
cachedResult
.
getMachineLoadStd
());
chromosome
.
setDelayTime
(
cachedResult
.
getDelayTime
());
chromosome
.
setResult
(
ProductionDeepCopyUtil
.
deepCopy
(
cachedResult
.
getResult
()
));
chromosome
.
setResult
(
cachedResult
.
getResult
(
));
// Chromosome chromosomen= ProductionDeepCopyUtil.deepCopy(cachedResult);
return
chromosome
;
...
...
src/main/java/com/aps/service/Algorithm/GeneticOperations.java
View file @
fc778193
...
...
@@ -136,11 +136,13 @@ public class GeneticOperations {
Chromosome
child1
=
new
Chromosome
();
child1
.
setOrders
(
parent1
.
getOrders
());
child1
.
setMachines
(
parent1
.
getMachines
());
child1
.
setMachineSelection
(
child1Ms
);
child1
.
setOperationSequencing
(
child1Os
);
Chromosome
child2
=
new
Chromosome
();
child2
.
setOrders
(
parent1
.
getOrders
());
child2
.
setMachines
(
parent1
.
getMachines
());
child2
.
setMachineSelection
(
child2Ms
);
child2
.
setOperationSequencing
(
child2Os
);
...
...
src/main/java/com/aps/service/Algorithm/Initialization.java
View file @
fc778193
package
com
.
aps
.
service
.
Algorithm
;
import
com.aps.common.util.ProductionDeepCopyUtil
;
import
com.aps.entity.Algorithm.Chromosome
;
import
com.aps.entity.Algorithm.GlobalOperationInfo
;
import
com.aps.entity.Algorithm.ScheduleParams
;
import
com.aps.entity.basic.Entry
;
import
com.aps.entity.basic.GlobalParam
;
import
com.aps.entity.basic.MachineOption
;
import
com.aps.entity.basic.Order
;
import
com.aps.entity.basic.*
;
import
java.util.*
;
import
java.util.stream.Collectors
;
...
...
@@ -22,10 +20,13 @@ public class Initialization {
private
static
List
<
Order
>
orders
;
public
Initialization
(
GlobalParam
globalParam
,
List
<
Entry
>
allOperations
,
List
<
Order
>
_orders
)
{
private
static
List
<
Machine
>
machines
;
public
Initialization
(
GlobalParam
globalParam
,
List
<
Entry
>
allOperations
,
List
<
Order
>
_orders
,
List
<
Machine
>
_machines
)
{
Initialization
.
allOperations
=
allOperations
;
_globalParam
=
globalParam
;
orders
=
_orders
;
machines
=
_machines
;
}
/**
* 预生成全局工序列表(按“订单0→订单1→…+订单内工序1→2→…”排序,分配GlobalOpId)
...
...
@@ -59,7 +60,7 @@ int populationSize=param.getPopulationSize();
.
parallel
()
// 开启并行
.
forEach
(
i
->
{
Chromosome
chromo
=
new
Chromosome
();
// 初始化染色体
chromo
.
setInitMachines
(
ProductionDeepCopyUtil
.
deepCopyList
(
machines
));
chromo
.
setOrders
(
orders
);
// 全局选择(GS):按GlobalOpId顺序生成MachineSelection
if
(
i
<
gsCount
)
{
...
...
src/main/java/com/aps/service/Algorithm/KpiCalculator.java
View file @
fc778193
package
com
.
aps
.
service
.
Algorithm
;
import
com.aps.common.util.ProductionDeepCopyUtil
;
import
com.aps.entity.Algorithm.Chromosome
;
import
com.aps.entity.Algorithm.GAScheduleResult
;
import
com.aps.entity.basic.Machine
;
...
...
@@ -128,7 +129,7 @@ public class KpiCalculator {
private
void
calculateMachine
()
{
// 按设备ID分组工序列表(对应C# GroupBy + ToList)
List
<
GAScheduleResult
>
list
=
chromosome
.
getResult
();
List
<
GAScheduleResult
>
list
=
chromosome
.
getResult
()
;
Map
<
Long
,
List
<
GAScheduleResult
>>
machineTasks
=
list
.
stream
()
.
collect
(
Collectors
.
groupingBy
(
GAScheduleResult:
:
getMachineId
));
...
...
src/main/java/com/aps/service/Algorithm/ScheduleOperationService.java
View file @
fc778193
...
...
@@ -33,9 +33,19 @@ public class ScheduleOperationService {
* @param newStartTime 新开始时间
* @param newMachineId 新设备ID
*/
public
void
moveOperation
(
Chromosome
chromosome
,
int
opId
,
int
newStartTime
,
public
void
moveOperation
(
Chromosome
chromosome
,
List
<
Integer
>
opIds
,
int
newStartTime
,
Long
newMachineId
,
GlobalParam
globalParam
)
{
List
<
Entry
>
allOperations
=
chromosome
.
getAllOperations
();
Map
<
Integer
,
Integer
>
opTimeMap
=
chromosome
.
getResult
().
stream
()
.
collect
(
Collectors
.
toMap
(
GAScheduleResult:
:
getOperationId
,
r
->
r
.
getStartTime
()
));
for
(
Integer
opId:
opIds
)
{
// 获取目标结果和工序
GAScheduleResult
targetResult
=
chromosome
.
getResult
().
stream
()
.
filter
(
r
->
r
.
getOperationId
()
==
opId
)
...
...
@@ -69,13 +79,31 @@ public class ScheduleOperationService {
chromosome
.
getMachineSelection
().
set
(
globalOpIndex
,
machineOptionIndex
);
if
(
targetOp
.
getSequence
()==
1
)
{
opTimeMap
.
put
(
opId
,
newStartTime
);
}
else
{
Entry
targetOp1
=
allOperations
.
stream
()
.
filter
(
o
->
o
.
getGroupId
()
==
targetOp
.
getGroupId
()
&&
o
.
getSequence
()==
targetOp
.
getSequence
()-
1
)
.
findFirst
()
.
orElseThrow
(()
->
new
NoSuchElementException
(
"Operation not found: "
+
opId
));
GAScheduleResult
targetResult1
=
chromosome
.
getResult
().
stream
()
.
filter
(
r
->
r
.
getOperationId
()
==
targetOp1
.
getId
())
.
findFirst
()
.
orElseThrow
(()
->
new
NoSuchElementException
(
"Operation not found: "
+
opId
));
if
(
targetResult1
.
getStartTime
()<
newStartTime
)
{
opTimeMap
.
put
(
opId
,
newStartTime
);
}
else
{
opTimeMap
.
put
(
opId
,
targetResult1
.
getStartTime
()+
1
);
}
}
newStartTime
=
newStartTime
+(
int
)
targetResult
.
getProcessingTime
();
}
// 生成新的工序顺序
Map
<
Integer
,
Integer
>
opTimeMap
=
chromosome
.
getResult
().
stream
()
.
collect
(
Collectors
.
toMap
(
GAScheduleResult:
:
getOperationId
,
r
->
r
.
getOperationId
()
==
opId
?
newStartTime
:
r
.
getStartTime
()
));
List
<
Integer
>
operationSequencing
=
allOperations
.
stream
()
.
sorted
((
op1
,
op2
)
->
{
...
...
@@ -96,7 +124,6 @@ public class ScheduleOperationService {
}
public
void
SpiltOperation
(
Chromosome
chromosome
,
int
opId
,
Double
[]
splitCounts
,
GlobalParam
globalParam
)
{
List
<
Entry
>
allOperations
=
chromosome
.
getAllOperations
();
...
...
@@ -693,9 +720,10 @@ public class ScheduleOperationService {
public
void
redecode
(
Chromosome
chromosome
,
LocalDateTime
baseTime
,
GlobalParam
globalParam
)
{
MachineSchedulerService
machineScheduler
=
new
MachineSchedulerService
(
baseTime
);
chromosome
.
setMachines
(
chromosome
.
getInitMachines
());
GeneticDecoder
decoder
=
new
GeneticDecoder
(
globalParam
,
baseTime
,
chromosome
.
getInitMachines
(),
chromosome
.
getOrders
(),
null
,
machineScheduler
,
chromosome
.
getOrderMaterials
());
chromosome
.
setMachines
(
chromosome
.
getInitMachines
());
chromosome
.
setResultOld
(
ProductionDeepCopyUtil
.
deepCopyList
(
chromosome
.
getResult
()));
chromosome
.
getResult
().
clear
();
...
...
src/main/java/com/aps/service/plan/PlanResultService.java
View file @
fc778193
...
...
@@ -301,6 +301,7 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
public
Chromosome
execute2
(
String
SceneId
)
{
try
{
SceneId
=
"6AF8001449FC4D20A3C9992EC24CBF05"
;
ScheduleParams
param
=
new
ScheduleParams
();
param
.
setBaseTime
(
LocalDateTime
.
of
(
2025
,
11
,
1
,
0
,
0
,
0
));
...
...
@@ -325,7 +326,7 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
// 3. 构建订单-工序数据
List
<
Order
>
orders
=
InitOrder
(
ProdLaunchOrders
);
List
<
Material
>
Materials
=
InitMaterial
();
List
<
Material
>
Materials
=
null
;
//
InitMaterial();
Map
<
Integer
,
Object
>
list
=
InitEntrys
(
SceneId
,
ProdEquipments
,
orders
);
List
<
Entry
>
entrys
=(
List
<
Entry
>)
list
.
get
(
1
);
...
...
@@ -404,7 +405,7 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
return
chromosome
;
}
public
Chromosome
Move
(
String
SceneId
,
int
opId
,
LocalDateTime
newStartTime
,
public
Chromosome
Move
(
String
SceneId
,
List
<
Integer
>
opId
,
LocalDateTime
newStartTime
,
Long
newMachineId
)
{
...
...
@@ -604,7 +605,7 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
public
void
WriteScheduleSummary
(
Chromosome
schedule
)
{
// 写入日志
FileHelper
.
writeLogFile
(
String
.
format
(
"\n=== Schedule Summary === %f"
,
schedule
.
getFitness
())
);
FileHelper
.
writeLogFile
(
"\n=== Schedule Summary === "
);
FileHelper
.
writeLogFile
(
String
.
format
(
"Operation: %s"
,
schedule
.
getOperationStr
()));
FileHelper
.
writeLogFile
(
String
.
format
(
"Makespan: %f minutes"
,
schedule
.
getMakespan
()));
FileHelper
.
writeLogFile
(
String
.
format
(
"Total Tardiness: %f hours"
,
schedule
.
getDelayTime
()));
...
...
src/test/java/com/aps/demo/PlanResultServiceTest.java
View file @
fc778193
...
...
@@ -26,9 +26,14 @@ public class PlanResultServiceTest {
@Test
public
void
testExecute
()
{
LocalDateTime
t
=
LocalDateTime
.
of
(
2025
,
10
,
31
,
6
,
51
,
11
);
// planResultService.execute2(""
);
planResultService
.
Move
(
"86ED02C9BAB54BB6B8F413938A3F2869"
,
1
,
t
,
3402L
);
LocalDateTime
t
=
LocalDateTime
.
of
(
2025
,
11
,
15
,
6
,
51
,
11
);
List
<
Integer
>
opids
=
new
ArrayList
<>();
opids
.
add
(
1
);
planResultService
.
Move
(
"B571EF6682DB463AB2977B1055A74112"
,
opids
,
t
,
3403L
);
// planResultService.Move("B571EF6682DB463AB2977B1055A74112",2,t,3243L);
}
@Test
...
...
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