Toggle navigation
Toggle navigation
This project
Loading...
Sign in
홍길동
/
onos
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Thomas Vachuska
2014-10-27 08:57:08 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4d69087215ae59342d519c4f37df2237070556c1
4d690872
1 parent
eb24e9d0
Doh! Forgot to actually check for negative cycles in relaxEdge.
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
3 deletions
utils/misc/src/main/java/org/onlab/graph/AbstractGraphPathSearch.java
utils/misc/src/main/java/org/onlab/graph/DijkstraGraphSearch.java
utils/misc/src/test/java/org/onlab/graph/DijkstraGraphSearchTest.java
utils/misc/src/main/java/org/onlab/graph/AbstractGraphPathSearch.java
View file @
4d69087
...
...
@@ -151,12 +151,19 @@ public abstract class AbstractGraphPathSearch<V extends Vertex, E extends Edge<V
* @param e edge to be relaxed
* @param cost base cost to reach the edge destination vertex
* @param ew optional edge weight function
* @param forbidNegatives if true negative values will forbid the link
* @return true if the edge was relaxed; false otherwise
*/
boolean
relaxEdge
(
E
e
,
double
cost
,
EdgeWeight
<
V
,
E
>
ew
)
{
boolean
relaxEdge
(
E
e
,
double
cost
,
EdgeWeight
<
V
,
E
>
ew
,
boolean
...
forbidNegatives
)
{
V
v
=
e
.
dst
();
double
oldCost
=
cost
(
v
);
double
newCost
=
cost
+
(
ew
==
null
?
1.0
:
ew
.
weight
(
e
));
double
hopCost
=
ew
==
null
?
1.0
:
ew
.
weight
(
e
);
if
(
hopCost
<
0
&&
forbidNegatives
.
length
==
1
&&
forbidNegatives
[
0
])
{
return
false
;
}
double
newCost
=
cost
+
hopCost
;
boolean
relaxed
=
newCost
<
oldCost
;
boolean
same
=
Math
.
abs
(
newCost
-
oldCost
)
<
samenessThreshold
;
if
(
same
||
relaxed
)
{
...
...
utils/misc/src/main/java/org/onlab/graph/DijkstraGraphSearch.java
View file @
4d69087
...
...
@@ -40,7 +40,7 @@ public class DijkstraGraphSearch<V extends Vertex, E extends Edge<V>>
if
(
cost
<
Double
.
MAX_VALUE
)
{
// If the vertex is reachable, relax all its egress edges.
for
(
E
e
:
graph
.
getEdgesFrom
(
nearest
))
{
result
.
relaxEdge
(
e
,
cost
,
weight
);
result
.
relaxEdge
(
e
,
cost
,
weight
,
true
);
}
}
...
...
utils/misc/src/test/java/org/onlab/graph/DijkstraGraphSearchTest.java
View file @
4d69087
...
...
@@ -91,4 +91,21 @@ public class DijkstraGraphSearchTest extends BreadthFirstSearchTest {
executeSearch
(
graphSearch
(),
graph
,
A
,
E
,
weight
,
3
,
3.0
);
}
@Test
public
void
negativeWeights
()
{
graph
=
new
AdjacencyListsGraph
<>(
of
(
A
,
B
,
C
,
D
,
E
,
F
,
G
),
of
(
new
TestEdge
(
A
,
B
,
1
),
new
TestEdge
(
A
,
C
,
-
1
),
new
TestEdge
(
B
,
D
,
1
),
new
TestEdge
(
D
,
A
,
-
2
),
new
TestEdge
(
C
,
D
,
1
),
new
TestEdge
(
D
,
E
,
1
),
new
TestEdge
(
D
,
F
,
1
),
new
TestEdge
(
E
,
G
,
1
),
new
TestEdge
(
F
,
G
,
1
),
new
TestEdge
(
G
,
A
,
-
5
),
new
TestEdge
(
A
,
G
,
4
)));
executeSearch
(
graphSearch
(),
graph
,
A
,
G
,
weight
,
3
,
4.0
);
}
}
...
...
Please
register
or
login
to post a comment