Comments (5)
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.
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.
Thanks Jeremy. Any particular algorithms you care about, so we can make sure they work?
from graph.
Good question. Yes, I'm using tsort
.
from graph.
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)
- Racket 5 tests don't work HOT 3
- stop supporting Racket versions < 6 HOT 1
- Tests fail on Racket 7 HOT 1
- Please add the racket topic to this repo HOT 1
- Allow setting of graphviz attributes other than color HOT 1
- Implement multigraphs HOT 1
- Serialization HOT 3
- Bug in maximum bipartite matching? HOT 12
- document gen:queue and queue-lib
- edge-weight should allow default value
- invalid version number
- Functional interface? HOT 3
- graphviz: support arbitrary edge values HOT 3
- `undirected-graph` raises `apply` error HOT 4
- Typed Racket interface HOT 7
- racket 8 breaks tests
- Is it possible to use Graph Properties to generate better `.dot` files? HOT 7
- Add `directed-graph?` and `undirected-graph?` HOT 8
- Inbound and outbound neighbors for directed graphs
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 graph.