Skip to content

Commit

Permalink
began BFS algorithm by reading adjacent nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
djryn committed Apr 7, 2022
1 parent 0ad3801 commit f3f23e2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 52 deletions.
8 changes: 2 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ add_executable(pa03 src/main.cpp src/Graph_helper.cpp)
configure_file(data/test_data_2.graphml data/test_data_2.graphml COPYONLY)
configure_file(data/dataset.graphml data/dataset.graphml COPYONLY)



set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
Expand All @@ -15,9 +17,3 @@ find_package(Boost 1.71.0 REQUIRED COMPONENTS graph system filesystem)
message(STATUS "Boost version: ${Boost_VERSION}")

target_link_libraries(pa03 PUBLIC Boost::graph PUBLIC Boost::system PUBLIC Boost::filesystem)

#set(1 file1)

#foreach(file IN LISTS 1)
# configure_file(${file} ${file} COPYONLY)
#endforeach()
9 changes: 3 additions & 6 deletions data/test_data_2.graphml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
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">
<key id="d0" for="node" attr.name="name" attr.type="string"/>
<key id="d1" for="node" attr.name="community" attr.type="int"/>
<key id="d0" for="node" attr.name="community" attr.type="int"/>
<graph id="G" edgedefault="undirected">
<node id="n0">
<data key="d0">A</data>
<data key="d1">1</data>
<data key="d0">1</data>
</node>
<node id="n1">
<data key="d0">B</data>
<data key="d1">1</data>
<data key="d0">1</data>
</node>
<edge source="n0" target="n1"/>
</graph>
Expand Down
32 changes: 30 additions & 2 deletions src/Graph_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ void Graph_helper::print_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;
for(auto iter = epair.first; iter != epair.second; iter++) {
graph[*iter].Name = "taco";
std::cout << "edge " << graph[*iter].Name << std::endl;

}
}

void Graph_helper::print_vertices() {
Expand All @@ -37,4 +40,29 @@ void Graph_helper::read_graphml(const char* file) {
std::cout << e.what() << std::endl;
return;
}

}

void Graph_helper::Breadth_first_search () {

// While Girvan-Neumann modularity is not satisfied
auto vpair = boost::vertices(graph);
for(auto iter = vpair.first; iter != vpair.second; iter++) {
auto out_edges = boost::out_edges(*iter, graph);
std::cout << *iter << " <--> ";
for(auto it = out_edges.first; it != out_edges.second; it++)
std::cout << boost::target(*it, graph) << " ";
std::cout << std::endl;


}
// loop through each node
// get arr of prev.
// reconstruct path and add 1 to each edge

// remove edge with highest value

// find communities


}
4 changes: 3 additions & 1 deletion src/Graph_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
#include <typeinfo>
#include <cxxabi.h>
#include <fstream>
#include <queue>

struct GraphData { int community; };
struct VertexProperty {
int community;
};
struct EdgeProperty { std::string Name; };
struct EdgeProperty { std::string Name = "m"; };

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

Expand All @@ -36,6 +37,7 @@ class Graph_helper {
void print_vertices();

void read_graphml(const char*);
void Breadth_first_search();


};
Expand Down
39 changes: 2 additions & 37 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,50 +1,15 @@
//
// 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 "Graph_helper.h"

int main(int argc, char** argv) {
// cout << "Hello CS3353, your arguments were: ";
// for (int i = 1; i < argc; i++) {
// cout << argv[i];
// if (i < argc - 1)
// cout << ", ";
// }
// cout << endl << endl;
//
// return 0;

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

// create a typedef for the Graph type
// 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);

//g.print_graph();
g.Breadth_first_search();

return 0;
}

0 comments on commit f3f23e2

Please sign in to comment.