-
Notifications
You must be signed in to change notification settings - Fork 139
Feature matrix market format #299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
45760d9
Remove static_cast of 0 to template type T in best_first_search
61a1ff1
Merge branch 'ZigRazor:master' into master
sbaldu 2f2734c
Add import/export functions for mtx format
sbaldu 9f80b75
Add file for testing import/export in mtx format
sbaldu 407edd0
Add tests for mtx format
sbaldu ef379d7
Fix import from mtx method
sbaldu 87fd56e
Fix symmetric declaration in export mtx function
sbaldu cf5a681
Formatting
sbaldu 1eef3bb
Remove assert from import mtx
sbaldu a1fdaea
Add error message in import mtx for inconsistent edge definition
sbaldu 3abbbd5
Use algorithms instead of raw loops in export mtx and setNodeData
sbaldu 3c0474d
Small fix
sbaldu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| #include <Edge/Edge.hpp> | ||
| #include <Edge/Weighted.hpp> | ||
| #include <Node/Node.hpp> | ||
|
|
||
| #include "CXXGraph.hpp" | ||
| #include "gtest/gtest.h" | ||
|
|
||
| TEST(MTXTest, WriteToMtxDirectedWeighted) { | ||
| // Generate a simple test graph with few nodes and edges | ||
| CXXGraph::Node<int> node1("1", 1); | ||
| CXXGraph::Node<int> node2("2", 2); | ||
| CXXGraph::Node<int> node3("3", 3); | ||
| std::pair<const CXXGraph::Node<int> *, const CXXGraph::Node<int> *> pairNode( | ||
| &node1, &node2); | ||
| CXXGraph::DirectedWeightedEdge<int> edge1(1, pairNode, 5); | ||
| CXXGraph::DirectedWeightedEdge<int> edge2(2, node2, node3, 3); | ||
| CXXGraph::DirectedWeightedEdge<int> edge3(3, node3, node1, 7); | ||
| CXXGraph::T_EdgeSet<int> edgeSet; | ||
| edgeSet.insert(&edge1); | ||
| edgeSet.insert(&edge2); | ||
| edgeSet.insert(&edge3); | ||
| CXXGraph::Graph<int> graph(edgeSet); | ||
|
|
||
| // Write the graph to a DOT file | ||
| graph.writeToMTXFile(".", "example_graph_directed_weighted", ' '); | ||
| } | ||
|
|
||
| TEST(MTXTest, WriteToMtxUndirected) { | ||
| // Generate a simple test graph with few nodes and edges | ||
| CXXGraph::Node<int> node1("1", 1); | ||
| CXXGraph::Node<int> node2("2", 2); | ||
| CXXGraph::Node<int> node3("3", 3); | ||
| std::pair<const CXXGraph::Node<int> *, const CXXGraph::Node<int> *> pairNode( | ||
| &node1, &node2); | ||
| CXXGraph::UndirectedEdge<int> edge1(1, pairNode); | ||
| CXXGraph::UndirectedEdge<int> edge2(2, node2, node3); | ||
| CXXGraph::UndirectedEdge<int> edge3(3, node3, node1); | ||
| CXXGraph::T_EdgeSet<int> edgeSet; | ||
| edgeSet.insert(&edge1); | ||
| edgeSet.insert(&edge2); | ||
| edgeSet.insert(&edge3); | ||
| CXXGraph::Graph<int> graph(edgeSet); | ||
|
|
||
| // Write the graph to a DOT file | ||
| graph.writeToMTXFile(".", "example_graph_undirected", ' '); | ||
| } | ||
|
|
||
| TEST(MTXTest, WriteToMtxMixed) { | ||
| CXXGraph::Node<int> node1("1", 1); | ||
| CXXGraph::Node<int> node2("2", 2); | ||
| CXXGraph::Node<int> node3("3", 3); | ||
|
|
||
| CXXGraph::DirectedWeightedEdge<int> edge1(1, node1, node2, 1); | ||
| CXXGraph::UndirectedWeightedEdge<int> edge2(2, node2, node3, 1); | ||
| CXXGraph::DirectedEdge<int> edge3(3, node1, node3); | ||
|
|
||
| CXXGraph::T_EdgeSet<int> edgeSet; | ||
| edgeSet.insert(&edge1); | ||
| edgeSet.insert(&edge2); | ||
| edgeSet.insert(&edge3); | ||
|
|
||
| CXXGraph::Graph<int> graph(edgeSet); | ||
| graph.writeToMTXFile(".", "example_graph_mixed", ' '); | ||
| } | ||
|
|
||
| TEST(MTXTest, ReadFromMtxDirectedWeighted) { | ||
| CXXGraph::Graph<int> graph; | ||
| graph.readFromMTXFile("..", "test_mtx"); | ||
|
|
||
| // Check the number of edges and nodes | ||
| ASSERT_EQ(graph.getEdgeSet().size(), 8); | ||
| ASSERT_EQ(graph.getNodeSet().size(), 5); | ||
|
|
||
| // Check the first edge | ||
| ASSERT_EQ(graph.getEdge(0).value()->getNodePair().first->getUserId(), "1"); | ||
| ASSERT_EQ(graph.getEdge(0).value()->getNodePair().second->getUserId(), "1"); | ||
| // Check that it is directed | ||
| ASSERT_EQ(graph.getEdge(0).value()->isDirected(), false); | ||
| // Check that it's weighted and the value of the weight | ||
| ASSERT_EQ(graph.getEdge(0).value()->isWeighted(), true); | ||
| ASSERT_EQ(dynamic_cast<const CXXGraph::Weighted *>(graph.getEdge(0).value()) | ||
| ->getWeight(), | ||
| 1.); | ||
|
|
||
| // Check the last edge | ||
| ASSERT_EQ(graph.getEdge(7).value()->getNodePair().first->getUserId(), "5"); | ||
| ASSERT_EQ(graph.getEdge(7).value()->getNodePair().second->getUserId(), "5"); | ||
| // Check that it is directed | ||
| ASSERT_EQ(graph.getEdge(7).value()->isDirected(), false); | ||
| // Check that it's weighted and the value of the weight | ||
| ASSERT_EQ(graph.getEdge(7).value()->isWeighted(), true); | ||
| ASSERT_EQ(dynamic_cast<const CXXGraph::Weighted *>(graph.getEdge(7).value()) | ||
| ->getWeight(), | ||
| 12.); | ||
|
|
||
| // Check an edge in the middle | ||
| ASSERT_EQ(graph.getEdge(3).value()->getNodePair().first->getUserId(), "1"); | ||
| ASSERT_EQ(graph.getEdge(3).value()->getNodePair().second->getUserId(), "4"); | ||
| // Check that it is directed | ||
| ASSERT_EQ(graph.getEdge(3).value()->isDirected(), true); | ||
| // Check that it's weighted and the value of the weight | ||
| ASSERT_EQ(graph.getEdge(3).value()->isWeighted(), true); | ||
| ASSERT_EQ(dynamic_cast<const CXXGraph::Weighted *>(graph.getEdge(3).value()) | ||
| ->getWeight(), | ||
| 6.); | ||
| } | ||
|
|
||
| TEST(MTXTest, ReadFromMtxUndirectedWeighted) { | ||
| CXXGraph::Graph<int> graph; | ||
| graph.readFromMTXFile("..", "test_mtx_symmetric"); | ||
|
|
||
| // Check the number of edges and nodes | ||
| ASSERT_EQ(graph.getEdgeSet().size(), 8); | ||
| ASSERT_EQ(graph.getNodeSet().size(), 5); | ||
|
|
||
| // Check the first edge | ||
| ASSERT_EQ(graph.getEdge(0).value()->getNodePair().first->getUserId(), "1"); | ||
| ASSERT_EQ(graph.getEdge(0).value()->getNodePair().second->getUserId(), "1"); | ||
| // Check that it is directed | ||
| ASSERT_EQ(graph.getEdge(0).value()->isDirected(), false); | ||
| // Check that it's weighted and the value of the weight | ||
| ASSERT_EQ(graph.getEdge(0).value()->isWeighted(), true); | ||
| ASSERT_EQ(dynamic_cast<const CXXGraph::Weighted *>(graph.getEdge(0).value()) | ||
| ->getWeight(), | ||
| 1.); | ||
|
|
||
| // Check the last edge | ||
| ASSERT_EQ(graph.getEdge(7).value()->getNodePair().first->getUserId(), "5"); | ||
| ASSERT_EQ(graph.getEdge(7).value()->getNodePair().second->getUserId(), "5"); | ||
| // Check that it is directed | ||
| ASSERT_EQ(graph.getEdge(7).value()->isDirected(), false); | ||
| // Check that it's weighted and the value of the weight | ||
| ASSERT_EQ(graph.getEdge(7).value()->isWeighted(), true); | ||
| ASSERT_EQ(dynamic_cast<const CXXGraph::Weighted *>(graph.getEdge(7).value()) | ||
| ->getWeight(), | ||
| 12.); | ||
|
|
||
| // Check an edge in the middle | ||
| ASSERT_EQ(graph.getEdge(3).value()->getNodePair().first->getUserId(), "1"); | ||
| ASSERT_EQ(graph.getEdge(3).value()->getNodePair().second->getUserId(), "4"); | ||
| // Check that it is directed | ||
| ASSERT_EQ(graph.getEdge(3).value()->isDirected(), false); | ||
| // Check that it's weighted and the value of the weight | ||
| ASSERT_EQ(graph.getEdge(3).value()->isWeighted(), true); | ||
| ASSERT_EQ(dynamic_cast<const CXXGraph::Weighted *>(graph.getEdge(3).value()) | ||
| ->getWeight(), | ||
| 6.); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| %%MatrixMarket graph | ||
| 5 5 8 | ||
| 1 1 1.000e+00 | ||
| 2 2 1.050e+01 | ||
| 3 3 1.500e-02 | ||
| 1 4 6.000e+00 | ||
| 4 2 2.505e+02 | ||
| 4 4 -2.800e+02 | ||
| 4 5 3.332e+01 | ||
| 5 5 1.200e+01 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| %%MatrixMarket graph symmetric | ||
| % | ||
| % | ||
| % | ||
| 5 5 8 | ||
| 1 1 1.000e+00 | ||
| 2 2 1.050e+01 | ||
| 3 3 1.500e-02 | ||
| 1 4 6.000e+00 | ||
| 4 2 2.505e+02 | ||
| 4 4 -2.800e+02 | ||
| 4 5 3.332e+01 | ||
| 5 5 1.200e+01 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.