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 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
|
/**************************************************************/
/* ********************************************************** */
/* * * */
/* * COMPONENTS OF CLAUSES * */
/* * * */
/* * $Module: COMPONENT * */
/* * * */
/* * Copyright (C) 1996, 1998, 2000, 2001 * */
/* * MPI fuer Informatik * */
/* * * */
/* * This program is free software; you can redistribute * */
/* * it and/or modify it under the terms of the FreeBSD * */
/* * Licence. * */
/* * * */
/* * This program is distributed in the hope that it will * */
/* * be useful, but WITHOUT ANY WARRANTY; without even * */
/* * the implied warranty of MERCHANTABILITY or FITNESS * */
/* * FOR A PARTICULAR PURPOSE. See the LICENCE file * */
/* * for more details. * */
/* * * */
/* * * */
/* $Revision: 1.3 $ * */
/* $State: Exp $ * */
/* $Date: 2011-05-22 12:06:19 $ * */
/* $Author: weidenb $ * */
/* * * */
/* * Contact: * */
/* * Christoph Weidenbach * */
/* * MPI fuer Informatik * */
/* * Stuhlsatzenhausweg 85 * */
/* * 66123 Saarbruecken * */
/* * Email: spass@mpi-inf.mpg.de * */
/* * Germany * */
/* * * */
/* ********************************************************** */
/**************************************************************/
/* $RCSfile: component.c,v $ */
#include "term.h"
#include "component.h"
/**************************************************************
*Previously Inlined Function *
* ***********************************************************/
BOOL literal_GetUsed(CLITERAL C)
{
return C->used;
}
int literal_GetLitIndex(CLITERAL C)
{
return C->litindex;
}
LIST literal_GetLitVarList(CLITERAL C)
{
return C->litvarlist;
}
void literal_PutUsed(CLITERAL C,BOOL Bool)
{
C->used = Bool;
}
void literal_PutLitIndex(CLITERAL C, int I)
{
C->litindex = I;
}
void literal_PutLitVarList(CLITERAL C, LIST L)
{
C->litvarlist = L;
}
CLITERAL litptr_Literal(LITPTR C, intptr_t I)
{
return C->litptr[I];
}
void litptr_SetLiteral(LITPTR LP, int I, CLITERAL CL)
{
LP->litptr[I] = CL;
}
int litptr_Length(LITPTR C)
{
return C->length;
}
void litptr_SetLength(LITPTR C, int n)
{
C->length = n;
}
void litptr_IncLength(LITPTR C)
{
(C->length)++;
}
void literal_Free(CLITERAL Lit)
{
memory_Free(Lit, sizeof(CLITERAL_NODE));
}
/**************************************************************
*Previously Inlined Functions Ends here *
* ***********************************************************/
CLITERAL literal_Create(BOOL used, int literal_index, LIST varlist)
/**********************************************************
INPUT: A boolean used, an integer index and a list varlist.
RETURNS: A LITERAL is created.
MEMORY: The boolean, integer and varlist are no copies.
************************************************************/
{
CLITERAL literal;
literal = (CLITERAL)memory_Malloc(sizeof(CLITERAL_NODE));
literal_PutUsed(literal,used);
literal_PutLitIndex(literal,literal_index);
literal_PutLitVarList(literal,varlist);
return literal;
}
void literal_Delete(CLITERAL literal)
/**********************************************************
INPUT: A literal.
RETURNS: None.
MEMORY: Deletes the LITERAL and frees the storage.
***********************************************************/
{
list_Delete(literal_GetLitVarList(literal));
literal_Free(literal);
}
LITPTR litptr_Create(LIST Indexlist, LIST Termsymblist)
/**********************************************************
INPUT: A list of indexes and a list of terms, i.e. a list of integers.
RETURNS: A LITPTR structure is created.
MEMORY: The integers in the created structure are the integers
in indexList, no copies.
***********************************************************/
{
LITPTR lit_ptr;
LIST Scan,varlist;
CLITERAL literal;
intptr_t literal_index;
int n,k;
n = list_Length(Indexlist);
lit_ptr = (LITPTR)memory_Malloc(sizeof(LITPTR_NODE));
litptr_SetLength(lit_ptr, n);
if (n > 0) {
lit_ptr->litptr = (CLITERAL *)memory_Malloc(n * sizeof(CLITERAL));
k = 0;
for (Scan = Indexlist; !list_Empty(Scan); Scan = list_Cdr(Scan)) {
literal_index = (intptr_t)list_Car(Scan);
varlist = (LIST)list_Car(Termsymblist);
Termsymblist = list_Cdr(Termsymblist);
literal = literal_Create(FALSE,literal_index,varlist);
litptr_SetLiteral(lit_ptr, k, literal);
k++;
}
} else
lit_ptr->litptr = NULL;
return lit_ptr;
}
void litptr_Delete(LITPTR lit_ptr)
/**********************************************************
INPUT: A pointer to LITPTR.
MEMORY: Deletes the LITPTR and frees the storage.
***********************************************************/
{
int n,i;
n = litptr_Length(lit_ptr);
if (n > 0) {
for (i = 0; i < n; i++)
literal_Delete(litptr_Literal(lit_ptr,i));
memory_Free(lit_ptr->litptr, sizeof(CLITERAL) * n);
memory_Free(lit_ptr, sizeof(LITPTR_NODE));
} else
memory_Free(lit_ptr, sizeof(LITPTR_NODE));
}
void litptr_Print(LITPTR lit_ptr)
/**************************************************************
INPUT: A term.
RETURNS: void.
SUMMARY: Prints any term to stdout.
CAUTION: Uses the other term_Output functions.
***************************************************************/
{
int i,n;
n = litptr_Length(lit_ptr);
/*n = lit_ptr->length;*/
if (n > 0) {
printf("\nlength of LITPTR: %d\n",n);
for (i = 0; i < n; i++) {
printf("Entries of literal %d : \n",i);
puts("----------------------");
fputs("used:\t\t", stdout);
if (literal_GetUsed(litptr_Literal(lit_ptr,i)))
/*if (lit_ptr->litptr[i]->used)*/
puts("TRUE");
else
puts("FALSE");
printf("litindex:\t%d\n",
literal_GetLitIndex(litptr_Literal(lit_ptr,i)));
fputs("litvarlist:\t", stdout);
list_Apply((void (*)(POINTER)) symbol_Print,
literal_GetLitVarList(litptr_Literal(lit_ptr,i)));
puts("\n");
}
}else
puts("No entries in litptr structure");
}
BOOL litptr_AllUsed(LITPTR lit_ptr)
/**************************************************************
INPUT: A LITPTR.
RETURNS: TRUE if every literal in the LITPTR is used and
FALSE otherwise.
***************************************************************/
{
int n,i;
n = litptr_Length(lit_ptr);
for (i = 0; i < n; i++)
if (!(literal_GetUsed(litptr_Literal(lit_ptr,i))))
return FALSE;
return TRUE;
}
LIST subs_CompList(LITPTR litptr)
/**********************************************************
INPUT: A pointer litptr.
RETURNS: A list with indexes which represents the first component of
with respect to the actual bindings and to litptr.
CAUTION: The structure to which litptr points to
is changed destructively in the used slot.
***********************************************************/
{
BOOL found,hasinter;
LIST scan,complist,compindexlist;
int n,lit;
intptr_t i,j;
compindexlist = list_Nil(); /* the result will be placed into this list */
complist = list_Nil(); /* added afterwards */
n = litptr_Length(litptr);
if (n > 0) {
for (j = 0; j < n; j++) {
printf("\nj = %zd\n",j);
if (!literal_GetUsed(litptr_Literal(litptr,j))){
complist = list_Nil();
complist = list_Cons((POINTER)j,complist);
compindexlist = list_Cons((POINTER)(litptr->litptr[j]->litindex),
compindexlist);
literal_PutUsed(litptr_Literal(litptr,j), TRUE);
j = n+1;
printf("\nj == %zd\n",j);
}
}
if (j == n){
list_Delete(complist); /* There is no more component */
return compindexlist; /* should be empty here */
}
found = TRUE;
while (found) {
found = FALSE;
for (scan = complist; !list_Empty(scan); scan = list_Cdr(scan)) {
lit = (intptr_t)list_Car(scan);
for (i = 0; i < n; i++) {
if (!literal_GetUsed(litptr_Literal(litptr,i))) {
printf("lit = %d\n",lit);
printf("i = %zd\n",i);
hasinter = list_HasIntersection(litptr->litptr[lit]->litvarlist,
litptr->litptr[i]->litvarlist);
if (hasinter) {
puts("hasinter = TRUE");
complist = list_Cons((POINTER)i,complist);
compindexlist = list_Cons((POINTER)(litptr->litptr[i]->litindex),compindexlist);
literal_PutUsed(litptr_Literal(litptr,i), TRUE);
found = TRUE;
}
}
}
}
if (!found) { /* one component is finished */
list_Delete(complist);
found = FALSE;
}
}
}
return compindexlist;
}
|