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
f30098ce
Commit
f30098ce
authored
Mar 17, 2026
by
Tong Li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
目标kpi可配置
parent
e9d075e2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
492 additions
and
149 deletions
+492
-149
GlobalParam.java
src/main/java/com/aps/entity/basic/GlobalParam.java
+123
-0
ObjectiveConfig.java
src/main/java/com/aps/entity/basic/ObjectiveConfig.java
+46
-0
GeneticAlgorithm.java
...main/java/com/aps/service/Algorithm/GeneticAlgorithm.java
+3
-7
GeneticDecoder.java
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
+83
-65
NSGAIIUtils.java
src/main/java/com/aps/service/Algorithm/NSGAIIUtils.java
+213
-73
PlanResultService.java
src/main/java/com/aps/service/plan/PlanResultService.java
+5
-3
NSGAIIUtilsTest.java
src/test/java/com/aps/demo/NSGAIIUtilsTest.java
+18
-0
PlanResultServiceTest.java
src/test/java/com/aps/demo/PlanResultServiceTest.java
+1
-1
No files found.
src/main/java/com/aps/entity/basic/GlobalParam.java
View file @
f30098ce
...
...
@@ -2,6 +2,11 @@ package com.aps.entity.basic;
import
lombok.Data
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* 作者:佟礼
* 时间:2025-11-21
...
...
@@ -43,4 +48,122 @@ public class GlobalParam {
private
boolean
_smoothChangeOver
=
true
;
// 默认true,设置时间 是否考虑换型时间
private
boolean
_smoothChangeOverInWeek
=
true
;
// 默认true,后台任务设置 休息时间是否换型
/**
* NSGA-II模式:true=纯帕累托(无视权重),false=加权帕累托
*/
private
boolean
pureNSGAIIMode
=
true
;
/// <summary>
/// 目标值配置列表:包含目标值的名称、是否启用、层级和权重
/// </summary>
private
List
<
ObjectiveConfig
>
objectiveConfigs
=
new
ArrayList
<>();
/// <summary>
/// 目标值名称常量
/// </summary>
public
static
final
String
OBJECTIVE_MAKESPAN
=
"makespan"
;
// 最早完工时间
public
static
final
String
OBJECTIVE_FLOW_TIME
=
"flowTime"
;
// 总流程时间
public
static
final
String
OBJECTIVE_SETUP_TIME
=
"setupTime"
;
// 总换型时间
public
static
final
String
OBJECTIVE_MACHINE_LOAD
=
"machineLoad"
;
// 机器负载均衡
public
static
final
String
OBJECTIVE_TARDINESS
=
"tardiness"
;
// 延迟时间
/// <summary>
/// 构造函数,初始化默认值
/// </summary>
public
GlobalParam
()
{
// 初始化默认目标值配置
//完工时间、总流程时间、总换型时间、机器负载标准差、延迟时间
objectiveConfigs
.
add
(
new
ObjectiveConfig
(
OBJECTIVE_MAKESPAN
,
true
,
1
,
0.6
));
objectiveConfigs
.
add
(
new
ObjectiveConfig
(
OBJECTIVE_FLOW_TIME
,
false
,
2
,
0.1
));
objectiveConfigs
.
add
(
new
ObjectiveConfig
(
OBJECTIVE_SETUP_TIME
,
true
,
2
,
0.1
));
objectiveConfigs
.
add
(
new
ObjectiveConfig
(
OBJECTIVE_MACHINE_LOAD
,
false
,
3
,
0.1
));
objectiveConfigs
.
add
(
new
ObjectiveConfig
(
OBJECTIVE_TARDINESS
,
true
,
1
,
0.3
));
}
/// <summary>
/// 获取目标值启用状态
/// </summary>
public
Map
<
String
,
Boolean
>
getObjectiveEnabled
()
{
Map
<
String
,
Boolean
>
enabledMap
=
new
HashMap
<>();
for
(
ObjectiveConfig
config
:
objectiveConfigs
)
{
enabledMap
.
put
(
config
.
getName
(),
config
.
isEnabled
());
}
return
enabledMap
;
}
/// <summary>
/// 获取目标值层级
/// </summary>
public
Map
<
String
,
Integer
>
getObjectiveLevels
()
{
Map
<
String
,
Integer
>
levelsMap
=
new
HashMap
<>();
for
(
ObjectiveConfig
config
:
objectiveConfigs
)
{
levelsMap
.
put
(
config
.
getName
(),
config
.
getLevel
());
}
return
levelsMap
;
}
/// <summary>
/// 获取目标值顺序
/// </summary>
public
List
<
String
>
getObjectiveOrder
()
{
List
<
String
>
orderList
=
new
ArrayList
<>();
for
(
ObjectiveConfig
config
:
objectiveConfigs
)
{
orderList
.
add
(
config
.
getName
());
}
return
orderList
;
}
/// <summary>
/// 获取目标值权重
/// </summary>
public
Map
<
String
,
Double
>
getObjectiveWeights
()
{
Map
<
String
,
Double
>
weightsMap
=
new
HashMap
<>();
for
(
ObjectiveConfig
config
:
objectiveConfigs
)
{
if
(
config
.
isEnabled
())
{
weightsMap
.
put
(
config
.
getName
(),
config
.
getWeight
());
}
}
return
weightsMap
;
}
/// <summary>
/// 根据名称获取目标值配置
/// </summary>
public
ObjectiveConfig
getObjectiveConfig
(
String
name
)
{
for
(
ObjectiveConfig
config
:
objectiveConfigs
)
{
if
(
config
.
getName
().
equals
(
name
))
{
return
config
;
}
}
return
null
;
}
/// <summary>
/// 添加目标值配置
/// </summary>
public
void
addObjectiveConfig
(
ObjectiveConfig
config
)
{
objectiveConfigs
.
add
(
config
);
}
/// <summary>
/// 更新目标值配置
/// </summary>
public
void
updateObjectiveConfig
(
String
name
,
ObjectiveConfig
config
)
{
for
(
int
i
=
0
;
i
<
objectiveConfigs
.
size
();
i
++)
{
if
(
objectiveConfigs
.
get
(
i
).
getName
().
equals
(
name
))
{
objectiveConfigs
.
set
(
i
,
config
);
return
;
}
}
}
/// <summary>
/// 移除目标值配置
/// </summary>
public
void
removeObjectiveConfig
(
String
name
)
{
objectiveConfigs
.
removeIf
(
config
->
config
.
getName
().
equals
(
name
));
}
}
src/main/java/com/aps/entity/basic/ObjectiveConfig.java
0 → 100644
View file @
f30098ce
package
com
.
aps
.
entity
.
basic
;
import
lombok.Data
;
/**
* 目标值配置实体类
* 作者:佟礼
* 时间:2026-03-17
*/
@Data
public
class
ObjectiveConfig
{
/**
* 目标值名称
*/
private
String
name
;
/**
* 是否启用
*/
private
boolean
enabled
;
/**
* 层级,层级越低优先级越高,1为最高
*/
private
int
level
;
/**
* 权重
*/
private
double
weight
;
/**
* 构造函数
*/
public
ObjectiveConfig
()
{
}
/**
* 构造函数
*/
public
ObjectiveConfig
(
String
name
,
boolean
enabled
,
int
level
,
double
weight
)
{
this
.
name
=
name
;
this
.
enabled
=
enabled
;
this
.
level
=
level
;
this
.
weight
=
weight
;
}
}
\ No newline at end of file
src/main/java/com/aps/service/Algorithm/GeneticAlgorithm.java
View file @
f30098ce
...
...
@@ -65,14 +65,10 @@ public class GeneticAlgorithm {
materialIds
=
_materialIds
;
}
public
void
Init
(
double
[]
customWeights
,
boolean
pureNSGAIIMode
)
{
public
void
Init
()
{
// 自定义权重配置
if
(
customWeights
!=
null
&&
customWeights
.
length
==
5
)
{
_objectiveWeights
.
setWeights
(
customWeights
);
_objectiveWeights
.
setPureNSGAIIMode
(
pureNSGAIIMode
);
}
_nsgaIIUtils
.
init
(
_objectiveWeights
);
_nsgaIIUtils
.
init
(
_GlobalParam
);
}
public
Chromosome
Run
(
ScheduleParams
param
,
List
<
Entry
>
allOperations
)
{
...
...
src/main/java/com/aps/service/Algorithm/GeneticDecoder.java
View file @
f30098ce
...
...
@@ -1759,12 +1759,24 @@ if(MaterialRequirements==null||MaterialRequirements.size()==0)
private
void
calculateScheduleResult
(
Chromosome
chromosome
)
{
double
[]
Objectives
=
new
double
[
_globalParam
.
getObjectiveWeights
().
size
()];
int
i
=
0
;
for
(
ObjectiveConfig
config
:
_globalParam
.
getObjectiveConfigs
())
{
if
(
config
.
isEnabled
())
{
if
(
config
.
getName
()==
GlobalParam
.
OBJECTIVE_MAKESPAN
)
{
// 1. 最早完工时间(最小化)
double
makespan
=
chromosome
.
getResult
().
stream
()
.
mapToInt
(
GAScheduleResult:
:
getEndTime
)
.
max
()
.
orElse
(
0
);
Objectives
[
i
]=
makespan
;
chromosome
.
setMakespan
(
makespan
);
}
if
(
config
.
getName
()==
GlobalParam
.
OBJECTIVE_TARDINESS
)
{
// 2. 交付期满足情况(最小化延迟)
double
tardiness
=
0
;
...
...
@@ -1786,8 +1798,8 @@ if(MaterialRequirements==null||MaterialRequirements.size()==0)
.
filter
(
t
->
orderIds
.
contains
(
t
.
getOrderId
()))
.
max
(
Comparator
.
comparing
(
Order:
:
getDueDate
))
.
orElse
(
null
);
if
(
order
.
isNewCreate
())
{
continue
;}
if
(
order
.
isNewCreate
())
{
continue
;}
LocalDateTime
dueDateTime
=
order
.
getDueDate
();
...
...
@@ -1804,28 +1816,34 @@ if(order.isNewCreate())
}
Objectives
[
i
]=
tardiness
;
chromosome
.
setDelayTime
(
tardiness
);
}
if
(
config
.
getName
()==
GlobalParam
.
OBJECTIVE_SETUP_TIME
)
{
// 3. 最小总换型时间
double
totalSetupTime
=
calculateTotalSetupTime
(
chromosome
);
chromosome
.
setTotalChangeoverTime
(
totalSetupTime
);
Objectives
[
i
]=
totalSetupTime
;
}
if
(
config
.
getName
()==
GlobalParam
.
OBJECTIVE_FLOW_TIME
)
{
// 4. 最小化总流程时间 所有工序加工时间的总和
double
totalFlowTime
=
calculateTotalFlowTime
(
chromosome
);
chromosome
.
setTotalFlowTime
(
totalFlowTime
);
Objectives
[
i
]=
totalFlowTime
;
}
if
(
config
.
getName
()==
GlobalParam
.
OBJECTIVE_MACHINE_LOAD
)
{
// 5. 机器负载均衡
double
machineLoadBalance
=
calculateMachineLoadBalance
(
chromosome
);
// 存储各目标值
chromosome
.
setMakespan
(
makespan
);
chromosome
.
setTotalFlowTime
(
totalFlowTime
);
chromosome
.
setTotalChangeoverTime
(
totalSetupTime
);
chromosome
.
setMachineLoadStd
(
machineLoadBalance
);
chromosome
.
setDelayTime
(
tardiness
);
Objectives
[
i
]=
machineLoadBalance
;
}
i
++;
}
}
double
[]
Objectives
=
new
double
[
5
];
Objectives
[
0
]
=
makespan
;
Objectives
[
1
]
=
totalFlowTime
;
Objectives
[
2
]
=
totalSetupTime
;
Objectives
[
3
]
=
machineLoadBalance
;
Objectives
[
4
]
=
tardiness
;
chromosome
.
setObjectives
(
Objectives
);
}
...
...
src/main/java/com/aps/service/Algorithm/NSGAIIUtils.java
View file @
f30098ce
This diff is collapsed.
Click to expand it.
src/main/java/com/aps/service/plan/PlanResultService.java
View file @
f30098ce
...
...
@@ -208,13 +208,14 @@ public class PlanResultService {
.
map
(
Material:
:
getId
)
.
distinct
()
.
collect
(
Collectors
.
toList
());
globalParam
.
setPureNSGAIIMode
(
false
);
// 5. 执行调度算法
GeneticAlgorithm
scheduler
=
new
GeneticAlgorithm
(
globalParam
,
machines
,
orders
,
Materials1
,
materialIds
,
machineScheduler
,
entryRel
,
materialRequirementService
,
_sceneService
,
SceneId
);
//new GeneticAlgorithm(products, machines, orders, machineScheduler);
param
.
initAdaptiveParams
(
entrys
.
size
());
double
[]
customWeights
=
new
double
[]
{
0.4
,
0.1
,
0.1
,
0.1
,
0.3
};
// 延迟时间权重提升到0.5
//完工时间、总流程时间、总换型时间、机器负载标准差、延迟时间
scheduler
.
Init
(
customWeights
,
false
);
scheduler
.
Init
();
// scheduler.Init(customWeights,false);
Chromosome
chromosome
=
scheduler
.
Run
(
param
,
entrys
);
KpiCalculator
kpiCalculator
=
new
KpiCalculator
(
chromosome
);
...
...
@@ -770,7 +771,8 @@ public class PlanResultService {
param
.
initAdaptiveParams
(
entrys
.
size
());
double
[]
customWeights
=
new
double
[]
{
0.4
,
0.1
,
0.1
,
0.1
,
0.3
};
// 延迟时间权重提升到0.5
//完工时间、总流程时间、总换型时间、机器负载标准差、延迟时间
scheduler
.
Init
(
customWeights
,
false
);
// scheduler.Init(customWeights,false);
scheduler
.
Init
();
Chromosome
chromosomes
=
scheduler
.
Run
(
param
,
entrys
);
KpiCalculator
kpiCalculator
=
new
KpiCalculator
(
chromosomes
);
kpiCalculator
.
calculatekpi
();
...
...
src/test/java/com/aps/demo/NSGAIIUtilsTest.java
0 → 100644
View file @
f30098ce
package
com
.
aps
.
demo
;
import
com.aps.service.Algorithm.NSGAIIUtils
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.test.context.SpringBootTest
;
/**
* 作者:佟礼
* 时间:2026-03-17
*/
@SpringBootTest
public
class
NSGAIIUtilsTest
{
private
NSGAIIUtils
_nsgaIIUtils
=
new
NSGAIIUtils
();
@Test
public
void
test
()
{
_nsgaIIUtils
.
Test
();
}
}
src/test/java/com/aps/demo/PlanResultServiceTest.java
View file @
f30098ce
...
...
@@ -39,7 +39,7 @@ public class PlanResultServiceTest {
// TestSortService sortService=new TestSortService();
// sortService.test1();
// nsgaiiUtils.Test();
planResultService
.
execute2
(
"
5475E00B844847ACB6DC20227967BA2F
"
);
planResultService
.
execute2
(
"
EFDD34E4B5BC434BAEAE6A84DFCD4E7B
"
);
// planResultService.execute2("00E0C5D3E4AD4F36B56C39395906618D");
// planResultService.execute2("92BB773E1E2447C99D8176C991D5C9D2");
...
...
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