Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
yangxiujun
/
paidan_demo
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 8f969e73
authored
Nov 13, 2023
by
chamberone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修复时间窗错误,修复偏好距离为空bug,修复派工结果更新bug
1 parent
bb5efd87
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
5 deletions
project-dispatch/src/main/java/com/dituhui/pea/dispatch/pojo/Technician.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/service/impl/SolveServiceImpl.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/utils/DispatchSolutionUtils.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/utils/RoadDistanceUtils.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/pojo/Technician.java
View file @
8f969e7
...
...
@@ -138,7 +138,7 @@ public class Technician {
}
/**
* 总路线距离
* 总路线距离
(米)
*
* @return
*/
...
...
@@ -156,7 +156,7 @@ public class Technician {
}
totalDistance
+=
previousLocation
.
getDistanceTo
(
this
.
getVehicleType
(),
depot
.
getLocation
());
return
totalDistance
;
return
totalDistance
*
1000
;
}
/**
...
...
@@ -169,6 +169,11 @@ public class Technician {
return
0
;
}
// 技术员未设置偏好位置
if
(
preferredlocationDistanceMap
.
isEmpty
()){
return
0
;
}
long
totalDistance
=
0
;
for
(
Customer
customer
:
customerList
)
{
totalDistance
+=
preferredlocationDistanceMap
.
get
(
customer
.
getCode
());
...
...
project-dispatch/src/main/java/com/dituhui/pea/dispatch/service/impl/SolveServiceImpl.java
View file @
8f969e7
...
...
@@ -15,6 +15,7 @@ import com.dituhui.pea.dispatch.service.ExtractService;
import
com.dituhui.pea.dispatch.service.SolveService
;
import
com.dituhui.pea.dispatch.utils.DispatchSolutionUtils
;
import
com.google.common.collect.Lists
;
import
com.google.gson.Gson
;
import
lombok.extern.slf4j.Slf4j
;
import
org.optaplanner.core.api.solver.Solver
;
...
...
@@ -290,10 +291,15 @@ public class SolveServiceImpl implements SolveService {
// 距离偏好map
Map
<
String
,
Long
>
preferedLoctionDistanceMap
=
new
HashMap
<
String
,
Long
>();
if
(
location
.
getLongitude
()
>
1
&&
location
.
getLatitude
()
>
1
)
{
// 设置了偏好位置
customerList
.
forEach
(
customer
->
{
long
distance
=
distanceCalculator
.
calculateDistance
(
location
,
customer
.
getLocation
());
preferedLoctionDistanceMap
.
put
(
customer
.
getCode
(),
distance
);
});
}
else
{
// 未设置,不参与计算
}
// 硬约束:电动车固定40km上限,其他无限制
int
maxDistance
=
engineer
.
getMaxDistance
()
*
1000
;
...
...
@@ -312,7 +318,13 @@ public class SolveServiceImpl implements SolveService {
}
Location
engineerLocation
=
new
Location
(
engineer
.
getId
(),
engineer
.
getEngineerCode
(),
"起点"
,
x
,
y
);
Depot
engineerDepot
=
new
Depot
(
engineer
.
getId
(),
engineer
.
getEngineerCode
(),
engineerLocation
,
60
*
8
,
60
*
18
);
// FIXME 无锡时间窗数据错误,暂时改成固定值
int
[][]
timeWindows
=
engineerCalendarService
.
timeWindows
(
engineer
.
getEngineerCode
(),
teamId
,
LocalDateTimeUtil
.
parseDate
(
currDay
,
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd"
)));
System
.
err
.
println
(
engineer
.
getEngineerName
()+
" : "
+
new
Gson
().
toJson
(
timeWindows
));
log
.
info
(
engineer
.
getEngineerName
()+
" : "
+
new
Gson
().
toJson
(
timeWindows
));
timeWindows
=
new
int
[][]
{
{
480
,
1080
}
};
Technician
vehicle
=
new
Technician
(
engineer
.
getId
(),
engineer
.
getEngineerCode
(),
engineer
.
getMaxNum
(),
engineer
.
getMaxMinute
(),
maxDistance
,
engineer
.
getVehicleType
(),
engineerDepot
,
timeWindows
,
Set
.
copyOf
(
skillList
),
preferedLoctionDistanceMap
);
technicianList
.
add
(
vehicle
);
});
...
...
project-dispatch/src/main/java/com/dituhui/pea/dispatch/utils/DispatchSolutionUtils.java
View file @
8f969e7
...
...
@@ -151,12 +151,15 @@ public class DispatchSolutionUtils {
// 技术员偏好中心点
String
preferredlocation
=
"\""
+
solution
.
getTechnicianList
().
stream
()
.
map
(
c
->
c
.
getPreferredlocation
().
getX
()
+
","
+
c
.
getPreferredlocation
().
getY
())
.
map
(
c
->
(
c
.
getPreferredlocation
()
==
null
?
""
:
c
.
getPreferredlocation
().
getX
())
+
","
+
(
c
.
getPreferredlocation
()
==
null
?
""
:
c
.
getPreferredlocation
().
getY
()))
.
reduce
((
a
,
b
)
->
a
+
";"
+
b
).
get
()
+
"\""
;
// 技术员名称
String
names
=
"\""
+
solution
.
getTechnicianList
().
stream
()
.
map
(
c
->
c
.
getPreferredlocation
().
getX
()
+
","
+
c
.
getPreferredlocation
().
getY
()+
","
+
c
.
getCode
())
.
map
(
c
->
(
c
.
getPreferredlocation
()
==
null
?
""
:
c
.
getPreferredlocation
().
getX
())
+
","
+
(
c
.
getPreferredlocation
()
==
null
?
""
:
c
.
getPreferredlocation
().
getY
())
+
","
+
c
.
getCode
())
.
reduce
((
a
,
b
)
->
a
+
";"
+
b
).
get
()
+
"\""
;
List
<
String
>
dispatchMapLines
=
IOUtils
.
readLines
(
new
FileInputStream
(
"data/dispatchMap.html"
),
"GBK"
);
...
...
project-dispatch/src/main/java/com/dituhui/pea/dispatch/utils/RoadDistanceUtils.java
View file @
8f969e7
...
...
@@ -136,7 +136,7 @@ public class RoadDistanceUtils {
}
String
text
=
requestGetAK
(
url
,
params
);
System
.
out
.
println
(
url
+
" : "
+
gson
.
toJson
(
params
)
+
" : "
+
text
);
//
System.out.println(url + " : " + gson.toJson(params) + " : " + text);
BDResult
webResult
=
gson
.
fromJson
(
text
,
BDResult
.
class
);
float
dis
=
webResult
.
getResult
().
get
(
0
).
getDistance
().
getValue
()
/
1000
F
;
int
time
=
webResult
.
getResult
().
get
(
0
).
getDuration
().
getValue
();
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment