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
2f7a699b
Commit
2f7a699b
authored
May 29, 2026
by
DESKTOP-VKRD9QF\Administration
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://39.100.78.207:1213/tongli/hyh.apsj
parents
f3011df8
813959ca
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
654 additions
and
81 deletions
+654
-81
DraftScheduleResult.java
...in/java/com/aps/entity/Algorithm/DraftScheduleResult.java
+35
-0
Entry.java
src/main/java/com/aps/entity/basic/Entry.java
+6
-0
Material.java
src/main/java/com/aps/entity/basic/Material.java
+10
-0
GeneticDecoder.java
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
+164
-33
GeneticDecoderBom.java
...ain/java/com/aps/service/Algorithm/GeneticDecoderBom.java
+109
-0
HybridAlgorithm.java
src/main/java/com/aps/service/Algorithm/HybridAlgorithm.java
+7
-3
Initialization.java
src/main/java/com/aps/service/Algorithm/Initialization.java
+24
-5
MachineCalculator.java
...ain/java/com/aps/service/Algorithm/MachineCalculator.java
+11
-4
MaterialRequirementService.java
...com/aps/service/Algorithm/MaterialRequirementService.java
+4
-4
OperationSplitService.java
...java/com/aps/service/Algorithm/OperationSplitService.java
+272
-31
PlanResultService.java
src/main/java/com/aps/service/plan/PlanResultService.java
+12
-1
No files found.
src/main/java/com/aps/entity/Algorithm/DraftScheduleResult.java
0 → 100644
View file @
2f7a699b
package
com
.
aps
.
entity
.
Algorithm
;
/**
* 作者:佟礼
* 时间:2026-05-27
*/
public
class
DraftScheduleResult
{
private
int
operationId
;
private
int
idealStartTime
;
private
int
idealEndTime
;
private
Long
selectedMachineId
;
private
double
processTime
;
private
int
groupId
;
private
int
sequence
;
public
DraftScheduleResult
(
int
operationId
,
int
idealStartTime
,
int
idealEndTime
,
Long
selectedMachineId
,
double
processTime
,
int
groupId
,
int
sequence
)
{
this
.
operationId
=
operationId
;
this
.
idealStartTime
=
idealStartTime
;
this
.
idealEndTime
=
idealEndTime
;
this
.
selectedMachineId
=
selectedMachineId
;
this
.
processTime
=
processTime
;
this
.
groupId
=
groupId
;
this
.
sequence
=
sequence
;
}
public
int
getOperationId
()
{
return
operationId
;
}
public
int
getIdealStartTime
()
{
return
idealStartTime
;
}
public
int
getIdealEndTime
()
{
return
idealEndTime
;
}
public
Long
getSelectedMachineId
()
{
return
selectedMachineId
;
}
public
double
getProcessTime
()
{
return
processTime
;
}
public
int
getGroupId
()
{
return
groupId
;
}
public
int
getSequence
()
{
return
sequence
;
}
}
src/main/java/com/aps/entity/basic/Entry.java
View file @
2f7a699b
...
...
@@ -175,6 +175,12 @@ private Long isInterrupt = 1l;
private
int
anchorTimeSecond
=
0
;
private
transient
boolean
backwardFailed
=
false
;
private
transient
boolean
scheduled
=
false
;
private
transient
Integer
actualFinishTime
;
public
enum
SchedulingMode
{
FORWARD
,
BACKWARD
}
...
...
src/main/java/com/aps/entity/basic/Material.java
View file @
2f7a699b
...
...
@@ -67,6 +67,16 @@ public class Material {
*/
private
Long
CkeckLeadTime
;
/**
* 最小生产量
*/
private
BigDecimal
minProduction
;
/**
* 最大生产量
*/
private
BigDecimal
maxProduction
;
@Override
public
String
toString
()
{
return
"Material{"
+
...
...
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
View file @
2f7a699b
This diff is collapsed.
Click to expand it.
src/main/java/com/aps/service/Algorithm/GeneticDecoderBom.java
View file @
2f7a699b
...
...
@@ -385,4 +385,113 @@ if(isJit)
return
Math
.
max
(
estimatedStartTime
,
rawTime
);
}
/**
* 半成品锚点计算(JIT倒排模式:成品先于半成品,直接取成品已排的开始时间)
* 返回 -1 触发正排+标记成品重排,>=0 作为半成品倒排锚点(半成品最晚完成时间)
*/
public
int
computeHybridSemiAnchor
(
GeneticDecoder
decoder
,
int
semiOrderId
,
Map
<
Integer
,
List
<
Entry
>>
entrysBygroupId
,
Map
<
String
,
OpMachine
>
opMachineKeyMap
,
Chromosome
chromosome
,
Map
<
Integer
,
GAScheduleResult
>
scheduleIndexById
,
Map
<
Long
,
CopyOnWriteArrayList
<
GAScheduleResult
>>
machineTasksCache
,
Map
<
Long
,
Machine
>
machineIdMap
,
Map
<
Integer
,
Entry
>
entryIndexById
,
Set
<
Integer
>
reForwardFinishedOrderIds
,
GlobalParam
_globalParam
,
Order
order
)
{
List
<
Entry
>
sfOps
=
entrysBygroupId
.
get
(
semiOrderId
);
if
(
sfOps
==
null
||
sfOps
.
isEmpty
())
return
0
;
Entry
firstSfOp
=
sfOps
.
stream
().
min
(
Comparator
.
comparing
(
Entry:
:
getSequence
)).
orElse
(
null
);
if
(
firstSfOp
==
null
)
return
0
;
List
<
Integer
>
targetFinishedOpIds
=
firstSfOp
.
getTargetFinishedOperationId
();
if
(
targetFinishedOpIds
==
null
||
targetFinishedOpIds
.
isEmpty
())
{
return
0
;
}
// 找关联的成品订单
int
finishedOrderId
=
-
1
;
Entry
targetFinishedOp
=
null
;
for
(
Integer
targetOpId
:
targetFinishedOpIds
)
{
Entry
op
=
entryIndexById
.
get
(
targetOpId
);
if
(
op
!=
null
)
{
targetFinishedOp
=
op
;
finishedOrderId
=
op
.
getGroupId
();
break
;
}
}
if
(
finishedOrderId
<=
0
)
return
0
;
List
<
Entry
>
finishedOps
=
entrysBygroupId
.
get
(
finishedOrderId
).
stream
()
.
sorted
(
Comparator
.
comparing
(
Entry:
:
getSequence
))
.
collect
(
Collectors
.
toList
());
if
(
finishedOps
.
isEmpty
())
return
0
;
// JIT倒排模式成品已排完,直接从scheduleIndexById取成品第一道工序的开始时间
Entry
finishedFirstOp
=
finishedOps
.
get
(
0
);
GAScheduleResult
finishedFirstResult
=
scheduleIndexById
.
get
(
finishedFirstOp
.
getId
());
if
(
finishedFirstResult
==
null
)
{
// 成品还没排(不应该发生在JIT模式),降级为原有逻辑
return
computeSemiFinishedAnchor
(
decoder
,
semiOrderId
,
entrysBygroupId
,
opMachineKeyMap
,
chromosome
,
scheduleIndexById
,
machineTasksCache
,
machineIdMap
,
entryIndexById
);
}
String
schedulingMode
=
finishedFirstOp
.
getSchedulingMode
();
if
(
Entry
.
SchedulingMode
.
BACKWARD
.
name
().
equals
(
schedulingMode
))
{
// 成品倒排成功 → 半成品倒排:锚点 = 成品开始时间 - 缓冲
int
semiLatestEndTime
=
finishedFirstResult
.
getStartTime
();
int
semiTotalTime
=
0
;
for
(
Entry
op
:
sfOps
)
{
String
key
=
semiOrderId
+
"_"
+
op
.
getSequence
();
OpMachine
opt
=
opMachineKeyMap
.
get
(
key
);
if
(
opt
!=
null
)
semiTotalTime
+=
calculateOperationProcessingTime
(
op
,
opt
,
_globalParam
);
}
Material
material
=
chromosome
.
getMaterials
().
get
(
order
.
getMaterialId
());
int
ckeckLeadTime
=
0
;
if
(
material
.
getCkeckLeadTime
()!=
null
)
{
ckeckLeadTime
=(
material
.
getCkeckLeadTime
().
intValue
()*
24
*
60
*
60
);
}
semiTotalTime
+=
ckeckLeadTime
;
if
(
semiLatestEndTime
-
semiTotalTime
<
0
)
{
FileHelper
.
writeLogFile
(
"[HybridSemi] 半成品"
+
semiOrderId
+
" 倒排开工<0,正排+成品"
+
finishedOrderId
+
"重排"
);
reForwardFinishedOrderIds
.
add
(
finishedOrderId
);
return
-
1
;
}
FileHelper
.
writeLogFile
(
"[HybridSemi] 半成品"
+
semiOrderId
+
" 锚点="
+
semiLatestEndTime
+
" (成品"
+
finishedOrderId
+
"开始="
+
finishedFirstResult
.
getStartTime
()
+
")"
);
return
semiLatestEndTime
-
ckeckLeadTime
;
}
else
{
// 成品正排了 → 半成品也正排
FileHelper
.
writeLogFile
(
"[HybridSemi] 成品"
+
finishedOrderId
+
"已正排,半成品"
+
semiOrderId
+
"也正排"
);
reForwardFinishedOrderIds
.
add
(
finishedOrderId
);
return
-
1
;
}
}
private
int
calculateOperationProcessingTime
(
Entry
op
,
OpMachine
machineOption
,
GlobalParam
_globalParam
)
{
int
total
=
0
;
if
(
op
.
getConstTime
()
==
1
)
//常数时间
{
total
=
(
int
)
Math
.
ceil
(
machineOption
.
getRuntime
().
doubleValue
());
}
else
{
double
t
=
machineOption
.
getRuntime
().
doubleValue
()
/
machineOption
.
getSingleOut
().
doubleValue
()
*
(
op
.
getQuantity
());
total
=
(
int
)
Math
.
ceil
(
t
);
}
if
(
op
.
getSetupTime
()
!=
null
)
total
+=
op
.
getSetupTime
().
intValue
();
total
+=
op
.
getTeardownTime
();
if
(
!
_globalParam
.
is_smoothSetup
())
{
total
+=
op
.
getPreTime
();
}
return
total
;
}
}
src/main/java/com/aps/service/Algorithm/HybridAlgorithm.java
View file @
2f7a699b
...
...
@@ -85,7 +85,9 @@ public class HybridAlgorithm {
{
throw
new
RuntimeException
(
"没有待排产工单"
);
}
if
(
_GlobalParam
.
isIsMultipleMachine
())
{
allOperations
=
OperationSplitService
.
splitMultiMachineOperations
(
allOperations
,
_GlobalParam
,
machines
,
_entryRel
);
}
// if(materials!=null&&materials.size()>0) {
//
// materialRequirementService.init(materials, orders, allOperations, _entryRel, machineScheduler, machines,_GlobalParam);
...
...
@@ -433,6 +435,7 @@ public class HybridAlgorithm {
chromosome
.
setMaterials
(
ProductionDeepCopyUtil
.
deepCopyTreeMap
(
materials
,
String
.
class
,
Material
.
class
));
// 简单拷贝,实际可能需要深拷贝
chromosome
.
setAllOperations
(
ProductionDeepCopyUtil
.
deepCopyList
(
new
CopyOnWriteArrayList
<>(
allOperations
),
Entry
.
class
)
);
// 简单拷贝,实际可能需要深拷贝
chromosome
.
setGlobalOpList
(
ProductionDeepCopyUtil
.
deepCopyList
(
globalOpList
,
GlobalOperationInfo
.
class
)
);
// 简单拷贝,实际可能需要深拷贝
//chromosome.setObjectiveWeights(_objectiveWeights);
chromosome
.
setBaseTime
(
param
.
getBaseTime
());
...
...
@@ -490,8 +493,9 @@ public class HybridAlgorithm {
chromosome
.
setMaterials
(
ProductionDeepCopyUtil
.
deepCopyTreeMap
(
materials
,
String
.
class
,
Material
.
class
));
// 简单拷贝,实际可能需要深拷贝
chromosome
.
setAllOperations
(
ProductionDeepCopyUtil
.
deepCopyList
(
new
CopyOnWriteArrayList
<>(
allOperations
),
Entry
.
class
)
);
// 简单拷贝,实际可能需要深拷贝
// chromosome.setGlobalOpList(ProductionDeepCopyUtil.deepCopyList(globalOpList, GlobalOperationInfo.class) ); // 简单拷贝,实际可能需要深拷贝
if
(
chromosome
.
getAllOperations
()
==
null
||
chromosome
.
getAllOperations
().
isEmpty
())
{
chromosome
.
setAllOperations
(
ProductionDeepCopyUtil
.
deepCopyList
(
new
CopyOnWriteArrayList
<>(
allOperations
),
Entry
.
class
)
);
}
// chromosome.setGlobalOpList(ProductionDeepCopyUtil.deepCopyList(globalOpList, GlobalOperationInfo.class) ); // 简单拷贝,实际可能需要深拷贝
//chromosome.setObjectiveWeights(_objectiveWeights);
chromosome
.
setBaseTime
(
param
.
getBaseTime
());
// chromosome.setInitMachines(ProductionDeepCopyUtil.deepCopyList(machines,Machine.class)); // 简单拷贝,实际可能需要深拷贝
...
...
src/main/java/com/aps/service/Algorithm/Initialization.java
View file @
2f7a699b
...
...
@@ -478,7 +478,10 @@ public class Initialization {
.
thenComparing
(
randomIds:
:
get
));
}
}
if
(
_globalParam
.
isIsMultipleMachine
())
{
sortedOps
=
OperationSplitService
.
splitOpsForHeuristic
(
sortedOps
,
rnd
);
chromosome
.
setAllOperations
(
new
CopyOnWriteArrayList
<>(
sortedOps
));
}
int
globalOpId
=
0
;
// 为每个工序选择机器
...
...
@@ -583,7 +586,10 @@ public class Initialization {
.
thenComparing
(
randomIds:
:
get
));
}
if
(
_globalParam
.
isIsMultipleMachine
())
{
sortedOps
=
OperationSplitService
.
splitOpsForHeuristic
(
sortedOps
,
rnd
);
chromosome
.
setAllOperations
(
new
CopyOnWriteArrayList
<>(
sortedOps
));
}
int
globalOpId
=
0
;
// 为每个工序选择机器
for
(
Entry
op
:
sortedOps
)
{
...
...
@@ -672,6 +678,10 @@ public class Initialization {
.
thenComparing
(
op
->
op
.
getMachineOptions
().
get
(
0
).
getProcessingTime
()
*
op
.
getQuantity
())
.
thenComparing
(
randomIds:
:
get
));
if
(
_globalParam
.
isIsMultipleMachine
())
{
sortedOps
=
OperationSplitService
.
splitOpsForHeuristic
(
sortedOps
,
rnd
);
chromosome
.
setAllOperations
(
new
CopyOnWriteArrayList
<>(
sortedOps
));
}
int
globalOpId
=
0
;
for
(
Entry
op
:
sortedOps
)
{
...
...
@@ -817,7 +827,10 @@ public class Initialization {
})
.
thenComparing
(
randomIds:
:
get
));
}
if
(
_globalParam
.
isIsMultipleMachine
())
{
sortedOps
=
OperationSplitService
.
splitOpsForHeuristic
(
sortedOps
,
rnd
);
chromosome
.
setAllOperations
(
new
CopyOnWriteArrayList
<>(
sortedOps
));
}
int
globalOpId
=
0
;
for
(
Entry
op
:
sortedOps
)
{
int
groupId
=
op
.
getGroupId
();
...
...
@@ -907,7 +920,10 @@ public class Initialization {
})
.
thenComparing
(
op
->
op
.
getProductId
()
!=
null
?
op
.
getProductId
()
:
""
)
.
thenComparing
(
randomIds:
:
get
));
if
(
_globalParam
.
isIsMultipleMachine
())
{
sortedOps
=
OperationSplitService
.
splitOpsForHeuristic
(
sortedOps
,
rnd
);
chromosome
.
setAllOperations
(
new
CopyOnWriteArrayList
<>(
sortedOps
));
}
int
globalOpId
=
0
;
for
(
Entry
op
:
sortedOps
)
{
int
groupId
=
op
.
getGroupId
();
...
...
@@ -971,7 +987,10 @@ public class Initialization {
.
thenComparing
(
op
->
op
.
getProductId
()
!=
null
?
op
.
getProductId
()
:
""
)
// 相同物料排在一起,减少换型
.
thenComparing
(
randomIds:
:
get
));
if
(
_globalParam
.
isIsMultipleMachine
())
{
sortedOps
=
OperationSplitService
.
splitOpsForHeuristic
(
sortedOps
,
rnd
);
chromosome
.
setAllOperations
(
new
CopyOnWriteArrayList
<>(
sortedOps
));
}
int
globalOpId
=
0
;
...
...
src/main/java/com/aps/service/Algorithm/MachineCalculator.java
View file @
2f7a699b
...
...
@@ -540,13 +540,20 @@ public class MachineCalculator {
double
e
=
(
double
)
processingTime
/
slot
.
getEfficiency
();
LocalDateTime
endCandidate
=
startCandidate
.
plusSeconds
((
int
)
Math
.
ceil
(
e
));
LocalDateTime
endCandidate
=
null
;
LocalDateTime
startCandidate1
=
null
;
if
(
isJit
)
{
endCandidate
=
endCandidate1
;
startCandidate1
=
endCandidate
.
plusSeconds
(-(
int
)
Math
.
ceil
(
e
));;
}
else
{
endCandidate
=
startCandidate
.
plusSeconds
((
int
)
Math
.
ceil
(
e
));
startCandidate1
=
startCandidate
;
}
ScheduleResultDetail
time
=
new
ScheduleResultDetail
();
time
.
setKey
(
slot
.
getKey
());
time
.
setStartTime
((
int
)
ChronoUnit
.
SECONDS
.
between
(
baseTime
,
startCandidate
));
time
.
setStartTime
((
int
)
ChronoUnit
.
SECONDS
.
between
(
baseTime
,
startCandidate
1
));
time
.
setEndTime
((
int
)
ChronoUnit
.
SECONDS
.
between
(
baseTime
,
endCandidate
));
time
.
setOneTime
(
oneTime
);
time
.
setQuantity
(
quantity
);
...
...
src/main/java/com/aps/service/Algorithm/MaterialRequirementService.java
View file @
2f7a699b
...
...
@@ -1250,7 +1250,7 @@ if(demand==null)
}
}
}
FileHelper
.
writeLogFile
(
"BOM:"
+
material
.
getCode
());
//
FileHelper.writeLogFile("BOM:"+material.getCode());
if
(
needed
<=
0
)
{
orderMaterial
.
setYpQty
(
allneeded
-
needed
);
orderMaterial
.
setQjQty
(
needed
);
...
...
@@ -1285,11 +1285,11 @@ if(demand==null)
for
(
RoutingSupportingReplace
rsr
:
routingsupportingreplaces2
)
{
Material
material1
=
materials
.
get
(
rsr
.
getTargetmaterialid
());
FileHelper
.
writeLogFile
(
"RoutingSupportingReplace:"
+
material1
.
getCode
());
//
FileHelper.writeLogFile("RoutingSupportingReplace:"+material1.getCode());
if
(
material1
==
null
)
{
break
;
}
FileHelper
.
writeLogFile
(
"RoutingSupportingReplace: "
+(
commitChanges
?
"1"
:
"0"
)+
" "
+
material1
.
getCode
()+
": "
+
useStock
);
//
FileHelper.writeLogFile("RoutingSupportingReplace: "+(commitChanges?"1":"0")+" " +material1.getCode()+": "+useStock);
OrderMaterialRequirement
orderMaterial1
=
MaterialStock
(
material1
,
rsr
.
getTargetmaterialid
(),
orderMaterial
.
getOrderId
(),
orderMaterial
.
getChildOrderId
(),
operationId
,
allneeded
,
needed
,
earliestStartTime
,
commitChanges
);
if
(
orderMaterial1
!=
null
)
{
...
...
@@ -1297,7 +1297,7 @@ if(demand==null)
needed
-=
useStock
;
FileHelper
.
writeLogFile
(
"RoutingSupportingReplace: "
+(
commitChanges
?
"1"
:
"0"
)+
" "
+
material1
.
getCode
()+
": "
+
useStock
);
//
FileHelper.writeLogFile("RoutingSupportingReplace: "+(commitChanges?"1":"0")+" " +material1.getCode()+": "+useStock);
orderMaterial
.
setUseStock
(
orderMaterial
.
getUseStock
()
+
useStock
);
orderMaterial
.
getReplaceMaterial
().
add
(
orderMaterial1
);
if
(
needed
<=
0
)
{
...
...
src/main/java/com/aps/service/Algorithm/OperationSplitService.java
View file @
2f7a699b
This diff is collapsed.
Click to expand it.
src/main/java/com/aps/service/plan/PlanResultService.java
View file @
2f7a699b
...
...
@@ -2069,6 +2069,12 @@ public class PlanResultService {
.
sorted
(
Comparator
.
comparingInt
(
GAScheduleResult:
:
getOperationId
))
.
collect
(
Collectors
.
toList
());
Map
<
Integer
,
Order
>
orders
=
schedule
.
getOrders
().
stream
()
.
collect
(
Collectors
.
toMap
(
Order:
:
getId
,
// 2. Value映射:Material → Material
order
->
order
));
for
(
GAScheduleResult
job
:
sortedJobs
)
{
StringBuilder
sb
=
new
StringBuilder
();
String
TargetFinishedOperationIds
=
""
;
...
...
@@ -2078,14 +2084,16 @@ public class PlanResultService {
.
map
(
String:
:
valueOf
)
// 把每个Integer转成String
.
collect
(
Collectors
.
joining
(
","
));
}
Order
order
=
orders
.
get
(
job
.
getGroupId
());
sb
.
append
(
String
.
format
(
"[%d-%d]:[%s-%s] Order %d,OrderID %s, Machine %d, Operation %d, Quantity %.1f, processingTime %.1f, 前处理 %d, 后处理 %d, 离散参数 %d, bomtime %s,TargetOperationId %s"
,
"[%d-%d]:[%s-%s] Order %d,OrderID %s,
OrderDueDate %s,
Machine %d, Operation %d, Quantity %.1f, processingTime %.1f, 前处理 %d, 后处理 %d, 离散参数 %d, bomtime %s,TargetOperationId %s"
,
job
.
getStartTime
(),
job
.
getEndTime
(),
ConvertTime
(
job
.
getStartTime
()),
ConvertTime
(
job
.
getEndTime
()),
job
.
getGroupId
(),
job
.
getOrderId
(),
order
.
getDueDate
().
format
(
DateTimeFormatter
.
ofPattern
(
"YYYY-MM-dd HH:mm:ss"
)),
job
.
getMachineId
(),
job
.
getOperationId
(),
job
.
getQuantity
(),
...
...
@@ -2469,6 +2477,9 @@ if(job.getGeneDetails()!=null)
material
.
setMaterialTypeName
(
m
.
getMaterialTypeName
());
material
.
setCode
(
m
.
getCode
());
material
.
setName
(
m
.
getName
());
material
.
setMaxProduction
(
m
.
getMaxProduction
());
material
.
setMinProduction
(
m
.
getMinProduction
());
// material.setCkeckLeadTime(m.getInspectDuration());
// material.setPurchaseLeadTime(m.getPurchaseDuration());
...
...
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