void InHC4Revise::ibwd(const Function& f, const Domain& y, IntervalVector& x, const IntervalVector& xin) { Eval e; if (!xin.is_empty()) { e.eval(f,xin); assert(!f.expr().deco.d->is_empty()); for (int i=0; i<f.nb_nodes(); i++) *f.node(i).deco.p = *f.node(i).deco.d; } else { for (int i=0; i<f.nb_nodes(); i++) f.node(i).deco.p->set_empty(); } e.eval(f,x); assert(!f.expr().deco.d->is_empty()); *f.expr().deco.d = y; try { f.backward<InHC4Revise>(*this); f.read_arg_domains(x); } catch(EmptyBoxException&) { x.set_empty(); } }
bool InHC4Revise::ibwd(const Function& f, const Domain& y, ExprLabel** x) { Eval e; // the box to be inflated is found // in the "p" field of the x labels: Array<Domain> argP(f.nb_arg()); for (int i=0; i<f.nb_arg(); i++) { argP.set_ref(i,*x[i]->p); } if (!argP[0].is_empty()) { // if the first domain is empty, so they all are e.eval(f,argP); assert(!f.expr().deco.d->is_empty()); for (int i=0; i<f.nb_nodes(); i++) *f.node(i).deco.p = *f.node(i).deco.d; } else { for (int i=0; i<f.nb_nodes(); i++) f.node(i).deco.p->set_empty(); } e.eval(f,x); assert(!f.expr().deco.d->is_empty()); *f.expr().deco.d = y; Array<Domain> argD(f.nb_arg()); for (int i=0; i<f.nb_arg(); i++) { argD.set_ref(i,*(x[i]->d)); } try { f.backward<InHC4Revise>(*this); f.read_arg_domains(argD); } catch(EmptyBoxException&) { // should we force argD to be the empty set here? // (probably no, as long as this function is called // inside InHC4Revise) return false; } return true; }
int main(int argc, char* argv[]) { Parser P; Eval E; char input[1000]; char current[1000]; char alter[1000]; Tree* dList=new Tree(); cout<<"\n LISP INTERPRETER\n"; cout<<"To terminate a particular input, please type EOF at the end\n"; memset(input,0,1000); fgets(input, 1000, stdin); Interpreter I; // Read input till the last parenthesis. while(I.scanUntil(input)<0) { // memcpy and memset for faster performances. memcpy(current,input,1000); memset(alter,0,1000); memset(input,0,1000); fgets(alter, 1000, stdin); sprintf(input,"%s\n%s",current,alter); } // Convert to UpperCase Characters for(unsigned int i=0;i<strlen(input);i++){ if (input[i] >= 'a' && input[i]<= 'z') input[i] = ('A' + input[i] - 'a'); } Tree* T = P.parse(input,strlen(input)); if(T==NULL) { } else { for (int i=0;i<T->getSize();i++) { SExp* aList = new SExp(0); SExp* Sin = T->get(i); E.def=0; SExp* Sout=E.eval(Sin,aList,dList); if(Sout!=NULL && E.def==0) { memset(alter,0,1000); Sout->convertStringList(alter); printf("%s\n",alter); } } } return 0; }
void InHC4Revise::iproj(const Function& f, const Domain& y, IntervalVector& x, const IntervalVector& xin) { Eval e; if (!xin.is_empty()) { e.eval(f,xin); for (int i=0; i<f.nb_nodes(); i++) *f.node(i).deco.p = *f.node(i).deco.d; } else { for (int i=0; i<f.nb_nodes(); i++) f.node(i).deco.p->set_empty(); } e.eval(f,x); *f.expr().deco.d = y; try { f.backward<InHC4Revise>(*this); if (f.all_args_scalar()) { int j; for (int i=0; i<f.nb_used_vars; i++) { j=f.used_var[i]; x[j]=f.arg_domains[j].i(); } } else load(x,f.arg_domains,f.nb_used_vars,f.used_var); } catch(EmptyBoxException&) { x.set_empty(); } }