-
Notifications
You must be signed in to change notification settings - Fork 11
/
gsat-tabu.c
159 lines (116 loc) · 3.89 KB
/
gsat-tabu.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
/*
## ## ##### ##### $$$$$ $$$$ $$$$$$
## ## ## ## ## $$ $$ $$ $$
## ## ##### ## $$$$ $$$$$$ $$
## ## ## ## ## $$ $$ $$ $$
#### ##### ##### $$$$$ $$ $$ $$
======================================================
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"
UINT32 iTabuTenure;
void PickGSatTabu();
void PickGSatTabuW();
void AddGSatTabu() {
ALGORITHM *pCurAlg;
pCurAlg = CreateAlgorithm("gsat-tabu","",FALSE,
"GSAT-TABU: GSAT with Tabu search",
"Mazure, Sais, Gregoire [AAAI 97]",
"PickGSatTabu",
"DefaultProcedures,Flip+VarScore,VarLastChange",
"default","default");
AddParmUInt(&pCurAlg->parmList,"-tabu","tabu tenure [default %s]","variables flipped within the last INT steps are tabu","",&iTabuTenure,10);
CreateTrigger("PickGSatTabu",ChooseCandidate,PickGSatTabu,"","");
pCurAlg = CreateAlgorithm("gsat-tabu","",TRUE,
"GSAT-TABU: GSAT with Tabu search (weighted)",
"Mazure, Sais, Gregoire [AAAI 97]",
"PickGSatTabuW",
"DefaultProceduresW,Flip+VarScoreW,VarLastChange",
"default_w","default");
CopyParameters(pCurAlg,"gsat-tabu","",FALSE);
CreateTrigger("PickGSatTabuW",ChooseCandidate,PickGSatTabuW,"","");
}
void PickGSatTabu() {
UINT32 j;
SINT32 iScore;
UINT32 iTabuCutoff;
/* calculation of tabu cutoff */
if (iStep > iTabuTenure) {
iTabuCutoff = iStep - iTabuTenure;
if (iVarLastChangeReset > iTabuCutoff) {
iTabuCutoff = iVarLastChangeReset;
}
} else {
iTabuCutoff = 1;
}
iNumCandidates = 0;
iBestScore = iNumClauses;
for (j=1;j<=iNumVars;j++) {
/* check score of all non-tabu variables */
if (aVarLastChange[j] < iTabuCutoff) {
/* use cached value of score */
iScore = aVarScore[j];
/* build candidate list of best vars */
if (iScore <= iBestScore) {
if (iScore < iBestScore) {
iNumCandidates=0;
iBestScore = iScore;
}
aCandidateList[iNumCandidates++] = j;
}
}
}
/* select flip candidate uniformly from candidate list */
if (iNumCandidates > 1) {
iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)];
} else {
iFlipCandidate = aCandidateList[0];
}
}
void PickGSatTabuW() {
UINT32 j;
FLOAT fScore;
UINT32 iTabuCutoff;
/* calculation of tabu cutoff */
if (iStep > iTabuTenure) {
iTabuCutoff = iStep - iTabuTenure;
if (iVarLastChangeReset > iTabuCutoff) {
iTabuCutoff = iVarLastChangeReset;
}
} else {
iTabuCutoff = 1;
}
iNumCandidates = 0;
fBestScore = fTotalWeight;
for (j=1;j<=iNumVars;j++) {
/* check score of all non-tabu variables */
if (aVarLastChange[j] < iTabuCutoff) {
/* use cached value of weighted score */
fScore = aVarScoreW[j];
/* build candidate list of best vars */
if (fScore <= fBestScore) {
if (fScore < fBestScore) {
iNumCandidates=0;
fBestScore = fScore;
}
aCandidateList[iNumCandidates++] = j;
}
}
}
/* select flip candidate uniformly from candidate list */
if (iNumCandidates > 1) {
iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)];
} else {
iFlipCandidate = aCandidateList[0];
}
}