<NME> sat.hxx
<BEF> #pragma once
#ifndef OPENGM_INFERENCE_SAT_HXX
#define OPENGM_INFERENCE_SAT_HXX

#include <iostream>
#include <vector>

#include <boost/config.hpp>
#include <boost/graph/strong_components.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/foreach.hpp>

#include "opengm/inference/inference.hxx"
#include "opengm/operations/and.hxx"
#include "opengm/operations/or.hxx"
#include "opengm/inference/visitors/visitors.hxx"

namespace opengm {

   /// 2-SAT solver
   ///
   /// \ingroup inference
   template<class GM>
   class SAT : Inference<GM, opengm::Or> {
   public:
      typedef opengm::Or AccumulationType;
      typedef GM GraphicalModelType;
      OPENGM_GM_TYPE_TYPEDEFS;


        template<class _GM>
        struct RebindGm{
            typedef SAT<_GM> type;
        };

        template<class _GM,class _ACC>
        struct RebindGmAndAcc{
            typedef SAT<_GM> type;
        };


       struct Parameter{
         Parameter ( ) {};
         template<class P>
         Parameter (const P & p) {};
       };

      SAT(const GraphicalModelType&, const Parameter& = Parameter());
      std::string name() const;
      const GraphicalModelType& graphicalModel() const;
      InferenceTermination infer();
      template<class VISITOR>
      InferenceTermination infer(VISITOR &);
      virtual void reset();
      ValueType value() const;
      typedef visitors::VerboseVisitor<SAT<GM> >        VerboseVisitorType;
      typedef visitors::TimingVisitor<SAT<GM> >         TimingVisitorType;
		typedef visitors::EmptyVisitor<SAT<GM> >          EmptyVisitorType;
   private:
      const GraphicalModelType& gm_;
      std::vector<int> component_;
   };

   template<class GM>
   inline SAT<GM>::SAT
   (
      const GraphicalModelType& gm,
      const Parameter& para
   )
   :  gm_(gm)
   {
      if(!NO_DEBUG) {
         OPENGM_ASSERT(gm_.factorOrder() <= 2);
         OPENGM_ASSERT(typeid(OperatorType) == typeid(opengm::And));
         for(size_t i=0; i<gm_.numberOfVariables();++i) {
            OPENGM_ASSERT(gm_.numberOfLabels(i) == 2);
         }
      }
   }
   template<class GM>
   void
   inline SAT<GM>::reset()
   {
   }

   template<class GM>
   inline std::string
   SAT<GM>::name() const
   {
      return "2Sat";
   }

   template<class GM>
   inline const GM&
   SAT<GM>::graphicalModel() const
   {
      return gm_;
   }
   
   template<class GM>
   InferenceTermination
   SAT<GM>::infer() {
      EmptyVisitorType v;
      return infer(v);
   }
   
   template<class GM>
   template<class VISITOR>
   InferenceTermination
   SAT<GM>::infer
   (
      VISITOR & visitor
   ) {
      visitor.begin(*this);
      typedef std::pair<int, int> clause;
      typedef boost::adjacency_list<> Graph; // properties of our graph. by default: oriented graph
      // build graph
      Graph g(gm_.numberOfVariables() * 2);
         }
      }
      component_.resize(num_vertices(g));
      strong_components(g,&component_[0]);
      visitor.end(*this);
      return NORMAL;
   }
               if(!gm_[f](vec.begin())) {
                  const int  v1=gm_[f].variableIndex(0)+(1-vec[0])*gm_.numberOfVariables();
                  const int nv1=gm_[f].variableIndex(0)+(0+vec[0])*gm_.numberOfVariables();
                  const int  v2=gm_[f].variableIndex(1)+(1-vec[1])*gm_.numberOfVariables();
                  const int nv2=gm_[f].variableIndex(1)+(0+vec[1])*gm_.numberOfVariables();
                  boost::add_edge(nv1,v2,g);
                  boost::add_edge(nv2,v1,g);
               }
            }
         }
      }
      component_.resize(num_vertices(g));
      strong_components(g, make_iterator_property_map(component_.begin(), get(boost::vertex_index, g)));
      visitor.end(*this);
      return NORMAL;
   }

   template<class GM>
   inline typename GM::ValueType
   SAT<GM>::value() const
   {
      bool satisfied = true;
      for(IndexType i=0; i<gm_.numberOfVariables(); i++) {
         if(component_[i] == component_[i+gm_.numberOfVariables()]) {
            satisfied = false;
         }
      }
      return satisfied;
   }

} // namespace opengm

