added interface for walkers

some new helper methods
added interpolater for paths
This commit is contained in:
2016-01-28 21:48:04 +01:00
parent c4ea811342
commit da0bd43fe0
10 changed files with 92 additions and 66 deletions

15
grid/walk/GridWalk.h Normal file
View File

@@ -0,0 +1,15 @@
#ifndef GRIDWALK_H
#define GRIDWALK_H
#include "GridWalkState.h"
#include "../Grid.h"
template <typename T> class GridWalk {
public:
virtual GridWalkState<T> getDestination(Grid<T>& grid, const GridWalkState<T> start, const float distance_m) = 0;
};
#endif // GRIDWALK_H

View File

@@ -2,6 +2,7 @@
#define GRIDWALKHELPER_H
#include "../../geo/Heading.h"
#include "GridWalkState.h"
class GridWalkHelper {
@@ -41,6 +42,7 @@ public:
template <typename T, typename Walker> static GridWalkState<T> retryOrInvert(Walker& w, const int numRetries, Grid<T>& grid, GridWalkState<T> start, float distance_m) {
Assert::isTrue(distance_m >= 0, "distance must not be negative!");
Assert::isNotNull(start.node, "starting node must not be null");
GridWalkState<T> res;

View File

@@ -9,6 +9,7 @@
#include "../../nav/dijkstra/Dijkstra.h"
#include "GridWalk.h"
#include "GridWalkState.h"
#include "GridWalkHelper.h"
@@ -16,7 +17,7 @@
* perform walks on the grid based on some sort of weighting
* and drawing from the weighted elements
*/
template <typename T> class GridWalkLightAtTheEndOfTheTunnel {
template <typename T> class GridWalkLightAtTheEndOfTheTunnel : public GridWalk<T> {
friend class GridWalkHelper;
@@ -62,7 +63,7 @@ public:
}
GridWalkState<T> getDestination(Grid<T>& grid, GridWalkState<T> start, float distance_m) {
GridWalkState<T> getDestination(Grid<T>& grid, GridWalkState<T> start, float distance_m) override {
return GridWalkHelper::retryOrInvert(*this, 2, grid, start, distance_m);
@@ -72,7 +73,7 @@ private:
GridWalkState<T> walk(Grid<T>& grid, GridWalkState<T> cur, float distRest_m) {
drawer.reset();;
drawer.reset();
// calculate the weight for all possible destinations from "cur"
for (T& neighbor : grid.neighbors(*cur.node)) {

View File

@@ -12,13 +12,14 @@
#include "GridWalkState.h"
#include "GridWalkHelper.h"
#include "GridWalk.h"
/**
* keeps something like an "average position within the last X steps"
* and tries to move away from this point as fast as possible
*
*/
template <typename T> class GridWalkPushForward {
template <typename T> class GridWalkPushForward : public GridWalk<T> {
friend class GridWalkHelper;
@@ -42,7 +43,7 @@ public:
;
}
GridWalkState<T> getDestination(Grid<T>& grid, const GridWalkState<T> start, const float distance_m) {
GridWalkState<T> getDestination(Grid<T>& grid, const GridWalkState<T> start, const float distance_m) override {
return GridWalkHelper::retryOrInvert(*this, 2, grid, start, distance_m);

View File

@@ -6,6 +6,7 @@
#include "../../nav/dijkstra/Dijkstra.h"
#include "GridWalk.h"
#include "GridWalkState.h"
#include "GridWalkHelper.h"
@@ -22,14 +23,14 @@
* to stay within the room..
*
*/
template <typename T> class GridWalkRandomHeadingUpdate {
template <typename T> class GridWalkRandomHeadingUpdate : public GridWalk<T> {
friend class GridWalkHelper;
private:
/** per-edge: change heading with this sigma */
static constexpr float HEADING_CHANGE_SIGMA = Angle::degToRad(4);
static constexpr float HEADING_CHANGE_SIGMA = Angle::degToRad(8);
/** fast random-number-generator */
std::minstd_rand gen;
@@ -41,10 +42,10 @@ public:
/** ctor */
GridWalkRandomHeadingUpdate() {
;
gen.seed(1234);
}
GridWalkState<T> getDestination(Grid<T>& grid, const GridWalkState<T> start, const float distance_m) {
GridWalkState<T> getDestination(Grid<T>& grid, const GridWalkState<T> start, const float distance_m) override {
return GridWalkHelper::retryOrInvert(*this, 2, grid, start, distance_m);

View File

@@ -9,6 +9,7 @@
#include "../../math/Distributions.h"
#include "../../nav/dijkstra/Dijkstra.h"
#include "GridWalk.h"
#include "GridWalkState.h"
#include "GridWalkHelper.h"
@@ -23,14 +24,14 @@
* - adds additional randomness which should be more stable
*
*/
template <typename T> class GridWalkRandomHeadingUpdateAdv {
template <typename T> class GridWalkRandomHeadingUpdateAdv : public GridWalk<T> {
friend class GridWalkHelper;
private:
/** per-edge: change heading with this sigma */
static constexpr float HEADING_CHANGE_SIGMA = Angle::degToRad(5);
static constexpr float HEADING_CHANGE_SIGMA = Angle::degToRad(10);
/** fast random-number-generator */
std::minstd_rand gen;
@@ -45,7 +46,7 @@ public:
;
}
GridWalkState<T> getDestination(Grid<T>& grid, const GridWalkState<T> start, const float distance_m) {
GridWalkState<T> getDestination(Grid<T>& grid, const GridWalkState<T> start, const float distance_m) override {
return GridWalkHelper::retryOrInvert(*this, 2, grid, start, distance_m);