Commit b3d3f7dd authored by Alan Mishchenko's avatar Alan Mishchenko

Duplicating Glucose package.

parent 890aa684
......@@ -27,7 +27,7 @@ MODULES := \
src/opt/cut src/opt/fxu src/opt/fxch src/opt/rwr src/opt/mfs src/opt/sim \
src/opt/ret src/opt/fret src/opt/res src/opt/lpk src/opt/nwk src/opt/rwt \
src/opt/cgt src/opt/csw src/opt/dar src/opt/dau src/opt/dsc src/opt/sfm src/opt/sbd \
src/sat/bsat src/sat/xsat src/sat/satoko src/sat/csat src/sat/msat src/sat/psat src/sat/cnf src/sat/bmc src/sat/glucose \
src/sat/bsat src/sat/xsat src/sat/satoko src/sat/csat src/sat/msat src/sat/psat src/sat/cnf src/sat/bmc src/sat/glucose src/sat/glucose2 \
src/bool/bdc src/bool/deco src/bool/dec src/bool/kit src/bool/lucky \
src/bool/rsb src/bool/rpo \
src/proof/pdr src/proof/abs src/proof/live src/proof/ssc src/proof/int \
......
......@@ -2366,6 +2366,114 @@ SOURCE=.\src\sat\glucose\Vec.h
SOURCE=.\src\sat\glucose\XAlloc.h
# End Source File
# End Group
# Begin Group "glucose2"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\src\sat\glucose2\AbcGlucose2.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\AbcGlucose2.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\AbcGlucoseCmd2.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\Alg.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\Alloc.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\BoundedQueue.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\Constants.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\Dimacs.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\Glucose2.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\Heap.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\IntTypes.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\Map.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\Options.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\Options2.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\ParseUtils.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\pstdint.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\Queue.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\SimpSolver.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\SimpSolver2.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\Solver.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\SolverTypes.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\Sort.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\System.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\System2.cpp
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\Vec.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\glucose2\XAlloc.h
# End Source File
# End Group
# End Group
# Begin Group "opt"
......
......@@ -65,6 +65,8 @@ extern void Abc85_Init( Abc_Frame_t * pAbc );
extern void Abc85_End( Abc_Frame_t * pAbc );
extern void Glucose_Init( Abc_Frame_t *pAbc );
extern void Glucose_End( Abc_Frame_t * pAbc );
extern void Glucose2_Init( Abc_Frame_t *pAbc );
extern void Glucose2_End( Abc_Frame_t * pAbc );
static Abc_FrameInitializer_t* s_InitializerStart = NULL;
static Abc_FrameInitializer_t* s_InitializerEnd = NULL;
......@@ -120,6 +122,7 @@ void Abc_FrameInit( Abc_Frame_t * pAbc )
Sim_Init( pAbc );
Test_Init( pAbc );
Glucose_Init( pAbc );
Glucose2_Init( pAbc );
for( p = s_InitializerStart ; p ; p = p->next )
if(p->init)
p->init(pAbc);
......
This diff is collapsed.
This diff is collapsed.
/**CFile****************************************************************
FileName [AbcGlucose.h]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [SAT solver Glucose 3.0 by Gilles Audemard and Laurent Simon.]
Synopsis [Interface to Glucose.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - September 6, 2017.]
Revision [$Id: AbcGlucose.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#ifndef ABC_SAT_GLUCOSE_H_
#define ABC_SAT_GLUCOSE_H_
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
#include "aig/gia/gia.h"
////////////////////////////////////////////////////////////////////////
/// PARAMETERS ///
////////////////////////////////////////////////////////////////////////
#define GLUCOSE_UNSAT -1
#define GLUCOSE_SAT 1
#define GLUCOSE_UNDEC 0
ABC_NAMESPACE_HEADER_START
////////////////////////////////////////////////////////////////////////
/// BASIC TYPES ///
////////////////////////////////////////////////////////////////////////
typedef struct Glucose2_Pars_ Glucose2_Pars;
struct Glucose2_Pars_ {
int pre; // preprocessing
int verb; // verbosity
int cust; // customizable
int nConfls; // conflict limit (0 = no limit)
};
static inline Glucose2_Pars Glucose_CreatePars(int p, int v, int c, int nConfls)
{
Glucose2_Pars pars;
pars.pre = p;
pars.verb = v;
pars.cust = c;
pars.nConfls = nConfls;
return pars;
}
typedef void bmcg2_sat_solver;
////////////////////////////////////////////////////////////////////////
/// MACRO DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
extern bmcg2_sat_solver * bmcg2_sat_solver_start();
extern void bmcg2_sat_solver_stop( bmcg2_sat_solver* s );
extern void bmcg2_sat_solver_reset( bmcg2_sat_solver* s );
extern int bmcg2_sat_solver_addclause( bmcg2_sat_solver* s, int * plits, int nlits );
extern void bmcg2_sat_solver_setcallback( bmcg2_sat_solver* s, void * pman, int(*pfunc)(void*, int, int*) );
extern int bmcg2_sat_solver_solve( bmcg2_sat_solver* s, int * plits, int nlits );
extern int bmcg2_sat_solver_final( bmcg2_sat_solver* s, int ** ppArray );
extern int bmcg2_sat_solver_addvar( bmcg2_sat_solver* s );
extern void bmcg2_sat_solver_set_nvars( bmcg2_sat_solver* s, int nvars );
extern int bmcg2_sat_solver_eliminate( bmcg2_sat_solver* s, int turn_off_elim );
extern int bmcg2_sat_solver_var_is_elim( bmcg2_sat_solver* s, int v );
extern void bmcg2_sat_solver_var_set_frozen( bmcg2_sat_solver* s, int v, int freeze );
extern int bmcg2_sat_solver_elim_varnum(bmcg2_sat_solver* s);
extern int * bmcg2_sat_solver_read_cex( bmcg2_sat_solver* s );
extern int bmcg2_sat_solver_read_cex_varvalue( bmcg2_sat_solver* s, int );
extern void bmcg2_sat_solver_set_stop( bmcg2_sat_solver* s, int * pstop );
extern abctime bmcg2_sat_solver_set_runtime_limit( bmcg2_sat_solver* s, abctime Limit );
extern void bmcg2_sat_solver_set_conflict_budget( bmcg2_sat_solver* s, int Limit );
extern int bmcg2_sat_solver_varnum( bmcg2_sat_solver* s );
extern int bmcg2_sat_solver_clausenum( bmcg2_sat_solver* s );
extern int bmcg2_sat_solver_learntnum( bmcg2_sat_solver* s );
extern int bmcg2_sat_solver_conflictnum( bmcg2_sat_solver* s );
extern int bmcg2_sat_solver_minimize_assumptions( bmcg2_sat_solver * s, int * plits, int nlits, int pivot );
extern int bmcg2_sat_solver_add_and( bmcg2_sat_solver * s, int iVar, int iVar0, int iVar1, int fCompl0, int fCompl1, int fCompl );
extern int bmcg2_sat_solver_quantify( bmcg2_sat_solver * s[], Gia_Man_t * p, int iLit, int fHash, int(*pFuncCiToKeep)(void *, int), void * pData, Vec_Int_t * vDLits );
extern int bmcg2_sat_solver_equiv_overlap_check( bmcg2_sat_solver * s, Gia_Man_t * p, int iLit0, int iLit1, int fEquiv );
extern Vec_Str_t * bmcg2_sat_solver_sop( Gia_Man_t * p, int CubeLimit );
extern void Glucose2_SolveCnf( char * pFilename, Glucose2_Pars * pPars );
extern int Glucose2_SolveAig( Gia_Man_t * p, Glucose2_Pars * pPars );
ABC_NAMESPACE_HEADER_END
#endif
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
/**CFile****************************************************************
FileName [AbcGlucoseCmd.cpp]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [SAT solver Glucose 3.0 by Gilles Audemard and Laurent Simon.]
Synopsis [Interface to Glucose.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - September 6, 2017.]
Revision [$Id: AbcGlucoseCmd.cpp,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "aig/gia/gia.h"
#include "base/main/mainInt.h"
#include "sat/glucose2/AbcGlucose2.h"
ABC_NAMESPACE_HEADER_START
extern void Glucose2_Init( Abc_Frame_t *pAbc );
extern void Glucose2_End( Abc_Frame_t * pAbc );
ABC_NAMESPACE_HEADER_END
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
static int Abc_CommandGlucose( Abc_Frame_t * pAbc, int argc, char ** argv );
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Glucose2_Init(Abc_Frame_t *pAbc)
{
Cmd_CommandAdd( pAbc, "ABC9", "&glucose", Abc_CommandGlucose, 0 );
}
void Glucose2_End( Abc_Frame_t * pAbc )
{
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Abc_CommandGlucose( Abc_Frame_t * pAbc, int argc, char ** argv )
{
int c = 0;
int pre = 1;
int verb = 0;
int nConfls = 0;
Glucose2_Pars pPars;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "Cpvh" ) ) != EOF )
{
switch ( c )
{
case 'C':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-C\" should be followed by an integer.\n" );
goto usage;
}
nConfls = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( nConfls < 0 )
goto usage;
break;
case 'p':
pre ^= 1;
break;
case 'v':
verb ^= 1;
break;
case 'h':
goto usage;
default:
goto usage;
}
}
pPars = Glucose_CreatePars(pre,verb,0,nConfls);
if ( argc == globalUtilOptind + 1 )
{
Glucose2_SolveCnf( argv[globalUtilOptind], &pPars );
return 0;
}
if ( pAbc->pGia == NULL )
{
Abc_Print( -1, "Abc_CommandGlucose(): There is no AIG.\n" );
return 1;
}
if ( Glucose2_SolveAig( pAbc->pGia, &pPars ) == 10 )
Abc_FrameReplaceCex( pAbc, &pAbc->pGia->pCexComb );
return 0;
usage:
Abc_Print( -2, "usage: &glucose2 [-C num] [-pvh] <file.cnf>\n" );
Abc_Print( -2, "\t run Glucose 3.0 by Gilles Audemard and Laurent Simon\n" );
Abc_Print( -2, "\t-C num : conflict limit [default = %d]\n", nConfls );
Abc_Print( -2, "\t-p : enable preprocessing [default = %d]\n",pre);
Abc_Print( -2, "\t-v : verbosity [default = %d]\n",verb);
Abc_Print( -2, "\t-h : print the command usage\n");
Abc_Print( -2, "\t<file.cnf> : (optional) CNF file to solve\n");
return 1;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END
/*******************************************************************************************[Alg.h]
Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
Copyright (c) 2007-2010, 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 Glucose_Alg_h
#define Glucose_Alg_h
#include "sat/glucose2/Vec.h"
ABC_NAMESPACE_CXX_HEADER_START
namespace Gluco2 {
//=================================================================================================
// Useful functions on vector-like types:
//=================================================================================================
// Removing and searching for elements:
//
template<class V, class T>
static inline void remove(V& ts, const T& t)
{
int 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, class T>
static inline bool find(V& ts, const T& t)
{
int j = 0;
for (; j < ts.size() && ts[j] != t; j++);
return j < ts.size();
}
//=================================================================================================
// Copying vectors with support for nested vector types:
//
// Base case:
template<class T>
static inline void copy(const T& from, T& to)
{
to = from;
}
// Recursive case:
template<class T>
static inline void copy(const vec<T>& from, vec<T>& to, bool append = false)
{
if (!append)
to.clear();
for (int i = 0; i < from.size(); i++){
to.push();
copy(from[i], to.last());
}
}
template<class T>
static inline void append(const vec<T>& from, vec<T>& to){ copy(from, to, true); }
//=================================================================================================
}
ABC_NAMESPACE_CXX_HEADER_END
#endif
/*****************************************************************************************[Alloc.h]
Copyright (c) 2008-2010, 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 Glucose_Alloc_h
#define Glucose_Alloc_h
#include "sat/glucose2/XAlloc.h"
#include "sat/glucose2/Vec.h"
ABC_NAMESPACE_CXX_HEADER_START
namespace Gluco2 {
//=================================================================================================
// Simple Region-based memory allocator:
template<class T>
class RegionAllocator
{
T* memory;
uint32_t sz;
uint32_t cap;
uint32_t wasted_;
void capacity(uint32_t min_cap);
public:
// TODO: make this a class for better type-checking?
typedef uint32_t Ref;
enum { Ref_Undef = UINT32_MAX };
enum { Unit_Size = sizeof(uint32_t) };
explicit RegionAllocator(uint32_t start_cap = 1024*1024) : memory(NULL), sz(0), cap(0), wasted_(0){ capacity(start_cap); }
~RegionAllocator()
{
if (memory != NULL)
::free(memory);
}
uint32_t size () const { return sz; }
uint32_t wasted () const { return wasted_; }
Ref alloc (int size);
void free_ (int size) { wasted_ += size; }
void clear () { sz = 0; wasted_=0; }
// Deref, Load Effective Address (LEA), Inverse of LEA (AEL):
T& operator[](Ref r) { assert(r >= 0 && r < sz); return memory[r]; }
const T& operator[](Ref r) const { assert(r >= 0 && r < sz); return memory[r]; }
T* lea (Ref r) { assert(r >= 0 && r < sz); return &memory[r]; }
const T* lea (Ref r) const { assert(r >= 0 && r < sz); return &memory[r]; }
Ref ael (const T* t) { assert((void*)t >= (void*)&memory[0] && (void*)t < (void*)&memory[sz-1]);
return (Ref)(t - &memory[0]); }
void moveTo(RegionAllocator& to) {
if (to.memory != NULL) ::free(to.memory);
to.memory = memory;
to.sz = sz;
to.cap = cap;
to.wasted_ = wasted_;
memory = NULL;
sz = cap = wasted_ = 0;
}
};
template<class T>
void RegionAllocator<T>::capacity(uint32_t min_cap)
{
if (cap >= min_cap) return;
uint32_t prev_cap = cap;
while (cap < min_cap){
// NOTE: Multiply by a factor (13/8) without causing overflow, then add 2 and make the
// result even by clearing the least significant bit. The resulting sequence of capacities
// is carefully chosen to hit a maximum capacity that is close to the '2^32-1' limit when
// using 'uint32_t' as indices so that as much as possible of this space can be used.
uint32_t delta = ((cap >> 1) + (cap >> 3) + 2) & ~1;
cap += delta;
if (cap <= prev_cap)
throw OutOfMemoryException();
}
//printf(" .. (%p) cap = %u\n", this, cap);
assert(cap > 0);
memory = (T*)xrealloc(memory, sizeof(T)*cap);
}
template<class T>
typename RegionAllocator<T>::Ref
RegionAllocator<T>::alloc(int size)
{
//printf("ALLOC called (this = %p, size = %d)\n", this, size); fflush(stdout);
assert(size > 0);
capacity(sz + size);
uint32_t prev_sz = sz;
sz += size;
// Handle overflow:
if (sz < prev_sz)
throw OutOfMemoryException();
return prev_sz;
}
//=================================================================================================
}
ABC_NAMESPACE_CXX_HEADER_END
#endif
/***********************************************************************************[BoundedQueue.h]
Glucose -- Copyright (c) 2009, Gilles Audemard, Laurent Simon
CRIL - Univ. Artois, France
LRI - Univ. Paris Sud, France
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 BoundedQueue_h
#define BoundedQueue_h
#include "sat/glucose2/Vec.h"
ABC_NAMESPACE_CXX_HEADER_START
//=================================================================================================
namespace Gluco2 {
template <class T>
class bqueue {
vec<T> elems;
int first;
int last;
uint64_t sumofqueue;
int maxsize;
int queuesize; // Number of current elements (must be < maxsize !)
bool expComputed;
double exp,value;
public:
bqueue(void) : first(0), last(0), sumofqueue(0), maxsize(0), queuesize(0),expComputed(false) { }
void initSize(int size) {growTo(size);exp = 2.0/(size+1);} // Init size of bounded size queue
void push(T x) {
expComputed = false;
if (queuesize==maxsize) {
assert(last==first); // The queue is full, next value to enter will replace oldest one
sumofqueue -= elems[last];
if ((++last) == maxsize) last = 0;
} else
queuesize++;
sumofqueue += x;
elems[first] = x;
if ((++first) == maxsize) {first = 0;last = 0;}
}
T peek() { assert(queuesize>0); return elems[last]; }
void pop() {sumofqueue-=elems[last]; queuesize--; if ((++last) == maxsize) last = 0;}
uint64_t getsum() const {return sumofqueue;}
unsigned int getavg() const {return (unsigned int)(sumofqueue/((uint64_t)queuesize));}
int maxSize() const {return maxsize;}
double getavgDouble() const {
double tmp = 0;
for(int i=0;i<elems.size();i++) {
tmp+=elems[i];
}
return tmp/elems.size();
}
int isvalid() const {return (queuesize==maxsize);}
void growTo(int size) {
elems.growTo(size);
first=0; maxsize=size; queuesize = 0;last = 0;
for(int i=0;i<size;i++) elems[i]=0;
}