main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
gecode
int
task
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
45
forceinline
Event::Type
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>
86
forceinline
Event
*
87
Event::events
(
Region
&
r
,
const
TaskArray<Task>
&
t
,
bool
&
assigned
) {
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
125
e[
n
++].
init
(
Event::END
,
Limits::infinity
,0);
126
127
return
e;
128
}
129
130
template
<
class
Task>
131
forceinline
Event
*
132
Event::events
(
Region
&
r
,
const
TaskArray<Task>
&
t
) {
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
154
e[
n
++].
init
(
Event::END
,
Limits::infinity
,0);
155
156
return
e;
157
}
158
159
}}
160
161
// STATISTICS: int-prop
Gecode::Int::Event::ERT
@ ERT
Earliest required time of task.
Definition:
task.hh:502
forceinline
#define forceinline
Definition:
config.hpp:173
Gecode::Int::Event::EST
@ EST
Earliest start time of task.
Definition:
task.hh:500
Gecode::Int::Event
Time-tabling event for task.
Definition:
task.hh:494
Gecode::Int::Precede::assigned
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition:
single.hpp:47
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
t
NodeType t
Type of node.
Definition:
bool-expr.cpp:234
Gecode::Int::Event::init
void init(Type e, int t, int i)
Initialize event.
Definition:
event.hpp:41
Gecode::Support::quicksort
void quicksort(Type *l, Type *r, Less &less)
Standard quick sort.
Definition:
sort.hpp:134
Gecode
Gecode toplevel namespace
Gecode::Int::Event::operator<
bool operator<(const Event &e) const
Order among events.
Definition:
event.hpp:59
Gecode::Int::Event::type
Type type(void) const
Return event type.
Definition:
event.hpp:46
Gecode::Region
Handle to region.
Definition:
region.hpp:61
Gecode::Int::Event::idx
int idx(void) const
Return event index.
Definition:
event.hpp:54
Gecode::r
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition:
set.hh:784
Gecode::Int::operator<<
std::basic_ostream< Char, Traits > & operator<<(std::basic_ostream< Char, Traits > &os, const IdxViewArray< View > &x)
Definition:
idx-view.hpp:165
GECODE_NEVER
#define GECODE_NEVER
Assert that this command is never executed.
Definition:
macros.hpp:60
Gecode::Int::Event::t
int t
Time of event.
Definition:
task.hh:509
Gecode::Int::Event::LCT
@ LCT
Latest completion time of task.
Definition:
task.hh:499
Gecode::Int::Limits::infinity
const int infinity
Infinity for integers.
Definition:
int.hh:120
Gecode::Int::Event::time
int time(void) const
Return event time.
Definition:
event.hpp:50
Gecode::Int::Event::END
@ END
End marker.
Definition:
task.hh:503
Gecode::Int::Event::events
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::Int::TaskArray
Task array.
Definition:
task.hh:169
Gecode::Int::Event::ei
unsigned int ei
Combines type and number of task.
Definition:
task.hh:507
Gecode::Int::Event::ZRO
@ ZRO
Zero-length task start time.
Definition:
task.hh:501
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238
Gecode::Int::Event::Type
Type
Event type for task with order in which they are processed.
Definition:
task.hh:497
Gecode::Int::Event::LRT
@ LRT
Latest required time of task.
Definition:
task.hh:498