1
0
Fork 0

Added version with broken threads. Computation is correct, but threads do not fire up

This commit is contained in:
Michael Hackstein 2015-04-23 13:40:41 -07:00
parent a553548d87
commit c1c98b16f6
3 changed files with 74 additions and 13 deletions

View File

@ -55,6 +55,8 @@ class SimpleEdgeExpander {
CollectionNameResolver const* resolver;
bool usesDist;
string dirung;
public:
Traverser::VertexId extractFromId(TRI_doc_mptr_copy_t ptr) {
@ -85,6 +87,7 @@ class SimpleEdgeExpander {
Traverser::Direction dir,
vector<Traverser::Neighbor>& result
) {
cout << dirung << endl;
std::vector<TRI_doc_mptr_copy_t> edges;
// Process Vertex Id!
size_t split;
@ -105,11 +108,12 @@ class SimpleEdgeExpander {
throw TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
}
auto collectionCId = col->_cid;
if (dir == Traverser::FORWARD) {
edges = TRI_LookupEdgesDocumentCollection(edgeCollection, forwardDirection, collectionCId, buffer);
} else {
edges = TRI_LookupEdgesDocumentCollection(edgeCollection, backwardDirection, collectionCId, buffer);
edges = TRI_LookupEdgesDocumentCollection(edgeCollection, direction, collectionCId, buffer);
if (direction == 1) {
cout << edges.size() << endl;
}
std::unordered_map<Traverser::VertexId, Traverser::Neighbor> candidates;
Traverser::VertexId from;
Traverser::VertexId to;
@ -160,9 +164,16 @@ class SimpleEdgeExpander {
SimpleEdgeExpander(
TRI_edge_direction_e edgeDirection,
TRI_document_collection_t* edgeCollection,
<<<<<<< HEAD
CollectionNameResolver const* resolver
=======
string edgeCollectionName,
CollectionNameResolver const resolver,
string dirung
>>>>>>> Added version with broken threads. Computation is correct, but threads do not fire up
) :
edgeCollection(edgeCollection),
<<<<<<< HEAD
resolver(resolver)
{
usesDist = false;
@ -181,6 +192,21 @@ class SimpleEdgeExpander {
static <v8::Handle<v8::Value> pathToV8(v8::Isolate* isolate, Traverser::Path p) {
v8::Handle<v8::Value> result;
=======
resolver(resolver),
usesDist(false),
dirung(dirung)
{
cout << direction << endl;
edgeIdPrefix = edgeCollectionName + "/";
};
};
static v8::Handle<v8::Value> pathIdsToV8(v8::Isolate* isolate, Traverser::Path& p) {
v8::EscapableHandleScope scope(isolate);
TRI_GET_GLOBALS();
v8::Handle<v8::Object> result = v8::Object::New(isolate);
>>>>>>> Added version with broken threads. Computation is correct, but threads do not fire up
uint32_t const vn = static_cast<uint32_t>(p.vertices.size());
v8::Handle<v8::Array> vertices = v8::Array::New(isolate, static_cast<int>(vn));
@ -196,7 +222,12 @@ static <v8::Handle<v8::Value> pathToV8(v8::Isolate* isolate, Traverser::Path p)
for (size_t j = 0; j < en; ++j) {
edges->Set(static_cast<uint32_t>(j), TRI_V8_ASCII_STRING(p.edges[j]));
}
<<<<<<< HEAD
result->Set("edges", edges);
=======
result->Set(TRI_V8_STRING("edges"), edges);
result->Set(TRI_V8_STRING("distance"), v8::Number::New(isolate, p.weight));
>>>>>>> Added version with broken threads. Computation is correct, but threads do not fire up
return result;
};
@ -316,8 +347,26 @@ void TRI_RunDijkstraSearch (const v8::FunctionCallbackInfo<v8::Value>& args) {
TRI_V8_THROW_EXCEPTION_MEMORY();
}
<<<<<<< HEAD
v8::Handle<v8::Value> result;
v8::Handle<v8::Array> documents;
=======
TRI_document_collection_t* ecol = trx.trxCollection(col->_cid)->_collection->_collection;
CollectionNameResolver resolver1(vocbase);
CollectionNameResolver resolver2(vocbase);
SimpleEdgeExpander forwardExpander(TRI_EDGE_OUT, ecol, edgeCollectionName, resolver1, "A");
SimpleEdgeExpander backwardExpander(TRI_EDGE_IN, ecol, edgeCollectionName, resolver2, "B");
Traverser traverser(forwardExpander, backwardExpander);
unique_ptr<Traverser::Path> path(traverser.ShortestPath(startVertex, targetVertex));
if (path.get() == nullptr) {
res = trx.finish(res);
v8::EscapableHandleScope scope(isolate);
TRI_V8_RETURN(scope.Escape<v8::Value>(v8::Object::New(isolate)));
}
auto result = pathIdsToV8(isolate, *path);
res = trx.finish(res);
>>>>>>> Added version with broken threads. Computation is correct, but threads do not fire up
// This is how to get the data out of the collections!
// Vertices

View File

@ -90,11 +90,16 @@ void Traverser::lookupPeer (ThreadInfo& info,
////////////////////////////////////////////////////////////////////////////////
void Traverser::searchFromVertex (
ThreadInfo myInfo,
ThreadInfo peerInfo,
ThreadInfo* myInfo_p,
ThreadInfo* peerInfo_p,
VertexId start,
ExpanderFunction expander
ExpanderFunction expander,
string id
) {
ThreadInfo& myInfo(*myInfo_p);
ThreadInfo& peerInfo(*peerInfo_p);
cout << id << ": inserting " << start << endl;
insertNeighbor(myInfo, start, "", "", 0);
auto nextVertexIt = myInfo.queue.begin();
std::vector<Neighbor> neighbors;
@ -103,9 +108,12 @@ void Traverser::searchFromVertex (
// there still is a vertex on the stack.
while (!bingo && nextVertexIt != myInfo.queue.end()) {
auto nextVertex = *nextVertexIt;
cout << id << ": next " << nextVertex.vertex << endl;
myInfo.queue.erase(nextVertexIt);
neighbors.clear();
expander(nextVertex.vertex, neighbors);
for (auto neighbor : neighbors) {
for (auto& neighbor : neighbors) {
cout << id << ": neighbor " << neighbor.neighbor << endl;
insertNeighbor(myInfo, neighbor.neighbor, nextVertex.vertex,
neighbor.edge, nextVertex.weight + neighbor.weight);
}
@ -115,6 +123,7 @@ void Traverser::searchFromVertex (
auto nextVertexLookup = myInfo.lookup.find(nextVertex.vertex);
TRI_ASSERT(nextVertexLookup != myInfo.lookup.end());
cout << id << ": done " << nextVertexLookup->first << endl;
nextVertexLookup->second.done = true;
myInfo.mutex.unlock();
@ -145,12 +154,14 @@ Traverser::Path* Traverser::ShortestPath (VertexId const& start,
ThreadInfo backwardInfo(_backwardLookup, _backwardQueue, _backwardMutex);
std::thread forwardSearcher(&Traverser::searchFromVertex,
this, forwardInfo, backwardInfo, start, forwardExpander);
this, &forwardInfo, &backwardInfo, start, forwardExpander, "X");
std::thread backwardSearcher(&Traverser::searchFromVertex,
this, backwardInfo, forwardInfo, target, backwardExpander);
this, &backwardInfo, &forwardInfo, target, backwardExpander, "Y");
forwardSearcher.join();
backwardSearcher.join();
cout << forwardInfo.lookup.size() << backwardInfo.lookup.size() << endl;
if (!bingo) {
return nullptr;
}

View File

@ -574,10 +574,11 @@ namespace triagens {
VertexId& neighbor,
EdgeWeight& weight
);
void searchFromVertex ( ThreadInfo myInfo,
ThreadInfo peerInfo,
void searchFromVertex ( ThreadInfo* myInfo,
ThreadInfo* peerInfo,
VertexId start,
ExpanderFunction expander
ExpanderFunction expander,
std::string id
);
};
}