dressipi hard coded query

This commit is contained in:
Marko Budiselic 2016-09-25 12:51:58 +01:00
parent d806d635f9
commit a0438392df
5 changed files with 19 additions and 162 deletions

View File

@ -241,7 +241,6 @@ FILE(COPY ${include_dir}/storage/label/label_collection.hpp DESTINATION ${build_
FILE(COPY ${include_dir}/storage/label/label_store.hpp DESTINATION ${build_include_dir}/storage/label)
FILE(COPY ${include_dir}/storage/indexes/index_record.hpp DESTINATION ${build_include_dir}/storage/indexes)
FILE(COPY ${include_dir}/storage/indexes/index_record_collection.hpp DESTINATION ${build_include_dir}/storage/indexes)
FILE(COPY ${include_dir}/storage/indexes/index_base.hpp DESTINATION ${build_include_dir}/storage/indexes)
FILE(COPY ${include_dir}/storage/indexes/impl/nonunique_unordered_index.hpp DESTINATION ${build_include_dir}/storage/indexes/impl)

View File

@ -47,7 +47,25 @@ ctest -R concurrent
ctest -R concurrent --parallel 4
```
# custom test build example
## Proof of concept
### Dressipi
Run command:
```
cd build/poc
MEMGRAPH_CONFIG=/path/to/config/memgraph.yaml ./poc_astar -v "dressipi/graph_nodes_export.csv" -e "dressipi/graph_edges_export.csv"
```
### Powerlinx
Run command:
```
cd build/poc
MEMGRAPH_CONFIG=/path/to/config/memgraph.yaml ./profile -d ";" -v "node_account.csv" -v "node_company.csv" -v "node_opportunity.csv" -v "node_personnel.csv" -e "rel_created.csv" -e "rel_has_match.csv" -e "rel_interested_in.csv" -e "rel_is_employee.csv" -e "rel_partnered_with.csv" -e "rel_reached_to.csv" -e "rel_searched_and_clicked.csv" -e "rel_viewed.csv" -e "rel_works_in.csv"
```
# Custom test build example
clang++ -std=c++1y -o concurrent_skiplist ../tests/concurrent/skiplist.cpp -pg -I../src/ -I../libs/fmt -Lfmt-prefix/src/fmt-build/fmt -lfmt -lpthread
# TODO

View File

@ -1,3 +0,0 @@
/*
!.gitignore
!/cpu

View File

@ -1,3 +0,0 @@
/*
!.gitignore
!/hardcode

View File

@ -1,154 +0,0 @@
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include "query_engine/i_code_cpu.hpp"
#include "storage/model/properties/all.hpp"
#include "utils/memory/stack_allocator.hpp"
using std::cout;
using std::endl;
// Dressipi astar query of 4 clicks.
// BARRIER!
namespace barrier
{
// using STREAM = std::ostream;
using STREAM = RecordStream<::io::Socket>;
constexpr size_t max_depth = 3;
constexpr size_t limit = 10;
class Node
{
public:
Node *parent = {nullptr};
VertexPropertyType<Double> tkey;
double cost;
int depth = {0};
VertexAccessor vacc;
Node(VertexAccessor vacc, double cost,
VertexPropertyType<Double> const &tkey)
: cost(cost), vacc(vacc), tkey(tkey)
{
}
Node(VertexAccessor vacc, double cost, Node *parent,
VertexPropertyType<Double> const &tkey)
: cost(cost), vacc(vacc), parent(parent), depth(parent->depth + 1),
tkey(tkey)
{
}
double sum_vertex_score()
{
auto now = this;
double sum = 0;
do {
sum += (now->vacc.at(tkey).get())->value();
now = now->parent;
} while (now != nullptr);
return sum;
}
};
bool vertex_filter_contained(DbAccessor &t, VertexAccessor &v, Node *before)
{
if (v.fill()) {
bool found;
do {
found = false;
before = before->parent;
if (before == nullptr) {
return true;
}
} while (v.in_contains(before->vacc));
}
return false;
}
void astar(DbAccessor &t, code_args_t &args, STREAM &stream)
{
StackAllocator stack;
VertexPropertyType<Double> tkey = t.vertex_property_key<Double>("score");
auto cmp = [](Node *left, Node *right) { return left->cost > right->cost; };
std::priority_queue<Node *, std::vector<Node *>, decltype(cmp)> queue(cmp);
std::vector<Node *> all_nodes;
auto start_vr = t.vertex_find(Id(args[0].as<Int64>().value()));
if (!start_vr.is_present()) {
stream.write_failure({{}});
return;
}
start_vr.get().fill();
Node *start = stack.make<Node>(start_vr.take(), 0, tkey);
queue.push(start);
all_nodes.push_back(start);
int count = 0;
do {
auto now = queue.top();
queue.pop();
if (max_depth <= now->depth) {
// best.push_back(now);
count++;
if (count >= limit) {
break;
}
continue;
}
iter::for_all(now->vacc.out(), [&](auto edge) {
VertexAccessor va = edge.to();
if (vertex_filter_contained(t, va, now)) {
auto cost = 1 - va.at(tkey).get()->value();
Node *n = stack.make<Node>(va, now->cost + cost, now, tkey);
queue.push(n);
all_nodes.push_back(n);
}
});
} while (!queue.empty());
stream.write_field("n");
stream.write_record();
stream.write_list_header(0);
stream.chunk();
stream.write_meta("r");
// for (auto n : all_nodes) {
// delete n;
// }
stack.free();
}
class CodeCPU : public ICodeCPU<STREAM>
{
public:
bool run(Db &db, code_args_t &args, STREAM &stream) override
{
DbAccessor t(db);
astar(t, args, stream);
return t.commit();
}
~CodeCPU() {}
};
}
extern "C" ICodeCPU<barrier::STREAM> *produce()
{
// BARRIER!
return new barrier::CodeCPU();
}
extern "C" void destruct(ICodeCPU<barrier::STREAM> *p) { delete p; }