Giter Club home page Giter Club logo

Comments (5)

stchang avatar stchang commented on July 21, 2024 1

Thanks for the request! Sorry for the slow response but I do want to add this. I have a student who may be interested in working on it, so we might have something soon. I think it should be straightforward to add, with a decent multiset implementation in Racket.

from graph.

jsiek avatar jsiek commented on July 21, 2024

Great!

BTW, here's the code that I cobbled together for the time being:

#lang racket
(require graph)
(provide (all-defined-out))

(define (remove-all v lst)
  (cond [(null? lst) lst]
        [(equal? v (car lst)) (remove-all v (cdr lst))]
        [else (cons (car lst) (remove-all v (cdr lst)))]))

(struct multigraph (adj)
  #:methods gen:graph
  [(define (add-directed-edge! g u v [weight #f])
     (define adj (multigraph-adj g))
     (hash-update! adj u (lambda (vs) (cons v vs)) (list)))

   (define (remove-directed-edge! g u v)
     (define adj (multigraph-adj g))
     (hash-update! adj u (lambda (vs) (remove v vs)) (list)))
   
   (define (add-vertex! g u)
     (define adj (multigraph-adj g))
     (hash-update! adj u (lambda (vs) vs) (list)))
   
   (define (remove-vertex! g u)
     (define adj (multigraph-adj g))
     (hash-remove! adj u)
     (for ([(v vs) (in-hash adj)]) 
       (hash-set! adj v (remove-all u vs))))
   
   (define (in-vertices g)
     (in-hash-keys (multigraph-adj g)))

   (define (get-vertices g)
     (hash-keys (multigraph-adj g)))
   
   (define (in-neighbors g u)
     (hash-ref (multigraph-adj g) u))
   
   (define (get-neighbors g u)
     (hash-ref (multigraph-adj g) u))

   (define (vertex=? g u v)
     (equal? u v))

   (define (transpose g)
     (define g^T (multigraph (make-hash)))
     (for ([u (in-vertices g)])
       (add-vertex! g^T u))
     (for ([u (in-vertices g)])
       (for ([v (in-neighbors g u)])
         (add-directed-edge! g^T v u)))
     g^T)
   ])

(define (make-multigraph edge-list)
  (define adj (make-hash))
  (for ([e edge-list])
    (add-directed-edge! adj (first e) (second e)))
  (multigraph adj))

from graph.

stchang avatar stchang commented on July 21, 2024

Thanks Jeremy. Any particular algorithms you care about, so we can make sure they work?

from graph.

jsiek avatar jsiek commented on July 21, 2024

Good question. Yes, I'm using tsort.

from graph.

stchang avatar stchang commented on July 21, 2024

Great, thanks. If you also have specific examples you want to share I'd be happy to test against them.

from graph.

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.