File: cpr_dpll.c

package info (click to toggle)
eprover 2.6%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 21,288 kB
  • sloc: ansic: 331,111; csh: 12,026; python: 10,178; awk: 5,825; makefile: 461; sh: 389
file content (195 lines) | stat: -rw-r--r-- 5,133 bytes parent folder | download | duplicates (2)
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
/*-----------------------------------------------------------------------

File  : cpr_dpll.c

Author: Stephan Schulz

Contents

  Code for the main DPLL algorithm.

Copyright 1998-2011 by the author.
  This code is released under the GNU General Public Licence and
  the GNU Lesser General Public License.
  See the file COPYING in the main E directory for details..
  Run "eprover -h" for contact information.

Changes

<1> Wed May 14 01:56:29 CEST 2003
    New

-----------------------------------------------------------------------*/

#include "cpr_dpll.h"


/*---------------------------------------------------------------------*/
/*                        Global Variables                             */
/*---------------------------------------------------------------------*/


/*---------------------------------------------------------------------*/
/*                      Forward Declarations                           */
/*---------------------------------------------------------------------*/


/*---------------------------------------------------------------------*/
/*                         Internal Functions                          */
/*---------------------------------------------------------------------*/


/*-----------------------------------------------------------------------
//
// Function: deactivate_clauses()
//
//   Deactivete all clauses in *tree and record them on
//   state->decativated. Return number of clauses.
//
// Global Variables: -
//
// Side Effects    : Changes state.
//
/----------------------------------------------------------------------*/

long deactivate_clauses(DPLLState_p state, PTree_p *clauses)
{
   long res = 0;

   return res;
}


/*-----------------------------------------------------------------------
//
// Function: shorten_clauses()
//
//   Shorten all clauses in *tree by one.
//
// Global Variables: -
//
// Side Effects    : Changes state
//
/----------------------------------------------------------------------*/

long shorten_clauses(DPLLState_p state, PTree_p *clauses)
{
   long res = 0;

   return res;
}



/*---------------------------------------------------------------------*/
/*                         Exported Functions                          */
/*---------------------------------------------------------------------*/


/*-----------------------------------------------------------------------
//
// Function: DPLLStateAlloc()
//
//   Allocate an initialized DPLL search state.
//
// Global Variables: -
//
// Side Effects    : Memory operations
//
/----------------------------------------------------------------------*/

DPLLState_p DPLLStateAlloc(DPLLFormula_p form)
{
   DPLLState_p handle = DPLLStateCellAlloc();
   long i, limit;
   DPLLClause_p clause;

   handle->form         = form;
   handle->assignment   = PStackAlloc();
   handle->deactivated  = PStackAlloc();
   handle->unproc_units = PStackAlloc();
   handle->open_atoms   = AtomSetAlloc();

   for(i=1; i<form->atom_no; i++)
   {
      if(form->atoms[i].pos_occur + form->atoms[i].neg_occur)
      {
    AtomSetInsert(handle->open_atoms, i);
      }
   }
   limit = PStackGetSP(form->clauses);
   for(i=0; i<limit; i++)
   {
      clause = PStackElementP(form->clauses, i);
      if(DPLLClauseIsUnit(clause))
      {
    PStackPushP(handle->unproc_units, clause);
      }
   }
   return handle;
}


/*-----------------------------------------------------------------------
//
// Function: DPLLStateFree()
//
//   Free a DPLL search state
//
// Global Variables: -
//
// Side Effects    : Memory operations
//
/----------------------------------------------------------------------*/

void DPLLStateFree(DPLLState_p junk)
{
   PStackFree(junk->assignment);
   PStackFree(junk->deactivated);
   PStackFree(junk->unproc_units);
   AtomSetFree(junk->open_atoms);
   DPLLFormulaFree(junk->form);
   DPLLStateCellFree(junk);
}


/*-----------------------------------------------------------------------
//
// Function: DPLLAssignVar()
//
//   Extend the assignment with the given new propositional variable
//   assignment. Return true if no empty clause has been generated.
//
// Global Variables: -
//
// Side Effects    : Changes state!
//
/----------------------------------------------------------------------*/

bool DPLLAssignVar(DPLLState_p state, PLiteralCode assignment)
{
   bool res = true;
   Atom_p atom;

   PStackPushInt(state->assignment, assignment);
   PStackPushP(state->deactivated, NULL); /* Mark new subset */

   if(assignment > 0)
   {
      atom = &(state->form->atoms[assignment]);
      deactivate_clauses(state, &(atom->pos_active));
      res = shorten_clauses(state, &(atom->neg_active));
   }
   else
   {
      assignment = -assignment;
      atom = &(state->form->atoms[assignment]);
      deactivate_clauses(state, &(atom->pos_active));
      res = shorten_clauses(state, &(atom->neg_active));
   }
   return res;
}

/*---------------------------------------------------------------------*/
/*                        End of File                                  */
/*---------------------------------------------------------------------*/