Comments (7)
Hi there, how can I contribute to this, where can I get started?
from cxxgraph.
@nrkramer @sbaldu can you give some help to @badumbatish ?
from cxxgraph.
If the graph is undirected then we can same some execution time by only checking the upper triangle of the adj matrix, because other triangle will be identical but inverted. In other words you could iterate over the adj matrix, and if a source node (which is the key of the map) has already been added to the nodeSet, you can just skip it.
On the other hand, if the node is directed I think that it would be more difficult. Any ideas? @nrkramer @ZigRazor
Ps. sorry for the delay
from cxxgraph.
maybe I'm missing sth but why can't we just iterate over the keys of the adj matrix, which is the shared<const Node<T>
and just put that into the newly created set?
from cxxgraph.
The keys of the map are the source nodes, and for every source node you have a vector of edge/destination node pairs. If a node is not the source of any link but just a destination, and in directed graphs this can easily happen, you will miss it.
from cxxgraph.
template <typename T>
shared<AdjacencyMatrix<T>> Graph<T>::getAdjMatrix() const {
auto adj = std::make_shared<AdjacencyMatrix<T>>();
auto addElementToAdjMatrix = [&adj](shared<const Node<T>> nodeFrom,
shared<const Node<T>> nodeTo,
shared<const Edge<T>> edge) {
std::pair<shared<const Node<T>>, shared<const Edge<T>>> elem = {nodeTo,
edge};
(*adj)[nodeFrom].push_back(std::move(elem));
};
for (const auto &edgeSetIt : edgeSet) {
if (edgeSetIt->isDirected().has_value() &&
edgeSetIt->isDirected().value()) {
shared<const DirectedEdge<T>> d_edge =
std::static_pointer_cast<const DirectedEdge<T>>(edgeSetIt);
addElementToAdjMatrix(d_edge->getNodePair().first,
d_edge->getNodePair().second, d_edge);
} else if (edgeSetIt->isDirected().has_value() &&
!edgeSetIt->isDirected().value()) {
shared<const UndirectedEdge<T>> ud_edge =
std::static_pointer_cast<const UndirectedEdge<T>>(edgeSetIt);
;
addElementToAdjMatrix(ud_edge->getNodePair().first,
ud_edge->getNodePair().second, ud_edge);
addElementToAdjMatrix(ud_edge->getNodePair().second,
ud_edge->getNodePair().first, ud_edge);
} else { // is a simple edge we cannot create adj matrix
return adj;
}
}
return adj;
}
For a directed edge you only add one element to the adjacency matrix.
from cxxgraph.
@sbaldu Hi there, i followed your directions and implemented the change on my branch. If the graph is undirected, I just add all source nodes from the adjacency matrix to the nodeSet, together with the isolatedNodeSet.
template <typename T>
const T_NodeSet<T> Graph<T>::getNodeSet() const {
T_NodeSet<T> nodeSet;
if (this->isUndirectedGraph() == true) {
for (const auto &[nodeFrom, nodeEdgeVec] : *getAdjMatrix()) {
nodeSet.insert(nodeFrom);
}
} else {
for (const auto &edgeSetIt : edgeSet) {
nodeSet.insert(edgeSetIt->getNodePair().first);
nodeSet.insert(edgeSetIt->getNodePair().second);
}
}
// Merge with the isolated nodes
nodeSet.insert(this->isolatedNodesSet.begin(), this->isolatedNodesSet.end());
return nodeSet;
}
I'm not sure where I went wrong but some test starts failing:
[ RUN ] BoruvkaTest.test_3
/home/jjsm/CLionProjects/CXXGraph/test/BoruvkaTest.cpp:152: Failure
Expected equality of these values:
res.mst.size()
Which is: 0
graph.getNodeSet().size() - 1
Which is: 18446744073709551615
[ FAILED ] BoruvkaTest.test_3 (0 ms)
[ RUN ] BoruvkaTest.test_2
/home/jjsm/CLionProjects/CXXGraph/test/BoruvkaTest.cpp:106: Failure
Expected equality of these values:
res.mst.size()
Which is: 0
graph.getNodeSet().size() - 1
Which is: 18446744073709551615
[ FAILED ] BoruvkaTest.test_2 (0 ms)
Do you have any pointers on approaching this? My fork is https://github.com/badumbatish/CXXGraph
from cxxgraph.
Related Issues (20)
- Faster edge lookup HOT 8
- Add `CXXGraph::Node` storage to `CXXGraph::Graph` to support trivial graphs and friends HOT 10
- For Node<T> move constructor, T copy constructor is called when the move constructor is not defined but the move assignment operator is defined. HOT 1
- Unable to build test "GraphTest" after PullRequest #344 HOT 3
- addEdge() method does not copy the weight HOT 4
- some test fails if test_exe ran from current directory other than build/test HOT 2
- Segmentation fault while running benchmark_exe HOT 3
- Use of cached adjacency matrix in all algorithms HOT 1
- Implement matrices used in network dynamics HOT 2
- Add generic `addNode` and `addEdge` overloads HOT 7
- Break out algorithms in Graph.hpp into Algorithms/ folder HOT 2
- Inclusion of "sink nodes" in adjacency map HOT 1
- bug on a floyd warshall test
- Introduce Bron-Kerbosch Algorithm
- Introduce Graph Coloring Algorithm
- Introduce Welsh Powell Algorithm HOT 4
- Build a Docusaurus Documentation HOT 9
- [BUG] Illegal Instruction SIGILL in addEgdes_1 HOT 2
- How to best improve results of an algorithm (get nodes and order in path) HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cxxgraph.