-
Notifications
You must be signed in to change notification settings - Fork 16
/
Run.cs
1168 lines (1037 loc) · 59.5 KB
/
Run.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
namespace mapf;
/// <summary>
/// This class is responsible for running the experiments.
/// </summary>
public class Run : IDisposable
{
////////debug
// public static TextWriter resultsWriterdd;
/////////////
/// <summary>
/// Delimiter character used when writing the results of the runs to the output file.
/// </summary>
public static readonly string RESULTS_DELIMITER = ",";
public enum CsvSolutionCodes
{
SUCCESS = 1,
FAILURE = 0
};
/// <summary>
/// Number of random steps performed when generating a new problem instance for choosing a start-goal pair.
/// </summary>
public static int RANDOM_WALK_STEPS = 100000;
/// <summary>
/// Indicates the starting time in ms for timing the different algorithms.
/// </summary>
public double startTime;
/// <summary>
/// This holds an open stream to the results file.
/// </summary>
private TextWriter resultsWriter;
/// <summary>
/// EH: I introduced this variable so that debugging and experiments
/// can have deterministic results.
/// </summary>
static public Random rand = new Random();
/// <summary>
/// Calls resultsWriter.Dispose()
/// </summary>
protected virtual void Dispose(bool dispose_managed)
{
if (dispose_managed)
{
if (this.resultsWriter != null)
{
this.resultsWriter.Close();
this.resultsWriter.Dispose();
this.resultsWriter = null;
}
}
}
public void Dispose() {
this.Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Open the results file for output. Currently the file is opened in append mode.
/// </summary>
/// <param name="fileName">The name of the results file</param>
public void OpenResultsFile(string fileName)
{
this.resultsWriter = new StreamWriter(fileName, true); // 2nd argument indicates the "append" mode
}
/// <summary>
/// Closes the results file.
/// </summary>
public void CloseResultsFile()
{
this.resultsWriter.Close();
}
/// <summary>
/// All types of algorithms to be run
/// </summary>
List<ISolver> solvers;
/// <summary>
/// All types of A* heuristics used
/// </summary>
public List<IHeuristicCalculator<WorldState>> astar_heuristics; // FIXME: Make unpublic again later
/// <summary>
/// Counts the number of times each algorithm went out of time consecutively
/// </summary>
public int[] outOfTimeCounters;
/// <summary>
/// Construct with chosen algorithms.
/// </summary>
public Run()
{
this.watch = Stopwatch.StartNew();
// Preparing the heuristics:
astar_heuristics = new List<IHeuristicCalculator<WorldState>>();
IHeuristicCalculator<WorldState> simple = null;
if (Constants.costFunction == Constants.CostFunction.SUM_OF_COSTS)
{
simple = new SumIndividualCosts();
}
else if (Constants.costFunction == Constants.CostFunction.MAKESPAN ||
Constants.costFunction == Constants.CostFunction.MAKESPAN_THEN_SUM_OF_COSTS)
{
simple = new MaxIndividualCosts();
}
astar_heuristics.Add(simple);
var cbs_heuristics = new List<IHeuristicCalculator<CbsNode>>();
var mvc = new MvcHeuristicForCbs();
cbs_heuristics.Add(mvc);
var mddPruning = new MddPruningHeuristicForCbs();
cbs_heuristics.Add(mddPruning);
var astar = new A_Star(simple);
var cbs = new CBS(astar, astar, -1);
var astar_with_od = new A_Star_WithOD(simple);
var epea = new EPEA_Star(simple);
//var macbsLocal5Epea = new CBS(astar, epea, 5);
//var macbsLocal50Epea = new CBS(astar, epea, 50);
//var cbsHeuristicNoSolve1 = new CbsHeuristicForAStar(cbs, this, false, 1);
//var cbsHeuristicNoSolve2 = new CbsHeuristicForAStar(cbs, this, false, 2);
//var cbsHeuristicNoSolve3 = new CbsHeuristicForAStar(cbs, this, false, 3);
//var cbsHeuristicNoSolve4 = new CbsHeuristicForAStar(cbs, this, false, 4);
//var cbsHeuristicNoSolve5 = new CbsHeuristicForAStar(cbs, this, false, 5);
//var cbsHeuristicNoSolve6 = new CbsHeuristicForAStar(cbs, this, false, 6);
//var cbsHeuristicSolve1 = new CbsHeuristicForAStar(cbs, this, true, 1);
//var cbsHeuristicSolve2 = new CbsHeuristicForAStar(cbs, this, true, 2);
//var cbsHeuristicSolve3 = new CbsHeuristicForAStar(cbs, this, true, 3);
//var cbsHeuristicSolve4 = new CbsHeuristicForAStar(cbs, this, true, 4);
//var cbsHeuristicSolve5 = new CbsHeuristicForAStar(cbs, this, true, 5);
//var cbsHeuristicSolve6 = new CbsHeuristicForAStar(cbs, this, true, 6);
//var sicOrCbsh6 = new RandomChoiceOfHeuristic(cbsHeuristicSolve6, simple, 1.0 / 5);
//var dynamicLazyCbsh = new DynamicLazyCbsh(cbs, this, true);
//heuristics.Add(dynamicLazyCbsh);
//var dynamicLazyMacbsLocal5EpeaH = new DynamicLazyCbsh(macbsLocal5Epea, this, true);
//heuristics.Add(dynamicLazyMacbsLocal5EpeaH);
//var dynamicLazyMacbsLocal50EpeaH = new DynamicLazyCbsh(macbsLocal50Epea, this, true);
//heuristics.Add(dynamicLazyMacbsLocal50EpeaH);
//var dynamicLazyMacbsLocal5EpeaHForOracleMustBeLast = new DynamicLazyCbsh(macbsLocal5Epea, this, true);
//heuristics.Add(dynamicLazyMacbsLocal5EpeaHForOracleMustBeLast);
// Preparing the solvers:
solvers = new List<ISolver>();
solvers.Add(new IndependenceDetection(astar, epea, IndependenceDetection.ConflictChoice.FIRST, true, ConflictAvoidanceTable.AvoidanceGoal.MINIMIZE_CONFLICTS)); // EPEA* + ID
solvers.Add(new IndependenceDetection(astar, epea, IndependenceDetection.ConflictChoice.SMALLEST_RESULTING_GROUP, true, ConflictAvoidanceTable.AvoidanceGoal.MINIMIZE_LARGEST_CONFLICTING_GROUP_THEN_NUMBER_OF_SUCH_GROUPS)); // EPEA* + ID
solvers.Add(new IndependenceDetection(astar, epea, IndependenceDetection.ConflictChoice.LARGEST_RESULTING_GROUP, true, ConflictAvoidanceTable.AvoidanceGoal.MINIMIZE_CONFLICTS)); // EPEA* + ID
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea)); // CBS/EPEA*
//solvers.Add(new MACBS_WholeTreeThreshold(
// astar, epea, bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD)); // CBS/EPEA* with first-fit adoption 1 expansions max
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// lookaheadMaxExpansions: 256)); // CBS/EPEA* with first-fit adoption 256 expansions max
//solvers.Add(new MACBS_WholeTreeThreshold(
// astar, epea, bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// lookaheadMaxExpansions: int.MaxValue)); // CBS/EPEA* with first-fit adoption infinity expansions max
// B is actually set according to the map in a hack elsewhere
//IJCAI:
//soldier: solvers.Add(new CBS(
// astar, epea conflictChoice: CBS.ConflictChoice.MOST_CONFLICTING)); // CBS/EPEA* + choosing most conflicting agent's conflict
//solvers.Add(new IndependenceDetection(singleAgentSolver: astar,
// new MACBS_WholeTreeThreshold(
// singleAgentSolver: astar, generalSolver: epea,
// conflictChoice: CBS.ConflictChoice.MOST_CONFLICTING), simple)); // CBS/EPEA* + choosing most conflicting agent's conflict + ID
//soldier: solvers.Add(new CBS(astar, epea,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD)); // CBS/EPEA* Cardinal using MDDs
//solvers.Add(new CBS(astar, epea,
// conflictChoice: CBS.ConflictChoice.CARDINAL_LOOKAHEAD)); // CBS/EPEA* Cardinal not using MDDs
//soldier:
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 2)); // MA-CBS(2)/EPEA*
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 4)); // MA-CBS(4)/EPEA*
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 8)); // MA-CBS(8)/EPEA*
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 16)); // MA-CBS(16)/EPEA*
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 32)); // MA-CBS(32)/EPEA*
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 64)); // MA-CBS(64)/EPEA*
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 50)); // MA-CBS(50)/EPEA*
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 128)); // MA-CBS(128)/EPEA*
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 256)); // MA-CBS(256)/EPEA*
//solvers.Add(new IndependenceDetection(astar,
// new MACBS_WholeTreeThreshold(astar, epea, 5), simple)); // MA-CBS(5)/EPEA* + ID.
//solvers.Add(new IndependenceDetection(astar,
// new MACBS_WholeTreeThreshold(astar, epea, 10), simple)); // MA-CBS(10)/EPEA* + ID.
//solvers.Add(new IndependenceDetection(astar,
// new MACBS_WholeTreeThreshold(astar, epea, 25), simple)); // MA-CBS(25)/EPEA* + ID.
//solvers.Add(new IndependenceDetection(astar,
// new MACBS_WholeTreeThreshold(astar, epea, 100), simple)); // MA-CBS(100)/EPEA* + ID.
//solvers.Add(new IndependenceDetection(astar,
// new MACBS_WholeTreeThreshold(astar, epea, 150), simple)); // MA-CBS(150)/EPEA* + ID.
//solvers.Add(new IndependenceDetection(astar,
// new MACBS_WholeTreeThreshold(astar, epea, 200), simple)); // MA-CBS(200)/EPEA* + ID.
//solvers.Add(new IndependenceDetection(astar,
// new MACBS_WholeTreeThreshold(astar, epea, 300), simple)); // MA-CBS(300)/EPEA* + ID.
//solvers.Add(new IndependenceDetection(astar,
// new MACBS_WholeTreeThreshold(astar, epea, 500), simple)); // MA-CBS(500)/EPEA* + ID.
//solvers.Add(new IndependenceDetection(astar,
// new MACBS_WholeTreeThreshold(astar, epea, 5, mergeCausesRestart: true),
// simple)); // MA-CBS(5)/EPEA* + ID + restart
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 5,
// conflictChoice: CBS.ConflictChoice.MOST_CONFLICTING)); // MA-CBS(5)/EPEA* + choosing most conflicting agent's conflict
//solvers.Add(new CBS(astar, epea, 5,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD)); // MA-CBS(5)/EPEA* Cardinal using MDDs
//solvers.Add(new CBS(astar, epea, 5,
// conflictChoice: CBS.ConflictChoice.CARDINAL_LOOKAHEAD)); // MA-CBS(5)/EPEA* Cardinal not using MDDs
//soldier: solvers.Add(new CBS(astar, epea, 5, mergeCausesRestart: true)); // MA-CBS(5)/EPEA* + restart
//solvers.Add(new CBS(astar, epea, 64, mergeCausesRestart: true)); // MA-CBS(64)/EPEA* + restart
//soldier: solvers.Add(new CBS(astar, epea,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD)); // CBS/EPEA* + BP1
//soldier:solvers.Add(new MACBS_WholeTreeThreshold(astar, epea,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD)); // CBS/EPEA* + CARDINAL + BP1
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD)); // CBS + CARDINAL (lookahead) + BP1
//solvers.Add(new IndependenceDetection(astar, new MACBS_WholeTreeThreshold(astar, epea,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD), simple)); // CBS + CARDINAL + BP1 + ID
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_LOOKAHEAD)); // CBS/EPEA* Cardinal not using MDDs + BP1
//solvers.Add(new IndependenceDetection(astar, new MACBS_WholeTreeThreshold(
// astar, epea, 5, false, CBS.BypassStrategy.NONE, false,
// CBS.ConflictChoice.FIRST, false, false, int.MaxValue, true),
// simple)); // MA-CBS(B)/EPEA* + ID + restart
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 5, false, CBS.BypassStrategy.NONE, false,
// CBS.ConflictChoice.MOST_CONFLICTING, false, false, int.MaxValue, false)); // MA-CBS(5)/EPEA*
//solvers.Add(new CBS(astar, epea, 5, false, CBS.BypassStrategy.NONE, false,
// CBS.ConflictChoice.CARDINAL_MDD, false, false)); // MA-CBS(5)/EPEA* Cardinal using MDDs
//solvers.Add(new CBS(astar, epea, 5, false, CBS.BypassStrategy.NONE, false,
// CBS.ConflictChoice.CARDINAL_LOOKAHEAD, false, false)); // MA-CBS(5)/EPEA* Cardinal not using MDDs
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea)); // CBS/EPEA*
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD)); // CBS/EPEA* + first cardinal
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD,
// hValueStrategy: CBS.HValueStrategy.GREEDY)); // CBS/EPEA* + greedy h + cardinal
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD, heuristic: mvc)); // CBS/EPEA* + h + cardinal without BP
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 2,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD, mergeCausesRestart: true)); // MA-CBS(2)/EPEA* + cardinal + BP1 + restart
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 4,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD, mergeCausesRestart: true)); // MA-CBS(4)/EPEA* + cardinal + BP1 + restart
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 5,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD, mergeCausesRestart: true)); // MA-CBS(5)/EPEA* + cardinal + BP1 + restart
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 8,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD, mergeCausesRestart: true)); // MA-CBS(8)/EPEA* + cardinal + BP1 + restart
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 16,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD, mergeCausesRestart: true)); // MA-CBS(16)/EPEA* + cardinal + BP1 + restart
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 25,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD, mergeCausesRestart: true)); // MA-CBS(25)/EPEA* + cardinal + BP1 + restart, AKA ICBS(25)
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 32,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD, mergeCausesRestart: true)); // MA-CBS(32)/EPEA* + cardinal + BP1 + restart
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 50,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD, mergeCausesRestart: true)); // MA-CBS(50)/EPEA* + cardinal + BP1 + restart
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 64,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD, mergeCausesRestart: true)); // MA-CBS(64)/EPEA* + cardinal + BP1 + restart
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 128,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD, mergeCausesRestart: true)); // MA-CBS(128)/EPEA* + cardinal + BP1 + restart
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 256,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD, mergeCausesRestart: true)); // MA-CBS(256)/EPEA* + cardinal + BP1 + restart
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 512,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD, mergeCausesRestart: true)); // MA-CBS(512)/EPEA* + cardinal + BP1 + restart
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 1024,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD, mergeCausesRestart: true)); // MA-CBS(1024)/EPEA* + cardinal + BP1 + restart
//solvers.Add(new IndependenceDetection(astar, new MACBS_WholeTreeThreshold(astar, epea, 5
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD, mergeCausesRestart: true), simple)); // MA-CBS(5)/EPEA* + cardinal + BP1 + restart + ID
//solvers.Add(new IndependenceDetection(astar, new MACBS_WholeTreeThreshold(astar, epea, 10,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD, mergeCausesRestart: true), simple)); // MA-CBS(10)/EPEA* + cardinal + BP1 + restart + ID
//solvers.Add(new IndependenceDetection(astar, new MACBS_WholeTreeThreshold(astar, epea, 25,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD, mergeCausesRestart: true), simple)); // MA-CBS(25)/EPEA* + cardinal + BP1 + restart + ID
//solvers.Add(new IndependenceDetection(astar, new MACBS_WholeTreeThreshold(astar, epea, 100,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD, mergeCausesRestart: true), simple)); // MA-CBS(100)/EPEA* + cardinal + BP1 + restart + ID
//solvers.Add(new IndependenceDetection(astar, new MACBS_WholeTreeThreshold(astar, epea, 150,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD, mergeCausesRestart: true), simple)); // MA-CBS(100)/EPEA* + cardinal + BP1 + restart + ID
//solvers.Add(new IndependenceDetection(astar, new MACBS_WholeTreeThreshold(astar, epea, 200,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD, mergeCausesRestart: true), simple)); // MA-CBS(100)/EPEA* + cardinal + BP1 + restart + ID
//solvers.Add(new IndependenceDetection(astar, new MACBS_WholeTreeThreshold(astar, epea, 300,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD, mergeCausesRestart: true), simple)); // MA-CBS(100)/EPEA* + cardinal + BP1 + restart + ID
//solvers.Add(new IndependenceDetection(astar, new MACBS_WholeTreeThreshold(astar, epea, 500,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD, mergeCausesRestart: true), simple)); // MA-CBS(500)/EPEA* + cardinal + BP1 + restart + ID
//solvers.Add(new CBS(astar, epea, 5,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// conflictChoice: CBS.ConflictChoice.CARDINAL_MDD, mergeCausesRestart: true)); // MA-CBS(5)/EPEA* Cardinal using MDDs + BP1 + restart
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 5,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// lookaheadMaxExpansions: int.MaxValue)); // MA-CBS(5)/EPEA* with first-fit adoption infinity expansions max
//solvers.Add(new IndependenceDetection(astar, new MACBS_WholeTreeThreshold(astar, epea, 5,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD), simple)); // MA-CBS(5)/EPEA* with first-fit adoption 1 expansions max + ID
//solvers.Add(new MACBS_WholeTreeThreshold(astar, epea, 5,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// lookaheadMaxExpansions: 256)); // MA-CBS(5)/EPEA* with first-fit adoption 256 expansions max
//solvers.Add(new IndependenceDetection(astar, new MACBS_WholeTreeThreshold(astar, epea, 5,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// lookaheadMaxExpansions: int.MaxValue), simple)); // MA-CBS(5)/EPEA* with first-fit adoption infinity expansions max + ID
//solvers.Add(epea); // EPEA*
//solvers.Add(new CostTreeSearchSolverOldMatching(3)); // ICTS
//solvers.Add(new IndependenceDetection(astar, epea, simple)); // EPEA* + ID
//solvers.Add(new IndependenceDetection(astar, new CostTreeSearchSolverOldMatching(3), simple)); // ICTS + ID
/*
solvers.Add(new CBS(astar, epea, 5)); // MACBS(5)/EPEA* - Works and is very fast so is a good choice for cost validation
solvers.Add(new CBS(astar, epea, 5,
bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
lookaheadMaxExpansions: 1)); // MACBS(5)/EPEA* + adoption immediately
solvers.Add(new CBS(astar, epea, 5,
bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
lookaheadMaxExpansions: int.MaxValue)); // MACBS(5)/EPEA* + adoption immediately infinite expansions
solvers.Add(new CBS(astar, epea, 5,
bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
lookaheadMaxExpansions: 2)); // MACBS(5)/EPEA* + adoption immediately 2 expansions
solvers.Add(new CBS(astar, epea, 5,
bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
lookaheadMaxExpansions: 4)); // MACBS(5)/EPEA* + adoption immediately 4 expansions
solvers.Add(new CBS(astar, epea, 5,
bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
lookaheadMaxExpansions: 8)); // MACBS(5)/EPEA* + adoption immediately 8 expansions
solvers.Add(new CBS(astar, epea, 5,
bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
lookaheadMaxExpansions: 16)); // MACBS(5)/EPEA* + adoption immediately 16 expansions
solvers.Add(new CBS(astar, epea, 5,
bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
lookaheadMaxExpansions: 32)); // MACBS(5)/EPEA* + adoption immediately 32 expansions
solvers.Add(new CBS(astar, epea, 5,
bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
lookaheadMaxExpansions: 64)); // MACBS(5)/EPEA* + adoption immediately 64 expansions
solvers.Add(new CBS(astar, epea, 5,
bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
lookaheadMaxExpansions: 128)); // MACBS(5)/EPEA* + adoption immediately 128 expansions
solvers.Add(new CBS(astar, epea, 5,
bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
lookaheadMaxExpansions: 256)); // MACBS(5)/EPEA* + adoption immediately 256 expansions
*/
//solvers.Add(new CBS(astar, epea, doShuffle: true)); // CBS + shuffle
//solvers.Add(new CBS(astar, epea,
// bypassStrategy: CBS.BypassStrategy.FIRST_FIT_LOOKAHEAD,
// heuristic: mddPruning)); // CBS + MDD Pruning heuristic + adoption
//solvers.Add(new CBS(astar, epea,
// doShuffle: true,
// useMddHeuristic: true)); // CBS+MDD+shuffle
//solvers.Add(new CBS(astar, epea, 5, justbreakForConflicts: true)); // MA-CBS(5) + Simply tie break for more conflicts
//solvers.Add(new CBS(astar, epea, doMalte: true)); // CBS + Malte
/*
//solvers.Add(new CBS(epea, epea, -1));
//solvers.Add(new MACBS_WholeTreeThreshold(epea, epea, -1)); // Should be identical since no merging is done.
//solvers.Add(new CBS(epea, epea, 0));
solvers.Add(new CBS(astar, epea, 0));
//solvers.Add(new MACBS_WholeTreeThreshold(epea, epea, 0));
//solvers.Add(new CBS(epea, epea, 1));
//solvers.Add(new MACBS_WholeTreeThreshold(epea, epea, 1));
//solvers.Add(new CBS(epea, epea, 5));
solvers.Add(new CBS(astar, epea, 5));
//solvers.Add(new MACBS_WholeTreeThreshold(epea, epea, 5));
//solvers.Add(new CBS(epea, epea, 10));
solvers.Add(new CBS(astar, epea, 10));
//solvers.Add(new MACBS_WholeTreeThreshold(epea, epea, 10));
//solvers.Add(new CBS(epea, epea, 100));
solvers.Add(new CBS(astar, epea, 100));
//solvers.Add(new MACBS_WholeTreeThreshold(epea, epea, 100));
//solvers.Add(new CBS(epea, epea, 500));
//solvers.Add(new MACBS_WholeTreeThreshold(epea, epea, 500));
//solvers.Add(new CBS(astar_with_od, astar_with_od, -1));
//solvers.Add(new MACBS_WholeTreeThreshold(astar_with_od, astar_with_od, -1)); // Should be identical since no merging is done.
//solvers.Add(new CBS(astar_with_od, astar_with_od, 0));
solvers.Add(new CBS(astar, astar_with_od, 0));
//solvers.Add(new MACBS_WholeTreeThreshold(astar_with_od, astar_with_od, 0));
//solvers.Add(new CBS(astar_with_od, astar_with_od, 1));
//solvers.Add(new MACBS_WholeTreeThreshold(astar_with_od, astar_with_od, 1));
//solvers.Add(new CBS(astar_with_od, astar_with_od, 5));
solvers.Add(new CBS(astar, astar_with_od, 5));
//solvers.Add(new MACBS_WholeTreeThreshold(astar_with_od, astar_with_od, 5));
//solvers.Add(new CBS(astar_with_od, astar_with_od, 10));
solvers.Add(new CBS(astar, astar_with_od, 10));
//solvers.Add(new MACBS_WholeTreeThreshold(astar_with_od, astar_with_od, 10));
//solvers.Add(new CBS(astar_with_od, astar_with_od, 100));
solvers.Add(new CBS(astar, astar_with_od, 100));
//solvers.Add(new MACBS_WholeTreeThreshold(astar_with_od, astar_with_od, 100));
//solvers.Add(new CBS(astar_with_od, astar_with_od, 500));
//solvers.Add(new MACBS_WholeTreeThreshold(astar_with_od, astar_with_od, 500));
*/
//solvers.Add(new A_Star(simple, mStar: true)); // rM*! Works
//solvers.Add(new A_Star(simple, mStar: true, mStarShuffle: true)); // rM* shuffle! Works
//solvers.Add(new A_Star(cbsHeuristic)); // A* with cbsHeuristic
//solvers.Add(new A_Star_WithOD(simple)); // A* + OD
//solvers.Add(new A_Star_WithOD(simple, mStar: true)); // rM*+OD!
//solvers.Add(new A_Star_WithOD(simple, mStar: true, mStar: true)); // rM*+OD shuffle!
//solvers.Add(new PEA_Star(simple)); // Works
//solvers.Add(new PEA_Star(cbsHeuristic));
//soldier: solvers.Add(new EPEA_Star(simple)); // Works.
//solvers.Add(new EPEA_Star(simple, true, false)); // EPErM*
//solvers.Add(new EPEA_Star(simple, true, true)); // EPErM* shuffle
//soldier: solvers.Add(new CBS(astar, epea, 0)); // EPEA*+(S)ID
//solvers.Add(new A_Star(cbsHeuristicSolve1));
//solvers.Add(new A_Star(cbsHeuristicSolve2));
//solvers.Add(new A_Star(cbsHeuristicSolve3));
//solvers.Add(new A_Star(cbsHeuristicSolve4));
//solvers.Add(new A_Star(cbsHeuristicSolve5));
//solvers.Add(new A_Star(cbsHeuristicSolve6));
//solvers.Add(new A_Star(cbsHeuristicNoSolve1));
//solvers.Add(new A_Star(cbsHeuristicNoSolve2));
//solvers.Add(new A_Star(cbsHeuristicNoSolve3));
//solvers.Add(new A_Star(cbsHeuristicNoSolve4));
//solvers.Add(new A_Star(cbsHeuristicNoSolve5));
//solvers.Add(new A_Star(cbsHeuristicNoSolve6));
//solvers.Add(new A_Star(sicOrCbsh6));
//solvers.Add(new A_Star_WithOD(cbsHeuristicSolve1));
//solvers.Add(new A_Star_WithOD(cbsHeuristicSolve2));
//solvers.Add(new A_Star_WithOD(cbsHeuristicSolve3));
//solvers.Add(new A_Star_WithOD(cbsHeuristicSolve4));
//solvers.Add(new A_Star_WithOD(cbsHeuristicSolve5));
//solvers.Add(new A_Star_WithOD(cbsHeuristicSolve6));
//solvers.Add(new A_Star_WithOD(cbsHeuristicNoSolve1));
//solvers.Add(new A_Star_WithOD(cbsHeuristicNoSolve2));
//solvers.Add(new A_Star_WithOD(cbsHeuristicNoSolve3));
//solvers.Add(new A_Star_WithOD(cbsHeuristicNoSolve4));
//solvers.Add(new A_Star_WithOD(cbsHeuristicNoSolve5));
//solvers.Add(new A_Star_WithOD(cbsHeuristicNoSolve6));
//solvers.Add(new A_Star_WithOD(sicOrCbsh6));
A_Star solver;
// dynamic not rational lazy A*+OD/CBS/A*/SIC:
//solver = new A_Star_WithOD(simple);
//var dynamicLazyOpenList1 = new DynamicLazyOpenList(solver, dynamicLazyCbsh, this);
//solver.openList = dynamicLazyOpenList1;
//solvers.Add(solver);
// dynamic rational lazy A*+OD/CBS/A*/SIC:
//solver = new A_Star_WithOD(simple);
//var dynamicRationalLazyOpenList1 = new DynamicRationalLazyOpenList(solver, dynamicLazyCbsh, this);
//solver.openList = dynamicRationalLazyOpenList1;
//solvers.Add(solver);
// dynamic rational lazy MA-CBS-local-5/A*+OD/MA-CBS-local-5/EPEA*/SIC:
//solver = new A_Star_WithOD(simple);
//var dynamicRationalLazyOpenList3 = new DynamicRationalLazyOpenList(solver, dynamicLazyMacbsLocal5EpeaH, this);
//solver.openList = dynamicRationalLazyOpenList3;
//solvers.Add(new CBS(astar, solver, 5));
//solvers.Add(new EPEA_Star(cbsHeuristicSolve1));
//solvers.Add(new EPEA_Star(cbsHeuristicSolve2));
//solvers.Add(new EPEA_Star(cbsHeuristicSolve3));
//solvers.Add(new EPEA_Star(cbsHeuristicSolve4));
//solvers.Add(new EPEA_Star(cbsHeuristicSolve5));
//solvers.Add(new EPEA_Star(cbsHeuristicSolve6));
//solvers.Add(new EPEA_Star(cbsHeuristicNoSolve1));
//solvers.Add(new EPEA_Star(cbsHeuristicNoSolve2));
//solvers.Add(new EPEA_Star(cbsHeuristicNoSolve3));
//solvers.Add(new EPEA_Star(cbsHeuristicNoSolve4));
//solvers.Add(new EPEA_Star(cbsHeuristicNoSolve5));
//solvers.Add(new EPEA_Star(cbsHeuristicNoSolve6));
//solvers.Add(new EPEA_Star(sicOrCbsh6));
// dynamic not rational lazy EPEA*/CBS/A*/SIC:
//solver = new EPEA_Star(simple);
//var dynamicLazyOpenList2 = new DynamicLazyOpenList(solver, dynamicLazyCbsh, this);
//solver.openList = dynamicLazyOpenList2;
//solvers.Add(solver);
// dynamic rational lazy EPEA*/CBS/A*/SIC:
//solver = new EPEA_Star(simple);
//var dynamicRationalLazyOpenList2 = new DynamicRationalLazyOpenList(solver, dynamicLazyCbsh, this);
//solver.openList = dynamicRationalLazyOpenList2;
//solvers.Add(solver);
/*
* soldiers:
// MA-CBS-local-5 / dynamic rational lazy EPEA* / MA-CBS-local-50 / EPEA* / SIC:
solver = new EPEA_Star(simple);
var dynamicRationalLazyOpenList4 = new DynamicRationalLazyOpenList(solver, dynamicLazyMacbsLocal50EpeaH, this);
solver.openList = dynamicRationalLazyOpenList4;
solvers.Add(new CBS(astar, solver, 5));
// dynamic rational lazy EPEA* / MA-CBS-local-5 / EPEA* / SIC + (S)ID:
solver = new EPEA_Star(simple);
var dynamicRationalLazyOpenList6 = new DynamicRationalLazyOpenList(solver, dynamicLazyMacbsLocal5EpeaH, this);
solver.openList = dynamicRationalLazyOpenList6;
solvers.Add(new CBS(astar, solver, 0));
*/
/*
//soldier: but can't handle 50 agents
// dynamic rational lazy EPEA* / MA-CBS-local-5 / EPEA* / SIC:
solver = new EPEA_Star(simple);
var dynamicRationalLazyOpenList8 = new DynamicRationalLazyOpenList(solver, dynamicLazyMacbsLocal5EpeaH, this);
solver.openList = dynamicRationalLazyOpenList8;
solvers.Add(solver);
*/
//solvers.Add(new CostTreeSearchSolverNoPruning());
//solvers.Add(new CostTreeSearchSolverKMatch(2));
//solvers.Add(new CostTreeSearchSolverOldMatching(2));
//solvers.Add(new CostTreeSearchSolverRepeatedMatch(2));
//solvers.Add(new CostTreeSearchSolverKMatch(3));
//!@# USE ME solvers.Add(new CostTreeSearchSolverOldMatching(3)); // Use this parameter. Best according to paper. 3RE
//solvers.Add(new CostTreeSearchSolverRepeatedMatch(3));
//solvers.Add(new CostTreeSearchNoPruning());
//solvers.Add(new CostTreeSearchKMatch(2));
//solvers.Add(new CostTreeSearchOldMatching(2));
//solvers.Add(new CostTreeSearchRepeatedMatch(2));
//solvers.Add(new CostTreeSearchKMatch(3));
//solvers.Add(new CostTreeSearchOldMatching(3));
//solvers.Add(new CostTreeSearchRepeatedMatch(3));
//solvers.Add(new IndependenceDetection(new EPEA_Star()));
//solvers.Add(new IndependenceDetection(new MACBS_WholeTreeThreshold(new EPEA_Star(), 1, 1)));
//solvers.Add(new IndependenceDetection(new MACBS_WholeTreeThreshold(new EPEA_Star(), 5, 5)));
//solvers.Add(new IndependenceDetection(new MACBS_WholeTreeThreshold(new EPEA_Star(), 10, 10)));
//solvers.Add(new IndependenceDetection(new MACBS_WholeTreeThreshold(new EPEA_Star(), 100, 100)));
//solvers.Add(new IndependenceDetection(new MACBS_WholeTreeThreshold(new EPEA_Star(), 500, 500)));
//solvers.Add(new IndependenceDetection(new MACBS_WholeTreeThreshold(new A_Star())));
//solvers.Add(new IndependenceDetection(new MACBS_WholeTreeThreshold(new A_Star(), 1, 1)));
//solvers.Add(new IndependenceDetection(new MACBS_WholeTreeThreshold(new A_Star(), 5, 5)));
//solvers.Add(new IndependenceDetection(new MACBS_WholeTreeThreshold(new A_Star(), 10, 10)));
//solvers.Add(new IndependenceDetection(new MACBS_WholeTreeThreshold(new A_Star(), 100, 100)));
//solvers.Add(new IndependenceDetection(new MACBS_WholeTreeThreshold(new A_Star(), 500, 500)));
//solvers.Add(new IndependenceDetection(new PEA_Star()));
//solvers.Add(new IndependenceDetection(new EPEA_Star()));
//solvers.Add(new IndependenceDetection(new A_Star()));
//solvers.Add(new IndependenceDetection());
//solvers.Add(new CBS_IDA(new A_Star())); // Don't run! Uses must conds
//solvers.Add(new MACBS_WholeTreeThreshold(new A_Star())); // Works
//solvers.Add(new CBS_NoDD(new A_Star()));
//solvers.Add(new CBS_NoDDb3(new A_Star()));
//solvers.Add(new MACBS_WholeTreeThreshold(new A_Star(), 1, 1)); // Run this!
outOfTimeCounters = new int[solvers.Count];
for (int i = 0; i < outOfTimeCounters.Length; i++)
{
outOfTimeCounters[i] = 0;
}
}
/// <summary>
/// Generates a problem instance, including a board, start and goal locations of desired number of agents
/// and desired precentage of obstacles
/// TODO: Refactor to use operators.
/// </summary>
/// <param name="gridSize"></param>
/// <param name="agentsNum"></param>
/// <param name="obstaclesNum"></param>
/// <returns></returns>
public ProblemInstance GenerateProblemInstance(int gridSize, int agentsNum, int obstaclesNum)
{
// Randomization based on timer is disabled for purposes of getting
// reproducible experiments.
//Random rand = new Random();
Debug.WriteLine($"Generating instance with {agentsNum} agents, {obstaclesNum} obstacles of size {gridSize}");
if (agentsNum + obstaclesNum + 1 > gridSize * gridSize)
throw new Exception($"Not enough room for {agentsNum}, {obstaclesNum} and one empty space in a {gridSize}x{gridSize} map.");
int x;
int y;
Agent[] aGoals = new Agent[agentsNum];
AgentState[] aStart = new AgentState[agentsNum];
bool[][] grid = new bool[gridSize][];
bool[][] goals = new bool[gridSize][];
// Generate a random grid
for (int i = 0; i < gridSize; i++)
{
grid[i] = new bool[gridSize];
goals[i] = new bool[gridSize];
}
for (int i = 0; i < obstaclesNum; i++)
{
x = rand.Next(gridSize);
y = rand.Next(gridSize);
if (grid[x][y]) // Already an obstacle
i--;
grid[x][y] = true;
}
// Choose random goal locations
for (int i = 0; i < agentsNum; i++)
{
x = rand.Next(gridSize);
y = rand.Next(gridSize);
if (goals[x][y] || grid[x][y])
i--;
else
{
goals[x][y] = true;
aGoals[i] = new Agent(x, y, i);
}
}
// Select random start/goal locations for every agent by performing a random walk
for (int i = 0; i < agentsNum; i++)
{
aStart[i] = new AgentState(aGoals[i].Goal.x, aGoals[i].Goal.y, aGoals[i]);
}
// Initialized here only for the IsValid() call. TODO: Think how this can be sidestepped elegantly.
ProblemInstance problem = new ProblemInstance();
problem.Init(aStart, grid);
for (int j = 0; j < RANDOM_WALK_STEPS; j++)
{
for (int i = 0; i < agentsNum; i++)
{
goals[aStart[i].lastMove.x][aStart[i].lastMove.y] = false; // We're going to move the goal somewhere else
while (true)
{
Move.Direction op = (Move.Direction)rand.Next(0, 5); // TODO: fixme
aStart[i].lastMove.Update(op);
if (problem.IsValid(aStart[i].lastMove) &&
!goals[aStart[i].lastMove.x][aStart[i].lastMove.y]) // this spot isn't another agent's goal
break;
else
aStart[i].lastMove.setOppositeMove(); // Rollback
}
goals[aStart[i].lastMove.x][aStart[i].lastMove.y] = true; // Claim agent's new goal
}
}
// Zero the agents' timesteps
foreach (AgentState agentStart in aStart)
{
agentStart.lastMove.time = 0;
}
// TODO: There is some repetition here of previous instantiation of ProblemInstance. Think how to elegantly bypass this.
problem = new ProblemInstance();
problem.Init(aStart, grid);
return problem;
}
/// <summary>
/// Generates a problem instance based on a DAO map file.
/// TODO: Fix code dup with GenerateProblemInstance and Import later.
/// </summary>
/// <param name="mapFilePath"></param>
/// <param name="agentsNum"></param>
/// <returns></returns>
public ProblemInstance GenerateDragonAgeProblemInstance(string mapFilePath, int agentsNum)
{
Debug.WriteLine($"Generating instance with {agentsNum} agents");
using (TextReader input = new StreamReader(mapFilePath))
{
string[] lineParts;
string line;
line = input.ReadLine();
Trace.Assert(line.StartsWith("type octile"));
// Read grid dimensions
line = input.ReadLine();
lineParts = line.Split(' ');
Trace.Assert(lineParts[0].StartsWith("height"));
int maxX = int.Parse(lineParts[1]);
line = input.ReadLine();
lineParts = line.Split(' ');
Trace.Assert(lineParts[0].StartsWith("width"));
int maxY = int.Parse(lineParts[1]);
line = input.ReadLine();
Trace.Assert(line.StartsWith("map"));
bool[][] grid = new bool[maxX][];
char cell;
for (int i = 0; i < maxX; i++)
{
grid[i] = new bool[maxY];
line = input.ReadLine();
for (int j = 0; j < maxY; j++)
{
cell = line[j];
if (cell == '@' || cell == 'O' || cell == 'T' || cell == 'W' /* Water isn't traversable from land */)
grid[i][j] = true;
else
grid[i][j] = false;
}
}
int x;
int y;
Agent[] agentGoals = new Agent[agentsNum];
AgentState[] agentStates = new AgentState[agentsNum];
bool[][] goals = new bool[maxX][];
for (int i = 0; i < maxX; i++)
goals[i] = new bool[maxY];
// Choose random valid unclaimed goal locations
for (int i = 0; i < agentsNum; i++)
{
x = rand.Next(maxX);
y = rand.Next(maxY);
if (goals[x][y] || grid[x][y])
i--;
else
{
goals[x][y] = true;
agentGoals[i] = new Agent(x, y, i);
}
}
// Select random start/goal locations for every agent by performing a random walk
for (int i = 0; i < agentsNum; i++)
{
agentStates[i] = new AgentState(agentGoals[i].Goal.x, agentGoals[i].Goal.y, agentGoals[i]);
}
ProblemInstance problem = new ProblemInstance();
problem.gridName = Path.GetFileNameWithoutExtension(mapFilePath);
problem.Init(agentStates, grid);
for (int j = 0; j < RANDOM_WALK_STEPS; j++)
{
for (int i = 0; i < agentsNum; i++)
{
goals[agentStates[i].lastMove.x][agentStates[i].lastMove.y] = false; // We're going to move the goal somewhere else.
// Move in a random legal direction:
while (true)
{
Move.Direction op = (Move.Direction)rand.Next(0, 5); // TODO: fixme
agentStates[i].lastMove.Update(op);
if (problem.IsValid(agentStates[i].lastMove) &&
!goals[agentStates[i].lastMove.x][agentStates[i].lastMove.y]) // This spot isn't another agent's goal
break;
else
agentStates[i].lastMove.setOppositeMove(); // Rollback
}
goals[agentStates[i].lastMove.x][agentStates[i].lastMove.y] = true; // Claim agent's new goal
}
}
// Zero the agents' timesteps
foreach (AgentState agentStart in agentStates)
agentStart.lastMove.time = 0;
return problem;
}
}
/// <summary>
/// Solve given instance with a list of algorithms
/// </summary>
/// <param name="instance">The instance to solve</param>
/// <returns>Whether any solver succeeded in solving the instance</returns>
public bool SolveGivenProblem(ProblemInstance instance)
{
//return; // add for generator
// Preparing a list of agent indices (not agent nums) for the heuristics' Init() method
List<uint> agentList = Enumerable.Range(0, instance.agents.Length).Select(x=> (uint)x).ToList(); // FIXME: Must the heuristics really receive a list of uints?
// Solve using the different algorithms
Console.WriteLine($"Solving {instance}");
this.PrintProblemStatistics(instance);
// Initializing all heuristics, whereever they're used
for (int i = 0; i < astar_heuristics.Count; i++)
astar_heuristics[i].Init(instance, agentList);
int solutionCost = -1;
int solutionDepth = -1;
int firstSolverToSolveIndex = -1;
for (int i = 0; i < solvers.Count; i++)
{
if (outOfTimeCounters[i] < Constants.MAX_FAIL_COUNT) // After "MAX_FAIL_COUNT" consecutive failures of a given algorithm we stop running it.
// Assuming problem difficulties are non-decreasing, if it consistently failed on several problems it won't suddenly succeed in solving the next problem.
{
GC.Collect();
GC.WaitForPendingFinalizers();
//if (i != 2)
// continue;
//if (i == 1)
// ((A_Star)solvers[i]).debug = true;
//if (i == 4)
// ((CBS)solvers[i]).debug = true;
//if (i == 4)
// ((CBS)((IndependenceDetection)solvers[i]).groupSolver).debug = true;
if (solvers[i].GetType() == typeof(CBS) || solvers[i].GetType() == typeof(MACBS_WholeTreeThreshold))
{
if (((CBS)solvers[i]).mergeThreshold == 314159) // MAGIC NUMBER WHICH MAKES US ADJUST B according to map
{
if (instance.gridName.StartsWith("den"))
((CBS)solvers[i]).mergeThreshold = 10;
else if (instance.gridName.StartsWith("brc") || instance.gridName.StartsWith("ost"))
((CBS)solvers[i]).mergeThreshold = 100;
}
}
if (
(solvers[i].GetType() == typeof(IndependenceDetection) &&
((IndependenceDetection)solvers[i]).groupSolver.GetType() == typeof(CBS)) ||
(solvers[i].GetType() == typeof(IndependenceDetection) &&
((IndependenceDetection)solvers[i]).groupSolver.GetType() == typeof(MACBS_WholeTreeThreshold))
)
{
if (((CBS)((IndependenceDetection)solvers[i]).groupSolver).mergeThreshold == 314159) // MAGIC NUMBER SEE ABOVE
{
if (instance.gridName.StartsWith("den"))
((CBS)((IndependenceDetection)solvers[i]).groupSolver).mergeThreshold = 10;
else if (instance.gridName.StartsWith("brc") || instance.gridName.StartsWith("ost"))
((CBS)((IndependenceDetection)solvers[i]).groupSolver).mergeThreshold = 100;
}
}
this.run(solvers[i], instance);
Console.WriteLine();
int solverSolutionCost = solvers[i].GetSolutionCost();
int solverSolutionDepth = solvers[i].GetSolutionDepth();
if (solverSolutionCost >= 0) // Solved successfully
{
Plan plan = solvers[i].GetPlan();
plan.PrintPlanIfShort();
outOfTimeCounters[i] = 0;
plan.Check(instance);
// Validate solution:
if (solutionCost == -1) // This is the first time the problem is successfully solved
{
solutionCost = solverSolutionCost;
solutionDepth = solverSolutionDepth;
firstSolverToSolveIndex = i;
}
else // Problem solved before
{
Trace.Assert(solutionCost == solverSolutionCost,
$"{solvers[i]} solution cost {solverSolutionCost} is different " +
$"to the solution cost {solutionCost} of {solvers[firstSolverToSolveIndex]}"); // Assuming algs are supposed to find an optimal solution, this is an error.
//Trace.Assert(solvers[0].GetExpanded() == solvers[i].GetExpanded(), "Different Expanded");
//Trace.Assert(solvers[0].GetGenerated() == solvers[i].GetGenerated(), "Different Generated");
//Trace.Assert(solvers[0].GetSolutionDepth() == solvers[i].GetSolutionDepth(), "Depth Bug " + solvers[i]);
}
Console.WriteLine("+SUCCESS+ (:");
}
else
{
if (solutionCost != -1) // Problem solved before
Trace.Assert(solutionDepth >= solverSolutionDepth,
$"Failed solver {solvers[i]} solution depth lower bound {solverSolutionDepth} is *greater* than " +
$"the solution depth {solvers[firstSolverToSolveIndex]} of successful solver {solutionDepth}. " +
$"This is a problem if both start with an SIC estimate."); // Assuming algs are supposed to find an optimal solution, this is an error.
if (solverSolutionCost == (int) Constants.SpecialCosts.TIMEOUT_COST)
outOfTimeCounters[i]++;
if (solverSolutionCost != (int)Constants.SpecialCosts.NO_SOLUTION_COST)
Console.WriteLine("-FAILURE- ):");
else
Console.WriteLine("-NO SOLUTION- ]:");
}
}
else
PrintNullStatistics(solvers[i]);
Console.WriteLine();
}
this.ContinueToNextLine();
return solutionCost != -1;
}
/// <summary>
/// Solve given instance with a list of algorithms
/// </summary>
/// <param name="instance">The instance to solve</param>
public void SolveGivenProblemIncrementally(ProblemInstance instance)
{
// Preparing a list of agent indices (not agent nums) for the heuristics' Init() method
List<uint> agentList = Enumerable.Range(0, instance.agents.Length).Select(x => (uint)x).ToList(); // FIXME: Must the heuristics really receive a list of uints?
CooperativeAStar cooperativeAStar = new CooperativeAStar();
cooperativeAStar.Setup(instance, this);
this.startTime = this.ElapsedMillisecondsTotal();
double handlingStartTime = this.ElapsedMillisecondsTotal();
double elapsedTime = 0;
foreach (var agentIndex in Enumerable.Range(0, instance.agents.Length))
{
// Solve using the different algorithms
Console.WriteLine($"Solving {instance} agent {agentIndex}");
this.PrintProblemStatistics(instance);
GC.Collect();
GC.WaitForPendingFinalizers();
this.startTime += this.ElapsedMillisecondsTotal() - handlingStartTime;
bool solved = cooperativeAStar.AddOneAgent(agentIndex);
elapsedTime = this.ElapsedMilliseconds();
handlingStartTime = this.ElapsedMillisecondsTotal();
if (solved)
{
Console.WriteLine("Total cost: {0}", cooperativeAStar.GetSolutionCost());
Console.WriteLine("Solution depth: {0}", cooperativeAStar.GetSolutionDepth());
}
else
{
Console.WriteLine("Failed to solve");
Console.WriteLine("Solution depth lower bound: {0}", cooperativeAStar.GetSolutionDepth());
}
Console.WriteLine();
Console.WriteLine("Time In milliseconds: {0}", elapsedTime);
this.PrintStatistics(instance, cooperativeAStar, elapsedTime + instance.shortestPathComputeTime);
Console.WriteLine();
int solverSolutionCost = cooperativeAStar.GetSolutionCost();
if (solverSolutionCost >= 0) // Solved successfully
{
Plan plan = cooperativeAStar.GetPlan();
plan.PrintPlanIfShort();
Console.WriteLine("+SUCCESS+ (:");
}
else
{
Console.WriteLine("-FAILURE- ):");
break;
}
Console.WriteLine();
this.ContinueToNextLine();
}
}
/// <summary>
/// Solve a given instance with the given solver
/// </summary>
/// <param name="solver">The solver</param>
/// <param name="instance">The problem instance that will be solved</param>
private void run(ISolver solver, ProblemInstance instance)
{