int entailmentCheck(Store store, Indexical indexical) /*--------------------------------------------------------------- DESCRIPCION: Implemtacion del algoritmo que chequea la deduccion de un indexicals de la actual configuracion de la bodega de restricciones. PARAMETROS: indexical: Indexical a analizar store : Es el store del Sistema de Restricciones. USA: RETORNA: El estado de la operacion PRE: POS: La Ope = ENTAILED || Ope = SUSPENDED. NOTAS: ---------------------------------------------------------------*/ { int variable_key, aux; Domain x_sigma,r_sigma,I; variable_key=getX(indexical); x_sigma=Inicp1Domain(getDomainFDVariable(getVariableStore(store, variable_key))); r_sigma = r_Sigma(store,indexical); I=Inicp1Domain(x_sigma); intersectionDomain(I,r_sigma); aux=equalsDomain(I,x_sigma); freeDomain(I); freeDomain(x_sigma); freeDomain(r_sigma); if(aux) return ENTAILED; else return SUSPENDED; }
int basicTell(Store store,Indexicals indexicals, Stamp *s,int *indextemp,FrameConst frmconst) /*--------------------------------------------------------------- DESCRIPCION: Implementacion de la operacion basica tell sobre el Sistema de Restricciones. PARAMETROS: frmconst es la representacion de una restriccion aritmetica como un FrameConst. store : Es el store del Sistema de Restricciones. indexicals: Son los indexicals que representan las restricciones impuestas sobre el store. s: Marca de tiempo para la evaluacion de los indexicals indextemp: Identificador de las variables generaradas por restricciones no lineales. USA: RETORNA: El estado de la operacion PRE: POS: La Ope = FAIL || Ope = SUCCESS. NOTAS: ---------------------------------------------------------------*/ { int variable_key, posIndexical,RV_key, monot_ind, estado; Cola Q; Lista ListaRV; ListaFC ListaIndexNec=inicListaFC(); FDVariable fdvariable; // En la implementacion de la structura. debe estar el puntero Indexical indexical; // En la implementacion de la struct debe estar el puntero. Domain x_sigma, r_sigma, I; // En la implementacion de la struct debe estar el puntero. ListaIndexNec = IndexNecAritToIndex(ListaIndexNec, indextemp, frmconst); for (primListaFC(ListaIndexNec); !finListaFC(ListaIndexNec); sigListaFC(ListaIndexNec)) { indexical = InicpIndexical(infoListaFC(ListaIndexNec),*s); variable_key = getValueFrameConst(getLefSonFrameConst(infoListaFC(ListaIndexNec))); indexicals = addElementIndexicals(indexicals, indexical); posIndexical = sizeIndexicals(indexicals); ListaRV = getVariablesIndexical(indexical); primLista(ListaRV); RV_key = infoLista(ListaRV); if (getVariableStore(store, RV_key)== NULL) { fdvariable = InicpFDVariable(RV_key,*s,indexicals); store = insertVariableStore(store, RV_key, fdvariable); freeFDVariable(fdvariable); } /*Crea las variables que aparezcan en el rango del indexical y que no existan en el store*/ for ( sigLista(ListaRV); !finLista(ListaRV); sigLista(ListaRV)) { RV_key = infoLista(ListaRV); if (getVariableStore(store, RV_key)== NULL) { fdvariable = InicpFDVariable(RV_key,*s,indexicals); store = insertVariableStore(store, RV_key, fdvariable); freeFDVariable(fdvariable); } else updateDepFDVariable(getVariableStore(store, RV_key),posIndexical,indexical,RV_key); } destruirLista(ListaRV); /* Realizacion del TELL sobre el store */ x_sigma = Inicp1Domain(getDomainFDVariable(getVariableStore(store, variable_key))); r_sigma =r_Sigma(store,indexical); I = Inicp1Domain(x_sigma); intersectionDomain(I, r_sigma); monot_ind = Monotonicity(getCodef(indexical),store); if (!isConsistentDomain(I)) {/* <Vacio> */ if (monot_ind == MONOTONE|| monot_ind == CONSTANT) { indexicals = removeElementAtIndexicals(indexicals, posIndexical); store = desrefVariableDepStore(store, posIndexical); /* Nuevo para que realmente quede la inconsistencia */ setDomainFDVariable(getVariableStore(store, variable_key), I); /* Nuevo para que realmente quede la inconsistencia */ freeDomain(x_sigma); freeDomain(r_sigma); freeDomain(I); freeIndexical(indexical); destruirListaFC(ListaIndexNec); return FAIL; } /*else continue */ } else if (equalsDomain(I, x_sigma)) /*x_sigma */ { if (monot_ind == ANTIMONOTONE || monot_ind == UNDEFINED) { indexicals = removeElementAtIndexicals(indexicals, posIndexical); store = desrefVariableDepStore(store, posIndexical); } } else {/* otherwise */ if (monot_ind == MONOTONE || monot_ind == CONSTANT) { (*s)++; store = updateVarStampStore(store,variable_key,*s); if (!updateVarDomStore(store, variable_key,I)) { freeDomain(x_sigma); freeDomain(r_sigma); freeDomain(I); freeIndexical(indexical); destruirListaFC(ListaIndexNec); return FAIL; } if (monot_ind == CONSTANT) { setEntailed(indexical, TRUE); indexicals = setElementAtIndexicals(indexicals, indexical, posIndexical); } } } Q = inicCola(); adicCola(Q, variable_key); estado = VariableCheck(store,indexicals,s,Q); destruirCola(Q); freeDomain(x_sigma); freeDomain(r_sigma); freeDomain(I); freeIndexical(indexical); if (estado == FAIL) return estado; } destruirListaFC(ListaIndexNec); return SUCCESS; }
int VariableCheck(Store store, Indexicals indexicals, Stamp *s, Cola Q) /*--------------------------------------------------------------- DESCRIPCION: Implementacion del algoritmo resolutivo basico. PARAMETROS: Q: es una cola de variables store : Es el store del Sistema de Restricciones. indexicals: Son los indexicals que representan las restricciones impuestas sobre el store. s: Marca de tiempo para la evaluacion de los indexicals USA: RETORNA: El estado de la operacion PRE: POS: La Ope = FAIL || Ope = SUCCESS. NOTAS: ---------------------------------------------------------------*/ { int tokeny, posIndexical, xkey, monot_f; FDVariable fdvariabley; Domain x_sigma, r_sigma, I; Lista IndexSusy; Indexical f; while(!vaciaCola(Q)) {/* Mientra la cola no este vacia */ tokeny = infoCola(Q); fdvariabley = getVariableStore(store, tokeny); elimCola(Q); /* Q = Q \ {y} */ IndexSusy = suspended(store, tokeny); /* Indexicals que dependen de la variable y */ for ( primLista(IndexSusy); !finLista(IndexSusy); sigLista(IndexSusy)) { posIndexical = infoLista(IndexSusy); f = elementAtIndexicals(indexicals, posIndexical); if (getEntailed(f)) /* Si f esta marcada como deducido */ { indexicals = removeElementAtIndexicals(indexicals, posIndexical); store = desrefVariableDepStore(store, posIndexical); } else { if(getStampFDVariable(fdvariabley) >= getStamp(f)) { xkey = getX(f); x_sigma = Inicp1Domain(getDomainFDVariable(getVariableStore(store, xkey))); r_sigma = r_Sigma(store,f); I = Inicp1Domain(x_sigma); intersectionDomain(I, r_sigma); setStamp(f, *s); indexicals = setElementAtIndexicals(indexicals, f, posIndexical); monot_f = Monotonicity(getCodef(f),store); if (!isConsistentDomain(I)) {/* <Vacio> */ if (monot_f == MONOTONE|| monot_f == CONSTANT) { freeDomain(x_sigma); freeDomain(r_sigma); freeDomain(I); freeIndexical(f); destruirLista(IndexSusy); return FAIL; } } else if (equalsDomain(I, x_sigma)) /* x_sigma */ { if (monot_f == ANTIMONOTONE) { setEntailed(f,TRUE); indexicals = removeElementAtIndexicals(indexicals, posIndexical); store = desrefVariableDepStore(store, posIndexical); } } else {/* otherwise */ if (monot_f == MONOTONE || monot_f == CONSTANT) { (*s)++; store = updateVarStampStore(store, xkey,*s); if (!updateVarDomStore(store, xkey,I)) { freeDomain(x_sigma); freeDomain(r_sigma); freeDomain(I); freeIndexical(f); destruirLista(IndexSusy); return FAIL; } if (!existeElementoCola(Q,xkey)) { adicCola(Q,xkey); } if (monot_f == CONSTANT) { setEntailed(f, TRUE); indexicals = removeElementAtIndexicals(indexicals, posIndexical); store = desrefVariableDepStore(store, posIndexical); } } } freeDomain(x_sigma); freeDomain(r_sigma); freeDomain(I); } } freeIndexical(f); } destruirLista(IndexSusy); } return SUCCESS; }
/******************* FUNCTION *********************/ CMRVarSystem::~CMRVarSystem ( void ) { freeDomain(CMR_ALL,CMR_ALL); }