diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c80cf9..9bbb2f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,11 @@ cmake_minimum_required(VERSION 3.27) -project(Project) +project(Mining-FIs-Using-CLM VERSION 1.0 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 20) -add_executable(Project main.cpp +set(CMAKE_CXX_FLAGS_RELEASE "-Oz -DNDEBUG") +set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") + +add_executable(clm-miner main.cpp src/Graph.cpp - include/Graph.h) + include/Graph.hpp) diff --git a/main.cpp b/main.cpp index 349d0fa..2395cc3 100644 --- a/main.cpp +++ b/main.cpp @@ -1,7 +1,7 @@ #include #include -#include "include/Graph.h" +#include "include\Graph.hpp" int main(int argc, char **argv) { diff --git a/src/Graph.cpp b/src/Graph.cpp index e5643a6..425ee5f 100644 --- a/src/Graph.cpp +++ b/src/Graph.cpp @@ -1,4 +1,4 @@ -#include "../include/Graph.h" +#include "..\include\Graph.hpp" // PRIVATE FUNCTIONS @@ -36,7 +36,7 @@ int Graph::mapNodeToPosition(const char node) const noexcept int i = 0; for (auto it = nodes.cbegin(); it != nodes.cend(); ++i, ++it) { - if (node == it->first) + if (node == it->label) { return i; } @@ -45,72 +45,6 @@ int Graph::mapNodeToPosition(const char node) const noexcept return -1; } -nlohmann::json Graph::toJSONObject() const noexcept -{ - nlohmann::json json; - - json["transactions"] = transactions; - - std::vector nodesJSON; - for (const auto &[node, occurrence] : nodes) - { - nlohmann::json nodeJSON; - - nodeJSON["node"] = std::string(1, node); - nodeJSON["occurrence"] = occurrence; - - nodesJSON.push_back(nodeJSON); - } - json["nodes"] = nodesJSON; - - std::vector edgesJSON; - for (const auto &[fromNode, toNode, extraNodes, weight] : rawEdges) - { - nlohmann::json edgeJSON; - - edgeJSON["fromNode"] = std::string(1, fromNode); - edgeJSON["toNode"] = std::string(1, toNode); - - std::list extraNodesStr; - for (const auto &node : extraNodes) - { - extraNodesStr.emplace_back(1, node); - } - - edgeJSON["extraNodes"] = extraNodesStr; - edgeJSON["weight"] = weight; - - edgesJSON.push_back(edgeJSON); - } - json["edges"] = edgesJSON; - - nlohmann::json rowsCLMJSON; - std::vector headers; - auto it = nodes.cbegin(); - for (int i = 0; i < getNodesCount(); i++) - { - headers.emplace_back(1, it->first); - - for (const auto &key : nodes | std::views::keys) - { - headers.emplace_back(1, key); - } - - ++it; - } - rowsCLMJSON["header"] = headers; - - it = nodes.cbegin(); - for (const auto &row : CLM) - { - rowsCLMJSON[std::string(1, it->first)] = row; - ++it; - } - json["CLM"] = rowsCLMJSON; - - return json; -} - // PUBLIC FUNCTIONS @@ -172,7 +106,7 @@ void Graph::processTransaction(const std::string &str) } // Save the history - jsonHistory.push_back(toJSONObject()); + jsonHistory.emplace_back(*this); } void Graph::processCLM() @@ -224,10 +158,6 @@ void Graph::processCLM() } } -std::string Graph::getJSONHistoryAsJSON() const noexcept { return nlohmann::json(jsonHistory).dump(0); } - -std::string Graph::toJSON(const int indent) const noexcept { return toJSONObject().dump(0); } - std::string Graph::toString() const noexcept { std::stringstream ss; @@ -255,11 +185,11 @@ std::string Graph::toString() const noexcept auto it = nodes.cbegin(); for (int i = 0; i < getNodesCount(); ++i, ++it) { - ss << it->first << ' '; + ss << it->label << ' '; ss << "| "; - for (const auto &key : nodes | std::views::keys) + for (const auto &[label, occurrence] : nodes) { - ss << key << ' '; + ss << label << ' '; } ss << "| "; } @@ -269,7 +199,7 @@ std::string Graph::toString() const noexcept for (int i = 0; i < getNodesCount(); ++i, ++it) { - ss << "\t" << it->first << " | "; + ss << "\t" << it->label << " | "; int j = 0; for (const int &key : CLM[i])