From: Diego Olivier Fernandez Pons <dofp.ocaml@gmail.com>
To: Ly Kim Quyen <lykimq@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Compute the equivalence classes
Date: Tue, 1 Nov 2011 18:20:11 +0100 [thread overview]
Message-ID: <CAHqiZ-+T=7nep4TmUuzzYu0qMpO908TmegwaNCg7f--+4PVeGw@mail.gmail.com> (raw)
In-Reply-To: <CAHrFk+vEoS+1PoKm=PR4EBko0Ot8osuNVpk9EO4JLL-fu7mm6w@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 951 bytes --]
Ly,
The algorithm for the transitive closure is fine. It's a typical
Floyd-Warshall algorithm
// Make a random graph
let makegraph = fun n -> Array.init n (fun _ -> Array.init n (fun _ ->
Random.int(2)))
// Compute transitive closure (in place)
let transitiveClosure = fun matrix ->
let n = Array.length matrix in
for k = 0 to n - 1 do
for i = 0 to n - 1 do
for j = 0 to n - 1 do
matrix.(i).(j) <- max matrix.(i).(j) (min
matrix.(i).(k) matrix.(k).(j))
done;
done;
done
I guess that by "equivalence class" you mean strongly connected components.
There are linear algorithm (Tarjan, Gabow) that are variants of DFS (depht
first search) with bookkeeping
http://en.wikipedia.org/wiki/Strongly_connected_component
You can compute the strongly connected components directly on the
transitive closure. Notice you don't need to transpose it explicitely
[-- Attachment #2: Type: text/html, Size: 1380 bytes --]
next prev parent reply other threads:[~2011-11-01 17:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-31 15:36 Ly Kim Quyen
2011-10-31 16:13 ` Kakadu
2011-10-31 23:59 ` Toby Kelsey
2011-11-01 17:20 ` Diego Olivier Fernandez Pons [this message]
2011-11-01 17:55 ` Diego Olivier Fernandez Pons
2011-11-03 8:10 ` Ly Kim Quyen
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='CAHqiZ-+T=7nep4TmUuzzYu0qMpO908TmegwaNCg7f--+4PVeGw@mail.gmail.com' \
--to=dofp.ocaml@gmail.com \
--cc=caml-list@inria.fr \
--cc=lykimq@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