00001
00002
00003
00004
00005
00006
00007 package edu.tum.cs.srl.mln.inference;
00008
00009 import java.util.ArrayList;
00010
00011 import edu.tum.cs.logic.GroundAtom;
00012 import edu.tum.cs.logic.PossibleWorld;
00013 import edu.tum.cs.logic.sat.weighted.WeightedClausalKB;
00014 import edu.tum.cs.srl.mln.MarkovRandomField;
00015
00016 public class MaxWalkSAT extends MAPInferenceAlgorithm {
00017
00018 protected edu.tum.cs.logic.sat.weighted.MaxWalkSAT sat;
00019
00020 public MaxWalkSAT(MarkovRandomField mrf) throws Exception {
00021 this(mrf, edu.tum.cs.logic.sat.weighted.MaxWalkSAT.class);
00022 }
00023
00024 public MaxWalkSAT(MarkovRandomField mrf, Class<? extends edu.tum.cs.logic.sat.weighted.MaxWalkSAT> mwsClass) throws Exception {
00025 super(mrf);
00026 WeightedClausalKB wckb = new WeightedClausalKB(mrf, false);
00027 PossibleWorld state = new PossibleWorld(mrf.getWorldVariables());
00028 sat = mwsClass.getConstructor(WeightedClausalKB.class, PossibleWorld.class, edu.tum.cs.logic.WorldVariables.class, edu.tum.cs.srl.Database.class).newInstance(wckb, state, mrf.getWorldVariables(), mrf.getDb());
00029
00030 }
00031
00032 @Override
00033 public double getResult(GroundAtom ga) {
00034 return sat.getBestState().get(ga.index) ? 1.0 : 0.0;
00035 }
00036
00037 @Override
00038 public ArrayList<InferenceResult> infer(Iterable<String> queries, int maxSteps) throws Exception {
00039 sat.setMaxSteps(maxSteps);
00040 sat.run();
00041 return getResults(queries);
00042 }
00043
00044 public PossibleWorld getSolution() {
00045 return sat.getBestState();
00046 }
00047
00052 public void setP(double p) {
00053 sat.setP(p);
00054 }
00055
00056 @Override
00057 public String getAlgorithmName() {
00058 return String.format("MAP/%s[p=%f]", sat.getClass().getSimpleName(), sat.getP());
00059 }
00060
00061 }