Giter Site home page Giter Site logo

Comments (7)

badumbatish avatar badumbatish commented on May 23, 2024

Hi there, how can I contribute to this, where can I get started?

from cxxgraph.

ZigRazor avatar ZigRazor commented on May 23, 2024

@nrkramer @sbaldu can you give some help to @badumbatish ?

from cxxgraph.

sbaldu avatar sbaldu commented on May 23, 2024

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.

badumbatish avatar badumbatish commented on May 23, 2024

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.

sbaldu avatar sbaldu commented on May 23, 2024

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.

sbaldu avatar sbaldu commented on May 23, 2024
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.

badumbatish avatar badumbatish commented on May 23, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.