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
a02e041c
Commit
a02e041c
authored
Apr 23, 2026
by
Tong Li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bom
parent
c1efacb9
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
57 deletions
+52
-57
GeneticDecoder.java
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
+8
-8
VariableNeighborhoodSearch.java
...com/aps/service/Algorithm/VariableNeighborhoodSearch.java
+41
-46
PlanResultService.java
src/main/java/com/aps/service/plan/PlanResultService.java
+1
-1
PlanResultServiceTest.java
src/test/java/com/aps/demo/PlanResultServiceTest.java
+2
-2
No files found.
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
View file @
a02e041c
...
@@ -66,7 +66,7 @@ public class GeneticDecoder {
...
@@ -66,7 +66,7 @@ public class GeneticDecoder {
private
DiscreteParameterMatrixService
discreteParameterMatrixService
;
private
DiscreteParameterMatrixService
discreteParameterMatrixService
;
private
String
sceneId
;
private
String
sceneId
;
private
boolean
rebuildStructureForCurrentDecode
=
fals
e
;
private
boolean
rebuildStructureForCurrentDecode
=
tru
e
;
...
@@ -1328,13 +1328,13 @@ public class GeneticDecoder {
...
@@ -1328,13 +1328,13 @@ public class GeneticDecoder {
// }
// }
bomtime
=
Math
.
max
(
bomtime
,
committedBomTime
);
bomtime
=
Math
.
max
(
bomtime
,
committedBomTime
);
if
(
committedBomTime
>
startTime
)
{
if
(
committedBomTime
>
startTime
)
{
throw
new
IllegalStateException
(
String
.
format
(
//
throw new IllegalStateException(String.format(
"工序固定点求解未收敛,operationId=%d, groupId=%d, startTime=%d, bomTime=%d, maxIterations=%d"
,
//
"工序固定点求解未收敛,operationId=%d, groupId=%d, startTime=%d, bomTime=%d, maxIterations=%d",
operation
.
getId
(),
//
operation.getId(),
operation
.
getGroupId
(),
//
operation.getGroupId(),
startTime
,
//
startTime,
committedBomTime
,
//
committedBomTime,
maxSolveIterations
));
//
maxSolveIterations));
}
}
}
}
...
...
src/main/java/com/aps/service/Algorithm/VariableNeighborhoodSearch.java
View file @
a02e041c
...
@@ -1048,43 +1048,35 @@ public class VariableNeighborhoodSearch {
...
@@ -1048,43 +1048,35 @@ public class VariableNeighborhoodSearch {
lastUsedStrategy
,
consecutiveSameStrategyCount
));
lastUsedStrategy
,
consecutiveSameStrategyCount
));
}
}
// 按成功率排序,但加入随机扰动和探索机制
// 先为每个策略计算固定的评分(包含随机扰动),避免在Comparator中使用随机数
strategies
.
sort
((
a
,
b
)
->
{
final
double
[]
scores
=
new
double
[
4
];
double
successRateA
=
strategyTotalCount
[
a
]
>
0
?
for
(
int
strategy
:
strategies
)
{
(
double
)
strategySuccessCount
[
a
]
/
strategyTotalCount
[
a
]
:
INITIAL_SUCCESS_RATE
;
double
score
=
strategyTotalCount
[
strategy
]
>
0
?
double
successRateB
=
strategyTotalCount
[
b
]
>
0
?
(
double
)
strategySuccessCount
[
strategy
]
/
strategyTotalCount
[
strategy
]
:
INITIAL_SUCCESS_RATE
;
(
double
)
strategySuccessCount
[
b
]
/
strategyTotalCount
[
b
]
:
INITIAL_SUCCESS_RATE
;
// 强制轮换:给最后使用的策略降权
// 强制轮换:给最后使用的策略降权
if
(
needForceRotate
&&
a
==
lastUsedStrategy
)
{
if
(
needForceRotate
&&
strategy
==
lastUsedStrategy
)
{
successRateA
-=
FORCE_ROTATE_PENALTY
;
// 大幅降权
score
-=
FORCE_ROTATE_PENALTY
;
// 大幅降权
}
if
(
needForceRotate
&&
b
==
lastUsedStrategy
)
{
successRateB
-=
FORCE_ROTATE_PENALTY
;
}
}
// 给使用次数少的策略加分,鼓励探索
// 给使用次数少的策略加分,鼓励探索
if
(
strategyTotalCount
[
a
]
<
MIN_USE_COUNT_FOR_EXPLORATION_BONUS
)
{
if
(
strategyTotalCount
[
strategy
]
<
MIN_USE_COUNT_FOR_EXPLORATION_BONUS
)
{
successRateA
+=
EXPLORATION_BONUS_FOR_LOW_USE
;
score
+=
EXPLORATION_BONUS_FOR_LOW_USE
;
}
if
(
strategyTotalCount
[
b
]
<
MIN_USE_COUNT_FOR_EXPLORATION_BONUS
)
{
successRateB
+=
EXPLORATION_BONUS_FOR_LOW_USE
;
}
}
// 如果策略被尝试次数很多但成功率很低,给它额外加分鼓励探索
// 如果策略被尝试次数很多但成功率很低,给它额外加分鼓励探索
if
(
strategyTotalCount
[
a
]
>
LOW_SUCCESS_RATE_MIN_TRIALS
&&
successRateA
<
LOW_SUCCESS_RATE_THRESHOLD
)
{
if
(
strategyTotalCount
[
strategy
]
>
LOW_SUCCESS_RATE_MIN_TRIALS
&&
score
<
LOW_SUCCESS_RATE_THRESHOLD
)
{
successRateA
+=
EXPLORATION_BONUS_FOR_LOW_SUCCESS
;
score
+=
EXPLORATION_BONUS_FOR_LOW_SUCCESS
;
}
if
(
strategyTotalCount
[
b
]
>
LOW_SUCCESS_RATE_MIN_TRIALS
&&
successRateB
<
LOW_SUCCESS_RATE_THRESHOLD
)
{
successRateB
+=
EXPLORATION_BONUS_FOR_LOW_SUCCESS
;
}
}
// 加入少量随机扰动,避免陷入局部最优
// 加入少量随机扰动,避免陷入局部最优
successRateA
+=
rnd
.
nextDouble
()
*
RANDOM_NOISE_FACTOR
;
score
+=
rnd
.
nextDouble
()
*
RANDOM_NOISE_FACTOR
;
successRateB
+=
rnd
.
nextDouble
()
*
RANDOM_NOISE_FACTOR
;
return
Double
.
compare
(
successRateB
,
successRateA
);
scores
[
strategy
]
=
score
;
});
}
// 按评分排序(Comparator只使用预计算的固定值)
strategies
.
sort
((
a
,
b
)
->
Double
.
compare
(
scores
[
b
],
scores
[
a
]));
return
strategies
;
return
strategies
;
}
}
...
@@ -1197,9 +1189,10 @@ public class VariableNeighborhoodSearch {
...
@@ -1197,9 +1189,10 @@ public class VariableNeighborhoodSearch {
Entry
entryA
=
entrybyids
.
get
(
a
.
getOperationId
());
Entry
entryA
=
entrybyids
.
get
(
a
.
getOperationId
());
Entry
entryB
=
entrybyids
.
get
(
b
.
getOperationId
());
Entry
entryB
=
entrybyids
.
get
(
b
.
getOperationId
());
if
(
entryA
==
null
||
entryB
==
null
)
{
// 统一处理null值:null值排后面
return
0
;
if
(
entryA
==
null
&&
entryB
==
null
)
return
0
;
}
if
(
entryA
==
null
)
return
1
;
if
(
entryB
==
null
)
return
-
1
;
int
sizeA
=
priorityToGroupIds
.
getOrDefault
(
entryA
.
getPriority
(),
new
HashSet
<>()).
size
();
int
sizeA
=
priorityToGroupIds
.
getOrDefault
(
entryA
.
getPriority
(),
new
HashSet
<>()).
size
();
int
sizeB
=
priorityToGroupIds
.
getOrDefault
(
entryB
.
getPriority
(),
new
HashSet
<>()).
size
();
int
sizeB
=
priorityToGroupIds
.
getOrDefault
(
entryB
.
getPriority
(),
new
HashSet
<>()).
size
();
...
@@ -1379,7 +1372,11 @@ public class VariableNeighborhoodSearch {
...
@@ -1379,7 +1372,11 @@ public class VariableNeighborhoodSearch {
Entry
entryA
=
entrybyids
.
get
(
a
.
getOperationId
());
Entry
entryA
=
entrybyids
.
get
(
a
.
getOperationId
());
Entry
entryB
=
entrybyids
.
get
(
b
.
getOperationId
());
Entry
entryB
=
entrybyids
.
get
(
b
.
getOperationId
());
if
(
entryA
!=
null
&&
entryB
!=
null
)
{
// 统一处理null值:null值排后面
if
(
entryA
==
null
&&
entryB
==
null
)
return
0
;
if
(
entryA
==
null
)
return
1
;
if
(
entryB
==
null
)
return
-
1
;
// 优先按订单数从多到少排序
// 优先按订单数从多到少排序
int
sizeA
=
priorityToGroupIds
.
getOrDefault
(
entryA
.
getPriority
(),
new
HashSet
<>()).
size
();
int
sizeA
=
priorityToGroupIds
.
getOrDefault
(
entryA
.
getPriority
(),
new
HashSet
<>()).
size
();
int
sizeB
=
priorityToGroupIds
.
getOrDefault
(
entryB
.
getPriority
(),
new
HashSet
<>()).
size
();
int
sizeB
=
priorityToGroupIds
.
getOrDefault
(
entryB
.
getPriority
(),
new
HashSet
<>()).
size
();
...
@@ -1398,8 +1395,6 @@ public class VariableNeighborhoodSearch {
...
@@ -1398,8 +1395,6 @@ public class VariableNeighborhoodSearch {
int
endTimeA
=
orderCompletionTimes
.
getOrDefault
(
a
.
getGroupId
(),
0
);
int
endTimeA
=
orderCompletionTimes
.
getOrDefault
(
a
.
getGroupId
(),
0
);
int
endTimeB
=
orderCompletionTimes
.
getOrDefault
(
b
.
getGroupId
(),
0
);
int
endTimeB
=
orderCompletionTimes
.
getOrDefault
(
b
.
getGroupId
(),
0
);
return
Integer
.
compare
(
endTimeB
,
endTimeA
);
return
Integer
.
compare
(
endTimeB
,
endTimeA
);
}
return
0
;
});
});
if
(
sortedBottleneckOps
.
isEmpty
())
{
if
(
sortedBottleneckOps
.
isEmpty
())
{
...
...
src/main/java/com/aps/service/plan/PlanResultService.java
View file @
a02e041c
...
@@ -2097,7 +2097,7 @@ public class PlanResultService {
...
@@ -2097,7 +2097,7 @@ public class PlanResultService {
globalParam
.
setIsCheckSf
(
c
.
isValue
());
globalParam
.
setIsCheckSf
(
c
.
isValue
());
}
}
globalParam
.
setIsCheckSf
(
true
);
}
}
FileHelper
.
writeLogFile
(
"初始化约束-----------结束-------"
);
FileHelper
.
writeLogFile
(
"初始化约束-----------结束-------"
);
return
globalParam
;
return
globalParam
;
...
...
src/test/java/com/aps/demo/PlanResultServiceTest.java
View file @
a02e041c
...
@@ -41,9 +41,9 @@ public class PlanResultServiceTest {
...
@@ -41,9 +41,9 @@ public class PlanResultServiceTest {
// nsgaiiUtils.Test();
// nsgaiiUtils.Test();
// planResultService.execute2("E29F2B3ADA8149F6B916B5119296A92B");//2000
// planResultService.execute2("E29F2B3ADA8149F6B916B5119296A92B");//2000
planResultService
.
execute2
(
"E2CD1FC6FF9B4B19A59FEC7F846D4952"
);
//600
//
planResultService.execute2("E2CD1FC6FF9B4B19A59FEC7F846D4952");//600
// planResultService.execute2("EAF3C94B8F3345278F226C94FB0FED86");//bom
// planResultService.execute2("EAF3C94B8F3345278F226C94FB0FED86");//bom
//
planResultService.execute2("6D63146BE5C84A78B5AB044327BA55BD");//2000
planResultService
.
execute2
(
"6D63146BE5C84A78B5AB044327BA55BD"
);
//2000
// planResultService.execute2("6D63146BE5C84A78B5AB044327BA55BD");//5000
// planResultService.execute2("6D63146BE5C84A78B5AB044327BA55BD");//5000
// planResultService.execute2("C8B533BD8944405B9A2F8823C575C204");//500
// planResultService.execute2("C8B533BD8944405B9A2F8823C575C204");//500
// planResultService.execute2("EFDD34E4B5BC434BAEAE6A84DFCD4E7B");//20
// planResultService.execute2("EFDD34E4B5BC434BAEAE6A84DFCD4E7B");//20
...
...
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