2
2
3
3
import BasicMAPF .CostFunctions .I_SolutionCostFunction ;
4
4
import BasicMAPF .CostFunctions .SumOfCosts ;
5
+ import BasicMAPF .CostFunctions .SumServiceTimes ;
5
6
import BasicMAPF .DataTypesAndStructures .*;
6
7
import BasicMAPF .Instances .Agent ;
7
8
import BasicMAPF .Instances .MAPF_Instance ;
8
9
import BasicMAPF .Instances .Maps .Coordinates .I_Coordinate ;
10
+ import BasicMAPF .Solvers .AStar .CostsAndHeuristics .CachingDistanceTableHeuristic ;
9
11
import BasicMAPF .Solvers .AStar .CostsAndHeuristics .ServiceTimeGAndH ;
10
12
import BasicMAPF .Solvers .AStar .GoalConditions .VisitedTargetAStarGoalCondition ;
11
13
import BasicMAPF .Solvers .AStar .GoalConditions .VisitedTargetAndBlacklistAStarGoalCondition ;
24
26
import BasicMAPF .Solvers .AStar .RunParameters_SAAStar ;
25
27
import BasicMAPF .Solvers .AStar .SingleAgentAStar_Solver ;
26
28
import BasicMAPF .Solvers .ConstraintsAndConflicts .*;
27
- import TransientMAPF .TransientMAPFBehaviour ;
29
+ import TransientMAPF .TransientMAPFSettings ;
28
30
import TransientMAPF .TransientMAPFSolution ;
29
31
30
32
import java .util .*;
@@ -100,7 +102,7 @@ public class CBS_Solver extends A_Solver {
100
102
*/
101
103
private final boolean sharedSources ;
102
104
103
- private final TransientMAPFBehaviour transientMAPFBehaviour ;
105
+ private final TransientMAPFSettings transientMAPFSettings ;
104
106
105
107
/* = Constructors = */
106
108
@@ -112,11 +114,11 @@ public class CBS_Solver extends A_Solver {
112
114
* @param openListManagementMode @see {@link OpenListManagementMode}. @Nullable
113
115
* @param costFunction a cost function for solutions. @Nullable
114
116
* @param cbsNodeComparator determines how to sort {@link #openList OPEN}. @Nullable
115
- * @param useCorridorReasoning whether or not to use corridor reasoning.
117
+ * @param useCorridorReasoning whether to use corridor reasoning.
116
118
*/
117
119
public CBS_Solver (I_Solver lowLevelSolver , I_OpenList <CBS_Node > openList , OpenListManagementMode openListManagementMode ,
118
120
I_SolutionCostFunction costFunction , Comparator <? super CBS_Node > cbsNodeComparator , Boolean useCorridorReasoning ,
119
- Boolean sharedGoals , Boolean sharedSources , TransientMAPFBehaviour transientMAPFBehaviour ) {
121
+ Boolean sharedGoals , Boolean sharedSources , TransientMAPFSettings transientMAPFSettings ) {
120
122
this .lowLevelSolver = Objects .requireNonNullElseGet (lowLevelSolver , SingleAgentAStar_Solver ::new );
121
123
this .openList = Objects .requireNonNullElseGet (openList , OpenListHeap ::new );
122
124
this .openListManagementMode = openListManagementMode != null ? openListManagementMode : OpenListManagementMode .AUTOMATIC ;
@@ -127,9 +129,9 @@ public CBS_Solver(I_Solver lowLevelSolver, I_OpenList<CBS_Node> openList, OpenLi
127
129
this .CBSNodeComparator = cbsNodeComparator != null ? cbsNodeComparator : new CBSNodeComparatorForcedTotalOrdering ();
128
130
this .sharedGoals = Objects .requireNonNullElse (sharedGoals , false );
129
131
this .sharedSources = Objects .requireNonNullElse (sharedSources , false );
130
- this .transientMAPFBehaviour = Objects .requireNonNullElse (transientMAPFBehaviour , TransientMAPFBehaviour . regularMAPF );
132
+ this .transientMAPFSettings = Objects .requireNonNullElse (transientMAPFSettings , TransientMAPFSettings . defaultRegularMAPF );
131
133
132
- super .name = "CBS" + (this .transientMAPFBehaviour .isTransientMAPF () ? "t" : "" );
134
+ super .name = "CBS" + (this .transientMAPFSettings .isTransientMAPF () ? "t" : "" );
133
135
}
134
136
135
137
/**
@@ -149,12 +151,22 @@ protected void init(MAPF_Instance instance, RunParameters runParameters) {
149
151
this .generatedNodes = 0 ;
150
152
this .expandedNodes = 0 ;
151
153
this .instance = instance ;
152
- this .singleAgentGAndH = runParameters .singleAgentGAndH != null ? runParameters .singleAgentGAndH :
153
- this .lowLevelSolver instanceof SingleAgentAStar_Solver ?
154
- this .transientMAPFBehaviour == TransientMAPFBehaviour .transientMAPFsstWithBlacklist ?
155
- new ServiceTimeGAndH (new DistanceTableSingleAgentHeuristic (new ArrayList <>(this .instance .agents ), this .instance .map )) :
156
- new DistanceTableSingleAgentHeuristic (new ArrayList <>(this .instance .agents ), this .instance .map ) :
157
- null ;
154
+
155
+ // heuristic
156
+ if (runParameters .singleAgentGAndH != null ){
157
+ this .singleAgentGAndH = runParameters .singleAgentGAndH ;
158
+ }
159
+ else {
160
+ if (this .lowLevelSolver instanceof SingleAgentAStar_Solver ){
161
+ this .singleAgentGAndH = new DistanceTableSingleAgentHeuristic (new ArrayList <>(instance .agents ), instance .map );
162
+ }
163
+ if (this .singleAgentGAndH instanceof CachingDistanceTableHeuristic ){
164
+ ((CachingDistanceTableHeuristic )this .singleAgentGAndH ).setCurrentMap (instance .map );
165
+ }
166
+ if (this .singleAgentGAndH != null && this .costFunction instanceof SumServiceTimes ){
167
+ this .singleAgentGAndH = new ServiceTimeGAndH (this .singleAgentGAndH );
168
+ }
169
+ }
158
170
}
159
171
160
172
/* = algorithm = */
@@ -189,7 +201,7 @@ private void initOpen(I_ConstraintSet initialConstraints) {
189
201
*/
190
202
private CBS_Node generateRoot (I_ConstraintSet initialConstraints ) {
191
203
// init an empty solution
192
- Solution solution = transientMAPFBehaviour .isTransientMAPF () ? new TransientMAPFSolution () : new Solution ();
204
+ Solution solution = transientMAPFSettings .isTransientMAPF () ? new TransientMAPFSolution () : new Solution ();
193
205
// for every agent, add its plan to the solution
194
206
for (Agent agent :
195
207
this .instance .agents ) {
@@ -292,7 +304,7 @@ private CBS_Node generateNode(CBS_Node parent, Constraint constraint, boolean co
292
304
293
305
// replace with copies if required
294
306
if (copyDatastructures ) {
295
- solution = transientMAPFBehaviour .isTransientMAPF () ? new TransientMAPFSolution (solution ) : new Solution (solution );
307
+ solution = transientMAPFSettings .isTransientMAPF () ? new TransientMAPFSolution (solution ) : new Solution (solution );
296
308
}
297
309
298
310
// modify for this node
@@ -367,16 +379,19 @@ private RunParameters getSubproblemParameters(Solution currentSolution, I_Constr
367
379
RunParameters_SAAStar astarSubproblemParameters = new RunParameters_SAAStar (subproblemParametes );
368
380
369
381
// TMAPF goal condition
370
- if (transientMAPFBehaviour == TransientMAPFBehaviour . transientMAPF || transientMAPFBehaviour == TransientMAPFBehaviour . transientMAPFsstWithBlacklist ){
371
- astarSubproblemParameters . goalCondition = new VisitedTargetAStarGoalCondition ();
372
- } else if ( transientMAPFBehaviour == TransientMAPFBehaviour . transientMAPFWithBlacklist ) {
373
- Set < I_Coordinate > targetsOfAgentsThatHaventPlannedYet = new HashSet <>();
374
- for ( Agent agentToBlack : this . instance . agents ) {
375
- if (! agent . equals (agentToBlack )){
376
- targetsOfAgentsThatHaventPlannedYet . add ( agentToBlack . target );
382
+ if (transientMAPFSettings . isTransientMAPF () ){
383
+ if ( transientMAPFSettings . useBlacklist ()) {
384
+ Set < I_Coordinate > targetsOfAgentsThatHaventPlannedYet = new HashSet <>();
385
+ for ( Agent agentToBlack : this . instance . agents ) {
386
+ if (! agent . equals ( agentToBlack ) ) {
387
+ targetsOfAgentsThatHaventPlannedYet . add (agentToBlack . target );
388
+ }
377
389
}
390
+ astarSubproblemParameters .goalCondition = new VisitedTargetAndBlacklistAStarGoalCondition (targetsOfAgentsThatHaventPlannedYet );
391
+ }
392
+ else {
393
+ astarSubproblemParameters .goalCondition = new VisitedTargetAStarGoalCondition ();
378
394
}
379
- astarSubproblemParameters .goalCondition = new VisitedTargetAndBlacklistAStarGoalCondition (targetsOfAgentsThatHaventPlannedYet );
380
395
}
381
396
382
397
SingleUseConflictAvoidanceTable cat = new SingleUseConflictAvoidanceTable (currentSolution , agent );
0 commit comments