Skip to content

Commit f8f8859

Browse files
committed
add failing pruning test for branching propagator
1 parent a82b883 commit f8f8859

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

core/test/test_serial.cpp

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,32 @@ struct GeneratorMockup : Generator
5757
class PropagatorMockup : public PropagatingEitherWay
5858
{
5959
PredefinedCosts costs_;
60+
std::size_t solutions_per_compute_;
6061

6162
public:
62-
PropagatorMockup(std::initializer_list<double> costs = { 0.0 }) : PropagatingEitherWay(), costs_(false, costs) {}
63+
PropagatorMockup(std::initializer_list<double> costs = { 0.0 }, std::size_t solutions_per_compute = 1)
64+
: PropagatingEitherWay(), costs_(false, costs), solutions_per_compute_(solutions_per_compute) {}
6365

6466
void computeForward(const InterfaceState& from) override {
65-
SubTrajectory solution(robot_trajectory::RobotTrajectoryConstPtr(), costs_.cost());
66-
sendForward(from, InterfaceState(from.scene()->diff()), std::move(solution));
67+
for (std::size_t i = 0; i < solutions_per_compute_; ++i) {
68+
SubTrajectory solution(robot_trajectory::RobotTrajectoryConstPtr(), costs_.cost());
69+
sendForward(from, InterfaceState(from.scene()->diff()), std::move(solution));
70+
}
6771
}
6872
void computeBackward(const InterfaceState& to) override {
69-
SubTrajectory solution(robot_trajectory::RobotTrajectoryConstPtr(), costs_.cost());
70-
sendBackward(InterfaceState(to.scene()->diff()), to, std::move(solution));
73+
for (std::size_t i = 0; i < solutions_per_compute_; ++i) {
74+
SubTrajectory solution(robot_trajectory::RobotTrajectoryConstPtr(), costs_.cost());
75+
sendBackward(InterfaceState(to.scene()->diff()), to, std::move(solution));
76+
}
7177
}
7278
};
7379
class ForwardMockup : public PropagatorMockup
7480
{
7581
static unsigned int id_;
7682

7783
public:
78-
ForwardMockup(std::initializer_list<double> costs = { 0.0 }) : PropagatorMockup(costs) {
84+
ForwardMockup(std::initializer_list<double> costs = { 0.0 }, std::size_t solutions_per_compute = 1)
85+
: PropagatorMockup(costs, solutions_per_compute) {
7986
restrictDirection(FORWARD);
8087
setName("FW" + std::to_string(++id_));
8188
}
@@ -95,7 +102,7 @@ class BackwardMockup : public PropagatorMockup
95102
struct ForwardDummy : PropagatingForward
96103
{
97104
using PropagatingForward::PropagatingForward;
98-
void computeForward(const InterfaceState& from) override {}
105+
void computeForward(const InterfaceState& /*from*/) override {}
99106
};
100107

101108
/* Connect creating solutions with given costs */
@@ -176,6 +183,28 @@ TEST(ConnectConnect, PruningForward) {
176183
EXPECT_EQ(c2->calls_, 6u);
177184
}
178185

186+
TEST(ConnectConnect, PruningMultiForward) {
187+
GeneratorMockup::id_ = Connect::id_ = 0; // reset IDs
188+
Task t;
189+
190+
t.setRobotModel(getModel());
191+
t.add(Stage::pointer(new GeneratorMockup()));
192+
t.add(Stage::pointer(new Connect()));
193+
t.add(Stage::pointer(new BackwardMockup()));
194+
/* TODO(v4hn):
195+
* t.add(Stage::pointer(new GeneratorMockup()));
196+
* should be enough instead of the above, but propagators do not even respect ENABLED/DISABLED yet
197+
*/
198+
199+
t.add(Stage::pointer(new GeneratorMockup()));
200+
t.add(Stage::pointer(new ForwardMockup({ 0, 0 }, 2))); // spawn two solutions for the only incoming state
201+
t.add(Stage::pointer(new ForwardMockup({ 0, inf })));
202+
t.plan();
203+
204+
ASSERT_EQ(t.solutions().size(), 1);
205+
EXPECT_EQ((*t.solutions().begin())->cost(), 0u);
206+
}
207+
179208
TEST(ConnectConnect, PruningBackward) {
180209
GeneratorMockup::id_ = Connect::id_ = 0; // reset IDs
181210
Task t;

0 commit comments

Comments
 (0)