Commit 395618f0 authored by VIGNET Pierre's avatar VIGNET Pierre

Remove useless files here

parent 7169e8d5
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
PROJECT(pyCryptoMS)
if (CMAKE_COMPILER_IS_GNUCC)
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -fno-omit-frame-pointer -Wall -Werror -Wno-deprecated -g -mtune=native")
SET(CMAKE_CXX_FLAGS_DEBUG "-Wall -Werror -Wno-deprecated -O0 -ggdb")
SET(CMAKE_CXX_FLAGS_RELEASE "-Wall -Werror -Wno-deprecated -O3 -g -DNDEBUG -mtune=native -fomit-frame-pointer")
#-fprofile-generate / -fprofile-use
endif(CMAKE_COMPILER_IS_GNUCC)
find_package(ZLIB REQUIRED)
link_directories(${ZLIB_LIBRARY})
include_directories(${ZLIB_INCLUDE_DIR})
# added by MLB for FindOpenMP
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_macros)
find_package(OpenMP REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
#find_package(Perftools)
add_definitions(-DVERSION="2.9.0")
add_definitions(-DUSE_GAUSS)
add_subdirectory(src)
################################################
# #
# SAT SOLVER CONPILATION INSTRUCTIONS #
# #
# http://cadbiom.genouest.org/ #
# #
################################################
################################################
# LICENCE #
################################################
CADBIOM software uses CryptoMiniSat solver,
an LGPL-licenced SAT solver
(see http://www.msoos.org/cryptominisat2/).
################################################
# COMPILATION #
################################################
(1) Unpack source_solver.tar.gz
It contains :
- build (folder)
- CMakeFiles (folder)
- cmake_macros (folder)
- docs (folder)
- src (folder)
- CMakeLists.txt
- INSTALL
(2) In build/ run the following command :
cmake ..
make
It generates pyCryptoMS.py and _pyCryptoMS.so
in build/src/binding/
(3) Paste these both files in the solver folder
that you have defined in your pythonpath
# - Finds OpenMP support
# This module can be used to detect OpenMP support in a compiler.
# If the compiler supports OpenMP, the flags required to compile with
# openmp support are set.
#
# The following variables are set:
# OpenMP_C_FLAGS - flags to add to the C compiler for OpenMP support
# OpenMP_CXX_FLAGS - flags to add to the CXX compiler for OpenMP support
# OPENMP_FOUND - true if openmp is detected
#
# Supported compilers can be found at http://openmp.org/wp/openmp-compilers/
# Copyright 2008, 2009 <André Rigland Brodtkorb> Andre.Brodtkorb@ifi.uio.no
#
# Redistribution AND use is allowed according to the terms of the New
# BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
# Modified by Marc-Andre Gardner
# 31/07/2009
# Fix unset uses
include(CheckCSourceCompiles)
include(CheckCXXSourceCompiles)
include(FindPackageHandleStandardArgs)
set(OpenMP_C_FLAG_CANDIDATES
#Gnu
"-fopenmp"
#Microsoft Visual Studio
"/openmp"
#Intel windows
"-Qopenmp"
#Intel
"-openmp"
#Empty, if compiler automatically accepts openmp
" "
#Sun
"-xopenmp"
#HP
"+Oopenmp"
#IBM XL C/c++
"-qsmp"
#Portland Group
"-mp"
)
set(OpenMP_CXX_FLAG_CANDIDATES ${OpenMP_C_FLAG_CANDIDATES})
# sample openmp source code to test
set(OpenMP_C_TEST_SOURCE
"
#include <omp.h>
int main() {
#ifdef _OPENMP
return 0;
#else
breaks_on_purpose
#endif
}
")
# use the same source for CXX as C for now
set(OpenMP_CXX_TEST_SOURCE ${OpenMP_C_TEST_SOURCE})
# if these are set then do not try to find them again,
# by avoiding any try_compiles for the flags
if(DEFINED OpenMP_C_FLAGS AND DEFINED OpenMP_CXX_FLAGS)
set(OpenMP_C_FLAG_CANDIDATES)
set(OpenMP_CXX_FLAG_CANDIDATES)
endif(DEFINED OpenMP_C_FLAGS AND DEFINED OpenMP_CXX_FLAGS)
# check c compiler
foreach(FLAG ${OpenMP_C_FLAG_CANDIDATES})
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${FLAG}")
set(OpenMP_FLAG_DETECTED)
message(STATUS "Try OpenMP C flag = [${FLAG}]")
check_c_source_compiles("${OpenMP_CXX_TEST_SOURCE}" OpenMP_FLAG_DETECTED)
set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
if(OpenMP_FLAG_DETECTED)
set(OpenMP_C_FLAGS_INTERNAL "${FLAG}")
break()
endif(OpenMP_FLAG_DETECTED)
endforeach(FLAG ${OpenMP_C_FLAG_CANDIDATES})
# check cxx compiler
foreach(FLAG ${OpenMP_CXX_FLAG_CANDIDATES})
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${FLAG}")
set(OpenMP_FLAG_DETECTED)
message(STATUS "Try OpenMP CXX flag = [${FLAG}]")
check_cxx_source_compiles("${OpenMP_C_TEST_SOURCE}" OpenMP_FLAG_DETECTED)
set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
if(OpenMP_FLAG_DETECTED)
set(OpenMP_CXX_FLAGS_INTERNAL "${FLAG}")
break()
endif(OpenMP_FLAG_DETECTED)
endforeach(FLAG ${OpenMP_CXX_FLAG_CANDIDATES})
set(OpenMP_C_FLAGS "${OpenMP_C_FLAGS_INTERNAL}"
CACHE STRING "C compiler flags for OpenMP parallization")
set(OpenMP_CXX_FLAGS "${OpenMP_CXX_FLAGS_INTERNAL}"
CACHE STRING "C++ compiler flags for OpenMP parallization")
# handle the standard arguments for find_package
find_package_handle_standard_args(OpenMP DEFAULT_MSG
OpenMP_C_FLAGS OpenMP_CXX_FLAGS )
mark_as_advanced(
OpenMP_C_FLAGS
OpenMP_CXX_FLAGS
)
# for binding
add_subdirectory(tests)
set(CMAKE_C_COMPILER /usr/bin/g++)
#add_definitions( -g -Wall -fopenmp -MD -MP -MF -O2)
#ADD_LIBRARY(CryptoMS SHARED CryptoMS.cpp )
# cmake use swig
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
find_package(PythonLibs)
include_directories(${PYTHON_INCLUDE_PATH})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../cmsat)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../mtl)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../MTRand)
set(CMAKE_SWIG_FLAGS "-c++")
set(CMAKE_SWIG_OUTDIR ${PROJECT_DIR})
set_source_files_properties(CryptoMS.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties(CryptoMS.i PROPERTIES SWIG_FLAGS "-includeall")
swig_add_module(pyCryptoMS python CryptoMS.i CryptoMS.cpp)
swig_link_libraries(pyCryptoMS ${PYTHON_LIBRARIES} cryptoms ${ZLIB_LIBRARY})
#ENABLE_TESTING()
This diff is collapsed.
/*****************************************************************************
MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
CryptoMiniSat -- Copyright (c) 2009 Mate Soos
PyCryptoMS -- Copyright (c) 2011 Michel Le Borgne
Original code by MiniSat authors are under an MIT licence.
Modifications for CryptoMiniSat are under GPLv3 licence.
Modification for PyCryptoMS are under GPLv3 licence.
******************************************************************************/
#ifndef CRYPTOMS_H
#define CRYPTOMS_H
#include <string>
using std::string;
#include <vector>
//#ifndef DISABLE_ZLIB
//#include <zlib.h>
//#endif // DISABLE_ZLIB
#include "Solver.h"
class CryptoMS
{
public:
CryptoMS();
CryptoMS(std::vector<std::string> options);
~CryptoMS(void);
// management and statistiss
void set_options(std::vector<std::string> options);
void clear_solver();
void print_stats(); // for debug
void print_nb_clauses_vars(); // for debug
int nb_clauses();
int nb_vars();
// clauses loading
bool add_clause(std::vector<int> dim);
void read_in_a_file(const std::string& filename);
// problem solving
const std::vector<int> solve(void);
const std::vector<std::vector<int> > msolve(int max_nb_sol);
const std::vector<std::vector<int> > msolve_selected(int max_nr_of_solutions, std::vector<int> var_selected);
bool is_satisfiable();
private:
const char* has_prefix(const char*, const char* prefix);
void acc_models(const CMSat::lbool ret);
void set_double_precision(const uint32_t verbosity);
int correct_return_value(const CMSat::lbool ret) const;
CMSat::SolverConf conf;
CMSat::GaussConf gaussconfig;
CMSat::Solver *solver;
std::vector<std::vector<int> > solutions;
};
//class for exceptions
class CryptoMSError{
public:
std::string message;
CryptoMSError();
CryptoMSError(char* _message);
CryptoMSError(std::string _message);
};
#endif //CRYPTOMS_H
%module pyCryptoMS
%include "typemaps.i"
%include "std_string.i"
%include "exception.i"
%include "std_vector.i"
%{
#include "CryptoMS.h"
%}
// Instantiate templates used by example
namespace std {
%template(IntVector) vector<int>;
%template(IntVectorVector) vector<vector<int> >;
%template(StringVector)vector<string>;
}
%exception {
try {
$function;
}
catch (CryptoMSError e)
{
PyErr_SetString(PyExc_Exception, e.message.c_str());
return NULL;
}
}
class CryptoMS
{
public:
CryptoMS();
~CryptoMS(void);
// management and statistisc
void set_options(std::vector<std::string> options);
void clear_solver();
void print_stats(); // for debug
void print_nb_clauses_vars(); // for debug
int nb_clauses();
int nb_vars();
// clauses loading
bool add_clause(std::vector<int> dim);
void read_in_a_file(const std::string& filename);
// problem solving
const std::vector<int> solve(void);
const std::vector<std::vector<int> > msolve(int max_nb_sol);
const std::vector<std::vector<int> > msolve_selected(int max_nr_of_solutions, std::vector<int> var_selected);
bool is_satisfiable();
};
class CryptoMSError{
public:
std::string message;
CryptoMSError();
CryptoMSError(char* _message);
CryptoMSError(std::string _message);
};
# executable are tests
set(CMAKE_C_COMPILER /usr/bin/g++)
add_definitions( -g -Wall -fopenmp -MD -MP -MF -O2)
set(CMAKE_EXE_LINKER_FLAGS " -lgomp -lz ")
add_executable(crypto_test crypto_test.cpp ../CryptoMS.cpp)
add_executable(test_solver test_solver.cpp )
target_link_libraries(crypto_test cryptoms)
target_link_libraries(test_solver cryptoms)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../..)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../cmsat)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../mtl)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../MTRand)
#ENABLE_TESTING()
#ADD_TEST()
#include "CryptoMS.h"
using namespace CMSat;
int main(int argc, char** argv)
{
std::vector<string> opt;
std::vector<int> iclause;
std::vector<std::vector<int> > msol;
std::vector<int> sol;
CryptoMS cms;
printf("AVANT \n");
//cms = new CryptoMS();
opt.push_back("verbosity=0");
cms.set_options(opt);
// add clause
// iclause.clear();
// iclause.push_back(1);
// iclause.push_back(-2);
// iclause.push_back(3);
// cms.addClause(iclause);
// iclause.push_back(5);
// iclause.push_back(-6);
// iclause.push_back(7);
// cms.add_clause(iclause);
cms.read_in_a_file("/home/michel/SAT/examples/bmc/bmc-ibm-11.cnf");
cms.print_nb_clauses_vars();
// sol = cms.solve();
// for(uint32_t i; i<sol.size(); i++)
// printf(" v = %i,",sol[i]);
msol = cms.msolve(3);
printf("solution size %i\n",msol.size());
for(uint32_t j; j<msol.size(); j++)
printf("NB composantes: %i\n", msol[j].size());
// for(uint32_t i; i<msol[j].size(); i++)
// printf(" v = %i,",msol[j][i]);
// printf("Problem satisfiability: %i\n", cms.is_satisfiable());
printf("APRES \n");
}
//#include "SCCFinder.h"
#include "Solver.h"
#include <string>
using std::string;
#include<vector>
using namespace CMSat;
int main(int argc, char** argv)
{
int i = 5;
Solver *psolver;
Lit l;
vec<Lit> assomps;
//SCCFinder* sCCFinder;
SolverConf conf;
GaussConf gaussconfig;
printf("hello: %i \n",i);
//solver.printStats();
psolver = new Solver(conf, gaussconfig);
//sCCFinder = new SCCFinder(solver);
printf("hello: %i \n",++i);
//delete psolver;
}
import unittest
import sys
sys.path.append('../../../build/src/Binding')
from pyCryptoMS import *
class TestSolv(unittest.TestCase):
def setUp(self):
self.solv = CryptoMS()
c1 = [1, -2, 3]
self.solv.addClause(c1)
c2 = [-1,-2,-3]
self.solv.addClause(c2)
def tearDown(self):
pass
## def testSimple(self):
## sol = self.solv.solve()
## print "SOL: ",sol
def testSolvMultiple(self):
msol = self.solv.msolve(100)
print '\nMSOLV',msol
print 'nbsol', len(msol)
def testMsolvSelected(self):
smsol = self.solv.msolve_selected(100, [1,2])
print '\nSMSOLV',smsol
print 'nbsol', len(smsol)
if __name__ == "__main__":
unittest.main()
## suite = unittest.TestSuite()
## suite.addTest(TestSolv("testNextSol_qdd"))
## unittest.TextTestRunner(verbosity=2).run(suite)
# head source file
ADD_SUBDIRECTORY(cmsat)
ADD_SUBDIRECTORY(Binding)
ADD_SUBDIRECTORY(mtl)
ADD_SUBDIRECTORY(MTRand)
#ENABLE_TESTING()
# source directory for MTRand
SET(CMAKE_C_COMPILER /usr/bin/g++)
ADD_DEFINITIONS(-g -Wall)
This diff is collapsed.
/*******************************************************************************************[Alg.h]
MiniSat -- Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**************************************************************************************************/
#ifndef ALG_H
#define ALG_H
#include <iostream>
#include "cmsat/Vec.h"
#include "cmsat/SolverTypes.h"
#include "cmsat/Watched.h"
#include "cmsat/constants.h"
// Useful functions on vectors
namespace CMSat {
template<class V, class T>
static inline void remove(V& ts, const T& t)
{
uint32_t j = 0;
for (; j < ts.size() && ts[j] != t; j++);
assert(j < ts.size());
for (; j < ts.size()-1; j++) ts[j] = ts[j+1];
ts.pop();
}
template<class V>
static inline uint32_t removeAll(V& ts, const Var t)
{
Lit* i = ts.getData();
Lit* j = i;
for (Lit *end = ts.getDataEnd(); i != end; i++) {
if (i->var() != t) {
*j++ = *i;
}
}
ts.shrink(i-j);
return (i-j);
}
template<class V, class T>
static inline void removeW(V& ts, const T& t)
{
uint32_t j = 0;
for (; j < ts.size() && ts[j].clause != t; j++);
assert(j < ts.size());
for (; j < ts.size()-1; j++) ts[j] = ts[j+1];
ts.pop();
}
template<class V, class T>
static inline bool find(V& ts, const T& t)
{
uint32_t j = 0;
for (; j < ts.size() && ts[j] != t; j++);
return j < ts.size();
}
template<class V, class T>
static inline bool findW(V& ts, const T& t)
{
uint32_t j = 0;
for (; j < ts.size() && ts[j].clause != t; j++);
return j < ts.size();
}
//Normal clause
static bool findWCl(const vec<Watched>& ws, const ClauseOffset c);
static void removeWCl(vec<Watched> &ws, const ClauseOffset c);
//Binary clause
static bool findWBin(const vec<vec<Watched> >& wsFull, const Lit lit1, const Lit impliedLit);
static bool findWBin(const vec<vec<Watched> >& wsFull, const Lit lit1, const Lit impliedLit, const bool learnt);
static void removeWBin(vec<Watched> &ws, const Lit impliedLit, const bool learnt);
static void removeWTri(vec<Watched> &ws, const Lit lit1, Lit lit2);
static std::pair<uint32_t, uint32_t> removeWBinAll(vec<Watched> &ws, const Lit impliedLit);
static Watched& findWatchedOfBin(vec<vec<Watched> >& wsFull, const Lit lit1, const Lit lit2, const bool learnt);
static Watched& findWatchedOfBin(vec<vec<Watched> >& wsFull, const Lit lit1, const Lit lit2);
//Xor Clause
static bool findWXCl(const vec<Watched>& ws, const ClauseOffset c);
static void removeWXCl(vec<Watched> &ws, const ClauseOffset c);
//////////////////
// NORMAL Clause
//////////////////
static inline bool findWCl(const vec<Watched>& ws, const ClauseOffset c)
{
vec<Watched>::const_iterator i = ws.getData(), end = ws.getDataEnd();
for (; i != end && (!i->isClause() || i->getNormOffset() != c); i++);
return i != end;
}
static inline void removeWCl(vec<Watched> &ws, const ClauseOffset c)
{
vec<Watched>::iterator i = ws.getData(), end = ws.getDataEnd();
for (; i != end && (!i->isClause() || i->getNormOffset() != c); i++);
assert(i != end);
vec<Watched>::iterator j = i;
i++;
for (; i != end; j++, i++) *j = *i;
ws.shrink_(1);
}
//////////////////
// XOR Clause
//////////////////
static inline bool findWXCl(const vec<Watched>& ws, const ClauseOffset c)
{
vec<Watched>::const_iterator i = ws.getData(), end = ws.getDataEnd();
for (; i != end && (!i->isXorClause() || i->getXorOffset() != c); i++);
return i != end;
}
static inline void removeWXCl(vec<Watched> &ws, const ClauseOffset c)
{
vec<Watched>::iterator i = ws.getData(), end = ws.getDataEnd();
for (; i != end && (!i->isXorClause() || i->getXorOffset() != c); i++);
assert(i != end);
vec<Watched>::iterator j = i;
i++;
for (; i != end; j++, i++) *j = *i;
ws.shrink_(1);
}
//////////////////
// TRI Clause
//////////////////
static inline bool findWTri(const vec<Watched> &ws, const Lit lit1, const Lit lit2)
{
vec<Watched>::const_iterator i = ws.getData(), end = ws.getDataEnd();
for (; i != end && (!i->isTriClause() || i->getOtherLit() != lit1 || i->getOtherLit2() != lit2); i++);
return i != end;
}
static inline void removeWTri(vec<Watched> &ws, const Lit lit1, const Lit lit2)
{
vec<Watched>::iterator i = ws.getData(), end = ws.getDataEnd();
for (; i != end && (!i->isTriClause() || i->getOtherLit() != lit1 || i->getOtherLit2() != lit2); i++);
assert(i != end);
vec<Watched>::iterator j = i;
i++;
for (; i != end; j++, i++) *j = *i;
ws.shrink_(1);