00001
00002 #ifndef _LAZY_WALKSAT_H_
00003 #define _LAZY_WALKSAT_H_
00004
00005 #include <iostream>
00006 #include <stdio.h>
00007 #include <stdlib.h>
00008 #include <math.h>
00009 #include <sys/time.h>
00010 #include <sys/resource.h>
00011 #include <signal.h>
00012
00013 #include "freestoremanager.h"
00014
00015 #include "array.h"
00016 #include "lwinfo.h"
00017 #include "wsutil.h"
00018 #include "maxwalksatparams.h"
00019 #include "samplesatparams.h"
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 class LazyWalksat
00030 {
00031
00032 int numatom;
00033 int basenumatom;
00034 int numclause;
00035 int numliterals;
00036
00037 int atommem;
00038 int clausemem;
00039
00040 int saRatio;
00041 int temperature;
00042 bool latesa;
00043
00044 int ** clause;
00045
00046 int * cost;
00047 int * size;
00048 int * falseclause;
00049 int * wherefalse;
00050 int * numtruelit;
00051
00052 int ** occurence;
00053
00054
00055 int * numoccurence;
00056 int * newnumoccurence;
00057 int * occurencemem;
00058
00059
00060
00061 int * atom;
00062 int * initatom;
00063
00064 int * lowatom;
00065
00066 int * changed;
00067
00068 int * breakcost;
00069
00070 int numfalse;
00071 int costofnumfalse;
00072
00073
00074 bool costexpected;
00075 bool abort_flag;
00076
00077 int heuristic;
00078 int numerator;
00079 int denominator;
00080 int tabu_length;
00081
00082 long int numflip;
00083 long int numnullflip;
00084
00085
00086 int highestcost;
00087 int eqhighest;
00088 int numhighest;
00089
00090 bool hard;
00091
00092 bool noApprox;
00093
00094 FreeStoreManager *clauseFSMgr;
00095 int clauseFreeStore;
00096 int *clauseStorePtr;
00097
00098 FreeStoreManager *atomFSMgr;
00099 int atomFreeStore;
00100 int *atomStorePtr;
00101
00102 Array<Array<int> *> allClauses;
00103 Array<int> allClauseWeights;
00104 Array<Array<int> *> newClauses;
00105 Array<int> newClauseWeights;
00106
00107
00108 Array<IntClause *> supersetClauses_;
00109
00110
00111
00112 bool * fixedAtoms_;
00113 int maxFixedAtoms;
00114
00115 LWInfo *lwInfo;
00116
00117
00118 int memLimit;
00119
00120 int clauseLimit;
00121
00122 bool haveDeactivated;
00123
00124 int initClauseCount;
00125
00126 int initAtomCount;
00127
00128 public:
00129
00130 LazyWalksat(LWInfo *lwInfo, int memLimit);
00131
00132 ~LazyWalksat();
00133
00134
00135 bool sample(const MaxWalksatParams* const & mwsParams,
00136 const SampleSatParams& sampleSatParams,
00137 const bool& initial);
00138
00139
00140 void infer(const MaxWalksatParams* const & params,
00141 const int& numSolutions, const bool& includeUnsatSolutions,
00142 Array<Array<bool>*>& solutions, Array<int>& numBad,
00143 const bool& initial);
00144
00145 int getNumInitClauses();
00146
00147 int getNumInitAtoms();
00148
00149 int getNumClauses();
00150
00151 void resetSampleSat();
00152
00153 void randomizeActiveAtoms();
00154
00155 private:
00156
00157
00158 void init();
00159
00160
00161 void initrun(void);
00162
00163
00164 void fix(int tofix);
00165
00166
00167 void addNewClauses(bool initial);
00168
00169
00170 void trimClauses();
00171
00172
00173 void removeAllNullFromArray(int array[]);
00174
00175
00176 void initializeBreakCost(int startclause);
00177
00178
00179
00180
00181 void initializeClauseMemory();
00182
00183
00184 void initializeAtomMemory();
00185
00186
00187 void allocateClauseMemory(int allocCount);
00188
00189
00190 void allocateAtomMemory(int allocCount);
00191
00192
00193 void deleteClauseMemory();
00194
00195
00196 void deleteAtomMemory();
00197
00198
00199
00200 int getTotalWeight(Array<int> &clauseWeights);
00201
00202
00203 void flipatom(int toflip);
00204
00205 int selecthigh(int);
00206
00207 double elapsed_seconds(void);
00208 int countunsat(void);
00209 void countlowunsatcost( int *, int *);
00210 void scanone(int argc, char *argv[], int i, int *varptr);
00211
00212 int pickrandom(int *numbreak,int clausesize, int tofix);
00213 int pickproductsum(int *numbreak,int clausesize, int tofix);
00214 int pickreciprocal(int *numbreak,int clausesize, int tofix);
00215 int pickadditive(int *numbreak,int clausesize, int tofix);
00216 int pickbest(int *numbreak,int clausesize, int tofix);
00217 int picktabu(int *numbreak,int clausesize, int tofix);
00218 int pickexponential(int *numbreak,int clausesize, int tofix);
00219 int pickzero(int *numbreak,int clausesize);
00220 int pickweight(int *weight,int clausesize);
00221
00222 bool simAnnealing();
00223
00224 void undoFixedAtoms();
00225 void initFixedAtoms(Array<Array<int> *> &clauses,
00226 Array<int> &clauseWeights);
00227
00228 void print_false_clauses_cost(long int lowbad);
00229 void print_low_assign(long int lowbad);
00230
00231 void printClause(int clause);
00232
00233 void save_low_assign(void);
00234
00235 long super(int i);
00236
00237 };
00238
00239 #endif