Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gecode/kernel/branch/view-sel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,8 @@ namespace Gecode {
void
ViewSelRnd<View>::ties(Space& home, ViewArray<View>& x, int s,
int* ties, int& n,
BrancherFilter<View>&) {
n=1; ties[0] = select(home,x,s);
BrancherFilter<View>& f) {
n=1; ties[0] = select(home,x,s,f);
}
template<class View>
void
Expand Down
97 changes: 96 additions & 1 deletion test/branch/int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,104 @@

#include "test/branch.hh"

#include <gecode/int/branch.hh>
#include <gecode/search.hh>

namespace Test { namespace Branch {

/// Space for testing filtered random tie selection
class FilteredRndTiesSpace : public Gecode::Space {
public:
/// Variables to branch on
Gecode::IntVarArray x;

/// Initialize space
FilteredRndTiesSpace(Gecode::Rnd r)
: x(*this, 4, 0, 1) {
Gecode::IntVarArgs xa(x);
Gecode::ViewArray<Gecode::Int::IntView> xv(*this, xa);
Gecode::ViewSel<Gecode::Int::IntView>* vs[2] = {
Gecode::Int::Branch::viewsel(*this, Gecode::INT_VAR_RND(r)),
Gecode::Int::Branch::viewsel(*this, Gecode::INT_VAR_SIZE_MIN())
};
// Post directly so the random selector remains first in the tie chain.
Gecode::postviewvalbrancher<Gecode::Int::IntView,2,int,2>(
*this, xv, vs,
Gecode::Int::Branch::valselcommit(*this, Gecode::INT_VAL_MIN()),
[](const Gecode::Space&, Gecode::IntVar, int i) {
return (i == 0) || (i == 2);
}, nullptr);
}

/// Constructor for cloning
FilteredRndTiesSpace(FilteredRndTiesSpace& s)
: Gecode::Space(s) {
x.update(*this, s.x);
}

/// Copy space during cloning
virtual Gecode::Space* copy(void) {
return new FilteredRndTiesSpace(*this);
}
};

/// Test filtered random tie selection with accepted and rejected views
class FilteredRndTies : public Base {
public:
/// Create and register test
FilteredRndTies(void)
: Base("Int::Branch::FilteredRndTies") {}

/// Run test
virtual bool run(void) {
bool selected[2] = {false, false};

for (unsigned int seed = 1; seed <= 16; seed++) {
FilteredRndTiesSpace* probe =
new FilteredRndTiesSpace(Gecode::Rnd(seed));
if (probe->status() != Gecode::SS_BRANCH) {
delete probe;
return false;
}
const Gecode::Choice* c = probe->choice();
const Gecode::PosChoice& pc
= static_cast<const Gecode::PosChoice&>(*c);
const int p = pc.pos().pos;
delete c;
delete probe;
if ((p != 0) && (p != 2))
return false;
selected[p == 2] = true;

FilteredRndTiesSpace* root =
new FilteredRndTiesSpace(Gecode::Rnd(seed));
Gecode::Search::Options o;
o.c_d = 2;
o.a_d = 1;
Gecode::DFS<FilteredRndTiesSpace> e(root, o);
delete root;

int n = 0;
while (Gecode::Space* s = e.next()) {
FilteredRndTiesSpace* solution =
static_cast<FilteredRndTiesSpace*>(s);
if (solution->x[1].assigned() || solution->x[3].assigned()) {
delete solution;
return false;
}
delete solution;
n++;
}
if (n != 4)
return false;
}

return selected[0] && selected[1];
}
};

FilteredRndTies filtered_rnd_ties;

/// %Test brancher with distinct propagator
class Int : public IntTest {
public:
Expand Down Expand Up @@ -63,4 +159,3 @@ namespace Test { namespace Branch {
}}

// STATISTICS: test-branch

Loading