Generated on Sat Feb 7 2015 02:01:14 for Gecode by doxygen 1.8.9.1
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  * Last modified:
10  * $Date: 2010-10-04 10:01:21 +0200 (Mon, 04 Oct 2010) $ by $Author: schulte $
11  * $Revision: 11440 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #include <gecode/int.hh>
39 
40 namespace Gecode {
41 
42  IntArgs::IntArgs(int n, int e0, ...) : PrimArgArray<int>(n) {
43  va_list args;
44  va_start(args, e0);
45  a[0] = e0;
46  for (int i = 1; i < n; i++)
47  a[i] = va_arg(args,int);
48  va_end(args);
49  }
50 
51  IntVarArray::IntVarArray(Space& home, int n, int min, int max)
52  : VarArray<IntVar>(home,n) {
53  Int::Limits::check(min,"IntVarArray::IntVarArray");
54  Int::Limits::check(max,"IntVarArray::IntVarArray");
55  if (min > max)
56  throw Int::VariableEmptyDomain("IntVarArray::IntVarArray");
57  for (int i = size(); i--; )
58  x[i]._init(home,min,max);
59  }
60 
61  IntVarArray::IntVarArray(Space& home, int n, const IntSet& s)
62  : VarArray<IntVar>(home,n) {
63  Int::Limits::check(s.min(),"IntVarArray::IntVarArray");
64  Int::Limits::check(s.max(),"IntVarArray::IntVarArray");
65  if (s.size() == 0)
66  throw Int::VariableEmptyDomain("IntVarArray::IntVarArray");
67  for (int i = size(); i--; )
68  x[i]._init(home,s);
69  }
70 
71  BoolVarArray::BoolVarArray(Space& home, int n, int min, int max)
72  : VarArray<BoolVar>(home, n) {
73  if ((min < 0) || (max > 1))
74  throw Int::NotZeroOne("BoolVarArray::BoolVarArray");
75  if (min > max)
76  throw Int::VariableEmptyDomain("BoolVarArray::BoolVarArray");
77  for (int i = size(); i--; )
78  x[i]._init(home,min,max);
79  }
80 
81  IntVarArgs::IntVarArgs(Space& home, int n, int min, int max)
82  : VarArgArray<IntVar>(n) {
83  Int::Limits::check(min,"IntVarArgs::IntVarArgs");
84  Int::Limits::check(max,"IntVarArgs::IntVarArgs");
85  if (min > max)
86  throw Int::VariableEmptyDomain("IntVarArgs::IntVarArgs");
87  for (int i = size(); i--; )
88  a[i]._init(home,min,max);
89  }
90 
91  IntVarArgs::IntVarArgs(Space& home, int n, const IntSet& s)
92  : VarArgArray<IntVar>(n) {
93  Int::Limits::check(s.min(),"IntVarArgs::IntVarArgs");
94  Int::Limits::check(s.max(),"IntVarArgs::IntVarArgs");
95  if (s.size() == 0)
96  throw Int::VariableEmptyDomain("IntVarArgs::IntVarArgs");
97  for (int i = size(); i--; )
98  a[i]._init(home,s);
99  }
100 
101  BoolVarArgs::BoolVarArgs(Space& home, int n, int min, int max)
102  : VarArgArray<BoolVar>(n) {
103  if ((min < 0) || (max > 1))
104  throw Int::NotZeroOne("BoolVarArgs::BoolVarArgs");
105  if (min > max)
106  throw Int::VariableEmptyDomain("BoolVarArgs::BoolVarArgs");
107  for (int i = size(); i--; )
108  a[i]._init(home,min,max);
109  }
110 
111 }
112 
113 // STATISTICS: int-post
IntVarArray(void)
Default constructor (array of size 0)
Definition: array.hpp:80
BoolVarArray(void)
Default constructor (array of size 0)
Definition: array.hpp:96
int size(void) const
Return size of array (number of elements)
Argument array for primtive types.
Definition: array.hpp:640
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:57
Variable arrays
Definition: array.hpp:52
Computation spaces.
Definition: core.hpp:1362
Gecode::IntArgs i(4, 1, 2, 3, 4)
Exception: Variable created with empty domain
Definition: exception.hpp:63
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
IntVarArgs(void)
Allocate empty array.
Definition: int.hh:641
IntArgs(void)
Allocate empty array.
Definition: array.hpp:46
IntVar * x
Array of variables.
Definition: array.hpp:91
Integer sets.
Definition: int.hh:171
unsigned int size(void) const
Return size (cardinality) of set.
Definition: int-set-1.hpp:161
Boolean integer variables.
Definition: int.hh:491
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:75
Integer variables.
Definition: int.hh:350
Exception: Not 0/1 integer
Definition: exception.hpp:55
int n
Number of elements.
Definition: array.hpp:524
BoolVarArgs(void)
Allocate empty array.
Definition: int.hh:695
Gecode toplevel namespace
Argument array for variables.
Definition: array.hpp:53
void check(int n, const char *l)
Check whether n is in range, otherwise throw out of limits with information l.
Definition: limits.hpp:50
int size(void) const
Return size of array (number of elements)
int max(int i) const
Return maximum of range at position i.
Definition: int-set-1.hpp:121
int min(int i) const
Return minimum of range at position i.
Definition: int-set-1.hpp:115
int * a
Element array.
Definition: array.hpp:528