-
Notifications
You must be signed in to change notification settings - Fork 1
/
fd-patch.diff
2840 lines (2783 loc) · 112 KB
/
fd-patch.diff
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
diff -X lp-recognizer/fd-patch.ignore -ruN fast-downward-original/src/search/CMakeLists.txt fast-downward/src/search/CMakeLists.txt
--- fast-downward-original/src/search/CMakeLists.txt 2023-11-15 18:14:39.797760300 -0300
+++ fast-downward/src/search/CMakeLists.txt 2024-02-24 20:05:13.695279700 -0300
@@ -857,7 +857,10 @@
SOURCES
operator_counting/constraint_generator
operator_counting/delete_relaxation_constraints
+ operator_counting/flow_constraints
+ operator_counting/flow_constraint_internals
operator_counting/lm_cut_constraints
+ operator_counting/oc_single_shot_heuristic
operator_counting/operator_counting_heuristic
operator_counting/pho_constraints
operator_counting/state_equation_constraints
@@ -873,6 +876,7 @@
pdbs/canonical_pdbs_heuristic
pdbs/cegar
pdbs/dominance_pruning
+ pdbs/explicit_projection
pdbs/incremental_canonical_pdbs
pdbs/match_tree
pdbs/max_cliques
diff -X lp-recognizer/fd-patch.ignore -ruN fast-downward-original/src/search/algorithms/combinations.h fast-downward/src/search/algorithms/combinations.h
--- fast-downward-original/src/search/algorithms/combinations.h 1969-12-31 21:00:00.000000000 -0300
+++ fast-downward/src/search/algorithms/combinations.h 2024-02-24 20:05:13.691320200 -0300
@@ -0,0 +1,45 @@
+#ifndef ALGORITHMS_COMBINATIONS_H
+#define ALGORITHMS_COMBINATIONS_H
+
+#include "../task_proxy.h"
+#include "../utils/logging.h"
+#include "../utils/collections.h"
+
+#include <cassert>
+#include <iostream>
+#include <vector>
+
+template<typename T>
+class Combinations {
+ std::vector<T> current_combination;
+ std::vector<std::vector<T>> combinations;
+
+ void add_combinations(const std::vector<T> &sequence, int offset, int k) {
+ if (k == 0) {
+ combinations.push_back(current_combination);
+ return;
+ }
+ for (size_t i = offset; i <= sequence.size() - k; ++i) {
+ assert(utils::in_bounds(i, sequence));
+ current_combination.push_back(sequence[i]);
+ add_combinations(sequence, i + 1, k - 1);
+ current_combination.pop_back();
+ }
+ }
+
+public:
+ std::vector<std::vector<T>> && get_combinations(
+ const std::vector<T> &sequence, int k) {
+ assert(k >= 0);
+ combinations.clear();
+ current_combination.clear();
+ int n = sequence.size();
+ if (k > n) {
+ return std::move(combinations);
+ }
+ add_combinations(sequence, 0, k);
+ return std::move(combinations);
+ }
+};
+
+#endif
diff -X lp-recognizer/fd-patch.ignore -ruN fast-downward-original/src/search/algorithms/named_vector.h fast-downward/src/search/algorithms/named_vector.h
--- fast-downward-original/src/search/algorithms/named_vector.h 2023-11-15 18:14:29.852554800 -0300
+++ fast-downward/src/search/algorithms/named_vector.h 2024-02-24 20:05:13.693284200 -0300
@@ -92,6 +92,10 @@
names.clear();
}
+ void erase(std::vector<T>::const_iterator start, std::vector<T>::const_iterator end) {
+ elements.erase(start, end);
+ }
+
void reserve(int capacity) {
/* No space is reserved in the names vector because it is kept
at minimal size and space is only used when necessary. */
diff -X lp-recognizer/fd-patch.ignore -ruN fast-downward-original/src/search/heuristics/lm_cut_landmarks.cc fast-downward/src/search/heuristics/lm_cut_landmarks.cc
--- fast-downward-original/src/search/heuristics/lm_cut_landmarks.cc 2023-11-15 18:14:39.829874200 -0300
+++ fast-downward/src/search/heuristics/lm_cut_landmarks.cc 2024-02-24 20:05:13.697389500 -0300
@@ -10,6 +10,63 @@
namespace lm_cut_heuristic {
// construction and destruction
+
+LandmarkCutLandmarks::LandmarkCutLandmarks(const TaskProxy &task_proxy, const vector<int> &observations, bool include_goal) {
+ task_properties::verify_no_axioms(task_proxy);
+ task_properties::verify_no_conditional_effects(task_proxy);
+
+ // Build propositions.
+ num_propositions = 2; // artificial goal and artificial precondition
+ VariablesProxy variables = task_proxy.get_variables();
+ propositions.resize(variables.size());
+ for (FactProxy fact : variables.get_facts()) {
+ int var_id = fact.get_variable().get_id();
+ propositions[var_id].push_back(RelaxedProposition());
+ ++num_propositions;
+ }
+
+ // Build relaxed operators for operators and axioms.
+ for (OperatorProxy op : task_proxy.get_operators())
+ build_relaxed_operator(op);
+
+ // Simplify relaxed operators.
+ // simplify();
+ /* TODO: Put this back in and test if it makes sense,
+ but only after trying out whether and how much the change to
+ unary operators hurts. */
+
+ // Build artificial goal proposition and operator.
+ vector<RelaxedProposition *> goal_op_pre, goal_op_eff;
+
+ if (include_goal) {
+ for (FactProxy goal : task_proxy.get_goals()) {
+ goal_op_pre.push_back(get_proposition(goal));
+ }
+ }
+ cout << "Observation preconditions: " << endl;
+ for (int op_id : observations) {
+ for (FactProxy f : task_proxy.get_operators()[op_id].get_preconditions()) {
+ RelaxedProposition *pre = get_proposition(f);
+ if (std::find(goal_op_pre.begin(), goal_op_pre.end(), pre) == goal_op_pre.end()) {
+ goal_op_pre.push_back(pre);
+ cout << f.get_name() << endl;
+ }
+ }
+ }
+ goal_op_eff.push_back(&artificial_goal);
+ /* Use the invalid operator ID -1 so accessing
+ the artificial operator will generate an error. */
+ add_relaxed_operator(move(goal_op_pre), move(goal_op_eff), -1, 0);
+
+ // Cross-reference relaxed operators.
+ for (RelaxedOperator &op : relaxed_operators) {
+ for (RelaxedProposition *pre : op.preconditions)
+ pre->precondition_of.push_back(&op);
+ for (RelaxedProposition *eff : op.effects)
+ eff->effect_of.push_back(&op);
+ }
+}
+
LandmarkCutLandmarks::LandmarkCutLandmarks(const TaskProxy &task_proxy) {
task_properties::verify_no_axioms(task_proxy);
task_properties::verify_no_conditional_effects(task_proxy);
diff -X lp-recognizer/fd-patch.ignore -ruN fast-downward-original/src/search/heuristics/lm_cut_landmarks.h fast-downward/src/search/heuristics/lm_cut_landmarks.h
--- fast-downward-original/src/search/heuristics/lm_cut_landmarks.h 2023-11-15 18:14:39.830871400 -0300
+++ fast-downward/src/search/heuristics/lm_cut_landmarks.h 2024-02-24 20:05:13.699384700 -0300
@@ -87,6 +87,7 @@
using CostCallback = std::function<void (int)>;
using LandmarkCallback = std::function<void (const Landmark &, int)>;
+ LandmarkCutLandmarks(const TaskProxy &task_proxy, const std::vector<int> &observations, bool include_goal=true);
LandmarkCutLandmarks(const TaskProxy &task_proxy);
virtual ~LandmarkCutLandmarks();
diff -X lp-recognizer/fd-patch.ignore -ruN fast-downward-original/src/search/operator_counting/constraint_generator.cc fast-downward/src/search/operator_counting/constraint_generator.cc
--- fast-downward-original/src/search/operator_counting/constraint_generator.cc 2023-11-15 18:14:39.881902300 -0300
+++ fast-downward/src/search/operator_counting/constraint_generator.cc 2024-02-24 20:05:13.701379000 -0300
@@ -5,10 +5,18 @@
using namespace std;
namespace operator_counting {
+
void ConstraintGenerator::initialize_constraints(
const shared_ptr<AbstractTask> &, lp::LinearProgram &) {
}
+void ConstraintGenerator::set_observations(const vector<int>& observations, int obs_info) {
+ this->obs_info = obs_info;
+ this->observations = observations;
+}
+
+void ConstraintGenerator::log_info(const TaskProxy&, const vector<double>&, vector<double>&) {}
+
static class ConstraintGeneratorCategoryPlugin : public plugins::TypedCategoryPlugin<ConstraintGenerator> {
public:
ConstraintGeneratorCategoryPlugin() : TypedCategoryPlugin("ConstraintGenerator") {
diff -X lp-recognizer/fd-patch.ignore -ruN fast-downward-original/src/search/operator_counting/constraint_generator.h fast-downward/src/search/operator_counting/constraint_generator.h
--- fast-downward-original/src/search/operator_counting/constraint_generator.h 2023-11-15 18:14:39.882899700 -0300
+++ fast-downward/src/search/operator_counting/constraint_generator.h 2024-02-24 20:05:13.703374300 -0300
@@ -5,6 +5,7 @@
#include <vector>
#include "../algorithms/named_vector.h"
+#include "../task_proxy.h"
class AbstractTask;
class State;
@@ -12,8 +13,20 @@
namespace lp {
class LinearProgram;
class LPSolver;
+class LPVariable;
}
+namespace options {
+class OptionParser;
+class Options;
+}
+
+// obs_info
+#define OBS_NONE 0
+#define OBS_NO_ORDER 1
+#define OBS_SOFT_ORDER 2
+#define OBS_HARD_ORDER 3
+
namespace operator_counting {
/*
Derive from this class to add new operator-counting constraints. We support
@@ -31,6 +44,8 @@
*/
class ConstraintGenerator {
public:
+ std::vector<int> observations;
+ int obs_info = 0;
virtual ~ConstraintGenerator() = default;
/*
@@ -49,6 +64,9 @@
*/
virtual bool update_constraints(
const State &state, lp::LPSolver &lp_solver) = 0;
+
+ void set_observations(const std::vector<int>& observations, int obs_info = 0);
+ virtual void log_info(const TaskProxy &task_proxy, const std::vector<double>& solution, std::vector<double>& info);
};
}
diff -X lp-recognizer/fd-patch.ignore -ruN fast-downward-original/src/search/operator_counting/delete_relaxation_constraints.cc fast-downward/src/search/operator_counting/delete_relaxation_constraints.cc
--- fast-downward-original/src/search/operator_counting/delete_relaxation_constraints.cc 2023-11-15 18:14:39.882899700 -0300
+++ fast-downward/src/search/operator_counting/delete_relaxation_constraints.cc 2024-02-26 17:00:47.602226500 -0300
@@ -7,6 +7,7 @@
#include "../utils/markup.h"
#include <cassert>
+#include <map>
using namespace std;
@@ -21,15 +22,37 @@
}
+// noisy
+#define DL_NO_NOISY 0
+#define DL_NOISY 1
+#define DL_NOISY_INV 2
+#define DL_NOISY_SOFT_INV 3
+
+// is_integer
+#define INT_NONE 0
+#define INT_ALL 1
+#define INT_OBS 2
+
+
DeleteRelaxationConstraints::DeleteRelaxationConstraints(const plugins::Options &opts)
: use_time_vars(opts.get<bool>("use_time_vars")),
- use_integer_vars(opts.get<bool>("use_integer_vars")) {
+ // use_integer_vars(opts.get<bool>("use_integer_vars")),
+ use_integer_vars_op(opts.get<int>("use_integer_vars_op")),
+ use_integer_vars_op2(opts.get<int>("use_integer_vars_op2")),
+ use_integer_vars_facts(opts.get<int>("use_integer_vars_fact")),
+ use_integer_vars_achiever(opts.get<int>("use_integer_vars_achiever")),
+ use_integer_vars_time(opts.get<int>("use_integer_vars_time")),
+ noisy(opts.get<int>("noisy")) {
}
int DeleteRelaxationConstraints::get_var_op_used(const OperatorProxy &op) {
return lp_var_id_op_used[op.get_id()];
}
+int DeleteRelaxationConstraints::get_var_op_used2(const OperatorProxy &op) {
+ return lp_var_id_op_used2[op.get_id()];
+}
+
int DeleteRelaxationConstraints::get_var_fact_reached(FactPair f) {
return lp_var_id_fact_reached[f.var][f.value];
}
@@ -43,6 +66,10 @@
return lp_var_id_op_time[op.get_id()];
}
+int DeleteRelaxationConstraints::get_var_op_time2(const OperatorProxy &op) {
+ return lp_var_id_op_time2[op.get_id()];
+}
+
int DeleteRelaxationConstraints::get_var_fact_time(FactPair f) {
return lp_var_id_fact_time[f.var][f.value];
}
@@ -51,6 +78,17 @@
return constraint_ids[f.var][f.value];
}
+// For var_op_used and var_op_used2
+static void add_lp_variables(int count, vector<bool>& obs_used,
+ LPVariables &variables, vector<int> &indices,
+ double lower, double upper, double objective,
+ int is_integer) {
+ for (int i = 0; i < count; ++i) {
+ indices.push_back(variables.size());
+ variables.emplace_back(lower, upper, objective, is_integer == INT_ALL || (is_integer == INT_OBS && obs_used[i]));
+ }
+}
+
void DeleteRelaxationConstraints::create_auxiliary_variables(
const TaskProxy &task_proxy, LPVariables &variables) {
OperatorsProxy ops = task_proxy.get_operators();
@@ -58,38 +96,45 @@
VariablesProxy vars = task_proxy.get_variables();
int num_vars = vars.size();
+ vector<bool> obs_used(num_ops, false);
+ for (int id : observations)
+ obs_used[id] = true;
+
// op_used
- add_lp_variables(num_ops, variables, lp_var_id_op_used, 0, 1, 0, use_integer_vars);
+ add_lp_variables(num_ops, variables, lp_var_id_op_used, 0, 1, 0, use_integer_vars_op);
+ if (obs_info != OBS_NONE)
+ add_lp_variables(num_ops, obs_used, variables, lp_var_id_op_used2, 0, 1, 0, use_integer_vars_op2);
// fact_reached
lp_var_id_fact_reached.resize(num_vars);
for (VariableProxy var : vars) {
add_lp_variables(var.get_domain_size(), variables,
lp_var_id_fact_reached[var.get_id()],
- 0, 1, 0, use_integer_vars);
+ 0, 1, 0, use_integer_vars_facts == INT_ALL);
}
// first_achiever
lp_var_id_first_achiever.resize(num_ops);
for (OperatorProxy op : ops) {
+ bool is_integer = use_integer_vars_achiever == INT_ALL || (use_integer_vars_achiever == INT_OBS && obs_used[op.get_id()]);
lp_var_id_first_achiever[op.get_id()].resize(num_vars);
for (VariableProxy var : vars) {
- add_lp_variables(var.get_domain_size(), variables,
+ add_lp_variables(var.get_domain_size(), obs_used, variables,
lp_var_id_first_achiever[op.get_id()][var.get_id()],
- 0, 1, 0, use_integer_vars);
+ 0, 1, 0, is_integer);
}
}
if (use_time_vars) {
// op_time
- add_lp_variables(num_ops, variables, lp_var_id_op_time, 0, num_ops, 0, use_integer_vars);
+ add_lp_variables(num_ops, variables, lp_var_id_op_time, 0, num_ops, 0, use_integer_vars_time);
// fact_time
lp_var_id_fact_time.resize(num_vars);
for (VariableProxy var : vars) {
add_lp_variables(var.get_domain_size(), variables,
lp_var_id_fact_time[var.get_id()],
- 0, num_ops, 0, use_integer_vars);
+ 0, num_ops, 0, use_integer_vars_time == INT_ALL);
}
}
}
@@ -165,6 +210,28 @@
}
}
+ // Observed operators
+ map<int, int> occur;
+ for (int obs_id : observations)
+ occur[obs_id]++;
+ if (noisy == DL_NOISY) {
+ cout << "Soft restrictions for observation variables." << endl;
+ int var_id = task_proxy.get_operators().size();
+ for (auto it = occur.begin(); it != occur.end(); it++) {
+ lp::LPConstraint constraint_inv(0, infinity);
+ constraint_inv.insert(var_id, -1);
+ constraint_inv.insert(lp_var_id_op_used[it->first], it->second);
+ constraints.push_back(constraint_inv);
+ var_id++;
+ }
+ } else if (noisy == DL_NO_NOISY) {
+ cout << "Hard restrictions for operator variables." << endl;
+ for (int obs : observations) {
+ int var = get_var_op_used(ops[obs]);
+ variables[var].lower_bound = 1;
+ }
+ }
+
if (use_time_vars) {
/*
Preconditions must be reached before the operator is used.
@@ -179,6 +246,34 @@
}
}
+
+ if (obs_info == OBS_NONE)
+ cout << "No observations." << endl;
+ else if (obs_info == OBS_NO_ORDER)
+ cout << "No observation order." << endl;
+ else if (obs_info == OBS_SOFT_ORDER)
+ cout << "Soft observation order." << endl;
+ else if (obs_info == OBS_HARD_ORDER)
+ cout << "Hard observation order." << endl;
+
+ if (obs_info != OBS_NONE) {
+ int N = ops.size();
+ vector<int> first_obs;
+ for (int obs : observations)
+ if (find(first_obs.begin(), first_obs.end(), obs) == first_obs.end())
+ first_obs.push_back(obs);
+ for (uint i = 1; i < first_obs.size(); i++) {
+ OperatorProxy op1 = ops[first_obs[i-1]];
+ OperatorProxy op2 = ops[first_obs[i]];
+ lp::LPConstraint constraint(1, infinity);
+ constraint.insert(get_var_op_time(op2), 1);
+ constraint.insert(get_var_op_time(op1), -1);
+ if (obs_info == OBS_SOFT_ORDER) // Soft observation order
+ constraint.insert(get_var_op_used2(op2), N);
+ constraints.push_back(constraint);
+ }
+ }
+
/*
If an operator is a first achiever, its effects are reached in
the time step following its use.
@@ -208,13 +303,37 @@
lp::LPConstraint constraint(0, infinity);
constraint.insert(op.get_id(), 1);
constraint.insert(get_var_op_used(op), -1);
+ if (obs_info == OBS_SOFT_ORDER) // Soft observation order
+ constraint.insert(get_var_op_used2(op), -1);
constraints.push_back(constraint);
+ if (noisy == DL_NOISY_SOFT_INV || (noisy == DL_NOISY_INV && occur[op.get_id()] > 0)) {
+ lp::LPConstraint constraint_inv(0, infinity);
+ constraint_inv.insert(op.get_id(), -1);
+ constraint_inv.insert(get_var_op_used(op), 10000);
+ constraints.push_back(constraint_inv);
+ }
}
}
-void DeleteRelaxationConstraints::initialize_constraints(
- const shared_ptr<AbstractTask> &task, lp::LinearProgram &lp) {
+void DeleteRelaxationConstraints::initialize_constraints(const shared_ptr<AbstractTask> &task,
+ lp::LinearProgram &lp) {
+ lp_var_id_op_used.clear();
+ lp_var_id_op_used2.clear();
+ lp_var_id_fact_reached.clear();
+ lp_var_id_first_achiever.clear();
+ lp_var_id_op_time.clear();
+ lp_var_id_op_time2.clear();
+ lp_var_id_fact_time.clear();
+ if (use_integer_vars_op)
+ cout << "Using integer operator variables" << endl;
+ if (use_integer_vars_achiever)
+ cout << "Using integer first achiever variables" << endl;
+ if (use_integer_vars_facts)
+ cout << "Using integer fact variables" << endl;
+ if (use_integer_vars_time)
+ cout << "Using integer time variables" << endl;
+ constraint_ids.clear();
TaskProxy task_proxy(*task);
create_auxiliary_variables(task_proxy, lp.get_variables());
create_constraints(task_proxy, lp);
@@ -236,6 +355,18 @@
return false;
}
+void DeleteRelaxationConstraints::log_info(const TaskProxy &task_proxy, const vector<double> &solution, vector<double> &info) {
+ if (obs_info != OBS_SOFT_ORDER)
+ return;
+ int u2 = 0;
+ for (OperatorProxy op : task_proxy.get_operators()) {
+ int var_id = get_var_op_used2(op);
+ if (solution[var_id] > 0)
+ u2++;
+ }
+ info.push_back(u2);
+}
+
class DeleteRelaxationConstraintsFeature : public plugins::TypedFeature<ConstraintGenerator, DeleteRelaxationConstraints> {
public:
DeleteRelaxationConstraintsFeature() : TypedFeature("delete_relaxation_constraints") {
@@ -264,15 +395,39 @@
"increase the size of the constraints which has a strong impact on "
"runtime. Constraints involving time variables use a big-M encoding, "
"so they are more useful if used with integer variables.",
- "false");
- add_option<bool>(
+ "true");
+ /*add_option<bool>(
"use_integer_vars",
"restrict auxiliary variables to integer values. These variables "
"encode whether operators are used, facts are reached, which operator "
"first achieves which fact, and in which order the operators are used. "
"Restricting them to integers generally improves the heuristic value "
"at the cost of increased runtime.",
- "false");
+ "false");*/
+
+ add_option<int>(
+ "use_integer_vars_op",
+ "",
+ "0");
+ add_option<int>(
+ "use_integer_vars_op2",
+ "",
+ "0");
+ add_option<int>(
+ "use_integer_vars_fact",
+ "",
+ "0");
+ add_option<int>(
+ "use_integer_vars_achiever",
+ "",
+ "0");
+ add_option<int>(
+ "use_integer_vars_time",
+ "",
+ "0");
+ add_option<int>("noisy",
+ "consider noisy observations",
+ "0");
document_note(
"Example",
@@ -283,4 +438,4 @@
};
static plugins::FeaturePlugin<DeleteRelaxationConstraintsFeature> _plugin;
-}
+}
\ No newline at end of file
diff -X lp-recognizer/fd-patch.ignore -ruN fast-downward-original/src/search/operator_counting/delete_relaxation_constraints.h fast-downward/src/search/operator_counting/delete_relaxation_constraints.h
--- fast-downward-original/src/search/operator_counting/delete_relaxation_constraints.h 2023-11-15 18:14:39.882899700 -0300
+++ fast-downward/src/search/operator_counting/delete_relaxation_constraints.h 2024-02-24 20:05:13.707486400 -0300
@@ -3,13 +3,12 @@
#include "constraint_generator.h"
-#include "../task_proxy.h"
-
#include <memory>
namespace lp {
class LPConstraint;
struct LPVariable;
+class LinearProgram;
}
namespace plugins {
@@ -22,11 +21,13 @@
class DeleteRelaxationConstraints : public ConstraintGenerator {
bool use_time_vars;
- bool use_integer_vars;
+ int use_integer_vars_op, use_integer_vars_op2, use_integer_vars_facts, use_integer_vars_achiever, use_integer_vars_time;
+ int noisy;
/* [U_o] Is op part of the relaxed plan?
Binary, indexed with op.id */
std::vector<int> lp_var_id_op_used;
+ std::vector<int> lp_var_id_op_used2;
/* [R_f] Is fact <V,v> reached by the relaxed plan?
Binary, indexed with var.id, value */
@@ -39,6 +40,7 @@
/* [T_o] At what time is o used first?
{0, ..., |O|}, indexed with op.id */
std::vector<int> lp_var_id_op_time;
+ std::vector<int> lp_var_id_op_time2;
/* [T_f] At what time is <V,v> first achieved?
{0, ..., |O|}, indexed with var.id, value */
@@ -53,15 +55,18 @@
std::vector<FactPair> last_state;
int get_var_op_used(const OperatorProxy &op);
+ int get_var_op_used2(const OperatorProxy &op);
int get_var_fact_reached(FactPair f);
int get_var_first_achiever(const OperatorProxy &op, FactPair f);
int get_var_op_time(const OperatorProxy &op);
+ int get_var_op_time2(const OperatorProxy &op);
int get_var_fact_time(FactPair f);
int get_constraint_id(FactPair f);
void create_auxiliary_variables(
- const TaskProxy &task_proxy, LPVariables &variables);
- void create_constraints(const TaskProxy &task_proxy, lp::LinearProgram &lp);
+ const TaskProxy &task_proxy, LPVariables &variables);
+ void create_constraints(
+ const TaskProxy &task_proxy, lp::LinearProgram &lp);
public:
explicit DeleteRelaxationConstraints(const plugins::Options &opts);
@@ -70,6 +75,8 @@
lp::LinearProgram &lp) override;
virtual bool update_constraints(
const State &state, lp::LPSolver &lp_solver) override;
+
+ virtual void log_info(const TaskProxy &task_proxy, const std::vector<double>& solution, std::vector<double>& info) override;
};
}
diff -X lp-recognizer/fd-patch.ignore -ruN fast-downward-original/src/search/operator_counting/flow_constraint_internals.cc fast-downward/src/search/operator_counting/flow_constraint_internals.cc
--- fast-downward-original/src/search/operator_counting/flow_constraint_internals.cc 1969-12-31 21:00:00.000000000 -0300
+++ fast-downward/src/search/operator_counting/flow_constraint_internals.cc 2024-02-24 20:05:13.710480200 -0300
@@ -0,0 +1,243 @@
+#include "flow_constraint_internals.h"
+
+#include "../lp/lp_solver.h"
+#include "../utils/logging.h"
+#include "../utils/memory.h"
+
+using namespace std;
+
+namespace operator_counting {
+FlowConstraintInternals::FlowConstraintInternals(
+ const AbstractTask &task, lp::LinearProgram &lp,
+ const FlowConstraintSettings &settings)
+ : initial_state_is_dead_end(false),
+ single_goal_state(-1),
+ abstraction_function(nullptr) {
+ TaskProxy task_proxy(task);
+ auto abstraction_and_ts = pdbs::project_task(
+ task, settings.pattern, settings.remove_dead_states, settings.use_mutexes, settings.partial_merge_states);
+ abstraction_function = utils::make_unique_ptr<pdbs::AbstractionFunction>(move(abstraction_and_ts.first));
+ const pdbs::AbstractTransitionSystem &transition_system = abstraction_and_ts.second;
+ num_abstract_states = transition_system.num_states;
+
+ if (transition_system.goal_states.empty()) {
+ initial_state_is_dead_end = true;
+ } else {
+ create_constraints(lp, transition_system, task_proxy, settings);
+ }
+}
+
+
+vector<OperatorCategory> FlowConstraintInternals::get_operator_categories(
+ const pdbs::AbstractTransitionSystem &transition_system, const TaskProxy &task_proxy,
+ const FlowConstraintSettings &settings) {
+ int num_operators = task_proxy.get_operators().size();
+ vector<OperatorCategory> operator_category(num_operators, OperatorCategory::USE_STRONG_LINKING_CONSTRAINT);
+
+ vector<int> num_self_loops(num_operators, 0);
+ for (pdbs::Transition t : transition_system.self_loops) {
+ num_self_loops[t.op_id] += 1;
+ }
+ for (int op_id : transition_system.self_loops_on_all_states) {
+ num_self_loops[op_id] += transition_system.num_states;
+ }
+
+ vector<int> num_state_changing_transitions(num_operators, 0);
+ for (pdbs::Transition t : transition_system.state_changing_transitions) {
+ num_state_changing_transitions[t.op_id] += 1;
+ }
+
+ for (int op_id = 0; op_id < num_operators; ++op_id) {
+ int num_sct = num_state_changing_transitions[op_id];
+ int num_loops = num_self_loops[op_id];
+
+ if (settings.single_transition_optimization && num_sct == 1 && num_loops == 0) {
+ operator_category[op_id] = OperatorCategory::USE_OP_COUNT_DIRECTLY;
+ }
+
+ if (settings.self_loop_optimization && num_sct == 0 && num_loops > 0) {
+ operator_category[op_id] = OperatorCategory::IGNORE_OPERATOR;
+ }
+
+ if (settings.weak_linking_constraints && num_sct > 0 && num_loops > 0) {
+ operator_category[op_id] = OperatorCategory::USE_WEAK_LINKING_CONSTRAINT;
+ }
+ }
+
+ return operator_category;
+}
+
+void FlowConstraintInternals::create_constraints(lp::LinearProgram &lp,
+ const pdbs::AbstractTransitionSystem &transition_system,
+ const TaskProxy &task_proxy,
+ const FlowConstraintSettings &settings) {
+ int num_operators = task_proxy.get_operators().size();
+ vector<OperatorCategory> operator_category = get_operator_categories(transition_system, task_proxy, settings);
+
+ LPVariables &variables = lp.get_variables();
+ LPConstraints &constraints = lp.get_constraints();
+ double infinity = lp.get_infinity();
+
+ /*
+ Create constraints of the type
+ sum_{t \in in(s)} Count_t - sum_{t \in out(s)} Count_t >= -[s is init] if s is an abstract goal
+ sum_{t \in in(s)} Count_t - sum_{t \in out(s)} Count_t = -[s is init] otherwise
+ for all abstract states s. While doing this, we use operator_category to
+ - replace some Count_t (transition-counting variable) by Count_o (operator-counting variable),
+ - ignore other Count_t variables, and
+ - introduce Count_t variables where necessary.
+
+ Where necessary, we also create a linking constraint (weak or strong, depending on operator_category).
+ sum_{t \in trans(o)} Count_t = Count_o (strong)
+ sum_{t \in trans(o), t is no self loop} Count_t <= Count_o (weak)
+ */
+
+ state_constraint_offset = constraints.size();
+ for (int state = 0; state < transition_system.num_states; ++state) {
+ // Handle initial and goal states later.
+ constraints.emplace_back(0, 0);
+ }
+ // Set some state as current, so we don't need a special case for "no current state".
+ int intitial_id = state_constraint_offset + transition_system.initial_state;
+ current_state = transition_system.initial_state;
+ constraints[intitial_id].set_lower_bound(-1);
+ constraints[intitial_id].set_upper_bound(-1);
+
+ // Special case for single goal state for comparability to SEQ on TNF tasks
+ if (transition_system.goal_states.size() == 1) {
+ single_goal_state = transition_system.goal_states[0];
+ int goal_id = state_constraint_offset + single_goal_state;
+ int bound = (int)constraints[goal_id].get_lower_bound() + 1;
+ constraints[goal_id].set_lower_bound(bound);
+ constraints[goal_id].set_upper_bound(bound);
+ } else {
+ assert(is_goal.empty());
+ is_goal.resize(transition_system.num_states, false);
+ for (int goal : transition_system.goal_states) {
+ is_goal[goal] = true;
+ int goal_id = state_constraint_offset + goal;
+ constraints[goal_id].set_upper_bound(infinity);
+ }
+ }
+
+ vector<vector<int>> linking_constraint_entries(num_operators);
+ for (pdbs::Transition t: transition_system.state_changing_transitions) {
+ int op_id = t.op_id;
+ OperatorCategory category = operator_category[op_id];
+ if (category == OperatorCategory::IGNORE_OPERATOR) {
+ continue;
+ }
+ int lp_var;
+ if (category == OperatorCategory::USE_OP_COUNT_DIRECTLY) {
+ lp_var = op_id;
+ } else {
+ // Create transition-counting variable
+ lp_var = variables.size();
+ variables.emplace_back(0, infinity, 0, true);
+ linking_constraint_entries[op_id].push_back(lp_var);
+ }
+
+ /* The lp variable occurs with coefficient -1 in the constraint
+ of its source state because it is an outgoing transition. */
+ int source_constraint_id = state_constraint_offset + t.source;
+ constraints[source_constraint_id].insert(lp_var, -1);
+
+ /* The lp variable occurs with coefficient +1 in the constraint
+ of its target state because it is an incoming transition. */
+ int target_constraint_id = state_constraint_offset + t.target;
+ constraints[target_constraint_id].insert(lp_var, 1);
+ }
+ for (pdbs::Transition t: transition_system.self_loops) {
+ // Self-loops cancel out in all constraints except in the strong linking constraint.
+ int op_id = t.op_id;
+ OperatorCategory category = operator_category[op_id];
+ if (category == OperatorCategory::USE_STRONG_LINKING_CONSTRAINT) {
+ // Create transition-counting variable
+ int lp_var = variables.size();
+ variables.emplace_back(0, infinity, 0, true);
+ linking_constraint_entries[op_id].push_back(lp_var);
+ }
+ }
+ for (int op_id: transition_system.self_loops_on_all_states) {
+ // Self-loops cancel out in all constraints except in the strong linking constraint.
+ OperatorCategory category = operator_category[op_id];
+ if (category == OperatorCategory::USE_STRONG_LINKING_CONSTRAINT) {
+ // Create transition-counting variable
+ int lp_var = variables.size();
+ variables.emplace_back(0, infinity, 0, true);
+ linking_constraint_entries[op_id].push_back(lp_var);
+ }
+ }
+
+ // Create linking constraints.
+ for (int op_id = 0; op_id < num_operators; ++op_id) {
+ OperatorCategory category = operator_category[op_id];
+ if (category != OperatorCategory::USE_STRONG_LINKING_CONSTRAINT &&
+ category != OperatorCategory::USE_WEAK_LINKING_CONSTRAINT) {
+ continue;
+ }
+ if (linking_constraint_entries[op_id].empty()) {
+ // Handle constraints without entries in variable bounds.
+ if (category == OperatorCategory::USE_STRONG_LINKING_CONSTRAINT) {
+ variables[op_id].upper_bound = 0;
+ }
+ // No need to handle a weak linking constraint without entries (C_o >= 0).
+ } else {
+ constraints.emplace_back(0, 0);
+ lp::LPConstraint &linking_constraint = constraints.back();
+ if (category == OperatorCategory::USE_WEAK_LINKING_CONSTRAINT) {
+ linking_constraint.set_lower_bound(-infinity);
+ }
+ linking_constraint.insert(op_id, -1);
+ for (int entry : linking_constraint_entries[op_id]) {
+ linking_constraint.insert(entry, 1);
+ }
+ }
+ }
+}
+
+bool FlowConstraintInternals::update_constraints(
+ const State &state, lp::LPSolver &lp_solver) {
+ if (initial_state_is_dead_end) {
+ return true;
+ }
+ int current_id = state_constraint_offset + current_state;
+ int next_state = abstraction_function->get_abstract_state(state);
+ int next_id = state_constraint_offset + next_state;
+
+ if (next_state == -1) {
+ /* This state was pruned from the transition system as a dead state.
+ If it is reachable, it is a dead end. */
+ return true;
+ }
+
+ if (current_id != next_id) {
+ if (single_goal_state > -1) {
+ // Special case for SEQ comparability on TNF tasks
+ int old_bound = 0;
+ if (current_state == single_goal_state) {
+ old_bound = 1;
+ }
+ lp_solver.set_constraint_lower_bound(current_id, old_bound);
+ lp_solver.set_constraint_upper_bound(current_id, old_bound);
+ int new_bound = -1;
+ if (next_state == single_goal_state) {
+ new_bound = 0;
+ }
+ lp_solver.set_constraint_lower_bound(next_id, new_bound);
+ lp_solver.set_constraint_upper_bound(next_id, new_bound);
+ } else {
+ lp_solver.set_constraint_lower_bound(current_id, 0);
+ if (!is_goal[current_state]) {
+ lp_solver.set_constraint_upper_bound(current_id, 0);
+ }
+ lp_solver.set_constraint_lower_bound(next_id, -1);
+ if (!is_goal[next_state]) {
+ lp_solver.set_constraint_upper_bound(next_id, -1);
+ }
+ }
+ current_state = next_state;
+ }
+ return false;
+}
+}
diff -X lp-recognizer/fd-patch.ignore -ruN fast-downward-original/src/search/operator_counting/flow_constraint_internals.h fast-downward/src/search/operator_counting/flow_constraint_internals.h
--- fast-downward-original/src/search/operator_counting/flow_constraint_internals.h 1969-12-31 21:00:00.000000000 -0300
+++ fast-downward/src/search/operator_counting/flow_constraint_internals.h 2024-02-24 20:05:13.712478900 -0300
@@ -0,0 +1,68 @@
+#ifndef OPERATOR_COUNTING_FLOW_CONSTRAINT_INTERNALS_H
+#define OPERATOR_COUNTING_FLOW_CONSTRAINT_INTERNALS_H
+
+#include "constraint_generator.h"
+
+#include "../pdbs/explicit_projection.h"
+#include "../pdbs/pattern_generator.h"
+
+#include <vector>
+
+namespace lp {
+class LPConstraint;
+struct LPVariable;
+class LinearProgram;
+}
+
+namespace operator_counting {
+using LPConstraints = named_vector::NamedVector<lp::LPConstraint>;
+using LPVariables = named_vector::NamedVector<lp::LPVariable>;
+enum class OperatorCategory {
+ IGNORE_OPERATOR,
+ USE_OP_COUNT_DIRECTLY,
+ USE_WEAK_LINKING_CONSTRAINT,
+ USE_STRONG_LINKING_CONSTRAINT
+};
+
+struct FlowConstraintSettings {
+ pdbs::Pattern pattern;
+ bool remove_dead_states;
+ bool single_transition_optimization;
+ bool self_loop_optimization;
+ bool weak_linking_constraints;
+ bool use_mutexes;
+ std::vector<std::vector<int>> partial_merge_states;
+};
+
+class FlowConstraintInternals {
+ std::vector<bool> is_goal;
+ int state_constraint_offset;
+ int current_state;
+ bool initial_state_is_dead_end;
+ int single_goal_state;
+ std::unique_ptr<pdbs::AbstractionFunction> abstraction_function;
+
+ int num_abstract_states;
+
+ std::vector<OperatorCategory> get_operator_categories(
+ const pdbs::AbstractTransitionSystem &transition_system, const TaskProxy &task_proxy,
+ const FlowConstraintSettings &settings);
+ void create_constraints(
+ lp::LinearProgram &lp,
+ const pdbs::AbstractTransitionSystem &transition_system,
+ const TaskProxy &task_proxy,
+ const FlowConstraintSettings &settings);
+public:
+ FlowConstraintInternals(
+ const AbstractTask &task,
+ lp::LinearProgram &lp,
+ const FlowConstraintSettings &settings);
+
+ bool update_constraints(const State &state, lp::LPSolver &lp_solver);
+ int get_num_abstract_states() const {
+ return num_abstract_states;
+ }
+};
+}
+
+#endif
diff -X lp-recognizer/fd-patch.ignore -ruN fast-downward-original/src/search/operator_counting/flow_constraints.cc fast-downward/src/search/operator_counting/flow_constraints.cc
--- fast-downward-original/src/search/operator_counting/flow_constraints.cc 1969-12-31 21:00:00.000000000 -0300
+++ fast-downward/src/search/operator_counting/flow_constraints.cc 2024-02-26 17:12:07.807801900 -0300
@@ -0,0 +1,510 @@
+#include "flow_constraints.h"
+
+#include "../plugins/plugin.h"
+#include "../lp/lp_solver.h"
+#include "../utils/logging.h"
+#include "../utils/timer.h"
+#include "../utils/countdown_timer.h"
+#include "../algorithms/combinations.h"
+
+#include <unordered_map>
+
+using namespace std;
+
+namespace operator_counting {
+
+FlowConstraints::FlowConstraints(const plugins::Options &opts)
+ : pattern_generator(opts.get<shared_ptr<pdbs::PatternCollectionGenerator>>("patterns")),
+ remove_dead_states(opts.get<bool>("remove_dead_states")),
+ single_transition_optimization(opts.get<bool>("single_transition_optimization")),
+ self_loop_optimization(opts.get<bool>("self_loop_optimization")),
+ weak_linking_constraints(opts.get<bool>("weak_linking_constraints")),
+ use_mutexes(opts.get<bool>("use_mutexes")),
+ partial_merges(opts.get<int>("partial_merges")),
+ max_merge_feature_size(opts.get<int>("max_merge_feature_size")),
+ partial_merge_time_limit(opts.get<double>("partial_merge_time_limit")),
+ lp_solve_time_limit(opts.get<double>("merge_lp_solve_time_limit")),
+ merge_goal_only(opts.get<bool>("merge_goal_only")),
+ merge_preconditions(opts.get<int>("merge_preconditions")),
+ merge_effects(opts.get<int>("merge_effects")){
+}
+
+void FlowConstraints::initialize_constraints(const shared_ptr<AbstractTask> &task,
+ lp::LinearProgram &lp) {
+ assert(pattern_generator);
+ pdbs::PatternCollectionInformation pattern_collection_info =
+ pattern_generator->generate(task);
+ shared_ptr<pdbs::PatternCollection> patterns = pattern_collection_info.get_patterns();
+ //pattern_generator = nullptr;
+
+ int num_maximal_abstract_states = 0;
+ int num_actual_abstract_states = 0;
+ TaskProxy task_proxy(*task);
+ VariablesProxy vars = task_proxy.get_variables();
+
+ utils::Timer constraint_generation_timer;
+
+ sub_constraints.reserve(patterns->size());
+ for (const pdbs::Pattern &pattern : *patterns) {
+ FlowConstraintSettings settings;
+ settings.pattern = pattern;
+ settings.remove_dead_states = remove_dead_states;
+ settings.single_transition_optimization = single_transition_optimization;
+ settings.self_loop_optimization = self_loop_optimization;
+ settings.weak_linking_constraints = weak_linking_constraints;
+ settings.use_mutexes = use_mutexes;
+ sub_constraints.emplace_back(*task, lp, settings);
+
+ int num_abstract_states = 1;
+ for (int v : pattern) {
+ num_abstract_states *= vars[v].get_domain_size();
+ }
+ num_maximal_abstract_states += num_abstract_states;
+ num_actual_abstract_states += sub_constraints.back().get_num_abstract_states();
+ }
+
+ if (partial_merges == 1) {