Generated on Fri Jul 13 2018 06:08:28 for Gecode by doxygen 1.8.14
event.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, 2015
8  *
9  * Last modified:
10  * $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
11  * $Revision: 14967 $
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 namespace Gecode { namespace Int {
39 
40  forceinline void
41  Event::init(Event::Type e0, int t0, int i0) {
42  ei=static_cast<unsigned int>(e0 | (i0 << 3)); t=t0;
43  }
44 
46  Event::type(void) const {
47  return static_cast<Type>(ei & 7);
48  }
49  forceinline int
50  Event::time(void) const {
51  return t;
52  }
53  forceinline int
54  Event::idx(void) const {
55  return static_cast<int>(ei >> 3);;
56  }
57 
58  forceinline bool
59  Event::operator <(const Event& e) const {
60  if (time() == e.time())
61  return type() < e.type();
62  return time() < e.time();
63  }
64 
65 
66  template<class Char, class Traits>
67  inline std::basic_ostream<Char,Traits>&
68  operator <<(std::basic_ostream<Char,Traits>& os, const Event& e) {
69  std::basic_ostringstream<Char,Traits> s;
70  s.copyfmt(os); s.width(0);
71  s << '[';
72  switch (e.type()) {
73  case Event::LRT: s << "LRT"; break;
74  case Event::LCT: s << "LCT"; break;
75  case Event::EST: s << "EST"; break;
76  case Event::ZRO: s << "ZRO"; break;
77  case Event::ERT: s << "ERT"; break;
78  default: GECODE_NEVER;
79  }
80  s << ',' << e.time() << ',' << e.idx() << ']';
81  return os << s.str();
82  }
83 
84 
85  template<class Task>
88  Event* e = r.alloc<Event>(4*t.size()+1);
89 
90  // Initialize events
91  assigned=true;
92  bool required=false;
93 
94  int n=0;
95  for (int i=t.size(); i--; )
96  if (t[i].assigned()) {
97  // Only add required part
98  if (t[i].pmin() > 0) {
99  required = true;
100  e[n++].init(Event::ERT,t[i].lst(),i);
101  e[n++].init(Event::LRT,t[i].ect(),i);
102  } else if (t[i].pmax() == 0) {
103  required = true;
104  e[n++].init(Event::ZRO,t[i].lst(),i);
105  }
106  } else {
107  assigned = false;
108  e[n++].init(Event::EST,t[i].est(),i);
109  e[n++].init(Event::LCT,t[i].lct(),i);
110  // Check whether task has required part
111  if (t[i].lst() < t[i].ect()) {
112  required = true;
113  e[n++].init(Event::ERT,t[i].lst(),i);
114  e[n++].init(Event::LRT,t[i].ect(),i);
115  }
116  }
117 
118  if (!required)
119  return NULL;
120 
121  // Sort events
122  Support::quicksort(e, n);
123 
124  // Write end marker
126 
127  return e;
128  }
129 
130  template<class Task>
133  Event* e = r.alloc<Event>(2*t.size()+1);
134 
135  // Only add assigned and mandatory tasks
136  int n=0;
137  for (int i=t.size(); i--; )
138  if (t[i].assigned() && t[i].mandatory()) {
139  if (t[i].pmin() > 0) {
140  e[n++].init(Event::ERT,t[i].lst(),i);
141  e[n++].init(Event::LRT,t[i].ect(),i);
142  } else if (t[i].pmax() == 0) {
143  e[n++].init(Event::ZRO,t[i].lst(),i);
144  }
145  } else {
146  assert(!t[i].excluded());
147  return NULL;
148  }
149 
150  // Sort events
151  Support::quicksort(e, n);
152 
153  // Write end marker
155 
156  return e;
157  }
158 
159 }}
160 
161 // STATISTICS: int-prop
Zero-length task start time.
Definition: task.hh:501
NodeType t
Type of node.
Definition: bool-expr.cpp:234
Type type(void) const
Return event type.
Definition: event.hpp:46
unsigned int ei
Combines type and number of task.
Definition: task.hh:507
int time(void) const
Return event time.
Definition: event.hpp:50
int idx(void) const
Return event index.
Definition: event.hpp:54
void init(Type e, int t, int i)
Initialize event.
Definition: event.hpp:41
Earliest required time of task.
Definition: task.hh:502
Task array.
Definition: task.hh:169
Handle to region.
Definition: region.hpp:61
End marker.
Definition: task.hh:503
Gecode::IntArgs i(4, 1, 2, 3, 4)
void quicksort(Type *l, Type *r, Less &less)
Standard quick sort.
Definition: sort.hpp:134
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Time-tabling event for task.
Definition: task.hh:494
bool operator<(const Event &e) const
Order among events.
Definition: event.hpp:59
Latest completion time of task.
Definition: task.hh:499
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:784
const int infinity
Infinity for integers.
Definition: int.hh:120
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:47
#define forceinline
Definition: config.hpp:173
Latest required time of task.
Definition: task.hh:498
static Event * events(Region &r, const TaskArray< Task > &t, bool &assigned)
Allocate from r and initialize event array with tasks t.
Definition: event.hpp:87
Gecode toplevel namespace
int t
Time of event.
Definition: task.hh:509
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
Type
Event type for task with order in which they are processed.
Definition: task.hh:497
Earliest start time of task.
Definition: task.hh:500