123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215(**************************************************************************)(* *)(* Ocamlgraph: a generic graph library for OCaml *)(* Copyright (C) 2004-2010 *)(* Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles *)(* *)(* This software is free software; you can redistribute it and/or *)(* modify it under the terms of the GNU Library General Public *)(* License version 2.1, with the special exception on linking *)(* described in file LICENSE. *)(* *)(* This software is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *)(* *)(**************************************************************************)(* $Id: pack.ml,v 1.13 2006-05-12 14:07:16 filliatr Exp $ *)moduleGeneric(G:Sig.IMwithtypeV.label=intandtypeE.label=int)=structincludeGexceptionFoundofV.tletfind_vertexgi=tryiter_vertex(funv->ifV.labelv=ithenraise(Foundv))g;raiseNot_foundwithFoundv->vmoduleBuilder=Builder.I(G)moduleDfs=Traverse.Dfs(G)moduleBfs=Traverse.Bfs(G)moduleMarking=Traverse.Mark(G)moduleColoring=Coloring.Mark(G)moduleClassic=Classic.I(G)moduleRand=Rand.I(G)moduleComponents=Components.Make(G)moduleW=structtypeedge=G.E.ttypet=intletweighte=G.E.labeleletzero=0letadd=(+)letsub=(-)letcompare:t->t->int=Stdlib.compareendincludePath.Dijkstra(G)(W)includePath.Johnson(G)(W)moduleBF=Path.BellmanFord(G)(W)letbellman_ford=BF.find_negative_cycle_frommoduleBfs01=Path.Bfs01(G)letbfs_0_1=Bfs01.itermoduleF=structtypelabel=inttypet=intletmax_capacityx=xletmin_capacity_=0letflow_=0letadd=(+)letsub=(-)letcompare:t->t->int=Stdlib.compareletzero=0endmoduleFF=Flow.Ford_Fulkerson(G)(F)letford_fulkersong=ifnotG.is_directedtheninvalid_arg"ford_fulkerson: not a directed graph";FF.maxflowgmoduleGoldberg=Flow.Goldberg_Tarjan(G)(F)letgoldberg_tarjang=ifnotG.is_directedtheninvalid_arg"goldberg: not a directed graph";Goldberg.maxflowgincludeOper.Make(Builder)modulePathCheck=Path.Check(G)moduleTopological=structincludeTopological.Make(G)moduleS=Topological.Make_stable(G)letfold_stable=S.foldletiter_stable=S.iterendmoduleEulerian=structincludeEulerian.Make(G)endmoduleInt=structtypet=intletcompare:t->t->int=Stdlib.compareendincludeKruskal.Make(G)(Int)moduleDisplay=structincludeGletvertex_namev=string_of_int(V.labelv)letgraph_attributes_=[]letdefault_vertex_attributes_=[]letvertex_attributes_=[]letdefault_edge_attributes_=[]letedge_attributese=[`Label(string_of_int(E.labele))]letget_subgraph_=NoneendmoduleDot_=Graphviz.Dot(Display)moduleNeato=Graphviz.Neato(Display)letdot_outputgf=letoc=open_outfinifis_directedthenDot_.output_graphocgelseNeato.output_graphocg;close_outocletdisplay_with_gvg=lettmp=Filename.temp_file"graph"".dot"indot_outputgtmp;ignore(Sys.command("dot -Tps "^tmp^" | gv -"));Sys.removetmpmoduleGmlParser=Gml.Parse(Builder)(structletnodel=trymatchList.assoc"id"lwithGml.Intn->n|_->-1withNot_found->-1letedge_=0end)letparse_gml_file=GmlParser.parsemoduleDotParser=Dot.Parse(Builder)(structletnodes=Hashtbl.create97letnew_node=ref0letnode(id,_)_=tryHashtbl.findnodesidwithNot_found->incrnew_node;Hashtbl.addnodesid!new_node;!new_nodeletedge_=0end)letparse_dot_file=DotParser.parseopenFormatmoduleGmlPrinter=Gml.Print(G)(structletnoden=["label",Gml.Intn]letedgen=["label",Gml.Intn]end)letprint_gml=GmlPrinter.printletprint_gml_filegf=letc=open_outfinletfmt=formatter_of_out_channelcinfprintffmt"%a@."GmlPrinter.printg;close_outc(*
module GraphmlPrinter =
Graphml.Print
(G)
(struct
let node n = ["label", Gml.Int n]
let edge n = ["label", Gml.Int n]
module Vhash = Hashtbl.Make(G.V)
let vertex_uid = uid (Vhash.create 17) Vhash.find Vhash.add
module Ehash = Hashtbl.Make(G.E)
let edge_uid = uid (Ehash.create 17) Ehash.find Ehash.add
end)
let print_gml = GmlPrinter.print
let print_gml_file g f =
let c = open_out f in
let fmt = formatter_of_out_channel c in
fprintf fmt "%a@." GmlPrinter.print g;
close_out c
*)endmoduleI=structtypet=intletcompare:t->t->int=Stdlib.compareletdefault=0endmoduleDigraph=Generic(Imperative.Digraph.AbstractLabeled(I)(I))moduleGraph=Generic(Imperative.Graph.AbstractLabeled(I)(I))