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
cfcaec50
Commit
cfcaec50
authored
Dec 03, 2025
by
Tong Li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
遗传算法
parent
79e47803
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
807 additions
and
41 deletions
+807
-41
schedule_log.txt
schedule_log.txt
+333
-0
ResourceGanttController.java
...ava/com/aps/controller/gantt/ResourceGanttController.java
+54
-6
GAScheduleResult.java
src/main/java/com/aps/entity/Algorithm/GAScheduleResult.java
+2
-1
Entry.java
src/main/java/com/aps/entity/basic/Entry.java
+17
-1
GeneticAlgorithm.java
...main/java/com/aps/service/Algorithm/GeneticAlgorithm.java
+1
-1
GeneticDecoder.java
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
+11
-0
IdGroupingWithDualSerial.java
...a/com/aps/service/Algorithm/IdGroupingWithDualSerial.java
+22
-7
ScheduleOperationService.java
...a/com/aps/service/Algorithm/ScheduleOperationService.java
+262
-12
PlanResultService.java
src/main/java/com/aps/service/plan/PlanResultService.java
+105
-13
No files found.
schedule_log.txt
View file @
cfcaec50
This diff is collapsed.
Click to expand it.
src/main/java/com/aps/controller/gantt/ResourceGanttController.java
View file @
cfcaec50
...
...
@@ -15,13 +15,11 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import
io.swagger.v3.oas.annotations.Operation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
java.time.LocalDateTime
;
import
java.time.temporal.ChronoUnit
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.stream.Collectors
;
...
...
@@ -136,14 +134,64 @@ public class ResourceGanttController {
}
@GetMapping
(
"/Move"
)
public
Chromosome
Move
(
String
SceneId
,
int
opid
,
LocalDateTime
newStartTime
,
Long
newMachineId
)
{
// opid=1;
// newStartTime= LocalDateTime.of(2025, 12, 7, 0, 0);
// newMachineId=3402L;
// SceneId="B571EF6682DB463AB2977B1055A74112";
// 调用 PlanResultService 获取 ScheduleChromosome 列表
Chromosome
scheduleChromosomes
=
planResultService
.
Move
(
SceneId
,
opid
,
newStartTime
,
newMachineId
);
// 提取所有场景ID
return
scheduleChromosomes
;
}
@PostMapping
(
"/SpiltOperation"
)
public
Chromosome
SpiltOperation
(
@RequestParam
String
SceneId
,
@RequestParam
int
opid
,
@RequestBody
List
<
Double
>
splitCounts
)
{
opid
=
1
;
// newStartTime= LocalDateTime.of(2025, 12, 7, 0, 0);
// newMachineId=3402L;
splitCounts
=
new
ArrayList
<>();
splitCounts
.
add
(
20000
d
);
splitCounts
.
add
(
30000
d
);
SceneId
=
"B571EF6682DB463AB2977B1055A74112"
;
public
Chromosome
Move
()
{
// 调用 PlanResultService 获取 ScheduleChromosome 列表
Chromosome
scheduleChromosomes
=
planResultService
.
Move
(
"B571EF6682DB463AB2977B1055A74112"
);
Chromosome
scheduleChromosomes
=
planResultService
.
SpiltOperation
(
SceneId
,
opid
,
splitCounts
.
toArray
(
new
Double
[
0
])
);
// 提取所有场景ID
return
scheduleChromosomes
;
}
@PostMapping
(
"/delOperation"
)
public
Chromosome
DelOperation
(
@RequestParam
String
SceneId
,
@RequestParam
int
opid
)
{
opid
=
1
;
SceneId
=
"B571EF6682DB463AB2977B1055A74112"
;
// 调用 PlanResultService 获取 ScheduleChromosome 列表
Chromosome
scheduleChromosomes
=
planResultService
.
DelOperation
(
SceneId
,
opid
);
// 提取所有场景ID
return
scheduleChromosomes
;
}
@PostMapping
(
"/LockedOperation"
)
public
Chromosome
LockedOperation
(
@RequestParam
String
SceneId
,
@RequestParam
int
opid
,
@RequestParam
boolean
isLocked
)
{
opid
=
1
;
SceneId
=
"B571EF6682DB463AB2977B1055A74112"
;
// 调用 PlanResultService 获取 ScheduleChromosome 列表
Chromosome
scheduleChromosomes
=
planResultService
.
LockOperation
(
SceneId
,
opid
,
isLocked
);
// 提取所有场景ID
return
scheduleChromosomes
;
}
/**
* 将 ScheduleChromosome 转换为 ResourceGanttVO 列表
...
...
src/main/java/com/aps/entity/Algorithm/GAScheduleResult.java
View file @
cfcaec50
...
...
@@ -27,7 +27,8 @@ public class GAScheduleResult {
private
double
Quantity
;
// 批次大小(订单可拆分)
private
List
<
ScheduleResultDetail
>
GeneDetails
;
// 时间详情
private
int
designatedStartTime
=
-
1
;
// 设计开始时间(默认-1)
private
int
forcedMachineId
=
-
1
;
// 强制分配的设备ID(-1表示无强制)
private
Long
forcedMachineId
=-
1L
;
// 强制分配的设备ID(-1表示无强制)
private
boolean
IsLocked
=
false
;
private
double
OneTime
;
// 单件工时
private
double
ProcessingTime
;
// 绝对处理时间(分钟)
private
int
ChangeoverTime
;
...
...
src/main/java/com/aps/entity/basic/Entry.java
View file @
cfcaec50
...
...
@@ -25,15 +25,26 @@ public class Entry {
public
int
GroupId
;
/**
*
所属组ID 需要按照前后顺序生产的工单给一组
*
原订单ID
*/
public
String
OrderId
;
private
Long
routingDetailId
;
private
Long
taskSeq
;
private
String
routingDetailName
;
private
String
productId
;
/**
* 工单ID
*/
public
String
ExecId
;
/**
* 工单ID
*/
public
String
MainId
;
/**
* 离散参数
*/
...
...
@@ -64,6 +75,11 @@ public class Entry {
*/
public
List
<
Integer
>
NextEntryIds
;
//后工序
/**
* 数据状态 1 拆分 2 新建
*/
public
Integer
state
;
/**
* 是否可中断,间缝插针
*/
...
...
src/main/java/com/aps/service/Algorithm/GeneticAlgorithm.java
View file @
cfcaec50
...
...
@@ -131,7 +131,7 @@ public class GeneticAlgorithm {
break
;
}
}
best
.
setBaseTime
(
param
.
getBaseTime
());
best
.
setInitMachines
(
ProductionDeepCopyUtil
.
deepCopyList
(
machines
));
best
.
setOrders
(
orders
);
// 步骤3:返回最优解
...
...
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
View file @
cfcaec50
...
...
@@ -168,6 +168,16 @@ public class GeneticDecoder {
Entry
currentOp
=
orderOps
.
get
(
scheduledCount
);
int
opSequence
=
currentOp
.
getSequence
();
GAScheduleResult
existingResult
=
chromosome
.
getResultOld
().
stream
()
.
filter
(
r
->
r
.
getOperationId
()
==
currentOp
.
Id
)
.
findFirst
().
orElse
(
null
);
if
(
existingResult
!=
null
)
{
if
(
existingResult
.
isIsLocked
())
{
continue
;
}
}
// 从映射表中获取机器和加工时间
OpMachine
machineOption
=
opMachineMap
.
stream
()
.
filter
(
m
->
m
.
getGroupId
()
==
groupId
&&
m
.
getSequence
()==
opSequence
)
...
...
@@ -356,6 +366,7 @@ public class GeneticDecoder {
result
.
setTeardownTime
(
teardownTime
);
if
(
existingResult
!=
null
)
{
result
.
setDesignatedStartTime
(
existingResult
.
getDesignatedStartTime
());
}
result
.
setOneTime
(
processingTime
);
...
...
src/main/java/com/aps/service/Algorithm/IdGroupingWithDualSerial.java
View file @
cfcaec50
...
...
@@ -215,7 +215,7 @@ public class IdGroupingWithDualSerial {
* @return 更新后的结果
*/
public
static
List
<
GroupResult
>
addNode
(
List
<
GroupResult
>
existingResults
,
int
targetGroupIndex
,
String
newId
,
List
<
Integer
>
newParentIds
,
List
<
Integer
>
newChildIds
)
{
String
newId
,
List
<
Integer
>
newParentIds
,
List
<
Integer
>
newChildIds
,
String
insertAfterOriginalId
)
{
// 1. 空值安全检查
if
(
existingResults
==
null
||
existingResults
.
isEmpty
()
||
targetGroupIndex
<
0
||
targetGroupIndex
>=
existingResults
.
size
())
{
throw
new
IllegalArgumentException
(
"无效的现有结果或目标分组索引"
);
...
...
@@ -244,12 +244,26 @@ public class IdGroupingWithDualSerial {
newGlobalSerial
++;
}
// 5. 找到新节点的插入位置(父节点之后)
// 5. 找到插入位置:优先插入到指定节点之后,否则插入到父节点之后
int
insertIndex
=
0
;
for
(
int
i
=
0
;
i
<
nodeList
.
size
();
i
++)
{
NodeInfo
node
=
nodeList
.
get
(
i
);
if
(
newParentIds
.
contains
(
node
.
getGlobalSerial
()))
{
insertIndex
=
i
+
1
;
// 插入到最后一个父节点之后
// 定位要插入到其后的节点(如"20")
if
(
insertAfterOriginalId
!=
null
&&
!
insertAfterOriginalId
.
trim
().
isEmpty
())
{
for
(
int
i
=
0
;
i
<
nodeList
.
size
();
i
++)
{
NodeInfo
node
=
nodeList
.
get
(
i
);
if
(
insertAfterOriginalId
.
equals
(
node
.
getOriginalId
()))
{
insertIndex
=
i
+
1
;
// 插入到指定节点之后
break
;
}
}
}
// 若未找到指定节点,回退到父节点之后的逻辑
if
(
insertIndex
==
0
)
{
for
(
int
i
=
0
;
i
<
nodeList
.
size
();
i
++)
{
NodeInfo
node
=
nodeList
.
get
(
i
);
if
(
newParentIds
.
contains
(
node
.
getGlobalSerial
()))
{
insertIndex
=
i
+
1
;
}
}
}
...
...
@@ -528,7 +542,7 @@ public class IdGroupingWithDualSerial {
int
targetGroupIndex
=
1
;
// 分组2的索引
// 添加新节点
results
=
addNode
(
results
,
targetGroupIndex
,
newId
,
newParentIds
,
newChildIds
);
results
=
addNode
(
results
,
targetGroupIndex
,
newId
,
newParentIds
,
newChildIds
,
""
);
List
<
String
>
newIdList
=
Arrays
.
asList
(
"20"
,
"21"
,
"24"
);
...
...
@@ -540,6 +554,7 @@ public class IdGroupingWithDualSerial {
results
=
deleteNodeByGlobalSerial
(
results
,
13
);
// 输出结果
for
(
int
i
=
0
;
i
<
results
.
size
();
i
++)
{
GroupResult
groupResult
=
results
.
get
(
i
);
...
...
src/main/java/com/aps/service/Algorithm/ScheduleOperationService.java
View file @
cfcaec50
This diff is collapsed.
Click to expand it.
src/main/java/com/aps/service/plan/PlanResultService.java
View file @
cfcaec50
...
...
@@ -30,6 +30,7 @@ import java.time.format.DateTimeFormatter;
import
java.time.temporal.ChronoUnit
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
java.util.stream.IntStream
;
@Service
public
class
PlanResultService
{
...
...
@@ -65,7 +66,7 @@ public class PlanResultService {
@Autowired
private
ProdOrderProcessService
_prodOrderProcessService
;
private
final
LocalDateTime
baseTime
=
LocalDateTime
.
of
(
2025
,
10
,
1
,
0
,
0
,
0
);
private
LocalDateTime
baseTime
=
LocalDateTime
.
of
(
2025
,
11
,
1
,
0
,
0
,
0
);
public
List
<
ScheduleChromosome
>
execute
()
{
try
{
...
...
@@ -228,7 +229,7 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
WriteScheduleSummary
(
Chromosomes
);
ScheduleOperationService
ScheduleOperation
=
new
ScheduleOperationService
();
LocalDateTime
ds
=
LocalDateTime
.
of
(
2025
,
12
,
7
,
23
,
59
);
ScheduleOperation
.
moveOperation
(
Chromosomes
,
3
,
(
int
)
ChronoUnit
.
SECONDS
.
between
(
param
.
getBaseTime
(),
ds
),
2
,
param
.
getBaseTime
(),
globalParam
);
// ScheduleOperation.moveOperation(Chromosomes,3, (int)ChronoUnit.SECONDS.between(param.getBaseTime(), ds),(Long)
2,param.getBaseTime(), globalParam);
WriteScheduleSummary
(
Chromosomes
);
return
Chromosomes
;
...
...
@@ -296,24 +297,112 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
throw
new
RuntimeException
(
"调度执行失败"
,
e
);
}
}
public
Chromosome
Move
(
String
SceneId
)
{
public
Chromosome
EditOperation
(
String
SceneId
,
Entry
operation
)
{
Chromosome
chromosome
=
_sceneService
.
loadChromosomeFromFile
(
SceneId
);
if
(
chromosome
==
null
||
chromosome
.
getAllOperations
()
==
null
)
{
return
chromosome
;
// 直接返回,空值由上层处理
}
List
<
Entry
>
operations
=
chromosome
.
getAllOperations
();
// 直接查找匹配元素的索引(避免先找元素再查索引的冗余)
int
position
=
IntStream
.
range
(
0
,
operations
.
size
())
.
filter
(
i
->
{
Entry
t
=
operations
.
get
(
i
);
return
t
.
getId
()==
operation
.
getId
();
})
.
findFirst
()
.
orElse
(-
1
);
// 索引有效时替换
if
(
position
!=
-
1
)
{
operations
.
set
(
position
,
operation
);
}
ScheduleOperationService
ScheduleOperation
=
new
ScheduleOperationService
();
ScheduleParams
param
=
new
ScheduleParams
();
param
.
setBaseTime
(
LocalDateTime
.
of
(
2025
,
11
,
1
,
0
,
0
,
0
));
GlobalParam
globalParam
=
new
GlobalParam
();
ScheduleOperation
.
redecode
(
chromosome
,
param
.
getBaseTime
(),
globalParam
);
return
chromosome
;
}
public
Chromosome
Move
(
String
SceneId
,
int
opId
,
LocalDateTime
newStartTime
,
Long
newMachineId
)
{
GlobalParam
globalParam
=
new
GlobalParam
();
Chromosome
chromosome
=
_sceneService
.
loadChromosomeFromFile
(
SceneId
);
// WriteScheduleSummary(chromosome);
ScheduleOperationService
ScheduleOperation
=
new
ScheduleOperationService
();
ScheduleOperation
.
moveOperation
(
chromosome
,
opId
,
(
int
)
ChronoUnit
.
SECONDS
.
between
(
chromosome
.
getBaseTime
(),
newStartTime
),
newMachineId
,
globalParam
);
// WriteScheduleSummary(chromosome);
_sceneService
.
saveChromosomeToFile
(
chromosome
,
SceneId
);
return
chromosome
;
}
public
Chromosome
SpiltOperation
(
String
SceneId
,
int
opId
,
Double
[]
splitCounts
)
{
GlobalParam
globalParam
=
new
GlobalParam
();
Chromosome
chromosome
=
_sceneService
.
loadChromosomeFromFile
(
SceneId
);
//this.baseTime=param.getBaseTime();
// WriteScheduleSummary(chromosome);
ScheduleOperationService
ScheduleOperation
=
new
ScheduleOperationService
();
ScheduleOperation
.
SpiltOperation
(
chromosome
,
opId
,
splitCounts
,
globalParam
);
WriteScheduleSummary
(
chromosome
);
_sceneService
.
saveChromosomeToFile
(
chromosome
,
SceneId
);
return
chromosome
;
}
public
Chromosome
DelOperation
(
String
SceneId
,
int
opId
)
{
GlobalParam
globalParam
=
new
GlobalParam
();
Chromosome
chromosome
=
_sceneService
.
loadChromosomeFromFile
(
SceneId
);
//this.baseTime=param.getBaseTime();
// WriteScheduleSummary(chromosome);
ScheduleOperationService
ScheduleOperation
=
new
ScheduleOperationService
();
ScheduleOperation
.
DelOperation
(
chromosome
,
opId
,
globalParam
);
WriteScheduleSummary
(
chromosome
);
_sceneService
.
saveChromosomeToFile
(
chromosome
,
SceneId
);
return
chromosome
;
}
public
Chromosome
LockOperation
(
String
SceneId
,
int
opId
,
boolean
isLocked
)
{
GlobalParam
globalParam
=
new
GlobalParam
();
Chromosome
chromosome
=
_sceneService
.
loadChromosomeFromFile
(
SceneId
);
//this.baseTime=param.getBaseTime();
// WriteScheduleSummary(chromosome);
ScheduleOperationService
ScheduleOperation
=
new
ScheduleOperationService
();
LocalDateTime
ds
=
LocalDateTime
.
of
(
2025
,
12
,
7
,
23
,
59
);
ScheduleOperation
.
moveOperation
(
chromosome
,
2
,
(
int
)
ChronoUnit
.
SECONDS
.
between
(
param
.
getBaseTime
(),
ds
),
2
,
param
.
getBaseTime
()
,
globalParam
);
ScheduleOperation
.
LockOperation
(
chromosome
,
opId
,
isLocked
,
globalParam
);
WriteScheduleSummary
(
chromosome
);
//
_sceneService.saveChromosomeToFile(chromosome, SceneId);
_sceneService
.
saveChromosomeToFile
(
chromosome
,
SceneId
);
return
chromosome
;
}
public
Chromosome
schedule
(
String
SceneId
)
{
public
Chromosome
schedule
(
String
SceneId
)
{
try
{
ScheduleParams
param
=
new
ScheduleParams
();
...
...
@@ -400,11 +489,9 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
.
collect
(
Collectors
.
toList
());
for
(
GAScheduleResult
job
:
sortedJobs
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
String
.
format
(
"[%d-%d]:[%s-%s] Order %d, Machine %d, Operation %d, Batch %
d, processingTime %d
"
,
"[%d-%d]:[%s-%s] Order %d, Machine %d, Operation %d, Batch %
.1f, processingTime %%.1f
"
,
job
.
getStartTime
(),
job
.
getEndTime
(),
ConvertTime
(
job
.
getStartTime
()),
...
...
@@ -436,7 +523,7 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
}
}
private
String
ConvertTime
(
int
minute
)
{
return
baseTime
.
plus
Minute
s
(
minute
).
format
(
java
.
time
.
format
.
DateTimeFormatter
.
ofPattern
(
"MM-dd HH:mm"
));
return
baseTime
.
plus
Second
s
(
minute
).
format
(
java
.
time
.
format
.
DateTimeFormatter
.
ofPattern
(
"MM-dd HH:mm"
));
}
/**
...
...
@@ -666,6 +753,9 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
{
entry
.
setOrderId
(
op
.
getOrderId
());
entry
.
setQuantity
(
op
.
getPlanQty
());
entry
.
setRoutingDetailId
(
op
.
getRoutingDetailId
());
entry
.
setTaskSeq
(
op
.
getTaskSeq
());
entry
.
setRoutingDetailName
(
op
.
getRoutingDetailName
());
ProdLaunchOrder
order
=
ProdLaunchOrders
.
stream
()
.
filter
(
t
->
t
.
getOrderId
().
equals
(
op
.
getOrderId
()))
.
findFirst
().
orElse
(
null
);
...
...
@@ -681,8 +771,10 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
MachineOption
mo
=
new
MachineOption
();
mo
.
setMachineId
(
e
.
getEquipId
());
mo
.
setProcessingTime
(
e
.
getSpeed
());
// mo.setContantTime(op.getConstTime());
// mo.setTeardownTime(op.getPostprocessingTime());
mo
.
setContantTime
(
op
.
getConstTime
());
mo
.
setSetupTime
(
op
.
getChangeLineTime
());
mo
.
setTeardownTime
(
op
.
getPostprocessingTime
());
mo
.
setPreTime
(
e
.
getSetupTime
());
mos
.
add
(
mo
);
}
...
...
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