Generated on Sat Feb 7 2015 02:01:21 for Gecode by doxygen 1.8.9.1
tree.hpp
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, 2009
8  *
9  * Last modified:
10  * $Date: 2011-05-25 16:56:41 +0200 (Wed, 25 May 2011) $ by $Author: schulte $
11  * $Revision: 12022 $
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 <algorithm>
39 
40 namespace Gecode { namespace Int { namespace Unary {
41 
42  /*
43  * Omega tree
44  */
45 
46  forceinline void
48  p = 0; ect = -Int::Limits::infinity;
49  }
50 
51  forceinline void
53  p = l.p + r.p;
54  ect = std::max(plus(l.ect,r.p), r.ect);
55  }
56 
57  template<class TaskView>
59  : TaskTree<TaskView,OmegaNode>(r,t) {
60  for (int i=tasks.size(); i--; ) {
61  leaf(i).p = 0; leaf(i).ect = -Int::Limits::infinity;
62  }
63  init();
64  }
65 
66  template<class TaskView>
67  forceinline void
69  leaf(i).p = tasks[i].pmin();
70  leaf(i).ect = tasks[i].est()+tasks[i].pmin();
71  update(i);
72  }
73 
74  template<class TaskView>
75  forceinline void
77  leaf(i).p = 0; leaf(i).ect = -Int::Limits::infinity;
78  update(i);
79  }
80 
81  template<class TaskView>
82  forceinline int
84  return root().ect;
85  }
86 
87  template<class TaskView>
88  forceinline int
90  // Check whether task i is in?
91  OmegaTree<TaskView>& o = const_cast<OmegaTree<TaskView>&>(*this);
92  if (o.leaf(i).ect != -Int::Limits::infinity) {
93  o.remove(i);
94  int ect = o.root().ect;
95  o.insert(i);
96  return ect;
97  } else {
98  return root().ect;
99  }
100  }
101 
102 
103 
104  /*
105  * Ome lambda tree
106  */
107 
108  forceinline void
110  OmegaNode::init(l,r);
111  lp = p; lect = ect; resEct = undef; resLp = undef;
112  }
113 
114  forceinline void
116  OmegaNode::update(l,r);
117  if (l.lp + r.p > l.p + r.lp) {
118  resLp = l.resLp;
119  lp = l.lp + r.p;
120  } else {
121  resLp = r.resLp;
122  lp = l.p + r.lp;
123  }
124  if ((r.lect >= plus(l.ect,r.lp)) && (r.lect >= plus(l.lect,r.p))) {
125  lect = r.lect; resEct = r.resEct;
126  } else if (plus(l.ect,r.lp) >= plus(l.lect,r.p)) {
127  assert(plus(l.ect,r.lp) > r.lect);
128  lect = plus(l.ect,r.lp); resEct = r.resLp;
129  } else {
130  assert((plus(l.lect,r.p) > r.lect) &&
131  (plus(l.lect,r.p) > plus(l.ect,r.lp)));
132  lect = plus(l.lect,r.p); resEct = l.resEct;
133  }
134  }
135 
136 
137  template<class TaskView>
139  const TaskViewArray<TaskView>& t,
140  bool inc)
141  : TaskTree<TaskView,OmegaLambdaNode>(r,t) {
142  if (inc) {
143  // Enter all tasks into tree (omega = all tasks, lambda = empty)
144  for (int i=tasks.size(); i--; ) {
145  leaf(i).p = leaf(i).lp = tasks[i].pmin();
146  leaf(i).ect = leaf(i).lect = tasks[i].est()+tasks[i].pmin();
147  leaf(i).resEct = OmegaLambdaNode::undef;
148  leaf(i).resLp = OmegaLambdaNode::undef;
149  }
150  update();
151  } else {
152  // Enter no tasks into tree (omega = empty, lambda = empty)
153  for (int i=tasks.size(); i--; ) {
154  leaf(i).p = leaf(i).lp = 0;
155  leaf(i).ect = leaf(i).lect = -Int::Limits::infinity;
156  leaf(i).resEct = OmegaLambdaNode::undef;
157  leaf(i).resLp = OmegaLambdaNode::undef;
158  }
159  init();
160  }
161  }
162 
163  template<class TaskView>
164  forceinline void
166  // That means that i is in omega
167  assert(leaf(i).ect > -Int::Limits::infinity);
168  leaf(i).p = 0;
169  leaf(i).ect = -Int::Limits::infinity;
170  leaf(i).resEct = i;
171  leaf(i).resLp = i;
172  update(i);
173  }
174 
175  template<class TaskView>
176  forceinline void
178  leaf(i).p = tasks[i].pmin();
179  leaf(i).ect = tasks[i].est()+tasks[i].pmin();
180  update(i);
181  }
182 
183  template<class TaskView>
184  forceinline void
186  leaf(i).lp = tasks[i].pmin();
187  leaf(i).lect = tasks[i].est()+tasks[i].pmin();
188  leaf(i).resEct = i;
189  leaf(i).resLp = i;
190  update(i);
191  }
192 
193  template<class TaskView>
194  forceinline void
196  leaf(i).lp = 0;
197  leaf(i).lect = -Int::Limits::infinity;
198  leaf(i).resEct = OmegaLambdaNode::undef;
199  leaf(i).resLp = OmegaLambdaNode::undef;
200  update(i);
201  }
202 
203  template<class TaskView>
204  forceinline bool
206  return root().resEct < 0;
207  }
208 
209  template<class TaskView>
210  forceinline int
212  return root().resEct;
213  }
214 
215  template<class TaskView>
216  forceinline int
218  return root().ect;
219  }
220 
221  template<class TaskView>
222  forceinline int
224  return root().lect;
225  }
226 
227 }}}
228 
229 // STATISTICS: int-prop
int resEct
Node which is responsible for lect.
Definition: unary.hh:704
Node for an omega tree.
Definition: unary.hh:660
NodeType t
Type of node.
Definition: bool-expr.cpp:234
Task view array.
Definition: task.hh:233
void init(const OmegaLambdaNode &l, const OmegaLambdaNode &r)
Initialize node from left child l and right child r.
Definition: tree.hpp:109
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
bool lempty(void) const
Whether has responsible task.
Definition: tree.hpp:205
const FloatNum max
Largest allowed float value.
Definition: float.hh:831
int lp
Processing times for subtree.
Definition: unary.hh:700
void update(const OmegaNode &l, const OmegaNode &r)
Update node from left child l and right child r.
Definition: tree.hpp:52
void linsert(int i)
Insert task with index i to lambda.
Definition: tree.hpp:185
Handle to region.
Definition: region.hpp:61
int ect
Earliest completion time for subtree.
Definition: unary.hh:665
void insert(int i)
Insert task with index i.
Definition: tree.hpp:68
int lect
Earliest completion times for subtree.
Definition: unary.hh:702
void oinsert(int i)
Insert task with index i to omega.
Definition: tree.hpp:177
Omega trees for computing ect of task sets.
Definition: unary.hh:674
Gecode::IntArgs i(4, 1, 2, 3, 4)
void update(const OmegaLambdaNode &l, const OmegaLambdaNode &r)
Update node from left child l and right child r.
Definition: tree.hpp:115
void update(void)
Update all inner nodes of tree after leaves have been initialized.
void remove(int i)
Remove task with index i.
Definition: tree.hpp:76
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
void init(void)
Initialize tree after leaves have been initialized.
Node for an omega lambda tree.
Definition: unary.hh:695
int plus(int x, int y)
Safe addition in case x is -IntLimits::infinity.
Definition: tree.hpp:43
int lect(void) const
Return earliest completion time of all tasks excluding lambda tasks.
Definition: tree.hpp:223
int responsible(void) const
Return responsible task.
Definition: tree.hpp:211
int resLp
Node which is responsible for lp.
Definition: unary.hh:706
OmegaLambdaTree(Region &r, const TaskViewArray< TaskView > &t, bool inc=true)
Initialize tree for tasks t with all tasks included, if inc is true.
Definition: tree.hpp:138
const int infinity
Infinity for integers.
Definition: int.hh:117
OmegaTree(Region &r, const TaskViewArray< TaskView > &t)
Initialize tree for tasks t.
Definition: tree.hpp:58
int ect(void) const
Return earliest completion time of all tasks.
Definition: tree.hpp:83
#define forceinline
Definition: config.hpp:132
void lremove(int i)
Remove task with index i from lambda.
Definition: tree.hpp:195
OmegaNode & leaf(int i)
Return leaf for task i.
void init(const OmegaNode &l, const OmegaNode &r)
Initialize node from left child l and right child r.
Definition: tree.hpp:47
void shift(int i)
Shift task with index i from omega to lambda.
Definition: tree.hpp:165
Gecode toplevel namespace
const OmegaNode & root(void) const
Return root node.
const TaskViewArray< TaskView > & tasks
The tasks from which the tree is computed.
Definition: task.hh:369
int ect(void) const
Return earliest completion time of all tasks.
Definition: tree.hpp:217
static const int undef
Undefined task.
Definition: unary.hh:698
Task trees for task views with node type Node.
Definition: task.hh:365
int p
Processing time for subtree.
Definition: unary.hh:663