-
Notifications
You must be signed in to change notification settings - Fork 11
/
rgsat.c
122 lines (95 loc) · 3.02 KB
/
rgsat.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
/*
## ## ##### ##### $$$$$ $$$$ $$$$$$
## ## ## ## ## $$ $$ $$ $$
## ## ##### ## $$$$ $$$$$$ $$
## ## ## ## ## $$ $$ $$ $$
#### ##### ##### $$$$$ $$ $$ $$
======================================================
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 PickRGSat();
void PickRGSatW();
void AddRGSat() {
ALGORITHM *pCurAlg;
pCurAlg = CreateAlgorithm("rgsat","",FALSE,
"RGSAT: Restarting GSAT (poor algorithm -- academic use only)",
"Tompkins, Hoos [SAIM 04]",
"PickRGSat",
"DefaultProcedures,Flip+VarScore",
"default","default");
CreateTrigger("PickRGSat",CheckRestart,PickRGSat,"","");
pCurAlg = CreateAlgorithm("rgsat","",TRUE,
"RGSAT: Restarting GSAT (poor algorithm -- academic use only) (weighted)",
"Tompkins, Hoos [SAIM 04]",
"PickRGSatW",
"DefaultProceduresW,Flip+VarScoreW",
"default_w","default");
CreateTrigger("PickRGSatW",CheckRestart,PickRGSatW,"","");
}
void PickRGSat() {
UINT32 j;
SINT32 iScore;
iNumCandidates = 0;
iBestScore = iNumClauses;
/* Algorithm is essentially GSAT */
for (j=1;j<=iNumVars;j++) {
iScore = aVarScore[j];
if (iScore <= iBestScore) {
if (iScore < iBestScore) {
iNumCandidates=0;
iBestScore = iScore;
}
aCandidateList[iNumCandidates++] = j;
}
}
/* If improving step possible, select flip candidate uniformly from candidate list */
if (iBestScore < 0) {
if (iNumCandidates > 1) {
iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)];
} else {
iFlipCandidate = aCandidateList[0];
}
} else {
/* Otherwise, restart */
iFlipCandidate = 0;
bRestart = TRUE;
}
}
void PickRGSatW() {
/* weighted varaint -- see regular algorithm for comments */
UINT32 j;
FLOAT fScore;
iNumCandidates = 0;
fBestScore = fTotalWeight;
for (j=1;j<=iNumVars;j++) {
fScore = aVarScoreW[j];
if (fScore <= fBestScore) {
if (fScore < fBestScore) {
iNumCandidates=0;
fBestScore = fScore;
}
aCandidateList[iNumCandidates++] = j;
}
}
if (fBestScore < FLOATZERO) {
if (iNumCandidates > 1) {
iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)];
} else {
iFlipCandidate = aCandidateList[0];
}
} else {
iFlipCandidate = 0;
bRestart = TRUE;
}
}