Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Ly Kim Quyen <lykimq@gmail.com>
To: Diego Olivier Fernandez Pons <dofp.ocaml@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Compute the equivalence classes
Date: Thu, 3 Nov 2011 16:10:25 +0800	[thread overview]
Message-ID: <CAHrFk+v5NBVuzc83MXf-KOHBzm6uTR3JLGKxsAJKEpk5WpYdpQ@mail.gmail.com> (raw)
In-Reply-To: <CAHqiZ-Jg36Tu-4zgXe9M1dUMqQQ-NJwjKt2LO0Oo-N_EFc4-+w@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2108 bytes --]

Hi Diego,

Thank you very much.

>>You will need to avoid generating multiple times the same component.

Here is the code:

let output = function matrix ->
  let n = Array.length matrix in
  let marked = Array.make n false in
  let result = ref [] in
  for i = 0 to n - 1 do
    if (not marked.(i)) then
      begin
let component = ref[i] in
for j = i + 1 to n - 1 do
*          if matrix.(i).(j) = true && matrix.(j).(i) = true then*
    begin
  marked.(j) <- true;
  component := j :: !component
 end
 done;
result := !component :: !result
      end
  done;
  !result ;;

Ly
On 2 November 2011 01:55, Diego Olivier Fernandez Pons <dofp.ocaml@gmail.com
> wrote:

> ... sorry, sent too early
>
> > You can compute the strongly connected components directly on the
> transitive closure. Notice you don't need to transpose it explicitely
>
> // Strong connected components matrix form
> let sccmatrix = function matrix ->
>   let n = Array.length matrix in
>   let result = Array.make_matrix n n 0 in
>   for i = 0 to n - 1 do
>       for j = 0 to n - 1 do
>           result.(i).(j) <- min matrix.(i).(j) matrix.(j).(i)
>       done;
>   done;
>   result
>
> Now you just have to collect the results in a list of lists.
> You will need to avoid generating multiple times the same component.
>
> // Output list of lists from matrix
> let output = function matrix ->
>     let n = Array.length matrix in
>     let marked = Array.make n false in
>     let result = ref [] in
>     for i = 0 to n - 1 do
>         if (not marked.(i)) then
>         begin
>             let component = ref [i] in
>             for j = i + 1 to n - 1 do
>                 if matrix.(i).(j) = 1 then
>                 begin
>                      marked.(j) <- true;
>                      component := j :: !component
>                 end
>             done;
>             result := !component :: !result
>          end
>      done;
>      !result
>
> Since the code uses for loops, it needs references to store the results.
>
> One can do a nicer code and merge the two functions sccmatrix and output
>
>         Diego Olivier
>

[-- Attachment #2: Type: text/html, Size: 4268 bytes --]

      reply	other threads:[~2011-11-03  8:11 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
2011-11-01 17:55   ` Diego Olivier Fernandez Pons
2011-11-03  8:10     ` Ly Kim Quyen [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=CAHrFk+v5NBVuzc83MXf-KOHBzm6uTR3JLGKxsAJKEpk5WpYdpQ@mail.gmail.com \
    --to=lykimq@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=dofp.ocaml@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