#endif // #ifndef OPENGM_INFERENCE_SAT_HXX


<MSG> Merge pull request #241 from yanlend/patch-1

Update sat.hxx call to boost::strong_components
<DFF> @@ -119,7 +119,7 @@ namespace opengm {
          }
       }
       component_.resize(num_vertices(g));
-      strong_components(g,&component_[0]);
+      strong_components(g, make_iterator_property_map(component_.begin(), get(boost::vertex_index, g)));
       visitor.end(*this);
       return NORMAL;
    }

{'commit': 'diff --git a/include/opengm/inference/sat.hxx b/include/opengm/inference/sat.hxx\nindex 69a38b5..2fdbfc4 100644\n--- a/include/opengm/inference/sat.hxx\n+++ b/include/opengm/inference/sat.hxx\n@@ -119,7 +119,7 @@ namespace opengm {\n          }\n       }\n       component_.resize(num_vertices(g));\n-      strong_components(g,&component_[0]);\n+      strong_components(g, make_iterator_property_map(component_.begin(), get(boost::vertex_index, g)));\n       visitor.end(*this);\n       return NORMAL;\n    }\n', 'commit_subject': 'Merge pull request #241 from yanlend/patch-1', 'repo_name': 'opengm/opengm', 'committer': {'name': 'Joerg Kappes', 'email': '1bdc2be9ae99d934be4202eb4d310bbaacd5dc64@math.uni-heidelberg.de', 'time_sec': '1394112531', 'tz_offset': '60', 'date': {'seconds': '1394112531'}}, 'commit_tree': '0147abbc9f66ae843ba8e2b51e5bd7a3d07217bb', 'commit_message': 'Merge pull request #241 from yanlend/patch-1\n\nUpdate sat.hxx call to boost::strong_components', 'language_name': 'MATLAB', 'license': 'mit', 'hunks': '@@ -119,7 +119,7 @@ namespace opengm {\n          }\n       }\n       component_.resize(num_vertices(g));\n-      strong_components(g,&component_[0]);\n+      strong_components(g, make_iterator_property_map(component_.begin(), get(boost::vertex_index, g)));\n       visitor.end(*this);\n       return NORMAL;\n    }\n', 'addition_count': 1, 'deletion_count': 1, 'src_file': 'a/include/opengm/inference/sat.hxx', 'tgt_file': 'b/include/opengm/inference/sat.hxx', 'file_extension': '.hxx', 'before_file': '#pragma once\n#ifndef OPENGM_INFERENCE_SAT_HXX\n#define OPENGM_INFERENCE_SAT_HXX\n\n#include <iostream>\n#include <vector>\n\n#include <boost/config.hpp>\n#include <boost/graph/strong_components.hpp>\n#include <boost/graph/adjacency_list.hpp>\n#include <boost/foreach.hpp>\n\n#include "opengm/inference/inference.hxx"\n#include "opengm/operations/and.hxx"\n#include "opengm/operations/or.hxx"\n#include "opengm/inference/visitors/visitors.hxx"\n\nnamespace opengm {\n\n   /// 2-SAT solver\n   ///\n   /// \\ingroup inference\n   template<class GM>\n   class SAT : Inference<GM, opengm::Or> {\n   public:\n      typedef opengm::Or AccumulationType;\n      typedef GM GraphicalModelType;\n      OPENGM_GM_TYPE_TYPEDEFS;\n\n\n        template<class _GM>\n        struct RebindGm{\n            typedef SAT<_GM> type;\n        };\n\n        template<class _GM,class _ACC>\n        struct RebindGmAndAcc{\n            typedef SAT<_GM> type;\n        };\n\n\n       struct Parameter{\n         Parameter ( ) {};\n         template<class P>\n         Parameter (const P & p) {};\n       };\n\n      SAT(const GraphicalModelType&, const Parameter& = Parameter());\n      std::string name() const;\n      const GraphicalModelType& graphicalModel() const;\n      InferenceTermination infer();\n      template<class VISITOR>\n      InferenceTermination infer(VISITOR &);\n      virtual void reset();\n      ValueType value() const;\n      typedef visitors::VerboseVisitor<SAT<GM> >        VerboseVisitorType;\n      typedef visitors::TimingVisitor<SAT<GM> >         TimingVisitorType;\n\t\ttypedef visitors::EmptyVisitor<SAT<GM> >          EmptyVisitorType;\n   private:\n      const GraphicalModelType& gm_;\n      std::vector<int> component_;\n   };\n\n   template<class GM>\n   inline SAT<GM>::SAT\n   (\n      const GraphicalModelType& gm,\n      const Parameter& para\n   )\n   :  gm_(gm)\n   {\n      if(!NO_DEBUG) {\n         OPENGM_ASSERT(gm_.factorOrder() <= 2);\n         OPENGM_ASSERT(typeid(OperatorType) == typeid(opengm::And));\n         for(size_t i=0; i<gm_.numberOfVariables();++i) {\n            OPENGM_ASSERT(gm_.numberOfLabels(i) == 2);\n         }\n      }\n   }\n   template<class GM>\n   void\n   inline SAT<GM>::reset()\n   {\n   }\n\n   template<class GM>\n   inline std::string\n   SAT<GM>::name() const\n   {\n      return "2Sat";\n   }\n\n   template<class GM>\n   inline const GM&\n   SAT<GM>::graphicalModel() const\n   {\n      return gm_;\n   }\n   \n   template<class GM>\n   InferenceTermination\n   SAT<GM>::infer() {\n      EmptyVisitorType v;\n      return infer(v);\n   }\n   \n   template<class GM>\n   template<class VISITOR>\n   InferenceTermination\n   SAT<GM>::infer\n   (\n      VISITOR & visitor\n   ) {\n      visitor.begin(*this);\n      typedef std::pair<int, int> clause;\n      typedef boost::adjacency_list<> Graph; // properties of our graph. by default: oriented graph\n      // build graph\n      Graph g(gm_.numberOfVariables() * 2);\n         }\n      }\n      component_.resize(num_vertices(g));\n      strong_components(g,&component_[0]);\n      visitor.end(*this);\n      return NORMAL;\n   }\n               if(!gm_[f](vec.begin())) {\n                  const int  v1=gm_[f].variableIndex(0)+(1-vec[0])*gm_.numberOfVariables();\n                  const int nv1=gm_[f].variableIndex(0)+(0+vec[0])*gm_.numberOfVariables();\n                  const int  v2=gm_[f].variableIndex(1)+(1-vec[1])*gm_.numberOfVariables();\n                  const int nv2=gm_[f].variableIndex(1)+(0+vec[1])*gm_.numberOfVariables();\n                  boost::add_edge(nv1,v2,g);\n                  boost::add_edge(nv2,v1,g);\n               }\n            }\n         }\n      }\n      component_.resize(num_vertices(g));\n      strong_components(g, make_iterator_property_map(component_.begin(), get(boost::vertex_index, g)));\n      visitor.end(*this);\n      return NORMAL;\n   }\n\n   template<class GM>\n   inline typename GM::ValueType\n   SAT<GM>::value() const\n   {\n      bool satisfied = true;\n      for(IndexType i=0; i<gm_.numberOfVariables(); i++) {\n         if(component_[i] == component_[i+gm_.numberOfVariables()]) {\n            satisfied = false;\n         }\n      }\n      return satisfied;\n   }\n\n} // namespace opengm\n\n#endif // #ifndef OPENGM_INFERENCE_SAT_HXX\n\n', 'message': 'Merge pull request #241 from yanlend/patch-1\n\nUpdate sat.hxx call to boost::strong_components', 'author_name': 'Joerg Kappes', 'lang': 'hxx'}