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
e0ba6b7a
Commit
e0ba6b7a
authored
Dec 09, 2025
by
Tong Li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
遗传算法-配套
parent
baeaecee
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
26 deletions
+73
-26
OrderMaterialRequirement.java
...va/com/aps/entity/Algorithm/OrderMaterialRequirement.java
+1
-1
Entry.java
src/main/java/com/aps/entity/basic/Entry.java
+18
-0
GeneticAlgorithm.java
...main/java/com/aps/service/Algorithm/GeneticAlgorithm.java
+5
-1
MaterialRequirementService.java
...com/aps/service/Algorithm/MaterialRequirementService.java
+45
-20
PlanResultService.java
src/main/java/com/aps/service/plan/PlanResultService.java
+4
-4
No files found.
src/main/java/com/aps/entity/Algorithm/OrderMaterialRequirement.java
View file @
e0ba6b7a
...
@@ -72,5 +72,5 @@ public class OrderMaterialRequirement {
...
@@ -72,5 +72,5 @@ public class OrderMaterialRequirement {
/**
/**
* 创建或使用的半成品订单ID
* 创建或使用的半成品订单ID
*/
*/
private
List
<
Integer
>
productOrderID
;
private
List
<
String
>
productOrderID
;
}
}
src/main/java/com/aps/entity/basic/Entry.java
View file @
e0ba6b7a
...
@@ -4,6 +4,7 @@ import com.aps.entity.Algorithm.OperationDependency;
...
@@ -4,6 +4,7 @@ import com.aps.entity.Algorithm.OperationDependency;
import
com.aps.entity.RoutingDiscreteParam
;
import
com.aps.entity.RoutingDiscreteParam
;
import
lombok.Data
;
import
lombok.Data
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
...
@@ -102,4 +103,21 @@ public class Entry {
...
@@ -102,4 +103,21 @@ public class Entry {
*/
*/
public
Long
EquipTypeID
;
public
Long
EquipTypeID
;
/// <summary>
/// 当前工序依赖的前置工序ID(半成品工序→成品工序)
/// </summary>
public
List
<
String
>
DependentOnOrderIds
=
new
ArrayList
<>();
/// <summary>
/// 关联的成品工序ID(核心:明确该半成品服务于哪个成品工序)
/// </summary>
public
int
TargetFinishedOperationId
=
0
;
/// <summary>
/// 半成品最晚完工时间(即成品工序开始时间-1天)
/// </summary>
public
LocalDateTime
LatestCompletionTime
;
}
}
src/main/java/com/aps/service/Algorithm/GeneticAlgorithm.java
View file @
e0ba6b7a
...
@@ -4,6 +4,7 @@ import com.aps.common.util.DeepCopyUtil;
...
@@ -4,6 +4,7 @@ import com.aps.common.util.DeepCopyUtil;
import
com.aps.common.util.ProductionDeepCopyUtil
;
import
com.aps.common.util.ProductionDeepCopyUtil
;
import
com.aps.entity.Algorithm.Chromosome
;
import
com.aps.entity.Algorithm.Chromosome
;
import
com.aps.entity.Algorithm.GlobalOperationInfo
;
import
com.aps.entity.Algorithm.GlobalOperationInfo
;
import
com.aps.entity.Algorithm.IDAndChildID.GroupResult
;
import
com.aps.entity.Algorithm.Pair
;
import
com.aps.entity.Algorithm.Pair
;
import
com.aps.entity.Algorithm.ScheduleParams
;
import
com.aps.entity.Algorithm.ScheduleParams
;
import
com.aps.entity.basic.*
;
import
com.aps.entity.basic.*
;
...
@@ -23,14 +24,16 @@ public class GeneticAlgorithm {
...
@@ -23,14 +24,16 @@ public class GeneticAlgorithm {
private
final
List
<
Order
>
orders
;
private
final
List
<
Order
>
orders
;
private
final
List
<
Material
>
materials
;
private
final
List
<
Material
>
materials
;
private
static
GlobalParam
_GlobalParam
;
private
static
GlobalParam
_GlobalParam
;
private
List
<
GroupResult
>
_entryRel
;
public
GeneticAlgorithm
(
GlobalParam
globalParam
,
List
<
Machine
>
machines
,
List
<
Order
>
orders
,
public
GeneticAlgorithm
(
GlobalParam
globalParam
,
List
<
Machine
>
machines
,
List
<
Order
>
orders
,
List
<
Material
>
materials
,
MachineSchedulerService
machineScheduler
)
{
List
<
Material
>
materials
,
MachineSchedulerService
machineScheduler
,
List
<
GroupResult
>
entryRel
)
{
this
.
machines
=
machines
;
this
.
machines
=
machines
;
this
.
orders
=
orders
;
this
.
orders
=
orders
;
this
.
materials
=
materials
;
this
.
materials
=
materials
;
this
.
machineScheduler
=
machineScheduler
;
this
.
machineScheduler
=
machineScheduler
;
_GlobalParam
=
globalParam
;
_GlobalParam
=
globalParam
;
_entryRel
=
entryRel
;
}
}
public
Chromosome
Run
(
ScheduleParams
param
,
List
<
Entry
>
allOperations
)
{
public
Chromosome
Run
(
ScheduleParams
param
,
List
<
Entry
>
allOperations
)
{
System
.
out
.
println
(
"开始"
);
System
.
out
.
println
(
"开始"
);
...
@@ -134,6 +137,7 @@ public class GeneticAlgorithm {
...
@@ -134,6 +137,7 @@ public class GeneticAlgorithm {
best
.
setBaseTime
(
param
.
getBaseTime
());
best
.
setBaseTime
(
param
.
getBaseTime
());
best
.
setInitMachines
(
ProductionDeepCopyUtil
.
deepCopyList
(
machines
));
best
.
setInitMachines
(
ProductionDeepCopyUtil
.
deepCopyList
(
machines
));
best
.
setOrders
(
orders
);
best
.
setOrders
(
orders
);
best
.
setOperatRel
(
_entryRel
);
// 步骤3:返回最优解
// 步骤3:返回最优解
return
best
;
return
best
;
...
...
src/main/java/com/aps/service/Algorithm/MaterialRequirementService.java
View file @
e0ba6b7a
...
@@ -3,15 +3,13 @@ package com.aps.service.Algorithm;
...
@@ -3,15 +3,13 @@ package com.aps.service.Algorithm;
import
com.aps.common.util.SnowFlackIdWorker
;
import
com.aps.common.util.SnowFlackIdWorker
;
import
com.aps.entity.*
;
import
com.aps.entity.*
;
import
com.aps.entity.Algorithm.BOMBuildResult
;
import
com.aps.entity.Algorithm.BOMBuildResult
;
import
com.aps.entity.Algorithm.IDAndChildID.GroupResult
;
import
com.aps.entity.Algorithm.OrderMaterialRequirement
;
import
com.aps.entity.Algorithm.OrderMaterialRequirement
;
import
com.aps.entity.basic.*
;
import
com.aps.entity.basic.*
;
import
com.aps.mapper.RoutingHeaderMapper
;
import
com.aps.mapper.RoutingHeaderMapper
;
import
com.aps.mapper.RoutingSupportingReplaceMapper
;
import
com.aps.mapper.RoutingSupportingReplaceMapper
;
import
com.aps.mapper.RoutingsupportingMapper
;
import
com.aps.mapper.RoutingsupportingMapper
;
import
com.aps.service.LanuchService
;
import
com.aps.service.*
;
import
com.aps.service.ProdEquipSpecialCalService
;
import
com.aps.service.RoutingDetailConnectService
;
import
com.aps.service.RoutingHeaderService
;
import
com.aps.service.impl.LanuchServiceImpl
;
import
com.aps.service.impl.LanuchServiceImpl
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
@@ -36,12 +34,19 @@ public class MaterialRequirementService {
...
@@ -36,12 +34,19 @@ public class MaterialRequirementService {
private
List
<
Entry
>
_allOperations
;
private
List
<
Entry
>
_allOperations
;
private
List
<
GroupResult
>
_entryRel
;
private
List
<
RoutingHeader
>
headers
;
private
List
<
RoutingHeader
>
headers
;
private
List
<
Routingsupporting
>
routingsupportings
;
private
List
<
Routingsupporting
>
routingsupportings
;
private
List
<
RoutingSupportingReplace
>
routingsupportingreplaces
;
private
List
<
RoutingSupportingReplace
>
routingsupportingreplaces
;
List
<
RoutingDetail
>
allRoutingDetails
=
new
ArrayList
<>();
List
<
RoutingDetailEquip
>
allroutingDetailEquips
=
new
ArrayList
<>();
List
<
RoutingDetailConnect
>
allroutingDetailconnections
=
new
ArrayList
<>();
List
<
RoutingDiscreteParam
>
allroutingDiscreteParams
=
new
ArrayList
<>();
@Autowired
@Autowired
RoutingDetailConnectService
routingDetailConnectService
;
RoutingDetailConnectService
routingDetailConnectService
;
...
@@ -57,16 +62,21 @@ public class MaterialRequirementService {
...
@@ -57,16 +62,21 @@ public class MaterialRequirementService {
@Autowired
@Autowired
RoutingsupportingMapper
routingsupportingMapper
;
RoutingsupportingMapper
routingsupportingMapper
;
@Autowired
RoutingDataService
_routingDataService
;
@Autowired
private
RoutingDiscreteParamService
_routingDiscreteParamService
;
private
LocalDateTime
baseTime
;
private
LocalDateTime
baseTime
;
public
MaterialRequirementService
(
List
<
Material
>
materials
,
List
<
Order
>
_orders
,
List
<
Entry
>
allOperations
)
public
MaterialRequirementService
(
List
<
Material
>
materials
,
List
<
Order
>
_orders
,
List
<
Entry
>
allOperations
,
List
<
GroupResult
>
entryRel
)
{
{
this
.
orders
=
_orders
;
this
.
orders
=
_orders
;
_allOperations
=
allOperations
;
_allOperations
=
allOperations
;
_materials
=
materials
;
_materials
=
materials
;
_entryRel
=
entryRel
;
}
}
/**
/**
...
@@ -110,7 +120,7 @@ public class MaterialRequirementService {
...
@@ -110,7 +120,7 @@ public class MaterialRequirementService {
}
}
// 递归展开BOM层级(通过结果对象接收out参数数据)
// 递归展开BOM层级(通过结果对象接收out参数数据)
BOMBuildResult
result
=
buildOrderBOM
(
demand
.
getRoutingId
(),
""
,
demand
.
getOrderId
(),
""
,
BOMBuildResult
result
=
buildOrderBOM
(
demand
.
getRoutingId
(),
""
,
demand
.
getOrderId
(),
demand
.
getOrderId
()
,
demand
.
getQuantity
(),
0
);
demand
.
getQuantity
(),
0
);
allRequirements
.
addAll
(
result
.
getMaterialRequirements
());
allRequirements
.
addAll
(
result
.
getMaterialRequirements
());
childorders
.
addAll
(
result
.
getChildOrders
());
childorders
.
addAll
(
result
.
getChildOrders
());
...
@@ -154,7 +164,7 @@ public class MaterialRequirementService {
...
@@ -154,7 +164,7 @@ public class MaterialRequirementService {
// 遍历产品的工序,递归构建工序BOM
// 遍历产品的工序,递归构建工序BOM
List
<
Entry
>
Operations
=
_allOperations
.
stream
()
List
<
Entry
>
Operations
=
_allOperations
.
stream
()
.
filter
(
t
->
t
.
getOrderId
()==
main
orderId
)
.
filter
(
t
->
t
.
getOrderId
()==
child
orderId
)
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
...
@@ -183,17 +193,12 @@ public class MaterialRequirementService {
...
@@ -183,17 +193,12 @@ public class MaterialRequirementService {
.
eq
(
RoutingHeader:
:
getIsDeleted
,
0
)
.
eq
(
RoutingHeader:
:
getIsDeleted
,
0
)
.
eq
(
RoutingHeader:
:
getApprovalStatus
,
1
);
// 添加 is_deleted=0 过滤条件
.
eq
(
RoutingHeader:
:
getApprovalStatus
,
1
);
// 添加 is_deleted=0 过滤条件
RoutingHeader
headers1
=
routingHeaderMapper
.
selectOne
(
wrapper
);
RoutingHeader
headers1
=
routingHeaderMapper
.
selectOne
(
wrapper
);
if
(
headers
==
null
)
if
(
headers
==
null
)
{
{
return
;
return
;
}
}
headers
.
add
(
headers1
);
headers
.
add
(
headers1
);
// List<Integer> routingIds = headers1.stream()
// .map(RoutingHeader::getId)
// .distinct()
// .collect(Collectors.toList());
Integer
routingIds
=
headers1
.
getId
();
Integer
routingIds
=
headers1
.
getId
();
LambdaQueryWrapper
<
Routingsupporting
>
routingsupportingwrapper
=
new
LambdaQueryWrapper
<>();
LambdaQueryWrapper
<
Routingsupporting
>
routingsupportingwrapper
=
new
LambdaQueryWrapper
<>();
...
@@ -202,6 +207,7 @@ if(headers==null)
...
@@ -202,6 +207,7 @@ if(headers==null)
List
<
Routingsupporting
>
routingsupportings1
=
routingsupportingMapper
.
selectList
(
routingsupportingwrapper
);
List
<
Routingsupporting
>
routingsupportings1
=
routingsupportingMapper
.
selectList
(
routingsupportingwrapper
);
routingsupportings
.
addAll
(
routingsupportings1
);
routingsupportings
.
addAll
(
routingsupportings1
);
LambdaQueryWrapper
<
RoutingSupportingReplace
>
routingsupportingreplacewrapper
=
new
LambdaQueryWrapper
<>();
LambdaQueryWrapper
<
RoutingSupportingReplace
>
routingsupportingreplacewrapper
=
new
LambdaQueryWrapper
<>();
routingsupportingreplacewrapper
.
in
(
RoutingSupportingReplace:
:
getStrsupid
,
routingIds
)
routingsupportingreplacewrapper
.
in
(
RoutingSupportingReplace:
:
getStrsupid
,
routingIds
)
.
eq
(
RoutingSupportingReplace:
:
getIsdeleted
,
0
);
.
eq
(
RoutingSupportingReplace:
:
getIsdeleted
,
0
);
...
@@ -241,6 +247,24 @@ if(headers==null)
...
@@ -241,6 +247,24 @@ if(headers==null)
.
map
(
connection
->
lanuchService
.
createProcessRelation
(
prodOrderMain
,
connection
,
sceneId
,
routingDetailIdToExecIdMap
))
.
map
(
connection
->
lanuchService
.
createProcessRelation
(
prodOrderMain
,
connection
,
sceneId
,
routingDetailIdToExecIdMap
))
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
List
<
Long
>
routingDetailIds
=
RoutingDetails
.
stream
()
.
map
(
RoutingDetail:
:
getId
)
.
distinct
()
.
collect
(
Collectors
.
toList
());
List
<
RoutingDiscreteParam
>
routingDiscreteParams
=
_routingDiscreteParamService
.
lambdaQuery
()
.
in
(
RoutingDiscreteParam:
:
getRoutingDetailId
,
routingDetailIds
)
.
eq
(
RoutingDiscreteParam:
:
getIsDeleted
,
0
)
.
list
();
List
<
ProdLaunchOrder
>
ProdLaunchOrders
=
new
ArrayList
<>();
ProdLaunchOrders
.
add
(
prodOrderMain
);
Map
<
Integer
,
Object
>
list
=
_routingDataService
.
CreateEntry
(
sceneId
,
ProdEquipmentList
,
ProdLaunchOrders
,
routingDiscreteParams
,
ProdOrderProcesslist
,
processExecList
,
_entryRel
);
}
}
private
ProdLaunchOrder
convertToLaunchOrder
(
Order
order
,
String
sceneId
)
{
private
ProdLaunchOrder
convertToLaunchOrder
(
Order
order
,
String
sceneId
)
{
...
@@ -378,7 +402,7 @@ if(headers==null)
...
@@ -378,7 +402,7 @@ if(headers==null)
order
.
setFinishOrderId
(
new
ArrayList
<>());
order
.
setFinishOrderId
(
new
ArrayList
<>());
}
}
order
.
getFinishOrderId
().
add
(
orderId
);
order
.
getFinishOrderId
().
add
(
orderId
);
orderMaterial
.
getProductOrderID
().
add
(
order
.
getId
());
orderMaterial
.
getProductOrderID
().
add
(
order
.
get
Order
Id
());
double
useq
=
Math
.
min
(
needed
,
order
.
getSYQuantity
());
double
useq
=
Math
.
min
(
needed
,
order
.
getSYQuantity
());
needed
-=
useq
;
needed
-=
useq
;
...
@@ -392,6 +416,7 @@ if(headers==null)
...
@@ -392,6 +416,7 @@ if(headers==null)
order
.
getQuantity
(),
l
);
order
.
getQuantity
(),
l
);
materialRequirements
.
addAll
(
childResult
.
getMaterialRequirements
());
materialRequirements
.
addAll
(
childResult
.
getMaterialRequirements
());
_childorders
.
addAll
(
childResult
.
getChildOrders
());
_childorders
.
addAll
(
childResult
.
getChildOrders
());
operation
.
getDependentOnOrderIds
().
add
(
order
.
getOrderId
());
}
}
if
(
needed
<=
0
)
{
if
(
needed
<=
0
)
{
...
@@ -415,9 +440,9 @@ if(headers==null)
...
@@ -415,9 +440,9 @@ if(headers==null)
childorder
.
setFinishOrderId
(
new
ArrayList
<>());
childorder
.
setFinishOrderId
(
new
ArrayList
<>());
childorder
.
getFinishOrderId
().
add
(
orderId
);
childorder
.
getFinishOrderId
().
add
(
orderId
);
_childorders
.
add
(
childorder
);
_childorders
.
add
(
childorder
);
CreateChild
(
childorder
,
material
.
getId
());
orderMaterial
.
getProductOrderID
().
add
(
childorder
.
getId
()
);
orderMaterial
.
getProductOrderID
().
add
(
OrderId
);
operation
.
getDependentOnOrderIds
().
add
(
OrderId
);
// 递归构建BOM
// 递归构建BOM
int
l
=
level
+
1
;
int
l
=
level
+
1
;
BOMBuildResult
childResult
=
buildOrderBOM
(
0
,
material
.
getId
(),
BOMBuildResult
childResult
=
buildOrderBOM
(
0
,
material
.
getId
(),
...
...
src/main/java/com/aps/service/plan/PlanResultService.java
View file @
e0ba6b7a
...
@@ -246,7 +246,7 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
...
@@ -246,7 +246,7 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
}
}
GlobalParam
globalParam
=
new
GlobalParam
();
GlobalParam
globalParam
=
new
GlobalParam
();
// 5. 执行调度算法
// 5. 执行调度算法
GeneticAlgorithm
scheduler
=
new
GeneticAlgorithm
(
globalParam
,
machines
,
orders
,
null
,
machineScheduler
);
//new GeneticAlgorithm(products, machines, orders, machineScheduler);
GeneticAlgorithm
scheduler
=
new
GeneticAlgorithm
(
globalParam
,
machines
,
orders
,
null
,
machineScheduler
,
null
);
//new GeneticAlgorithm(products, machines, orders, machineScheduler);
Chromosome
Chromosomes
=
scheduler
.
Run
(
param
,
allOperations
);
Chromosome
Chromosomes
=
scheduler
.
Run
(
param
,
allOperations
);
WriteScheduleSummary
(
Chromosomes
);
WriteScheduleSummary
(
Chromosomes
);
ScheduleOperationService
ScheduleOperation
=
new
ScheduleOperationService
();
ScheduleOperationService
ScheduleOperation
=
new
ScheduleOperationService
();
...
@@ -308,9 +308,9 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
...
@@ -308,9 +308,9 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
GlobalParam
globalParam
=
new
GlobalParam
();
GlobalParam
globalParam
=
new
GlobalParam
();
// 5. 执行调度算法
// 5. 执行调度算法
GeneticAlgorithm
scheduler
=
new
GeneticAlgorithm
(
globalParam
,
machines
,
orders
,
null
,
machineScheduler
);
//new GeneticAlgorithm(products, machines, orders, machineScheduler);
GeneticAlgorithm
scheduler
=
new
GeneticAlgorithm
(
globalParam
,
machines
,
orders
,
null
,
machineScheduler
,
entryRel
);
//new GeneticAlgorithm(products, machines, orders, machineScheduler);
Chromosome
chromosome
=
scheduler
.
Run
(
param
,
entrys
);
Chromosome
chromosome
=
scheduler
.
Run
(
param
,
entrys
);
chromosome
.
setOperatRel
(
entryRel
);
_sceneService
.
saveChromosomeToFile
(
chromosome
,
SceneId
);
_sceneService
.
saveChromosomeToFile
(
chromosome
,
SceneId
);
// Chromosomes.forEach(this::WriteScheduleSummary);
// Chromosomes.forEach(this::WriteScheduleSummary);
...
@@ -522,7 +522,7 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
...
@@ -522,7 +522,7 @@ order.setDueDate(LocalDateTime.of(2025, 12, 1,0,0,0));
GlobalParam
globalParam
=
new
GlobalParam
();
GlobalParam
globalParam
=
new
GlobalParam
();
// 5. 执行调度算法
// 5. 执行调度算法
GeneticAlgorithm
scheduler
=
new
GeneticAlgorithm
(
globalParam
,
machines
,
orders
,
null
,
machineScheduler
);
//new GeneticAlgorithm(products, machines, orders, machineScheduler);
GeneticAlgorithm
scheduler
=
new
GeneticAlgorithm
(
globalParam
,
machines
,
orders
,
null
,
machineScheduler
,
entryRel
);
//new GeneticAlgorithm(products, machines, orders, machineScheduler);
Chromosome
chromosomes
=
scheduler
.
Run
(
param
,
entrys
);
Chromosome
chromosomes
=
scheduler
.
Run
(
param
,
entrys
);
chromosomes
.
setScenarioID
(
SceneId
);
chromosomes
.
setScenarioID
(
SceneId
);
...
...
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