Skip to content

Commit

Permalink
Make MDP fully a C++ module too.
Browse files Browse the repository at this point in the history
  • Loading branch information
instance01 committed Jun 1, 2019
1 parent b0f9f43 commit 4c792b5
Show file tree
Hide file tree
Showing 9 changed files with 507 additions and 642 deletions.
5 changes: 5 additions & 0 deletions osmnx_mdp/algorithms/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Each algorithm implements the Algorithm class.
Each algorithm consists of:
* C++ file with the meat of the algorithm
* pyx file with the Cython wrapper for the C++ module
* pxd file (Cython header) for easier importing
13 changes: 3 additions & 10 deletions osmnx_mdp/algorithms/cpp_brtdp.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
#include <google/dense_hash_map>
#include <random>
#include <vector>


// TODO: Copied from dstar lite
struct pair_hash {
long long operator () (const std::pair<long, long> &p) const {
long long ret = p.first;
ret <<= 32;
return ret + p.second;
}
};
#include "cpp_lib.hpp"


class CPP_BRTDP {
Expand All @@ -30,6 +21,8 @@ class CPP_BRTDP {
std::vector<long> *S;
google::dense_hash_map<long, std::vector<std::pair<long, long>>> *A;
google::dense_hash_map<std::pair<long, long>, float, pair_hash> *C;
// It is needed that this is DOUBLE. Especially (B)RTDP
// needs precision. Who knows how bad the effect in VI is.
google::dense_hash_map<
long,
google::dense_hash_map<
Expand Down
9 changes: 1 addition & 8 deletions osmnx_mdp/algorithms/cpp_dstar_lite.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
#include <google/dense_hash_map>
#include <set>
#include <vector>
#include "cpp_lib.hpp"

// TODO: Copied from testthis.cpp
struct pair_hash {
long long operator () (const std::pair<long, long> &p) const {
long long ret = p.first;
ret <<= 32;
return ret + p.second;
}
};

class cpp_DStar_Lite {
public:
Expand Down
28 changes: 28 additions & 0 deletions osmnx_mdp/algorithms/cpp_lib.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef LIB_INCLUDE
#define LIB_INCLUDE

#include <vector>
// TODO: Move to ../cpp_lib.hpp
// Basically create a C++ version of lib.

// TODO: Explain why collisions probably won't happen with this.
// We assume a 64 bit system.
// Node numbers sometimes exceed the maximum 32 bit number, which is around
// 2.1 billion, by a small margin (e.g. 3, 4 or 5 billion). Thus by shifting
// We lose one number at the front, e.g. 3.1 billion becomes 100 million
// (before shifting).
// Since we use this hashing for actions, i.e. the two longs denote the ids of
// two adjacent nodes, to get a collision, we need to find a node that has as
// neighbors two numbers that are exactly the same up to their last (most
// signifcant) digit, the billion digit.
// This is highly unlikely. // TODO WHY
// Since we simply add the second number, none of its digits get lost.
// And with just two ops it's super efficient. Just uses a lot of space.
struct pair_hash {
long long operator () (const std::pair<long, long> &p) const {
long long ret = p.first;
ret <<= 32;
return ret + p.second;
}
};
#endif
Loading

0 comments on commit 4c792b5

Please sign in to comment.