sat.h

00001 /*
00002  * All of the documentation and software included in the
00003  * Alchemy Software is copyrighted by Stanley Kok, Parag
00004  * Singla, Matthew Richardson, Pedro Domingos, Marc
00005  * Sumner and Hoifung Poon.
00006  * 
00007  * Copyright [2004-07] Stanley Kok, Parag Singla, Matthew
00008  * Richardson, Pedro Domingos, Marc Sumner and Hoifung
00009  * Poon. All rights reserved.
00010  * 
00011  * Contact: Pedro Domingos, University of Washington
00012  * (pedrod@cs.washington.edu).
00013  * 
00014  * Redistribution and use in source and binary forms, with
00015  * or without modification, are permitted provided that
00016  * the following conditions are met:
00017  * 
00018  * 1. Redistributions of source code must retain the above
00019  * copyright notice, this list of conditions and the
00020  * following disclaimer.
00021  * 
00022  * 2. Redistributions in binary form must reproduce the
00023  * above copyright notice, this list of conditions and the
00024  * following disclaimer in the documentation and/or other
00025  * materials provided with the distribution.
00026  * 
00027  * 3. All advertising materials mentioning features or use
00028  * of this software must display the following
00029  * acknowledgment: "This product includes software
00030  * developed by Stanley Kok, Parag Singla, Matthew
00031  * Richardson, Pedro Domingos, Marc Sumner and Hoifung
00032  * Poon in the Department of Computer Science and
00033  * Engineering at the University of Washington".
00034  * 
00035  * 4. Your publications acknowledge the use or
00036  * contribution made by the Software to your research
00037  * using the following citation(s): 
00038  * Stanley Kok, Parag Singla, Matthew Richardson and
00039  * Pedro Domingos (2005). "The Alchemy System for
00040  * Statistical Relational AI", Technical Report,
00041  * Department of Computer Science and Engineering,
00042  * University of Washington, Seattle, WA.
00043  * http://www.cs.washington.edu/ai/alchemy.
00044  * 
00045  * 5. Neither the name of the University of Washington nor
00046  * the names of its contributors may be used to endorse or
00047  * promote products derived from this software without
00048  * specific prior written permission.
00049  * 
00050  * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF WASHINGTON
00051  * AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
00052  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00053  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00054  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY
00055  * OF WASHINGTON OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
00056  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00057  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00058  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00059  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00060  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00061  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00062  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
00063  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00064  * 
00065  */
00066 #ifndef SAT_H_
00067 #define SAT_H_
00068 
00069 #include "inference.h"
00070 
00075 class SAT : public Inference
00076 {
00077  public:
00078  
00079   SAT(VariableState* state, long int seed, const bool& trackClauseTrueCnts) : 
00080     Inference(state, seed, trackClauseTrueCnts) {}
00081     // Virtual destructor
00082   virtual ~SAT() {}
00083 
00084   const int getNumSolutions()
00085   {
00086     return numSolutions_;
00087   }
00088   
00089   void setNumSolutions(const int& numSolutions)
00090   {
00091     numSolutions_ = numSolutions;
00092   }
00093  
00094   const long double getTargetCost()
00095   {
00096     return targetCost_;
00097   }
00098   
00099   void setTargetCost(const long double& targetCost)
00100   {
00101     targetCost_ = targetCost;
00102   }
00103 
00107   void printProbabilities(ostream& out)
00108   {
00109     for (int i = 0; i < state_->getNumAtoms(); i++)
00110     {
00111       state_->printGndPred(i, out);
00112       out << " " << state_->getValueOfLowAtom(i + 1) << endl;
00113     }
00114   }
00115 
00125   void getPredsWithNonZeroProb(vector<string>& nonZeroPreds,
00126                                vector<float>& probs)
00127   {
00128     nonZeroPreds.clear();
00129     probs.clear();
00130     for (int i = 0; i < state_->getNumAtoms(); i++)
00131     {
00132       if (state_->getValueOfLowAtom(i + 1))
00133       {
00134         ostringstream oss(ostringstream::out);
00135         state_->printGndPred(i, oss);
00136         nonZeroPreds.push_back(oss.str());
00137         probs.push_back(1);
00138       }
00139     }
00140   }
00141 
00145   double getProbability(GroundPredicate* const& gndPred)
00146   {
00147     int idx = state_->getGndPredIndex(gndPred);
00148     int truthValue = 0;
00149     if (idx >= 0) truthValue = state_->getValueOfLowAtom(idx + 1);
00150     return truthValue;
00151   }
00152 
00156   void printTruePreds(ostream& out)
00157   {
00158     for (int i = 0; i < state_->getNumAtoms(); i++)
00159     {
00160       if (state_->getValueOfLowAtom(i + 1))
00161       {
00162         state_->printGndPred(i, out);
00163         out << endl;
00164       }
00165     }
00166   }
00167   
00168  protected:
00169 
00171     // Max. number of tries the SAT-solver will do before giving up
00172   int maxTries_;
00173     // Max. number of steps the SAT-solver will do in each try before giving up
00174   int maxSteps_;
00175     // Target weight SAT-solver will try to reach
00176   long double targetCost_;
00177     // Number of solutions which the SAT-solver will produce
00178   int numSolutions_;
00180 
00181   
00182     // Marks the iteration of the last time an atom was flipped
00183   Array<int> changed_;
00184     // Number of changes so far
00185   int numFlips_;
00186   
00187 };
00188  
00189 #endif /*SAT_H_*/

Generated on Wed Feb 14 15:15:18 2007 for Alchemy by  doxygen 1.5.1