From 34c8adbcb90d43863c67cefe5b43f9a21e2fb1f1 Mon Sep 17 00:00:00 2001 From: Marko Budiselic Date: Sun, 25 Sep 2016 19:01:46 +0100 Subject: [PATCH] small changes in POC's main functions --- CMakeLists.txt | 3 +-- poc/CMakeLists.txt | 2 -- poc/astar.cpp | 16 ++++++++-------- poc/profile.cpp | 47 +++++++++++++++++++++++++++------------------- 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bf95ac01..11a4c99fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -305,8 +305,7 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") endif() # release flags -set(CMAKE_CXX_FLAGS_RELEASE - "${CMAKE_CXX_FLAGS_RELEASE} -Wall") +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") # TODO: find a way how to applay the defines at the query compile time # -- configure defines -- default is ON | true | enabled ---------------------- diff --git a/poc/CMakeLists.txt b/poc/CMakeLists.txt index 10ea30e24..fe6b87353 100644 --- a/poc/CMakeLists.txt +++ b/poc/CMakeLists.txt @@ -2,11 +2,9 @@ cmake_minimum_required(VERSION 3.1) project(memgraph_poc) - include_directories(${CMAKE_SOURCE_DIR}/poc) include_directories(${CMAKE_SOURCE_DIR}/queries) - add_executable(poc_astar astar.cpp) target_link_libraries(poc_astar memgraph) target_link_libraries(poc_astar Threads::Threads) diff --git a/poc/astar.cpp b/poc/astar.cpp index a3cb365b5..cdcf1576a 100644 --- a/poc/astar.cpp +++ b/poc/astar.cpp @@ -159,11 +159,11 @@ auto a_star( EdgeAccessor &edge, VertexAccessor &vertex), int limit) { + // get transaction DbAccessor t(db); - type_key_t tkey = - t.vertex_property_family_get("score") - .get(Flags::Double) - .type_key(); + + type_key_t type_key = + t.vertex_property_family_get("score").get(Flags::Double).type_key(); auto best_found = new std::map[max_depth]; @@ -174,7 +174,7 @@ auto a_star( auto start_vr = t.vertex_find(sys_id_start); assert(start_vr); start_vr.get().fill(); - Node *start = new Node(start_vr.take(), 0, tkey); + Node *start = new Node(start_vr.take(), 0, type_key); queue.push(start); int count = 0; do { @@ -205,8 +205,8 @@ auto a_star( if (e_filter[now->depth](t, edge, now)) { VertexAccessor va = edge.to(); if (v_filter[now->depth](t, va, now)) { - auto cost = calc_heuristic_cost(tkey, edge, va); - Node *n = new Node(va, now->cost + cost, now, tkey); + auto cost = calc_heuristic_cost(type_key, edge, va); + Node *n = new Node(va, now->cost + cost, now, type_key); queue.push(n); } } @@ -293,7 +293,7 @@ void add_scores(Db &db) int i = 1; iter::for_all(t.vertex_access(), [&](auto v) { if (v.fill()) { - // from Kruno's head :) (could be ALMOST anything else) + // any random number is OK std::srand(i ^ 0x7482616); v.set(StoredProperty( Double((std::rand() % max_score) / (max_score + 0.0)), diff --git a/poc/profile.cpp b/poc/profile.cpp index 0d611918f..b74c9674c 100644 --- a/poc/profile.cpp +++ b/poc/profile.cpp @@ -19,6 +19,9 @@ using namespace std; +using company_profile_type = + pair>; + // Accepts flags for csv import. // -db name # will create database with that name. // -s true # will create snapshot of the database after import. @@ -35,12 +38,11 @@ int main(int argc, char **argv) { DbAccessor t(db); - vector>> - coll; + vector company_profiles; // QUERY BENCHMARK auto begin = clock(); - int n = for_all_companys(barrier::trans(t), coll); + int n = for_all_companys(barrier::trans(t), company_profiles); clock_t end = clock(); double elapsed_s = (double(end - begin) / CLOCKS_PER_SEC); @@ -54,28 +56,35 @@ int main(int argc, char **argv) << endl; cout << "Throughput: " << 1 / (elapsed_s / n) << " [query/sec]" << endl; - auto res = coll.back(); + // remove ones who don't have profile results + auto res = company_profiles.back(); while (res.second.empty()) { - coll.pop_back(); - res = coll.back(); + company_profiles.pop_back(); + res = company_profiles.back(); } - auto prop_vertex_id = t.vertex_property_key("company_id"); - cout << endl - << "Example: " - << *barrier::trans(res.first).at(prop_vertex_id).get() << endl; - for (auto e : res.second) { - cout << e.first << " = " << e.second << endl; - } - - double sum = 0; - for (auto r : coll) { - for (auto e : r.second) { - sum += e.second; + // print specific company + int company_id = std::stoi(get_argument(para, "-company_id", "230216")); + for (auto &company_profile : company_profiles) { + auto prop_vertex_id = t.vertex_property_key("company_id"); + auto db_company_id = *barrier::trans(company_profile.first) + .at(prop_vertex_id).get(); + if (db_company_id == company_id) { + cout << endl << "CompanyID: " << company_id << endl; + for (auto e : company_profile.second) { + cout << e.first << " = " << e.second << endl; + } } } - cout << endl << endl << "Compiler sum " << sum << endl; + // double sum = 0; + // for (auto r : coll) { + // for (auto e : r.second) { + // sum += e.second; + // } + // } + // cout << endl << endl << "Compiler sum " << sum << endl; + t.commit(); }