Skip to content

Commit

Permalink
moved all graph stuff to a class and began fine tuning reading function
Browse files Browse the repository at this point in the history
  • Loading branch information
djryn committed Apr 6, 2022
1 parent 7d4fb83 commit e8eac8d
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 49 deletions.
5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project(22s_pa03)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS_RELEASE -O3)

add_executable(pa03 src/main.cpp)
add_executable(pa03 src/main.cpp src/Graph_helper.cpp)
configure_file(data/test_data_2.graphml data/test_data_2.graphml COPYONLY)

set(Boost_USE_STATIC_LIBS OFF)
Expand Down
14 changes: 11 additions & 3 deletions data/test_data_2.graphml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<key id="d0" for="node" attr.name="name" attr.type="string"/>
<key id="d1" for="node" attr.name="community" attr.type="int"/>
<graph id="G" edgedefault="undirected">
<node id="n0"/>
<node id="n1"/>
<node id="n0">
<data key="d0">A</data>
<data key="d1">1</data>
</node>
<node id="n1">
<data key="d0">B</data>
<data key="d1">1</data>
</node>
<edge source="n0" target="n1"/>
</graph>
</graphml>
41 changes: 41 additions & 0 deletions src/Graph_helper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Created by Daniel Ryan on 4/5/22.
//

#include "Graph_helper.h"


void Graph_helper::print_graph() {
boost::print_graph(graph, get(&VertexProperty::name, graph));
}

void Graph_helper::print_edges() {
auto epair = boost::edges(graph);
for(auto iter = epair.first; iter != epair.second; iter++)
std::cout << "edge " << *iter << std::endl;
}

void Graph_helper::print_vertices() {
auto vpair = boost::vertices(graph);
for(auto iter = vpair.first; iter != vpair.second; iter++)
std::cout << "vertex " << *iter << std::endl;
}

void Graph_helper::read_graphml(const char* file) {
std::ifstream is;
is.open(file);
if(!is.is_open()) {
std::cout << "[ERROR]: could not open Graphml file" << std::endl;
return;
}

try {
boost::dynamic_properties dp(boost::ignore_other_properties);
dp.property("name", boost::get(&VertexProperty::name, graph));
dp.property("community", boost::get(&VertexProperty::community, graph));
boost::read_graphml(is, graph, dp);
}catch(std::exception& e) {
std::cout << e.what() << std::endl;
return;
}
}
44 changes: 44 additions & 0 deletions src/Graph_helper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Created by Daniel Ryan on 4/5/22.
//

#ifndef INC_22S_PA03_GRAPH_HELPER_H
#define INC_22S_PA03_GRAPH_HELPER_H

#include <iostream>
#include <utility>
#include <algorithm>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/graph/graphml.hpp>
#include <boost/property_map/dynamic_property_map.hpp>
#include <boost/property_map/property_map.hpp>
#include <typeinfo>
#include <cxxabi.h>
#include <fstream>

struct GraphData { int community; };
struct VertexProperty {
std::string name;
int community;
};
struct EdgeProperty { std::string Name; };

using Graph = boost::adjacency_list<boost::setS, boost::vecS, boost::undirectedS, VertexProperty, EdgeProperty>;

class Graph_helper {
private:
Graph graph;

public:
void print_graph();
void print_edges();
void print_vertices();

void read_graphml(const char*);


};

#endif //INC_22S_PA03_GRAPH_HELPER_H
49 changes: 4 additions & 45 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,7 @@
//TODO: make bundled vertix and edge structures
//TODO: make undirected graph with bundles and add edges and vertices
//TODO: Find away to move through graph and perform Breadth First Search, shortest path algo
#include <iostream>
#include <utility>
#include <algorithm>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/graph/graphml.hpp>
#include <boost/property_map/dynamic_property_map.hpp>
#include <boost/property_map/property_map.hpp>
#include <typeinfo>
#include <cxxabi.h>
#include <fstream>


struct GraphData { std::string Name; };
struct VertexProperty { std::string Name; };
struct EdgeProperty { std::string Name; };

using Graph = boost::adjacency_list<boost::setS, boost::vecS, boost::undirectedS>;
#include "Graph_helper.h"

int main(int argc, char** argv) {
// cout << "Hello CS3353, your arguments were: ";
Expand All @@ -34,21 +16,10 @@ int main(int argc, char** argv) {
// cout << endl << endl;
//
// return 0;
std::ifstream is;
is.open("data/test_data_2.graphml");
if(!is.is_open())
std::cout << "hi" << std::endl;
try {
Graph graph;
boost::dynamic_properties dp;

boost::read_graphml(is, graph, dp);
boost::print_graph(graph);
}catch(std::exception& e) {
std::cout << e.what() << std::endl;
return 1;
}

Graph_helper g;
g.read_graphml("data/test_data_2.graphml");
g.print_graph();

// create a typedef for the Graph type
// typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> Graph;
Expand All @@ -72,18 +43,6 @@ int main(int argc, char** argv) {
// // add the edges to the graph object
// for (int i = 0; i < num_edges; ++i)
// boost::add_edge(edge_array[i].first, edge_array[i].second, g);
//
// auto vpair = boost::vertices(g);
// for(auto iter = vpair.first; iter != vpair.second; iter++)
// std::cout << "vertex " << *iter << std::endl;
//
// auto epair = boost::edges(g);
// for(auto iter = epair.first; iter != epair.second; iter++)
// std::cout << "edge " << *iter << std::endl;



// Breadth First Search


return 0;
Expand Down

0 comments on commit e8eac8d

Please sign in to comment.