main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Mar 24 2020 14:04:04 for Gecode by
doxygen
1.8.17
test
float
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
40
namespace
Test
{
namespace
Float {
41
43
namespace
Channel {
44
46
class
Int
:
public
Test
{
47
public
:
49
Int
(
Gecode::FloatNum
st)
50
:
Test
(
"Channel::Int"
,2,-1,2,st,
CPLT_ASSIGNMENT
,false) {}
52
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
53
Gecode::FloatNum
tmp;
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
:
71
Bool
(
Gecode::FloatNum
st)
72
:
Test
(
"Channel::Bool"
,2,0,1,st,
CPLT_ASSIGNMENT
,false) {}
74
virtual
MaybeType
solution
(
const
Assignment
&
x
)
const
{
75
Gecode::FloatNum
tmp;
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
89
Gecode::FloatNum
step1
= 0.7;
90
Gecode::FloatNum
step2
= 0.1;
91
92
Int
ci
(
step1
);
93
Bool
cb
(
step2
);
95
96
}
97
}}
98
99
// STATISTICS: test-float
100
minimodel.hh
Test::Float::Channel::Bool
Test channel between float and Boolean
Definition:
channel.cpp:68
Test::Float::Channel::Bool::solution
virtual MaybeType solution(const Assignment &x) const
Check whether x is solution.
Definition:
channel.cpp:74
Test::Float::MT_FALSE
@ MT_FALSE
Definition:
float.hh:52
Test::Float::Channel::cb
Bool cb(step2)
Gecode::Float::Limits::min
const FloatNum min
Smallest allowed float value.
Definition:
float.hh:846
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
Test::Float::MT_TRUE
@ MT_TRUE
Definition:
float.hh:53
Gecode
Gecode toplevel namespace
float.hh
Test::Float::Channel::step2
Gecode::FloatNum step2
Definition:
channel.cpp:90
x
Node * x
Pointer to corresponding Boolean expression node.
Definition:
bool-expr.cpp:249
Test::Float::Channel::Int::solution
virtual MaybeType solution(const Assignment &x) const
Check whether x is solution.
Definition:
channel.cpp:52
Test::Float::Channel::ci
Int ci(step1)
Test::Float::Channel::step1
Gecode::FloatNum step1
Definition:
channel.cpp:89
Gecode::FloatNum
double FloatNum
Floating point number base type.
Definition:
float.hh:106
Gecode::BoolVar
Boolean integer variables.
Definition:
int.hh:512
Test::Float::CPLT_ASSIGNMENT
@ CPLT_ASSIGNMENT
Definition:
float.hh:62
Test::Float::Channel::Bool::post
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Definition:
channel.cpp:81
Gecode::IntVar
Integer variables.
Definition:
int.hh:371
Test::Float::Channel::Int
Test channel between float and integer
Definition:
channel.cpp:46
Test::Float::Channel::Int::post
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Definition:
channel.cpp:59
Test::Float::Channel::Bool::Bool
Bool(Gecode::FloatNum st)
Construct and register test.
Definition:
channel.cpp:71
Test::Float::MaybeType
MaybeType
Type for comparisons and solutions.
Definition:
float.hh:51
Gecode::FloatVarArray
Float variable array.
Definition:
float.hh:1030
Test::Float::Channel::Int::Int
Int(Gecode::FloatNum st)
Construct and register test.
Definition:
channel.cpp:49
Test
General test support.
Definition:
afc.cpp:39
Test::Float::Assignment
Base class for assignments
Definition:
float.hh:80
Gecode::Float::Limits::max
const FloatNum max
Largest allowed float value.
Definition:
float.hh:844
Gecode::channel
void channel(Home home, const SetVarArgs &x, const SetVarArgs &y)
Definition:
channel.cpp:72