├── .gitignore ├── algorithms.txt ├── src ├── mylocal.h ├── ubcsat-mem.h ├── ubcsat-time.h ├── ubcsat.h ├── ubcsat-lit.h ├── ubcsat-limits.h ├── algorithms.c ├── reports.h ├── samd.c ├── ubcsat-mem.c ├── ubcsat-time.c ├── algorithms.h ├── hwsat.c ├── rgsat.c ├── ubcsat.c ├── random.c ├── hsat.c ├── ubcsat-io.h ├── gsat.c ├── gsat-tabu.c ├── gwsat.c ├── adaptnovelty.c ├── ddfw.c ├── mylocal.c ├── rots.c ├── ubcsat-internal.h ├── walksat.c ├── rnovelty.c ├── walksat-tabu.c ├── mt19937ar.c ├── ubcsat-io.c ├── paws.c ├── parameters.c ├── ubcsat-types.h ├── g2wsat.c ├── vw.c ├── derandomized.c ├── novelty+p.c ├── irots.c └── ubcsat-globals.h ├── Makefile ├── readme.txt ├── legal.txt └── revisions.txt /.gitignore: -------------------------------------------------------------------------------- 1 | ubcsat 2 | ubcsat.exe -------------------------------------------------------------------------------- /algorithms.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dtompkins/ubcsat/HEAD/algorithms.txt -------------------------------------------------------------------------------- /src/mylocal.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | 24 | void AddLocal(); 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/ubcsat-mem.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | void *AllocateRAM( size_t size ); 24 | void AdjustLastRAM( size_t size ); 25 | void PrintMemUsage(); 26 | void SetString(char **sNew, const char *sSrc); 27 | void FreeRAM(); 28 | 29 | extern UINT32 iNumHeap; 30 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: ubcsat 2 | 3 | ubcsat: src/adaptnovelty.c src/algorithms.c src/algorithms.h src/ddfw.c src/derandomized.c src/g2wsat.c src/gsat.c src/gsat-tabu.c src/gwsat.c src/hsat.c src/hwsat.c src/irots.c src/mt19937ar.c src/mylocal.c src/mylocal.h src/novelty.c src/novelty+p.c src/parameters.c src/paws.c src/random.c src/reports.c src/reports.h src/rgsat.c src/rnovelty.c src/rots.c src/samd.c src/saps.c src/ubcsat.c src/ubcsat.h src/ubcsat-globals.h src/ubcsat-help.c src/ubcsat-internal.c src/ubcsat-internal.h src/ubcsat-io.c src/ubcsat-io.h src/ubcsat-limits.h src/ubcsat-lit.h src/ubcsat-mem.c src/ubcsat-mem.h src/ubcsat-reports.c src/ubcsat-time.c src/ubcsat-time.h src/ubcsat-triggers.c src/ubcsat-triggers.h src/ubcsat-types.h src/vw.c src/walksat.c src/walksat-tabu.c 4 | gcc -O3 -lm -o ubcsat src/adaptnovelty.c src/algorithms.c src/derandomized.c src/ddfw.c src/g2wsat.c src/gsat.c src/gsat-tabu.c src/gwsat.c src/hsat.c src/hwsat.c src/irots.c src/mt19937ar.c src/mylocal.c src/novelty.c src/novelty+p.c src/parameters.c src/paws.c src/random.c src/reports.c src/rgsat.c src/rnovelty.c src/rots.c src/samd.c src/saps.c src/ubcsat.c src/ubcsat-help.c src/ubcsat-internal.c src/ubcsat-io.c src/ubcsat-mem.c src/ubcsat-reports.c src/ubcsat-time.c src/ubcsat-triggers.c src/vw.c src/walksat.c src/walksat-tabu.c 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/ubcsat-time.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #ifdef WIN32 24 | #include 25 | #else 26 | #include 27 | #include 28 | #include 29 | #endif 30 | 31 | void InitSeed(); 32 | 33 | void StartTotalClock(); 34 | void StopTotalClock(); 35 | 36 | void StartRunClock(); 37 | void StopRunClock(); 38 | 39 | double TotalTimeElapsed(); 40 | double RunTimeElapsed(); 41 | 42 | extern double fTotalTime; 43 | extern double fRunTime; 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/ubcsat.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #ifndef UBCSAT 24 | 25 | #define UBCSAT 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "ubcsat-limits.h" 33 | #include "ubcsat-types.h" 34 | 35 | #include "ubcsat-lit.h" 36 | #include "ubcsat-mem.h" 37 | #include "ubcsat-time.h" 38 | #include "ubcsat-io.h" 39 | #include "ubcsat-internal.h" 40 | #include "ubcsat-globals.h" 41 | #include "ubcsat-triggers.h" 42 | 43 | #include "algorithms.h" 44 | #include "reports.h" 45 | 46 | #include "mylocal.h" 47 | 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /src/ubcsat-lit.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #define LITTYPE unsigned long 24 | 25 | #define GetTrueLit(V) (((V) << 1) + 1 - aVarValue[V]) 26 | #define GetFalseLit(V) (((V) << 1) + aVarValue[V]) 27 | 28 | #define GetPosLit(V) (((V) << 1)) 29 | #define GetNegLit(V) (((V) << 1) + 1) 30 | 31 | #define GetNegatedLit(L) ((L) ^ 0x00000001) 32 | 33 | #define GetLitSign(L) ((L) & 0x00000001) 34 | 35 | #define GetVarFromLit(L) ((L) >> 1) 36 | #define GetVar(c,p) (pClauseLits[c][p] >> 1) 37 | 38 | #define IsLitTrue(L) (aVarValue[(L) >> 1] ^ (L & 0x00000001)) 39 | 40 | #define SetLitFromFile(V) (((V) < 0) ? (((-(V)) << 1) + 1) : ((V) << 1)) 41 | 42 | -------------------------------------------------------------------------------- /src/ubcsat-limits.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #define DEFAULTHEAPSIZE 4194304 24 | #define MAXHEAPS 1024 25 | 26 | #define LITSPERCHUNK 262144 27 | 28 | #define MAXNUMALG 128 29 | #define MAXALGPARMS 16 30 | 31 | #define MAXFXNLIST 32 32 | 33 | #define MAXCNFLINELEN 16384 34 | 35 | #define MAXREPORTS 64 36 | #define MAXREPORTPARMS 8 37 | 38 | #define MAXPARMLINELEN 4096 39 | #define MAXTOTALPARMS 128 40 | 41 | #define MAXITEMLIST 512 42 | #define MAXITEMLISTSTRINGLENGTH 1024 43 | 44 | #define MAXREPORTHEADERSTRING 256 45 | 46 | #define RANDOMFILEBUFFERSIZE 1048576 47 | 48 | #define HELPSTRINGLENGTH 128 49 | 50 | #define MAXDYNAMICPARMS 16 51 | 52 | -------------------------------------------------------------------------------- /src/algorithms.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #include "ubcsat.h" 24 | 25 | void AddAlgorithms() { 26 | 27 | AddGSat(); 28 | AddGWSat(); 29 | AddGSatTabu(); 30 | 31 | AddHSat(); 32 | AddHWSat(); 33 | 34 | AddWalkSat(); 35 | AddWalkSatTabu(); 36 | 37 | AddNovelty(); 38 | AddNoveltyPlus(); 39 | AddNoveltyPlusPlus(); 40 | 41 | AddNoveltyPlusP(); 42 | 43 | AddAdaptNoveltyPlus(); 44 | 45 | AddRNovelty(); 46 | AddRNoveltyPlus(); 47 | 48 | AddSAPS(); 49 | 50 | AddPAWS(); 51 | 52 | AddDDFW(); 53 | 54 | AddG2WSat(); 55 | 56 | AddVW(); 57 | 58 | AddRoTS(); 59 | AddIRoTS(); 60 | 61 | AddSAMD(); 62 | 63 | AddRandom(); 64 | 65 | AddDerandomized(); 66 | 67 | AddRGSat(); 68 | 69 | } 70 | 71 | -------------------------------------------------------------------------------- /src/reports.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | void AddReports(); 24 | 25 | extern REPORT *pRepHelp; 26 | extern REPORT *pRepErr; 27 | 28 | extern REPORT *pRepOut; 29 | extern REPORT *pRepRTD; 30 | extern REPORT *pRepStats; 31 | extern REPORT *pRepState; 32 | extern REPORT *pRepModel; 33 | extern REPORT *pRepSolution; 34 | extern REPORT *pRepUniqueSol; 35 | extern REPORT *pRepBestSol; 36 | extern REPORT *pRepBestStep; 37 | extern REPORT *pRepTrajBestLM; 38 | extern REPORT *pRepOptClauses; 39 | extern REPORT *pRepFalseHist; 40 | extern REPORT *pRepDistance; 41 | extern REPORT *pRepDistHist; 42 | extern REPORT *pRepCNFStats; 43 | extern REPORT *pRepFlipCounts; 44 | extern REPORT *pRepBiasCounts; 45 | extern REPORT *pRepUnsatCounts; 46 | extern REPORT *pRepVarLast; 47 | extern REPORT *pRepClauseLast; 48 | extern REPORT *pRepSQGrid; 49 | extern REPORT *pRepPenalty; 50 | extern REPORT *pRepPenMean; 51 | extern REPORT *pRepPenStddev; 52 | extern REPORT *pRepPenCV; 53 | extern REPORT *pRepMobility; 54 | extern REPORT *pRepMobFixed; 55 | extern REPORT *pRepMobFixedFreq; 56 | extern REPORT *pRepAutoCorr; 57 | extern REPORT *pRepTriggers; 58 | extern REPORT *pRepSATComp; 59 | 60 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | 2 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 3 | ## ## ## ## ## $$ $$ $$ $$ 4 | ## ## ##### ## $$$$ $$$$$$ $$ 5 | ## ## ## ## ## $$ $$ $$ $$ 6 | #### ##### ##### $$$$$ $$ $$ $$ 7 | ====================================================== 8 | SLS SAT Solver from The University of British Columbia 9 | ====================================================== 10 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 11 | ------------------------------------------------------ 12 | .......consult legal.txt for legal information........ 13 | ......consult revisions.txt for revision history...... 14 | ------------------------------------------------------ 15 | ... project website: http://www.satlib.org/ubcsat .... 16 | ------------------------------------------------------ 17 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 18 | ------------------------------------------------------ 19 | 20 | 21 | README Release Notes 22 | ==================== 23 | 24 | The website should be consulted for the latest news on the ubcsat project 25 | 26 | http://www.satlib.org/ubcsat (or, alternatively, www.cs.ubc.ca/~davet/ubcsat) 27 | 28 | * to get started with ubcsat, we recommend you consult the online "Quick Start" guide 29 | 30 | * the FAQ may also help with some of your initial questions 31 | 32 | * please do not hesitate to contact us via e-mail regarding any 33 | questions, problems, suggestions, comments 34 | 35 | * To receive updates when new versions of ubcsat are available, 36 | and other exciting ubcsat news, 37 | we highly recommend you subscribe to our mailing list. 38 | 39 | Note that the mailing list is moderated, spam-free, and and will not be abused. 40 | 41 | to subscribe, send a message to majordomo@cs.ubc.ca with the text: 42 | 43 | subscribe ubcsat-updates 44 | 45 | as the body (not the header) of the message 46 | 47 | 48 | * If you want to understand how to write code and interface with the code, 49 | we suggest you read the paper 50 | 51 | then look at an algorithm implementation (i.e.: walksat-tabu.c) and then... 52 | 53 | for now (more documentation forthcoming) look at code examples on how to use: 54 | 55 | (ubcsat-globals.h) -- describes all the global variables and routines you need 56 | 57 | (ubcsat-triggers.h) -- describes the available triggers and their data structures 58 | 59 | -------------------------------------------------------------------------------- /src/samd.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #include "ubcsat.h" 24 | 25 | void SAMDUpdateVarLastChange(); 26 | void SAMDUpdateVarLastChangeW(); 27 | 28 | void AddSAMD() { 29 | 30 | ALGORITHM *pCurAlg; 31 | 32 | pCurAlg = CreateAlgorithm("samd","",FALSE, 33 | "SAMD: Steepest Ascent Mildest Descent", 34 | "Hansen and Jaumard [Computing 1990]", 35 | "PickGSatTabu,SAMDUpdateVarLastChange", 36 | "DefaultProcedures,Flip+VarScore", 37 | "default","default"); 38 | 39 | CopyParameters(pCurAlg,"gsat-tabu","",FALSE); 40 | 41 | CreateTrigger("SAMDUpdateVarLastChange",UpdateStateInfo,SAMDUpdateVarLastChange,"VarLastChange","UpdateVarLastChange"); 42 | 43 | pCurAlg = CreateAlgorithm("samd","",TRUE, 44 | "SAMD: Steepest Ascent Mildest Descent (weighted)", 45 | "Hansen and Jaumard [Computing 1990]", 46 | "PickGSatTabuW,SAMDUpdateVarLastChangeW", 47 | "DefaultProceduresW,Flip+VarScoreW", 48 | "default_w","default"); 49 | 50 | CopyParameters(pCurAlg,"gsat-tabu","",1); 51 | 52 | CreateTrigger("SAMDUpdateVarLastChangeW",UpdateStateInfo,SAMDUpdateVarLastChangeW,"VarLastChange","UpdateVarLastChange"); 53 | } 54 | 55 | /* SAMD is essentially the same as GSAT-TABU, 56 | except the age of flipped variables are not changed (and hence not tabu) 57 | if they were flipped in an improving search step 58 | */ 59 | 60 | void SAMDUpdateVarLastChange() { 61 | if (iBestScore >= 0) { 62 | UpdateVarLastChange(); 63 | } 64 | } 65 | 66 | void SAMDUpdateVarLastChangeW() { 67 | if (fBestScore >= FLOATZERO) { 68 | UpdateVarLastChange(); 69 | } 70 | } 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /src/ubcsat-mem.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #include "ubcsat.h" 24 | 25 | /* 26 | This file contains the simple memory managment of ubcsat 27 | */ 28 | 29 | 30 | UINT32 iNumHeap; 31 | size_t iLastRequestSize; 32 | UINT32 iLastHeap; 33 | 34 | typedef struct typeUBCSATHEAP { 35 | char *pHeap; 36 | char *pFree; 37 | size_t iBytesFree; 38 | } UBCSATHEAP; 39 | 40 | UBCSATHEAP aHeap[MAXHEAPS]; 41 | 42 | void *AllocateRAM( size_t size ) { 43 | UINT32 j; 44 | BOOL bFound; 45 | UINT32 iHeapID = 0; 46 | void *pReturn; 47 | 48 | size = size + (4-(size % 4)); 49 | 50 | iLastRequestSize = size; 51 | 52 | bFound = FALSE; 53 | 54 | for (j=0;j= size) { 56 | bFound = TRUE; 57 | iHeapID = j; 58 | break; 59 | } 60 | } 61 | if (!bFound) { 62 | if (size > DEFAULTHEAPSIZE) { 63 | aHeap[iNumHeap].pHeap = malloc(size); 64 | aHeap[iNumHeap].pFree = aHeap[iNumHeap].pHeap; 65 | aHeap[iNumHeap].iBytesFree = size; 66 | } else { 67 | aHeap[iNumHeap].pHeap = malloc(DEFAULTHEAPSIZE); 68 | aHeap[iNumHeap].pFree = aHeap[iNumHeap].pHeap; 69 | aHeap[iNumHeap].iBytesFree = DEFAULTHEAPSIZE; 70 | } 71 | iHeapID = iNumHeap; 72 | iNumHeap++; 73 | if (iNumHeap == MAXHEAPS) { 74 | ReportPrint1(pRepErr,"Unexpected Error: increase constant MAXHEAPS [%u]\n",MAXHEAPS); 75 | AbnormalExit(); 76 | } 77 | } 78 | 79 | pReturn = (void *) aHeap[iHeapID].pFree; 80 | aHeap[iHeapID].pFree += size; 81 | aHeap[iHeapID].iBytesFree -= size; 82 | iLastHeap = iHeapID; 83 | return(pReturn); 84 | } 85 | 86 | void AdjustLastRAM( size_t size ) { 87 | size = size + (4-(size % 4)); 88 | aHeap[iLastHeap].iBytesFree += (iLastRequestSize - size); 89 | aHeap[iLastHeap].pFree -= (iLastRequestSize - size); 90 | } 91 | 92 | void SetString(char **sNew, const char *sSrc) { 93 | (*sNew) = AllocateRAM(strlen(sSrc)+1); 94 | strcpy(*sNew,sSrc); 95 | } 96 | 97 | void FreeRAM() { 98 | 99 | UINT32 j; 100 | 101 | for (j=0;jparmList,"-wp","walk probability [default %s]","with probability PR, select a random variable from those~that appear in unsat clauses","",&iWp,0.10); 40 | 41 | CreateTrigger("PickHWSat",ChooseCandidate,PickHWSat,"",""); 42 | 43 | pCurAlg = CreateAlgorithm("hwsat","",TRUE, 44 | "HWSAT: HSAT with random walk (weighted)", 45 | "Gent, Walsh [Hybrid Problems... 95]", 46 | "PickHWSatW", 47 | "DefaultProceduresW,Flip+VarScoreW,VarLastChange,FalseClauseList", 48 | "default_w","default"); 49 | 50 | CopyParameters(pCurAlg,"hwsat","",FALSE); 51 | 52 | CreateTrigger("PickHWSatW",ChooseCandidate,PickHWSatW,"",""); 53 | 54 | } 55 | 56 | void PickHWSat() { 57 | UINT32 iClause; 58 | LITTYPE litPick; 59 | 60 | /* with probability (iWp) uniformly choose an unsatisfied clause, 61 | and then uniformly choose a literal from that clause */ 62 | 63 | if (RandomProb(iWp)) { 64 | if (iNumFalse) { 65 | iClause = aFalseList[RandomInt(iNumFalse)]; 66 | litPick = pClauseLits[iClause][RandomInt(aClauseLen[iClause])]; 67 | iFlipCandidate = GetVarFromLit(litPick); 68 | } else { 69 | iFlipCandidate = 0; 70 | } 71 | } else { 72 | 73 | /* otherwise, perform a regular HSAT step */ 74 | 75 | PickHSat(); 76 | } 77 | } 78 | 79 | void PickHWSatW() { 80 | UINT32 iClause; 81 | LITTYPE litPick; 82 | 83 | /* with probability (iWp) uniformly choose an unsatisfied clause, 84 | and then uniformly choose a literal from that clause */ 85 | 86 | if (RandomProb(iWp)) { 87 | if (iNumFalse) { 88 | iClause = aFalseList[RandomInt(iNumFalse)]; 89 | litPick = pClauseLits[iClause][RandomInt(aClauseLen[iClause])]; 90 | iFlipCandidate = GetVarFromLit(litPick); 91 | } else { 92 | iFlipCandidate = 0; 93 | } 94 | } else { 95 | 96 | /* otherwise, perform a regular HWSAT step */ 97 | 98 | PickHSatW(); 99 | } 100 | } 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /src/rgsat.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #include "ubcsat.h" 24 | 25 | void PickRGSat(); 26 | void PickRGSatW(); 27 | 28 | void AddRGSat() { 29 | 30 | ALGORITHM *pCurAlg; 31 | 32 | pCurAlg = CreateAlgorithm("rgsat","",FALSE, 33 | "RGSAT: Restarting GSAT (poor algorithm -- academic use only)", 34 | "Tompkins, Hoos [SAIM 04]", 35 | "PickRGSat", 36 | "DefaultProcedures,Flip+VarScore", 37 | "default","default"); 38 | 39 | CreateTrigger("PickRGSat",CheckRestart,PickRGSat,"",""); 40 | 41 | pCurAlg = CreateAlgorithm("rgsat","",TRUE, 42 | "RGSAT: Restarting GSAT (poor algorithm -- academic use only) (weighted)", 43 | "Tompkins, Hoos [SAIM 04]", 44 | "PickRGSatW", 45 | "DefaultProceduresW,Flip+VarScoreW", 46 | "default_w","default"); 47 | 48 | CreateTrigger("PickRGSatW",CheckRestart,PickRGSatW,"",""); 49 | 50 | } 51 | 52 | void PickRGSat() { 53 | 54 | UINT32 j; 55 | SINT32 iScore; 56 | 57 | iNumCandidates = 0; 58 | iBestScore = iNumClauses; 59 | 60 | /* Algorithm is essentially GSAT */ 61 | 62 | for (j=1;j<=iNumVars;j++) { 63 | iScore = aVarScore[j]; 64 | if (iScore <= iBestScore) { 65 | if (iScore < iBestScore) { 66 | iNumCandidates=0; 67 | iBestScore = iScore; 68 | } 69 | aCandidateList[iNumCandidates++] = j; 70 | } 71 | } 72 | 73 | /* If improving step possible, select flip candidate uniformly from candidate list */ 74 | 75 | if (iBestScore < 0) { 76 | if (iNumCandidates > 1) { 77 | iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)]; 78 | } else { 79 | iFlipCandidate = aCandidateList[0]; 80 | } 81 | } else { 82 | 83 | /* Otherwise, restart */ 84 | 85 | iFlipCandidate = 0; 86 | bRestart = TRUE; 87 | } 88 | } 89 | 90 | 91 | void PickRGSatW() { 92 | 93 | /* weighted varaint -- see regular algorithm for comments */ 94 | 95 | UINT32 j; 96 | FLOAT fScore; 97 | 98 | iNumCandidates = 0; 99 | fBestScore = fTotalWeight; 100 | for (j=1;j<=iNumVars;j++) { 101 | fScore = aVarScoreW[j]; 102 | if (fScore <= fBestScore) { 103 | if (fScore < fBestScore) { 104 | iNumCandidates=0; 105 | fBestScore = fScore; 106 | } 107 | aCandidateList[iNumCandidates++] = j; 108 | } 109 | } 110 | if (fBestScore < FLOATZERO) { 111 | if (iNumCandidates > 1) { 112 | iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)]; 113 | } else { 114 | iFlipCandidate = aCandidateList[0]; 115 | } 116 | } else { 117 | iFlipCandidate = 0; 118 | bRestart = TRUE; 119 | } 120 | } 121 | 122 | 123 | -------------------------------------------------------------------------------- /src/ubcsat.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #include "ubcsat.h" 24 | 25 | const char sVersion[] = "1.1.0 (Sea to Sky Release)"; 26 | 27 | int ubcsatmain(int argc, char *argv[]) { 28 | 29 | InitSeed(); 30 | 31 | SetupUBCSAT(); 32 | 33 | AddAlgorithms(); 34 | AddParameters(); 35 | AddReports(); 36 | AddDataTriggers(); 37 | AddReportTriggers(); 38 | 39 | AddLocal(); 40 | 41 | ParseAllParameters(argc,argv); 42 | 43 | ActivateAlgorithmTriggers(); 44 | ActivateReportTriggers(); 45 | 46 | RandomSeed(iSeed); 47 | 48 | RunProcedures(PostParameters); 49 | 50 | RunProcedures(ReadInInstance); 51 | 52 | RunProcedures(PostRead); 53 | 54 | RunProcedures(CreateData); 55 | RunProcedures(CreateStateInfo); 56 | 57 | iRun = 0; 58 | iNumSolutionsFound = 0; 59 | bTerminateAllRuns = FALSE; 60 | 61 | RunProcedures(PreStart); 62 | 63 | StartTotalClock(); 64 | 65 | while ((iRun < iNumRuns) && (! bTerminateAllRuns)) { 66 | 67 | iRun++; 68 | 69 | iStep = 0; 70 | bSolutionFound = FALSE; 71 | bTerminateRun = FALSE; 72 | bRestart = TRUE; 73 | 74 | RunProcedures(PreRun); 75 | 76 | StartRunClock(); 77 | 78 | while ((iStep < iCutoff) && (! bSolutionFound) && (! bTerminateRun)) { 79 | 80 | iStep++; 81 | iFlipCandidate = 0; 82 | 83 | RunProcedures(PreStep); 84 | RunProcedures(CheckRestart); 85 | 86 | if (bRestart) { 87 | RunProcedures(PreInit); 88 | RunProcedures(InitData); 89 | RunProcedures(InitStateInfo); 90 | RunProcedures(PostInit); 91 | bRestart = FALSE; 92 | } else { 93 | RunProcedures(ChooseCandidate); 94 | RunProcedures(PreFlip); 95 | RunProcedures(FlipCandidate); 96 | RunProcedures(UpdateStateInfo); 97 | RunProcedures(PostFlip); 98 | } 99 | 100 | RunProcedures(PostStep); 101 | 102 | RunProcedures(StepCalculations); 103 | 104 | RunProcedures(CheckTerminate); 105 | } 106 | 107 | StopRunClock(); 108 | 109 | RunProcedures(RunCalculations); 110 | 111 | RunProcedures(PostRun); 112 | 113 | if (bSolutionFound) { 114 | iNumSolutionsFound++; 115 | if (iNumSolutionsFound == iFind) { 116 | bTerminateAllRuns = TRUE; 117 | } 118 | } 119 | } 120 | 121 | StopTotalClock(); 122 | 123 | RunProcedures(FinalCalculations); 124 | 125 | RunProcedures(FinalReports); 126 | 127 | CleanExit(); 128 | 129 | return(0); 130 | 131 | } 132 | 133 | #ifndef ALTERNATEMAIN 134 | 135 | int main(int argc, char *argv[]) { 136 | return(ubcsatmain(argc,argv)); 137 | } 138 | 139 | #endif 140 | 141 | -------------------------------------------------------------------------------- /src/random.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #include "ubcsat.h" 24 | 25 | void PickURWalk(); 26 | void PickCRWalk(); 27 | void SchoeningRestart(); 28 | 29 | void AddRandom() { 30 | 31 | ALGORITHM *pCurAlg; 32 | 33 | pCurAlg = CreateAlgorithm("urwalk","",FALSE, 34 | "Uninformed Random Walk: flip any var at random", 35 | "", 36 | "PickURWalk", 37 | "DefaultProcedures", 38 | "default","default"); 39 | 40 | CreateTrigger("PickURWalk",ChooseCandidate,PickURWalk,"",""); 41 | 42 | pCurAlg = CreateAlgorithm("urwalk","",TRUE, 43 | "Uninformed Random Walk: flip any var at random (weighted)", 44 | "", 45 | "PickURWalk", 46 | "DefaultProceduresW", 47 | "default_w","default"); 48 | 49 | pCurAlg = CreateAlgorithm("crwalk","",FALSE, 50 | "Conflict-Directed Random Walk: choose unsat clause, then literal at random", 51 | "Papadimitriou [FOCS 91]", 52 | "PickCRWalk", 53 | "DefaultProcedures,Flip+FalseClauseList", 54 | "default","default"); 55 | 56 | CreateTrigger("PickCRWalk",ChooseCandidate,PickCRWalk,"",""); 57 | 58 | pCurAlg = CreateAlgorithm("crwalk","",TRUE, 59 | "Conflict-Directed Random Walk (weighted)", 60 | "Papadimitriou [FOCS 91]", 61 | "PickCRWalk", 62 | "DefaultProceduresW,Flip+FalseClauseListW", 63 | "default_w","default"); 64 | 65 | CreateTrigger("SchoeningRestart",CreateData,SchoeningRestart,"",""); 66 | 67 | pCurAlg = CreateAlgorithm("crwalk","schoening",FALSE, 68 | "Conflict-Directed Random Walk, restart every 3n steps", 69 | "Schoening [FOCS 99]", 70 | "PickCRWalk,SchoeningRestart", 71 | "DefaultProcedures,Flip+FalseClauseList", 72 | "default","default"); 73 | 74 | pCurAlg = CreateAlgorithm("crwalk","schoening",TRUE, 75 | "Conflict-Directed Random Walk, restart every 3n steps (weighted)", 76 | "Schoening [FOCS 99]", 77 | "PickCRWalk,SchoeningRestart", 78 | "DefaultProceduresW,Flip+FalseClauseListW", 79 | "default_w","default"); 80 | 81 | } 82 | 83 | 84 | void PickURWalk() { 85 | iFlipCandidate = RandomInt(iNumVars) + 1; 86 | } 87 | 88 | void PickCRWalk() { 89 | 90 | UINT32 iClause; 91 | UINT32 iClauseLen; 92 | 93 | LITTYPE litPick; 94 | 95 | if (iNumFalse) { 96 | iClause = aFalseList[RandomInt(iNumFalse)]; 97 | iClauseLen = aClauseLen[iClause]; 98 | litPick = (pClauseLits[iClause][RandomInt(iClauseLen)]); 99 | iFlipCandidate = GetVarFromLit(litPick); 100 | } 101 | } 102 | 103 | void SchoeningRestart() { 104 | 105 | if (iPeriodicRestart != 0) { 106 | ReportPrint(pRepErr,"Warning! Changing -prestart value to match Schoening's Algorithm\n"); 107 | } 108 | 109 | iPeriodicRestart = iNumVars * 3; 110 | 111 | } 112 | 113 | -------------------------------------------------------------------------------- /src/hsat.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #include "ubcsat.h" 24 | 25 | void PickHSat(); 26 | void PickHSatW(); 27 | 28 | void AddHSat() { 29 | 30 | ALGORITHM *pCurAlg; 31 | 32 | pCurAlg = CreateAlgorithm("hsat","",FALSE, 33 | "HSAT", 34 | "Gent, Walsh [AAAI 93]", 35 | "PickHSat", 36 | "DefaultProcedures,Flip+VarScore,VarLastChange", 37 | "default","default"); 38 | 39 | CreateTrigger("PickHSat",ChooseCandidate,PickHSat,"",""); 40 | 41 | pCurAlg = CreateAlgorithm("hsat","",TRUE, 42 | "HSAT (weighted)", 43 | "Gent, Walsh [AAAI 93]", 44 | "PickHSatW", 45 | "DefaultProceduresW,Flip+VarScoreW,VarLastChange", 46 | "default_w","default"); 47 | 48 | CreateTrigger("PickHSatW",ChooseCandidate,PickHSatW,"",""); 49 | 50 | } 51 | 52 | void PickHSat() { 53 | 54 | UINT32 j; 55 | SINT32 iScore; 56 | 57 | iNumCandidates = 0; 58 | iBestScore = iNumClauses; 59 | 60 | /* check score of all variables */ 61 | 62 | for (j=1;j<=iNumVars;j++) { 63 | 64 | /* use cached value of score */ 65 | 66 | iScore = aVarScore[j]; 67 | 68 | /* build candidate list of best vars */ 69 | 70 | if (iScore <= iBestScore) { 71 | 72 | /* if 2 variables are tied, and one is 'older' then choose older var */ 73 | 74 | if ((iScore < iBestScore)||(aVarLastChange[j] 1) { 86 | iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)]; 87 | } else { 88 | iFlipCandidate = aCandidateList[0]; 89 | } 90 | } 91 | 92 | void PickHSatW() { 93 | 94 | UINT32 j; 95 | FLOAT fScore; 96 | 97 | iNumCandidates = 0; 98 | fBestScore = fTotalWeight; 99 | 100 | /* check score of all variables */ 101 | 102 | for (j=1;j<=iNumVars;j++) { 103 | 104 | /* use cached value of weighted score */ 105 | 106 | fScore = aVarScoreW[j]; 107 | 108 | /* build candidate list of best vars */ 109 | 110 | if (fScore <= fBestScore) { 111 | 112 | /* if 2 variables are tied, and one is 'older' then choose older var */ 113 | 114 | if ((fScore < fBestScore)||(aVarLastChange[j] 1) { 126 | iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)]; 127 | } else { 128 | iFlipCandidate = aCandidateList[0]; 129 | } 130 | } 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /src/ubcsat-io.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | void RandomSeed(UINT32 iSeed); 24 | UINT32 RandomMax(); 25 | UINT32 RandomInt(UINT32 iMax); 26 | BOOL RandomProb(PROBABILITY); 27 | FLOAT RandomFloat(); 28 | 29 | FLOAT ProbToFloat(PROBABILITY iProb); 30 | PROBABILITY FloatToProb(FLOAT fProb); 31 | UINT32 ProbToInvInt(PROBABILITY iProb); 32 | 33 | void ActivateReportTriggers(); 34 | void AbnormalExit(); 35 | void CleanExit(); 36 | 37 | void CloseSingleFile(FILE *filToClose); 38 | 39 | void SetupFile(FILE **fFil,const char *sOpenType, const char *sFilename, FILE *filDefault, BOOL bAllowNull); 40 | 41 | extern UINT32 iNumRandomCalls; 42 | void SetupCountRandom(); 43 | void InitCountRandom(); 44 | 45 | void InitVarsFromFile(); 46 | 47 | extern FILE *filReportPrint; 48 | 49 | #define ReportPrint(pRep, sFormat) { filReportPrint = 0; if (pRep) filReportPrint = pRep->fileOut; if ((filReportPrint)&&(pRep->bActive)) fprintf(filReportPrint,sFormat); if ((bReportEcho) && (pRep->bActive) && (filReportPrint != stdout)) fprintf(stdout,sFormat); } 50 | #define ReportPrint1(pRep, sFormat, pVal1) { filReportPrint = 0; if (pRep) filReportPrint = pRep->fileOut; if ((filReportPrint)&&(pRep->bActive)) fprintf(filReportPrint,sFormat,pVal1); if ((bReportEcho) && (pRep->bActive) && (filReportPrint != stdout)) fprintf(stdout,sFormat,pVal1); } 51 | #define ReportPrint2(pRep, sFormat, pVal1, pVal2) { filReportPrint = 0; if (pRep) filReportPrint = pRep->fileOut; if ((filReportPrint)&&(pRep->bActive)) fprintf(filReportPrint,sFormat,pVal1,pVal2); if ((bReportEcho) && (pRep->bActive) && (filReportPrint != stdout)) fprintf(stdout,sFormat,pVal1,pVal2); } 52 | #define ReportPrint3(pRep, sFormat, pVal1, pVal2, pVal3) { filReportPrint = 0; if (pRep) filReportPrint = pRep->fileOut; if ((filReportPrint)&&(pRep->bActive)) fprintf(filReportPrint,sFormat,pVal1,pVal2,pVal3); if ((bReportEcho) && (pRep->bActive) && (filReportPrint != stdout)) fprintf(stdout,sFormat,pVal1,pVal2,pVal3); } 53 | 54 | 55 | #define ReportHdrPrefix(pRep) {if (!bReportClean) { filReportPrint = 0; if (pRep) filReportPrint = pRep->fileOut; if ((filReportPrint)&&(pRep->bActive)) fprintf(filReportPrint,"%s ",sCommentString); if ((bReportEcho) && (pRep->bActive) && (filReportPrint != stdout)) fprintf(stdout,"%s ",sCommentString); }} 56 | #define ReportHdrPrint(pRep, sFormat) { if (!bReportClean) { filReportPrint = 0; if (pRep) filReportPrint = pRep->fileOut; if ((filReportPrint)&&(pRep->bActive)) fprintf(filReportPrint,sFormat); if ((bReportEcho) && (pRep->bActive) && (filReportPrint != stdout)) fprintf(stdout,sFormat); }} 57 | #define ReportHdrPrint1(pRep, sFormat, pVal1) { if (!bReportClean) { filReportPrint = 0; if (pRep) filReportPrint = pRep->fileOut; if ((filReportPrint)&&(pRep->bActive)) fprintf(filReportPrint,sFormat,pVal1); if ((bReportEcho) && (pRep->bActive) && (filReportPrint != stdout)) fprintf(stdout,sFormat,pVal1); }} 58 | #define ReportHdrPrint2(pRep, sFormat, pVal1, pVal2) { if (!bReportClean) { filReportPrint = 0; if (pRep) filReportPrint = pRep->fileOut; if ((filReportPrint)&&(pRep->bActive)) fprintf(filReportPrint,sFormat,pVal1,pVal2); if ((bReportEcho) && (pRep->bActive) && (filReportPrint != stdout)) fprintf(stdout,sFormat,pVal1,pVal2); }} 59 | 60 | extern char *sFilenameRandomData; 61 | extern char *sFilenameAbort; 62 | void CreateFileRandom(); 63 | void CloseFileRandom(); 64 | void FileAbort(); 65 | 66 | 67 | -------------------------------------------------------------------------------- /src/gsat.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #include "ubcsat.h" 24 | 25 | void PickGSatSimple(); 26 | void PickGSatWithBSL(); 27 | void PickGSatW(); 28 | 29 | void AddGSat() { 30 | 31 | ALGORITHM *pCurAlg; 32 | 33 | pCurAlg = CreateAlgorithm("gsat","",FALSE, 34 | "GSAT: Greedy search for SAT", 35 | "Selman, Levesque, Mitchell [AAAI 93]", 36 | "PickGSatWithBSL", 37 | "DefaultProcedures,Flip+TrackChanges,BestScoreList", 38 | "default","default"); 39 | 40 | CreateTrigger("PickGSatWithBSL",ChooseCandidate,PickGSatWithBSL,"",""); 41 | 42 | pCurAlg = CreateAlgorithm("gsat","simple",FALSE, 43 | "GSAT: Greedy search for SAT (simple, but slower version)", 44 | "Selman, Levesque, Mitchell [AAAI 93]", 45 | "PickGSatSimple", 46 | "DefaultProcedures,Flip+VarScore", 47 | "default","default"); 48 | 49 | CreateTrigger("PickGSatSimple",ChooseCandidate,PickGSatSimple,"",""); 50 | 51 | pCurAlg = CreateAlgorithm("gsat","",TRUE, 52 | "GSAT: Greedy search for SAT (weighted)", 53 | "Selman, Levesque, Mitchell [AAAI 93]", 54 | "PickGSatW", 55 | "DefaultProceduresW,Flip+VarScoreW", 56 | "default_w","default"); 57 | 58 | CreateTrigger("PickGSatW",ChooseCandidate,PickGSatW,"",""); 59 | 60 | } 61 | 62 | 63 | void PickGSatSimple() { 64 | 65 | UINT32 j; 66 | SINT32 iScore; 67 | 68 | iNumCandidates = 0; 69 | iBestScore = iNumClauses; 70 | 71 | /* check score of all variables */ 72 | 73 | for (j=1;j<=iNumVars;j++) { 74 | 75 | /* use cached value of score */ 76 | 77 | iScore = aVarScore[j]; 78 | 79 | /* build candidate list of best vars */ 80 | 81 | if (iScore <= iBestScore) { 82 | if (iScore < iBestScore) { 83 | iNumCandidates=0; 84 | iBestScore = iScore; 85 | } 86 | aCandidateList[iNumCandidates++] = j; 87 | } 88 | } 89 | 90 | /* select flip candidate uniformly from candidate list */ 91 | 92 | if (iNumCandidates > 1) { 93 | iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)]; 94 | } else { 95 | iFlipCandidate = aCandidateList[0]; 96 | } 97 | } 98 | 99 | void PickGSatWithBSL() { 100 | 101 | /* this is a fancier 'prototype' gsat implementation, 102 | which caches a list of the 'best' variables at all times */ 103 | 104 | if (iNumBestScoreList > 1) { 105 | iFlipCandidate = aBestScoreList[RandomInt(iNumBestScoreList)]; 106 | } else { 107 | iFlipCandidate = aBestScoreList[0]; 108 | } 109 | } 110 | 111 | 112 | void PickGSatW() { 113 | 114 | UINT32 j; 115 | FLOAT fScore; 116 | 117 | iNumCandidates = 0; 118 | fBestScore = fTotalWeight; 119 | 120 | /* check score of all variables */ 121 | 122 | for (j=1;j<=iNumVars;j++) { 123 | 124 | /* use cached value of weighted score */ 125 | 126 | fScore = aVarScoreW[j]; 127 | 128 | /* build candidate list of best vars */ 129 | 130 | if (fScore <= fBestScore) { 131 | if (fScore < fBestScore) { 132 | iNumCandidates=0; 133 | fBestScore = fScore; 134 | } 135 | aCandidateList[iNumCandidates++] = j; 136 | } 137 | } 138 | 139 | /* select flip candidate uniformly from candidate list */ 140 | 141 | if (iNumCandidates > 1) { 142 | iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)]; 143 | } else { 144 | iFlipCandidate = aCandidateList[0]; 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /src/gsat-tabu.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #include "ubcsat.h" 24 | 25 | UINT32 iTabuTenure; 26 | 27 | void PickGSatTabu(); 28 | void PickGSatTabuW(); 29 | 30 | void AddGSatTabu() { 31 | 32 | ALGORITHM *pCurAlg; 33 | 34 | pCurAlg = CreateAlgorithm("gsat-tabu","",FALSE, 35 | "GSAT-TABU: GSAT with Tabu search", 36 | "Mazure, Sais, Gregoire [AAAI 97]", 37 | "PickGSatTabu", 38 | "DefaultProcedures,Flip+VarScore,VarLastChange", 39 | "default","default"); 40 | 41 | AddParmUInt(&pCurAlg->parmList,"-tabu","tabu tenure [default %s]","variables flipped within the last INT steps are tabu","",&iTabuTenure,10); 42 | 43 | CreateTrigger("PickGSatTabu",ChooseCandidate,PickGSatTabu,"",""); 44 | 45 | pCurAlg = CreateAlgorithm("gsat-tabu","",TRUE, 46 | "GSAT-TABU: GSAT with Tabu search (weighted)", 47 | "Mazure, Sais, Gregoire [AAAI 97]", 48 | "PickGSatTabuW", 49 | "DefaultProceduresW,Flip+VarScoreW,VarLastChange", 50 | "default_w","default"); 51 | 52 | CopyParameters(pCurAlg,"gsat-tabu","",FALSE); 53 | 54 | CreateTrigger("PickGSatTabuW",ChooseCandidate,PickGSatTabuW,"",""); 55 | 56 | } 57 | 58 | void PickGSatTabu() { 59 | 60 | UINT32 j; 61 | SINT32 iScore; 62 | UINT32 iTabuCutoff; 63 | 64 | /* calculation of tabu cutoff */ 65 | 66 | if (iStep > iTabuTenure) { 67 | iTabuCutoff = iStep - iTabuTenure; 68 | if (iVarLastChangeReset > iTabuCutoff) { 69 | iTabuCutoff = iVarLastChangeReset; 70 | } 71 | } else { 72 | iTabuCutoff = 1; 73 | } 74 | 75 | iNumCandidates = 0; 76 | iBestScore = iNumClauses; 77 | 78 | for (j=1;j<=iNumVars;j++) { 79 | 80 | /* check score of all non-tabu variables */ 81 | 82 | if (aVarLastChange[j] < iTabuCutoff) { 83 | 84 | /* use cached value of score */ 85 | 86 | iScore = aVarScore[j]; 87 | 88 | /* build candidate list of best vars */ 89 | 90 | if (iScore <= iBestScore) { 91 | if (iScore < iBestScore) { 92 | iNumCandidates=0; 93 | iBestScore = iScore; 94 | } 95 | aCandidateList[iNumCandidates++] = j; 96 | } 97 | } 98 | } 99 | 100 | /* select flip candidate uniformly from candidate list */ 101 | 102 | if (iNumCandidates > 1) { 103 | iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)]; 104 | } else { 105 | iFlipCandidate = aCandidateList[0]; 106 | } 107 | } 108 | 109 | void PickGSatTabuW() { 110 | 111 | UINT32 j; 112 | FLOAT fScore; 113 | UINT32 iTabuCutoff; 114 | 115 | /* calculation of tabu cutoff */ 116 | 117 | if (iStep > iTabuTenure) { 118 | iTabuCutoff = iStep - iTabuTenure; 119 | if (iVarLastChangeReset > iTabuCutoff) { 120 | iTabuCutoff = iVarLastChangeReset; 121 | } 122 | } else { 123 | iTabuCutoff = 1; 124 | } 125 | 126 | iNumCandidates = 0; 127 | fBestScore = fTotalWeight; 128 | 129 | for (j=1;j<=iNumVars;j++) { 130 | 131 | /* check score of all non-tabu variables */ 132 | 133 | if (aVarLastChange[j] < iTabuCutoff) { 134 | 135 | /* use cached value of weighted score */ 136 | 137 | fScore = aVarScoreW[j]; 138 | 139 | /* build candidate list of best vars */ 140 | 141 | if (fScore <= fBestScore) { 142 | if (fScore < fBestScore) { 143 | iNumCandidates=0; 144 | fBestScore = fScore; 145 | } 146 | aCandidateList[iNumCandidates++] = j; 147 | } 148 | } 149 | } 150 | 151 | /* select flip candidate uniformly from candidate list */ 152 | 153 | if (iNumCandidates > 1) { 154 | iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)]; 155 | } else { 156 | iFlipCandidate = aCandidateList[0]; 157 | } 158 | } 159 | 160 | -------------------------------------------------------------------------------- /src/gwsat.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #include "ubcsat.h" 24 | 25 | PROBABILITY iWp; 26 | 27 | void PickGWSat(); 28 | void PickGWSatW(); 29 | 30 | void AddGWSat() { 31 | 32 | ALGORITHM *pCurAlg; 33 | 34 | pCurAlg = CreateAlgorithm("gwsat","",FALSE, 35 | "GWSAT: GSAT with random walk", 36 | "Selman, Kautz [IJCAI 93]", 37 | "PickGWSat", 38 | "DefaultProcedures,Flip+VarInFalse", 39 | "default","default"); 40 | 41 | AddParmProbability(&pCurAlg->parmList,"-wp","walk probability [default %s]","with probability PR, select a random variable from those~that appear in unsat clauses","",&iWp,0.50); 42 | 43 | CreateTrigger("PickGWSat",ChooseCandidate,PickGWSat,"",""); 44 | 45 | pCurAlg = CreateAlgorithm("gwsat","",1, 46 | "GWSAT: GSAT with random walk (weighted)", 47 | "Selman, Kautz [IJCAI 93]", 48 | "PickGWSatW", 49 | "DefaultProceduresW,VarScoreW,VarInFalse", 50 | "default_w","default"); 51 | 52 | CopyParameters(pCurAlg,"gwsat","",FALSE); 53 | 54 | CreateTrigger("PickGWSatW",ChooseCandidate,PickGWSatW,"",""); 55 | 56 | 57 | } 58 | 59 | void PickGWSat() { 60 | UINT32 j; 61 | SINT32 iScore; 62 | 63 | /* with probability (iWp) uniformly choose a variable from all 64 | variables that appear in false clauses */ 65 | 66 | if (RandomProb(iWp)) { 67 | if (iNumVarsInFalseList) { 68 | iFlipCandidate = aVarInFalseList[RandomInt(iNumVarsInFalseList)]; 69 | } else { 70 | iFlipCandidate = 0; 71 | } 72 | 73 | } else { 74 | 75 | iNumCandidates = 0; 76 | iBestScore = iNumClauses; 77 | 78 | /* check score of all variables */ 79 | 80 | for (j=1;j<=iNumVars;j++) { 81 | 82 | /* Maintaing VarFalseList requires MakeCount[], 83 | so use makecount & breakcount to calculate score */ 84 | 85 | iScore = aBreakCount[j] - aMakeCount[j]; 86 | 87 | /* build candidate list of best vars */ 88 | 89 | if (iScore <= iBestScore) { 90 | if (iScore < iBestScore) { 91 | iNumCandidates=0; 92 | iBestScore = iScore; 93 | } 94 | aCandidateList[iNumCandidates++] = j; 95 | } 96 | } 97 | 98 | /* select flip candidate uniformly from candidate list */ 99 | 100 | if (iNumCandidates > 1) { 101 | iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)]; 102 | } else { 103 | iFlipCandidate = aCandidateList[0]; 104 | } 105 | } 106 | } 107 | 108 | void PickGWSatW() { 109 | UINT32 j; 110 | FLOAT fScore; 111 | 112 | /* with probability (iWp) uniformly choose a variable from all 113 | variables that appear in false clauses */ 114 | 115 | if (RandomProb(iWp)) { 116 | if (iNumVarsInFalseList) { 117 | iFlipCandidate = aVarInFalseList[RandomInt(iNumVarsInFalseList)]; 118 | } else { 119 | iFlipCandidate = 0; 120 | } 121 | } else { 122 | 123 | iNumCandidates = 0; 124 | fBestScore = fTotalWeight; 125 | 126 | /* check score of all variables */ 127 | 128 | for (j=1;j<=iNumVars;j++) { 129 | 130 | /* use cached value of weighted score */ 131 | 132 | fScore = aVarScoreW[j]; 133 | 134 | /* build candidate list of best vars */ 135 | 136 | if (fScore <= fBestScore) { 137 | if (fScore < fBestScore) { 138 | iNumCandidates=0; 139 | fBestScore = fScore; 140 | } 141 | aCandidateList[iNumCandidates++] = j; 142 | } 143 | } 144 | 145 | /* select flip candidate uniformly from candidate list */ 146 | 147 | if (iNumCandidates > 1) { 148 | iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)]; 149 | } else { 150 | iFlipCandidate = aCandidateList[0]; 151 | } 152 | } 153 | } 154 | 155 | -------------------------------------------------------------------------------- /src/adaptnovelty.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #include "ubcsat.h" 24 | 25 | UINT32 iInvPhi=5; /* = 1/phi */ 26 | UINT32 iInvTheta=6; /* = 1/theta */ 27 | 28 | FLOAT fAdaptPhi; 29 | FLOAT fAdaptTheta; 30 | 31 | UINT32 iLastAdaptStep; 32 | UINT32 iLastAdaptNumFalse; 33 | FLOAT fLastAdaptSumFalseW; 34 | 35 | void InitAdaptNoveltyNoise(); 36 | void AdaptNoveltyNoise(); 37 | void AdaptNoveltyNoiseAdjust(); 38 | void AdaptNoveltyNoiseW(); 39 | 40 | void AddAdaptNoveltyPlus() { 41 | 42 | ALGORITHM *pCurAlg; 43 | 44 | pCurAlg = CreateAlgorithm("adaptnovelty+","",FALSE, 45 | "Adaptive Novelty+: Novelty+ with adaptive noise", 46 | "Hoos [AAAI 02]", 47 | "PickNoveltyPlus", 48 | "DefaultProcedures,Flip+FalseClauseList,AdaptNoveltyNoise,VarLastChange", 49 | "default","default"); 50 | 51 | AddParmProbability(&pCurAlg->parmList,"-wp","walk probability [default %s]","with probability PR, select a random variable from a~randomly selected unsat clause","",&iWp,0.01); 52 | 53 | CreateTrigger("InitAdaptNoveltyNoise",PostInit,InitAdaptNoveltyNoise,"",""); 54 | CreateTrigger("AdaptNoveltyNoise",PostFlip,AdaptNoveltyNoise,"InitAdaptNoveltyNoise",""); 55 | 56 | pCurAlg = CreateAlgorithm("adaptnovelty+","params",FALSE, 57 | "Adaptive Novelty+ with changable adaptability parameters", 58 | "Hoos [AAAI 02]", 59 | "PickNoveltyPlus", 60 | "DefaultProcedures,Flip+FalseClauseList,AdaptNoveltyNoiseAdjust,VarLastChange", 61 | "default","default"); 62 | 63 | CopyParameters(pCurAlg,"adaptnovelty+","",FALSE); 64 | AddParmFloat(&pCurAlg->parmList,"-phi","adjustment parameter phi [default %s]","phi determines the rate of change of noise","",&fAdaptPhi,(1.0f/5.0f)); 65 | AddParmFloat(&pCurAlg->parmList,"-theta","adjustment parameter theta [default %s]","theta determines the stagnation detection","",&fAdaptTheta,(1.0f/6.0f)); 66 | CreateTrigger("AdaptNoveltyNoiseAdjust",PostFlip,AdaptNoveltyNoiseAdjust,"InitAdaptNoveltyNoise",""); 67 | 68 | pCurAlg = CreateAlgorithm("adaptnovelty+","",TRUE, 69 | "Adaptive Novelty+: Novelty+ with adaptive noise (weighted)", 70 | "Hoos [AAAI 02]", 71 | "PickNoveltyPlusW", 72 | "DefaultProceduresW,Flip+FalseClauseListW,AdaptNoveltyNoiseW,VarLastChange", 73 | "default_w","default"); 74 | 75 | CopyParameters(pCurAlg,"adaptnovelty+","",FALSE); 76 | 77 | CreateTrigger("AdaptNoveltyNoiseW",PostFlip,AdaptNoveltyNoiseW,"InitAdaptNoveltyNoise",""); 78 | 79 | } 80 | 81 | void InitAdaptNoveltyNoise() { 82 | iLastAdaptStep=iStep; 83 | iLastAdaptNumFalse=iNumFalse; 84 | fLastAdaptSumFalseW=fTotalWeight; 85 | iNovNoise = 0; 86 | } 87 | 88 | void AdaptNoveltyNoise() { 89 | 90 | if (iStep-iLastAdaptStep > iNumClauses/iInvTheta) { 91 | 92 | /* if no improvement in a while, increase noise */ 93 | 94 | iNovNoise += (PROBABILITY) ((UINT32MAX - iNovNoise)/iInvPhi); 95 | 96 | iLastAdaptStep = iStep; 97 | iLastAdaptNumFalse = iNumFalse; 98 | 99 | } else if (iNumFalse < iLastAdaptNumFalse) { 100 | 101 | /* if improving, then decrease noise */ 102 | /* note: this is how the original code was implemented: [wp := wp - wp * phi / 2] */ 103 | /* it was incorrectly listed in AAAI02 paper as [wp := wp - wp * 2 * phi] */ 104 | 105 | iNovNoise -= (PROBABILITY) (iNovNoise / iInvPhi / 2); 106 | 107 | iLastAdaptStep = iStep; 108 | iLastAdaptNumFalse = iNumFalse; 109 | } 110 | } 111 | 112 | void AdaptNoveltyNoiseAdjust() { 113 | 114 | /* this varaint allows for different values of Phi & Theta */ 115 | 116 | if (iStep-iLastAdaptStep > iNumClauses*fAdaptTheta) { 117 | iNovNoise += (PROBABILITY) ((UINT32MAX - iNovNoise)*fAdaptPhi); 118 | iLastAdaptStep = iStep; 119 | iLastAdaptNumFalse = iNumFalse; 120 | } else if (iNumFalse < iLastAdaptNumFalse) { 121 | iNovNoise -= (PROBABILITY) (iNovNoise * fAdaptPhi / 2); 122 | iLastAdaptStep = iStep; 123 | iLastAdaptNumFalse = iNumFalse; 124 | } 125 | } 126 | 127 | 128 | void AdaptNoveltyNoiseW() { 129 | 130 | /* weighted varaint -- see regular algorithm for comments */ 131 | 132 | if (iStep-iLastAdaptStep > iNumClauses/iInvTheta) { 133 | 134 | iNovNoise += (PROBABILITY) ((UINT32MAX - iNovNoise)/iInvPhi); 135 | iLastAdaptStep = iStep; 136 | fLastAdaptSumFalseW = fSumFalseW; 137 | 138 | } else if (fSumFalseW < fLastAdaptSumFalseW) { 139 | 140 | iNovNoise -= (PROBABILITY) (iNovNoise / iInvPhi / 2); 141 | 142 | iLastAdaptStep = iStep; 143 | fLastAdaptSumFalseW = fSumFalseW; 144 | } 145 | } 146 | 147 | -------------------------------------------------------------------------------- /src/ddfw.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #include "ubcsat.h" 24 | 25 | void SetupDDFW(); 26 | void DistributeDDFW(); 27 | 28 | UINT32 iDDFWInitWeight; 29 | PROBABILITY iDDFW_TL; 30 | 31 | void AddDDFW() { 32 | 33 | ALGORITHM *pCurAlg; 34 | 35 | pCurAlg = CreateAlgorithm("ddfw","",FALSE, 36 | "DDFW: Divide and Distribute Fixed Weights", 37 | "Ishtaiwi, Thornton, Sattar, Pham [CP 05]", 38 | "PickPAWS,DistributeDDFW,SetupDDFW", 39 | "DefaultProcedures,Flip+MBPINT+FCL+VIF", 40 | "default","default"); 41 | 42 | AddParmProbability(&pCurAlg->parmList,"-pflat","flat move probabilty [default %s]","when a local minimum is encountered,~take a 'flat' (sideways) step with probability PR","",&iPAWSFlatMove,0.15); 43 | AddParmProbability(&pCurAlg->parmList,"-tl","deterministically select neighbour [default %s]","select a random neighbour to distribute weight from with~probability (1-PR)","",&iDDFW_TL,0.99); 44 | AddParmUInt(&pCurAlg->parmList,"-winit","initial clause weights [default %s]","","",&iDDFWInitWeight,8); 45 | 46 | CreateTrigger("DistributeDDFW",PostFlip,DistributeDDFW,"",""); 47 | CreateTrigger("SetupDDFW",PreStart,SetupDDFW,"",""); 48 | 49 | } 50 | 51 | void SetupDDFW() { 52 | iInitPenaltyINT = iDDFWInitWeight; 53 | } 54 | 55 | void DistributeDDFW() { 56 | 57 | UINT32 j; 58 | UINT32 k; 59 | UINT32 m; 60 | 61 | UINT32 iCurrentClause; 62 | LITTYPE *pLit; 63 | 64 | UINT32 *pNeighbourClause; 65 | 66 | UINT32 iSourceClause = 0; 67 | UINT32 iSourceClausePenalty; 68 | 69 | UINT32 iPenaltyChange; 70 | 71 | BOOL bFoundClause; 72 | 73 | /* only perform distribution for null flips */ 74 | 75 | if (iFlipCandidate) { 76 | return; 77 | } 78 | 79 | /* for each false clause, distribute penalty from another clause */ 80 | 81 | for(j=0;j 0) { 101 | 102 | /* find the satisfied clause with highest weight */ 103 | 104 | if (aClausePenaltyINT[*pNeighbourClause] >= iSourceClausePenalty) { 105 | iSourceClause = *pNeighbourClause; 106 | iSourceClausePenalty = aClausePenaltyINT[iSourceClause]; 107 | bFoundClause = TRUE; 108 | } 109 | } 110 | pNeighbourClause++; 111 | } 112 | pLit++; 113 | } 114 | 115 | /* This is not mentioned in the DDFW paper, but was found in the original DDFW code from the authors */ 116 | 117 | /* with probability (1-iDDFW_TL), ignore the found clause and choose randomly */ 118 | 119 | if (bFoundClause) { 120 | if (!RandomProb(iDDFW_TL)) { 121 | bFoundClause = FALSE; 122 | } 123 | } 124 | 125 | /* if no clause has been found, keep randomly selecting a clause until 126 | a) it is satisfied, and 127 | b) it has increased weight 128 | */ 129 | 130 | while (!bFoundClause) { 131 | iSourceClause = RandomInt(iNumClauses); 132 | if (aNumTrueLit[iSourceClause] > 0) { 133 | if (aClausePenaltyINT[iSourceClause] >= iDDFWInitWeight) { 134 | iSourceClausePenalty = aClausePenaltyINT[iSourceClause]; 135 | bFoundClause = TRUE; 136 | } 137 | } 138 | } 139 | 140 | /* the amount of weight to transfer depends on the source clause weight */ 141 | 142 | if (iSourceClausePenalty > iDDFWInitWeight) { 143 | iPenaltyChange = 2; 144 | } else { 145 | iPenaltyChange = 1; 146 | } 147 | 148 | /* transfer the weight between the clauses */ 149 | 150 | aClausePenaltyINT[iCurrentClause] += iPenaltyChange; 151 | aClausePenaltyINT[iSourceClause] -= iPenaltyChange; 152 | 153 | /* For the current clause, the 'make' score for each variable has to be increased */ 154 | 155 | pLit = pClauseLits[iCurrentClause]; 156 | for (k=0;kparmList,"-tabu","target (median) tabu tenure [default %s]","","",&iTabuTenure,10); 45 | AddParmUInt(&pCurAlg->parmList,"-tabuinterval","interval size: percent of tabu tenure [default %s]","range of tabu tenure is: tt +/- tt * (INT/100)","",&iTabuTenureInterval,25); 46 | 47 | CreateTrigger("InitRoTS",PostParameters,InitRoTS,"",""); 48 | CreateTrigger("PickRoTS",ChooseCandidate,PickRoTS,"InitRoTS,VarLastChange,BestFalse",""); 49 | 50 | pCurAlg = CreateAlgorithm("rots","",1, 51 | "RoTS: Robust TABU Search (weighted)", 52 | "Taillard [Parallel Computing 1991], based on implementation by Stuetzle", 53 | "PickRoTSW", 54 | "DefaultProceduresW,Flip+VarScoreW", 55 | "default_w","default"); 56 | 57 | CopyParameters(pCurAlg,"rots","",FALSE); 58 | CreateTrigger("PickRoTSW",ChooseCandidate,PickRoTSW,"InitRoTS,VarLastChange,BestFalse",""); 59 | 60 | } 61 | 62 | void InitRoTS() { 63 | 64 | /* use the iTabuTenureInterval to set the low & high range for the tabu tenure */ 65 | 66 | iTabuTenureLow = iTabuTenure - (iTabuTenureInterval * iTabuTenure) / 100; 67 | iTabuTenureHigh = iTabuTenure + (iTabuTenureInterval * iTabuTenure) / 100; 68 | } 69 | 70 | void PickRoTS() { 71 | 72 | UINT32 j; 73 | SINT32 iScore; 74 | UINT32 iTabuCutoff; 75 | 76 | /* every N steps, choose the tabu tenure uniformly from the tabu range */ 77 | 78 | if (iTabuTenureLow != iTabuTenureHigh) { 79 | if ((iStep % iNumVars)==0) { 80 | iTabuTenure = iTabuTenureLow + RandomInt(iTabuTenureHigh - iTabuTenureLow); 81 | } 82 | } 83 | 84 | /* calculation of tabu cutoff */ 85 | 86 | if (iStep > iTabuTenure) { 87 | iTabuCutoff = iStep - iTabuTenure; 88 | if (iVarLastChangeReset > iTabuCutoff) { 89 | iTabuCutoff = iVarLastChangeReset; 90 | } 91 | } else { 92 | iTabuCutoff = 1; 93 | } 94 | 95 | iNumCandidates = 0; 96 | iBestScore = iNumClauses; 97 | 98 | /* check all variables */ 99 | 100 | for (j=1;j<=iNumVars;j++) { 101 | 102 | /* use cached value of score */ 103 | 104 | iScore = aVarScore[j]; 105 | 106 | if (aVarLastChange[j] >= iTabuCutoff) { 107 | 108 | /* check for aspiration (early exit) */ 109 | 110 | if ((iNumFalse + iScore) < iBestNumFalse) { 111 | iFlipCandidate = j; 112 | return; 113 | } 114 | 115 | } else if ((iStep - aVarLastChange[j]) > (iNumVars * 10)) { 116 | 117 | /* check for variable stagnation (early exit) */ 118 | 119 | iFlipCandidate = j; 120 | return; 121 | 122 | } else { 123 | 124 | /* build candidate list of best vars */ 125 | 126 | if (iScore <= iBestScore) { 127 | if (iScore < iBestScore) { 128 | iNumCandidates=0; 129 | iBestScore = iScore; 130 | } 131 | aCandidateList[iNumCandidates++] = j; 132 | } 133 | } 134 | } 135 | 136 | /* select flip candidate uniformly from candidate list */ 137 | 138 | if (iNumCandidates > 1) { 139 | iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)]; 140 | } else { 141 | iFlipCandidate = aCandidateList[0]; 142 | } 143 | 144 | } 145 | 146 | void PickRoTSW() { 147 | 148 | /* weighted varaint -- see regular algorithm for comments */ 149 | 150 | UINT32 j; 151 | FLOAT fScore; 152 | UINT32 iTabuCutoff; 153 | 154 | if (iTabuTenureLow != iTabuTenureHigh) { 155 | if ((iStep % iNumVars)==0) { 156 | iTabuTenure = iTabuTenureLow + RandomInt(iTabuTenureHigh - iTabuTenureLow); 157 | } 158 | } 159 | if (iStep > iTabuTenure) { 160 | iTabuCutoff = iStep - iTabuTenure; 161 | if (iVarLastChangeReset > iTabuCutoff) { 162 | iTabuCutoff = iVarLastChangeReset; 163 | } 164 | } else { 165 | iTabuCutoff = 1; 166 | } 167 | iNumCandidates = 0; 168 | fBestScore = fTotalWeight; 169 | for (j=1;j<=iNumVars;j++) { 170 | fScore = aVarScoreW[j]; 171 | if (aVarLastChange[j] >= iTabuCutoff) { 172 | if ((fSumFalseW + fScore) < fBestSumFalseW) { 173 | iFlipCandidate = j; 174 | return; 175 | } 176 | } else if ((iStep - aVarLastChange[j]) > (iNumVars * 10)) { 177 | iFlipCandidate = j; 178 | return; 179 | } else { 180 | if (fScore <= fBestScore) { 181 | if (fScore < fBestScore) { 182 | iNumCandidates=0; 183 | fBestScore = fScore; 184 | } 185 | aCandidateList[iNumCandidates++] = j; 186 | } 187 | } 188 | } 189 | if (iNumCandidates > 1) { 190 | iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)]; 191 | } else { 192 | iFlipCandidate = aCandidateList[0]; 193 | } 194 | } 195 | 196 | -------------------------------------------------------------------------------- /src/ubcsat-internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | 24 | #define NOFXN 0 25 | #define NOREF(A) (A)=(A) 26 | 27 | #define RunProcedures(A) {if (aNumActiveProcedures[A]) {for (iRunProceduresLoop=0;iRunProceduresLoop>3])>>(7 - ((B)&0x07)))&0x01) 151 | VARSTATE NewVarState(); 152 | VARSTATE NewCopyVarState(VARSTATE vsCopy); 153 | void SetCurVarState(VARSTATE vsIn); 154 | BOOL SetCurVarStateString(VARSTATE vsIn, char *sVarState); 155 | void SetArrayFromVarState(UINT32 *aOut, VARSTATE vsIn); 156 | UINT32 HammingDistVarState(VARSTATE vsA, VARSTATE vsB); 157 | BOOL IsVarStateEqual(VARSTATE vsA, VARSTATE vsB); 158 | BOOL IsVarStateInList(VARSTATELIST *vsList, VARSTATE vsIn); 159 | UINT32 MinHammingVarStateList(VARSTATELIST *vsList, VARSTATE vsIn); 160 | void AddToVarStateList(VARSTATELIST *vsList, VARSTATE vsAdd); 161 | BOOL AddUniqueToVarStateList(VARSTATELIST *vsList, VARSTATE vsAdd); 162 | 163 | -------------------------------------------------------------------------------- /src/walksat.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #include "ubcsat.h" 24 | 25 | void PickWalkSatSKC(); 26 | void PickWalkSatSKCW(); 27 | 28 | void AddWalkSat() { 29 | 30 | ALGORITHM *pCurAlg; 31 | 32 | pCurAlg = CreateAlgorithm("walksat","",FALSE, 33 | "WALKSAT: Original WalkSAT algorithm (SKC variant)", 34 | "Selman, Kautz, Cohen [AAAI 94]", 35 | "PickWalkSatSKC", 36 | "DefaultProcedures,Flip+FalseClauseList", 37 | "default","default"); 38 | 39 | AddParmProbability(&pCurAlg->parmList,"-wp","walk probability [default %s]","with probability PR, select a random variable from a~randomly selected unsat clause","",&iWp,0.50); 40 | 41 | CreateTrigger("PickWalkSatSKC",ChooseCandidate,PickWalkSatSKC,"",""); 42 | 43 | 44 | pCurAlg = CreateAlgorithm("walksat","",TRUE, 45 | "WALKSAT: Original WalkSAT algorithm (SKC variant) (weighted)", 46 | "Selman, Kautz, Cohen [AAAI 94]", 47 | "PickWalkSatSKCW", 48 | "DefaultProceduresW,Flip+FalseClauseListW", 49 | "default_w","default"); 50 | 51 | CopyParameters(pCurAlg,"walksat","",FALSE); 52 | 53 | CreateTrigger("PickWalkSatSKCW",ChooseCandidate,PickWalkSatSKCW,"",""); 54 | 55 | } 56 | 57 | void PickWalkSatSKC() { 58 | 59 | UINT32 i; 60 | UINT32 j; 61 | SINT32 iScore; 62 | UINT32 iClause; 63 | UINT32 iClauseLen; 64 | UINT32 iVar; 65 | LITTYPE *pLit; 66 | UINT32 *pClause; 67 | LITTYPE litPick; 68 | UINT32 iNumOcc; 69 | 70 | iNumCandidates = 0; 71 | iBestScore = iNumClauses; 72 | 73 | /* select an unsatisfied clause uniformly at random */ 74 | 75 | if (iNumFalse) { 76 | iClause = aFalseList[RandomInt(iNumFalse)]; 77 | iClauseLen = aClauseLen[iClause]; 78 | } else { 79 | iFlipCandidate = 0; 80 | return; 81 | } 82 | 83 | pLit = pClauseLits[iClause]; 84 | 85 | for (j=0;j 0) { 123 | if (RandomProb(iWp)) { 124 | litPick = pClauseLits[iClause][RandomInt(iClauseLen)]; 125 | iFlipCandidate = GetVarFromLit(litPick); 126 | return; 127 | } 128 | } 129 | 130 | /* select flip candidate uniformly from candidate list */ 131 | 132 | if (iNumCandidates > 1) { 133 | iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)]; 134 | } else { 135 | iFlipCandidate = aCandidateList[0]; 136 | } 137 | } 138 | 139 | 140 | 141 | UINT32 PickClauseWCS() { 142 | 143 | /* this routine randomly selects a weighted clause so that 144 | clauses with larger weights are more likely to be selected 145 | ('roulette' selection) */ 146 | 147 | UINT32 j; 148 | FLOAT fRandClause; 149 | FLOAT fClauseSum; 150 | UINT32 iClause = 0; 151 | 152 | fRandClause = RandomFloat() * fSumFalseW; 153 | 154 | fClauseSum = FLOATZERO; 155 | 156 | for (j=0;j FLOATZERO) { 217 | if (RandomProb(iWp)) { 218 | litPick = pClauseLits[iClause][RandomInt(iClauseLen)]; 219 | iFlipCandidate = GetVarFromLit(litPick); 220 | return; 221 | } 222 | } 223 | if (iNumCandidates > 1) { 224 | iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)]; 225 | } else { 226 | iFlipCandidate = aCandidateList[0]; 227 | } 228 | } 229 | 230 | -------------------------------------------------------------------------------- /src/rnovelty.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #include "ubcsat.h" 24 | 25 | void PickRNovelty(); 26 | void PickRNoveltyPlus(); 27 | 28 | void AddRNovelty() { 29 | 30 | ALGORITHM *pCurAlg; 31 | 32 | pCurAlg = CreateAlgorithm("rnovelty","",FALSE, 33 | "RNovelty", 34 | "McAllester, Selman, Kautz [AAAI 97]", 35 | "PickRNovelty", 36 | "DefaultProcedures,Flip+FalseClauseList,VarLastChange", 37 | "default","default"); 38 | 39 | CopyParameters(pCurAlg,"novelty","",FALSE); 40 | 41 | CreateTrigger("PickRNovelty",ChooseCandidate,PickRNovelty,"",""); 42 | 43 | } 44 | 45 | void AddRNoveltyPlus() { 46 | 47 | ALGORITHM *pCurAlg; 48 | 49 | pCurAlg = CreateAlgorithm("rnovelty+","",FALSE, 50 | "RNovelty+: RNovelty with random walk", 51 | "Hoos [AAAI 99]", 52 | "PickRNoveltyPlus", 53 | "DefaultProcedures,Flip+FalseClauseList,VarLastChange", 54 | "default","default"); 55 | 56 | CopyParameters(pCurAlg,"novelty+","",FALSE); 57 | 58 | CreateTrigger("PickRNoveltyPlus",ChooseCandidate,PickRNoveltyPlus,"",""); 59 | 60 | } 61 | 62 | 63 | void PickRNoveltyCore() { 64 | 65 | /* see the Novelty() code for general comments */ 66 | 67 | UINT32 i; 68 | UINT32 j; 69 | SINT32 iScore; 70 | UINT32 iClause; 71 | UINT32 iClauseLen; 72 | LITTYPE *pLit; 73 | UINT32 *pClause; 74 | 75 | UINT32 iNumOcc; 76 | UINT32 iVar; 77 | 78 | UINT32 iYoungestVar; 79 | 80 | SINT32 iSecondBestScore; 81 | SINT32 iScoreMargin; 82 | 83 | UINT32 iBestVar=0; 84 | UINT32 iSecondBestVar=0; 85 | 86 | iBestScore = iNumClauses; 87 | iSecondBestScore = iNumClauses; 88 | 89 | if (iNumFalse) { 90 | iClause = aFalseList[RandomInt(iNumFalse)]; 91 | iClauseLen = aClauseLen[iClause]; 92 | } else { 93 | iFlipCandidate = 0; 94 | return; 95 | } 96 | 97 | pLit = pClauseLits[iClause]; 98 | iYoungestVar = GetVarFromLit(*pLit); 99 | for (j=0;j aVarLastChange[iYoungestVar]) { 119 | iYoungestVar = iVar; 120 | } 121 | if ((iScore < iBestScore) || ((iScore == iBestScore) && (aVarLastChange[iVar] < aVarLastChange[iBestVar]))) { 122 | iSecondBestVar = iBestVar; 123 | iBestVar = iVar; 124 | iSecondBestScore = iBestScore; 125 | iBestScore = iScore; 126 | } else if ((iScore < iSecondBestScore) || ((iScore == iSecondBestScore) && (aVarLastChange[iVar] < aVarLastChange[iSecondBestVar]))) { 127 | iSecondBestVar = iVar; 128 | iSecondBestScore = iScore; 129 | } 130 | pLit++; 131 | } 132 | 133 | iFlipCandidate = iBestVar; 134 | 135 | /* if the best is the youngest, select it */ 136 | 137 | if (iFlipCandidate != iYoungestVar) { 138 | return; 139 | } 140 | 141 | /* otherwise, calculate difference between 'best' and 'second best' */ 142 | 143 | iScoreMargin = iSecondBestScore - iBestScore; 144 | 145 | /* if novnoise < 0.5 always choose best if the margin is > 1, 146 | and choose the second best with noise (novnoise * 2) if margin is 1 */ 147 | 148 | if ((iNovNoise < 0x7FFFFFFF)) { 149 | if (iScoreMargin > 1) { 150 | return; 151 | } 152 | if (iScoreMargin == 1) { 153 | if (RandomProb(iNovNoise << 1)) { 154 | iFlipCandidate = iSecondBestVar; 155 | } 156 | return; 157 | } 158 | } 159 | 160 | /* if novnoise >= 0.5 always choose second best if the margin is = 1, 161 | and choose the second best with noise (1 - novnoise) * 2 if margin is > 1 */ 162 | 163 | if (iScoreMargin == 1) { 164 | iFlipCandidate = iSecondBestVar; 165 | return; 166 | } 167 | 168 | if (RandomProb(((iNovNoise - 0x7FFFFFFF)<<1))) { 169 | iFlipCandidate = iSecondBestVar; 170 | } 171 | } 172 | 173 | void PickRNovelty() 174 | { 175 | 176 | UINT32 iClause; 177 | UINT32 iClauseLen; 178 | LITTYPE litPick; 179 | 180 | /* every 100 steps uniformly choose an unsatisfied clause, 181 | and then uniformly choose a literal from that clause */ 182 | 183 | if ((iStep % 100) == 0) { 184 | if (iNumFalse) { 185 | iClause = aFalseList[RandomInt(iNumFalse)]; 186 | iClauseLen = aClauseLen[iClause]; 187 | litPick = (pClauseLits[iClause][RandomInt(iClauseLen)]); 188 | iFlipCandidate = GetVarFromLit(litPick); 189 | } else { 190 | iFlipCandidate = 0; 191 | } 192 | return; 193 | } 194 | 195 | /* otherwise, perform a regular RNovelty step */ 196 | 197 | PickRNoveltyCore(); 198 | } 199 | 200 | 201 | void PickRNoveltyPlus() 202 | { 203 | 204 | UINT32 iClause; 205 | UINT32 iClauseLen; 206 | LITTYPE litPick; 207 | 208 | /* with probability (iWp) uniformly choose an unsatisfied clause, 209 | and then uniformly choose a literal from that clause */ 210 | 211 | if (RandomProb(iWp)) { 212 | if (iNumFalse) { 213 | iClause = aFalseList[RandomInt(iNumFalse)]; 214 | iClauseLen = aClauseLen[iClause]; 215 | litPick = (pClauseLits[iClause][RandomInt(iClauseLen)]); 216 | iFlipCandidate = GetVarFromLit(litPick); 217 | } else { 218 | iFlipCandidate = 0; 219 | } 220 | return; 221 | } 222 | 223 | /* otherwise, perform a regular RNovelty step */ 224 | 225 | PickRNoveltyCore(); 226 | 227 | } 228 | 229 | -------------------------------------------------------------------------------- /src/walksat-tabu.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #include "ubcsat.h" 24 | 25 | void PickWalkSatTabu(); 26 | void PickWalkSatTabuW(); 27 | void PickWalkSatTabuNoNull(); 28 | 29 | void AddWalkSatTabu() { 30 | 31 | ALGORITHM *pCurAlg; 32 | 33 | pCurAlg = CreateAlgorithm("walksat-tabu","",FALSE, 34 | "WALKSAT-TABU: WalkSAT with TABU search", 35 | "McAllester, Selman, Kautz [AAAI 97]", 36 | "PickWalkSatTabu", 37 | "DefaultProcedures,Flip+FalseClauseList,VarLastChange", 38 | "default","default"); 39 | 40 | AddParmUInt(&pCurAlg->parmList,"-tabu","tabu tenure [default %s]","variables flipped within the last INT steps are tabu","",&iTabuTenure,10); 41 | 42 | CreateTrigger("PickWalkSatTabu",ChooseCandidate,PickWalkSatTabu,"",""); 43 | 44 | 45 | pCurAlg = CreateAlgorithm("walksat-tabu","",TRUE, 46 | "WALKSAT-TABU: WalkSAT with TABU search (weighted)", 47 | "McAllester, Selman, Kautz [AAAI 97]", 48 | "PickWalkSatTabuW", 49 | "DefaultProceduresW,Flip+FalseClauseListW,VarLastChange", 50 | "default_w","default"); 51 | 52 | CopyParameters(pCurAlg,"walksat-tabu","",FALSE); 53 | 54 | CreateTrigger("PickWalkSatTabuW",ChooseCandidate,PickWalkSatTabuW,"",""); 55 | 56 | } 57 | 58 | UINT32 iWalkSATTabuClause; 59 | 60 | void PickWalkSatTabu() 61 | { 62 | 63 | UINT32 i; 64 | UINT32 j; 65 | SINT32 iScore; 66 | UINT32 iClauseLen; 67 | LITTYPE *pLit; 68 | UINT32 *pClause; 69 | UINT32 iNumOcc; 70 | UINT32 iVar; 71 | 72 | UINT32 iTabuCutoff; 73 | 74 | iNumCandidates = 0; 75 | iBestScore = iNumClauses; 76 | 77 | /* calculation of tabu cutoff */ 78 | 79 | if (iStep > iTabuTenure) { 80 | iTabuCutoff = iStep - iTabuTenure; 81 | if (iVarLastChangeReset > iTabuCutoff) { 82 | iTabuCutoff = iVarLastChangeReset; 83 | } 84 | } else { 85 | iTabuCutoff = 1; 86 | } 87 | 88 | /* select an unsatisfied clause uniformly at random */ 89 | 90 | iWalkSATTabuClause = aFalseList[RandomInt(iNumFalse)]; 91 | iClauseLen = aClauseLen[iWalkSATTabuClause]; 92 | 93 | pLit = pClauseLits[iWalkSATTabuClause]; 94 | 95 | for (j=0;j 1) { 143 | iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)]; 144 | } else { 145 | iFlipCandidate = aCandidateList[0]; 146 | } 147 | 148 | } 149 | 150 | void PickWalkSatTabuW() 151 | { 152 | 153 | UINT32 i; 154 | UINT32 j; 155 | FLOAT fScore; 156 | UINT32 iClauseLen; 157 | LITTYPE *pLit; 158 | UINT32 *pClause; 159 | UINT32 iNumOcc; 160 | UINT32 iVar; 161 | 162 | UINT32 iTabuCutoff; 163 | 164 | iNumCandidates = 0; 165 | fBestScore = fTotalWeight; 166 | 167 | /* calculation of tabu cutoff */ 168 | 169 | if (iStep > iTabuTenure) { 170 | iTabuCutoff = iStep - iTabuTenure; 171 | if (iVarLastChangeReset > iTabuCutoff) { 172 | iTabuCutoff = iVarLastChangeReset; 173 | } 174 | } else { 175 | iTabuCutoff = 1; 176 | } 177 | 178 | /* select the clause according to a weighted scheme */ 179 | 180 | iWalkSATTabuClause = PickClauseWCS(); 181 | iClauseLen = aClauseLen[iWalkSATTabuClause]; 182 | 183 | pLit = pClauseLits[iWalkSATTabuClause]; 184 | 185 | for (j=0;j 1) { 234 | iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)]; 235 | } else { 236 | iFlipCandidate = aCandidateList[0]; 237 | } 238 | } 239 | 240 | -------------------------------------------------------------------------------- /src/mt19937ar.c: -------------------------------------------------------------------------------- 1 | /* 2 | A C-program for MT19937, with initialization improved 2002/1/26. 3 | Coded by Takuji Nishimura and Makoto Matsumoto. 4 | 5 | Before using, initialize the state by using init_genrand(seed) 6 | or init_by_array(init_key, key_length). 7 | 8 | Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, 9 | All rights reserved. 10 | 11 | Redistribution and use in source and binary forms, with or without 12 | modification, are permitted provided that the following conditions 13 | are met: 14 | 15 | 1. Redistributions of source code must retain the above copyright 16 | notice, this list of conditions and the following disclaimer. 17 | 18 | 2. Redistributions in binary form must reproduce the above copyright 19 | notice, this list of conditions and the following disclaimer in the 20 | documentation and/or other materials provided with the distribution. 21 | 22 | 3. The names of its contributors may not be used to endorse or promote 23 | products derived from this software without specific prior written 24 | permission. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 30 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 31 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 32 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 33 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 34 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 35 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 36 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | 38 | 39 | Any feedback is very welcome. 40 | http://www.math.keio.ac.jp/matumoto/emt.html 41 | email: matumoto@math.keio.ac.jp 42 | */ 43 | 44 | #include 45 | 46 | /* Period parameters */ 47 | #define N 624 48 | #define M 397 49 | #define MATRIX_A 0x9908b0dfUL /* constant vector a */ 50 | #define UPPER_MASK 0x80000000UL /* most significant w-r bits */ 51 | #define LOWER_MASK 0x7fffffffUL /* least significant r bits */ 52 | 53 | static unsigned long mt[N]; /* the array for the state vector */ 54 | static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */ 55 | 56 | /* initializes mt[N] with a seed */ 57 | void init_genrand(unsigned long s) 58 | { 59 | mt[0]= s & 0xffffffffUL; 60 | for (mti=1; mti> 30)) + mti); 63 | /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */ 64 | /* In the previous versions, MSBs of the seed affect */ 65 | /* only MSBs of the array mt[]. */ 66 | /* 2002/01/09 modified by Makoto Matsumoto */ 67 | mt[mti] &= 0xffffffffUL; 68 | /* for >32 bit machines */ 69 | } 70 | } 71 | 72 | #ifdef INITBYARRAY 73 | /* initialize by an array with array-length */ 74 | /* init_key is the array for initializing keys */ 75 | /* key_length is its length */ 76 | void init_by_array(init_key, key_length) 77 | unsigned long init_key[], key_length; 78 | { 79 | int i, j, k; 80 | init_genrand(19650218UL); 81 | i=1; j=0; 82 | k = (N>key_length ? N : key_length); 83 | for (; k; k--) { 84 | mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL)) 85 | + init_key[j] + j; /* non linear */ 86 | mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */ 87 | i++; j++; 88 | if (i>=N) { mt[0] = mt[N-1]; i=1; } 89 | if (j>=key_length) j=0; 90 | } 91 | for (k=N-1; k; k--) { 92 | mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL)) 93 | - i; /* non linear */ 94 | mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */ 95 | i++; 96 | if (i>=N) { mt[0] = mt[N-1]; i=1; } 97 | } 98 | 99 | mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */ 100 | } 101 | #endif 102 | 103 | /* generates a random number on [0,0xffffffff]-interval */ 104 | unsigned long genrand_int32(void) 105 | { 106 | unsigned long y; 107 | static unsigned long mag01[2]={0x0UL, MATRIX_A}; 108 | /* mag01[x] = x * MATRIX_A for x=0,1 */ 109 | 110 | if (mti >= N) { /* generate N words at one time */ 111 | int kk; 112 | 113 | if (mti == N+1) /* if init_genrand() has not been called, */ 114 | init_genrand(5489UL); /* a default initial seed is used */ 115 | 116 | for (kk=0;kk> 1) ^ mag01[y & 0x1UL]; 119 | } 120 | for (;kk> 1) ^ mag01[y & 0x1UL]; 123 | } 124 | y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK); 125 | mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL]; 126 | 127 | mti = 0; 128 | } 129 | 130 | y = mt[mti++]; 131 | 132 | /* Tempering */ 133 | y ^= (y >> 11); 134 | y ^= (y << 7) & 0x9d2c5680UL; 135 | y ^= (y << 15) & 0xefc60000UL; 136 | y ^= (y >> 18); 137 | 138 | return y; 139 | } 140 | 141 | /* generates a random number on [0,0x7fffffff]-interval */ 142 | long genrand_int31(void) 143 | { 144 | return (long)(genrand_int32()>>1); 145 | } 146 | 147 | /* generates a random number on [0,1]-real-interval */ 148 | double genrand_real1(void) 149 | { 150 | return genrand_int32()*(1.0/4294967295.0); 151 | /* divided by 2^32-1 */ 152 | } 153 | 154 | /* generates a random number on [0,1)-real-interval */ 155 | double genrand_real2(void) 156 | { 157 | return genrand_int32()*(1.0/4294967296.0); 158 | /* divided by 2^32 */ 159 | } 160 | 161 | /* generates a random number on (0,1)-real-interval */ 162 | double genrand_real3(void) 163 | { 164 | return (((double)genrand_int32()) + 0.5)*(1.0/4294967296.0); 165 | /* divided by 2^32 */ 166 | } 167 | 168 | /* generates a random number on [0,1) with 53-bit resolution*/ 169 | double genrand_res53(void) 170 | { 171 | unsigned long a=genrand_int32()>>5, b=genrand_int32()>>6; 172 | return(a*67108864.0+b)*(1.0/9007199254740992.0); 173 | } 174 | /* These real versions are due to Isaku Wada, 2002/01/09 added */ 175 | 176 | /* 177 | int main(void) 178 | { 179 | int i; 180 | unsigned long init[4]={0x123, 0x234, 0x345, 0x456}, length=4; 181 | init_by_array(init, length); 182 | printf("1000 outputs of genrand_int32()\n"); 183 | for (i=0; i<1000; i++) { 184 | printf("%10lu ", genrand_int32()); 185 | if (i%5==4) printf("\n"); 186 | } 187 | printf("\n1000 outputs of genrand_real2()\n"); 188 | for (i=0; i<1000; i++) { 189 | printf("%10.8f ", genrand_real2()); 190 | if (i%5==4) printf("\n"); 191 | } 192 | return 0; 193 | } 194 | */ 195 | -------------------------------------------------------------------------------- /src/ubcsat-io.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #include "ubcsat.h" 24 | 25 | /* 26 | This file contains some of the i/o routines for 27 | file access and random number generators 28 | */ 29 | 30 | #define MERSENNE 31 | 32 | #ifdef MERSENNE 33 | extern unsigned long genrand_int32(); 34 | extern void init_genrand(unsigned long s); 35 | 36 | FXNRAND32 fxnRandUInt32 = genrand_int32; 37 | #define fxnRandSeed(A) init_genrand(A) 38 | #else 39 | #ifdef WIN32 40 | FXNRAND32 fxnRandUInt32 = (UINT32 (*)()) rand; 41 | #define fxnRandSeed(A) srand(A) 42 | #else 43 | FXNRAND32 fxnRandUInt32 = (UINT32 (*)()) random; 44 | #define fxnRandSeed(A) srandom(A) 45 | #endif 46 | #endif 47 | 48 | FLOAT ProbToFloat(PROBABILITY iProb) { 49 | return (iProb*(1.0/4294967295.0)); 50 | } 51 | 52 | PROBABILITY FloatToProb(FLOAT fProb) { 53 | return ((PROBABILITY) (fProb * 4294967295.0)); 54 | } 55 | 56 | UINT32 ProbToInvInt(PROBABILITY iProb) { 57 | FLOAT fInv; 58 | fInv = 4294967295.0 / iProb; 59 | return ((UINT32) (fInv + 0.5)); 60 | } 61 | 62 | FLOAT RandomFloat() { 63 | UINT32 iNum; 64 | FLOAT fNum; 65 | iNum = fxnRandUInt32(); 66 | fNum = (FLOAT) iNum; 67 | fNum /= 4294967295.0; 68 | return(fNum); 69 | } 70 | 71 | UINT32 RandomInt(UINT32 iMax) { 72 | return(fxnRandUInt32() % iMax); 73 | } 74 | 75 | BOOL RandomProb(PROBABILITY iProb) { 76 | if (iProb==0) { 77 | return(FALSE); 78 | } 79 | if (fxnRandUInt32() <= iProb) { 80 | return(TRUE); 81 | } else { 82 | return(FALSE); 83 | } 84 | } 85 | 86 | UINT32 RandomMax() { 87 | return(fxnRandUInt32()); 88 | } 89 | 90 | void RandomSeed(UINT32 iSeed) { 91 | fxnRandSeed(iSeed); 92 | } 93 | 94 | UINT32 iNumRandomCalls; 95 | FXNRAND32 fxnRandOrig; 96 | 97 | UINT32 CountRandom() { 98 | iNumRandomCalls++; 99 | return(fxnRandOrig()); 100 | } 101 | 102 | void SetupCountRandom() { 103 | fxnRandOrig = fxnRandUInt32; 104 | fxnRandUInt32 = CountRandom; 105 | } 106 | 107 | void InitCountRandom() { 108 | iNumRandomCalls = 0; 109 | } 110 | 111 | void SetupFile(FILE **fFil,const char *sOpenType, const char *sFilename, FILE *filDefault, BOOL bAllowNull) { 112 | 113 | if (*sFilename) { 114 | if (strcmp(sFilename,"null")==0) { 115 | if (bAllowNull) { 116 | (*fFil) = NULL; 117 | } else { 118 | fprintf(stderr,"Fatal Error: Invalid use of null i/o\n"); 119 | AbnormalExit(); 120 | } 121 | } else { 122 | (*fFil) = fopen(sFilename,sOpenType); 123 | if ((*fFil) == NULL) { 124 | printf("Fatal Error: Invalid filename [%s] specified \n",sFilename); 125 | AbnormalExit(); 126 | } 127 | } 128 | } else { 129 | (*fFil) = filDefault; 130 | } 131 | } 132 | 133 | void ActivateReportTriggers() { 134 | 135 | UINT32 j; 136 | 137 | for (j=0;j= 4) { 206 | iReturn = *pNextRandomData++; 207 | iReturn = (iReturn << 8) | *pNextRandomData++; 208 | iReturn = (iReturn << 8) | *pNextRandomData++; 209 | iReturn = (iReturn << 8) | *pNextRandomData++; 210 | iRandomBufferRemaining -= 4; 211 | } else { 212 | j = 4; 213 | while (j--) { 214 | if (iRandomBufferRemaining==0) { 215 | if (bCycleData) { 216 | iRandomBufferRemaining = iCycleDataLen; 217 | pNextRandomData = pRandomDataBuffer; 218 | } else { 219 | iRandomBufferRemaining = fread(pRandomDataBuffer,1,RANDOMFILEBUFFERSIZE,filRandomData); 220 | if (iRandomBufferRemaining==0) { 221 | CloseSingleFile(filRandomData); 222 | SetupFile(&filRandomData,"rb",sFilenameRandomData,NULL,FALSE); 223 | iRandomBufferRemaining = fread(pRandomDataBuffer,1,RANDOMFILEBUFFERSIZE,filRandomData); 224 | } 225 | pNextRandomData = pRandomDataBuffer; 226 | } 227 | } 228 | iReturn = (iReturn << 8) | *pNextRandomData++; 229 | iRandomBufferRemaining--; 230 | } 231 | } 232 | return(iReturn); 233 | } 234 | 235 | void CreateFileRandom() { 236 | 237 | pRandomDataBuffer = AllocateRAM(RANDOMFILEBUFFERSIZE); 238 | 239 | SetupFile(&filRandomData,"rb",sFilenameRandomData,NULL,FALSE); 240 | 241 | if (filRandomData==NULL) { 242 | ReportPrint(pRepErr,"Error! Unable to read from random data file\n"); 243 | AbnormalExit(); 244 | } 245 | 246 | iRandomBufferRemaining = fread(pRandomDataBuffer,1,RANDOMFILEBUFFERSIZE,filRandomData); 247 | 248 | if ((iRandomBufferRemaining < RANDOMFILEBUFFERSIZE)||(feof(filRandomData))) { 249 | bCycleData = TRUE; 250 | iCycleDataLen = iRandomBufferRemaining; 251 | } else { 252 | bCycleData = FALSE; 253 | } 254 | 255 | pNextRandomData = pRandomDataBuffer; 256 | 257 | fxnRandUInt32 = FileRandomUInt32; 258 | } 259 | 260 | void CloseFileRandom() { 261 | CloseSingleFile(filRandomData); 262 | } 263 | 264 | void FileAbort() { 265 | 266 | FILE *fileAbort; 267 | 268 | fileAbort = fopen(sFilenameAbort,"r"); 269 | 270 | if (fileAbort) { 271 | bTerminateAllRuns = TRUE; 272 | fclose(fileAbort); 273 | } 274 | } 275 | 276 | -------------------------------------------------------------------------------- /src/paws.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #include "ubcsat.h" 24 | 25 | void PickPAWS(); 26 | void PostFlipPAWS(); 27 | 28 | UINT32 iPAWSMaxInc; 29 | PROBABILITY iPAWSFlatMove; 30 | 31 | UINT32 iPawsSmoothCounter; 32 | 33 | 34 | /***** Trigger PenClauseList *****/ 35 | 36 | void CreatePenClauseList(); 37 | void InitPenClauseList(); 38 | 39 | UINT32 *aPenClauseList; 40 | UINT32 *aPenClauseListPos; 41 | UINT32 iNumPenClauseList; 42 | 43 | void CreatePenClauseList() { 44 | aPenClauseList = AllocateRAM(iNumClauses*sizeof(UINT32)); 45 | aPenClauseListPos = AllocateRAM(iNumClauses*sizeof(UINT32)); 46 | } 47 | 48 | void InitPenClauseList() { 49 | iNumPenClauseList = 0; 50 | iPawsSmoothCounter = 0; 51 | } 52 | 53 | 54 | 55 | void AddPAWS() { 56 | 57 | ALGORITHM *pCurAlg; 58 | 59 | pCurAlg = CreateAlgorithm("paws","",FALSE, 60 | "PAWS: Pure Additive Weighting Scheme", 61 | "Thornton, Pham, Bain, Ferreira [AAAI 04]", 62 | "PickPAWS,PostFlipPAWS", 63 | "DefaultProcedures,Flip+MBPINT+FCL+VIF,PenClauseList", 64 | "default","default"); 65 | 66 | AddParmUInt(&pCurAlg->parmList,"-maxinc","frequency of penalty reductions [default %s]","reduce (smooth) all clause penalties by 1~after every INT increases","",&iPAWSMaxInc,10); 67 | AddParmProbability(&pCurAlg->parmList,"-pflat","flat move probabilty [default %s]","when a local minimum is encountered,~take a 'flat' (sideways) step with probability PR","",&iPAWSFlatMove,0.15); 68 | 69 | CreateTrigger("PickPAWS",ChooseCandidate,PickPAWS,"",""); 70 | CreateTrigger("PostFlipPAWS",PostFlip,PostFlipPAWS,"",""); 71 | 72 | CreateTrigger("CreatePenClauseList",CreateStateInfo,CreatePenClauseList,"",""); 73 | CreateTrigger("InitPenClauseList",InitStateInfo,InitPenClauseList,"",""); 74 | CreateContainerTrigger("PenClauseList","CreatePenClauseList,InitPenClauseList"); 75 | 76 | } 77 | 78 | void PickPAWS() { 79 | 80 | UINT32 j; 81 | UINT32 iVar; 82 | SINT32 iScore; 83 | SINT32 iBestScore; 84 | UINT32 iLoopEnd; 85 | 86 | iNumCandidates = 0; 87 | iBestScore = SINT32MAX; 88 | 89 | /* look at all variables that appear in false clauses */ 90 | 91 | for (j=0;j= iMaxCandidates) { 112 | ReportPrint1(pRepErr,"Unexpected Error: increase iMaxCandidates [%u]\n",iMaxCandidates); 113 | AbnormalExit(); 114 | } 115 | 116 | while (iNumCandidates < iLoopEnd) { 117 | aCandidateList[iNumCandidates++] = iVar; 118 | } 119 | } 120 | } 121 | 122 | iFlipCandidate = 0; 123 | 124 | if (iBestScore < 0) { 125 | 126 | /* if improving step can be made, select flip candidate uniformly from candidate list */ 127 | 128 | if (iNumCandidates > 1) { 129 | iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)]; 130 | } else { 131 | iFlipCandidate = *aCandidateList; 132 | } 133 | } else { 134 | 135 | if (iBestScore == 0) { 136 | 137 | /* if a flat / sideways step can be made, with probability (iPAWSFlatMove) 138 | flip candidate from candidate list, otherwise it's a null flip */ 139 | 140 | if (RandomProb(iPAWSFlatMove)) { 141 | if (iNumCandidates > 1) { 142 | iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)]; 143 | } else { 144 | iFlipCandidate = *aCandidateList; 145 | } 146 | } 147 | } 148 | } 149 | } 150 | 151 | void SmoothPAWS() { 152 | 153 | UINT32 j; 154 | UINT32 k; 155 | UINT32 iClause; 156 | UINT32 iLoopMax; 157 | LITTYPE *pLit; 158 | 159 | /* Because iNumPenClauseList can change, keep track of # Initial Clauses in list */ 160 | 161 | iLoopMax = iNumPenClauseList; 162 | 163 | /* Each clause penalty is going down by one, so total is going down by # clauses */ 164 | 165 | iTotalPenaltyINT -= iNumPenClauseList; 166 | 167 | for (j=0;j iPAWSMaxInc) { 258 | SmoothPAWS(); 259 | iPawsSmoothCounter = 0; 260 | } 261 | 262 | } 263 | 264 | -------------------------------------------------------------------------------- /src/parameters.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #include "ubcsat.h" 24 | 25 | void AddParameters() { 26 | 27 | AddParmString(&parmAlg,"-alg","algorithm name","","",&sAlgName,""); 28 | AddParmString(&parmAlg,"-v","algorithm variant name (if any)","some algorithms have multiple variants and you can use~the -v parameter to specify which variant you wish to use","",&sVarName,""); 29 | AddParmBool(&parmAlg,"-w","use the weighted variant of the algorithm (if it exists)","weighted algorithms solve weighted instances with static~clause weights (weights are specified in .wcnf files)","",&bWeighted,FALSE); 30 | 31 | AddParmBool(&parmHelp,"-help,--help,-h","general help","","",&bShowHelp,FALSE); 32 | AddParmBool(&parmHelp,"-helpparam,-hp","list ubcsat parameters","","",&bShowHelpP,FALSE); 33 | AddParmBool(&parmHelp,"-helpalg,-ha","list of available (unweighted) algorithms","","",&bShowHelpA,FALSE); 34 | AddParmBool(&parmHelp,"-helpalg,-hw","list of available (weighted) algorithms","","",&bShowHelpW,FALSE); 35 | AddParmBool(&parmHelp,"-helpreports,-hr","list all reports","","",&bShowHelpR,FALSE); 36 | AddParmBool(&parmHelp,"-helpcolumns,-hc","help for reports with columns (-r out),(-r rtd)","","",&bShowHelpC,FALSE); 37 | AddParmBool(&parmHelp,"-helpstats,-hs","help for the statistics report (-r stats)","","",&bShowHelpS,FALSE); 38 | AddParmBool(&parmHelp,"-helpverbose,-hv","list all parameters and algorithms (verbose)","","",&bShowHelpV,FALSE); 39 | AddParmBool(&parmHelp,"-helpterse,-ht","list all parameters and algorithms (terse)","","",&bShowHelpT,FALSE); 40 | 41 | AddParmUInt(&parmUBCSAT,"-runs","number of independent attempts (runs) [default %s]","","",&iNumRuns,1); 42 | AddParmUInt(&parmUBCSAT,"-cutoff","maximum number of search steps per run [default %s]","you can specify \"-cutoff max\" for largest integer limit","",&iCutoff,100000); 43 | AddParmFloat(&parmUBCSAT,"-timeout","maximum number of seconds per run","each run will terminate unsuccessfully after FL seconds,~or when the -cutoff is reached: whichever happens first~so use \"-cutoff max\" to ensure timeout times are reached","CheckTimeout",&fTimeOut,FLOATZERO); 44 | AddParmFloat(&parmUBCSAT,"-gtimeout","global timeout: maximum number of seconds for all runs","the current run and all remaining runs will terminate~after FL seconds","CheckTimeout",&fGlobalTimeOut,FLOATZERO); 45 | AddParmUInt(&parmUBCSAT,"-noimprove","terminate run if no improvement in INT steps","if no improvement in the solution quality has been made~in INT steps, then the run will terminate~(for solution quality description see -target and -wtarget)","NoImprove",&iNoImprove,0); 46 | 47 | AddParmUInt(&parmUBCSAT,"-target","target solution quality","for regular (unweighted) algorithms, the solution quality~is measured as the number of false clauses~~for MAX-SAT (or for some other reason) you can set~the desired solution quality so that solution is found if~the number false clauses <= target~~default target solution quality is zero (no false clauses)","",&iTarget,0); 48 | AddParmFloat(&parmUBCSAT,"-wtarget","weighted target solution quality","similar to -target, except the solution quality is the~sum of the weights of the false clauses","",&fTargetW,0); 49 | 50 | AddParmUInt(&parmUBCSAT,"-seed","specify an initial random seed","","",&iSeed,iSeed); 51 | 52 | AddParmBool(&parmUBCSAT,"-solve","stop when a solution has been found and print solution","-solve may not complete all (-runs) specified~-solve also turns on the model report (-r model)","SolveMode",&bSolveMode,FALSE); 53 | AddParmUInt(&parmUBCSAT,"-find,-numsol","terminate after INT successful runs","-find may not complete all (-runs) specified~or may terminate before enough successful runs","",&iFind,0); 54 | AddParmUInt(&parmUBCSAT,"-findunique","terminate after INT unique solutions have been found","-findunique may not complete all (-runs) specified~or may terminate before enough unique successful runs","UniqueSolutions",&iFindUnique,0); 55 | 56 | AddParmUInt(&parmUBCSAT,"-srestart","static (periodic) restart every INT steps","in UBCSAT restarts do not terminate a run, and several~restarts can occur within a single run","CheckForRestarts",&iPeriodicRestart,0); 57 | AddParmProbability(&parmUBCSAT,"-prestart","probabilistically restart at each step with probability PR","","CheckForRestarts",&iProbRestart,FLOATZERO); 58 | AddParmUInt(&parmUBCSAT,"-drestart","dynamic restart if no improvement in INT steps","similar to (-noimprove), except that -drestart restarts~the algorithm within the run instead of terminating the run","CheckForRestarts,BestFalse",&iStagnateRestart,0); 59 | 60 | AddParmString(&parmIO,"-inst,-i","specify input instance file: (.cnf) or (.wcnf) format","if no file is specified, then UBCSAT reads from stdin~example: ubcsat < sample.cnf","",&sFilenameIn,""); 61 | 62 | AddParmString(&parmIO,"-varinitfile","variable initialization file","variables are initialized to specific values at the~start of each run and at restarts~~Example file:~ -1 3 -4 9 ~sets variables (3,9) to true and variables (1,4) to false~and all other variables would be initialized randomly","",&sFilenameVarInit,""); 63 | AddParmUInt(&parmIO,"-varinitflip","flip INT variables after initialization","forces INT (unique) random variables to be flipped~after initialization","CandidateList",&iInitVarFlip,0); 64 | AddParmBool(&parmIO,"-varinitgreedy","greedy variable initialization","if a variable appears more often as a positive literal~then the var is initialized to true (and vice-versa)~for vars with ties, it alternates between true and false~this initialization is deterministic","",&bVarInitGreedy,FALSE); 65 | 66 | AddParmString(&parmIO,"-param,-fp","read command-line parameters from a file","file format is plain text, and in command-line syntax~the command-line will override any parameters from files~and you can specify more than one file~~Example file:~ -runs 100 -cutoff max -noimprove 1000n","",&sFilenameParms,""); 67 | 68 | AddParmReport(&parmIO,"-report,-r","-r reportname [filename [params]]... use -hr for more info","",""); 69 | 70 | AddParmBool(&parmIO, "-recho","all reports directed to files will also be echoed to stdout","","",&bReportEcho,FALSE); 71 | AddParmBool(&parmIO, "-rflush","all report buffers are flushed before each run","","FlushBuffers",&bReportFlush,FALSE); 72 | AddParmBool(&parmIO, "-rclean","suppress all report header output","","",&bReportClean,FALSE); 73 | 74 | AddParmString(&parmIO, "-rcomment","specify comment character for report headers (# is default)","","",&sCommentString,"#"); 75 | 76 | AddParmString(&parmIO,"-filesol,-fs","specify a file with known solutions","(for FDC calc, distance report, etc...)~file format is same as output from (-r solution)","LoadKnownSolutions",&sFilenameSoln,""); 77 | 78 | AddParmString(&parmIO,"-filerand,-fr","specify a file to read random bits from","can be used instead of a pseudo-random number generator~reads 32 bits of random data at a time, and will loop~back to the start of the file if it runs out of bits~file format is binary","FileRandom",&sFilenameRandomData,""); 79 | 80 | AddParmString(&parmIO,"-fileabort,-fa","specify a signal file to terminate all remaining runs","during a long execution with numerous runs, you can create~an abort file (the contents of the file are not important)~to prevent any remaining runs from starting...~the current run will finish and all reports will finish","FileAbort",&sFilenameAbort,""); 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/ubcsat-types.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | /* Column Statistic Fields */ 24 | 25 | #define STATCODE_all 0xFFFFFFFF 26 | #define STATCODE_mean 0x00000002 27 | #define STATCODE_stddev 0x00000004 28 | #define STATCODE_cv 0x00000008 29 | #define STATCODE_var 0x00000010 30 | #define STATCODE_stderr 0x00000020 31 | #define STATCODE_vmr 0x00000040 32 | #define STATCODE_sum 0x00000080 33 | #define STATCODE_median 0x00000100 34 | #define STATCODE_min 0x00000200 35 | #define STATCODE_max 0x00000400 36 | #define STATCODE_q05 0x00000800 37 | #define STATCODE_q10 0x00001000 38 | #define STATCODE_q25 0x00002000 39 | #define STATCODE_q75 0x00004000 40 | #define STATCODE_q90 0x00008000 41 | #define STATCODE_q95 0x00010000 42 | #define STATCODE_q98 0x00020000 43 | #define STATCODE_qr7525 0x00040000 44 | #define STATCODE_qr9010 0x00080000 45 | #define STATCODE_qr9505 0x00100000 46 | #define STATCODE_stepmean 0x00200000 47 | #define STATCODE_solvemean 0x00400000 48 | #define STATCODE_failmean 0x00800000 49 | #define STATCODE_solvemedian 0x01000000 50 | #define STATCODE_failmedian 0x02000000 51 | #define STATCODE_solvemin 0x04000000 52 | #define STATCODE_failmin 0x08000000 53 | #define STATCODE_solvemax 0x10000000 54 | #define STATCODE_failmax 0x20000000 55 | 56 | #define STATCODE_RAMMASK 0x3FFFFF00 57 | #define STATCODE_SORTMASK 0x001FFF00 58 | #define STATCODE_CALCMASK 0x0000007E 59 | #define STATCODE_SFMASK 0x3FE00000 60 | 61 | #define FLOAT double 62 | #define FLOATMAX (1E+300) 63 | #define FLOATZERO (0.0f) 64 | 65 | #define FLOATSTATSMIN (1E-8) 66 | 67 | #define PROBABILITY unsigned long 68 | 69 | #ifndef BOOL 70 | #define BOOL unsigned long 71 | #endif 72 | 73 | #ifndef UINT32 74 | #define UINT32 unsigned long 75 | #endif 76 | 77 | #define UINT32MAX 0xFFFFFFFF 78 | 79 | #ifndef SINT32 80 | #define SINT32 signed long 81 | #endif 82 | 83 | #define SINT32MAX 0x7FFFFFFF 84 | #define SINT32MIN 0x80000000 85 | 86 | #ifndef FALSE 87 | #define FALSE 0 88 | #endif 89 | 90 | #ifndef TRUE 91 | #define TRUE 1 92 | #endif 93 | 94 | #ifndef NULL 95 | #define NULL 0 96 | #endif 97 | 98 | enum EVENTPOINT 99 | { 100 | PostParameters, 101 | ReadInInstance, 102 | PostRead, 103 | CreateData, 104 | CreateStateInfo, 105 | PreStart, 106 | PreRun, 107 | CheckRestart, 108 | PreInit, 109 | InitData, 110 | InitStateInfo, 111 | PostInit, 112 | PreStep, 113 | ChooseCandidate, 114 | PreFlip, 115 | FlipCandidate, 116 | UpdateStateInfo, 117 | PostFlip, 118 | PostStep, 119 | StepCalculations, 120 | CheckTerminate, 121 | RunCalculations, 122 | PostRun, 123 | FinalCalculations, 124 | FinalReports, 125 | NUMEVENTPOINTS 126 | }; 127 | 128 | enum PARMTYPE { 129 | PTypeUInt, 130 | PTypeSInt, 131 | PTypeBool, 132 | PTypeString, 133 | PTypeProbability, 134 | PTypeFloat, 135 | PTypeReport 136 | }; 137 | 138 | enum CDATATYPE { 139 | DTypeUInt, 140 | DTypeSInt, 141 | DTypeFloat, 142 | DTypeString 143 | }; 144 | 145 | enum COLTYPE { 146 | ColTypeFinal, 147 | ColTypeMean, 148 | ColTypeStddev, 149 | ColTypeCV, 150 | ColTypeMin, 151 | ColTypeMax, 152 | ColTypeFinalDivStep, 153 | ColTypeFinalDivStep100 154 | }; 155 | 156 | typedef void (*FXNPTR)(); 157 | typedef void (*CALLBACKPTR)(UINT32, const char *sItem); 158 | typedef UINT32 (*FXNRAND32)(); 159 | 160 | typedef struct typeITEM { 161 | char *sID; 162 | BOOL bContainer; 163 | char *sContainerList; 164 | } ITEM; 165 | 166 | typedef struct typeITEMLIST { 167 | UINT32 iNumItems; 168 | ITEM aItems[MAXITEMLIST]; 169 | } ITEMLIST; 170 | 171 | typedef struct typeTRIGGER { 172 | 173 | enum EVENTPOINT eEventPoint; 174 | FXNPTR pProcedure; 175 | 176 | BOOL bActive; 177 | BOOL bDisabled; 178 | 179 | char *sDependencyList; 180 | char *sDeactivateList; 181 | 182 | } TRIGGER; 183 | 184 | typedef union typePARAMETERDEFAULT { 185 | UINT32 iUInt; 186 | SINT32 iSInt; 187 | BOOL bBool; 188 | char *sString; 189 | PROBABILITY iProb; 190 | FLOAT fFloat; 191 | } PARAMETERDEFAULT; 192 | 193 | typedef struct typeALGPARM { 194 | enum PARMTYPE eType; 195 | char *sSwitch; 196 | char *sTerseDescription; /* use less than 59 characters */ 197 | char *sVerboseDescription; /* pad with 25 spaces for each line */ 198 | void *pParmValue; 199 | BOOL bSpecified; 200 | char *sTriggers; 201 | PARAMETERDEFAULT defDefault; 202 | } ALGPARM; 203 | 204 | typedef struct ALGPARAMETERS { 205 | UINT32 iNumParms; 206 | ALGPARM aParms[MAXALGPARMS]; 207 | } ALGPARMLIST; 208 | 209 | typedef struct typeALGORITHM { 210 | 211 | char *sName; 212 | char *sVariant; 213 | BOOL bWeighted; 214 | 215 | char *sDescription; 216 | char *sAuthors; 217 | 218 | char *sHeuristicTriggers; 219 | char *sDataTriggers; 220 | 221 | char *sDefaultOutput; 222 | char *sDefaultStats; 223 | 224 | ALGPARMLIST parmList; 225 | 226 | } ALGORITHM; 227 | 228 | typedef struct typeREPORT { 229 | FILE *fileOut; 230 | char *sID; 231 | char *sDescription; 232 | char *sVerboseDescription; 233 | BOOL bActive; 234 | BOOL bSpecialFileIO; 235 | char *sOutputFile; 236 | char *sTriggers; 237 | UINT32 iNumParms; 238 | char *aParmName[MAXREPORTPARMS]; 239 | enum PARMTYPE aParmTypes[MAXREPORTPARMS]; 240 | void *aParameters[MAXREPORTPARMS]; 241 | } REPORT; 242 | 243 | typedef struct typeREPORTCOL { 244 | BOOL bActive; 245 | 246 | BOOL bAllocateColumnRAM; 247 | 248 | char *sDescription; 249 | char *sHeader1; 250 | char *sHeader2; 251 | char *sHeader3; 252 | char *sPrintFormat; 253 | 254 | UINT32 *puiCurValue; 255 | SINT32 *psiCurValue; 256 | FLOAT *pfCurValue; 257 | 258 | UINT32 *puiColumnData; 259 | SINT32 *psiColumnData; 260 | FLOAT *pfColumnData; 261 | 262 | UINT32 uiCurRowValue; 263 | SINT32 siCurRowValue; 264 | FLOAT fCurRowValue; 265 | 266 | char *sTriggers; 267 | 268 | enum CDATATYPE eSourceDataType; 269 | enum CDATATYPE eFinalDataType; 270 | enum COLTYPE eColType; 271 | 272 | SINT32 siMinMaxVal; 273 | UINT32 uiMinMaxVal; 274 | FLOAT fMinMaxVal; 275 | 276 | FLOAT fRowSum; 277 | FLOAT fRowSum2; 278 | 279 | FLOAT fColSum; 280 | FLOAT fColSum2; 281 | 282 | } REPORTCOL; 283 | 284 | 285 | typedef struct typeREPORTSTAT { 286 | 287 | unsigned char bActive; 288 | UINT32 iActiveID; 289 | 290 | char *sDataColumn; 291 | 292 | BOOL bCustomField; 293 | char *sCustomDescription; 294 | void *pCustomValue; 295 | enum CDATATYPE eCustomType; 296 | char *sPrintCustomFormat; 297 | 298 | char *sBaseDescription; 299 | 300 | char *sStatParms; 301 | 302 | UINT32 iStatFlags; 303 | 304 | char *sTriggers; 305 | 306 | BOOL bSortByStep; 307 | 308 | } REPORTSTAT; 309 | 310 | #ifndef BYTE 311 | #define BYTE unsigned char 312 | #endif 313 | 314 | typedef BYTE* VARSTATE; 315 | 316 | typedef struct typeVARSTATELIST { 317 | 318 | VARSTATE vsState; 319 | 320 | struct typeVARSTATELIST* pNext; 321 | 322 | } VARSTATELIST; 323 | 324 | typedef struct typeDYNAMICPARM { 325 | 326 | void *pTarget; 327 | enum CDATATYPE eDataType; 328 | UINT32 *pBase; 329 | FLOAT fFactor; 330 | 331 | } DYNAMICPARM; 332 | 333 | -------------------------------------------------------------------------------- /src/g2wsat.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #include "ubcsat.h" 24 | 25 | void PickG2WSat(); 26 | void PickG2WSatW(); 27 | 28 | void PickG2WSatNoveltyPlusOldest(); 29 | void PickG2WSatNoveltyPlusOldestW(); 30 | 31 | void PickG2WSatP(); 32 | 33 | void InitAdaptG2WSatNoise(); 34 | void AdaptG2WSatNoise(); 35 | 36 | 37 | void AddG2WSat() { 38 | 39 | ALGORITHM *pCurAlg; 40 | 41 | pCurAlg = CreateAlgorithm("g2wsat","",FALSE, 42 | "G2WSAT: Gradient-based Greedy WalkSAT (uses Novelty++)", 43 | "Li, Huang [SAT 05]", 44 | "PickG2WSat", 45 | "DefaultProcedures,Flip+TrackChanges+FCL,DecPromVars,FalseClauseList,VarLastChange", 46 | "default","default"); 47 | 48 | CopyParameters(pCurAlg,"novelty++","",FALSE); 49 | CreateTrigger("PickG2WSat",ChooseCandidate,PickG2WSat,"",""); 50 | 51 | 52 | pCurAlg = CreateAlgorithm("g2wsat","",TRUE, 53 | "G2WSAT: Gradient-based Greedy WalkSAT (weighted)", 54 | "Li, Huang [SAT 05]", 55 | "PickG2WSatW", 56 | "DefaultProceduresW,Flip+TrackChanges+FCL+W,DecPromVarsW,FalseClauseList,VarLastChange", 57 | "default_w","default"); 58 | 59 | CopyParameters(pCurAlg,"g2wsat","",FALSE); 60 | CreateTrigger("PickG2WSatW",ChooseCandidate,PickG2WSatW,"",""); 61 | 62 | 63 | pCurAlg = CreateAlgorithm("g2wsat","novelty+oldest",FALSE, 64 | "G2WSAT: Gradient-based Greedy WalkSAT (uses Nov+ & oldest dec. prom var)", 65 | "Li, Wei, and Zhang [SAT 07]", 66 | "PickG2WSatNoveltyPlusOldest", 67 | "DefaultProcedures,Flip+TrackChanges+FCL,DecPromVars,FalseClauseList,VarLastChange", 68 | "default","default"); 69 | 70 | CopyParameters(pCurAlg,"novelty+","",FALSE); 71 | CreateTrigger("PickG2WSatNoveltyPlusOldest",ChooseCandidate,PickG2WSatNoveltyPlusOldest,"",""); 72 | 73 | 74 | pCurAlg = CreateAlgorithm("g2wsat","novelty+oldest",TRUE, 75 | "G2WSAT: uses Nov+ & oldest dec. prom var) (weighted)", 76 | "Li, Wei, and Zhang [SAT 07]", 77 | "PickG2WSatNoveltyPlusOldestW", 78 | "DefaultProcedures,Flip+TrackChanges+FCL,DecPromVars,FalseClauseList,VarLastChange", 79 | "default","default"); 80 | 81 | CopyParameters(pCurAlg,"novelty+","",FALSE); 82 | 83 | CreateTrigger("PickG2WSatNoveltyPlusOldestW",ChooseCandidate,PickG2WSatNoveltyPlusOldestW,"",""); 84 | 85 | 86 | pCurAlg = CreateAlgorithm("g2wsat+p","",FALSE, 87 | "G2WSAT+p: Gradient-based Greedy WalkSAT with look-ahead (uses Novelty+p)", 88 | "Li, Wei, Zhang [SAT 07]", 89 | "PickG2WSatP", 90 | "DefaultProcedures,Flip+TrackChanges+FCL,DecPromVars,FalseClauseList,VarLastChange,LookAhead", 91 | "default","default"); 92 | 93 | CopyParameters(pCurAlg,"novelty+p","",FALSE); 94 | 95 | CreateTrigger("PickG2WSatP",ChooseCandidate,PickG2WSatP,"",""); 96 | 97 | 98 | pCurAlg = CreateAlgorithm("adaptg2wsat","",FALSE, 99 | "Adaptive G2WSat: Adaptive G2WSAT (uses Nov+, Oldest DecPromVar)", 100 | "Li, Wei, Zhang [SAT 07]", 101 | "PickG2WSatNoveltyPlusOldest", 102 | "DefaultProcedures,Flip+TrackChanges+FCL,DecPromVars,FalseClauseList,VarLastChange,AdaptG2WSatNoise", 103 | "default","default"); 104 | 105 | CopyParameters(pCurAlg,"g2wsat","novelty+oldest",FALSE); 106 | 107 | CreateTrigger("InitAdaptG2WSatNoise",PostInit,InitAdaptG2WSatNoise,"",""); 108 | CreateTrigger("AdaptG2WSatNoise",PostFlip,AdaptG2WSatNoise,"InitAdaptG2WSatNoise",""); 109 | 110 | 111 | pCurAlg = CreateAlgorithm("adaptg2wsat+p","",FALSE, 112 | "Adapt+G2WSat+p: Adaptive G2WSAT+p", 113 | "Li, Wei, Zhang [SAT 07]", 114 | "PickG2WSatP", 115 | "DefaultProcedures,Flip+TrackChanges+FCL,DecPromVars,FalseClauseList,VarLastChange,LookAhead,AdaptG2WSatNoise", 116 | "default","default"); 117 | 118 | CopyParameters(pCurAlg,"g2wsat+p","",FALSE); 119 | } 120 | 121 | 122 | void PickG2WSat() { 123 | 124 | UINT32 j; 125 | UINT32 iVar; 126 | SINT32 iScore; 127 | 128 | /* If there are Decreasing Promising Variables */ 129 | 130 | if (iNumDecPromVars > 0 ) { 131 | 132 | /* Find the one with the 'best' score */ 133 | 134 | iFlipCandidate = aDecPromVarsList[0]; 135 | iBestScore = aVarScore[iFlipCandidate]; 136 | for (j=1;j 0 ) { 170 | iFlipCandidate = aDecPromVarsListW[0]; 171 | fBestScore = aVarScoreW[iFlipCandidate]; 172 | for (j=1;j 0 ) { 199 | 200 | /* Find the one with that is the 'oldest' */ 201 | 202 | iFlipCandidate = aDecPromVarsList[0]; 203 | for (j=1;j 0 ) { 226 | iFlipCandidate = aDecPromVarsList[0]; 227 | for (j=1;j 0 ) { 246 | 247 | /* Find the one with that is the 'oldest' */ 248 | 249 | iFlipCandidate = aDecPromVarsList[0]; 250 | for (j=1;jparmList,"-wp","walk probability [default %s]","with probability PR, select a random variable from a~randomly selected unsat clause","",&iWp,0.50); 52 | 53 | CreateTrigger("PickVW1",ChooseCandidate,PickVW1,"",""); 54 | 55 | 56 | pCurAlg = CreateAlgorithm("vw2","",FALSE, 57 | "VW2: Variable Weighting Scheme Two", 58 | "Prestwich [SAT 05]", 59 | "PickVW2", 60 | "DefaultProcedures,Flip+FalseClauseList,VW2Weights", 61 | "default","default"); 62 | 63 | CopyParameters(pCurAlg,"vw1","",FALSE); 64 | AddParmFloat(&pCurAlg->parmList,"-s","VW2 smoothing factor [default %s]","paramater to adjust variable weight smoothing~s = 0 is equivalent to VW1~s = 1 is more HWSAT-like","",&fVW2Smooth,0.01); 65 | AddParmFloat(&pCurAlg->parmList,"-c","VW2 weighting factor [default %s]","paramater to adjust variable weight scoring~c = 0 is equivalent to WalkSAT/SKC","",&fVW2WeightFactor,0.01); 66 | 67 | CreateTrigger("PickVW2",ChooseCandidate,PickVW2,"",""); 68 | 69 | CreateTrigger("CreateVW2Weights",CreateStateInfo,CreateVW2Weights,"",""); 70 | CreateTrigger("InitVW2Weights",InitStateInfo,InitVW2Weights,"",""); 71 | CreateTrigger("UpdateVW2Weights",UpdateStateInfo,UpdateVW2Weights,"",""); 72 | CreateContainerTrigger("VW2Weights","InitVW2Weights,CreateVW2Weights,UpdateVW2Weights"); 73 | 74 | } 75 | 76 | void PickVW1() { 77 | 78 | UINT32 i; 79 | UINT32 j; 80 | SINT32 iScore; 81 | UINT32 iClause; 82 | UINT32 iClauseLen; 83 | UINT32 iVar; 84 | LITTYPE *pLit; 85 | UINT32 *pClause; 86 | LITTYPE litPick; 87 | UINT32 iNumOcc; 88 | UINT32 iBestVarFlipCount; 89 | 90 | iNumCandidates = 0; 91 | iBestScore = iNumClauses; 92 | iBestVarFlipCount = iStep; 93 | 94 | /* select an unsatisfied clause uniformly at random */ 95 | 96 | if (iNumFalse) { 97 | iClause = aFalseList[RandomInt(iNumFalse)]; 98 | iClauseLen = aClauseLen[iClause]; 99 | } else { 100 | iFlipCandidate = 0; 101 | return; 102 | } 103 | 104 | 105 | pLit = pClauseLits[iClause]; 106 | 107 | for (j=0;j 0) { 161 | if (RandomProb(iWp)) { 162 | litPick = pClauseLits[iClause][RandomInt(iClauseLen)]; 163 | iFlipCandidate = GetVarFromLit(litPick); 164 | return; 165 | } 166 | } 167 | 168 | /* select flip candidate uniformly from candidate list */ 169 | 170 | if (iNumCandidates > 1) { 171 | iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)]; 172 | } else { 173 | iFlipCandidate = aCandidateList[0]; 174 | } 175 | 176 | } 177 | 178 | void PickVW2() { 179 | 180 | UINT32 i; 181 | UINT32 j; 182 | SINT32 iScore; 183 | UINT32 iClause; 184 | UINT32 iClauseLen; 185 | UINT32 iVar; 186 | LITTYPE *pLit; 187 | UINT32 *pClause; 188 | LITTYPE litPick; 189 | UINT32 iNumOcc; 190 | FLOAT fCurVW2Score; 191 | FLOAT fBestVW2Score; 192 | 193 | iNumCandidates = 0; 194 | iBestScore = iNumClauses; 195 | fBestVW2Score = FLOATMAX; 196 | 197 | /* select an unsatisfied clause uniformly at random */ 198 | 199 | if (iNumFalse) { 200 | iClause = aFalseList[RandomInt(iNumFalse)]; 201 | iClauseLen = aClauseLen[iClause]; 202 | } else { 203 | iFlipCandidate = 0; 204 | return; 205 | } 206 | 207 | pLit = pClauseLits[iClause]; 208 | 209 | for (j=0;j 0) { 235 | iNumCandidates=0; 236 | iBestScore = 0; 237 | } 238 | aCandidateList[iNumCandidates++] = iVar; 239 | } else { 240 | if (iBestScore > 0) { 241 | 242 | /* if no freebie found yet, use the VW2 weighted score */ 243 | 244 | fCurVW2Score = (FLOAT) iScore + fVW2WeightFactor * (aVW2Weights[iVar] - fVW2WeightMean); 245 | 246 | if (fCurVW2Score <= fBestVW2Score) { 247 | if (fCurVW2Score < fBestVW2Score) { 248 | iNumCandidates=0; 249 | fBestVW2Score = fCurVW2Score; 250 | } 251 | aCandidateList[iNumCandidates++] = iVar; 252 | } 253 | } 254 | } 255 | pLit++; 256 | } 257 | 258 | /* if the best step is a worsening step, then with 259 | probability (iWp) randomly choose the literal to flip */ 260 | 261 | if (iBestScore > 0) { 262 | if (RandomProb(iWp)) { 263 | litPick = pClauseLits[iClause][RandomInt(iClauseLen)]; 264 | iFlipCandidate = GetVarFromLit(litPick); 265 | return; 266 | } 267 | } 268 | 269 | /* select flip candidate uniformly from candidate list */ 270 | 271 | if (iNumCandidates > 1) { 272 | iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)]; 273 | } else { 274 | iFlipCandidate = aCandidateList[0]; 275 | } 276 | } 277 | 278 | 279 | void CreateVW2Weights() { 280 | aVW2Weights = AllocateRAM((iNumVars+1)*sizeof(FLOAT)); 281 | } 282 | 283 | void InitVW2Weights() { 284 | memset(aVW2Weights,0,(iNumVars+1)*sizeof(FLOAT)); 285 | fVW2WeightMean = FLOATZERO; 286 | } 287 | 288 | void UpdateVW2Weights() { 289 | FLOAT fPrevWeight = aVW2Weights[iFlipCandidate]; 290 | aVW2Weights[iFlipCandidate] = (1.0f - fVW2Smooth) * (aVW2Weights[iFlipCandidate] + 1.0f) + (fVW2Smooth * (FLOAT) iStep); 291 | fVW2WeightMean += (aVW2Weights[iFlipCandidate] - fPrevWeight) / iNumVars; 292 | } 293 | 294 | -------------------------------------------------------------------------------- /src/derandomized.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #include "ubcsat.h" 24 | 25 | void PickDCRWalk(); 26 | void CreateClausePickCount(); 27 | void InitClausePickCount(); 28 | void UpdateClausePickCount(); 29 | void CreateNextClauseLit(); 30 | void InitNextClauseLit(); 31 | void UpdateNextClauseLit(); 32 | 33 | UINT32 iClausePick; 34 | UINT32 *aClausePickCount; 35 | UINT32 *aNextClauseLit; 36 | 37 | 38 | void PickDANOVP(); 39 | void InitAdaptNoveltyNoiseDet(); 40 | void AdaptNoveltyNoiseDet(); 41 | 42 | UINT32 iCountNovNoise0; 43 | UINT32 iCountNovNoise1; 44 | 45 | 46 | void AddDerandomized() { 47 | 48 | ALGORITHM *pCurAlg; 49 | 50 | pCurAlg = CreateAlgorithm("dcrwalk","",FALSE, 51 | "Deterministic Conflict-Directed Random Walk (For Academic Interest)", 52 | "Tompkins, Hoos [AI 2006]", 53 | "PickDCRWalk", 54 | "DefaultProcedures,Flip+FalseClauseList", 55 | "default","default"); 56 | 57 | CreateTrigger("PickDCRWalk",ChooseCandidate,PickDCRWalk,"ClausePickCount,NextClauseLit,UnsatCounts","UpdateUnsatCounts,UpdateNextClauseLit,UpdateClausePickCount"); 58 | 59 | CreateTrigger("CreateClausePickCount",CreateStateInfo,CreateClausePickCount,"",""); 60 | CreateTrigger("InitClausePickCount",InitStateInfo,InitClausePickCount,"",""); 61 | CreateTrigger("UpdateClausePickCount",PreFlip,UpdateClausePickCount,"",""); 62 | CreateContainerTrigger("ClausePickCount","CreateClausePickCount,InitClausePickCount,UpdateClausePickCount"); 63 | 64 | CreateTrigger("CreateNextClauseLit",CreateStateInfo,CreateNextClauseLit,"",""); 65 | CreateTrigger("InitNextClauseLit",InitStateInfo,InitNextClauseLit,"",""); 66 | CreateTrigger("UpdateNextClauseLit",PreFlip,UpdateNextClauseLit,"",""); 67 | CreateContainerTrigger("NextClauseLit","CreateNextClauseLit,InitNextClauseLit,UpdateNextClauseLit"); 68 | 69 | pCurAlg = CreateAlgorithm("danov+","",FALSE, 70 | "Deterministic Adaptive Novelty Plus (For Academic Interest)", 71 | "Tompkins, Hoos [AI 2006]", 72 | "PickDANOVP", 73 | "DefaultProcedures,Flip+FalseClauseList,AdaptNoveltyNoiseDet,VarLastChange", 74 | "default","default"); 75 | 76 | AddParmProbability(&pCurAlg->parmList,"-wp","pseudo-walk probability [default %s]","with frequency 1/PR, select a variable~from a an unsat clause to flip","",&iWp,0.01); 77 | 78 | CreateTrigger("PickDANOVP",ChooseCandidate,PickDANOVP,"ClausePickCount,NextClauseLit,UnsatCounts","UpdateUnsatCounts,UpdateClausePickCount,UpdateNextClauseLit"); 79 | 80 | CreateTrigger("InitAdaptNoveltyNoiseDet",PostInit,InitAdaptNoveltyNoiseDet,"",""); 81 | CreateTrigger("AdaptNoveltyNoiseDet",PostFlip,AdaptNoveltyNoiseDet,"InitAdaptNoveltyNoiseDet",""); 82 | 83 | } 84 | 85 | void CreateClausePickCount() { 86 | aClausePickCount = AllocateRAM(iNumClauses*sizeof(UINT32)); 87 | } 88 | 89 | void InitClausePickCount() { 90 | memset(aClausePickCount,0,iNumClauses*sizeof(UINT32)); 91 | } 92 | 93 | void UpdateClausePickCount() { 94 | aClausePickCount[iClausePick]++; 95 | } 96 | 97 | void CreateNextClauseLit() { 98 | aNextClauseLit = AllocateRAM(iNumClauses*sizeof(UINT32)); 99 | } 100 | 101 | void InitNextClauseLit() { 102 | memset(aNextClauseLit,0,iNumClauses*sizeof(UINT32)); 103 | } 104 | 105 | void UpdateNextClauseLit() { 106 | aNextClauseLit[iClausePick]++; 107 | if (aNextClauseLit[iClausePick]==aClauseLen[iClausePick]) { 108 | aNextClauseLit[iClausePick] = 0; 109 | } 110 | } 111 | 112 | void PickDCRWalk() { 113 | 114 | UINT32 j; 115 | FLOAT fClausePickScore; 116 | FLOAT fBestClausePickScore = FLOATMAX; 117 | UINT32 iClause; 118 | 119 | LITTYPE litPick; 120 | 121 | iClausePick = iNumClauses - 1; 122 | 123 | if (iNumFalse) { 124 | for (j=0;j aVarLastChange[iYoungestVar]) { 222 | iYoungestVar = iVar; 223 | } 224 | 225 | if ((iScore < iBestScore) || ((iScore == iBestScore) && (aVarLastChange[iVar] < aVarLastChange[iBestVar]))) { 226 | iSecondBestVar = iBestVar; 227 | iBestVar = iVar; 228 | iSecondBestScore = iBestScore; 229 | iBestScore = iScore; 230 | } else if ((iScore < iSecondBestScore) || ((iScore == iSecondBestScore) && (aVarLastChange[iVar] < aVarLastChange[iSecondBestVar]))) { 231 | iSecondBestVar = iVar; 232 | iSecondBestScore = iScore; 233 | } 234 | 235 | pLit++; 236 | } 237 | 238 | iFlipCandidate = iBestVar; 239 | 240 | if (iFlipCandidate != iYoungestVar) { 241 | return; 242 | } 243 | 244 | if (iNovNoise) { 245 | 246 | fCurNoiseCalc = ((FLOAT) iCountNovNoise1) / (FLOAT) (iCountNovNoise0 + iCountNovNoise1); 247 | 248 | if (fCurNoiseCalc < ProbToFloat(iNovNoise)) { 249 | iFlipCandidate = iSecondBestVar; 250 | iCountNovNoise1++; 251 | } else { 252 | iCountNovNoise0++; 253 | } 254 | } 255 | } 256 | } 257 | 258 | void InitAdaptNoveltyNoiseDet() { 259 | iLastAdaptStep=iStep; 260 | iLastAdaptNumFalse=iNumFalse; 261 | fLastAdaptSumFalseW=fTotalWeight; 262 | iNovNoise = 0; 263 | iCountNovNoise0 = 1; 264 | iCountNovNoise1 = 1; 265 | } 266 | 267 | void AdaptNoveltyNoiseDet() { 268 | 269 | if (iStep-iLastAdaptStep > iNumClauses/iInvTheta) { 270 | 271 | iNovNoise += (PROBABILITY) ((UINT32MAX - iNovNoise)/iInvPhi); 272 | iLastAdaptStep = iStep; 273 | iLastAdaptNumFalse = iNumFalse; 274 | if (iNovNoise == 0) { 275 | iCountNovNoise0 = 1; 276 | iCountNovNoise1 = 1; 277 | } else { 278 | iCountNovNoise1 = (iNovNoise >> 24) & (0xFF); 279 | iCountNovNoise0 = 256 - iCountNovNoise1; 280 | } 281 | } else if (iNumFalse < iLastAdaptNumFalse) { 282 | 283 | iNovNoise -= (PROBABILITY) (iNovNoise / iInvPhi / 2); 284 | 285 | iLastAdaptStep = iStep; 286 | iLastAdaptNumFalse = iNumFalse; 287 | 288 | if (iNovNoise == 0) { 289 | iCountNovNoise0 = 1; 290 | iCountNovNoise1 = 1; 291 | } else { 292 | iCountNovNoise1 = (iNovNoise >> 24) & (0xFF); 293 | iCountNovNoise0 = 256 - iCountNovNoise1; 294 | } 295 | } 296 | } 297 | 298 | 299 | -------------------------------------------------------------------------------- /src/novelty+p.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #include "ubcsat.h" 24 | 25 | void PickNoveltyPlusP(); 26 | void InitLookAhead(); 27 | void CreateLookAhead(); 28 | SINT32 BestLookAheadScore(UINT32 iLookVar); 29 | 30 | void AddNoveltyPlusP() { 31 | 32 | ALGORITHM *pCurAlg; 33 | 34 | pCurAlg = CreateAlgorithm("novelty+p","",FALSE, 35 | "Novelty+p: Novelty with random walk and look-ahead", 36 | "Li, Wei, and Zhang [SAT 07]", 37 | "PickNoveltyPlusP", 38 | "DefaultProcedures,Flip+TrackChanges+FCL,DecPromVars,FalseClauseList,VarLastChange,LookAhead", 39 | "default","default"); 40 | 41 | CopyParameters(pCurAlg,"novelty+","",FALSE); 42 | 43 | CreateTrigger("PickNoveltyPlusP",ChooseCandidate,PickNoveltyPlusP,"",""); 44 | 45 | CreateTrigger("CreateLookAhead",CreateStateInfo,CreateLookAhead,"",""); 46 | CreateTrigger("InitLookAhead",InitStateInfo,InitLookAhead,"",""); 47 | CreateContainerTrigger("LookAhead","CreateLookAhead,InitLookAhead"); 48 | 49 | } 50 | 51 | void PickNoveltyPlusP() { 52 | 53 | UINT32 j; 54 | UINT32 iClause; 55 | UINT32 iClauseLen; 56 | UINT32 iVar; 57 | LITTYPE *pLit; 58 | SINT32 iScore; 59 | UINT32 iYoungestVar; 60 | SINT32 iSecondBestScore; 61 | UINT32 iBestVar=0; 62 | UINT32 iSecondBestVar=0; 63 | 64 | LITTYPE litPick; 65 | 66 | SINT32 iSecondBestLookAheadScore; 67 | SINT32 iBestLookAheadScore; 68 | 69 | if (iNumFalse) { 70 | 71 | /* select random unsatisfied clause */ 72 | 73 | iClause = aFalseList[RandomInt(iNumFalse)]; 74 | iClauseLen = aClauseLen[iClause]; 75 | 76 | if (RandomProb(iWp)) { 77 | 78 | /* with probability (iWp) uniformly choose a literal from that clause */ 79 | 80 | litPick = (pClauseLits[iClause][RandomInt(iClauseLen)]); 81 | iFlipCandidate = GetVarFromLit(litPick); 82 | 83 | } else { 84 | 85 | iBestScore = iNumClauses; 86 | iSecondBestScore = iNumClauses; 87 | pLit = pClauseLits[iClause]; 88 | iYoungestVar = GetVarFromLit(*pLit); 89 | 90 | /* for each literal in the clause */ 91 | 92 | for (j=0;j aVarLastChange[iYoungestVar]) { 102 | iYoungestVar = iVar; 103 | } 104 | 105 | /* keep track of the 'best' and the 'second best' variables, 106 | breaking ties by selecting the younger variables */ 107 | 108 | if ((iScore < iBestScore) || ((iScore == iBestScore) && (aVarLastChange[iVar] < aVarLastChange[iBestVar]))) { 109 | iSecondBestVar = iBestVar; 110 | iBestVar = iVar; 111 | iSecondBestScore = iBestScore; 112 | iBestScore = iScore; 113 | } else if ((iScore < iSecondBestScore) || ((iScore == iSecondBestScore) && (aVarLastChange[iVar] < aVarLastChange[iSecondBestVar]))) { 114 | iSecondBestVar = iVar; 115 | iSecondBestScore = iScore; 116 | } 117 | pLit++; 118 | } 119 | 120 | /* choose the 'best' variable by default */ 121 | 122 | iFlipCandidate = iBestVar; 123 | 124 | /* If the best is the youngest, with probability (iNovNoise) select the 2nd best */ 125 | 126 | if (iFlipCandidate == iYoungestVar) { 127 | if (RandomProb(iNovNoise)) { 128 | iFlipCandidate = iSecondBestVar; 129 | return; 130 | } 131 | } else { 132 | 133 | /* If the best is older than then 2nd best, just choose the best */ 134 | 135 | if (aVarLastChange[iSecondBestVar] >= aVarLastChange[iFlipCandidate]) { 136 | return; 137 | } 138 | } 139 | 140 | /* otherwise, determine the 'look ahead' score for the 2nd best variable */ 141 | 142 | iSecondBestLookAheadScore = aVarScore[iSecondBestVar] + BestLookAheadScore(iSecondBestVar); 143 | 144 | if (iSecondBestLookAheadScore > iBestScore) { 145 | iBestLookAheadScore = iBestScore; 146 | } else { 147 | 148 | /* if the 'look ahead' score for the 2nd variable is better than the regular score 149 | for the best variable, calculate the look ahead score for the best variable */ 150 | 151 | iBestLookAheadScore = aVarScore[iFlipCandidate] + BestLookAheadScore(iFlipCandidate); 152 | } 153 | 154 | /* choose the variable with the best look ahead score */ 155 | 156 | /* Note that this BREAKS TIES by selecting the 2nd best variable -- as in the paper and in the author's code */ 157 | 158 | if (iBestLookAheadScore >= iSecondBestLookAheadScore) { 159 | iFlipCandidate = iSecondBestVar; 160 | } 161 | } 162 | } else { 163 | iFlipCandidate = 0; 164 | } 165 | } 166 | 167 | 168 | UINT32 *aIsLookAhead; 169 | UINT32 *aLookAheadList; 170 | SINT32 *aLookAheadScoreChange; 171 | 172 | #define UpdateLookAhead(var,diff) {if(aIsLookAhead[var]==FALSE) {aIsLookAhead[var]=TRUE; aLookAheadList[iNumLookAhead++] = var; aLookAheadScoreChange[var] = (diff);} else {aLookAheadScoreChange[var] += (diff);}}; 173 | 174 | void CreateLookAhead() { 175 | aIsLookAhead = AllocateRAM((iNumVars+1) * sizeof(UINT32)); 176 | aLookAheadList = AllocateRAM((iNumVars+1) * sizeof(UINT32)); 177 | aLookAheadScoreChange = AllocateRAM((iNumVars+1) * sizeof(SINT32)); 178 | } 179 | 180 | void InitLookAhead() { 181 | memset(aIsLookAhead,0,(iNumVars+1) * sizeof(UINT32)); 182 | } 183 | 184 | SINT32 BestLookAheadScore(UINT32 iLookVar) { 185 | UINT32 j; 186 | UINT32 k; 187 | UINT32 *pClause; 188 | UINT32 iVar; 189 | LITTYPE litWasTrue; 190 | LITTYPE litWasFalse; 191 | LITTYPE *pLit; 192 | UINT32 iNumLookAhead; 193 | SINT32 iScore; 194 | SINT32 iBestLookAheadScore; 195 | 196 | if (iLookVar == 0) { 197 | return(0); 198 | } 199 | 200 | iNumLookAhead = 0; 201 | 202 | /* Add all Decreasing Promising variables to the 'best lookahead' list */ 203 | 204 | for (j=0;j=0)) { 285 | 286 | /* find the best 'combined' score */ 287 | 288 | if (iScore < iBestLookAheadScore) { 289 | iBestLookAheadScore = iScore; 290 | } 291 | } 292 | } 293 | aIsLookAhead[iVar] = FALSE; 294 | } 295 | 296 | /* only consider 'improving' look ahead scores */ 297 | 298 | if (iBestLookAheadScore < 0) { 299 | return(iBestLookAheadScore); 300 | } else { 301 | return(0); 302 | } 303 | } 304 | -------------------------------------------------------------------------------- /src/irots.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | #include "ubcsat.h" 24 | 25 | /* note that this IRoTS implementation differs slightly from 26 | the previously published software... in mostly unimportant 27 | ways. in this implementation we have strived to match the 28 | text of the AI 2003 paper exactly */ 29 | 30 | UINT32 iIrotsEscapeSteps; 31 | UINT32 iIrotsPerturbSteps; 32 | 33 | UINT32 iLSTabuTenure; 34 | UINT32 iPerturbTabuTenure; 35 | 36 | PROBABILITY iIrotsNoise; 37 | 38 | UINT32 iLSTabuTenureLow; 39 | UINT32 iLSTabuTenureHigh; 40 | UINT32 iPerturbTabuTenureLow; 41 | UINT32 iPerturbTabuTenureHigh; 42 | 43 | UINT32 iIrotsLSBestStep; 44 | UINT32 iIrotsLSBestValue; 45 | FLOAT fIrotsLSBestValueW; 46 | 47 | UINT32 iIrotsSavedValue; 48 | FLOAT fIrotsSavedValueW; 49 | 50 | UINT32 iIrotsMode; 51 | 52 | UINT32 *aIrotsBackup; 53 | 54 | void InitIRoTSParms(); 55 | void InitIRoTS(); 56 | void PostStepIRoTS(); 57 | 58 | void CreateIRoTSBackup(); 59 | void IRoTSBackup(); 60 | void IRoTSRestore(); 61 | 62 | void AddIRoTS() { 63 | 64 | ALGORITHM *pCurAlg; 65 | 66 | pCurAlg = CreateAlgorithm("irots","",FALSE, 67 | "IRoTS: Iterated Robust TABU Search", 68 | "Smyth, Hoos, Stuetzle [AI 2003]", 69 | "PickRoTS,PostStepIRoTS", 70 | "DefaultProcedures,Flip+VarScore,CreateIRoTSBackup", 71 | "default","default"); 72 | 73 | AddParmUInt(&pCurAlg->parmList,"-ltabu","local search phase median tabu tenure","[default is 0.1n + 4]","",&iLSTabuTenure,0); 74 | AddParmUInt(&pCurAlg->parmList,"-tabuinterval","interval size: percent of tabu tenure [default %s]","range of tabu tenure is: tt +/- tt * (INT/100)","",&iTabuTenureInterval,25); 75 | AddParmUInt(&pCurAlg->parmList,"-esteps","perturb after INT steps beyond last improving step", "[default is n^2/4]","",&iIrotsEscapeSteps,0); 76 | AddParmUInt(&pCurAlg->parmList,"-psteps","perturb for exactly INT steps", "[default is 0.9n]","",&iIrotsPerturbSteps,0); 77 | AddParmUInt(&pCurAlg->parmList,"-ptabu","perturb phase median tabu tenure", "[default to psteps/2]","",&iPerturbTabuTenure,0); 78 | AddParmProbability(&pCurAlg->parmList,"-pnoise","irots noise [default %s]","probability of selecting the worst of the two candidates","",&iIrotsNoise,0.10); 79 | 80 | CreateTrigger("InitIRoTSParms",PreStart,InitIRoTSParms,"",""); 81 | CreateTrigger("InitIRoTS",PreRun,InitIRoTS,"",""); 82 | CreateTrigger("PostStepIRoTS",PostStep,PostStepIRoTS,"InitIRoTS,InitIRoTSParms",""); 83 | 84 | CreateTrigger("CreateIRoTSBackup",CreateStateInfo,CreateIRoTSBackup,"",""); 85 | 86 | pCurAlg = CreateAlgorithm("irots","",TRUE, 87 | "IRoTS: Iterated Robust TABU Search (weighted)", 88 | "Smyth, Hoos, Stuetzle [AI 2003]", 89 | "PickRoTSW,PostStepIRoTS", 90 | "DefaultProceduresW,Flip+VarScoreW,CreateIRoTSBackup", 91 | "default_w","default"); 92 | 93 | CopyParameters(pCurAlg,"irots","",FALSE); 94 | 95 | } 96 | 97 | void InitIRoTSParms() { 98 | 99 | /* this variable initialization scheme is from the paper */ 100 | 101 | if (iLSTabuTenure == 0) iLSTabuTenure = iNumVars / 10 + 4; 102 | if (iIrotsEscapeSteps == 0) iIrotsEscapeSteps = iNumVars * iNumVars / 4; 103 | if (iIrotsPerturbSteps == 0) iIrotsPerturbSteps = iNumVars * 9 / 10; 104 | if (iPerturbTabuTenure == 0) iPerturbTabuTenure = iIrotsPerturbSteps / 2; 105 | 106 | /* use the iTabuTenureInterval to set the low & high range for the tabu tenure */ 107 | 108 | iLSTabuTenureLow = iLSTabuTenure - (iTabuTenureInterval * iLSTabuTenure) / 100; 109 | iLSTabuTenureHigh = iLSTabuTenure + (iTabuTenureInterval * iLSTabuTenure) / 100; 110 | 111 | iPerturbTabuTenureLow = iPerturbTabuTenure - (iTabuTenureInterval * iPerturbTabuTenure) / 100; 112 | iPerturbTabuTenureHigh = iPerturbTabuTenure + (iTabuTenureInterval * iPerturbTabuTenure) / 100; 113 | } 114 | 115 | void InitIRoTS() { 116 | 117 | /* mode 0 ==> initial local search phase */ 118 | 119 | iIrotsMode = 0; 120 | 121 | /* set RoTS parameters to the LS mode */ 122 | 123 | iTabuTenureLow = iLSTabuTenureLow; 124 | iTabuTenureHigh = iLSTabuTenureHigh; 125 | iTabuTenure = iLSTabuTenure; 126 | 127 | iIrotsLSBestStep = 1; 128 | iIrotsLSBestValue = iNumClauses + 1; 129 | fIrotsLSBestValueW = fTotalWeight; 130 | 131 | iVarLastChangeReset = 0; 132 | } 133 | 134 | 135 | void PostStepIRoTS() { 136 | 137 | BOOL bSwitchMode = FALSE; 138 | BOOL bSave = FALSE; 139 | BOOL bRestore = FALSE; 140 | 141 | /* after a regular IRoTS step, the process depends on what 142 | 'mode' the solver is in */ 143 | 144 | switch (iIrotsMode) { 145 | 146 | /* mode 0 ==> initial local search phase */ 147 | 148 | case 0: 149 | 150 | /* keep track of the 'step' with last best improvement */ 151 | 152 | if (bWeighted) { 153 | if (fSumFalseW < fIrotsLSBestValueW) { 154 | fIrotsLSBestValueW = fSumFalseW; 155 | iIrotsLSBestStep = iStep; 156 | } 157 | } else { 158 | if (iNumFalse < iIrotsLSBestValue) { 159 | iIrotsLSBestValue = iNumFalse; 160 | iIrotsLSBestStep = iStep; 161 | } 162 | } 163 | 164 | /* in no improvement past the best in 'esteps' steps, go to perturbation phase */ 165 | 166 | if (iStep == iIrotsLSBestStep + iIrotsEscapeSteps + 1) { 167 | 168 | /* because this is the initial phase, we must 'save' the candidate solution */ 169 | 170 | bSave = TRUE; 171 | iIrotsMode++; 172 | bSwitchMode = TRUE; 173 | } 174 | 175 | break; 176 | 177 | /* mode 1 ==> perturbation search phase */ 178 | 179 | case 1: 180 | 181 | /* stay in this phase for exactly 'psteps' steps */ 182 | 183 | if (iStep == iVarLastChangeReset + iIrotsPerturbSteps + 1) { 184 | bSwitchMode = TRUE; 185 | iIrotsMode++; 186 | iIrotsLSBestValue = iNumFalse; 187 | fIrotsLSBestValueW = fSumFalseW; 188 | iIrotsLSBestStep = iStep; 189 | } 190 | 191 | break; 192 | 193 | /* mode 2 ==> ongoing local search phase */ 194 | 195 | case 2: 196 | 197 | /* keep track of the 'step' with last best improvement */ 198 | 199 | if (bWeighted) { 200 | if (fSumFalseW < fIrotsLSBestValueW) { 201 | fIrotsLSBestValueW = fSumFalseW; 202 | iIrotsLSBestStep = iStep; 203 | } 204 | } else { 205 | if (iNumFalse < iIrotsLSBestValue) { 206 | iIrotsLSBestValue = iNumFalse; 207 | iIrotsLSBestStep = iStep; 208 | } 209 | } 210 | 211 | /* in no improvement past the best in 'esteps' steps, go to perturbation phase */ 212 | 213 | if (iStep == iIrotsLSBestStep + iIrotsEscapeSteps + 1) { 214 | iIrotsMode--; 215 | bSwitchMode = TRUE; 216 | 217 | /* compare current candidate solution against the last 'saved' candidate solution 218 | choose the worst solution with probability (iWp) 219 | if we choose the current solution, 'save' it and continue 220 | otherwise, 'restore' the previously saved solution */ 221 | 222 | if (bWeighted) { 223 | if (fSumFalseW <= fIrotsSavedValueW) { 224 | if (RandomProb(iIrotsNoise)) { 225 | bRestore = TRUE; 226 | } else { 227 | bSave = TRUE; 228 | } 229 | } else { 230 | if (RandomProb(iIrotsNoise)) { 231 | bSave = TRUE; 232 | } else { 233 | bRestore = TRUE; 234 | } 235 | } 236 | } else { 237 | if (iNumFalse <= iIrotsSavedValue) { 238 | if (RandomProb(iIrotsNoise)) { 239 | bRestore = TRUE; 240 | } else { 241 | bSave = TRUE; 242 | } 243 | } else { 244 | if (RandomProb(iIrotsNoise)) { 245 | bSave = TRUE; 246 | } else { 247 | bRestore = TRUE; 248 | } 249 | } 250 | } 251 | } 252 | 253 | break; 254 | } 255 | 256 | /* if switching modes, then set IRoTS parameters appropriately */ 257 | 258 | if (bSwitchMode) { 259 | iVarLastChangeReset = iStep; 260 | 261 | if (iIrotsMode == 1) { 262 | iTabuTenureLow = iPerturbTabuTenureLow; 263 | iTabuTenureHigh = iPerturbTabuTenureHigh; 264 | iTabuTenure = iPerturbTabuTenure; 265 | } else { 266 | iTabuTenureLow = iLSTabuTenureLow; 267 | iTabuTenureHigh = iLSTabuTenureHigh; 268 | iTabuTenure = iLSTabuTenure; 269 | } 270 | 271 | /* choose the tabu tenure uniformly from the tabu range */ 272 | 273 | if (iTabuTenureLow != iTabuTenureHigh) { 274 | iTabuTenure = iTabuTenureLow + RandomInt(iTabuTenureHigh - iTabuTenureLow); 275 | } 276 | } 277 | 278 | if (bSave) { 279 | 280 | IRoTSBackup(); 281 | 282 | if (bWeighted) { 283 | fIrotsSavedValueW = fSumFalseW; 284 | } else { 285 | iIrotsSavedValue = iNumFalse; 286 | } 287 | } 288 | 289 | if (bRestore) { 290 | 291 | IRoTSRestore(); 292 | 293 | /* after restoring the variables, we must reset all state information */ 294 | 295 | RunProcedures2(InitStateInfo); 296 | RunProcedures2(PostInit); 297 | } 298 | 299 | } 300 | 301 | 302 | void CreateIRoTSBackup() { 303 | aIrotsBackup = AllocateRAM((iNumVars+1)*sizeof(UINT32)); 304 | } 305 | 306 | void IRoTSBackup() { 307 | UINT32 j; 308 | for (j=1;j<=iNumVars;j++) { 309 | aIrotsBackup[j] = aVarValue[j]; 310 | } 311 | } 312 | 313 | void IRoTSRestore() { 314 | UINT32 j; 315 | for (j=1;j<=iNumVars;j++) { 316 | aVarValue[j] = aIrotsBackup[j]; 317 | } 318 | } 319 | 320 | -------------------------------------------------------------------------------- /revisions.txt: -------------------------------------------------------------------------------- 1 | 2 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 3 | ## ## ## ## ## $$ $$ $$ $$ 4 | ## ## ##### ## $$$$ $$$$$$ $$ 5 | ## ## ## ## ## $$ $$ $$ $$ 6 | #### ##### ##### $$$$$ $$ $$ $$ 7 | ====================================================== 8 | SLS SAT Solver from The University of British Columbia 9 | ====================================================== 10 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 11 | ------------------------------------------------------ 12 | ... project website: http://www.satlib.org/ubcsat .... 13 | ------------------------------------------------------ 14 | 15 | 16 | ====================== 17 | Future Planned Changes 18 | ====================== 19 | 20 | * Expect several new algorithm implementations with version 1.2 21 | - if there is an algorithm you'd like to see, let us know :) 22 | 23 | ------------------------ 24 | Changes in version 1.1.0 25 | ------------------------ 26 | 27 | BUG BUG BUG 28 | INTRO | FIXED | DESCRIPTION 29 | 30 | 1.0.0 1.1.0 Stats & RTD reports can cause crash when no (-r out) specified with a steps column 31 | 1.0.0 1.1.0 RTDs with search steps > 2^31 weren't sorted properly: (un)signed int issue 32 | 1.0.0 1.1.0 The RTD report could be incorrect if non -cutoff termination is used (-timeout, -noimprove) and <100% success 33 | 1.0.0 1.1.0 Wrong heuristic trigger for weighted adaptive nov+ [-alg adaptnovelty+ -w] 34 | 1.0.0 1.1.0 Score miscalculation in [-alg novelty(+) -w] and [-alg walksat-tabu -w] 35 | 1.0.0 1.1.0 Std. Deviation statistic miscalculation for row stats (not col. stats) 36 | 1.0.0 1.1.0 Some stats (example: VarFlipCounts) would only count from last restart 37 | 38 | 39 | * code cleanup: Major changes to all help messages, now specific parameter verbose/terse messages req'd 40 | * code cleanup: Method for adding column statistics has been changed / simplified 41 | 42 | * parameter change: -prestart is now -srestart \ 43 | * parameter change: -rrestart is now -prestart } sorry about the confusion 44 | * parameter change: -srestart is now -drestart / 45 | * parameter change: -varinit is now -varinitfile 46 | * parameter change: -timeout is now -gtimeout 47 | 48 | * parameter change: -timeout is now seconds per run, -gtimeout is total seconds for all runs 49 | * parameter change: you can now specify max as a parameter value for the cutoff i.e.: -cutoff max 50 | * parameter change: you can now specify parameters as a factor of the # vars, i.e.: -srestart 100n 51 | * parameter change: -varinitgreedy is now deterministic 52 | 53 | * report change: report "best" has been renamed "bestsol" 54 | * report change: report "unsatclauses" now prints for unsuccessful runs, and has a new paramter 55 | * report change: the default statistics provided have been modified slightly 56 | * column change: column/stat "time" has been renamed "timesteps" 57 | 58 | * new algorithm: "DDFW" (-alg ddfw) 59 | * new algorithm: "G2WSat" (-alg g2wsat) 60 | * new algorithm: "Novelty++" (-alg novelty++) 61 | * new algorithm: "PAWS" (-alg paws) 62 | * new algorithm: "random walk" (-alg urwalk) 63 | * new algorithm: "conflict-directed random walk" (-alg crwalk) 64 | * new algorithm: "Deterministic crwalk" (-alg dcrwalk) 65 | * new algorithm: "Deterministic Adaptive Novelty+" (-alg danovp) 66 | * new algorithm: "RGSAT" (-alg rgsat) 67 | * new algorithm: "Novelty+p" (-alg novelty+p) 68 | * new algorithm: "G2WSAT+p" (-alg g2wsat+p) 69 | * new algorithm: "Adaptive G2WSAT" (-alg adaptg2wsat) 70 | * new algorithm: "Adaptive G2WSAT+p" (-alg adaptg2wsat+p) 71 | * new algorithm: "VW1" (-alg vw1) 72 | * new algorithm: "VW2" (-alg vw2) 73 | 74 | * new algorithm variant: "Schoening's Algorithm" (-alg -crwalk -v schoening) 75 | * new algorithm variant: "SAPS/WInit" (-alg -saps -w -v winit) 76 | * new algorithm variant: "SAPS/WSmooth" (-alg -saps -w -v wsmooth) 77 | * new algorithm variant: "Paramaterized Adaptive Novelty+" (-alg adaptnovelty+ -v params) 78 | 79 | * new report: "Penalty report" (-r penalty) 80 | * new report: "Penalty Mean report" (-r penmean) 81 | * new report: "Penalty Stddev report" (-r penstddev) 82 | * new report: "Penalty CV report" (-r pencv) 83 | * new report: "Mobility" (-r mobility) 84 | * new report: "Mobility - Fixed Window" (-r mobfixed) 85 | * new report: "Mobility - Fixed Window Frequency" (-r mobfixedfreq) 86 | * new report: "Auto-Correlation-Length" (-r autocorr) 87 | * new report: "Unique solutions" (-r uniquesol) 88 | * new report: "Best Step Solution Quality" (-r beststep) 89 | * new report: "Trajectory Best Local Minima" (-r tbestlm) 90 | * new report: "False Histogram" (-r falsehist) 91 | * new report: "Distance" (-r distance) 92 | * new report: "Distance Histogram" (-r disthist) 93 | * new report: "Bias Counts" (-r biascount) 94 | * new report: "Triggers" (-r triggers) 95 | 96 | * new column: "Time in seconds, measured" (time) 97 | * new column: "# of Local Minima Encountered" (localmins) 98 | * new column: "% of steps in Local Minima" (percentlocal) 99 | * new column: "Distance to known solutions(s)" (soldistance) 100 | * new column: "Fitness-Distance Correlation Factor" (fdc) 101 | * new column: "Auto-Correlation Length" (acl) 102 | * new column: "Auto-Correlation of distance one" (acone) 103 | * new column: "Estimated Auto-Correlation Length from AC of 1" (estacl) 104 | * new column: "Mean Mobility of window size n (# vars)" (mobn) 105 | * new column: "Mean Mobility of window size x" (mobx) 106 | * new column: "Normalized Mean Mobility for window size n" (normmobn) 107 | * new column: "Normalized Mean Mobility of window size x" (normmobx) 108 | * new column: "Mobility C.V. for window size n" (mobncv) 109 | * new column: "Mobility C.V. for window size x" (mobxcv) 110 | * new column: "Average (Mean) # of False Clauses" (qualmean[_w]) 111 | * new column: "Std.Dev. # of False Clauses" (qualstddev[_w]) 112 | * new column: "Coeff. of Var. # of False Clauses" (qualcv[_w]) 113 | * new column: "Number of Restarts" (restarts) 114 | * new column: "Worst solution encountered" (worst[_w]) 115 | * new column: "Last solution encountered" (last[_w]) 116 | * new column: "First solution encountered" (start[_w]) 117 | * new column: "Mean Improvement per Step to Best Solution" (bestavgimpr[_w]) 118 | * new column: "First Local Minimum - # of False Clauses" (firstlm[_w]) 119 | * new column: "Step of the First Local Minimum Encountered" (firstlmstep[_w]) 120 | * new column: "Improvement from Start to First LM / Impr. to Best" (firstlmratio[_w]) 121 | * new column: "Mean of the Trajectory Best LM" (tbestlmmean[_w]) 122 | * new column: "C.V. of the Trajectory Best LM" (tbestlmcv[_w]) 123 | * new column: "Number of up steps" (upsteps) 124 | * new column: "Percent of up steps" (percentup[_w]) 125 | * new column: "Number of down steps" (downsteps) 126 | * new column: "Percent of down steps" (percentdown[_w]) 127 | * new column: "Number of side steps" (sidesteps) 128 | * new column: "Percent of side steps" (percentside[_w]) 129 | * new column: "Random Decisions Per Step" (randstep) 130 | * new column: "CV of the Variable Flip Count Distribution" (flipcountcv) 131 | * new column: "CV of the Clause Unsat Count Distribution" (unsatcountcv) 132 | * new column: "Mean Branching Factor" (branchfact[_w]) 133 | * new column: "Mean Bias - Max" (biasmax) 134 | * new column: "Mean Bias - Final" (biasfinal) 135 | 136 | * new statistic: added the number of runs executed (runs) 137 | * new statistic: added the number of successful runs (numsolve) 138 | * new statistic: added the name of the instance file (instname) 139 | * new statistic: added the algorithm parameters (alginfo) 140 | * new statistic: added the number of unique solutions found (numunique) 141 | * new statistic: added the version of UBCSAT (version) 142 | * new statistic: added a statistic for the agemean column example in the mylocal.c (thanks to FH) 143 | * new stat field: added var+stderr+vmr+sum 144 | * new stat field: added stepmean 145 | * new stat field: added solvemean+solvemedian+solvemin+solvemax 146 | * new stat field: added failmean+failmedian+failmin+failmax 147 | 148 | * new parameter: -filesoln specifies a file of known solutions for analysis & measuring FDC, solution distance, etc. 149 | * new parameter: -filerand specifies a file to read random bits from (instead of PRNG) 150 | * new parameter: -fileabort specifies a file that can be created to abort the current job 151 | * new parameter: -findunique is like -find, except it only counts unique solutions 152 | * new parameter: -rflush will flush out all output buffers between runs 153 | 154 | * new function: CalculateStats() & CorrelationCoeff() 155 | * new function: ActivateTriggers() & DeActivateTriggers() for explicit activation 156 | 157 | * new file: ddfw.c 158 | * new file: g2wsat.c 159 | * new file: random.c 160 | * new file: paws.c 161 | * new file: derandomized.c 162 | 163 | * new data type: VARSTATE is an array of bytes to store variable state information 164 | * new data type: VARSTATELIST is a linked list of VARSTATEs 165 | 166 | * code cleanup: all globals are now initialized in SetupUBCSAT() -- allows for multiple calls to ubcsatmain() 167 | * code cleanup: ReadCNF() is now more robust w.r.t. invalid files, comments, etc. 168 | * code cleanup: columns are now only allocated RAM when necessary (for medians, etc.) 169 | * code cleanup: many weighted [_w] columns and statistics fail for unweighted algorithms 170 | * code cleanup: all columns and statistics for weighted instances now end in [_w] 171 | * code cleanup: added field bSpecialFileIO to REPORT for reports with "special" i/o requirements 172 | * code cleanup: moved all (pClause++) elements outside of loops (bug fix) 173 | * code cleanup: removed warning for failed activation of already disabled trigger 174 | * code cleanup: changed default report for gwsat to default (was wdefault) 175 | * code cleanup: Typo: WalkSatSKC was incorrectly coded as SKG (too many Dreamworks movies ;) 176 | * code cleanup: UpdateBestFalse & UpdateSaveBest were moved from PostFlip to PostStep 177 | * code cleanup: Now All parameters have a terse & verbose description 178 | * code cleanup: IsLocalMinimum() now takes an argument for weighted algorithms as well 179 | * code cleanup: "," can now be used to separate parameters instead of "|" (looks cleaner) 180 | * code cleanup: IRoTS algorithms modified re: maintaining previous state information 181 | * code cleanup: the "best[_w]" columns no longer require the "BestFalse" trigger 182 | * code cleanup: renamed ActivateTrigger to ActivateTriggerID (and ActivateStat, etc...) 183 | * code cleanup: changed code to use the constant FLOATZERO 184 | * code cleanup: increased MAXCNFLINELEN 185 | * code cleanup: CopyParameters() now adds to the end of the list instead of replacing it 186 | 187 | ------------------------ 188 | Changes in version 1.0.0 189 | ------------------------ 190 | 191 | * The changes in 1.0.0 (from 0.9.7) are far too numerous to list 192 | 193 | * consult the archive section of the website for older revisions 194 | 195 | -------------------------------------------------------------------------------- /src/ubcsat-globals.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ## ## ##### ##### $$$$$ $$$$ $$$$$$ 4 | ## ## ## ## ## $$ $$ $$ $$ 5 | ## ## ##### ## $$$$ $$$$$$ $$ 6 | ## ## ## ## ## $$ $$ $$ $$ 7 | #### ##### ##### $$$$$ $$ $$ $$ 8 | ====================================================== 9 | SLS SAT Solver from The University of British Columbia 10 | ====================================================== 11 | ...Developed by Dave Tompkins (davet [@] cs.ubc.ca)... 12 | ------------------------------------------------------ 13 | .......consult legal.txt for legal information........ 14 | ......consult revisions.txt for revision history...... 15 | ------------------------------------------------------ 16 | ... project website: http://www.satlib.org/ubcsat .... 17 | ------------------------------------------------------ 18 | .....e-mail ubcsat-help [@] cs.ubc.ca for support..... 19 | ------------------------------------------------------ 20 | 21 | */ 22 | 23 | /***** UBCSAT GLOBAL VARIABLES *****/ 24 | /* 25 | sAlgName name of current algorithm 26 | sVarName variant name of current algorithm 27 | bWeighted does the current algorithm use weighted clauses? 28 | 29 | pActiveAlgorithm the active algorithm for this session of UBCSAT 30 | 31 | iNumRuns total number of runs 32 | iCutoff step cutoff for each run 33 | fTimeOut timeout per runs in seconds 34 | fGlobalTimeOut timeout for all runs in seconds 35 | iSeed initial seed for the system 36 | 37 | iTarget target solution quality (# of false clauses) 38 | fTargetW weighted target solution quality (sum of false clause weights) 39 | 40 | iFlipCandidate current variable to flip 41 | 42 | iFind total number of solutions to find 43 | iNumSolutionsFound number of solutions found so far 44 | 45 | iFindUnique # of unique solutions to find 46 | 47 | iPeriodicRestart restart each run every iPeriodicRestart steps 48 | iProbRestart restart with a probability 49 | iStagnateRestart restart if no improvement in iStagnateRestart steps 50 | 51 | bRestart flag to restart the current run 52 | 53 | iRun current run number 54 | iStep current step number 55 | 56 | bTerminateAllRuns flag to terminate all runs 57 | bSolutionFound flag to indicate target solution quality found this run 58 | bTerminateRun flag to terminate this run 59 | 60 | bSolveMode flag to indicate "solve mode" 61 | 62 | sFilenameIn file name of instance 63 | sFilenameParms file name of current parameter file (note, can be multiple files) 64 | sFilenameVarInit file name of variable initialization file 65 | 66 | bReportEcho flag to set all file output to screen 67 | bReportFlush flush all reports before each run 68 | bReportClean flag to remove headers from output 69 | 70 | iBestScore value of best score improvement this step 71 | fBestScore value of best weighted score improvement this step 72 | */ 73 | 74 | extern const char sNull; 75 | 76 | extern char *sAlgName; 77 | extern char *sVarName; 78 | extern BOOL bWeighted; 79 | 80 | extern ALGORITHM *pActiveAlgorithm; 81 | 82 | extern UINT32 iNumRuns; 83 | extern UINT32 iCutoff; 84 | extern FLOAT fTimeOut; 85 | extern FLOAT fGlobalTimeOut; 86 | extern UINT32 iSeed; 87 | 88 | extern UINT32 iTarget; 89 | extern FLOAT fTargetW; 90 | 91 | extern UINT32 iFlipCandidate; 92 | 93 | extern UINT32 iFind; 94 | extern UINT32 iNumSolutionsFound; 95 | extern UINT32 iFindUnique; 96 | extern UINT32 iPeriodicRestart; 97 | extern PROBABILITY iProbRestart; 98 | extern UINT32 iStagnateRestart; 99 | 100 | extern BOOL bRestart; 101 | 102 | extern UINT32 iRun; 103 | extern UINT32 iStep; 104 | 105 | extern BOOL bTerminateAllRuns; 106 | extern BOOL bSolutionFound; 107 | extern BOOL bTerminateRun; 108 | 109 | extern BOOL bSolveMode; 110 | 111 | extern char *sFilenameIn; 112 | extern char *sFilenameParms; 113 | extern char *sFilenameVarInit; 114 | 115 | extern BOOL bReportEcho; 116 | extern BOOL bReportClean; 117 | extern BOOL bReportFlush; 118 | 119 | extern SINT32 iBestScore; 120 | extern FLOAT fBestScore; 121 | 122 | 123 | /***** UBCSAT GLOBAL ROUTINES *****/ 124 | 125 | /* 126 | CreateAlgorithm() add a new algorithm to the UBCSAT system 127 | */ 128 | 129 | ALGORITHM *CreateAlgorithm (const char *sName, const char *sVariant, BOOL bWeighted, 130 | const char *sDescription, 131 | const char *sAuthors, 132 | const char *sHeuristicTriggers, 133 | const char *sDataTriggers, 134 | const char *sDefaultOutput, 135 | const char *sDefaultStats); 136 | 137 | 138 | /* 139 | CopyParameters() copy the parameters from one algorithm to another 140 | */ 141 | 142 | void CopyParameters(ALGORITHM *pDest, const char *sName, const char *sVar, BOOL bWeighted); 143 | 144 | /* 145 | InheritDataTriggers() copy the data triggers from one algorithm to another 146 | */ 147 | 148 | void InheritDataTriggers(ALGORITHM *pDest, const char *sName, const char *sVar, BOOL bWeighted); 149 | 150 | /* 151 | CreateTrigger() add a new trigger to the UBCSAT system 152 | */ 153 | 154 | void CreateTrigger(const char *sID, 155 | enum EVENTPOINT eEventPoint, 156 | FXNPTR pProcedure, 157 | char *sDependencyList, 158 | char *sDeactivateList); 159 | 160 | /* 161 | CreateContainerTrigger() add a new container trigger to the UBCSAT system 162 | */ 163 | 164 | void CreateContainerTrigger(const char *sID, const char *sList); 165 | 166 | 167 | /* 168 | ActivateTriggers() Explicitly Activate specific trigger(s) [not normally necessary] 169 | */ 170 | 171 | void ActivateTriggers(char *sTriggers); 172 | 173 | /* 174 | DeActivateTriggers() Explicitly DeActivate specific trigger(s) [not normally necessary] 175 | */ 176 | 177 | void DeActivateTriggers(char *sTriggers); 178 | 179 | 180 | /* 181 | AddParm????() adds a parameter to an algorithm (many different types) 182 | */ 183 | 184 | 185 | void AddParmProbability(ALGPARMLIST *pParmList, 186 | const char *sSwitch, 187 | const char *sName, 188 | const char *sDescription, 189 | const char *sTriggers, 190 | PROBABILITY *pProb, 191 | FLOAT fProb); 192 | 193 | void AddParmUInt(ALGPARMLIST *pParmList, 194 | const char *sSwitch, 195 | const char *sName, 196 | const char *sDescription, 197 | const char *sTriggers, 198 | UINT32 *pInt, 199 | UINT32 iDefInt); 200 | 201 | void AddParmSInt(ALGPARMLIST *pParmList, 202 | const char *sSwitch, 203 | const char *sName, 204 | const char *sDescription, 205 | const char *sTriggers, 206 | SINT32 *pSInt, 207 | SINT32 iDefSInt); 208 | 209 | void AddParmBool(ALGPARMLIST *pParmList, 210 | const char *sSwitch, 211 | const char *sName, 212 | const char *sDescription, 213 | const char *sTriggers, 214 | UINT32 *pBool, 215 | BOOL bDefBool); 216 | 217 | void AddParmFloat(ALGPARMLIST *pParmList, 218 | const char *sSwitch, 219 | const char *sName, 220 | const char *sDescription, 221 | const char *sTriggers, 222 | FLOAT *pFloat, 223 | FLOAT fDefFloat); 224 | 225 | void AddParmString(ALGPARMLIST *pParmList, 226 | const char *sSwitch, 227 | const char *sName, 228 | const char *sDescription, 229 | const char *sTriggers, 230 | char **pString, 231 | char *sDefString); 232 | 233 | 234 | /* 235 | CreateReport() add a new report to the system 236 | */ 237 | 238 | REPORT *CreateReport(const char *sID, 239 | const char *sDescription, 240 | const char *sVerboseDescription, 241 | const char *sOutputFile, 242 | const char *sTriggers); 243 | 244 | /* 245 | AddReportParm???() add a parameter to a report 246 | */ 247 | 248 | void AddReportParmUInt(REPORT *pRep, const char *sParmName, UINT32 *pParmValUInt, UINT32 iDefault); 249 | void AddReportParmFloat(REPORT *pRep, const char *sParmName, FLOAT *pParmValFloat, FLOAT fDefault); 250 | void AddReportParmString(REPORT *pRep, const char *sParmName, const char *pDefault); 251 | 252 | /* 253 | AddColumn????() add a column of data for output & rtd reports 254 | */ 255 | 256 | void AddColumnUInt(const char *sID, 257 | const char *sDescription, 258 | char *sHeader1, 259 | char *sHeader2, 260 | char *sHeader3, 261 | char *sPrintFormat, 262 | UINT32 *pCurValue, 263 | char *sTriggers, 264 | enum COLTYPE eColType); 265 | 266 | void AddColumnFloat(const char *sID, 267 | const char *sDescription, 268 | char *sHeader1, 269 | char *sHeader2, 270 | char *sHeader3, 271 | char *sPrintFormat, 272 | FLOAT *pCurValue, 273 | char *sTriggers, 274 | enum COLTYPE eColType); 275 | 276 | void AddColumnComposite(const char *sID, 277 | const char *sList); 278 | 279 | /* 280 | AddStatCol() add a column statistic, providing stats on columns of data 281 | */ 282 | 283 | void AddStatCol(const char *sID, 284 | const char *sBaseDescription, 285 | const char *sDefParm, 286 | BOOL bSortByStep); 287 | 288 | void AddContainerStat(const char *sID, 289 | const char *sList); 290 | 291 | /* 292 | AddStatCustom() add a custom statistic, which can be calculated via triggers 293 | */ 294 | 295 | void AddStatCustom(const char *sID, 296 | const char *sCustomDescription, 297 | const char *sBaseDescription, 298 | const char *sPrintCustomFormat, 299 | void *pCurValue, 300 | enum CDATATYPE eCustomType, 301 | const char *sDataColumn, 302 | const char *sTriggers); 303 | 304 | 305 | /* 306 | IsLocalMinimum() returns TRUE if currently in a local minimum 307 | */ 308 | 309 | BOOL IsLocalMinimum(BOOL bUseWeighted); 310 | 311 | --------------------------------------------------------------------------------