* @return a satisfying model or failure (null).
*/
public Model findModelFor(String logicalSentence, int numberOfFlips,
double probabilityOfRandomWalk) {
myModel = new Model();
Sentence s = (Sentence) new PEParser().parse(logicalSentence);
CNFTransformer transformer = new CNFTransformer();
CNFClauseGatherer clauseGatherer = new CNFClauseGatherer();
SymbolCollector sc = new SymbolCollector();
List<Symbol> symbols = new Converter<Symbol>().setToList(sc
.getSymbolsIn(s));
for (int i = 0; i < symbols.size(); i++) {
Symbol sym = (Symbol) symbols.get(i);
myModel = myModel.extend(sym, Util.randomBoolean());
}
List<Sentence> clauses = new Converter<Sentence>()
.setToList(clauseGatherer.getClausesFrom(transformer
.transform(s)));
for (int i = 0; i < numberOfFlips; i++) {
if (getNumberOfClausesSatisfiedIn(
new Converter<Sentence>().listToSet(clauses), myModel) == clauses
.size()) {
return myModel;
}
Sentence clause = clauses.get(random.nextInt(clauses.size()));
List<Symbol> symbolsInClause = new Converter<Symbol>().setToList(sc
.getSymbolsIn(clause));
if (random.nextDouble() >= probabilityOfRandomWalk) {
Symbol randomSymbol = symbolsInClause.get(random