Generated on for Gecode by doxygen 1.18.0
task.hh
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 *
6 * Copyright:
7 * Christian Schulte, 2009
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.dev
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34#ifndef GECODE_INT_TASK_HH
35#define GECODE_INT_TASK_HH
36
37#include <gecode/int.hh>
38
39namespace Gecode { namespace Int {
40
42 template<class ManTask>
43 class ManToOptTask : public ManTask {
44 protected:
47 public:
49
50
51 ManToOptTask(void);
53
55
56
57 bool mandatory(void) const;
59 bool excluded(void) const;
61 bool optional(void) const;
63
65
66 bool assigned(void) const;
68
70
71
74 ModEvent excluded(Space& home);
76
78
79
80 void update(Space& home, ManToOptTask& t);
82
84
85
86 void subscribe(Space& home, Propagator& p, PropCond pc);
88 void cancel(Space& home, Propagator& p, PropCond pc);
90 void reschedule(Space& home, Propagator& p, PropCond pc);
92 };
93
94}}
95
97
98namespace Gecode { namespace Int {
99
101 template<class TaskView>
102 class FwdToBwd : public TaskView {
103 public:
105
106
107 int est(void) const;
109 int ect(void) const;
111 int lst(void) const;
113 int lct(void) const;
115 int pmin(void) const;
117 int pmax(void) const;
119
121
122
123 ModEvent est(Space& home, int n);
125 ModEvent ect(Space& home, int n);
127 ModEvent lst(Space& home, int n);
129 ModEvent lct(Space& home, int n);
131 ModEvent norun(Space& home, int e, int l);
133 };
134
135}}
136
138
139namespace Gecode { namespace Int {
140
147 template<class TaskView>
149
156 template<class Task>
157 class TaskTraits {};
158
159}}
160
161namespace Gecode { namespace Int {
162
164 template<class Task>
165 class TaskArray {
166 private:
168 int n;
170 Task* t;
171 public:
173
174
175 TaskArray(void);
177 TaskArray(Space& home, int n);
179 TaskArray(const TaskArray<Task>& a);
183
185
186
187 int size(void) const;
189 void size(int n);
191
193
194
195 Task& operator [](int i);
197 const Task& operator [](int i) const;
199
201
202
205 void cancel(Space& home, Propagator& p, PropCond pc=Int::PC_INT_BND);
209
211
212
213 void update(Space&, TaskArray& a);
215
216 private:
217 static void* operator new(size_t);
218 static void operator delete(void*,size_t);
219 };
220
225 template<class Char, class Traits, class Task>
226 std::basic_ostream<Char,Traits>&
227 operator <<(std::basic_ostream<Char,Traits>& os,
228 const TaskArray<Task>& t);
229
230
232 template<class TaskView>
234 protected:
239 public:
241
242
245
247
248
249 int size(void) const;
251 void size(int n);
253
255
256
257 TaskView& operator [](int i);
259 const TaskView& operator [](int i) const;
261 private:
262 static void* operator new(size_t);
263 static void operator delete(void*,size_t);
264 };
265
270 template<class Char, class Traits, class TaskView>
271 std::basic_ostream<Char,Traits>&
272 operator <<(std::basic_ostream<Char,Traits>& os,
273 const TaskViewArray<TaskView>& t);
274
275}}
276
278
279namespace Gecode { namespace Int {
280
288
290 template<class TaskView, SortTaskOrder sto, bool inc>
291 void sort(TaskViewArray<TaskView>& t);
292
294 template<class TaskView, SortTaskOrder sto, bool inc>
295 void sort(int* map, const TaskViewArray<TaskView>& t);
296
298 template<class TaskView, SortTaskOrder sto, bool inc>
299 void sort(int* map, int n, const TaskViewArray<TaskView>& t);
300
301}}
302
304
305namespace Gecode { namespace Int {
306
308 template<class TaskView, SortTaskOrder sto, bool inc>
310 protected:
312 int* map;
314 int i;
316 TaskViewIter(void);
317 public:
321
322
323 bool operator ()(void) const;
325 int left(void) const;
327 void operator ++(void);
329
331
332
333 int task(void) const;
335 };
336
338 template<class OptTaskView, SortTaskOrder sto, bool inc>
339 class ManTaskViewIter : public TaskViewIter<OptTaskView,sto,inc> {
340 protected:
341 using TaskViewIter<OptTaskView,sto,inc>::map;
342 using TaskViewIter<OptTaskView,sto,inc>::i;
343 public:
346 };
347
348}}
349
351
352namespace Gecode { namespace Int {
353
355 long long int plus(long long int x, long long int y);
356
358 double plus(double x, double y);
359
361 template<class TaskView, class Node>
362 class TaskTree {
363 template<class,class> friend class TaskTree;
364 protected:
368 Node* node;
370 int* _leaf;
371
373 int n_inner(void) const;
375 int n_nodes(void) const;
377 static bool n_root(int i);
379 bool n_leaf(int i) const;
381 static int n_left(int i);
383 static bool left(int i);
385 static int n_right(int i);
387 static bool right(int i);
389 static int n_parent(int i);
390 protected:
392 Node& leaf(int i);
394 const Node& root(void) const;
396 void update(int i, bool l=true);
398 void init(void);
400 void update(void);
404 template<class Node2> TaskTree(Region& r,
405 const TaskTree<TaskView,Node2>& t);
406 };
407
408}}
409
411
412namespace Gecode { namespace Int {
413
420 template<class Task, class PL>
421 class TaskProp : public Propagator {
422 protected:
429 public:
431 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
433 virtual void reschedule(Space& home);
435 virtual size_t dispose(Space& home);
436 };
437
439 template<class OptTask, class PL>
441
443 template<class OptTask, class PL, class Cap>
444 ExecStatus purge(Space& home, Propagator& p, TaskArray<OptTask>& t, Cap c);
445
447 class PLB {
448 public:
450 static const bool basic = true;
452 static const bool advanced = false;
454 static const PropCond pc = PC_INT_DOM;
455 };
456
458 class PLA {
459 public:
461 static const bool basic = false;
463 static const bool advanced = true;
465 static const PropCond pc = PC_INT_BND;
466 };
467
469 class PLBA {
470 public:
472 static const bool basic = true;
474 static const bool advanced = true;
476 static const PropCond pc = PC_INT_DOM;
477 };
478
479}}
480
483
484namespace Gecode { namespace Int {
485
487 class Event {
488 public:
490 enum Type {
491 LRT = 0,
492 LCT = 1,
493 EST = 2,
494 ZRO = 3,
495 ERT = 4,
496 END = 5
497 };
498 protected:
500 unsigned int ei;
502 int t;
503 public:
505 void init(Type e, int t, int i);
507 Type type(void) const;
509 int time(void) const;
511 int idx(void) const;
513 bool operator <(const Event& e) const;
515 template<class Task>
516 static Event* events(Region& r, const TaskArray<Task>& t, bool& assigned);
518 template<class Task>
519 static Event* events(Region& r, const TaskArray<Task>& t);
520 };
521
523 template<class Char, class Traits>
524 std::basic_ostream<Char,Traits>&
525 operator <<(std::basic_ostream<Char,Traits>& os, const Event& e);
526
527}}
528
530
531#endif
532
533// STATISTICS: int-prop
Home class for posting propagators
Definition core.hpp:863
Boolean view for Boolean variables.
Definition view.hpp:1378
Time-tabling event for task.
Definition task.hh:487
int t
Time of event.
Definition task.hh:502
int idx(void) const
Return event index.
Definition event.hpp:50
static Event * events(Region &r, const TaskArray< Task > &t, bool &assigned)
Allocate from r and initialize event array with tasks t.
Definition event.hpp:83
unsigned int ei
Combines type and number of task.
Definition task.hh:500
void init(Type e, int t, int i)
Initialize event.
Definition event.hpp:37
Type
Event type for task with order in which they are processed.
Definition task.hh:490
@ ZRO
Zero-length task start time.
Definition task.hh:494
@ ERT
Earliest required time of task.
Definition task.hh:495
@ LRT
Latest required time of task.
Definition task.hh:491
@ EST
Earliest start time of task.
Definition task.hh:493
@ END
End marker.
Definition task.hh:496
@ LCT
Latest completion time of task.
Definition task.hh:492
int time(void) const
Return event time.
Definition event.hpp:46
Type type(void) const
Return event type.
Definition event.hpp:42
bool operator<(const Event &e) const
Order among events.
Definition event.hpp:55
Task mapper: turns a task view into its dual.
Definition task.hh:102
ModEvent lct(Space &home, int n)
Update latest completion time to n.
ModEvent lst(Space &home, int n)
Update latest start time to n.
int ect(void) const
Return earliest completion time.
int lst(void) const
Return latest start time.
ModEvent ect(Space &home, int n)
Update earliest completion time to n.
int lct(void) const
Return latest completion time.
ModEvent norun(Space &home, int e, int l)
Update such that task cannot run from e to l.
int est(void) const
Return earliest start time.
int pmin(void) const
Return minimum processing time.
ModEvent est(Space &home, int n)
Update earliest start time to n.
int pmax(void) const
Return maximum processing time.
ManTaskViewIter(Region &r, const TaskViewArray< OptTaskView > &t)
Initialize iterator with mandatory tasks.
Definition iter.hpp:76
Int::BoolView _m
Boolean view whether task is mandatory (= 1) or not.
Definition task.hh:46
bool assigned(void) const
Test whether task is assigned.
bool mandatory(void) const
Whether task is mandatory.
ManToOptTask(void)
Default constructor.
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p for task.
void update(Space &home, ManToOptTask &t)
Update this task to be a clone of task t.
bool optional(void) const
Whether task can still be optional.
bool excluded(void) const
Whether task is excluded.
void subscribe(Space &home, Propagator &p, PropCond pc)
Subscribe propagator p to task.
void reschedule(Space &home, Propagator &p, PropCond pc)
Schedule propagator p.
Class for defining advanced propagation level.
Definition task.hh:458
static const PropCond pc
For basic propagation, domain operations are needed.
Definition task.hh:465
static const bool advanced
Do not perform advanced propagation.
Definition task.hh:463
static const bool basic
Perform basic propagation.
Definition task.hh:461
Class for defining basic and advanced propagation level.
Definition task.hh:469
static const bool advanced
Do not perform advanced propagation.
Definition task.hh:474
static const bool basic
Perform basic propagation.
Definition task.hh:472
static const PropCond pc
For basic propagation, domain operations are needed.
Definition task.hh:476
Class for defining basic propagation level.
Definition task.hh:447
static const PropCond pc
For basic propagation, domain operations are needed.
Definition task.hh:454
static const bool advanced
Do not perform advanced propagation.
Definition task.hh:452
static const bool basic
Perform basic propagation.
Definition task.hh:450
Task array.
Definition task.hh:165
Task & operator[](int i)
Return task at position i.
Definition array.hpp:74
void update(Space &, TaskArray &a)
Update array to be a clone of array a.
Definition array.hpp:108
TaskArray(void)
Default constructor (array of size 0).
Definition array.hpp:42
void subscribe(Space &home, Propagator &p, PropCond pc=Int::PC_INT_BND)
Subscribe propagator p to all tasks.
Definition array.hpp:87
void cancel(Space &home, Propagator &p, PropCond pc=Int::PC_INT_BND)
Cancel subscription of propagator p for all tasks.
Definition array.hpp:94
void reschedule(Space &home, Propagator &p, PropCond pc=Int::PC_INT_BND)
Schedule propagator p.
Definition array.hpp:101
int size(void) const
Return size of array (number of elements).
Definition array.hpp:63
const TaskArray< Task > & operator=(const TaskArray< Task > &a)
Initialize from task array a (share elements).
Definition array.hpp:56
TaskArray< Task > t
Tasks.
Definition task.hh:424
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition prop.hpp:64
virtual void reschedule(Space &home)
Schedule function.
Definition prop.hpp:58
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as high linear).
Definition prop.hpp:52
TaskProp(Home home, TaskArray< Task > &t)
Constructor for creation.
Definition prop.hpp:38
Traits class for mapping tasks to task views.
Definition task.hh:157
int n_nodes(void) const
Return number of nodes for balanced binary tree.
Definition tree.hpp:51
const TaskViewArray< TaskView > & tasks
The tasks from which the tree is computed.
Definition task.hh:366
static int n_right(int i)
Return index of right child of node i.
Definition tree.hpp:79
int n_inner(void) const
Return number of inner nodes.
Definition tree.hpp:46
static bool right(int i)
Test whether node i is a right child.
Definition tree.hpp:84
static int n_left(int i)
Return index of left child of node i.
Definition tree.hpp:67
static bool left(int i)
Test whether node i is a left child.
Definition tree.hpp:72
void init(void)
Initialize tree after leaves have been initialized.
Definition tree.hpp:109
void update(int i, bool l=true)
Update tree after leaf for task i has changed (l whether i refers to a leaf).
Definition tree.hpp:123
Node * node
Task nodes.
Definition task.hh:368
friend class TaskTree
Definition task.hh:363
bool n_leaf(int i) const
Whether node i is leaf.
Definition tree.hpp:62
const Node & root(void) const
Return root node.
Definition tree.hpp:103
static int n_parent(int i)
Return index of parent of node i.
Definition tree.hpp:91
int * _leaf
Map task number to leaf node number in right order.
Definition task.hh:370
Node & leaf(int i)
Return leaf for task i.
Definition tree.hpp:97
static bool n_root(int i)
Whether node i is index of root.
Definition tree.hpp:57
Task view array.
Definition task.hh:233
TaskArray< Task > & t
Access to task array.
Definition task.hh:238
TaskViewTraits< TaskView >::Task Task
The underlying task type.
Definition task.hh:236
TaskViewArray(TaskArray< Task > &t)
Initialize from task array a.
Definition array.hpp:137
int size(void) const
Return size of array (number of elements).
Definition array.hpp:142
TaskView & operator[](int i)
Return task view at position i.
Definition array.hpp:154
void operator++(void)
Move iterator to next task.
Definition iter.hpp:62
bool operator()(void) const
Test whether iterator is still at a task.
Definition iter.hpp:52
int * map
Map for iteration order.
Definition task.hh:312
int task(void) const
Return current task position.
Definition iter.hpp:68
int left(void) const
How many tasks are left to be iterated.
Definition iter.hpp:57
int i
Current position.
Definition task.hh:314
TaskViewIter(void)
Default constructor (no initialization).
Definition iter.hpp:40
Traits class for mapping task views to tasks.
Definition task.hh:148
Propagation cost.
Definition core.hpp:493
Base-class for propagators.
Definition core.hpp:1073
friend class Space
Definition core.hpp:1075
Propagator(Home home)
Constructor for posting.
Definition core.hpp:3707
Handle to region.
Definition region.hpp:55
Computation spaces.
Definition core.hpp:1787
int ModEventDelta
Modification event deltas.
Definition core.hpp:94
Finite domain integers.
Definition lastval.hh:52
void sort(TaskViewArray< TaskView > &t)
Sort task view array t according to sto and inc (increasing or decreasing).
Definition sort.hpp:133
ExecStatus purge(Space &home, Propagator &p, TaskArray< OptTask > &t)
Purge optional tasks that are excluded and possibly rewrite propagator.
Definition purge.hpp:38
SortTaskOrder
How to sort tasks.
Definition task.hh:282
@ STO_ECT
Sort by earliest completion times.
Definition task.hh:284
@ STO_EST
Sort by earliest start times.
Definition task.hh:283
@ STO_LST
Sort by latest start times.
Definition task.hh:285
@ STO_LCT
Sort by latest completion times.
Definition task.hh:286
const Gecode::PropCond PC_INT_BND
Propagate when minimum or maximum of a view changes.
Definition var-type.hpp:99
long long int plus(long long int x, long long int y)
Safe addition in case x is -Int::Limits::llinfinity.
Definition tree.hpp:39
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const IdxViewArray< View > &x)
Definition idx-view.hpp:167
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition var-type.hpp:108
Gecode toplevel namespace
ExecStatus
Definition core.hpp:479
int PropCond
Type for propagation conditions.
Definition core.hpp:77
int ModEvent
Type for modification events.
Definition core.hpp:67