(* ========================================================================= *) (* THE WAITING SET OF CLAUSES *) (* Copyright (c) 2002 Joe Leslie-Hurd, distributed under the BSD License *) (* ========================================================================= *)
structure Waiting :> Waiting = struct
open Useful;
(* ------------------------------------------------------------------------- *) (* A type of waiting sets of clauses. *) (* ------------------------------------------------------------------------- *)
type weight = real;
type modelParameters =
{model : Model.parameters,
initialPerturbations : int,
maxChecks : int option,
perturbations : int,
weight : weight}
fun mkModelClause cl = let val lits = Clause.literals cl val fvs = LiteralSet.freeVars lits in
(fvs,lits) end;
val mkModelClauses = List.map mkModelClause;
fun perturbModel M cls = ifList.null cls then K () else let val N = {size = Model.size M}
fun perturbClause (fv,cl) = let val V = Model.randomValuation N fv in if Model.interpretClause M V cl then () else Model.perturbClause M V cl end
fun perturbClauses () = app perturbClause cls in
fn n => funpow n perturbClauses () end;
fun initialModel axioms conjecture parm = let val {model,initialPerturbations,...} : modelParameters = parm val m = Model.new model val () = perturbModel m conjecture initialPerturbations val () = perturbModel m axioms initialPerturbations in
m end;
fun checkModels parms models (fv,cl) = let fun check ((parm,model),z) = let val {maxChecks,weight,...} : modelParameters = parm val n = {maxChecks = maxChecks} val {T,F} = Model.check Model.interpretClause n model fv cl in
Math.pow (1.0 + Real.fromInt T / Real.fromInt (T + F), weight) * z end in List.foldl check 1.0 (zip parms models) end;
fun perturbModels parms models cls = let fun perturb (parm,model) = let val {perturbations,...} : modelParameters = parm in
perturbModel model cls perturbations end in app perturb (zip parms models) end;
fun add' waiting dist mcls cls = let val Waiting {parameters,clauses,models} = waiting val {models = modelParameters, ...} = parameters
(*MetisDebug val _ = not (List.null cls) orelse raise Bug "Waiting.add': null"
val _ = length mcls = length cls orelse raise Bug "Waiting.add': different lengths"
*)
val dist = dist + Math.ln (Real.fromInt (length cls))
fun addCl ((mcl,cl),acc) = let val weight = clauseWeight parameters models dist mcl cl in
Heap.add acc (weight,(dist,cl)) end
val clauses = List.foldl addCl clauses (zip mcls cls)
val () = perturbModels modelParameters models mcls in
Waiting {parameters = parameters, clauses = clauses, models = models} end;
fun add waiting (dist,cls) = ifList.null cls then waiting else let (*MetisTrace3 val () = Print.trace pp "Waiting.add: waiting" waiting val () = Print.trace (Print.ppList Clause.pp) "Waiting.add: cls" cls
*)
val waiting = add' waiting dist (mkModelClauses cls) cls
(*MetisTrace3 val () = Print.trace pp "Waiting.add: waiting" waiting
*) in
waiting end;
local fun cmp ((w1,_),(w2,_)) = Real.compare (w1,w2);
fun empty parameters axioms conjecture = let val {models = modelParameters, ...} = parameters val clauses = Heap.new cmp and models = List.map (initialModel axioms conjecture) modelParameters in
Waiting {parameters = parameters, clauses = clauses, models = models} end; in fun new parameters {axioms,conjecture} = let val mAxioms = mkModelClauses axioms and mConjecture = mkModelClauses conjecture
val waiting = empty parameters mAxioms mConjecture in ifList.null axioms andalso List.null conjecture then waiting else add' waiting 0.0 (mAxioms @ mConjecture) (axioms @ conjecture) end (*MetisDebug handle e => let val () = Print.trace Print.ppException "Waiting.new: exception" e in raise e end;
*) end;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.