Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
1b0cf6ce
Commit
1b0cf6ce
authored
Jan 13, 2020
by
Valentin Platzgummer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
123
parent
1ccf1519
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
3 deletions
+92
-3
OptimisationTools.cc
src/Wima/OptimisationTools.cc
+2
-3
OptimisationTools_delLater.cc
src/Wima/OptimisationTools_delLater.cc
+90
-0
No files found.
src/Wima/OptimisationTools.cc
View file @
1b0cf6ce
...
...
@@ -11,7 +11,8 @@ namespace OptimisationTools {
||
startIndex
<
0
||
endIndex
<
0
||
startIndex
>=
numElements
||
endIndex
>=
numElements
)
{
||
endIndex
>=
numElements
||
endIndex
==
startIndex
)
{
return
false
;
}
// Node struct
...
...
@@ -107,6 +108,4 @@ namespace OptimisationTools {
return
true
;
}
// don't seperate parameters with new lines or documentation will break
}
// end OptimisationTools namespace
src/Wima/OptimisationTools_delLater.cc
0 → 100644
View file @
1b0cf6ce
#include "OptimisationTools.h"
#include <QPointF>
namespace
OptimisationTools
{
namespace
{
}
bool
dijkstraAlgorithm
(
const
int
numNodes
,
const
int
startIndex
,
const
int
endIndex
,
QVector
<
int
>
&
elementPath
,
std
::
function
<
double
(
const
int
,
const
int
)
>
distance
)
{
if
(
numNodes
<
0
||
startIndex
<
0
||
endIndex
<
0
||
endIndex
>=
numNodes
||
startIndex
>=
numNodes
||
endIndex
==
startIndex
)
{
return
false
;
}
// distanceToStart[i] contains the distance of element[i] to element[startIndex] (after successful algorithm termination)
QVector
<
double
>
distanceToStart
(
numNodes
,
std
::
numeric_limits
<
qreal
>::
infinity
());
// elementPredecessor[i] contains the predecessor of element[i]
QVector
<
int
>
elementPredecessor
(
numNodes
,
-
1
);
// Elements will be successively removed from this list during the execution of the Dijkstra Algorithm.
QVector
<
int
>
workingSet
;
workingSet
.
reserve
(
numNodes
);
//fill workingSet with 0, 1, ..., numNodes-1
for
(
int
i
=
0
;
i
<
numNodes
;
i
++
)
workingSet
.
append
(
i
);
distanceToStart
[
startIndex
]
=
0
;
// Dijkstra Algorithm
// https://de.wikipedia.org/wiki/Dijkstra-Algorithmus
while
(
workingSet
.
size
()
>
0
)
{
// serach Node with minimal distance
double
minDist
=
std
::
numeric_limits
<
qreal
>::
infinity
();
int
minIndex
=
-
1
;
// index of element with least distance to element[startIndex]
for
(
int
i
=
0
;
i
<
workingSet
.
size
();
i
++
)
{
int
e
=
workingSet
[
i
];
double
dist
=
distanceToStart
[
e
];
if
(
dist
<
minDist
)
{
minDist
=
dist
;
minIndex
=
i
;
}
}
if
(
minIndex
==
-
1
)
return
false
;
int
u
=
workingSet
.
takeAt
(
minIndex
);
if
(
u
==
endIndex
)
// shortest path found
break
;
//update distance
double
distanceU
=
distanceToStart
[
u
];
for
(
int
i
=
0
;
i
<
workingSet
.
size
();
i
++
)
{
int
v
=
workingSet
[
i
];
double
dist
=
distance
(
u
,
v
);
// is ther a alternative path which is shorter?
double
alternative
=
distanceU
+
dist
;
if
(
alternative
<
distanceToStart
[
v
])
{
distanceToStart
[
v
]
=
alternative
;
elementPredecessor
[
v
]
=
u
;
}
}
}
// end Djikstra Algorithm
// reverse assemble elementPath
int
e
=
endIndex
;
while
(
1
)
{
if
(
e
==
-
1
)
{
if
(
elementPath
[
0
]
==
startIndex
)
// check if starting point was reached
break
;
return
false
;
}
elementPath
.
prepend
(
e
);
//Update Node
e
=
elementPredecessor
[
e
];
}
return
true
;
}
// end anonymous namespace
}
// end OptimisationTools namespace
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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