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 05cfb647
authored
Jun 25, 2023
by
chamberone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 字段调整,包名调整
1 parent
e58666f4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
22 deletions
project-dispatch/src/main/java/com/dituhui/pea/dispatch/pojo/VehicleRoutingSolution.java → project-dispatch/src/main/java/com/dituhui/pea/dispatch/pojo/DispatchSolution.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/pojo/Technician.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/service/impl/DispatchServiceImpl.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/shadowVariable/ArrivalTimeUpdatingVariableListener.java
project-dispatch/src/main/java/com/dituhui/pea/dispatch/pojo/
VehicleRouting
Solution.java
→
project-dispatch/src/main/java/com/dituhui/pea/dispatch/pojo/
Dispatch
Solution.java
View file @
05cfb64
...
@@ -14,7 +14,7 @@ import lombok.Data;
...
@@ -14,7 +14,7 @@ import lombok.Data;
@Data
@Data
@PlanningSolution
@PlanningSolution
public
class
VehicleRouting
Solution
{
public
class
Dispatch
Solution
{
private
String
name
;
private
String
name
;
...
@@ -35,10 +35,10 @@ public class VehicleRoutingSolution {
...
@@ -35,10 +35,10 @@ public class VehicleRoutingSolution {
@PlanningScore
@PlanningScore
private
HardSoftLongScore
score
;
private
HardSoftLongScore
score
;
public
VehicleRouting
Solution
()
{
public
Dispatch
Solution
()
{
}
}
public
VehicleRouting
Solution
(
String
name
,
List
<
Location
>
locationList
,
Depot
depot
,
public
Dispatch
Solution
(
String
name
,
List
<
Location
>
locationList
,
Depot
depot
,
List
<
Technician
>
technicianList
,
List
<
Customer
>
customerList
)
{
List
<
Technician
>
technicianList
,
List
<
Customer
>
customerList
)
{
this
.
name
=
name
;
this
.
name
=
name
;
this
.
locationList
=
locationList
;
this
.
locationList
=
locationList
;
...
...
project-dispatch/src/main/java/com/dituhui/pea/dispatch/pojo/Technician.java
View file @
05cfb64
...
@@ -61,6 +61,7 @@ public class Technician {
...
@@ -61,6 +61,7 @@ public class Technician {
/**
/**
* @return route of the vehicle
* @return route of the vehicle
*/
*/
@JsonIgnore
public
List
<
Location
>
getRoute
()
{
public
List
<
Location
>
getRoute
()
{
if
(
customerList
.
isEmpty
())
{
if
(
customerList
.
isEmpty
())
{
return
Collections
.
emptyList
();
return
Collections
.
emptyList
();
...
@@ -72,7 +73,6 @@ public class Technician {
...
@@ -72,7 +73,6 @@ public class Technician {
for
(
Customer
customer
:
customerList
)
{
for
(
Customer
customer
:
customerList
)
{
route
.
add
(
customer
.
getLocation
());
route
.
add
(
customer
.
getLocation
());
}
}
// route.add(depot.getLocation());
return
route
;
return
route
;
}
}
...
...
project-dispatch/src/main/java/com/dituhui/pea/dispatch/service/impl/DispatchServiceImpl.java
View file @
05cfb64
...
@@ -41,7 +41,7 @@ import org.slf4j.LoggerFactory;
...
@@ -41,7 +41,7 @@ import org.slf4j.LoggerFactory;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
com.dituhui.pea.dispatch.constraint.DispatchConstraintProvider
;
import
com.dituhui.pea.dispatch.constraint.DispatchConstraintProvider
;
import
com.dituhui.pea.dispatch.pojo.
VehicleRouting
Solution
;
import
com.dituhui.pea.dispatch.pojo.
Dispatch
Solution
;
import
com.dituhui.pea.common.Result
;
import
com.dituhui.pea.common.Result
;
import
com.dituhui.pea.dispatch.service.DispatchService
;
import
com.dituhui.pea.dispatch.service.DispatchService
;
import
com.dituhui.pea.dispatch.pojo.Customer
;
import
com.dituhui.pea.dispatch.pojo.Customer
;
...
@@ -68,13 +68,13 @@ public class DispatchServiceImpl implements DispatchService {
...
@@ -68,13 +68,13 @@ public class DispatchServiceImpl implements DispatchService {
Map
<
String
,
String
>
customerCodeSkillMap
=
loadCustomerCodeSkillMap
();
Map
<
String
,
String
>
customerCodeSkillMap
=
loadCustomerCodeSkillMap
();
Map
<
String
,
Map
<
String
,
Long
>>
preferredlocationDistanceMap
=
loadPreferredlocationDistanceMap
();
Map
<
String
,
Map
<
String
,
Long
>>
preferredlocationDistanceMap
=
loadPreferredlocationDistanceMap
();
Map
<
String
,
Integer
>
customerCodeServiceTimeMap
=
loadCustomerCodeServiceTimeMap
();
Map
<
String
,
Integer
>
customerCodeServiceTimeMap
=
loadCustomerCodeServiceTimeMap
();
VehicleRouting
Solution
problem
=
createVehicleRoutingSolution
(
customerIndexMap
,
technicianIndexMap
,
Dispatch
Solution
problem
=
createVehicleRoutingSolution
(
customerIndexMap
,
technicianIndexMap
,
technicianCodeSkillsMap
,
customerCodeSkillMap
,
preferredlocationDistanceMap
,
customerCodeServiceTimeMap
);
technicianCodeSkillsMap
,
customerCodeSkillMap
,
preferredlocationDistanceMap
,
customerCodeServiceTimeMap
);
// 创建求解器配置
// 创建求解器配置
// 创建 SolverConfig 对象,并设置求解器配置
// 创建 SolverConfig 对象,并设置求解器配置
SolverConfig
solverConfig
=
new
SolverConfig
();
SolverConfig
solverConfig
=
new
SolverConfig
();
solverConfig
.
setSolutionClass
(
VehicleRouting
Solution
.
class
);
solverConfig
.
setSolutionClass
(
Dispatch
Solution
.
class
);
solverConfig
.
withEntityClassList
(
Arrays
.
asList
(
Technician
.
class
,
Customer
.
class
));
// 这里不能漏掉,否则约束不生效
solverConfig
.
withEntityClassList
(
Arrays
.
asList
(
Technician
.
class
,
Customer
.
class
));
// 这里不能漏掉,否则约束不生效
solverConfig
.
withTerminationSpentLimit
(
Duration
.
ofSeconds
(
60
));
solverConfig
.
withTerminationSpentLimit
(
Duration
.
ofSeconds
(
60
));
...
@@ -82,9 +82,9 @@ public class DispatchServiceImpl implements DispatchService {
...
@@ -82,9 +82,9 @@ public class DispatchServiceImpl implements DispatchService {
solverConfig
.
withConstraintProviderClass
(
DispatchConstraintProvider
.
class
);
solverConfig
.
withConstraintProviderClass
(
DispatchConstraintProvider
.
class
);
// 创建求解器
// 创建求解器
SolverFactory
<
VehicleRouting
Solution
>
solverFactory
=
SolverFactory
.
create
(
solverConfig
);
SolverFactory
<
Dispatch
Solution
>
solverFactory
=
SolverFactory
.
create
(
solverConfig
);
Solver
<
VehicleRouting
Solution
>
solver
=
solverFactory
.
buildSolver
();
Solver
<
Dispatch
Solution
>
solver
=
solverFactory
.
buildSolver
();
VehicleRouting
Solution
solution
=
solver
.
solve
(
problem
);
Dispatch
Solution
solution
=
solver
.
solve
(
problem
);
printSolution
(
solution
,
customerIndexMap
,
technicianIndexMap
);
printSolution
(
solution
,
customerIndexMap
,
technicianIndexMap
);
...
@@ -216,10 +216,10 @@ public class DispatchServiceImpl implements DispatchService {
...
@@ -216,10 +216,10 @@ public class DispatchServiceImpl implements DispatchService {
return
customerIndexMap
;
return
customerIndexMap
;
}
}
private
static
VehicleRouting
Solution
createVehicleRoutingSolution
(
Map
<
Integer
,
String
>
customerIndexMap
,
private
static
Dispatch
Solution
createVehicleRoutingSolution
(
Map
<
Integer
,
String
>
customerIndexMap
,
Map
<
Integer
,
String
>
technicianIndexMap
,
Map
<
String
,
Set
<
String
>>
technicianCodeSkillsMap
,
Map
<
Integer
,
String
>
technicianIndexMap
,
Map
<
String
,
Set
<
String
>>
technicianCodeSkillsMap
,
Map
<
String
,
String
>
customerCodeSkillMap
,
Map
<
String
,
Map
<
String
,
Long
>>
preferredlocationDistanceMap
,
Map
<
String
,
Integer
>
customerCodeServiceTimeMap
)
throws
UncheckedIOException
,
FileNotFoundException
{
Map
<
String
,
String
>
customerCodeSkillMap
,
Map
<
String
,
Map
<
String
,
Long
>>
preferredlocationDistanceMap
,
Map
<
String
,
Integer
>
customerCodeServiceTimeMap
)
throws
UncheckedIOException
,
FileNotFoundException
{
VehicleRoutingSolution
vehicleRoutingSolution
=
new
VehicleRouting
Solution
();
DispatchSolution
vehicleRoutingSolution
=
new
Dispatch
Solution
();
// 翻转map
// 翻转map
Map
<
String
,
Integer
>
customerIndexMap2
=
customerIndexMap
.
entrySet
().
stream
()
Map
<
String
,
Integer
>
customerIndexMap2
=
customerIndexMap
.
entrySet
().
stream
()
...
@@ -308,7 +308,7 @@ public class DispatchServiceImpl implements DispatchService {
...
@@ -308,7 +308,7 @@ public class DispatchServiceImpl implements DispatchService {
return
vehicleRoutingSolution
;
return
vehicleRoutingSolution
;
}
}
static
void
printSolution
(
VehicleRouting
Solution
solution
,
Map
<
Integer
,
String
>
customerIndexMap
,
static
void
printSolution
(
Dispatch
Solution
solution
,
Map
<
Integer
,
String
>
customerIndexMap
,
Map
<
Integer
,
String
>
technicianIndexMap
)
{
Map
<
Integer
,
String
>
technicianIndexMap
)
{
System
.
out
.
println
(
"技能约束:"
);
System
.
out
.
println
(
"技能约束:"
);
solution
.
getTechnicianList
().
forEach
(
technician
->
{
solution
.
getTechnicianList
().
forEach
(
technician
->
{
...
...
project-dispatch/src/main/java/com/dituhui/pea/dispatch/shadowVariable/ArrivalTimeUpdatingVariableListener.java
View file @
05cfb64
...
@@ -6,41 +6,41 @@ import org.optaplanner.core.api.domain.variable.VariableListener;
...
@@ -6,41 +6,41 @@ import org.optaplanner.core.api.domain.variable.VariableListener;
import
org.optaplanner.core.api.score.director.ScoreDirector
;
import
org.optaplanner.core.api.score.director.ScoreDirector
;
import
com.dituhui.pea.dispatch.pojo.Customer
;
import
com.dituhui.pea.dispatch.pojo.Customer
;
import
com.dituhui.pea.dispatch.pojo.
VehicleRouting
Solution
;
import
com.dituhui.pea.dispatch.pojo.
Dispatch
Solution
;
public
class
ArrivalTimeUpdatingVariableListener
implements
VariableListener
<
VehicleRouting
Solution
,
Customer
>
{
public
class
ArrivalTimeUpdatingVariableListener
implements
VariableListener
<
Dispatch
Solution
,
Customer
>
{
@Override
@Override
public
void
beforeEntityAdded
(
ScoreDirector
<
VehicleRouting
Solution
>
scoreDirector
,
Customer
customer
)
{
public
void
beforeEntityAdded
(
ScoreDirector
<
Dispatch
Solution
>
scoreDirector
,
Customer
customer
)
{
// Do nothing
// Do nothing
}
}
@Override
@Override
public
void
afterEntityAdded
(
ScoreDirector
<
VehicleRouting
Solution
>
scoreDirector
,
Customer
customer
)
{
public
void
afterEntityAdded
(
ScoreDirector
<
Dispatch
Solution
>
scoreDirector
,
Customer
customer
)
{
updateArrivalTime
(
scoreDirector
,
customer
);
updateArrivalTime
(
scoreDirector
,
customer
);
}
}
@Override
@Override
public
void
beforeVariableChanged
(
ScoreDirector
<
VehicleRouting
Solution
>
scoreDirector
,
Customer
customer
)
{
public
void
beforeVariableChanged
(
ScoreDirector
<
Dispatch
Solution
>
scoreDirector
,
Customer
customer
)
{
// Do nothing
// Do nothing
}
}
@Override
@Override
public
void
afterVariableChanged
(
ScoreDirector
<
VehicleRouting
Solution
>
scoreDirector
,
Customer
customer
)
{
public
void
afterVariableChanged
(
ScoreDirector
<
Dispatch
Solution
>
scoreDirector
,
Customer
customer
)
{
updateArrivalTime
(
scoreDirector
,
customer
);
updateArrivalTime
(
scoreDirector
,
customer
);
}
}
@Override
@Override
public
void
beforeEntityRemoved
(
ScoreDirector
<
VehicleRouting
Solution
>
scoreDirector
,
Customer
customer
)
{
public
void
beforeEntityRemoved
(
ScoreDirector
<
Dispatch
Solution
>
scoreDirector
,
Customer
customer
)
{
// Do nothing
// Do nothing
}
}
@Override
@Override
public
void
afterEntityRemoved
(
ScoreDirector
<
VehicleRouting
Solution
>
scoreDirector
,
Customer
customer
)
{
public
void
afterEntityRemoved
(
ScoreDirector
<
Dispatch
Solution
>
scoreDirector
,
Customer
customer
)
{
updateArrivalTime
(
scoreDirector
,
customer
);
updateArrivalTime
(
scoreDirector
,
customer
);
}
}
protected
void
updateArrivalTime
(
ScoreDirector
<
VehicleRouting
Solution
>
scoreDirector
,
Customer
sourceCustomer
)
{
protected
void
updateArrivalTime
(
ScoreDirector
<
Dispatch
Solution
>
scoreDirector
,
Customer
sourceCustomer
)
{
if
(
sourceCustomer
.
getTechnician
()
==
null
)
{
if
(
sourceCustomer
.
getTechnician
()
==
null
)
{
if
(
sourceCustomer
.
getArrivalTime
()
!=
null
)
{
if
(
sourceCustomer
.
getArrivalTime
()
!=
null
)
{
...
...
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