GithubHelp home page GithubHelp logo

Comments (3)

sbromberger avatar sbromberger commented on June 6, 2024

This is expected (if not explicitly intended) for undirected graphs, as the adjacency matrix of an undirected graph yields 2 for self-loops:

g = Graph(3)
add_edge!(g, 1, 1)
Matrix(adjacency_matrix(g))

gives

2 0 0
0 0 0
0 0 0

from simpleweightedgraphs.jl.

pwl avatar pwl commented on June 6, 2024

Sorry, I'm at loss as to how the adjacency matrix comes in here, I'm new to the graph terminology. How is the adjacency matrix related to the weights in this context?

Am I on the right track to think that SimpleWeightedGraph(srcs, dsts, weights) is conceptually equivalent to creating a directed graph first and then converting it to an undirected one by summing all the edges, where self edges are counted twice because their adjacency matrix entry is 2?

And a related question, what would be the recommended way to construct a weighted graph that I expected to get in the first place? That is SimpleWeightedGraph(srcs, dsts, weights) without doubling the self-edges? Currently I directly construct the sparse matrix and build a weighted graph with it.

from simpleweightedgraphs.jl.

sbromberger avatar sbromberger commented on June 6, 2024

SimpleWeightedGraphs are stored as a sparse matrix with non-zero weights denoting adjacencies. Self-loops are a bit of an afterthought and aren't guaranteed to actually work with all algorithms. However, what you can do is simply iterate over the vertices and divide the weights by two, readding the edges.

A PR would also be welcome, if for nothing else than discussion as to the best way to proceed.

from simpleweightedgraphs.jl.

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.