Generated on for Gecode by doxygen 1.15.0
int.cpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Mikael Zayenz Lagerkvist <lagerkvist@gecode.dev>
5 *
6 * Copyright:
7 * Mikael Zayenz Lagerkvist, 2006
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.dev
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34#include "test/branch.hh"
35
36#include <gecode/int/branch.hh>
37#include <gecode/search.hh>
38
39namespace Test { namespace Branch {
40
43 public:
46
49 : x(*this, 4, 0, 1) {
55 };
56 // Post directly so the random selector remains first in the tie chain.
58 *this, xv, vs,
60 [](const Gecode::Space&, Gecode::IntVar, int i) {
61 return (i == 0) || (i == 2);
62 }, nullptr);
63 }
64
67 : Gecode::Space(s) {
68 x.update(*this, s.x);
69 }
70
72 virtual Gecode::Space* copy(void) {
73 return new FilteredRndTiesSpace(*this);
74 }
75 };
76
78 class FilteredRndTies : public Base {
79 public:
82 : Base("Int::Branch::FilteredRndTies") {}
83
85 virtual bool run(void) {
86 bool selected[2] = {false, false};
87
88 for (unsigned int seed = 1; seed <= 16; seed++) {
91 if (probe->status() != Gecode::SS_BRANCH) {
92 delete probe;
93 return false;
94 }
95 const Gecode::Choice* c = probe->choice();
96 const Gecode::PosChoice& pc
97 = static_cast<const Gecode::PosChoice&>(*c);
98 const int p = pc.pos().pos;
99 delete c;
100 delete probe;
101 if ((p != 0) && (p != 2))
102 return false;
103 selected[p == 2] = true;
104
108 o.c_d = 2;
109 o.a_d = 1;
111 delete root;
112
113 int n = 0;
114 while (Gecode::Space* s = e.next()) {
115 FilteredRndTiesSpace* solution =
116 static_cast<FilteredRndTiesSpace*>(s);
117 if (solution->x[1].assigned() || solution->x[3].assigned()) {
118 delete solution;
119 return false;
120 }
121 delete solution;
122 n++;
123 }
124 if (n != 4)
125 return false;
126 }
127
128 return selected[0] && selected[1];
129 }
130 };
131
133
135 class Int : public IntTest {
136 public:
138 Int(const std::string& s, const Gecode::IntSet& d, int n)
139 : IntTest(s,n,d) {}
140
141 virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
142 Gecode::distinct(home, x);
143 }
144 };
145
147 const int v_sparse[5] = {-100,-10,0,10,100};
149
151
152 Int d_3("Dense::3",d_dense,3);
153 Int d_5("Dense::5",d_dense,5);
154 Int s_3("Sparse::3",d_sparse,3);
155 Int s_5("Sparse::5",d_sparse,5);
156 Int l_2("Large::2",d_large,2);
157 Int l_3("Large::3",d_large,3);
158
159}}
160
161// STATISTICS: test-branch
Choice for performing commit
Definition core.hpp:1423
Depth-first search engine.
Definition search.hh:1080
Integer sets.
Definition int.hh:178
Passing integer variables.
Definition int.hh:680
Integer variable array.
Definition int.hh:791
Integer variables.
Definition int.hh:389
Choices storing position
Definition view.hpp:55
const Pos & pos(void) const
Return position in array.
Definition view.hpp:126
const int pos
Position of view.
Definition view.hpp:47
Random number generator.
Definition rnd.hpp:42
virtual T * next(void)
Return next solution (nullptr, if none exists or search has been stopped).
Definition base.hpp:46
Search engine options
Definition search.hh:751
unsigned int c_d
Create a clone after every c_d commits (commit distance).
Definition search.hh:758
unsigned int a_d
Create a clone during recomputation if distance is greater than a_d (adaptive distance).
Definition search.hh:760
Computation spaces.
Definition core.hpp:1775
bool assigned(void) const
Test if all variables are assigned.
Definition array.hpp:1036
View arrays.
Definition array.hpp:255
Abstract class for view selection.
Definition view-sel.hpp:44
Base(std::string s)
Create and register test with name s.
Definition test.cpp:60
Space for testing filtered random tie selection.
Definition int.cpp:42
virtual Gecode::Space * copy(void)
Copy space during cloning.
Definition int.cpp:72
FilteredRndTiesSpace(FilteredRndTiesSpace &s)
Constructor for cloning.
Definition int.cpp:66
FilteredRndTiesSpace(Gecode::Rnd r)
Initialize space.
Definition int.cpp:48
Gecode::IntVarArray x
Variables to branch on.
Definition int.cpp:45
Test filtered random tie selection with accepted and rejected views.
Definition int.cpp:78
virtual bool run(void)
Run test.
Definition int.cpp:85
FilteredRndTies(void)
Create and register test.
Definition int.cpp:81
IntTest(const std::string &s, int a, const Gecode::IntSet &d)
Construct and register test.
Definition branch.cpp:430
Test brancher with distinct propagator
Definition int.cpp:135
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post propagators on variables x.
Definition int.cpp:141
Int(const std::string &s, const Gecode::IntSet &d, int n)
Create and register test.
Definition int.cpp:138
Space(void)
Default constructor.
Definition core.cpp:121
const Choice * choice(void)
Create new choice for current brancher.
Definition core.cpp:568
SpaceStatus status(StatusStatistics &stat)
Query space status.
Definition core.cpp:282
@ SS_BRANCH
Space must be branched (at least one brancher left)
Definition core.hpp:1717
ViewSel< IntView > * viewsel(Space &home, const IntVarBranch &ivb)
Return view selectors for integer views.
Definition view-sel.cpp:39
ValSelCommitBase< IntView, int > * valselcommit(Space &home, const IntValBranch &ivb)
Return value and commit for integer views.
Gecode toplevel namespace
void distinct(Home home, const IntVarArgs &x, IntPropLevel ipl=IPL_DEF)
Post propagator for for all .
Definition distinct.cpp:46
void postviewvalbrancher(Home home, ViewArray< View > &x, ViewSel< View > *vs[n], ValSelCommitBase< View, Val > *vsc, BranchFilter< typename View::VarType > bf, VarValPrint< typename View::VarType, Val > vvp)
Post view value brancher.
Definition view-val.hpp:341
IntValBranch INT_VAL_MIN(void)
Select smallest value.
Definition val.hpp:55
IntVarBranch INT_VAR_RND(Rnd r)
Select random variable (uniform distribution, for tie breaking).
Definition var.hpp:101
IntVarBranch INT_VAR_SIZE_MIN(BranchTbl tbl=nullptr)
Select variable with smallest domain size.
Definition var.hpp:206
Tests for branchings.
Definition branch.cpp:58
Int d_5("Dense::5", d_dense, 5)
Gecode::IntSet d_sparse(v_sparse, 5)
Int s_3("Sparse::3", d_sparse, 3)
Gecode::IntSet d_large(-2, 10)
FilteredRndTies filtered_rnd_ties
Definition int.cpp:132
Int s_5("Sparse::5", d_sparse, 5)
const int v_sparse[5]
Definition int.cpp:147
Int l_3("Large::3", d_large, 3)
Int d_3("Dense::3", d_dense, 3)
Gecode::IntSet d_dense(-2, 2)
Int l_2("Large::2", d_large, 2)
General test support.
Definition afc.cpp:39
Region r
Definition region.cpp:65