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
f1998b61
Commit
f1998b61
authored
Apr 11, 2026
by
Tong Li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
变邻域+模拟退火+禁忌搜索
parent
8a7de711
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
723 additions
and
340 deletions
+723
-340
Order.java
src/main/java/com/aps/entity/basic/Order.java
+5
-0
GeneticDecoder.java
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
+99
-99
GeneticOperations.java
...ain/java/com/aps/service/Algorithm/GeneticOperations.java
+7
-1
MaterialRequirementService.java
...com/aps/service/Algorithm/MaterialRequirementService.java
+216
-218
MaterialRequirementServicebf.java
...m/aps/service/Algorithm/MaterialRequirementServicebf.java
+1
-1
VariableNeighborhoodSearch.java
...com/aps/service/Algorithm/VariableNeighborhoodSearch.java
+394
-20
PlanResultService.java
src/main/java/com/aps/service/plan/PlanResultService.java
+1
-1
No files found.
src/main/java/com/aps/entity/basic/Order.java
View file @
f1998b61
...
@@ -157,6 +157,11 @@ public class Order {
...
@@ -157,6 +157,11 @@ public class Order {
*/
*/
private
boolean
newCreate
=
false
;
private
boolean
newCreate
=
false
;
/**
* 是否新创建半成品,默认值:false
*/
private
boolean
newSfCreate
=
false
;
/**
/**
* 是否创建BOM,默认值:false
* 是否创建BOM,默认值:false
*/
*/
...
...
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
View file @
f1998b61
...
@@ -266,7 +266,7 @@ public class GeneticDecoder {
...
@@ -266,7 +266,7 @@ public class GeneticDecoder {
Initialization
initialization
=
new
Initialization
();
Initialization
initialization
=
new
Initialization
();
initialization
.
generateInitialSFPopulation
(
chromosome
,
globalOpList
);
initialization
.
generateInitialSFPopulation
(
chromosome
,
globalOpList
);
chromosome
.
getGlobalOpList
().
addAll
(
globalOpList
);
chromosome
.
getGlobalOpList
().
addAll
(
globalOpList
);
return
1
;
return
1
;
}
}
private
void
CreateNewOpSequence
(
Chromosome
chromosome
)
private
void
CreateNewOpSequence
(
Chromosome
chromosome
)
...
@@ -279,10 +279,10 @@ return 1;
...
@@ -279,10 +279,10 @@ return 1;
.
distinct
()
.
distinct
()
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
if
(
finishedOrder
==
null
||
finishedOrder
.
size
()==
0
)
if
(
finishedOrder
==
null
||
finishedOrder
.
size
()==
0
)
{
{
return
;
return
;
}
}
List
<
Integer
>
oldSequence
=
chromosome
.
getOperationSequencing
();
List
<
Integer
>
oldSequence
=
chromosome
.
getOperationSequencing
();
List
<
Integer
>
finalSequence
=
new
ArrayList
<>();
List
<
Integer
>
finalSequence
=
new
ArrayList
<>();
...
@@ -391,7 +391,7 @@ if(finishedOrder==null||finishedOrder.size()==0)
...
@@ -391,7 +391,7 @@ if(finishedOrder==null||finishedOrder.size()==0)
public
void
serialDecode
(
Chromosome
chromosome
)
{
public
void
serialDecode
(
Chromosome
chromosome
)
{
//
List<OrderMaterialRequirement> orderMaterials = materialRequirementService.buildMultiLevelRequirementNetwork(chromosome, sceneId, baseTime,_globalParam);
List
<
OrderMaterialRequirement
>
orderMaterials
=
materialRequirementService
.
buildMultiLevelRequirementNetwork
(
chromosome
,
sceneId
,
baseTime
,
_globalParam
);
chromosome
.
setScenarioID
(
sceneId
);
chromosome
.
setScenarioID
(
sceneId
);
if
(
_globalParam
.
isIsCheckSf
())
{
if
(
_globalParam
.
isIsCheckSf
())
{
int
isnew
=
generateGlobalOpList
(
chromosome
);
int
isnew
=
generateGlobalOpList
(
chromosome
);
...
@@ -1014,7 +1014,7 @@ if(finishedOrder==null||finishedOrder.size()==0)
...
@@ -1014,7 +1014,7 @@ if(finishedOrder==null||finishedOrder.size()==0)
prevtime
=
Math
.
max
(
prevtime
,
bomtime
);
prevtime
=
Math
.
max
(
prevtime
,
bomtime
);
Machine
machine
=
machineIdMap
.
get
(
machineId
);
Machine
machine
=
machineIdMap
.
get
(
machineId
);
int
actualEndTime
=
processWithSingleMachine
(
currentOp
,
machine
,
processTime
,
prevtime
,
machineOption
,
chromosome
,
false
,
prevendtime
,
machineTasksCache
,
entryIndexById
,
scheduleIndexById
);
int
actualEndTime
=
processWithSingleMachine
(
currentOp
,
machine
,
processTime
,
prevtime
,
machineOption
,
chromosome
,
false
,
prevendtime
,
machineTasksCache
,
entryIndexById
,
scheduleIndexById
);
return
actualEndTime
;
return
actualEndTime
;
}
}
...
@@ -1474,9 +1474,9 @@ return actualEndTime;
...
@@ -1474,9 +1474,9 @@ return actualEndTime;
{
{
return
0
;
return
0
;
}
}
LocalDateTime
earliestStartTime1
=
baseTime
.
plusSeconds
(
earliestStartTime
);
LocalDateTime
earliestStartTime1
=
baseTime
.
plusSeconds
(
earliestStartTime
);
materialRequirementService
.
EditOperationBOM
(
currentOp
,
chromosome
,
earliestStartTime1
,
this
,
machineTasksCache
,
entryIndexById
,
scheduleIndexById
);
materialRequirementService
.
EditOperationBOM
(
currentOp
,
chromosome
,
earliestStartTime1
,
this
,
machineTasksCache
,
entryIndexById
,
scheduleIndexById
,
baseTime
);
return
getOperationBOMTime
(
currentOp
,
chromosome
);
return
getOperationBOMTime
(
currentOp
,
chromosome
);
}
}
...
@@ -1576,10 +1576,10 @@ return getOperationBOMTime(currentOp, chromosome);
...
@@ -1576,10 +1576,10 @@ return getOperationBOMTime(currentOp, chromosome);
&&
t
.
getProductOrderID
()
!=
null
&&
!
t
.
getProductOrderID
().
isEmpty
()
&&
t
.
getProductOrderID
()
!=
null
&&
!
t
.
getProductOrderID
().
isEmpty
()
)
)
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
if
(
MaterialRequirements
==
null
||
MaterialRequirements
.
size
()==
0
)
if
(
MaterialRequirements
==
null
||
MaterialRequirements
.
size
()==
0
)
{
{
continue
;
continue
;
}
}
for
(
OrderMaterialRequirement
orderMaterial:
MaterialRequirements
)
{
for
(
OrderMaterialRequirement
orderMaterial:
MaterialRequirements
)
{
List
<
Integer
>
orderids
=
orderMaterial
.
getProductOrderID
();
List
<
Integer
>
orderids
=
orderMaterial
.
getProductOrderID
();
if
(
orderids
!=
null
&&
orderids
.
size
()>
0
)
{
if
(
orderids
!=
null
&&
orderids
.
size
()>
0
)
{
...
@@ -2332,7 +2332,7 @@ if(MaterialRequirements==null||MaterialRequirements.size()==0)
...
@@ -2332,7 +2332,7 @@ if(MaterialRequirements==null||MaterialRequirements.size()==0)
.
filter
(
t
->
orderIds
.
contains
(
t
.
getOrderId
()))
.
filter
(
t
->
orderIds
.
contains
(
t
.
getOrderId
()))
.
max
(
Comparator
.
comparing
(
Order:
:
getDueDate
))
.
max
(
Comparator
.
comparing
(
Order:
:
getDueDate
))
.
orElse
(
null
);
.
orElse
(
null
);
if
(
order
.
isNewCreate
())
{
if
(
order
.
isNew
Sf
Create
())
{
continue
;
continue
;
}
}
LocalDateTime
dueDateTime
=
order
.
getDueDate
();
LocalDateTime
dueDateTime
=
order
.
getDueDate
();
...
...
src/main/java/com/aps/service/Algorithm/GeneticOperations.java
View file @
f1998b61
...
@@ -25,6 +25,10 @@ public class GeneticOperations {
...
@@ -25,6 +25,10 @@ public class GeneticOperations {
private
static
ScheduleParams
param
;
private
static
ScheduleParams
param
;
public
GeneticOperations
()
{
}
public
GeneticOperations
(
GlobalParam
globalParam
,
List
<
Entry
>
_allOperations
,
ScheduleParams
_param
)
{
public
GeneticOperations
(
GlobalParam
globalParam
,
List
<
Entry
>
_allOperations
,
ScheduleParams
_param
)
{
_GlobalParam
=
globalParam
;
_GlobalParam
=
globalParam
;
allOperations
=
_allOperations
;
allOperations
=
_allOperations
;
...
@@ -424,10 +428,12 @@ public class GeneticOperations {
...
@@ -424,10 +428,12 @@ public class GeneticOperations {
public
void
DelOrder
(
Chromosome
chromosome
)
{
public
void
DelOrder
(
Chromosome
chromosome
)
{
List
<
Entry
>
allOperations
=
chromosome
.
getAllOperations
();
List
<
Entry
>
allOperations
=
chromosome
.
getAllOperations
();
List
<
GlobalOperationInfo
>
globalOpList
=
chromosome
.
getGlobalOpList
();
List
<
GlobalOperationInfo
>
globalOpList
=
chromosome
.
getGlobalOpList
();
if
(
chromosome
.
getOrders
()==
null
||
chromosome
.
getOrders
().
size
()==
0
)
return
;
List
<
Order
>
orders
=
chromosome
.
getOrders
();
List
<
Order
>
orders
=
chromosome
.
getOrders
();
List
<
Integer
>
OperationSequencing
=
chromosome
.
getOperationSequencing
();
List
<
Integer
>
OperationSequencing
=
chromosome
.
getOperationSequencing
();
List
<
Integer
>
newoorderids
=
orders
.
stream
()
List
<
Integer
>
newoorderids
=
orders
.
stream
()
.
filter
(
t
->
t
.
isNewCreate
())
.
filter
(
t
->
t
.
isNew
Sf
Create
())
.
map
(
Order:
:
getId
)
.
map
(
Order:
:
getId
)
.
sorted
(
Comparator
.
reverseOrder
())
.
sorted
(
Comparator
.
reverseOrder
())
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
...
...
src/main/java/com/aps/service/Algorithm/MaterialRequirementService.java
View file @
f1998b61
...
@@ -179,7 +179,7 @@ public class MaterialRequirementService {
...
@@ -179,7 +179,7 @@ public class MaterialRequirementService {
double
allneeded
=
component
.
getSpentQty
().
doubleValue
()/
component
.
getMainQty
().
doubleValue
()
*
operation
.
getQuantity
();
double
allneeded
=
component
.
getSpentQty
().
doubleValue
()/
component
.
getMainQty
().
doubleValue
()
*
operation
.
getQuantity
();
OrderMaterialRequirement
orderMaterialRequirement
=
CreateMaterialRequirement
(
material
,
orderId
,
""
,
operation
,
OrderMaterialRequirement
orderMaterialRequirement
=
CreateMaterialRequirement
(
material
,
orderId
,
""
,
operation
,
allneeded
,
component
.
getSpentQty
().
doubleValue
(),
component
.
getMainQty
().
doubleValue
(),
operation
.
getQuantity
());
allneeded
,
component
.
getSpentQty
().
doubleValue
(),
component
.
getMainQty
().
doubleValue
(),
operation
.
getQuantity
()
,
baseTime
);
orderMaterialRequirement
.
setBomId
(
component
.
getStrId
());
orderMaterialRequirement
.
setBomId
(
component
.
getStrId
());
if
(!
material
.
getMaterialTypeName
().
equals
(
"MP"
)
&&
isIsCheckSf
)
{
if
(!
material
.
getMaterialTypeName
().
equals
(
"MP"
)
&&
isIsCheckSf
)
{
materialIds
.
add
(
materialId
);
//半成品ID
materialIds
.
add
(
materialId
);
//半成品ID
...
@@ -503,8 +503,6 @@ public class MaterialRequirementService {
...
@@ -503,8 +503,6 @@ public class MaterialRequirementService {
* @return 所有物料需求列表
* @return 所有物料需求列表
*/
*/
public
List
<
OrderMaterialRequirement
>
buildMultiLevelRequirementNetwork
(
Chromosome
chromosome
,
String
sceneId
,
LocalDateTime
_baseTime
,
GlobalParam
_globalParam
)
{
public
List
<
OrderMaterialRequirement
>
buildMultiLevelRequirementNetwork
(
Chromosome
chromosome
,
String
sceneId
,
LocalDateTime
_baseTime
,
GlobalParam
_globalParam
)
{
baseTime
=
_baseTime
;
globalParam
=
_globalParam
;
List
<
OrderMaterialRequirement
>
allRequirements
=
new
ArrayList
<>();
List
<
OrderMaterialRequirement
>
allRequirements
=
new
ArrayList
<>();
List
<
Order
>
childorders
=
new
ArrayList
<>();
List
<
Order
>
childorders
=
new
ArrayList
<>();
List
<
Entry
>
_newEntrys
=
new
ArrayList
<>();
List
<
Entry
>
_newEntrys
=
new
ArrayList
<>();
...
@@ -519,7 +517,7 @@ public class MaterialRequirementService {
...
@@ -519,7 +517,7 @@ public class MaterialRequirementService {
.
entrySet
().
stream
()
.
entrySet
().
stream
()
.
collect
(
Collectors
.
toMap
(
Map
.
Entry
::
getKey
,
e
->
0
));
.
collect
(
Collectors
.
toMap
(
Map
.
Entry
::
getKey
,
e
->
0
));
List
<
Integer
>
operationSequencing
=
chromosome
.
getOperationSequencing
(
);
List
<
Integer
>
operationSequencing
=
new
ArrayList
<>(
chromosome
.
getOperationSequencing
()
);
orders
.
forEach
(
t
->
clearFinishOrder
(
t
));
orders
.
forEach
(
t
->
clearFinishOrder
(
t
));
...
@@ -546,7 +544,7 @@ public class MaterialRequirementService {
...
@@ -546,7 +544,7 @@ public class MaterialRequirementService {
// 调用BuildOperationBOM方法(返回结果对象替代out参数)
// 调用BuildOperationBOM方法(返回结果对象替代out参数)
BOMBuildResult
operationResult
=
buildOperationSFBOM
(
operation
.
getOrderId
(),
""
,
BOMBuildResult
operationResult
=
buildOperationSFBOM
(
operation
.
getOrderId
(),
""
,
operation
.
getQuantity
(),
operation
,
1
,
demand
,
sceneId
,
chromosome
);
operation
.
getQuantity
(),
operation
,
1
,
demand
,
sceneId
,
chromosome
,
_baseTime
,
_globalParam
);
// // 合并物料需求和子订单
// // 合并物料需求和子订单
if
(
operationResult
!=
null
)
{
if
(
operationResult
!=
null
)
{
allRequirements
.
addAll
(
operationResult
.
getMaterialRequirements
());
allRequirements
.
addAll
(
operationResult
.
getMaterialRequirements
());
...
@@ -567,13 +565,13 @@ public class MaterialRequirementService {
...
@@ -567,13 +565,13 @@ public class MaterialRequirementService {
return
allRequirements
;
return
allRequirements
;
}
}
private
void
clearFinishOrder
(
Order
order
)
private
void
clearFinishOrder
(
Order
order
)
{
{
if
(
order
.
getFinishOrderId
()
==
null
)
{
if
(
order
.
getFinishOrderId
()
==
null
)
{
order
.
setFinishOrderId
(
new
ArrayList
<>());
order
.
setFinishOrderId
(
new
ArrayList
<>());
order
.
setTargetFinishedOperationId
(
new
ArrayList
<>());
order
.
setTargetFinishedOperationId
(
new
ArrayList
<>());
}
}
}
}
/**
/**
* 构建订单BOM
* 构建订单BOM
...
@@ -586,7 +584,7 @@ private void clearFinishOrder (Order order)
...
@@ -586,7 +584,7 @@ private void clearFinishOrder (Order order)
* @return 包含物料需求列表和子订单列表的结果对象
* @return 包含物料需求列表和子订单列表的结果对象
*/
*/
public
BOMBuildResult
buildOrderBOM
(
String
sceneId
,
int
parent
,
String
materialID
,
String
mainorderId
,
public
BOMBuildResult
buildOrderBOM
(
String
sceneId
,
int
parent
,
String
materialID
,
String
mainorderId
,
String
childorderId
,
double
parentQuantity
,
int
level
,
Order
forder
,
int
finishOpertionID
,
Chromosome
chromosome
)
{
String
childorderId
,
double
parentQuantity
,
int
level
,
Order
forder
,
int
finishOpertionID
,
Chromosome
chromosome
,
LocalDateTime
baseTime
,
GlobalParam
globalParam
)
{
forder
.
setCreateBom
(
true
);
forder
.
setCreateBom
(
true
);
List
<
RoutingHeader
>
headers
=
GetRoutingHeader
(
sceneId
);
List
<
RoutingHeader
>
headers
=
GetRoutingHeader
(
sceneId
);
...
@@ -627,7 +625,7 @@ private void clearFinishOrder (Order order)
...
@@ -627,7 +625,7 @@ private void clearFinishOrder (Order order)
}
}
// 调用BuildOperationBOM方法(返回结果对象替代out参数)
// 调用BuildOperationBOM方法(返回结果对象替代out参数)
BOMBuildResult
operationResult
=
buildOperationBOM
(
mainorderId
,
childorderId
,
BOMBuildResult
operationResult
=
buildOperationBOM
(
mainorderId
,
childorderId
,
parentQuantity
,
operation
,
level
,
forder
,
sceneId
,
chromosome
);
parentQuantity
,
operation
,
level
,
forder
,
sceneId
,
chromosome
,
baseTime
,
globalParam
);
// // 合并物料需求和子订单
// // 合并物料需求和子订单
if
(
operationResult
!=
null
)
{
if
(
operationResult
!=
null
)
{
materialRequirements
.
addAll
(
operationResult
.
getMaterialRequirements
());
materialRequirements
.
addAll
(
operationResult
.
getMaterialRequirements
());
...
@@ -650,7 +648,7 @@ private void clearFinishOrder (Order order)
...
@@ -650,7 +648,7 @@ private void clearFinishOrder (Order order)
* @return 包含物料需求列表和子订单列表的结果对象(替代C#的out参数)
* @return 包含物料需求列表和子订单列表的结果对象(替代C#的out参数)
*/
*/
public
BOMBuildResult
buildOperationBOM
(
String
orderId
,
String
childorderId
,
double
parentQuantity
,
public
BOMBuildResult
buildOperationBOM
(
String
orderId
,
String
childorderId
,
double
parentQuantity
,
Entry
operation
,
int
level
,
Order
forder
,
String
sceneId
,
Chromosome
chromosome
)
{
Entry
operation
,
int
level
,
Order
forder
,
String
sceneId
,
Chromosome
chromosome
,
LocalDateTime
baseTime
,
GlobalParam
globalParam
)
{
List
<
OrderMaterialRequirement
>
materialRequirements
=
new
ArrayList
<>();
List
<
OrderMaterialRequirement
>
materialRequirements
=
new
ArrayList
<>();
List
<
Order
>
_childorders
=
new
ArrayList
<>();
List
<
Order
>
_childorders
=
new
ArrayList
<>();
List
<
Entry
>
_newEntrys
=
new
ArrayList
<>();
List
<
Entry
>
_newEntrys
=
new
ArrayList
<>();
...
@@ -678,7 +676,7 @@ private void clearFinishOrder (Order order)
...
@@ -678,7 +676,7 @@ private void clearFinishOrder (Order order)
return
null
;
return
null
;
}
}
OrderMaterialRequirement
orderMaterial
=
CreateMaterialRequirement
(
material
,
orderId
,
childorderId
,
operation
,
allneeded
,
component
.
getSpentQty
().
doubleValue
(),
component
.
getMainQty
().
doubleValue
()
,
parentQuantity
);
OrderMaterialRequirement
orderMaterial
=
CreateMaterialRequirement
(
material
,
orderId
,
childorderId
,
operation
,
allneeded
,
component
.
getSpentQty
().
doubleValue
(),
component
.
getMainQty
().
doubleValue
()
,
parentQuantity
,
baseTime
);
orderMaterial
.
setLevel
(
level
);
orderMaterial
.
setLevel
(
level
);
orderMaterial
.
setBomId
(
component
.
getStrId
());
orderMaterial
.
setBomId
(
component
.
getStrId
());
materialRequirements
.
add
(
orderMaterial
);
materialRequirements
.
add
(
orderMaterial
);
...
@@ -713,7 +711,7 @@ private void clearFinishOrder (Order order)
...
@@ -713,7 +711,7 @@ private void clearFinishOrder (Order order)
BOMBuildResult
childResult
=
buildOrderBOM
(
sceneId
,
0
,
orderMaterial
.
getMaterialId
(),
BOMBuildResult
childResult
=
buildOrderBOM
(
sceneId
,
0
,
orderMaterial
.
getMaterialId
(),
orderId
,
order
.
getOrderId
(),
orderId
,
order
.
getOrderId
(),
order
.
getQuantity
(),
l
,
order
,
operation
.
getId
(),
chromosome
);
order
.
getQuantity
(),
l
,
order
,
operation
.
getId
(),
chromosome
,
baseTime
,
globalParam
);
// materialRequirements.addAll(childResult.getMaterialRequirements());
// materialRequirements.addAll(childResult.getMaterialRequirements());
_childorders
.
addAll
(
childResult
.
getChildOrders
());
_childorders
.
addAll
(
childResult
.
getChildOrders
());
_newEntrys
.
addAll
(
childResult
.
getNewEntrys
());
_newEntrys
.
addAll
(
childResult
.
getNewEntrys
());
...
@@ -743,7 +741,7 @@ private void clearFinishOrder (Order order)
...
@@ -743,7 +741,7 @@ private void clearFinishOrder (Order order)
childorder
.
setQuantity
((
int
)
orderMaterial
.
getQjQty
());
childorder
.
setQuantity
((
int
)
orderMaterial
.
getQjQty
());
childorder
.
setFinishOrderId
(
new
ArrayList
<>());
childorder
.
setFinishOrderId
(
new
ArrayList
<>());
childorder
.
getFinishOrderId
().
add
(
forder
.
getId
());
childorder
.
getFinishOrderId
().
add
(
forder
.
getId
());
childorder
.
setNewCreate
(
true
);
childorder
.
setNew
Sf
Create
(
true
);
childorder
.
setTargetFinishedOperationId
(
new
ArrayList
<>());
childorder
.
setTargetFinishedOperationId
(
new
ArrayList
<>());
childorder
.
getTargetFinishedOperationId
().
add
(
operation
.
getId
());
childorder
.
getTargetFinishedOperationId
().
add
(
operation
.
getId
());
childorder
.
setSerie
(
forder
.
getSerie
());
childorder
.
setSerie
(
forder
.
getSerie
());
...
@@ -769,7 +767,7 @@ private void clearFinishOrder (Order order)
...
@@ -769,7 +767,7 @@ private void clearFinishOrder (Order order)
int
l
=
level
+
1
;
int
l
=
level
+
1
;
BOMBuildResult
childResult
=
buildOrderBOM
(
sceneId
,
0
,
orderMaterial
.
getMaterialId
(),
BOMBuildResult
childResult
=
buildOrderBOM
(
sceneId
,
0
,
orderMaterial
.
getMaterialId
(),
orderId
,
childorder
.
getOrderId
(),
orderId
,
childorder
.
getOrderId
(),
childorder
.
getQuantity
(),
l
,
childorder
,
0
,
chromosome
);
childorder
.
getQuantity
(),
l
,
childorder
,
0
,
chromosome
,
baseTime
,
globalParam
);
// materialRequirements.addAll(childResult.getMaterialRequirements());
// materialRequirements.addAll(childResult.getMaterialRequirements());
_childorders
.
addAll
(
childResult
.
getChildOrders
());
_childorders
.
addAll
(
childResult
.
getChildOrders
());
_newEntrys
.
addAll
(
childResult
.
getNewEntrys
());
_newEntrys
.
addAll
(
childResult
.
getNewEntrys
());
...
@@ -792,10 +790,10 @@ private void clearFinishOrder (Order order)
...
@@ -792,10 +790,10 @@ private void clearFinishOrder (Order order)
RoutingHeader
headers1
=
headers
.
stream
()
RoutingHeader
headers1
=
headers
.
stream
()
.
filter
(
t
->
t
.
getMaterialId
().
equals
(
materialID
))
.
filter
(
t
->
t
.
getMaterialId
().
equals
(
materialID
))
.
findFirst
().
orElse
(
null
);
.
findFirst
().
orElse
(
null
);
if
(
headers1
==
null
)
if
(
headers1
==
null
)
{
{
return
null
;
return
null
;
}
}
routingIds
=
headers1
.
getId
().
longValue
();
routingIds
=
headers1
.
getId
().
longValue
();
...
@@ -921,7 +919,7 @@ if(headers1==null)
...
@@ -921,7 +919,7 @@ if(headers1==null)
* @return 包含物料需求列表和子订单列表的结果对象(替代C#的out参数)
* @return 包含物料需求列表和子订单列表的结果对象(替代C#的out参数)
*/
*/
public
BOMBuildResult
buildOperationSFBOM
(
String
orderId
,
String
childorderId
,
double
parentQuantity
,
public
BOMBuildResult
buildOperationSFBOM
(
String
orderId
,
String
childorderId
,
double
parentQuantity
,
Entry
operation
,
int
level
,
Order
forder
,
String
sceneId
,
Chromosome
chromosome
)
{
Entry
operation
,
int
level
,
Order
forder
,
String
sceneId
,
Chromosome
chromosome
,
LocalDateTime
baseTime
,
GlobalParam
globalParam
)
{
List
<
OrderMaterialRequirement
>
materialRequirements
=
new
ArrayList
<>();
List
<
OrderMaterialRequirement
>
materialRequirements
=
new
ArrayList
<>();
List
<
Order
>
_childorders
=
new
ArrayList
<>();
List
<
Order
>
_childorders
=
new
ArrayList
<>();
List
<
Entry
>
_newEntrys
=
new
ArrayList
<>();
List
<
Entry
>
_newEntrys
=
new
ArrayList
<>();
...
@@ -980,7 +978,7 @@ if(headers1==null)
...
@@ -980,7 +978,7 @@ if(headers1==null)
BOMBuildResult
childResult
=
buildOrderBOM
(
sceneId
,
0
,
orderMaterial
.
getMaterialId
(),
BOMBuildResult
childResult
=
buildOrderBOM
(
sceneId
,
0
,
orderMaterial
.
getMaterialId
(),
orderId
,
order
.
getOrderId
(),
orderId
,
order
.
getOrderId
(),
order
.
getQuantity
(),
l
,
order
,
operation
.
getId
(),
chromosome
);
order
.
getQuantity
(),
l
,
order
,
operation
.
getId
(),
chromosome
,
baseTime
,
globalParam
);
materialRequirements
.
addAll
(
childResult
.
getMaterialRequirements
());
materialRequirements
.
addAll
(
childResult
.
getMaterialRequirements
());
_childorders
.
addAll
(
childResult
.
getChildOrders
());
_childorders
.
addAll
(
childResult
.
getChildOrders
());
_newEntrys
.
addAll
(
childResult
.
getNewEntrys
());
_newEntrys
.
addAll
(
childResult
.
getNewEntrys
());
...
@@ -1010,7 +1008,7 @@ if(headers1==null)
...
@@ -1010,7 +1008,7 @@ if(headers1==null)
childorder
.
setQuantity
((
int
)
orderMaterial
.
getQjQty
());
childorder
.
setQuantity
((
int
)
orderMaterial
.
getQjQty
());
childorder
.
setFinishOrderId
(
new
ArrayList
<>());
childorder
.
setFinishOrderId
(
new
ArrayList
<>());
childorder
.
getFinishOrderId
().
add
(
forder
.
getId
());
childorder
.
getFinishOrderId
().
add
(
forder
.
getId
());
childorder
.
setNew
Create
(
true
);
childorder
.
setNewSf
Create
(
true
);
childorder
.
setTargetFinishedOperationId
(
new
ArrayList
<>());
childorder
.
setTargetFinishedOperationId
(
new
ArrayList
<>());
childorder
.
getTargetFinishedOperationId
().
add
(
operation
.
getId
());
childorder
.
getTargetFinishedOperationId
().
add
(
operation
.
getId
());
childorder
.
setSerie
(
forder
.
getSerie
());
childorder
.
setSerie
(
forder
.
getSerie
());
...
@@ -1036,7 +1034,7 @@ if(headers1==null)
...
@@ -1036,7 +1034,7 @@ if(headers1==null)
int
l
=
level
+
1
;
int
l
=
level
+
1
;
BOMBuildResult
childResult
=
buildOrderBOM
(
sceneId
,
0
,
orderMaterial
.
getMaterialId
(),
BOMBuildResult
childResult
=
buildOrderBOM
(
sceneId
,
0
,
orderMaterial
.
getMaterialId
(),
orderId
,
childorder
.
getOrderId
(),
orderId
,
childorder
.
getOrderId
(),
childorder
.
getQuantity
(),
l
,
childorder
,
0
,
chromosome
);
childorder
.
getQuantity
(),
l
,
childorder
,
0
,
chromosome
,
baseTime
,
globalParam
);
materialRequirements
.
addAll
(
childResult
.
getMaterialRequirements
());
materialRequirements
.
addAll
(
childResult
.
getMaterialRequirements
());
_childorders
.
addAll
(
childResult
.
getChildOrders
());
_childorders
.
addAll
(
childResult
.
getChildOrders
());
_newEntrys
.
addAll
(
childResult
.
getNewEntrys
());
_newEntrys
.
addAll
(
childResult
.
getNewEntrys
());
...
@@ -1089,7 +1087,7 @@ if(headers1==null)
...
@@ -1089,7 +1087,7 @@ if(headers1==null)
}
}
private
OrderMaterialRequirement
CreateMaterialRequirement
(
Material
material
,
String
orderId
,
String
childorderId
,
Entry
operation
,
double
need
,
double
spentQty
,
double
mainQty
,
double
qty
)
{
private
OrderMaterialRequirement
CreateMaterialRequirement
(
Material
material
,
String
orderId
,
String
childorderId
,
Entry
operation
,
double
need
,
double
spentQty
,
double
mainQty
,
double
qty
,
LocalDateTime
baseTime
)
{
OrderMaterialRequirement
orderMaterial
=
new
OrderMaterialRequirement
();
OrderMaterialRequirement
orderMaterial
=
new
OrderMaterialRequirement
();
orderMaterial
.
setOrderId
(
orderId
);
orderMaterial
.
setOrderId
(
orderId
);
...
@@ -1140,7 +1138,7 @@ if(headers1==null)
...
@@ -1140,7 +1138,7 @@ if(headers1==null)
* @return 包含物料需求列表和子订单列表的结果对象(替代C#的out参数)
* @return 包含物料需求列表和子订单列表的结果对象(替代C#的out参数)
*/
*/
public
void
EditOperationBOM
(
Entry
operation
,
Chromosome
chromosome
,
LocalDateTime
earliestStartTime
,
GeneticDecoder
coder
,
Map
<
Long
,
CopyOnWriteArrayList
<
GAScheduleResult
>>
machineTasksCache
,
Map
<
Integer
,
Entry
>
entryIndexById
,
Map
<
Integer
,
GAScheduleResult
>
scheduleIndexById
)
{
public
void
EditOperationBOM
(
Entry
operation
,
Chromosome
chromosome
,
LocalDateTime
earliestStartTime
,
GeneticDecoder
coder
,
Map
<
Long
,
CopyOnWriteArrayList
<
GAScheduleResult
>>
machineTasksCache
,
Map
<
Integer
,
Entry
>
entryIndexById
,
Map
<
Integer
,
GAScheduleResult
>
scheduleIndexById
,
LocalDateTime
baseTime
)
{
List
<
OrderMaterialRequirement
>
materialRequirements
=
new
ArrayList
<>();
List
<
OrderMaterialRequirement
>
materialRequirements
=
new
ArrayList
<>();
String
sceneId
=
chromosome
.
getScenarioID
();
String
sceneId
=
chromosome
.
getScenarioID
();
...
@@ -1247,7 +1245,7 @@ if(headers1==null)
...
@@ -1247,7 +1245,7 @@ if(headers1==null)
continue
;
continue
;
}
}
MaterialInTransit
(
material
,
""
,
orderMaterial
,
needed
,
earliestStartTime
);
MaterialInTransit
(
material
,
""
,
orderMaterial
,
needed
,
earliestStartTime
,
materials
);
needed
-=
orderMaterial
.
getUseTransit
();
needed
-=
orderMaterial
.
getUseTransit
();
...
@@ -1268,7 +1266,7 @@ if(headers1==null)
...
@@ -1268,7 +1266,7 @@ if(headers1==null)
break
;
break
;
}
}
MaterialInTransit
(
material1
,
rsr
.
getMaterialid
(),
orderMaterial1
,
needed
,
earliestStartTime
);
MaterialInTransit
(
material1
,
rsr
.
getMaterialid
(),
orderMaterial1
,
needed
,
earliestStartTime
,
materials
);
needed
-=
orderMaterial1
.
getUseTransit
();
needed
-=
orderMaterial1
.
getUseTransit
();
...
@@ -1376,14 +1374,14 @@ if(headers1==null)
...
@@ -1376,14 +1374,14 @@ if(headers1==null)
private
void
MaterialInTransit
(
Material
material
,
String
materialId
,
OrderMaterialRequirement
orderMaterial
,
double
needed
,
LocalDateTime
earliestStartTime
){
private
void
MaterialInTransit
(
Material
material
,
String
materialId
,
OrderMaterialRequirement
orderMaterial
,
double
needed
,
LocalDateTime
earliestStartTime
,
List
<
Material
>
materials
){
// 处理在途物料
// 处理在途物料
double
accumulated
=
0
;
double
accumulated
=
0
;
LocalDateTime
earliestTime
=
LocalDateTime
.
of
(
2000
,
1
,
1
,
0
,
0
,
0
);
LocalDateTime
earliestTime
=
LocalDateTime
.
of
(
2000
,
1
,
1
,
0
,
0
,
0
);
double
useTransit
=
0
;
double
useTransit
=
0
;
if
(
material
==
null
)
{
if
(
material
==
null
)
{
material
=
_
materials
.
stream
()
material
=
materials
.
stream
()
.
filter
(
m
->
m
.
getId
().
equals
(
materialId
))
.
filter
(
m
->
m
.
getId
().
equals
(
materialId
))
.
findFirst
()
.
findFirst
()
.
orElse
(
null
);
.
orElse
(
null
);
...
...
src/main/java/com/aps/service/Algorithm/MaterialRequirementServicebf.java
View file @
f1998b61
...
@@ -894,7 +894,7 @@ public class MaterialRequirementServicebf {
...
@@ -894,7 +894,7 @@ public class MaterialRequirementServicebf {
childorder
.
setQuantity
((
int
)
orderMaterial
.
getQjQty
());
childorder
.
setQuantity
((
int
)
orderMaterial
.
getQjQty
());
childorder
.
setFinishOrderId
(
new
ArrayList
<>());
childorder
.
setFinishOrderId
(
new
ArrayList
<>());
childorder
.
getFinishOrderId
().
add
(
forder
.
getId
());
childorder
.
getFinishOrderId
().
add
(
forder
.
getId
());
childorder
.
setNewCreate
(
true
);
childorder
.
setNew
Sf
Create
(
true
);
childorder
.
setTargetFinishedOperationId
(
new
ArrayList
<>());
childorder
.
setTargetFinishedOperationId
(
new
ArrayList
<>());
childorder
.
getTargetFinishedOperationId
().
add
(
operation
.
getId
());
childorder
.
getTargetFinishedOperationId
().
add
(
operation
.
getId
());
childorder
.
setSerie
(
forder
.
getSerie
());
childorder
.
setSerie
(
forder
.
getSerie
());
...
...
src/main/java/com/aps/service/Algorithm/VariableNeighborhoodSearch.java
View file @
f1998b61
...
@@ -19,12 +19,60 @@ import java.util.stream.Collectors;
...
@@ -19,12 +19,60 @@ import java.util.stream.Collectors;
public
class
VariableNeighborhoodSearch
{
public
class
VariableNeighborhoodSearch
{
private
final
Random
rnd
=
new
Random
();
private
final
Random
rnd
=
new
Random
();
// ==================== 常量定义 ====================
private
static
final
int
MAX_CONSECUTIVE_SAME_STRATEGY
=
3
;
private
static
final
int
MAX_NEIGHBORHOODS
=
7
;
private
static
final
double
HIGH_PRIORITY_GROUP_PROBABILITY
=
0.7
;
private
static
final
int
MAX_ATTEMPTS
=
50
;
private
static
final
int
NEIGHBOR_SELECTION_TOP_K
=
3
;
private
static
final
int
MOVE_STEPS_MIN
=
1
;
private
static
final
int
MOVE_STEPS_MAX
=
5
;
private
static
final
int
NON_BOTTLENECK_MOVE_STEPS_MAX
=
3
;
private
static
final
int
RANDOM_NEIGHBOR_TYPE_COUNT
=
5
;
private
static
final
double
INITIAL_SUCCESS_RATE
=
0.3
;
private
static
final
double
LOW_SUCCESS_RATE_THRESHOLD
=
0.1
;
private
static
final
int
LOW_SUCCESS_RATE_MIN_TRIALS
=
10
;
private
static
final
double
EXPLORATION_BONUS_FOR_LOW_USE
=
0.3
;
private
static
final
double
EXPLORATION_BONUS_FOR_LOW_SUCCESS
=
0.2
;
private
static
final
double
RANDOM_NOISE_FACTOR
=
0.15
;
private
static
final
double
FORCE_ROTATE_PENALTY
=
0.5
;
private
static
final
double
PERCENTILE_90
=
0.90
;
private
static
final
double
BOTTLENECK_MACHINE_BASE_SCORE
=
10000
;
private
static
final
double
WAIT_TIME_WEIGHT
=
30
;
private
static
final
double
MACHINE_WAIT_TIME_WEIGHT
=
30
;
private
static
final
double
CRITICAL_PATH_WEIGHT_ON_BOTTLENECK
=
25
;
private
static
final
double
CRITICAL_PATH_WEIGHT_OFF_BOTTLENECK
=
20
;
private
static
final
double
DELAY_CONTRIBUTION_WEIGHT_ON_BOTTLENECK
=
15
;
private
static
final
double
DELAY_CONTRIBUTION_WEIGHT_OFF_BOTTLENECK
=
10
;
private
static
final
double
NORMALIZATION_CAP
=
1.5
;
private
static
final
int
TOP_BOTTLENECK_OPS_TO_RETURN
=
10
;
private
static
final
int
TOP_MACHINES_TO_LOG
=
5
;
private
static
final
double
PRIORITY_EPSILON
=
0.001
;
private
static
final
int
MIN_USE_COUNT_FOR_EXPLORATION_BONUS
=
5
;
// 日志级别
private
static
final
int
LOG_LEVEL_DEBUG
=
0
;
private
static
final
int
LOG_LEVEL_INFO
=
1
;
private
static
final
int
LOG_LEVEL_WARN
=
2
;
private
int
currentLogLevel
=
LOG_LEVEL_INFO
;
// 局部搜索优化
private
static
final
int
MAX_LOCAL_SEARCH_NEIGHBORS
=
5
;
private
void
log
(
String
message
)
{
private
void
log
(
String
message
)
{
log
(
message
,
tru
e
);
log
(
message
,
LOG_LEVEL_INFO
,
fals
e
);
}
}
private
void
log
(
String
message
,
boolean
enableLogging
)
{
private
void
log
(
String
message
,
boolean
enableLogging
)
{
if
(
enableLogging
)
{
log
(
message
,
LOG_LEVEL_INFO
,
enableLogging
);
}
private
void
log
(
String
message
,
int
level
)
{
log
(
message
,
level
,
false
);
}
private
void
log
(
String
message
,
int
level
,
boolean
enableLogging
)
{
if
(
enableLogging
&&
level
>=
currentLogLevel
)
{
FileHelper
.
writeLogFile
(
message
);
FileHelper
.
writeLogFile
(
message
);
}
}
}
}
...
@@ -51,7 +99,6 @@ public class VariableNeighborhoodSearch {
...
@@ -51,7 +99,6 @@ public class VariableNeighborhoodSearch {
// 强制策略轮换:跟踪最后使用的策略
// 强制策略轮换:跟踪最后使用的策略
private
int
lastUsedStrategy
=
-
1
;
private
int
lastUsedStrategy
=
-
1
;
private
int
consecutiveSameStrategyCount
=
0
;
private
int
consecutiveSameStrategyCount
=
0
;
private
static
final
int
MAX_CONSECUTIVE_SAME_STRATEGY
=
3
;
// 最多连续使用同一个策略3次
// 缓存的深拷贝列表,用于解码优化
// 缓存的深拷贝列表,用于解码优化
private
List
<
Machine
>
cachedMachines
;
private
List
<
Machine
>
cachedMachines
;
...
@@ -60,6 +107,8 @@ public class VariableNeighborhoodSearch {
...
@@ -60,6 +107,8 @@ public class VariableNeighborhoodSearch {
private
List
<
Material
>
cachedMaterials
;
private
List
<
Material
>
cachedMaterials
;
private
List
<
Entry
>
cachedAllOperations
;
private
List
<
Entry
>
cachedAllOperations
;
private
GeneticOperations
geneticOperations
;
// 邻域结构成功率统计(用于 search() 方法)
// 邻域结构成功率统计(用于 search() 方法)
private
static
class
NeighborhoodWithStats
{
private
static
class
NeighborhoodWithStats
{
NeighborhoodStructure
structure
;
NeighborhoodStructure
structure
;
...
@@ -87,7 +136,7 @@ public class VariableNeighborhoodSearch {
...
@@ -87,7 +136,7 @@ public class VariableNeighborhoodSearch {
public
VariableNeighborhoodSearch
(
List
<
Entry
>
allOperations
,
List
<
Order
>
orders
,
public
VariableNeighborhoodSearch
(
List
<
Entry
>
allOperations
,
List
<
Order
>
orders
,
List
<
Material
>
materials
,
List
<
GroupResult
>
entryRel
,
FitnessCalculator
fitnessCalculator
)
{
List
<
Material
>
materials
,
List
<
GroupResult
>
entryRel
,
FitnessCalculator
fitnessCalculator
)
{
this
(
allOperations
,
orders
,
materials
,
entryRel
,
fitnessCalculator
,
3
);
this
(
allOperations
,
orders
,
materials
,
entryRel
,
fitnessCalculator
,
1
);
}
}
public
VariableNeighborhoodSearch
(
List
<
Entry
>
allOperations
,
List
<
Order
>
orders
,
public
VariableNeighborhoodSearch
(
List
<
Entry
>
allOperations
,
List
<
Order
>
orders
,
...
@@ -126,7 +175,7 @@ public class VariableNeighborhoodSearch {
...
@@ -126,7 +175,7 @@ public class VariableNeighborhoodSearch {
for
(
NeighborhoodStructure
ns
:
initialNeighborhoods
)
{
for
(
NeighborhoodStructure
ns
:
initialNeighborhoods
)
{
neighborhoodsWithStats
.
add
(
new
NeighborhoodWithStats
(
ns
));
neighborhoodsWithStats
.
add
(
new
NeighborhoodWithStats
(
ns
));
}
}
geneticOperations
=
new
GeneticOperations
();
//log("VariableNeighborhoodSearch初始化: hasMultipleMachineOptions=" + hasMultipleMachineOptions);
//log("VariableNeighborhoodSearch初始化: hasMultipleMachineOptions=" + hasMultipleMachineOptions);
}
}
...
@@ -147,6 +196,12 @@ public class VariableNeighborhoodSearch {
...
@@ -147,6 +196,12 @@ public class VariableNeighborhoodSearch {
//非瓶颈工序往后移动
//非瓶颈工序往后移动
neighborhoods
.
add
(
new
NeighborhoodStructure
(
"MoveNonBottleneckBackward"
,
this
::
moveNonBottleneckBackwardWrapper
));
neighborhoods
.
add
(
new
NeighborhoodStructure
(
"MoveNonBottleneckBackward"
,
this
::
moveNonBottleneckBackwardWrapper
));
//瓶颈设备工序激进重排
neighborhoods
.
add
(
new
NeighborhoodStructure
(
"AggressiveBottleneckReorder"
,
this
::
aggressiveBottleneckReorderWrapper
));
//关键路径工序优化
neighborhoods
.
add
(
new
NeighborhoodStructure
(
"CriticalPathOptimize"
,
this
::
criticalPathOptimizeWrapper
));
//// 交换相同设备的两个工序
//// 交换相同设备的两个工序
neighborhoods
.
add
(
new
NeighborhoodStructure
(
"SwapSameMachine"
,
this
::
generateSameMachineSwapNeighbor
));
neighborhoods
.
add
(
new
NeighborhoodStructure
(
"SwapSameMachine"
,
this
::
generateSameMachineSwapNeighbor
));
...
@@ -176,7 +231,7 @@ public class VariableNeighborhoodSearch {
...
@@ -176,7 +231,7 @@ public class VariableNeighborhoodSearch {
// result.add(ns.structure);
// result.add(ns.structure);
// }
// }
int
maxNeighborhoods
=
Math
.
min
(
7
,
sorted
.
size
());
int
maxNeighborhoods
=
Math
.
min
(
MAX_NEIGHBORHOODS
,
sorted
.
size
());
for
(
int
i
=
0
;
i
<
maxNeighborhoods
;
i
++)
{
for
(
int
i
=
0
;
i
<
maxNeighborhoods
;
i
++)
{
result
.
add
(
sorted
.
get
(
i
).
structure
);
result
.
add
(
sorted
.
get
(
i
).
structure
);
}
}
...
@@ -218,7 +273,7 @@ public class VariableNeighborhoodSearch {
...
@@ -218,7 +273,7 @@ public class VariableNeighborhoodSearch {
*/
*/
public
Chromosome
search
(
Chromosome
chromosome
,
GeneticDecoder
decoder
,
List
<
Machine
>
machines
)
{
public
Chromosome
search
(
Chromosome
chromosome
,
GeneticDecoder
decoder
,
List
<
Machine
>
machines
)
{
log
(
"变邻域搜索 - 开始执行"
,
true
);
log
(
"变邻域搜索 - 开始执行"
,
true
);
geneticOperations
.
DelOrder
(
chromosome
);
// 深拷贝当前染色体
// 深拷贝当前染色体
Chromosome
current
=
ProductionDeepCopyUtil
.
deepCopy
(
chromosome
,
Chromosome
.
class
);
Chromosome
current
=
ProductionDeepCopyUtil
.
deepCopy
(
chromosome
,
Chromosome
.
class
);
Chromosome
best
=
ProductionDeepCopyUtil
.
deepCopy
(
chromosome
,
Chromosome
.
class
);
Chromosome
best
=
ProductionDeepCopyUtil
.
deepCopy
(
chromosome
,
Chromosome
.
class
);
...
@@ -276,7 +331,7 @@ public class VariableNeighborhoodSearch {
...
@@ -276,7 +331,7 @@ public class VariableNeighborhoodSearch {
// 邻域移动
// 邻域移动
boolean
success
=
isBetter
(
localBest
,
best
);
boolean
success
=
isBetter
(
localBest
,
best
);
if
(
success
)
{
if
(
success
)
{
best
=
ProductionDeepCopyUtil
.
deepCopy
(
localBest
,
Chromosome
.
class
)
;
best
=
localBest
;
writeKpi
(
best
);
writeKpi
(
best
);
current
=
localBest
;
current
=
localBest
;
k
=
0
;
// 重置邻域索引
k
=
0
;
// 重置邻域索引
...
@@ -554,7 +609,7 @@ public class VariableNeighborhoodSearch {
...
@@ -554,7 +609,7 @@ public class VariableNeighborhoodSearch {
}
}
// 订单数相同时,按优先级排序
// 订单数相同时,按优先级排序
return
Double
.
compare
(
entry
2
.
getPriority
(),
entry1
.
getPriority
());
return
Double
.
compare
(
entry
1
.
getPriority
(),
entry2
.
getPriority
());
});
});
}
}
...
@@ -1072,7 +1127,7 @@ public class VariableNeighborhoodSearch {
...
@@ -1072,7 +1127,7 @@ public class VariableNeighborhoodSearch {
}
}
// 订单数相同时,按优先级排序
// 订单数相同时,按优先级排序
return
Double
.
compare
(
entry
B
.
getPriority
(),
entryA
.
getPriority
());
return
Double
.
compare
(
entry
A
.
getPriority
(),
entryB
.
getPriority
());
});
});
// 70%概率选择前3个候选,30%概率随机选择
// 70%概率选择前3个候选,30%概率随机选择
...
@@ -1131,7 +1186,8 @@ public class VariableNeighborhoodSearch {
...
@@ -1131,7 +1186,8 @@ public class VariableNeighborhoodSearch {
}
}
/**
/**
* 给指定位置的工序换设备
* 给指定位置的工序换设备 - 考虑设备负载均衡优化
* 优先选择负载低的设备
*/
*/
private
Chromosome
generateMachineChangeForSpecificOp
(
Chromosome
chromosome
,
List
<
MachineOption
>
machineOptions
,
int
idx
)
{
private
Chromosome
generateMachineChangeForSpecificOp
(
Chromosome
chromosome
,
List
<
MachineOption
>
machineOptions
,
int
idx
)
{
Chromosome
neighbor
=
copyChromosome
(
chromosome
);
// ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
Chromosome
neighbor
=
copyChromosome
(
chromosome
);
// ProductionDeepCopyUtil.deepCopy(chromosome, Chromosome.class);
...
@@ -1147,7 +1203,8 @@ public class VariableNeighborhoodSearch {
...
@@ -1147,7 +1203,8 @@ public class VariableNeighborhoodSearch {
}
}
if
(!
availableMachines
.
isEmpty
())
{
if
(!
availableMachines
.
isEmpty
())
{
int
newMachineSeq
=
availableMachines
.
get
(
rnd
.
nextInt
(
availableMachines
.
size
()));
// 选择负载较低的设备(设备负载均衡优化)
int
newMachineSeq
=
selectMachineByLoad
(
availableMachines
,
machineOptions
,
chromosome
);
ms
.
set
(
idx
,
newMachineSeq
);
ms
.
set
(
idx
,
newMachineSeq
);
neighbor
.
setMachineSelection
(
ms
);
neighbor
.
setMachineSelection
(
ms
);
}
}
...
@@ -1247,7 +1304,7 @@ public class VariableNeighborhoodSearch {
...
@@ -1247,7 +1304,7 @@ public class VariableNeighborhoodSearch {
}
}
// 订单数相同时,按优先级排序
// 订单数相同时,按优先级排序
int
priorityCompare
=
Double
.
compare
(
entry
B
.
getPriority
(),
entryA
.
getPriority
());
int
priorityCompare
=
Double
.
compare
(
entry
A
.
getPriority
(),
entryB
.
getPriority
());
if
(
priorityCompare
!=
0
)
{
if
(
priorityCompare
!=
0
)
{
return
priorityCompare
;
return
priorityCompare
;
}
}
...
@@ -1381,6 +1438,7 @@ public class VariableNeighborhoodSearch {
...
@@ -1381,6 +1438,7 @@ public class VariableNeighborhoodSearch {
* 将工序往前移动
* 将工序往前移动
*/
*/
private
Chromosome
moveOperationForward
(
Chromosome
chromosome
,
Map
<
Integer
,
Entry
>
originalPositionIndex
,
int
pos
,
int
steps
)
{
private
Chromosome
moveOperationForward
(
Chromosome
chromosome
,
Map
<
Integer
,
Entry
>
originalPositionIndex
,
int
pos
,
int
steps
)
{
geneticOperations
.
DelOrder
(
chromosome
);
Chromosome
neighbor
=
ProductionDeepCopyUtil
.
deepCopy
(
chromosome
,
Chromosome
.
class
);
Chromosome
neighbor
=
ProductionDeepCopyUtil
.
deepCopy
(
chromosome
,
Chromosome
.
class
);
List
<
Integer
>
os
=
neighbor
.
getOperationSequencing
();
List
<
Integer
>
os
=
neighbor
.
getOperationSequencing
();
...
@@ -1522,14 +1580,15 @@ public class VariableNeighborhoodSearch {
...
@@ -1522,14 +1580,15 @@ public class VariableNeighborhoodSearch {
private
Chromosome
copyChromosome
(
Chromosome
chromosome
)
private
Chromosome
copyChromosome
(
Chromosome
chromosome
)
{
{
geneticOperations
.
DelOrder
(
chromosome
);
Chromosome
neighbor
=
new
Chromosome
();
Chromosome
neighbor
=
new
Chromosome
();
neighbor
.
setID
(
UUID
.
randomUUID
().
toString
());
neighbor
.
setID
(
UUID
.
randomUUID
().
toString
());
neighbor
.
setOperationSequencing
(
chromosome
.
getOperationSequencing
(
));
neighbor
.
setOperationSequencing
(
new
ArrayList
<>(
chromosome
.
getOperationSequencing
()
));
neighbor
.
setMachineSelection
(
chromosome
.
getMachineSelection
(
));
neighbor
.
setMachineSelection
(
new
ArrayList
<>(
chromosome
.
getMachineSelection
()
));
neighbor
.
setScenarioID
(
chromosome
.
getScenarioID
());
neighbor
.
setScenarioID
(
chromosome
.
getScenarioID
());
neighbor
.
setBaseTime
(
chromosome
.
getBaseTime
());
neighbor
.
setBaseTime
(
chromosome
.
getBaseTime
());
neighbor
.
setFitnessLevel
(
chromosome
.
getFitnessLevel
());
neighbor
.
setFitnessLevel
(
chromosome
.
getFitnessLevel
());
neighbor
.
setGlobalOpList
(
chromosome
.
getGlobalOpList
(
));
neighbor
.
setGlobalOpList
(
new
ArrayList
<>(
chromosome
.
getGlobalOpList
()
));
return
neighbor
;
return
neighbor
;
}
}
...
@@ -1722,14 +1781,17 @@ public class VariableNeighborhoodSearch {
...
@@ -1722,14 +1781,17 @@ public class VariableNeighborhoodSearch {
if
(
op
.
getMachineOptions
().
size
()
>
1
)
{
if
(
op
.
getMachineOptions
().
size
()
>
1
)
{
int
currentMachineSeq
=
ms
.
get
(
idx
);
int
currentMachineSeq
=
ms
.
get
(
idx
);
List
<
Integer
>
availableMachines
=
new
ArrayList
<>();
List
<
Integer
>
availableMachines
=
new
ArrayList
<>();
List
<
MachineOption
>
machineOptions
=
new
ArrayList
<>();
for
(
int
i
=
1
;
i
<=
op
.
getMachineOptions
().
size
();
i
++)
{
for
(
int
i
=
1
;
i
<=
op
.
getMachineOptions
().
size
();
i
++)
{
if
(
i
!=
currentMachineSeq
)
{
if
(
i
!=
currentMachineSeq
)
{
availableMachines
.
add
(
i
);
availableMachines
.
add
(
i
);
machineOptions
.
add
(
op
.
getMachineOptions
().
get
(
i
));
}
}
}
}
if
(!
availableMachines
.
isEmpty
())
{
if
(!
availableMachines
.
isEmpty
())
{
int
newMachineSeq
=
availableMachines
.
get
(
rnd
.
nextInt
(
availableMachines
.
size
()));
// 选择负载较低的设备(设备负载均衡优化)
int
newMachineSeq
=
selectMachineByLoad
(
availableMachines
,
machineOptions
,
chromosome
);
ms
.
set
(
idx
,
newMachineSeq
);
ms
.
set
(
idx
,
newMachineSeq
);
neighbor
.
setMachineSelection
(
ms
);
neighbor
.
setMachineSelection
(
ms
);
}
}
...
@@ -1858,10 +1920,11 @@ public class VariableNeighborhoodSearch {
...
@@ -1858,10 +1920,11 @@ public class VariableNeighborhoodSearch {
* 局部搜索
* 局部搜索
*/
*/
private
Chromosome
localSearch
(
Chromosome
chromosome
,
GeneticDecoder
decoder
,
List
<
Machine
>
machines
)
{
private
Chromosome
localSearch
(
Chromosome
chromosome
,
GeneticDecoder
decoder
,
List
<
Machine
>
machines
)
{
geneticOperations
.
DelOrder
(
chromosome
);
Chromosome
current
=
ProductionDeepCopyUtil
.
deepCopy
(
chromosome
,
Chromosome
.
class
);
Chromosome
current
=
ProductionDeepCopyUtil
.
deepCopy
(
chromosome
,
Chromosome
.
class
);
Chromosome
best
=
ProductionDeepCopyUtil
.
deepCopy
(
chromosome
,
Chromosome
.
class
);
Chromosome
best
=
ProductionDeepCopyUtil
.
deepCopy
(
chromosome
,
Chromosome
.
class
);
decode
(
decoder
,
best
,
machines
);
decode
(
decoder
,
best
,
machines
);
//
writeKpi(best);
writeKpi
(
best
);
// 预定义邻域结构,避免每次循环重复创建
// 预定义邻域结构,避免每次循环重复创建
List
<
NeighborhoodStructure
>
neighborhoods
=
defineNeighborhoods
();
List
<
NeighborhoodStructure
>
neighborhoods
=
defineNeighborhoods
();
...
@@ -1869,9 +1932,14 @@ public class VariableNeighborhoodSearch {
...
@@ -1869,9 +1932,14 @@ public class VariableNeighborhoodSearch {
while
(
improved
)
{
while
(
improved
)
{
improved
=
false
;
improved
=
false
;
// 生成
所有可能的邻域解
// 生成
邻域解(限制数量以提高性能)
List
<
Chromosome
>
neighbors
=
new
ArrayList
<>();
List
<
Chromosome
>
neighbors
=
new
ArrayList
<>();
for
(
NeighborhoodStructure
neighborhood
:
neighborhoods
)
{
for
(
NeighborhoodStructure
neighborhood
:
neighborhoods
)
{
if
(
neighbors
.
size
()
>=
MAX_LOCAL_SEARCH_NEIGHBORS
)
{
break
;
}
Chromosome
neighbor
=
generateNeighbor
(
current
,
neighborhood
);
Chromosome
neighbor
=
generateNeighbor
(
current
,
neighborhood
);
if
(
neighbor
!=
null
)
{
if
(
neighbor
!=
null
)
{
neighbors
.
add
(
neighbor
);
neighbors
.
add
(
neighbor
);
...
@@ -1884,7 +1952,7 @@ public class VariableNeighborhoodSearch {
...
@@ -1884,7 +1952,7 @@ public class VariableNeighborhoodSearch {
Batchdecode
(
decoder
,
neighbors
,
machines
);
Batchdecode
(
decoder
,
neighbors
,
machines
);
// 评估所有邻域解
// 评估所有邻域解
,找到第一个改进就停止(贪心策略)
for
(
Chromosome
neighbor
:
neighbors
)
{
for
(
Chromosome
neighbor
:
neighbors
)
{
if
(
neighbor
!=
null
&&
isBetter
(
neighbor
,
best
))
{
if
(
neighbor
!=
null
&&
isBetter
(
neighbor
,
best
))
{
...
@@ -1892,6 +1960,7 @@ public class VariableNeighborhoodSearch {
...
@@ -1892,6 +1960,7 @@ public class VariableNeighborhoodSearch {
writeKpi
(
best
);
writeKpi
(
best
);
current
=
neighbor
;
current
=
neighbor
;
improved
=
true
;
improved
=
true
;
break
;
// 找到一个改进就退出,提高效率
}
}
}
}
}
}
...
@@ -2105,4 +2174,309 @@ public class VariableNeighborhoodSearch {
...
@@ -2105,4 +2174,309 @@ public class VariableNeighborhoodSearch {
return
operator
.
apply
(
chromosome
);
return
operator
.
apply
(
chromosome
);
}
}
}
}
/**
* 机器选项和负载信息的辅助类
*/
private
static
class
MachineOptionWithUtilization
{
int
seq
;
MachineOption
option
;
double
utilization
;
MachineOptionWithUtilization
(
int
seq
,
MachineOption
option
,
double
utilization
)
{
this
.
seq
=
seq
;
this
.
option
=
option
;
this
.
utilization
=
utilization
;
}
}
/**
* 选择负载较低的设备 - 设备负载均衡优化
* 优先选择负载低的设备
*/
private
int
selectMachineByLoad
(
List
<
Integer
>
availableMachineSeqs
,
List
<
MachineOption
>
machineOptions
,
Chromosome
chromosome
)
{
// 计算当前各设备的负载(利用率)
Map
<
Long
,
Double
>
machineUtilization
=
calculateMachineUtilization
(
chromosome
);
// 构建可用机器列表,按负载从低到高排序
List
<
MachineOptionWithUtilization
>
availableMachines
=
new
ArrayList
<>();
for
(
int
seq
:
availableMachineSeqs
)
{
MachineOption
option
=
machineOptions
.
get
(
seq
-
1
);
Long
machineId
=
option
.
getMachineId
();
double
utilization
=
machineUtilization
.
getOrDefault
(
machineId
,
0.0
);
availableMachines
.
add
(
new
MachineOptionWithUtilization
(
seq
,
option
,
utilization
));
}
// 按利用率从低到高排序
availableMachines
.
sort
(
Comparator
.
comparingDouble
(
m
->
m
.
utilization
));
// 70%概率选择负载最低的设备,30%概率随机选择
if
(
rnd
.
nextDouble
()
<
0.7
)
{
return
availableMachines
.
get
(
0
).
seq
;
}
else
{
return
availableMachines
.
get
(
rnd
.
nextInt
(
availableMachines
.
size
())).
seq
;
}
}
/**
* 交换候选对象,包含位置和评分(用于准备时间优化)
*/
private
static
class
SwapCandidate
{
int
position
;
double
score
;
SwapCandidate
(
int
position
,
double
score
)
{
this
.
position
=
position
;
this
.
score
=
score
;
}
}
/**
* 瓶颈设备工序激进重排 - Wrapper方法
*/
private
Chromosome
aggressiveBottleneckReorderWrapper
(
Chromosome
chromosome
)
{
List
<
GAScheduleResult
>
results
=
chromosome
.
getResult
();
Map
<
Integer
,
Object
>
obj
=
buildPositionToEntryIndex
(
chromosome
);
Map
<
Integer
,
Entry
>
positionToEntryIndex
=
(
Map
<
Integer
,
Entry
>)
obj
.
get
(
1
);
List
<
List
<
Integer
>>
positionByPriority
=
(
List
<
List
<
Integer
>>)
obj
.
get
(
2
);
Map
<
String
,
Integer
>
machinePositionIndex
=
buildEntryMachinePositionIndex
(
chromosome
);
if
(
results
==
null
||
results
.
isEmpty
())
{
return
generateRandomNeighbor
(
chromosome
,
positionToEntryIndex
,
positionByPriority
);
}
Long
bottleneckMachineId
=
findBottleneckMachine
(
chromosome
);
if
(
bottleneckMachineId
!=
null
)
{
Chromosome
result
=
tryAggressiveBottleneckReorder
(
chromosome
,
bottleneckMachineId
,
positionToEntryIndex
,
machinePositionIndex
);
if
(
result
!=
null
)
{
return
result
;
}
}
return
generateRandomNeighbor
(
chromosome
,
positionToEntryIndex
,
positionByPriority
);
}
/**
* 瓶颈设备工序激进重排 - 更激进地调整瓶颈设备上的工序顺序
* 策略:将延迟订单的工序和高优先级工序尽可能往前移动
*/
private
Chromosome
tryAggressiveBottleneckReorder
(
Chromosome
chromosome
,
Long
bottleneckMachineId
,
Map
<
Integer
,
Entry
>
positionIndex
,
Map
<
String
,
Integer
>
machinePositionIndex
)
{
log
(
"tryAggressiveBottleneckReorder: 开始激进重排瓶颈设备工序"
);
List
<
GAScheduleResult
>
allResults
=
chromosome
.
getResult
();
if
(
allResults
==
null
||
allResults
.
isEmpty
())
{
return
null
;
}
// 获取瓶颈设备上的所有工序
List
<
GAScheduleResult
>
bottleneckOps
=
allResults
.
stream
()
.
filter
(
r
->
r
.
getMachineId
()==(
bottleneckMachineId
))
.
collect
(
Collectors
.
toList
());
if
(
bottleneckOps
.
size
()
<
2
)
{
log
(
"tryAggressiveBottleneckReorder: 瓶颈设备上工序太少,无法重排"
);
return
null
;
}
// 计算订单完成时间
Map
<
Integer
,
Integer
>
orderCompletionTimes
=
calculateOrderCompletionTimes
(
allResults
);
// 找出延迟订单(结束时间 > 到期时间,假设Entry有dueDate字段,这里简化为结束时间较晚的订单)
Set
<
Integer
>
delayedOrderIds
=
new
HashSet
<>();
int
avgCompletionTime
=
(
int
)
orderCompletionTimes
.
values
().
stream
()
.
mapToInt
(
Integer:
:
intValue
)
.
average
()
.
orElse
(
0
);
for
(
Map
.
Entry
<
Integer
,
Integer
>
entry
:
orderCompletionTimes
.
entrySet
())
{
if
(
entry
.
getValue
()
>
avgCompletionTime
*
1.2
)
{
// 超过平均完成时间20%视为延迟
delayedOrderIds
.
add
(
entry
.
getKey
());
}
}
Chromosome
neighbor
=
copyChromosome
(
chromosome
);
List
<
Integer
>
os
=
neighbor
.
getOperationSequencing
();
// 对瓶颈设备上的工序进行评分
List
<
OperationScore
>
scoredOps
=
new
ArrayList
<>();
for
(
GAScheduleResult
op
:
bottleneckOps
)
{
Entry
entry
=
entrybyids
.
get
(
op
.
getOperationId
());
if
(
entry
==
null
)
continue
;
double
score
=
0
;
// 1. 延迟订单的工序加分
if
(
delayedOrderIds
.
contains
(
op
.
getGroupId
()))
{
score
+=
100
;
}
// 2. 高优先级工序加分(注意:priority值越低优先级越高)
score
+=
(
10.0
/
(
entry
.
getPriority
()
+
0.1
))
*
50
;
// 优先级值越低,得分越高
// 3. 结束时间晚的工序加分(优先移动)
score
+=
(
double
)
op
.
getEndTime
()
/
10000
;
String
key
=
entry
.
getGroupId
()
+
"_"
+
entry
.
getSequence
();
Integer
pos
=
buildPositionIndex
(
chromosome
).
get
(
key
);
if
(
pos
!=
null
)
{
scoredOps
.
add
(
new
OperationScore
(
pos
,
score
));
}
}
if
(
scoredOps
.
size
()
<
2
)
{
return
null
;
}
// 按评分从高到低排序
scoredOps
.
sort
((
a
,
b
)
->
Double
.
compare
(
b
.
score
,
a
.
score
));
// 选择评分最高的工序,尝试往前移动
OperationScore
selectedOp
=
scoredOps
.
get
(
0
);
int
steps
=
rnd
.
nextInt
(
Math
.
min
(
10
,
selectedOp
.
position
))
+
1
;
// 最多往前移动10步
log
(
String
.
format
(
"tryAggressiveBottleneckReorder: 选择位置%d,往前移动%d步"
,
selectedOp
.
position
,
steps
));
return
insertOperationForward
(
neighbor
,
selectedOp
.
position
,
steps
,
entrys
,
positionIndex
);
}
/**
* 工序评分辅助类
*/
private
static
class
OperationScore
{
int
position
;
double
score
;
OperationScore
(
int
position
,
double
score
)
{
this
.
position
=
position
;
this
.
score
=
score
;
}
}
/**
* 关键路径工序优化 - Wrapper方法
*/
private
Chromosome
criticalPathOptimizeWrapper
(
Chromosome
chromosome
)
{
List
<
GAScheduleResult
>
results
=
chromosome
.
getResult
();
Map
<
Integer
,
Object
>
obj
=
buildPositionToEntryIndex
(
chromosome
);
Map
<
Integer
,
Entry
>
positionToEntryIndex
=
(
Map
<
Integer
,
Entry
>)
obj
.
get
(
1
);
List
<
List
<
Integer
>>
positionByPriority
=
(
List
<
List
<
Integer
>>)
obj
.
get
(
2
);
if
(
results
==
null
||
results
.
isEmpty
())
{
return
generateRandomNeighbor
(
chromosome
,
positionToEntryIndex
,
positionByPriority
);
}
Long
bottleneckMachineId
=
findBottleneckMachine
(
chromosome
);
Chromosome
result
=
tryCriticalPathOptimize
(
chromosome
,
bottleneckMachineId
,
positionToEntryIndex
);
if
(
result
!=
null
)
{
return
result
;
}
return
generateRandomNeighbor
(
chromosome
,
positionToEntryIndex
,
positionByPriority
);
}
/**
* 关键路径工序优化 - 专门针对关键路径上的工序进行优化
* 策略:
* 1. 找出关键路径上的工序
* 2. 优先尝试将关键路径工序往前移动
* 3. 尝试为关键路径工序换设备(如果有选择)
*/
private
Chromosome
tryCriticalPathOptimize
(
Chromosome
chromosome
,
Long
bottleneckMachineId
,
Map
<
Integer
,
Entry
>
positionIndex
)
{
log
(
"tryCriticalPathOptimize: 开始关键路径工序优化"
);
List
<
GAScheduleResult
>
allResults
=
chromosome
.
getResult
();
if
(
allResults
==
null
||
allResults
.
isEmpty
())
{
return
null
;
}
// 分析瓶颈工序,获取关键路径信息
List
<
BottleneckOperationAnalysis
>
analyses
=
analyzeBottleneckOperations
(
allResults
,
bottleneckMachineId
);
// 找出关键路径上的工序
List
<
BottleneckOperationAnalysis
>
criticalPathOps
=
analyses
.
stream
()
.
filter
(
a
->
a
.
onCriticalPath
)
.
collect
(
Collectors
.
toList
());
if
(
criticalPathOps
.
isEmpty
())
{
log
(
"tryCriticalPathOptimize: 没有找到关键路径工序"
);
return
null
;
}
log
(
String
.
format
(
"tryCriticalPathOptimize: 找到%d个关键路径工序"
,
criticalPathOps
.
size
()));
Chromosome
neighbor
=
copyChromosome
(
chromosome
);
List
<
Integer
>
os
=
neighbor
.
getOperationSequencing
();
// 对关键路径工序进行评分
List
<
CriticalPathOpScore
>
scoredOps
=
new
ArrayList
<>();
for
(
BottleneckOperationAnalysis
boa
:
criticalPathOps
)
{
GAScheduleResult
op
=
boa
.
operation
;
Entry
entry
=
entrybyids
.
get
(
op
.
getOperationId
());
if
(
entry
==
null
)
continue
;
double
score
=
0
;
// 1. 在瓶颈设备上的关键工序加分
if
(
bottleneckMachineId
!=
null
&&
op
.
getMachineId
()==(
bottleneckMachineId
))
{
score
+=
100
;
}
// 2. 等待时间长的工序加分
score
+=
boa
.
waitTime
/
100.0
;
// 3. 机器等待时间长的工序加分
score
+=
boa
.
machineWaitTime
/
100.0
;
// 4. 高优先级加分(注意:priority值越低优先级越高)
score
+=
(
10.0
/
(
entry
.
getPriority
()
+
0.1
))
*
30
;
// 优先级值越低,得分越高
String
key
=
entry
.
getGroupId
()
+
"_"
+
entry
.
getSequence
();
Integer
pos
=
buildPositionIndex
(
chromosome
).
get
(
key
);
if
(
pos
!=
null
)
{
scoredOps
.
add
(
new
CriticalPathOpScore
(
pos
,
entry
,
score
));
}
}
if
(
scoredOps
.
isEmpty
())
{
return
null
;
}
// 按评分从高到低排序
scoredOps
.
sort
((
a
,
b
)
->
Double
.
compare
(
b
.
score
,
a
.
score
));
CriticalPathOpScore
selected
=
scoredOps
.
get
(
0
);
// 50%概率尝试往前移动,50%概率尝试换设备(如果有选择)
if
(
rnd
.
nextDouble
()
<
0.5
&&
selected
.
position
>
0
)
{
// 尝试往前移动
int
steps
=
rnd
.
nextInt
(
Math
.
min
(
5
,
selected
.
position
))
+
1
;
log
(
String
.
format
(
"tryCriticalPathOptimize: 关键路径工序往前移动%d步"
,
steps
));
return
insertOperationForward
(
neighbor
,
selected
.
position
,
steps
,
entrys
,
positionIndex
);
}
else
if
(
selected
.
entry
.
getMachineOptions
().
size
()
>
1
)
{
// 尝试换设备
log
(
"tryCriticalPathOptimize: 关键路径工序尝试换设备"
);
Map
<
String
,
Integer
>
machinePositionIndex
=
buildEntryMachinePositionIndex
(
chromosome
);
int
maPos
=
machinePositionIndex
.
get
(
selected
.
entry
.
getGroupId
()
+
"_"
+
selected
.
entry
.
getSequence
());
if
(
maPos
>=
0
)
{
return
generateMachineChangeForSpecificOp
(
neighbor
,
selected
.
entry
.
getMachineOptions
(),
maPos
);
}
}
// 如果以上都失败,尝试简单的往前移动
if
(
selected
.
position
>
0
)
{
int
steps
=
rnd
.
nextInt
(
Math
.
min
(
3
,
selected
.
position
))
+
1
;
return
insertOperationForward
(
neighbor
,
selected
.
position
,
steps
,
entrys
,
positionIndex
);
}
return
null
;
}
/**
* 关键路径工序评分辅助类
*/
private
static
class
CriticalPathOpScore
{
int
position
;
Entry
entry
;
double
score
;
CriticalPathOpScore
(
int
position
,
Entry
entry
,
double
score
)
{
this
.
position
=
position
;
this
.
entry
=
entry
;
this
.
score
=
score
;
}
}
}
}
\ No newline at end of file
src/main/java/com/aps/service/plan/PlanResultService.java
View file @
f1998b61
...
@@ -238,7 +238,7 @@ public class PlanResultService {
...
@@ -238,7 +238,7 @@ public class PlanResultService {
_sceneService
.
saveChromosomeToFile
(
chromosome
,
SceneId
);
_sceneService
.
saveChromosomeToFile
(
chromosome
,
SceneId
);
WriteScheduleSummary
(
chromosome
);
//
WriteScheduleSummary(chromosome);
return
chromosome
;
return
chromosome
;
...
...
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