Generated on Sat Feb 7 2015 02:01:21 for Gecode by doxygen 1.8.9.1
task.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  * Guido Tack <tack@gecode.org>
6  *
7  * Copyright:
8  * Christian Schulte, 2009
9  * Guido Tack, 2010
10  *
11  * Last modified:
12  * $Date: 2011-05-25 16:56:41 +0200 (Wed, 25 May 2011) $ by $Author: schulte $
13  * $Revision: 12022 $
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 namespace Gecode { namespace Int { namespace Unary {
41 
42  /*
43  * Mandatory fixed task
44  */
45 
49  ManFixPTask::ManFixPTask(IntVar s, int p) : _s(s), _p(p) {}
50  forceinline void
52  _s=s; _p=p;
53  }
54  forceinline void
56  _s=t._s; _p=t._p;
57  }
58 
59  forceinline int
60  ManFixPTask::est(void) const {
61  return _s.min();
62  }
63  forceinline int
64  ManFixPTask::ect(void) const {
65  return _s.min()+_p;
66  }
67  forceinline int
68  ManFixPTask::lst(void) const {
69  return _s.max();
70  }
71  forceinline int
72  ManFixPTask::lct(void) const {
73  return _s.max()+_p;
74  }
75  forceinline int
76  ManFixPTask::pmin(void) const {
77  return _p;
78  }
79  forceinline int
80  ManFixPTask::pmax(void) const {
81  return _p;
82  }
84  ManFixPTask::st(void) const {
85  return _s;
86  }
87 
88  forceinline bool
89  ManFixPTask::mandatory(void) const {
90  return true;
91  }
92  forceinline bool
93  ManFixPTask::excluded(void) const {
94  return false;
95  }
96  forceinline bool
97  ManFixPTask::optional(void) const {
98  return false;
99  }
100 
101  forceinline bool
102  ManFixPTask::assigned(void) const {
103  return _s.assigned();
104  }
105 
107  ManFixPTask::est(Space& home, int n) {
108  return _s.gq(home,n);
109  }
111  ManFixPTask::ect(Space& home, int n) {
112  return _s.gq(home,n-_p);
113  }
115  ManFixPTask::lst(Space& home, int n) {
116  return _s.lq(home,n);
117  }
119  ManFixPTask::lct(Space& home, int n) {
120  return _s.lq(home,n-_p);
121  }
123  ManFixPTask::norun(Space& home, int e, int l) {
124  if (e <= l) {
126  return _s.minus_r(home,r,false);
127  } else {
128  return Int::ME_INT_NONE;
129  }
130  }
131 
132 
135  return Int::ME_INT_NONE;
136  }
139  return Int::ME_INT_FAILED;
140  }
141 
142  forceinline void
143  ManFixPTask::update(Space& home, bool share, ManFixPTask& t) {
144  _s.update(home,share,t._s); _p=t._p;
145  }
146 
147  forceinline void
149  _s.subscribe(home, p, pc);
150  }
151  forceinline void
153  _s.cancel(home, p, pc);
154  }
155 
156  template<class Char, class Traits>
157  std::basic_ostream<Char,Traits>&
158  operator <<(std::basic_ostream<Char,Traits>& os, const ManFixPTask& t) {
159  std::basic_ostringstream<Char,Traits> s;
160  s.copyfmt(os); s.width(0);
161  s << t.est() << ':' << t.pmin() << ':' << t.lct();
162  return os << s.str();
163  }
164 
165  /*
166  * Mandatory fixed task with fixed processing, start or end time
167  */
168 
173  : ManFixPTask(s,p), _t(t) {}
174  forceinline void
176  ManFixPTask::init(s,p); _t=t;
177  }
178  forceinline void
180  ManFixPTask::init(t0); _t = t0._t;
181  }
182 
183  forceinline int
184  ManFixPSETask::est(void) const {
185  return (_t == TT_FIXS) ? _p : _s.min();
186  }
187  forceinline int
188  ManFixPSETask::ect(void) const {
189  switch (_t) {
190  case TT_FIXP: return _s.min()+_p;
191  case TT_FIXS: return _s.min();
192  case TT_FIXE: return _p;
193  default: GECODE_NEVER;
194  }
195  return 0;
196  }
197  forceinline int
198  ManFixPSETask::lst(void) const {
199  return (_t == TT_FIXS) ? _p : _s.max();
200  }
201  forceinline int
202  ManFixPSETask::lct(void) const {
203  switch (_t) {
204  case TT_FIXP: return _s.max()+_p;
205  case TT_FIXS: return _s.max();
206  case TT_FIXE: return _p;
207  default: GECODE_NEVER;
208  }
209  return 0;
210  }
211  forceinline int
212  ManFixPSETask::pmin(void) const {
213  switch (_t) {
214  case TT_FIXP: return _p;
215  case TT_FIXS: return _s.min()-_p;
216  case TT_FIXE: return _p-_s.max();
217  default: GECODE_NEVER;
218  }
219  return 0;
220  }
221  forceinline int
222  ManFixPSETask::pmax(void) const {
223  switch (_t) {
224  case TT_FIXP: return _p;
225  case TT_FIXS: return _s.max()-_p;
226  case TT_FIXE: return _p-_s.min();
227  default: GECODE_NEVER;
228  }
229  return 0;
230  }
231 
233  ManFixPSETask::est(Space& home, int n) {
234  switch (_t) {
235  case TT_FIXE: // fall through
236  case TT_FIXP: return _s.gq(home,n);
237  case TT_FIXS: return (n <= _p) ? Int::ME_INT_NONE : Int::ME_INT_FAILED;
238  default: GECODE_NEVER;
239  }
240  return Int::ME_INT_NONE;
241  }
243  ManFixPSETask::ect(Space& home, int n) {
244  switch (_t) {
245  case TT_FIXE: return (n <= _p) ? Int::ME_INT_NONE : Int::ME_INT_FAILED;
246  case TT_FIXP: return _s.gq(home,n-_p);
247  case TT_FIXS: return _s.gq(home,n);
248  default: GECODE_NEVER;
249  }
250  return Int::ME_INT_NONE;
251  }
253  ManFixPSETask::lst(Space& home, int n) {
254  switch (_t) {
255  case TT_FIXE: // fall through
256  case TT_FIXP: return _s.lq(home,n);
257  case TT_FIXS: return (n >= _p) ? Int::ME_INT_NONE : Int::ME_INT_FAILED;
258  default: GECODE_NEVER;
259  }
260  return Int::ME_INT_NONE;
261  }
263  ManFixPSETask::lct(Space& home, int n) {
264  switch (_t) {
265  case TT_FIXE: return (n >= _p) ? Int::ME_INT_NONE : Int::ME_INT_FAILED;
266  case TT_FIXP: return _s.lq(home,n-_p);
267  case TT_FIXS: return _s.lq(home,n);
268  default: GECODE_NEVER;
269  }
270  return Int::ME_INT_NONE;
271  }
273  ManFixPSETask::norun(Space& home, int e, int l) {
274  if (e <= l) {
275  switch (_t) {
276  case TT_FIXP:
277  {
279  return _s.minus_r(home,r,false);
280  }
281  case TT_FIXE:
282  if (e <= _p)
283  return _s.gr(home,l);
284  break;
285  case TT_FIXS:
286  if (l >= _p)
287  return _s.lq(home,e);
288  break;
289  default:
290  GECODE_NEVER;
291  }
292  return Int::ME_INT_NONE;
293  } else {
294  return Int::ME_INT_NONE;
295  }
296  }
297 
298  forceinline void
300  ManFixPTask::update(home,share,t); _t=t._t;
301  }
302 
303  template<class Char, class Traits>
304  std::basic_ostream<Char,Traits>&
305  operator <<(std::basic_ostream<Char,Traits>& os, const ManFixPSETask& t) {
306  std::basic_ostringstream<Char,Traits> s;
307  s.copyfmt(os); s.width(0);
308  s << t.est() << ':' << t.pmin() << ':' << t.lct();
309  return os << s.str();
310  }
311 
312  /*
313  * Mandatory flexible task
314  */
315 
320  : _s(s), _p(p), _e(e) {}
321  forceinline void
323  _s=s; _p=p; _e=e;
324  }
325  forceinline void
327  _s=t._s; _p=t._p; _e=t._e;
328  }
329 
330  forceinline int
331  ManFlexTask::est(void) const {
332  return _s.min();
333  }
334  forceinline int
335  ManFlexTask::ect(void) const {
336  return _e.min();
337  }
338  forceinline int
339  ManFlexTask::lst(void) const {
340  return _s.max();
341  }
342  forceinline int
343  ManFlexTask::lct(void) const {
344  return _e.max();
345  }
346  forceinline int
347  ManFlexTask::pmin(void) const {
348  return _p.min();
349  }
350  forceinline int
351  ManFlexTask::pmax(void) const {
352  return _p.max();
353  }
355  ManFlexTask::st(void) const {
356  return _s;
357  }
359  ManFlexTask::p(void) const {
360  return _p;
361  }
363  ManFlexTask::e(void) const {
364  return _e;
365  }
366 
367  forceinline bool
369  return true;
370  }
371  forceinline bool
372  ManFlexTask::excluded(void) const {
373  return false;
374  }
375  forceinline bool
376  ManFlexTask::optional(void) const {
377  return false;
378  }
379 
380  forceinline bool
381  ManFlexTask::assigned(void) const {
382  return _s.assigned() && _p.assigned() && _e.assigned();
383  }
384 
386  ManFlexTask::est(Space& home, int n) {
387  return _s.gq(home,n);
388  }
390  ManFlexTask::ect(Space& home, int n) {
391  return _e.gq(home,n);
392  }
394  ManFlexTask::lst(Space& home, int n) {
395  return _s.lq(home,n);
396  }
398  ManFlexTask::lct(Space& home, int n) {
399  return _e.lq(home,n);
400  }
402  ManFlexTask::norun(Space& home, int e, int l) {
403  if (e <= l) {
404  Iter::Ranges::Singleton sr(e-_p.min()+1,l);
405  if (me_failed(_s.minus_r(home,sr,false)))
406  return Int::ME_INT_FAILED;
407  Iter::Ranges::Singleton er(e+1,_p.min()+l);
408  return _e.minus_r(home,er,false);
409  } else {
410  return Int::ME_INT_NONE;
411  }
412  }
413 
414 
417  return Int::ME_INT_NONE;
418  }
421  return Int::ME_INT_FAILED;
422  }
423 
424  forceinline void
425  ManFlexTask::update(Space& home, bool share, ManFlexTask& t) {
426  _s.update(home,share,t._s);
427  _p.update(home,share,t._p);
428  _e.update(home,share,t._e);
429  }
430 
431  forceinline void
433  _s.subscribe(home, p, pc);
434  _p.subscribe(home, p, pc);
435  _e.subscribe(home, p, pc);
436  }
437  forceinline void
439  _s.cancel(home, p, pc);
440  _p.cancel(home, p, pc);
441  _e.cancel(home, p, pc);
442  }
443 
444  template<class Char, class Traits>
445  std::basic_ostream<Char,Traits>&
446  operator <<(std::basic_ostream<Char,Traits>& os, const ManFlexTask& t) {
447  std::basic_ostringstream<Char,Traits> s;
448  s.copyfmt(os); s.width(0);
449  s << t.est() << ':' << t.lst() << ':' << t.pmin() << ':'
450  << t.pmax() << ':' << t.ect() << ':' << t.lct();
451  return os << s.str();
452  }
453 
454  /*
455  * Optional fixed task
456  */
457 
462  ManFixPTask::init(s,p); _m=m;
463  }
464  forceinline void
466  ManFixPTask::init(s,p); _m=m;
467  }
468 
469  template<class Char, class Traits>
470  std::basic_ostream<Char,Traits>&
471  operator <<(std::basic_ostream<Char,Traits>& os, const OptFixPTask& t) {
472  std::basic_ostringstream<Char,Traits> s;
473  s.copyfmt(os); s.width(0);
474  s << t.est() << ':' << t.pmin() << ':' << t.lct() << ':'
475  << (t.mandatory() ? '1' : (t.optional() ? '?' : '0'));
476  return os << s.str();
477  }
478 
479  /*
480  * Optional fixed task
481  */
482 
487  ManFixPSETask::init(t,s,p); _m=m;
488  }
489  forceinline void
491  ManFixPSETask::init(t,s,p); _m=m;
492  }
493 
494  template<class Char, class Traits>
495  std::basic_ostream<Char,Traits>&
496  operator <<(std::basic_ostream<Char,Traits>& os, const OptFixPSETask& t) {
497  std::basic_ostringstream<Char,Traits> s;
498  s.copyfmt(os); s.width(0);
499  s << t.est() << ':' << t.pmin() << ':' << t.lct() << ':'
500  << (t.mandatory() ? '1' : (t.optional() ? '?' : '0'));
501  return os << s.str();
502  }
503 
504  /*
505  * Optional flexible task
506  */
507 
512  ManFlexTask::init(s,p,e); _m=m;
513  }
514  forceinline void
516  ManFlexTask::init(s,p,e); _m=m;
517  }
518 
519  template<class Char, class Traits>
520  std::basic_ostream<Char,Traits>&
521  operator <<(std::basic_ostream<Char,Traits>& os, const OptFlexTask& t) {
522  std::basic_ostringstream<Char,Traits> s;
523  s.copyfmt(os); s.width(0);
524  s << t.est() << ':' << t.lst() << ':' << t.pmin() << ':'
525  << t.pmax() << ':' << t.ect() << ':' << t.lct() << ':'
526  << (t.mandatory() ? '1' : (t.optional() ? '?' : '0'));
527  return os << s.str();
528  }
529 
530 }}}
531 
532 // STATISTICS: int-var
int lct(void) const
Return latest completion time.
Definition: task.hpp:343
int pmin(void) const
Return minimum processing time.
Definition: task.hpp:212
ModEvent gr(Space &home, int n)
Restrict domain values to be greater than n.
Definition: int.hpp:142
Unary (mandatory) task with fixed processing, start or end time
Definition: unary.hh:150
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to view.
Definition: view.hpp:459
void update(Space &home, bool share, ManFixPSETask &t)
Update this task to be a clone of task t.
Definition: task.hpp:299
NodeType t
Type of node.
Definition: bool-expr.cpp:234
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
TaskType
Type of task for scheduling constraints.
Definition: int.hh:949
Unary optional task with flexible processing time
Definition: unary.hh:370
Range iterator for singleton range.
void init(IntVar s, int p)
Initialize with start time s and processing time p.
Definition: task.hpp:51
int _p
Processing time.
Definition: unary.hh:63
bool excluded(void) const
Whether task is excluded.
Definition: task.hpp:372
OptFlexTask(void)
Default constructor.
Definition: task.hpp:509
int lct(void) const
Return latest completion time.
Definition: task.hpp:202
Unary (mandatory) task with fixed processing time
Definition: unary.hh:58
int est(void) const
Return earliest start time.
Definition: task.hpp:331
void cancel(Space &home, Propagator &p, PropCond pc=Int::PC_INT_BND)
Cancel subscription of propagator p for task.
Definition: task.hpp:152
void init(IntVar s, IntVar p, IntVar e, BoolVar m)
Initialize with start time s, processing time p, end time e, and mandatory flag m.
Definition: task.hpp:515
int pmax(void) const
Return maximum processing time.
Definition: task.hpp:222
ManFlexTask(void)
Default constructor.
Definition: task.hpp:317
void init(TaskType t, IntVar s, int p, BoolVar m)
Initialize with start time s, processing time p, and mandatory flag m.
Definition: task.hpp:490
int ModEvent
Type for modification events.
Definition: core.hpp:146
Base-class for propagators.
Definition: core.hpp:755
int pmax(void) const
Return maximum processing time.
Definition: task.hpp:80
ModEvent minus_r(Space &home, I &i, bool depends=true)
Remove from domain the ranges described by i.
Definition: int.hpp:185
Computation spaces.
Definition: core.hpp:1362
bool assigned(void) const
Test whether task is assigned.
Definition: task.hpp:381
OptFixPSETask(void)
Default constructor.
Definition: task.hpp:484
int pmax(void) const
Return maximum processing time.
Definition: task.hpp:351
ModEvent norun(Space &home, int e, int l)
Update such that task cannot run from e to l.
Definition: task.hpp:273
IntVar e(void) const
Return end time.
Definition: task.hpp:363
const Gecode::ModEvent ME_INT_FAILED
Domain operation has resulted in failure.
Definition: var-type.hpp:52
int max(void) const
Return maximum of domain.
Definition: int.hpp:62
int ect(void) const
Return earliest completion time.
Definition: task.hpp:64
Unary optional task with fixed processing time
Definition: unary.hh:224
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to view.
Definition: view.hpp:453
Int::IntView _s
Start time.
Definition: unary.hh:61
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
bool mandatory(void) const
Whether task is mandatory.
Definition: task.hpp:368
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
ManFixPTask(void)
Default constructor.
Definition: task.hpp:47
void update(Space &home, bool share, ManFixPTask &t)
Update this task to be a clone of task t.
Definition: task.hpp:143
int pmin(void) const
Return minimum processing time.
Definition: task.hpp:76
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition: int.hpp:115
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
int PropCond
Type for propagation conditions.
Definition: core.hpp:156
int est(void) const
Return earliest start time.
Definition: task.hpp:184
ModEvent norun(Space &home, int e, int l)
Update such that task cannot run from e to l.
Definition: task.hpp:402
ModEvent norun(Space &home, int e, int l)
Update such that task cannot run from e to l.
Definition: task.hpp:123
int min(void) const
Return minimum of domain.
Definition: int.hpp:58
void init(IntVar s, IntVar p, IntVar e)
Initialize with start time s, processing time p, end time e.
Definition: task.hpp:322
TaskType _t
Task type.
Definition: unary.hh:153
bool optional(void) const
Whether task can still be optional.
Definition: task.hpp:376
void update(Space &home, bool share, VarImpView< Var > &y)
Update this view to be a clone of view y.
Definition: view.hpp:494
int lst(void) const
Return latest start time.
Definition: task.hpp:68
Int::IntView _e
End time.
Definition: unary.hh:279
Boolean integer variables.
Definition: int.hh:491
bool optional(void) const
Whether task can still be optional.
Definition: task.hpp:97
void init(TaskType t, IntVar s, int p)
Initialize task.
Definition: task.hpp:175
int ect(void) const
Return earliest completion time.
Definition: task.hpp:335
Int::IntView _p
Processing time.
Definition: unary.hh:277
bool mandatory(void) const
Whether task is mandatory.
Definition: task.hpp:89
IntVar st(void) const
Return start time.
Definition: task.hpp:84
void update(Space &home, bool share, ManFlexTask &t)
Update this task to be a clone of task t.
Definition: task.hpp:425
OptFixPTask(void)
Default constructor.
Definition: task.hpp:459
Multi _e(Gecode::IntArgs(4, 4, 2, 3, 1))
Integer variables.
Definition: int.hh:350
#define forceinline
Definition: config.hpp:132
bool assigned(void) const
Test whether view is assigned.
Definition: view.hpp:448
Unary optional task with fixed processing, start or end time.
Definition: unary.hh:248
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition: int.hpp:133
bool assigned(void) const
Test whether task is assigned.
Definition: task.hpp:102
void subscribe(Space &home, Propagator &p, PropCond pc=Int::PC_INT_BND)
Subscribe propagator p to task.
Definition: task.hpp:148
void cancel(Space &home, Propagator &p, PropCond pc=Int::PC_INT_BND)
Cancel subscription of propagator p for task.
Definition: task.hpp:438
Int::BoolView _m
Boolean view whether task is mandatory (= 1) or not.
Definition: task.hh:50
int pmin(void) const
Return minimum processing time.
Definition: task.hpp:347
ManFixPSETask(void)
Default constructor.
Definition: task.hpp:170
Gecode toplevel namespace
int lct(void) const
Return latest completion time.
Definition: task.hpp:72
Unary (mandatory) task with flexible processing time
Definition: unary.hh:272
void init(IntVar s, int p, BoolVar m)
Initialize with start time s, processing time p, and mandatory flag m.
Definition: task.hpp:465
int ect(void) const
Return earliest completion time.
Definition: task.hpp:188
IntVar p(void) const
Return processing time.
Definition: task.hpp:359
IntVar st(void) const
Return start time.
Definition: task.hpp:355
Int::IntView _s
Start time.
Definition: unary.hh:275
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
const Gecode::ModEvent ME_INT_NONE
Domain operation has not changed domain.
Definition: var-type.hpp:54
void subscribe(Space &home, Propagator &p, PropCond pc=Int::PC_INT_BND)
Subscribe propagator p to task.
Definition: task.hpp:432
bool excluded(void) const
Whether task is excluded.
Definition: task.hpp:93
bool me_failed(ModEvent me)
Check whether modification event me is failed.
Definition: modevent.hpp:58
int lst(void) const
Return latest start time.
Definition: task.hpp:339
int est(void) const
Return earliest start time.
Definition: task.hpp:60
int lst(void) const
Return latest start time.
Definition: task.hpp:198