int unmarshallGraph(const std::string& file, char delimiter) { Graphs graphs; graphs.unmarshall(file, delimiter); if(Env::verbose()) { std::cout << "Graphs: " << graphs.size() << std::endl; for (Graphs::Graph_map::iterator it = graphs.begin(); it != graphs.end(); it++) { std::cout << it->first << it->second << std::endl; } } std::shared_ptr<Graph> g = graphs.find("main"); if (g == nullptr) return -9; if(Env::verbose()) { std::cout << "Name: " << g->name() << "Size: " << g->nodeCount() << std::endl; } std::shared_ptr<Node> n = g->start(); printNode(n); g = graphs.find("Hello"); if (g == nullptr) return -9; if(Env::verbose()) { std::cout << "Name: " << g->name() << "Size: " << g->nodeCount() << std::endl; } n = g->start(); printNode(n); return 0; }
void printGraphs(const Graphs &graphs, int depth=0) { for (int i = 0; i < graphs.size(); i++) { for (int j = 0; j < depth; j++) cout << " "; printSequence(graphs[i].val); printGraphs(graphs[i].edges, depth + 1); } }
void addToGraphs(Graphs &graphs, OrderedSeq orderedSeq) { bool added = false; for (int i = 0; i < graphs.size(); i++) { if (nestsIn(graphs[i].val, orderedSeq)) { addToGraphs(graphs[i].edges, orderedSeq); added = true; } } if (!added) graphs.push_back(Node(orderedSeq)); }
// this is totally f****d vector<int> getLongestPath(const Graphs &graphs, vector<int> path=vector<int>()) { vector<int> longest(path); // lol so terrible int len = 0; for (int i = 0; i < graphs.size(); i++) { vector<int> dup(path); dup.push_back(graphs[i].val.second); vector<int> ret = getLongestPath(graphs[i].edges, dup); if (ret.size() > len) { longest = ret; len = ret.size(); } } return longest; }