From 9ed523bf73493fdacb76fffaaf78e42a89f7b12e Mon Sep 17 00:00:00 2001 From: Ruben Lapauw Date: Tue, 17 Apr 2018 12:19:10 +0200 Subject: [PATCH] Abstract printing a parity game over the out_channel --- src/paritygame/paritygame.ml | 29 ++++++++++++++++------------- src/paritygame/paritygame.mli | 1 + 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/paritygame/paritygame.ml b/src/paritygame/paritygame.ml index 790506f..85c6fd0 100644 --- a/src/paritygame/paritygame.ml +++ b/src/paritygame/paritygame.ml @@ -359,29 +359,32 @@ let game_to_string game = end done; "parity " ^ string_of_int (n-1) ^ ";\n" ^ !s;; - -let print_game game = + +let output_int c_out i = output_string c_out (string_of_int i);; +let output_newline c_out = output_char c_out '\n'; flush c_out;; +let output_game c_out game = let n = pg_size game in - print_string ("parity " ^ string_of_int n ^ ";\n"); + output_string c_out ("parity " ^ string_of_int (n-1) ^ ";\n"); for i = 0 to n - 1 do let (pr, pl, succs, _, desc) = pg_get_node game i in if pr >= 0 && pl >= 0 && pl <= 1 then ( - print_int i; - print_char ' '; - print_int pr; - print_char ' '; - print_int pl; - print_char ' '; - print_string (String.concat "," (List.map string_of_int (ns_nodes succs))); + output_int c_out i; + output_char c_out ' '; + output_int c_out pr; + output_char c_out ' '; + output_int c_out pl; + output_char c_out ' '; + output_string c_out (String.concat "," (List.map string_of_int (ns_nodes succs))); ( match desc with None -> () (* print_string (" \"" ^ string_of_int i ^ "\"") *) - | Some s -> if s <> "" then print_string (" \"" ^ s ^ "\"") + | Some s -> if s <> "" then output_string c_out (" \"" ^ s ^ "\"") ); - print_char ';'; - print_newline () + output_char c_out ';'; + output_newline c_out ) done;; +let print_game = output_game stdout;; let print_solution_strategy_parsable sol strat = let n = Array.length sol in diff --git a/src/paritygame/paritygame.mli b/src/paritygame/paritygame.mli index 1e542e9..e09cffc 100644 --- a/src/paritygame/paritygame.mli +++ b/src/paritygame/paritygame.mli @@ -209,6 +209,7 @@ val game_to_string : paritygame -> string (* `print_game ' prints on STDOUT s.t. it could be parsed again. *) val print_game : paritygame -> unit +val output_game : out_channel -> paritygame -> unit val print_solution_strategy_parsable : solution -> strategy -> unit