Generated on Sat Feb 7 2015 02:01:16 for Gecode by doxygen 1.8.9.1
linear.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3 o * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  * Vincent Barichard <Vincent.Barichard@univ-angers.fr>
6  *
7  * Copyright:
8  * Christian Schulte, 2002
9  * Vincent Barichard, 2012
10  *
11  * Last modified:
12  * $Date: 2013-01-29 17:43:05 +0100 (Tue, 29 Jan 2013) $ by $Author: schulte $
13  * $Revision: 13241 $
14  *
15  * This file is part of Gecode, the generic constraint
16  * development environment:
17  * http://www.gecode.org
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining
20  * a copy of this software and associated documentation files (the
21  * "Software"), to deal in the Software without restriction, including
22  * without limitation the rights to use, copy, modify, merge, publish,
23  * distribute, sublicense, and/or sell copies of the Software, and to
24  * permit persons to whom the Software is furnished to do so, subject to
25  * the following conditions:
26  *
27  * The above copyright notice and this permission notice shall be
28  * included in all copies or substantial portions of the Software.
29  *
30  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37  *
38  */
39 
40 #include <gecode/float/linear.hh>
41 
42 namespace Gecode {
43 
44  void
45  linear(Home home,
46  const FloatVarArgs& x, FloatRelType frt, FloatNum c) {
47  using namespace Float;
48  if (home.failed()) return;
49  Region re(home);
50  Linear::Term* t = re.alloc<Linear::Term>(x.size());
51  for (int i = x.size(); i--; ) {
52  t[i].a=1.0; t[i].x=x[i];
53  }
54  Linear::post(home,t,x.size(),frt,c);
55  }
56 
57  void
58  linear(Home home,
59  const FloatVarArgs& x, FloatRelType frt, FloatNum c, Reify r) {
60  using namespace Float;
61  if (home.failed()) return;
62  Region re(home);
63  Linear::Term* t = re.alloc<Linear::Term>(x.size());
64  for (int i = x.size(); i--; ) {
65  t[i].a=1.0; t[i].x=x[i];
66  }
67  Linear::post(home,t,x.size(),frt,c,r);
68  }
69 
70  void
71  linear(Home home,
72  const FloatValArgs& a, const FloatVarArgs& x, FloatRelType frt,
73  FloatNum c) {
74  using namespace Float;
75  if (a.size() != x.size())
76  throw ArgumentSizeMismatch("Float::linear");
77  if (home.failed()) return;
78  Region re(home);
79  Linear::Term* t = re.alloc<Linear::Term>(x.size());
80  for (int i = x.size(); i--; ) {
81  t[i].a=a[i]; t[i].x=x[i];
82  }
83  Linear::post(home,t,x.size(),frt,c);
84  }
85 
86  void
87  linear(Home home,
88  const FloatValArgs& a, const FloatVarArgs& x, FloatRelType frt,
89  FloatNum c, Reify r) {
90  using namespace Float;
91  if (a.size() != x.size())
92  throw ArgumentSizeMismatch("Float::linear");
93  if (home.failed()) return;
94  Region re(home);
95  Linear::Term* t = re.alloc<Linear::Term >(x.size());
96  for (int i = x.size(); i--; ) {
97  t[i].a=a[i]; t[i].x=x[i];
98  }
99  Linear::post(home,t,x.size(),frt,c,r);
100  }
101 
102  void
103  linear(Home home,
104  const FloatVarArgs& x, FloatRelType frt, FloatVar y) {
105  using namespace Float;
106  if (home.failed()) return;
107  Region re(home);
108  Linear::Term* t = re.alloc<Linear::Term>(x.size()+1);
109  for (int i = x.size(); i--; ) {
110  t[i].a=1.0; t[i].x=x[i];
111  }
112  FloatNum min, max;
113  estimate(t,x.size(),0.0,min,max);
114  FloatView v(y);
115  switch (frt) {
116  case FRT_EQ:
117  GECODE_ME_FAIL(v.gq(home,min)); GECODE_ME_FAIL(v.lq(home,max));
118  break;
119  case FRT_GQ: case FRT_GR:
120  GECODE_ME_FAIL(v.lq(home,max));
121  break;
122  case FRT_LQ: case FRT_LE:
123  GECODE_ME_FAIL(v.gq(home,min));
124  break;
125  default: ;
126  }
127  if (home.failed()) return;
128  t[x.size()].a=-1.0; t[x.size()].x=y;
129  Linear::post(home,t,x.size()+1,frt,0.0);
130  }
131 
132  void
133  linear(Home home,
134  const FloatVarArgs& x, FloatRelType frt, FloatVar y, Reify r) {
135  using namespace Float;
136  if (home.failed()) return;
137  Region re(home);
138  Linear::Term* t = re.alloc<Linear::Term>(x.size()+1);
139  for (int i = x.size(); i--; ) {
140  t[i].a=1.0; t[i].x=x[i];
141  }
142  t[x.size()].a=-1; t[x.size()].x=y;
143  Linear::post(home,t,x.size()+1,frt,0.0,r);
144  }
145 
146  void
147  linear(Home home,
148  const FloatValArgs& a, const FloatVarArgs& x, FloatRelType frt,
149  FloatVar y) {
150  using namespace Float;
151  if (a.size() != x.size())
152  throw ArgumentSizeMismatch("Float::linear");
153  if (home.failed()) return;
154  Region re(home);
155  Linear::Term* t = re.alloc<Linear::Term>(x.size()+1);
156  for (int i = x.size(); i--; ) {
157  t[i].a=a[i]; t[i].x=x[i];
158  }
159  FloatNum min, max;
160  estimate(t,x.size(),0.0,min,max);
161  FloatView v(y);
162  switch (frt) {
163  case FRT_EQ:
164  GECODE_ME_FAIL(v.gq(home,min)); GECODE_ME_FAIL(v.lq(home,max));
165  break;
166  case FRT_GQ: case FRT_GR:
167  GECODE_ME_FAIL(v.lq(home,max));
168  break;
169  case FRT_LQ: case FRT_LE:
170  GECODE_ME_FAIL(v.gq(home,min));
171  break;
172  default: ;
173  }
174  if (home.failed()) return;
175  t[x.size()].a=-1.0; t[x.size()].x=y;
176  Linear::post(home,t,x.size()+1,frt,0.0);
177  }
178 
179  void
180  linear(Home home,
181  const FloatValArgs& a, const FloatVarArgs& x, FloatRelType frt,
182  FloatVar y, Reify r) {
183  using namespace Float;
184  if (a.size() != x.size())
185  throw ArgumentSizeMismatch("Float::linear");
186  if (home.failed()) return;
187  Region re(home);
188  Linear::Term* t = re.alloc<Linear::Term>(x.size()+1);
189  for (int i = x.size(); i--; ) {
190  t[i].a=a[i]; t[i].x=x[i];
191  }
192  t[x.size()].a=-1.0; t[x.size()].x=y;
193  Linear::post(home,t,x.size()+1,frt,0.0,r);
194  }
195 
196 }
197 
198 // STATISTICS: float-post
bool failed(void) const
Check whether corresponding space is failed.
Definition: core.hpp:3446
Passing float arguments.
Definition: float.hh:937
NodeType t
Type of node.
Definition: bool-expr.cpp:234
void linear(Home home, const FloatVarArgs &x, FloatRelType frt, FloatNum c)
Post propagator for .
Definition: linear.cpp:45
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
Definition: post.cpp:228
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1662
int a
Coefficient.
Definition: linear.hh:1313
T * alloc(long unsigned int n)
Allocate block of n objects of type T from region.
Definition: region.hpp:326
Less or equal ( )
Definition: float.hh:1057
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:57
Passing float variables.
Definition: float.hh:966
Less ( )
Definition: float.hh:1058
Handle to region.
Definition: region.hpp:61
Greater or equal ( )
Definition: float.hh:1059
Gecode::IntArgs i(4, 1, 2, 3, 4)
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
FloatRelType
Relation types for floats.
Definition: float.hh:1054
Reification specification.
Definition: int.hh:854
Equality ( )
Definition: float.hh:1055
Greater ( )
Definition: float.hh:1060
const int v[7]
Definition: distinct.cpp:207
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:75
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
void estimate(Term *t, int n, FloatVal c, FloatNum &l, FloatNum &u)
Estimate lower and upper bounds.
Definition: post.cpp:49
#define GECODE_ME_FAIL(me)
Check whether modification event me is failed, and fail space home.
Definition: macros.hpp:70
Float variables.
Definition: float.hh:857
Class for describing linear term .
Definition: linear.hh:1310
Gecode toplevel namespace
Home class for posting propagators
Definition: core.hpp:717
Exception: Arguments are of different size
Definition: exception.hpp:77
double FloatNum
Floating point number base type.
Definition: float.hh:108
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.