[racket] Detecting cycle in directed graph

From: Stephen Chang (stchang at ccs.neu.edu)
Date: Fri Feb 14 11:41:44 EST 2014

You may be interested in my graph package:
http://stchang.github.io/graph/graph.html

To install: raco pkg install graph

Example:

#lang racket
(require graph)

(define G (unweighted-graph/directed '((a b) (b c) (c d))))
(dag? G)
(add-directed-edge! G 'd 'a)
(dag? G)

=>

#t
#f

On Fri, Feb 14, 2014 at 7:42 AM, Erich Rast <erich at snafu.de> wrote:
> I have a directed graph given as list of pairs ((from-node .
> to-node) ...) and need to detect whether adding a pair would create a
> cycle.
>
> Is there an easy way to do this already, e.g. some Planet package or
> snippet someone would like to share?
>
> I don't want to reinvent the wheel and this is not a homework question.
>
> Best,
>
> Erich
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.