Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Emmanuel Hebrard
SchedCL
Commits
0b6b0943
Commit
0b6b0943
authored
Oct 26, 2021
by
ehebrard
Browse files
prof
parent
68c7a036
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
src/header/BellmanFord.hpp
View file @
0b6b0943
...
...
@@ -7,6 +7,8 @@
#include
"Global.hpp"
#include
"SparseSet.hpp"
#define DEBUG_BELLMANFORD
using
namespace
std
;
namespace
schedcl
{
...
...
@@ -28,13 +30,27 @@ public:
// updates all shortest paths from x (and through y) and put them in
// 'shortest_path'. Sets the flag 'negative_cycle' if it finds a negative
// cycle including x-y
template
<
class
G
>
template
<
class
G
#ifdef DEBUG_BELLMANFORD
,
class
P
#endif
>
void
allShorterPaths
(
const
int
x
,
const
int
y
,
const
T
wxy
,
const
G
&
neighbors
,
vector
<
T
>
&
shortest_path
,
SparseSet
<>
&
reached
);
SparseSet
<>
&
reached
#ifdef DEBUG_BELLMANFORD
,
P
&
printer
#endif
);
bool
negative_cycle
{
false
};
#ifdef DEBUG_BELLMANFORD
bool
debug_flag
{
false
};
#endif
// vector<T> shortest_path;
// SparseSet<> reached;
...
...
@@ -98,8 +114,29 @@ void BellmanFord<T>::allShortestPaths(const int s, const G& neighbors, vector<T>
}
template
<
typename
T
>
template
<
class
G
>
void
BellmanFord
<
T
>::
allShorterPaths
(
const
int
x
,
const
int
y
,
const
T
wxy
,
const
G
&
neighbors
,
vector
<
T
>&
shortest_path
,
SparseSet
<>&
reached
)
{
template
<
class
G
#ifdef DEBUG_BELLMANFORD
,
class
P
#endif
>
void
BellmanFord
<
T
>::
allShorterPaths
(
const
int
x
,
const
int
y
,
const
T
wxy
,
const
G
&
neighbors
,
vector
<
T
>
&
shortest_path
,
SparseSet
<>
&
reached
#ifdef DEBUG_BELLMANFORD
,
P
&
printer
#endif
)
{
assert
(
changed
.
empty
());
#ifdef DEBUG_BELLMANFORD
if
(
debug_flag
)
cout
<<
" ASP from "
<<
printer
.
label
(
y
)
<<
" after edge "
<<
printer
.
label
(
x
)
<<
"->"
<<
printer
.
label
(
y
)
<<
" ("
<<
wxy
<<
")
\n
"
;
#endif
shortest_path
[
y
]
=
wxy
;
...
...
@@ -108,16 +145,52 @@ void BellmanFord<T>::allShorterPaths(const int x, const int y, const T wxy, cons
while
(
not
changed
.
empty
())
{
auto
u
{
changed
.
front
()};
#ifdef DEBUG_BELLMANFORD
if
(
debug_flag
)
{
cout
<<
printer
.
label
(
u
)
<<
" ("
<<
shortest_path
[
u
]
<<
") stack:"
;
for
(
auto
q
:
changed
)
cout
<<
" "
<<
printer
.
label
(
q
);
cout
<<
" vis:"
;
for
(
auto
q
:
reached
)
cout
<<
" "
<<
printer
.
label
(
q
);
cout
<<
endl
;
}
#endif
changed
.
pop_front
();
for
(
auto
e
:
neighbors
[
u
])
{
auto
v
{
e
.
neighbor
()};
auto
w
{
e
.
length
()};
#ifdef DEBUG_BELLMANFORD
if
(
debug_flag
)
cout
<<
" -"
<<
printer
.
label
(
v
)
<<
" ("
<<
shortest_path
[
u
]
<<
"+"
<<
w
<<
"/"
<<
shortest_path
[
v
]
<<
")
\n
"
;
#endif
if
(
w
!=
INFTY
and
shortest_path
[
u
]
+
w
<
shortest_path
[
v
])
{
if
(
v
==
x
and
wxy
+
w
<
0
)
{
#ifdef DEBUG_BELLMANFORD
if
(
debug_flag
)
cout
<<
" explore
\n
"
;
#endif
if
(
v
==
x
and
wxy
+
shortest_path
[
u
]
+
w
<
0
)
{
#ifdef DEBUG_BELLMANFORD
if
(
debug_flag
)
cout
<<
"created a negative cycle between "
<<
printer
.
label
(
x
)
<<
" and "
<<
printer
.
label
(
y
)
<<
" ("
<<
wxy
<<
" + "
<<
shortest_path
[
u
]
<<
" + "
<<
w
<<
")"
<<
endl
;
#endif
negative_cycle
=
true
;
changed
.
clear
();
// exit(1);
return
;
}
...
...
@@ -127,6 +200,10 @@ void BellmanFord<T>::allShorterPaths(const int x, const int y, const T wxy, cons
if
(
not
reached
.
has
(
v
))
reached
.
add
(
v
);
}
#ifdef DEBUG_BELLMANFORD
else
if
(
debug_flag
)
cout
<<
" reject
\n
"
;
#endif
}
}
}
...
...
src/header/DistanceVariable.hpp
View file @
0b6b0943
...
...
@@ -139,6 +139,7 @@ public:
// get the current distance
T
get
()
const
{
return
literals
.
back
().
value
;
}
operator
T
()
const
{
return
literals
.
back
().
value
;
}
const
Bound
<
T
>
&
back
()
const
{
return
literals
.
back
();
}
...
...
src/header/Schedule.hpp
View file @
0b6b0943
This diff is collapsed.
Click to expand it.
src/header/SparseGraph.hpp
View file @
0b6b0943
...
...
@@ -139,6 +139,7 @@ private:
template
<
typename
T
>
SparseGraph
<
T
>::
SparseGraph
()
:
ReversibleObject
()
{}
template
<
typename
T
>
void
SparseGraph
<
T
>::
addArc
(
DistanceVariable
<
T
>
*
v
)
{
auto
pto
{
static_cast
<
int
>
(
neighbor
[
PREDECESSOR
][
v
->
to
].
size
())};
auto
pfrom
{
static_cast
<
int
>
(
neighbor
[
SUCCESSOR
][
v
->
from
].
size
())};
...
...
src/header/TimeTabling.hpp
View file @
0b6b0943
...
...
@@ -125,28 +125,28 @@ CumulativeTimeTabling<T, C>::CumulativeTimeTabling(Schedule<T> &schedule,
// ORIGIN <= START(i)
distance
[
START
(
i
)][
ORIGIN
]
=
m_schedule
.
addPrecedence
(
ORIGIN
,
START
(
m_tasks
[
i
]));
m_schedule
.
addPrecedence
(
ORIGIN
,
START
(
m_tasks
[
i
])
,
-
INFTY
);
// START(i) <= ORIGIN + oo
distance
[
ORIGIN
][
START
(
i
)]
=
m_schedule
.
addMaximumLag
(
ORIGIN
,
START
(
m_tasks
[
i
]),
INFTY
);
// ORIGIN <= END(i)
distance
[
END
(
i
)][
ORIGIN
]
=
m_schedule
.
addPrecedence
(
ORIGIN
,
END
(
m_tasks
[
i
]));
m_schedule
.
addPrecedence
(
ORIGIN
,
END
(
m_tasks
[
i
])
,
-
INFTY
);
// END(i) <= ORIGIN + oo
distance
[
ORIGIN
][
END
(
i
)]
=
m_schedule
.
addMaximumLag
(
ORIGIN
,
END
(
m_tasks
[
i
]),
INFTY
);
// END(i) <= HORIZON
distance
[
HORIZON
][
END
(
i
)]
=
m_schedule
.
addPrecedence
(
END
(
m_tasks
[
i
]),
HORIZON
);
m_schedule
.
addPrecedence
(
END
(
m_tasks
[
i
]),
HORIZON
,
-
INFTY
);
// HORIZON <= END(i) + oo
distance
[
END
(
i
)][
HORIZON
]
=
m_schedule
.
addMaximumLag
(
END
(
m_tasks
[
i
]),
HORIZON
,
INFTY
);
// START(i) <= HORIZON
distance
[
HORIZON
][
START
(
i
)]
=
m_schedule
.
addPrecedence
(
START
(
m_tasks
[
i
]),
HORIZON
);
m_schedule
.
addPrecedence
(
START
(
m_tasks
[
i
]),
HORIZON
,
-
INFTY
);
// HORIZON <= START(i) + oo
distance
[
START
(
i
)][
HORIZON
]
=
m_schedule
.
addMaximumLag
(
START
(
m_tasks
[
i
]),
HORIZON
,
INFTY
);
...
...
@@ -227,19 +227,16 @@ void CumulativeTimeTabling<T, C>::post(const int idx) {
#ifdef DEBUG_CONSTRAINT
if
(
this
->
ResourceConstraint
<
T
>::
debug_flag
)
{
cout
<<
endl
<<
"post timetabling("
;
for
(
auto
t
:
m_tasks
)
{
cout
<<
" "
<<
m_schedule
.
taskLabel
(
t
)
<<
" "
<<
m_schedule
.
domain
(
t
);
}
cout
<<
")
\n
"
;
cout
<<
"post "
<<
*
this
<<
endl
;
}
#endif
int
k
{
0
};
//
int k{0};
for
(
int
i
{
0
};
i
<
distance
.
size
();
++
i
)
{
for
(
int
j
{
i
+
1
};
j
<
distance
.
size
();
++
j
)
{
m_schedule
.
wake_me_on
(
distance
[
i
][
j
],
idx
,
k
++
);
m_schedule
.
wake_me_on
(
distance
[
i
][
j
],
idx
,
i
*
distance
.
size
()
+
j
);
m_schedule
.
wake_me_on
(
distance
[
j
][
i
],
idx
,
j
*
distance
.
size
()
+
i
);
}
}
...
...
@@ -520,7 +517,13 @@ void CumulativeTimeTabling<T, C>::propagate() {
template
<
class
T
,
class
C
>
ostream
&
CumulativeTimeTabling
<
T
,
C
>::
display
(
ostream
&
os
)
const
{
os
<<
"TimeTabling("
;
os
<<
"TimeTabling"
;
#ifdef DEBUG_CONSTRAINT
os
<<
"["
<<
ResourceConstraint
<
T
>::
id
<<
"]"
;
#endif
os
<<
"("
;
for
(
auto
t
:
m_tasks
)
{
cout
<<
" "
<<
m_schedule
.
taskLabel
(
t
)
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment