Skip to content

Commit

Permalink
added basic ability to read graphml files
Browse files Browse the repository at this point in the history
  • Loading branch information
djryn committed Apr 5, 2022
1 parent 3f942a1 commit 7d4fb83
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 31 deletions.
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS_RELEASE -O3)

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

set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
Expand Down
11 changes: 11 additions & 0 deletions data/test_data_2.graphml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<graph id="G" edgedefault="undirected">
<node id="n0"/>
<node id="n1"/>
<edge source="n0" target="n1"/>
</graph>
</graphml>
93 changes: 62 additions & 31 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
//
// Created by Zachary on 3/25/2022.
//

//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/dijkstra_shortest_paths.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>;

int main(int argc, char** argv) {
// cout << "Hello CS3353, your arguments were: ";
Expand All @@ -22,38 +34,57 @@ 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;
}


// create a typedef for the Graph type
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS> Graph;

// Make convenient labels for the vertices
// defaults A=0, B=1, etc. so A-E are vertices and N is the number of vertices
enum { A, B, C, D, E, N };
const int num_vertices = N;
const char* name = "ABCDE";

// writing out the edges in the graph
typedef std::pair<int, int> Edge;
Edge edge_array[] =
{ Edge(A,B), Edge(A,D), Edge(C,A), Edge(D,C),
Edge(C,E), Edge(B,D), Edge(D,E) };
const int num_edges = sizeof(edge_array)/sizeof(edge_array[0]);

// declare a graph object
Graph g(num_vertices);

// 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;
// typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> Graph;
//
// // Make convenient labels for the vertices
// // defaults A=0, B=1, etc. so A-F are vertices and N is the number of vertices
// enum { A, B, C, D, E, F, N };
// const int num_vertices = N;
// const char* name = "ABCDEF";
//
// // writing out the edges in the graph
// typedef std::pair<int, int> Edge;
// Edge edge_array[] =
// { Edge(A,B), Edge(A,C), Edge(B,C), Edge(D,C),
// Edge(D,E), Edge(F,D), Edge(F,E) };
// const int num_edges = sizeof(edge_array)/sizeof(edge_array[0]);
//
// // declare a graph object
// Graph g(num_vertices);
//
// // 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;
}

0 comments on commit 7d4fb83

Please sign in to comment.