Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
channel.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 * Vincent Barichard <Vincent.Barichard@univ-angers.fr>
6 *
7 * Copyright:
8 * Christian Schulte, 2006
9 * Vincent Barichard, 2012
10 *
11 * This file is part of Gecode, the generic constraint
12 * development environment:
13 * http://www.gecode.org
14 *
15 * Permission is hereby granted, free of charge, to any person obtaining
16 * a copy of this software and associated documentation files (the
17 * "Software"), to deal in the Software without restriction, including
18 * without limitation the rights to use, copy, modify, merge, publish,
19 * distribute, sublicense, and/or sell copies of the Software, and to
20 * permit persons to whom the Software is furnished to do so, subject to
21 * the following conditions:
22 *
23 * The above copyright notice and this permission notice shall be
24 * included in all copies or substantial portions of the Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 *
34 */
35
36#include "test/float.hh"
37
38#include <gecode/minimodel.hh>
39
40namespace Test { namespace Float {
41
43 namespace Channel {
44
46 class Int : public Test {
47 public:
50 : Test("Channel::Int",2,-1,2,st,CPLT_ASSIGNMENT,false) {}
52 virtual MaybeType solution(const Assignment& x) const {
54 return (((modf(x[0].min(),&tmp)==0) ||
55 (modf(x[0].max(),&tmp)==0))
56 && (x[0]==x[1])) ? MT_TRUE : MT_FALSE;
57 }
59 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
60 using namespace Gecode;
61 IntVar iv(home,-1000,1000);
62 channel(home, x[0], iv);
63 channel(home, iv, x[1]);
64 }
65 };
66
68 class Bool : public Test {
69 public:
72 : Test("Channel::Bool",2,0,1,st,CPLT_ASSIGNMENT,false) {}
74 virtual MaybeType solution(const Assignment& x) const {
76 return (((modf(x[0].min(),&tmp)==0) ||
77 (modf(x[0].max(),&tmp)==0))
78 && (x[0]==x[1])) ? MT_TRUE : MT_FALSE;
79 }
81 virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
82 using namespace Gecode;
83 BoolVar bv(home,0,1);
84 channel(home, x[0], bv);
85 channel(home, bv, x[1]);
86 }
87 };
88
91
95
96 }
97}}
98
99// STATISTICS: test-float
100
Node * x
Pointer to corresponding Boolean expression node.
Boolean integer variables.
Definition int.hh:512
Float variable array.
Definition float.hh:1030
Integer variables.
Definition int.hh:371
Computation spaces.
Definition core.hpp:1742
Base class for assignments
Definition float.hh:80
Test channel between float and Boolean
Definition channel.cpp:68
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Definition channel.cpp:81
Bool(Gecode::FloatNum st)
Construct and register test.
Definition channel.cpp:71
virtual MaybeType solution(const Assignment &x) const
Check whether x is solution.
Definition channel.cpp:74
Test channel between float and integer
Definition channel.cpp:46
virtual MaybeType solution(const Assignment &x) const
Check whether x is solution.
Definition channel.cpp:52
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Definition channel.cpp:59
Int(Gecode::FloatNum st)
Construct and register test.
Definition channel.cpp:49
double FloatNum
Floating point number base type.
Definition float.hh:106
Gecode toplevel namespace
Gecode::FloatNum step2
Definition channel.cpp:90
Gecode::FloatNum step1
Definition channel.cpp:89
@ CPLT_ASSIGNMENT
Definition float.hh:62
MaybeType
Type for comparisons and solutions.
Definition float.hh:51
General test support.
Definition afc.cpp:39