Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file new_weight.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141moduletypeWeight_sig=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] *)valupdate:current:w->w->wvalup:w->'a->wvaldown:w->'a->wvalright:w->'a->wmoduleWMap:Map.Swithtypekey=wvaloptimum:'aWMap.t->(w*'a)optionendmoduleWeight_as_Depth=structtypew=intletppfmtw=Format.fprintffmt"depth = %d"wletinit=1letis_betterab=a<bletis_equalab=a=bletupdate~currentw=ifis_bettercurrentwthencurrentelsewletupw_=w-1letdownw_=w+1letrightw_=w(* let left w _ = w *)moduleWMap=Utils.IntMapletoptimum=WMap.min_binding_optendmoduleWeight_as_Depth_and_Size=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'letupdate~currentw=ifis_bettercurrentwthencurrentelsewletupw_={wwithcurrent=w.current-1}letdownw_=letcurrent=w.current+1in{current;size=w.size+1;max=maxcurrentw.max}letrightw_={wwithsize=w.size+1}moduleWMap=Map.Make(structtypet=wletcompareww'=matchw.max-w'.maxwith|0->(matchw.size-w'.sizewith|0->w.current-w'.current|r->r)|r->rend)letoptimum=WMap.min_binding_optendmoduleMapMake(W:Weight_sig)=structtype'at=(W.w*('alistW.WMap.t))optionletempty=Noneletppfmt=function|None->Format.fprintffmt"None"|Some(w,map)->letpp_mapfmtm=W.WMap.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=matchW.optimummapwith|None->None|Some(w',[])->remove_empty_bindings(W.WMap.removew'map)|Some(w',_)->Some(w',map)letaddweightstatemap=matchmapwith|None->Some(weight,W.WMap.addweight[state]W.WMap.empty)|Some(opt,map)whenW.is_betterweightopt->(* weight is strictly better than opt, hence no binding for
weight is present *)Some(weight,W.WMap.addweight[state]map)|Some(opt,map)whenW.is_equalweightopt->(* weight is opt *)letstates=W.WMap.findoptmapin(* Shouldn't raise a Not_found exception *)Some(opt,W.WMap.addopt(state::states)map)|Some(opt,map)->(* opt is trictly better than weight *)letstates=matchW.WMap.find_optweightmapwith|None->[state]|Someprevious_states->state::previous_statesinSome(opt,W.WMap.addweightstatesmap)letpop_optimumm=matchmwith|None->None|Some(w_opt,map)->(matchW.optimummapwith|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(W.WMap.removew'map))|Some(w',s::states)->Some(s,w',Some(w',W.WMap.addw'statesmap)))end