Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
exec.cpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.org>
5 *
6 * Copyright:
7 * Christian Schulte, 2009
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.org
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/set.hh"
35
36namespace Test { namespace Set {
37
39 namespace Exec {
40
47 class Wait : public SetTest {
48 protected:
50 bool sf;
51 public:
53 Wait(int n, bool sf0)
54 : SetTest("Wait::"+str(n)+"::"+
55 (sf0 ? "std::function" : "funptr"),n,
56 Gecode::IntSet(0,n),false), sf(sf0) {}
58 virtual bool solution(const SetAssignment& x) const {
59 (void) x;
60 return true;
61 }
65 using namespace Gecode;
66 auto f = static_cast<std::function<void(Space&)>>
67 ([](Space& home) { c(home); });
68 if (x.size() > 1) {
69 if (sf)
70 Gecode::wait(home, x, f);
71 else
72 Gecode::wait(home, x, &c);
73 } else {
74 if (sf)
75 Gecode::wait(home, x[0], f);
76 else
77 Gecode::wait(home, x[0], &c);
78 }
79 }
81 static void c(Gecode::Space& _home) {
82 SetTestSpace& home = static_cast<SetTestSpace&>(_home);
83 for (int i=0; i<home.x.size(); i++)
84 if (!home.x[i].assigned())
85 home.fail();
86 }
87 };
88
89 Wait w1t(1,true), w2t(2,true);
90 Wait w1f(1,false), w2f(2,false);
91
93
94 }
95
96}}
97
98// STATISTICS: test-int
int n
Number of negative literals for node type.
Node * x
Pointer to corresponding Boolean expression node.
Integer variable array.
Definition int.hh:763
Set variable array
Definition set.hh:570
Computation spaces.
Definition core.hpp:1742
bool assigned(void) const
Test if all variables are assigned.
Definition array.hpp:1026
int size(void) const
Return size of array (number of elements)
Definition array.hpp:926
Simple test for wait (set variables)
Definition exec.cpp:47
Wait(int n, bool sf0)
Create and register test.
Definition exec.cpp:53
virtual void post(Gecode::Space &home, Gecode::SetVarArray &x, Gecode::IntVarArray &)
Post wait on x.
Definition exec.cpp:63
bool sf
Whether to use std::function.
Definition exec.cpp:50
static void c(Gecode::Space &_home)
Continuation to be executed.
Definition exec.cpp:81
virtual bool solution(const SetAssignment &x) const
Check whether x is solution.
Definition exec.cpp:58
Generate all set assignments.
Definition set.hh:142
Space for executing set tests.
Definition set.hh:182
Gecode::SetVarArray x
Set variables to be tested.
Definition set.hh:187
Base class for tests with set constraints
Definition set.hh:273
static std::string str(Gecode::SetRelType srt)
Map set relation to string.
Definition set.hpp:46
void fail(void)
Fail space.
Definition core.hpp:4030
Gecode toplevel namespace
Wait w2t(2, true)
Wait w1f(1, false)
Wait w1t(1, true)
Wait w2f(2, false)
General test support.
Definition afc.cpp:39