caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe Filliatre <Jean-Christophe.Filliatre@lri.fr>
To: "Orlin Grigorov" <ogrigorov@gmail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Data structure for a directed bipartite graph
Date: Wed, 10 Oct 2007 21:36:42 +0200	[thread overview]
Message-ID: <18189.10698.543413.96648@serveur9-10.lri.fr> (raw)
In-Reply-To: <b17e12b30710100952t7669e0e9pcdf73d9b4b4bbee6@mail.gmail.com>


Hi,

Orlin Grigorov writes:
 > A bipartite graph is a graph [...]
 > So, I was thinking about a data structure in OCaml, in which I want to store
 > such graph, and also to allow me easy access to elements, as well as adding
 > new nodes and edges (therefore, the structure would be imperative, that is,
 > will have a state). So, how about this:

As already mentionned by somebody else, there exists at least one
graph library for ocaml at http://ocamlgraph.lri.fr/

It provides several data structures for graph, including matrix
representations as the one you are mentioning, but also others more
suitable for sparse graphs.

Note that the ability to add new nodes and new edges does not enforce
the use of an imperative data structure. A persistent one is equally
fine; you simply get a new graph when you add a node or an edge, the
previous one being unchanged (with a logarithmic time and space
overhead, typically). 

Ocamlgraph makes heavy use of ocaml module system to provide great
genericity and thus may appear as somewhat heavy for a newcomer. You
should start by having a look at module Pack, which provides an easy
access to the library (imperative data structure with nodes and edges
labeled with integers; see http://ocamlgraph.lri.fr/doc/Pack.html

Regarding the ability to attach information to nodes (or edges) you
may indeed use an additional data structure for that purpose (a hash
table, typically) but you may also use ocamlgraph to define your own
graph data structure with any kind of information associated to nodes
and edges. That is precisely why ocamlgraph was designed in a highly
generic way. See ocamlgraph's FAQ for an example of such instantiation.

Note that Ocamlgraph's documentation includes an article "Designing a
Generic Graph Library using ML Functors" which can be seen as an
introduction to ocamlgraph's design.

Hope this helps,
-- 
Jean-Christophe


      parent reply	other threads:[~2007-10-10 19:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-10 16:52 Orlin Grigorov
2007-10-10 18:34 ` [Caml-list] " Vincent Aravantinos
2007-10-10 19:36 ` Jean-Christophe Filliatre [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=18189.10698.543413.96648@serveur9-10.lri.fr \
    --to=jean-christophe.filliatre@lri.fr \
    --cc=caml-list@yquem.inria.fr \
    --cc=ogrigorov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).