-
Notifications
You must be signed in to change notification settings - Fork 11
/
paws.c
263 lines (183 loc) · 6.75 KB
/
paws.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*
## ## ##### ##### $$$$$ $$$$ $$$$$$
## ## ## ## ## $$ $$ $$ $$
## ## ##### ## $$$$ $$$$$$ $$
## ## ## ## ## $$ $$ $$ $$
#### ##### ##### $$$$$ $$ $$ $$
======================================================
SLS SAT Solver from The University of British Columbia
======================================================
...Developed by Dave Tompkins (davet [@] cs.ubc.ca)...
------------------------------------------------------
.......consult legal.txt for legal information........
......consult revisions.txt for revision history......
------------------------------------------------------
... project website: http://www.satlib.org/ubcsat ....
------------------------------------------------------
.....e-mail ubcsat-help [@] cs.ubc.ca for support.....
------------------------------------------------------
*/
#include "ubcsat.h"
void PickPAWS();
void PostFlipPAWS();
UINT32 iPAWSMaxInc;
PROBABILITY iPAWSFlatMove;
UINT32 iPawsSmoothCounter;
/***** Trigger PenClauseList *****/
void CreatePenClauseList();
void InitPenClauseList();
UINT32 *aPenClauseList;
UINT32 *aPenClauseListPos;
UINT32 iNumPenClauseList;
void CreatePenClauseList() {
aPenClauseList = AllocateRAM(iNumClauses*sizeof(UINT32));
aPenClauseListPos = AllocateRAM(iNumClauses*sizeof(UINT32));
}
void InitPenClauseList() {
iNumPenClauseList = 0;
iPawsSmoothCounter = 0;
}
void AddPAWS() {
ALGORITHM *pCurAlg;
pCurAlg = CreateAlgorithm("paws","",FALSE,
"PAWS: Pure Additive Weighting Scheme",
"Thornton, Pham, Bain, Ferreira [AAAI 04]",
"PickPAWS,PostFlipPAWS",
"DefaultProcedures,Flip+MBPINT+FCL+VIF,PenClauseList",
"default","default");
AddParmUInt(&pCurAlg->parmList,"-maxinc","frequency of penalty reductions [default %s]","reduce (smooth) all clause penalties by 1~after every INT increases","",&iPAWSMaxInc,10);
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);
CreateTrigger("PickPAWS",ChooseCandidate,PickPAWS,"","");
CreateTrigger("PostFlipPAWS",PostFlip,PostFlipPAWS,"","");
CreateTrigger("CreatePenClauseList",CreateStateInfo,CreatePenClauseList,"","");
CreateTrigger("InitPenClauseList",InitStateInfo,InitPenClauseList,"","");
CreateContainerTrigger("PenClauseList","CreatePenClauseList,InitPenClauseList");
}
void PickPAWS() {
UINT32 j;
UINT32 iVar;
SINT32 iScore;
SINT32 iBestScore;
UINT32 iLoopEnd;
iNumCandidates = 0;
iBestScore = SINT32MAX;
/* look at all variables that appear in false clauses */
for (j=0;j<iNumVarsInFalseList;j++) {
iVar = aVarInFalseList[j];
/* use cached value of breakcount - makecount */
iScore = aBreakPenaltyINT[iVar] - aMakePenaltyINT[iVar];
/* build candidate list of best vars */
if (iScore <= iBestScore) {
if (iScore < iBestScore) {
iNumCandidates = 0;
iBestScore = iScore;
}
/* using the "Monte Carlo" method, each variable appears
'Make Count' times in the candidate list */
iLoopEnd = iNumCandidates + aMakeCount[iVar];
if (iLoopEnd >= iMaxCandidates) {
ReportPrint1(pRepErr,"Unexpected Error: increase iMaxCandidates [%u]\n",iMaxCandidates);
AbnormalExit();
}
while (iNumCandidates < iLoopEnd) {
aCandidateList[iNumCandidates++] = iVar;
}
}
}
iFlipCandidate = 0;
if (iBestScore < 0) {
/* if improving step can be made, select flip candidate uniformly from candidate list */
if (iNumCandidates > 1) {
iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)];
} else {
iFlipCandidate = *aCandidateList;
}
} else {
if (iBestScore == 0) {
/* if a flat / sideways step can be made, with probability (iPAWSFlatMove)
flip candidate from candidate list, otherwise it's a null flip */
if (RandomProb(iPAWSFlatMove)) {
if (iNumCandidates > 1) {
iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)];
} else {
iFlipCandidate = *aCandidateList;
}
}
}
}
}
void SmoothPAWS() {
UINT32 j;
UINT32 k;
UINT32 iClause;
UINT32 iLoopMax;
LITTYPE *pLit;
/* Because iNumPenClauseList can change, keep track of # Initial Clauses in list */
iLoopMax = iNumPenClauseList;
/* Each clause penalty is going down by one, so total is going down by # clauses */
iTotalPenaltyINT -= iNumPenClauseList;
for (j=0;j<iLoopMax;j++) {
iClause = aPenClauseList[j];
/* decrease the clause penalty by one */
aClausePenaltyINT[iClause]--;
/* if clause penalty is equal to one, remove it from the list of penalized clauses. */
/* Note that moving the 'last' penalty to the current location j
doesn't prevent that other penalty from being adjusted as j loops
all the way to iLoopMax */
if (aClausePenaltyINT[iClause]==1) {
aPenClauseList[aPenClauseListPos[iClause]] = aPenClauseList[--iNumPenClauseList];
aPenClauseListPos[aPenClauseList[iNumPenClauseList]] = aPenClauseListPos[iClause];
}
/* For all false clauses, the 'make' score for each variable in the clause
has to be reduced by one */
if (aNumTrueLit[iClause]==0) {
pLit = pClauseLits[iClause];
for (k=0;k<aClauseLen[iClause];k++) {
aMakePenaltyINT[GetVarFromLit(*pLit)]--;
pLit++;
}
}
/* For critically satisfied clauses, the 'break' score for that critical variable
has to be reduced by one */
if (aNumTrueLit[iClause]==1) {
aBreakPenaltyINT[aCritSat[iClause]]--;
}
}
}
void ScalePAWS() {
UINT32 j;
UINT32 k;
UINT32 iClause;
LITTYPE *pLit;
/* for each false clause, increae the clause penalty by 1 */
iTotalPenaltyINT += iNumFalse;
for(j=0;j<iNumFalse;j++) {
iClause = aFalseList[j];
aClausePenaltyINT[iClause]++;
if (aClausePenaltyINT[iClause]==2) {
/* if the penalty is 2, then add it to the list of penalized clauses */
aPenClauseList[iNumPenClauseList] = iClause;
aPenClauseListPos[iClause] = iNumPenClauseList++;
}
/* The 'make' score for each variable in the clause has to be increased */
pLit = pClauseLits[iClause];
for (k=0;k<aClauseLen[iClause];k++) {
aMakePenaltyINT[GetVarFromLit(*pLit)]++;
pLit++;
}
}
}
void PostFlipPAWS() {
if (iFlipCandidate) {
return;
}
/* if a 'null flip' */
/* Scale penalties */
ScalePAWS();
/* smooth every iPAWSMaxInc Null Flips */
iPawsSmoothCounter++;
if (iPawsSmoothCounter > iPAWSMaxInc) {
SmoothPAWS();
iPawsSmoothCounter = 0;
}
}