123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188(**************************************************************************)(* *)(* 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: mcs_m.mli,v 1.2 2004-10-19 15:21:44 signoles Exp $ *)moduleMaximalCardinalitySearch=structmoduleWeightedV(V:Sig.COMPARABLE)=structincludeUtil.DataV(structtypet=intend)(V)letweight=dataletset_weight=set_dataendmoduleP(Gr:Sig.P)=structtypeedgelist=(Gr.V.t*Gr.V.t)listmoduleNewV=WeightedV(Gr.V)moduleG=Persistent.Graph.Concrete(NewV)moduleEdgeSet=Set.Make(G.E)moduleVerticesSet=Set.Make(NewV)moduleChoose=Oper.Choose(G)moduleH=Hashtbl.Make(NewV)letcheck_pathguv=leth=H.create97inletmaxw=NewV.weightuinletrecauxx:bool=ifH.memhxthenfalseelseifG.V.equalxvthentrueelseifNewV.weightx<maxw||G.V.equalxuthenbeginH.addhx();G.fold_succ(funxfound->ifnotfoundthenauxxelsefound)gxfalseendelse(H.addhx();false)inauxumoduleCopy=Gmap.Vertex(Gr)(structincludeGincludeBuilder.P(G)end)letfoldfd=letrecaux=function(true,a)->aux(fa)|(false,a)->ainauxdletmcsmg=letg'=Copy.map(NewV.create0)ginlet(_,_,ord,triang)=fold(fun((i,g',a,f)asx)->ifi=0then(false,x)elseletv=G.fold_vertex(funxmax->ifNewV.weightx>NewV.weightmaxthenxelsemax)g'(ref0,snd(Choose.choose_vertexg'))inlets=G.fold_vertex(funxs->ifG.V.equalxvthenselseifcheck_pathg'xvthenVerticesSet.addxselses)g'VerticesSet.emptyinletf'=VerticesSet.fold(funxf->NewV.set_weightx(succ(NewV.weightx));ifnot(G.mem_edgeg'xv)thenEdgeSet.add(x,v)felsef)sfinletg'=G.remove_vertexg'vinleta'=(i,NewV.labelv)::ain(true,(i-1,g',a',f')))(true,(Gr.nb_vertexg,g',[],EdgeSet.empty))in(List.revord,EdgeSet.fold(fun(x,y)e->(NewV.labelx,NewV.labely)::e)triang[])lettriangulateg=let(_,triang)=mcsmginList.fold_left(fung(x,y)->Gr.add_edgegxy)gtriangendmoduleI(Gr:Sig.I)=structtypeedgelist=(Gr.V.t*Gr.V.t)listmoduleNewV=WeightedV(Gr.V)moduleG=Imperative.Graph.Concrete(NewV)moduleEdgeSet=Set.Make(G.E)moduleVerticesSet=Set.Make(NewV)moduleChoose=Oper.Choose(G)moduleH=Hashtbl.Make(NewV)letcheck_pathguv=leth=H.create97inletmaxw=NewV.weightuinletrecauxx:bool=ifH.memhxthenfalseelseifG.V.equalxvthentrueelseifNewV.weightx<maxw||G.V.equalxuthenbeginH.addhx();G.fold_succ(funxfound->ifnotfoundthenauxxelsefound)gxfalseendelse(H.addhx();false)inauxumoduleCopy=Gmap.Vertex(Gr)(structincludeGincludeBuilder.I(G)end)letmcsmg=letf=refEdgeSet.emptyanda=ref[]andg'=Copy.map(NewV.create0)ginfori=Gr.nb_vertexgdownto1doletv=G.fold_vertex(funxmax->ifNewV.weightx>NewV.weightmaxthenxelsemax)g'(ref0,snd(Choose.choose_vertexg'))inlets=G.fold_vertex(funxs->ifG.V.equalxvthenselseifcheck_pathg'xvthenVerticesSet.addxselses)g'VerticesSet.emptyinletf'=VerticesSet.fold(funxf->NewV.set_weightx(succ(NewV.weightx));ifnot(G.mem_edgeg'xv)thenEdgeSet.add(x,v)felsef)s!finf:=f';G.remove_vertexg'v;a:=(i,NewV.labelv)::!a;done;(List.rev!a,EdgeSet.fold(fun(x,y)e->(NewV.labelx,NewV.labely)::e)!f[])lettriangulateg=let(_,triang)=mcsmginList.iter(fun(x,y)->Gr.add_edgegxy)triangendend