Generated on for Gecode by doxygen 1.17.0
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.dev>
5 * Guido Tack <tack@gecode.dev>
6 *
7 * Copyright:
8 * Christian Schulte, 2009
9 * Guido Tack, 2010
10 *
11 * This file is part of Gecode, the generic constraint
12 * development environment:
13 * http://www.gecode.dev
14 *
15 * Permission is hereby granted, free of charge, to any person obtaining
16 * a copy of this software and associated documentation files (the
17 * "Software"), to deal in the Software without restriction, including
18 * without limitation the rights to use, copy, modify, merge, publish,
19 * distribute, sublicense, and/or sell copies of the Software, and to
20 * permit persons to whom the Software is furnished to do so, subject to
21 * the following conditions:
22 *
23 * The above copyright notice and this permission notice shall be
24 * included in all copies or substantial portions of the Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 *
34 */
35
36namespace Gecode { namespace Int { namespace Unary {
37
45 forceinline int
46 norun_bound(long long v) {
47 return static_cast<int>(std::min(std::max(v, static_cast<long long>(Limits::min)),
48 static_cast<long long>(Limits::max) + 1));
49 }
50
51 /*
52 * Mandatory fixed task
53 */
54
58 ManFixPTask::ManFixPTask(IntVar s, int p) : _s(s), _p(p) {}
59 forceinline void
61 _s=s; _p=p;
62 }
63 forceinline void
65 _s=t._s; _p=t._p;
66 }
67
68 forceinline int
69 ManFixPTask::est(void) const {
70 return _s.min();
71 }
72 forceinline int
73 ManFixPTask::ect(void) const {
74 return _s.min()+_p;
75 }
76 forceinline int
77 ManFixPTask::lst(void) const {
78 return _s.max();
79 }
80 forceinline int
81 ManFixPTask::lct(void) const {
82 return _s.max()+_p;
83 }
84 forceinline int
85 ManFixPTask::pmin(void) const {
86 return _p;
87 }
88 forceinline int
89 ManFixPTask::pmax(void) const {
90 return _p;
91 }
93 ManFixPTask::st(void) const {
94 return _s;
95 }
96
97 forceinline bool
99 return true;
100 }
101 forceinline bool
103 return false;
104 }
105 forceinline bool
107 return false;
108 }
109
110 forceinline bool
112 return _s.assigned();
113 }
114
116 ManFixPTask::est(Space& home, int n) {
117 return _s.gq(home,n);
118 }
120 ManFixPTask::ect(Space& home, int n) {
121 return _s.gq(home,n-_p);
122 }
124 ManFixPTask::lst(Space& home, int n) {
125 return _s.lq(home,n);
126 }
128 ManFixPTask::lct(Space& home, int n) {
129 return _s.lq(home,n-_p);
130 }
132 ManFixPTask::norun(Space& home, int e, int l) {
133 if (e <= l) {
134 Iter::Ranges::Singleton r(norun_bound(static_cast<long long>(e)-_p+1),l);
135 return _s.minus_r(home,r,false);
136 } else {
137 return ME_INT_NONE;
138 }
139 }
140
141
150
151 forceinline void
153 _s.update(home,t._s); _p=t._p;
154 }
155
156 forceinline void
158 _s.subscribe(home, p, pc);
159 }
160 forceinline void
162 _s.cancel(home, p, pc);
163 }
164 forceinline void
166 _s.reschedule(home, p, pc);
167 }
168
169 template<class Char, class Traits>
170 std::basic_ostream<Char,Traits>&
171 operator <<(std::basic_ostream<Char,Traits>& os, const ManFixPTask& t) {
172 std::basic_ostringstream<Char,Traits> s;
173 s.copyfmt(os); s.width(0);
174 s << t.est() << ':' << t.pmin() << ':' << t.lct();
175 return os << s.str();
176 }
177
178 /*
179 * Mandatory fixed task with fixed processing, start or end time
180 */
181
187 forceinline void
189 ManFixPTask::init(s,p); _t=t;
190 }
191 forceinline void
193 ManFixPTask::init(t0); _t = t0._t;
194 }
195
196 forceinline int
197 ManFixPSETask::est(void) const {
198 return (_t == TT_FIXS) ? _p : _s.min();
199 }
200 forceinline int
201 ManFixPSETask::ect(void) const {
202 switch (_t) {
203 case TT_FIXP: return _s.min()+_p;
204 case TT_FIXS: return _s.min();
205 case TT_FIXE: return _p;
206 default: GECODE_NEVER;
207 }
208 return 0;
209 }
210 forceinline int
211 ManFixPSETask::lst(void) const {
212 return (_t == TT_FIXS) ? _p : _s.max();
213 }
214 forceinline int
215 ManFixPSETask::lct(void) const {
216 switch (_t) {
217 case TT_FIXP: return _s.max()+_p;
218 case TT_FIXS: return _s.max();
219 case TT_FIXE: return _p;
220 default: GECODE_NEVER;
221 }
222 return 0;
223 }
224 forceinline int
226 switch (_t) {
227 case TT_FIXP: return _p;
228 case TT_FIXS: return _s.min()-_p;
229 case TT_FIXE: return _p-_s.max();
230 default: GECODE_NEVER;
231 }
232 return 0;
233 }
234 forceinline int
236 switch (_t) {
237 case TT_FIXP: return _p;
238 case TT_FIXS: return _s.max()-_p;
239 case TT_FIXE: return _p-_s.min();
240 default: GECODE_NEVER;
241 }
242 return 0;
243 }
244
246 ManFixPSETask::est(Space& home, int n) {
247 switch (_t) {
248 case TT_FIXE: // fall through
249 case TT_FIXP: return _s.gq(home,n);
250 case TT_FIXS: return (n <= _p) ? ME_INT_NONE : ME_INT_FAILED;
251 default: GECODE_NEVER;
252 }
253 return ME_INT_NONE;
254 }
256 ManFixPSETask::ect(Space& home, int n) {
257 switch (_t) {
258 case TT_FIXE: return (n <= _p) ? ME_INT_NONE : ME_INT_FAILED;
259 case TT_FIXP: return _s.gq(home,n-_p);
260 case TT_FIXS: return _s.gq(home,n);
261 default: GECODE_NEVER;
262 }
263 return ME_INT_NONE;
264 }
266 ManFixPSETask::lst(Space& home, int n) {
267 switch (_t) {
268 case TT_FIXE: // fall through
269 case TT_FIXP: return _s.lq(home,n);
270 case TT_FIXS: return (n >= _p) ? ME_INT_NONE : ME_INT_FAILED;
271 default: GECODE_NEVER;
272 }
273 return ME_INT_NONE;
274 }
276 ManFixPSETask::lct(Space& home, int n) {
277 switch (_t) {
278 case TT_FIXE: return (n >= _p) ? ME_INT_NONE : ME_INT_FAILED;
279 case TT_FIXP: return _s.lq(home,n-_p);
280 case TT_FIXS: return _s.lq(home,n);
281 default: GECODE_NEVER;
282 }
283 return ME_INT_NONE;
284 }
286 ManFixPSETask::norun(Space& home, int e, int l) {
287 if (e <= l) {
288 switch (_t) {
289 case TT_FIXP:
290 {
291 Iter::Ranges::Singleton r(norun_bound(static_cast<long long>(e)-_p+1),l);
292 return _s.minus_r(home,r,false);
293 }
294 case TT_FIXE:
295 if (e <= _p)
296 return _s.gr(home,l);
297 break;
298 case TT_FIXS:
299 if (l >= _p)
300 return _s.lq(home,e);
301 break;
302 default:
304 }
305 return ME_INT_NONE;
306 } else {
307 return ME_INT_NONE;
308 }
309 }
310
311 forceinline void
315
316 template<class Char, class Traits>
317 std::basic_ostream<Char,Traits>&
318 operator <<(std::basic_ostream<Char,Traits>& os, const ManFixPSETask& t) {
319 std::basic_ostringstream<Char,Traits> s;
320 s.copyfmt(os); s.width(0);
321 s << t.est() << ':' << t.pmin() << ':' << t.lct();
322 return os << s.str();
323 }
324
325 /*
326 * Mandatory flexible task
327 */
328
334 forceinline void
336 _s=s; _p=p; _e=e;
337 }
338 forceinline void
340 _s=t._s; _p=t._p; _e=t._e;
341 }
342
343 forceinline int
344 ManFlexTask::est(void) const {
345 return _s.min();
346 }
347 forceinline int
348 ManFlexTask::ect(void) const {
349 return _e.min();
350 }
351 forceinline int
352 ManFlexTask::lst(void) const {
353 return _s.max();
354 }
355 forceinline int
356 ManFlexTask::lct(void) const {
357 return _e.max();
358 }
359 forceinline int
360 ManFlexTask::pmin(void) const {
361 return _p.min();
362 }
363 forceinline int
364 ManFlexTask::pmax(void) const {
365 return _p.max();
366 }
368 ManFlexTask::st(void) const {
369 return _s;
370 }
372 ManFlexTask::p(void) const {
373 return _p;
374 }
376 ManFlexTask::e(void) const {
377 return _e;
378 }
379
380 forceinline bool
382 return true;
383 }
384 forceinline bool
386 return false;
387 }
388 forceinline bool
390 return false;
391 }
392
393 forceinline bool
395 return _s.assigned() && _p.assigned() && _e.assigned();
396 }
397
399 ManFlexTask::est(Space& home, int n) {
400 return _s.gq(home,n);
401 }
403 ManFlexTask::ect(Space& home, int n) {
404 return _e.gq(home,n);
405 }
407 ManFlexTask::lst(Space& home, int n) {
408 return _s.lq(home,n);
409 }
411 ManFlexTask::lct(Space& home, int n) {
412 return _e.lq(home,n);
413 }
415 ManFlexTask::norun(Space& home, int e, int l) {
416 if (e <= l) {
417 Iter::Ranges::Singleton sr(norun_bound(static_cast<long long>(e)-_p.min()+1),l);
418 if (me_failed(_s.minus_r(home,sr,false)))
419 return ME_INT_FAILED;
420 Iter::Ranges::Singleton er(norun_bound(static_cast<long long>(e)+1),
421 norun_bound(static_cast<long long>(_p.min())+l));
422 return _e.minus_r(home,er,false);
423 } else {
424 return ME_INT_NONE;
425 }
426 }
427
428
437
438 forceinline void
440 _s.update(home,t._s);
441 _p.update(home,t._p);
442 _e.update(home,t._e);
443 }
444
445 forceinline void
447 _s.subscribe(home, p, pc);
448 _p.subscribe(home, p, pc);
449 _e.subscribe(home, p, pc);
450 }
451 forceinline void
453 _s.cancel(home, p, pc);
454 _p.cancel(home, p, pc);
455 _e.cancel(home, p, pc);
456 }
457 forceinline void
459 _s.reschedule(home, p, pc);
460 _p.reschedule(home, p, pc);
461 _e.reschedule(home, p, pc);
462 }
463
464 template<class Char, class Traits>
465 std::basic_ostream<Char,Traits>&
466 operator <<(std::basic_ostream<Char,Traits>& os, const ManFlexTask& t) {
467 std::basic_ostringstream<Char,Traits> s;
468 s.copyfmt(os); s.width(0);
469 s << t.est() << ':' << t.lst() << ':' << t.pmin() << ':'
470 << t.pmax() << ':' << t.ect() << ':' << t.lct();
471 return os << s.str();
472 }
473
474 /*
475 * Optional fixed task
476 */
477
482 ManFixPTask::init(s,p); _m=m;
483 }
484 forceinline void
486 ManFixPTask::init(s,p); _m=m;
487 }
488
489 template<class Char, class Traits>
490 std::basic_ostream<Char,Traits>&
491 operator <<(std::basic_ostream<Char,Traits>& os, const OptFixPTask& t) {
492 std::basic_ostringstream<Char,Traits> s;
493 s.copyfmt(os); s.width(0);
494 s << t.est() << ':' << t.pmin() << ':' << t.lct() << ':'
495 << (t.mandatory() ? '1' : (t.optional() ? '?' : '0'));
496 return os << s.str();
497 }
498
499 /*
500 * Optional fixed task
501 */
502
509 forceinline void
511 ManFixPSETask::init(t,s,p); _m=m;
512 }
513
514 template<class Char, class Traits>
515 std::basic_ostream<Char,Traits>&
516 operator <<(std::basic_ostream<Char,Traits>& os, const OptFixPSETask& t) {
517 std::basic_ostringstream<Char,Traits> s;
518 s.copyfmt(os); s.width(0);
519 s << t.est() << ':' << t.pmin() << ':' << t.lct() << ':'
520 << (t.mandatory() ? '1' : (t.optional() ? '?' : '0'));
521 return os << s.str();
522 }
523
524 /*
525 * Optional flexible task
526 */
527
534 forceinline void
538
539 template<class Char, class Traits>
540 std::basic_ostream<Char,Traits>&
541 operator <<(std::basic_ostream<Char,Traits>& os, const OptFlexTask& t) {
542 std::basic_ostringstream<Char,Traits> s;
543 s.copyfmt(os); s.width(0);
544 s << t.est() << ':' << t.lst() << ':' << t.pmin() << ':'
545 << t.pmax() << ':' << t.ect() << ':' << t.lct() << ':'
546 << (t.mandatory() ? '1' : (t.optional() ? '?' : '0'));
547 return os << s.str();
548 }
549
550}}}
551
552// STATISTICS: int-var
Boolean integer variables.
Definition int.hh:534
unsigned int width(void) const
Return width of domain (distance between maximum and minimum).
Definition bool.hpp:77
Integer variables.
Definition int.hh:390
bool mandatory(void) const
Whether task is mandatory.
bool optional(void) const
Whether task can still be optional.
Unary (mandatory) task with fixed processing, start or end time
Definition unary.hh:148
int ect(void) const
Return earliest completion time.
Definition task.hpp:201
ModEvent norun(Space &home, int e, int l)
Update such that task cannot run from e to l.
Definition task.hpp:286
int pmax(void) const
Return maximum processing time.
Definition task.hpp:235
int pmin(void) const
Return minimum processing time.
Definition task.hpp:225
ManFixPSETask(void)
Default constructor.
Definition task.hpp:183
void init(TaskType t, IntVar s, int p)
Initialize task.
Definition task.hpp:188
int est(void) const
Return earliest start time.
Definition task.hpp:197
int lct(void) const
Return latest completion time.
Definition task.hpp:215
int lst(void) const
Return latest start time.
Definition task.hpp:211
void update(Space &home, ManFixPSETask &t)
Update this task to be a clone of task t.
Definition task.hpp:312
Unary (mandatory) task with fixed processing time
Definition unary.hh:54
int pmax(void) const
Return maximum processing time.
Definition task.hpp:89
bool optional(void) const
Whether task can still be optional.
Definition task.hpp:106
ModEvent norun(Space &home, int e, int l)
Update such that task cannot run from e to l.
Definition task.hpp:132
ManFixPTask(void)
Default constructor.
Definition task.hpp:56
int est(void) const
Return earliest start time.
Definition task.hpp:69
int pmin(void) const
Return minimum processing time.
Definition task.hpp:85
void init(IntVar s, int p)
Initialize with start time s and processing time p.
Definition task.hpp:60
int ect(void) const
Return earliest completion time.
Definition task.hpp:73
Int::IntView _s
Start time.
Definition unary.hh:57
int _p
Processing time.
Definition unary.hh:59
bool assigned(void) const
Test whether task is assigned.
Definition task.hpp:111
void reschedule(Space &home, Propagator &p, PropCond pc)
Schedule propagator p.
Definition task.hpp:165
int lct(void) const
Return latest completion time.
Definition task.hpp:81
IntVar st(void) const
Return start time.
Definition task.hpp:93
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p for task.
Definition task.hpp:161
int lst(void) const
Return latest start time.
Definition task.hpp:77
void update(Space &home, ManFixPTask &t)
Update this task to be a clone of task t.
Definition task.hpp:152
bool mandatory(void) const
Whether task is mandatory.
Definition task.hpp:98
bool excluded(void) const
Whether task is excluded.
Definition task.hpp:102
void subscribe(Space &home, Propagator &p, PropCond pc)
Subscribe propagator p to task.
Definition task.hpp:157
Unary (mandatory) task with flexible processing time
Definition unary.hh:270
int lst(void) const
Return latest start time.
Definition task.hpp:352
int est(void) const
Return earliest start time.
Definition task.hpp:344
IntVar p(void) const
Return processing time.
Definition task.hpp:372
int pmin(void) const
Return minimum processing time.
Definition task.hpp:360
Int::IntView _s
Start time.
Definition unary.hh:273
IntVar st(void) const
Return start time.
Definition task.hpp:368
ModEvent norun(Space &home, int e, int l)
Update such that task cannot run from e to l.
Definition task.hpp:415
void reschedule(Space &home, Propagator &p, PropCond pc)
Schedule propagator p.
Definition task.hpp:458
bool mandatory(void) const
Whether task is mandatory.
Definition task.hpp:381
void subscribe(Space &home, Propagator &p, PropCond pc)
Subscribe propagator p to task.
Definition task.hpp:446
int ect(void) const
Return earliest completion time.
Definition task.hpp:348
Int::IntView _e
End time.
Definition unary.hh:277
int pmax(void) const
Return maximum processing time.
Definition task.hpp:364
IntVar e(void) const
Return end time.
Definition task.hpp:376
void update(Space &home, ManFlexTask &t)
Update this task to be a clone of task t.
Definition task.hpp:439
Int::IntView _p
Processing time.
Definition unary.hh:275
bool excluded(void) const
Whether task is excluded.
Definition task.hpp:385
int lct(void) const
Return latest completion time.
Definition task.hpp:356
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p for task.
Definition task.hpp:452
ManFlexTask(void)
Default constructor.
Definition task.hpp:330
bool optional(void) const
Whether task can still be optional.
Definition task.hpp:389
bool assigned(void) const
Test whether task is assigned.
Definition task.hpp:394
void init(IntVar s, IntVar p, IntVar e)
Initialize with start time s, processing time p, end time e.
Definition task.hpp:335
Unary optional task with fixed processing, start or end time.
Definition unary.hh:246
OptFixPSETask(void)
Default constructor.
Definition task.hpp:504
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:510
Unary optional task with fixed processing time
Definition unary.hh:222
void init(IntVar s, int p, BoolVar m)
Initialize with start time s, processing time p, and mandatory flag m.
Definition task.hpp:485
OptFixPTask(void)
Default constructor.
Definition task.hpp:479
Unary optional task with flexible processing time
Definition unary.hh:370
OptFlexTask(void)
Default constructor.
Definition task.hpp:529
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:535
Range iterator for singleton range.
Base-class for propagators.
Definition core.hpp:1073
Computation spaces.
Definition core.hpp:1787
bool me_failed(ModEvent me)
Check whether modification event me is failed.
Definition modevent.hpp:54
TaskType
Type of task for scheduling constraints.
Definition int.hh:1305
@ TT_FIXS
Definition int.hh:1307
@ TT_FIXE
Definition int.hh:1308
@ TT_FIXP
Definition int.hh:1306
const int min
Smallest allowed integer value.
Definition int.hh:123
const int max
Largest allowed integer value.
Definition int.hh:121
Int for unary resources
int norun_bound(long long v)
Clamp a time point for the no-run ranges to the integer limits.
Definition task.hpp:46
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const ManFixPTaskBwd &t)
Definition task-view.hpp:40
Finite domain integers.
Definition lastval.hh:52
const Gecode::ModEvent ME_INT_FAILED
Domain operation has resulted in failure.
Definition var-type.hpp:60
const Gecode::ModEvent ME_INT_NONE
Domain operation has not changed domain.
Definition var-type.hpp:62
Gecode toplevel namespace
int PropCond
Type for propagation conditions.
Definition core.hpp:77
int ModEvent
Type for modification events.
Definition core.hpp:67
#define forceinline
Definition config.hpp:144
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56