Using the graph library

338 views
Skip to first unread message

Lawrence Bottorff

unread,
Oct 29, 2016, 2:59:57 PM10/29/16
to Racket Users
I see the Racket Generic Graph Library, but I don't know how to use it. Where would one go to learn, tutorial-style" the ins and outs of using this library? I take it this library allows you to "roll your own" graph database? I did notice the HTDP has a section on graph things. Would this help?

LB

Jason Hemann

unread,
Oct 29, 2016, 3:06:18 PM10/29/16
to Lawrence Bottorff, Racket Users
Stephen's talk at 4th Racketcon (https://www.youtube.com/watch?v=SvYJF5HC19w) gave me a good tutorial-ish introduction. 

JBH

On Sat, Oct 29, 2016 at 8:59 PM, Lawrence Bottorff <bor...@gmail.com> wrote:
I see the Racket Generic Graph Library, but I don't know how to use it. Where would one go to learn, tutorial-style" the ins and outs of using this library? I take it this library allows you to "roll your own" graph database? I did notice the HTDP has a section on graph things. Would this help?

LB

--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
JBH

Lawrence Bottorff

unread,
Oct 29, 2016, 3:29:07 PM10/29/16
to Racket Users, bor...@gmail.com
On Saturday, October 29, 2016 at 3:06:18 PM UTC-4, jhemann wrote:
> Stephen's talk at 4th Racketcon (https://www.youtube.com/watch?v=SvYJF5HC19w) gave me a good tutorial-ish introduction. 
>
>
> JBH
>
>
> On Sat, Oct 29, 2016 at 8:59 PM, Lawrence Bottorff <bor...@gmail.com> wrote:
> I see the Racket Generic Graph Library, but I don't know how to use it. Where would one go to learn, tutorial-style" the ins and outs of using this library? I take it this library allows you to "roll your own" graph database? I did notice the HTDP has a section on graph things. Would this help?
>
>
>
> LB
>
>
>
> --
>
> You received this message because you are subscribed to the Google Groups "Racket Users" group.
>
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.
>
>
>
>
>
> --
>
>
> JBH

I would need something lots more basic-beginner than this talk. The Chang talk seems to assume a lot of graph knowledge. I'll pick through the Racket doc on the graph library, but it would be better for me to see something that starts at the very beginning.

Daniel Prager

unread,
Oct 29, 2016, 5:44:18 PM10/29/16
to Racket Users
Starting at the very beginning, you could pick up some material on graph theory, and work through it, while making use of the graph library.

E.g. Here's an introduction to the absolute basics of Graph Theory:


And here I've followed along in Racket, figuring out parts of the library as I go:

#lang racket

(require graph
         math/matrix)

; Define a simple graph
(define g (unweighted-graph/undirected
           '((v1 v2) (v1 v3) (v1 v4) (v4 v5) (v5 v6))))


; How many vertices are in the graph?
(define (cardinality g)
  (length (get-vertices g)))

(cardinality g)


; How many neighbors does vertex v have?
(define (degree g v)
  (length (get-neighbors g v)))

(degree g 'v1)


; Compute the adjacency list
(define (adjacency-list g)
  (for/list ([v (in-vertices g)])
    (list v
          (for/list ([ n (in-neighbors g v)])
            n))))

(adjacency-list g)


; Compute the adjacency matrix
(define (adjacency-matrix g)
  (define card-g (cardinality g))
  (define vertices (for/list ([v (in-vertices g)]) v))
  (build-matrix card-g card-g
                (λ (u v)
                  (if (has-edge? g (list-ref vertices u) (list-ref vertices v))
                      1 0))))

(adjacency-matrix g)


; Is the graph actually a tree?
(define (is-tree? g)
  (= (length (get-edges g))            ; Counts edges twice (in both directions)
     (* 2 (length (mst-kruskal g)))))

(is-tree? g)

(define loop (unweighted-graph/undirected '((a b) (a c) (b c))))
(is-tree? loop)


; Visualize the tree
(displayln (graphviz g))

; Paste output into www.webgraphviz.com to make an image


I hope that's enough to get you started

Dan

Stephen Chang

unread,
Oct 31, 2016, 10:19:10 AM10/31/16
to Lawrence Bottorff, Racket Users
Hi Lawrence,

Can you provide some more context? Are you looking to learn about
graphs in general, or specifically about the graph library API.

For the former, any well known algorithms textbook should have a
decent introduction. I used CLRS [1] as a guide when developing the
library.

For the latter, take a look at the example programs included with the
library [2]. If things are still confusing, I'm open to feedback on
which specific components could be improved.

[1]: https://mitpress.mit.edu/books/introduction-algorithms
[2]: https://github.com/stchang/graph/tree/master/graph/tests

On Sat, Oct 29, 2016 at 2:59 PM, Lawrence Bottorff <bor...@gmail.com> wrote:
> I see the Racket Generic Graph Library, but I don't know how to use it. Where would one go to learn, tutorial-style" the ins and outs of using this library? I take it this library allows you to "roll your own" graph database? I did notice the HTDP has a section on graph things. Would this help?
>
> LB
>
Reply all
Reply to author
Forward
0 new messages