small changes in POC's main functions

This commit is contained in:
Marko Budiselic 2016-09-25 19:01:46 +01:00
parent a0438392df
commit 34c8adbcb9
4 changed files with 37 additions and 31 deletions

View File

@ -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 ----------------------

View File

@ -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)

View File

@ -159,11 +159,11 @@ auto a_star(
EdgeAccessor &edge, VertexAccessor &vertex),
int limit)
{
// get transaction
DbAccessor t(db);
type_key_t<TypeGroupVertex, Double> tkey =
t.vertex_property_family_get("score")
.get(Flags::Double)
.type_key<Double>();
type_key_t<TypeGroupVertex, Double> type_key =
t.vertex_property_family_get("score").get(Flags::Double).type_key<Double>();
auto best_found = new std::map<Id, Score>[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<TypeGroupVertex>(
Double((std::rand() % max_score) / (max_score + 0.0)),

View File

@ -19,6 +19,9 @@
using namespace std;
using company_profile_type =
pair<barrier::VertexAccessor, unordered_map<string, double>>;
// 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<pair<barrier::VertexAccessor, unordered_map<string, double>>>
coll;
vector<company_profile_type> 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<Int64>("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<Int64>("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();
}