Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file weight.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164moduletypeWeight=sigtypewvalpp:Format.formatter->w->unitvalinit:wvalis_better:w->w->bool(** [is better w1 w2] returns [true] if [w1] is strictly better
than [w2] *)valis_equal:w->w->bool(** [is better w1 w2] returns [true] if [w1=w2] *)valup:w->'a->wvaldown:w->'a->wvalright:w->'a->wendmoduletypeWeight_sig=sigincludeWeightmoduleWMap:sigtype'atvalempty:'atvaloptimum:'at->woptionvalpp:Format.formatter->'at->unitvaladd:w->'a->'at->'atvalpop_optimum:'at->('a*w*'at)optionendendmoduleMapMake(W:sigincludeWeightvalcompare:w->w->intend)=structtypew=W.wletpp=W.ppletinit=W.initletis_better=W.is_betterletis_equal=W.is_equalletup=W.upletdown=W.downletright=W.rightmoduleLocalMap=Map.Make(structtypet=W.wletcompare=W.compareend)moduleWMap=structtype'at=(W.w*('alistLocalMap.t))optionletempty=Noneletoptimum=function|None->None|Some(w,_)->Somewletppfmt=function|None->Format.fprintffmt"None"|Some(w,map)->letpp_mapfmtm=LocalMap.iter(funkv->Format.fprintffmt"@[<hov>Bindings:@[ %a -> list of length %d@]@]@ "W.ppk(List.lengthv))minFormat.fprintffmt"@[Optimum set to: %a@ @[<v> @[%a@]@]@]"W.ppwpp_mapmapletrecremove_empty_bindingsmap=matchLocalMap.min_binding_optmapwith|None->None|Some(w',[])->remove_empty_bindings(LocalMap.removew'map)|Some(w',_)->Some(w',map)letaddweightstatemap=matchmapwith|None->Some(weight,LocalMap.addweight[state]LocalMap.empty)|Some(opt,map)whenW.is_betterweightopt->(* weight is strictly better than opt, hence no binding for
weight is present *)Some(weight,LocalMap.addweight[state]map)|Some(opt,map)whenW.is_equalweightopt->(* weight is opt *)letstates=LocalMap.findoptmapin(* Shouldn't raise a Not_found exception *)Some(opt,LocalMap.addopt(state::states)map)|Some(opt,map)->(* opt is trictly better than weight *)letstates=matchLocalMap.find_optweightmapwith|None->[state]|Someprevious_states->state::previous_statesinSome(opt,LocalMap.addweightstatesmap)letpop_optimumm=matchmwith|None->None|Some(w_opt,map)->(matchLocalMap.min_binding_optmapwith|None->failwith"Bug: optimum is set for an empty map"|Some(w',_)whenw'<>w_opt->failwith"Bug: optimum is not correctly set"|Some(_,[])->failwith"Bug: Should not occurr"|Some(w',[s])->Some(s,w',remove_empty_bindings(LocalMap.removew'map))|Some(w',s::states)->Some(s,w',Some(w',LocalMap.addw'statesmap)))endendmoduleWeight_as_Depth_init=structtypew=intletppfmtw=Format.fprintffmt"depth = %d"wletinit=1letis_betterab=a<bletis_equalab=a=bletupw_=w-1letdownw_=w+1letrightw_=w(* let left w _ = w *)letcompareab=a-bendmoduleWeight_as_Depth=MapMake(Weight_as_Depth_init)moduleWeight_as_Depth_and_Size_init=structtypew={current:int;max:int;size:int}letppfmtw=Format.fprintffmt"depth = %d, size = %d"w.maxw.sizeletinit={current=1;max=1;size=1}letis_betterww'=matchw.max-w'.maxwith|0->(matchw.size-w'.sizewith|0->w.current<w'.current|iwheni<0->true|_->false)|iwheni<0->true|_->falseletis_equalww'=w=w'letupw_={wwithcurrent=w.current-1}letdownw_=letcurrent=w.current+1in{current;size=w.size+1;max=maxcurrentw.max}letrightw_={wwithsize=w.size+1}letcompareww'=matchw.max-w'.maxwith|0->(matchw.size-w'.sizewith|0->w.current-w'.current|r->r)|r->rendmoduleWeight_as_Depth_and_Size=MapMake(Weight_as_Depth_and_Size_init)