Generated on Sat Jun 2 2018 07:17:44 for Gecode by doxygen 1.8.13
array.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, 2002
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 <gecode/int.hh>
35 
36 namespace Gecode {
37 
38  IntArgs::IntArgs(int n, int e0, ...) : PrimArgArray<int>(n) {
39  va_list args;
40  va_start(args, e0);
41  a[0] = e0;
42  for (int i = 1; i < n; i++)
43  a[i] = va_arg(args,int);
44  va_end(args);
45  }
46 
47  IntVarArray::IntVarArray(Space& home, int n, int min, int max)
48  : VarArray<IntVar>(home,n) {
49  Int::Limits::check(min,"IntVarArray::IntVarArray");
50  Int::Limits::check(max,"IntVarArray::IntVarArray");
51  if (min > max)
52  throw Int::VariableEmptyDomain("IntVarArray::IntVarArray");
53  for (int i = size(); i--; )
54  x[i]._init(home,min,max);
55  }
56 
57  IntVarArray::IntVarArray(Space& home, int n, const IntSet& s)
58  : VarArray<IntVar>(home,n) {
59  Int::Limits::check(s.min(),"IntVarArray::IntVarArray");
60  Int::Limits::check(s.max(),"IntVarArray::IntVarArray");
61  if (s.size() == 0)
62  throw Int::VariableEmptyDomain("IntVarArray::IntVarArray");
63  for (int i = size(); i--; )
64  x[i]._init(home,s);
65  }
66 
67  BoolVarArray::BoolVarArray(Space& home, int n, int min, int max)
68  : VarArray<BoolVar>(home, n) {
69  if ((min < 0) || (max > 1))
70  throw Int::NotZeroOne("BoolVarArray::BoolVarArray");
71  if (min > max)
72  throw Int::VariableEmptyDomain("BoolVarArray::BoolVarArray");
73  for (int i = size(); i--; )
74  x[i]._init(home,min,max);
75  }
76 
77  IntVarArgs::IntVarArgs(Space& home, int n, int min, int max)
78  : VarArgArray<IntVar>(n) {
79  Int::Limits::check(min,"IntVarArgs::IntVarArgs");
80  Int::Limits::check(max,"IntVarArgs::IntVarArgs");
81  if (min > max)
82  throw Int::VariableEmptyDomain("IntVarArgs::IntVarArgs");
83  for (int i = size(); i--; )
84  a[i]._init(home,min,max);
85  }
86 
87  IntVarArgs::IntVarArgs(Space& home, int n, const IntSet& s)
88  : VarArgArray<IntVar>(n) {
89  Int::Limits::check(s.min(),"IntVarArgs::IntVarArgs");
90  Int::Limits::check(s.max(),"IntVarArgs::IntVarArgs");
91  if (s.size() == 0)
92  throw Int::VariableEmptyDomain("IntVarArgs::IntVarArgs");
93  for (int i = size(); i--; )
94  a[i]._init(home,s);
95  }
96 
97  BoolVarArgs::BoolVarArgs(Space& home, int n, int min, int max)
98  : VarArgArray<BoolVar>(n) {
99  if ((min < 0) || (max > 1))
100  throw Int::NotZeroOne("BoolVarArgs::BoolVarArgs");
101  if (min > max)
102  throw Int::VariableEmptyDomain("BoolVarArgs::BoolVarArgs");
103  for (int i = size(); i--; )
104  a[i]._init(home,min,max);
105  }
106 
107 }
108 
109 // STATISTICS: int-post
IntVarArray(void)
Default constructor (array of size 0)
Definition: array.hpp:76
BoolVarArray(void)
Default constructor (array of size 0)
Definition: array.hpp:92
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1653
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:969
Argument array for primtive types.
Definition: array.hpp:624
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:49
Variable arrays
Definition: array.hpp:48
Computation spaces.
Definition: core.hpp:1701
int min(int i) const
Return minimum of range at position i.
Definition: int-set-1.hpp:111
Gecode::IntArgs i(4, 1, 2, 3, 4)
Exception: Variable created with empty domain
Definition: exception.hpp:59
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
IntVarArgs(void)
Allocate empty array.
Definition: int.hh:638
IntArgs(void)
Allocate empty array.
Definition: array.hpp:42
IntVar * x
Array of variables.
Definition: array.hpp:87
int max(int i) const
Return maximum of range at position i.
Definition: int-set-1.hpp:117
unsigned int size(void) const
Return size (cardinality) of set.
Definition: int-set-1.hpp:157
Integer sets.
Definition: int.hh:170
int n
Number of variables (size)
Definition: array.hpp:85
Boolean integer variables.
Definition: int.hh:488
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:67
Integer variables.
Definition: int.hh:347
Exception: Not 0/1 integer
Definition: exception.hpp:51
int n
Number of elements.
Definition: array.hpp:511
BoolVarArgs(void)
Allocate empty array.
Definition: int.hh:692
Gecode toplevel namespace
Argument array for variables.
Definition: array.hpp:49
void check(int n, const char *l)
Check whether n is in range, otherwise throw out of limits with information l.
Definition: limits.hpp:46
int * a
Element array.
Definition: array.hpp:515