void SimpSMTSolver::initialize( ) { CoreSMTSolver::initialize( ); #ifdef PRODUCE_PROOF if ( config.sat_preprocess_booleans != 0 || config.sat_preprocess_theory != 0 ) { opensmt_warning( "disabling SATElite preprocessing to track proof" ); use_simplification = false; config.sat_preprocess_booleans = 0; config.sat_preprocess_theory = 0; } #else use_simplification = config.sat_preprocess_booleans != 0; #endif // Add clauses for true/false // Useful for expressing TAtoms that are constantly true/false const Var var_True = newVar( ); const Var var_False = newVar( ); setFrozen( var_True, true ); setFrozen( var_False, true ); vec< Lit > clauseTrue, clauseFalse; clauseTrue.push( Lit( var_True ) ); addClause( clauseTrue ); clauseFalse.push( Lit( var_False, true ) ); addClause( clauseFalse ); theory_handler = new THandler( egraph, config, *this, trail, level, assigns, var_True, var_False ); }
Var* iom_iheader2var(struct iom_iheader* h) { Var* v; int i; v = newVar(); V_TYPE(v) = ID_VAL; V_FORMAT(v) = ihfmt2vfmt(h->format); /** Will not be possible now if (V_FORMAT(v) == VAX_FLOAT) V_FORMAT(v) = DV_FLOAT; if (V_FORMAT(v) == VAX_INTEGER) V_FORMAT(v) = DV_INT32; */ if (h->dim[0] < 0 || h->dim[1] < 0 || h->dim[2] < 0) { fprintf(stderr, "One of dim[i]'s is not set properly.\n"); fprintf(stderr, "See File: %s Line: %d.\n", __FILE__, __LINE__); } V_ORDER(v) = ihorg2vorg(h->org); V_DSIZE(v) = 1; for (i = 0; i < 3; i++) { V_SIZE(v)[i] = (((h->dim)[i] - 1) / h->s_skip[i]) + 1; V_DSIZE(v) *= V_SIZE(v)[i]; } return (v); }
int BLIFwriter::solve(){ if(solveNegation){ if(finalOr.size() > 0){ vector<int> tmp; tmp.resize(finalOr.size() + 1); tmp[0] = newVar(); for(int i=0; i<finalOr.size(); ++i){ tmp[i+1] = finalOr[i]; } addBigOrClause(&tmp[0], tmp.size()-1); output<<".names "<<nm(tmp[0])<<" OUT"<<endl; output<<"1 1"<<endl; }else{ output<<".names "; for(int i=0; i<tmpID; ++i){ output<<"tmp"<<i<<" "; } output<<" OUT"<<endl; for(int i=0; i<tmpID; ++i){ output<<"1"; } output<<" 1"<<endl; } } output<<".end"<<endl; return SATSolver::UNDETERMINED; }
size_t ExprVarEnv::mergeBranches(const ExprType& type, ExprVarEnv& env1, ExprVarEnv& env2) { typedef std::map<std::pair<ExprLocalVar*, ExprLocalVar*>, std::string> MakeMap; MakeMap phisToMake; /// For each thing in env1 see if env2 has an entry for (auto& ienv : env1._map) { const std::string& name = ienv.first; ExprLocalVar* var = ienv.second.get(); if (ExprLocalVar* env2Var = env2.find(name)) { phisToMake[std::make_pair(var, env2Var)] = name; } } /// For each thing in env2 see if env1 has an entry for (auto& ienv : env2._map) { const std::string& name = ienv.first; ExprLocalVar* var = ienv.second.get(); if (ExprLocalVar* env1Var = env1.find(name)) { phisToMake[std::make_pair(env1Var, var)] = name; } } std::vector<std::pair<std::string, ExprLocalVarPhi*>> mergedVariablesInThisCall; for (MakeMap::iterator it = phisToMake.begin(); it != phisToMake.end(); ++it) { std::unique_ptr<ExprLocalVar> newVar(new ExprLocalVarPhi(type, it->first.first, it->first.second)); mergedVariablesInThisCall.emplace_back(it->second, static_cast<ExprLocalVarPhi*>(newVar.get())); add(it->second, std::move(newVar)); } _mergedVariables.emplace_back(std::move(mergedVariablesInThisCall)); return _mergedVariables.size() - 1; }
CryptoMinisatSolver::CryptoMinisatSolver(StatisticsRegistry* registry, const std::string& name) : d_solver(new CMSat::SATSolver()) , d_numVariables(0) , d_okay(true) , d_statistics(registry, name) { d_true = newVar(); d_false = newVar(); std::vector<CMSat::Lit> clause(1); clause[0] = CMSat::Lit(d_true, false); d_solver->add_clause(clause); clause[0] = CMSat::Lit(d_false, true); d_solver->add_clause(clause); }
void Context::addVar( const char *varName, const Value &val ) { #ifdef __DEBUG__ printf("CONTEXT::addVar: %s\n", varName ); #endif Value var = newVar(varName); var.setValue(val); }
void Context::addVar( const char *varName, RAYExpression *varValue ) { #ifdef __DEBUG__ printf("CONTEXT::addVar: %s\n", varName ); #endif Value v = varValue->eval(*this); Value var = newVar(varName); var.setValue(v); }
SAT::SAT() : lit_sort(trailpos) , pushback_time(0) , trail(1) , qhead(1,0) , rtrail(1) , confl(NULL) , var_inc(1) , maxActivity(0) , cla_inc(1) , order_heap(VarOrderLt(activity)) , bin_clauses(0) , tern_clauses(0) , long_clauses(0) , learnt_clauses(0) , propagations(0) , back_jumps(0) , nrestarts(0) , next_simp_db(100000) , clauses_literals(0) , learnts_literals(0) , max_literals(0) , tot_literals(0) , avg_depth(100) , confl_rate(1000) , ll_time(wallClockTime()) , ll_inc(1) , learnt_len_el(10) , learnt_len_occ(MAX_SHARE_LEN,learnt_len_el*1000/MAX_SHARE_LEN) { newVar(); enqueue(Lit(0,1)); newVar(); enqueue(Lit(1,0)); temp_sc = (SClause*) malloc(TEMP_SC_LEN * sizeof(int)); short_expl = (Clause*) malloc(sizeof(Clause) + 3 * sizeof(Lit)); short_confl = (Clause*) malloc(sizeof(Clause) + 2 * sizeof(Lit)); short_expl->clearFlags(); short_confl->clearFlags(); short_confl->sz = 2; }
//This function encodes x == a; void BLIFwriter::addEquateClause(int x, int a){ if( !solveNegation ){ if(!off){ string t = outvar(); output<<".names "<<nm(a)<<" "<<nm(x)<<" "<<t<<endl; output<<sgn(a)<<nsgn(x)<<" 1"<<endl; output<<nsgn(a)<<sgn(x)<<" 1"<<endl; } }else{ int tmp = newVar (); addXorClause(tmp, x, a); finalOr.push_back(tmp); } }
varInfo *RcreateUVar(char *n, symbol **pp, int type) { symbol *p; varInfo *v; if (findName((*pp),n)) return(NULL); else { p = addName(pp,n); /* add name to tree */ v = newVar(); /* get new variable packet */ p->val = (char *)v; presetVal(v,type); /* preset values based on type */ } return(v); }
void insertMapValue(string key, void* value, map m){ if(m->count >= m->size * m->load) resizeMap(m, 2); size_t index = hashKey(key) % m->size; var v = newVar(key, value); linkedNode node = newLinkedNode(v); linkedList list = m->values[index]; if(!list) list = m->values[index] = newLinkedList(NULL); appendLinkedNode(node, list); m->count++; }
Var* new_module(char* module_name) { Var* v; if (module_name == NULL) { if (debug > DEBUG_THRESHOLD) { parse_error("Cannot create a module with (null) name."); } return NULL; } if (search_in_list_of_loaded_modules(module_name) != NULL) { /* If module already loaded, don't load it again */ parse_error("Module %s already loaded.", module_name); return NULL; } v = newVar(); memset(&V_MODULE(v), 0, sizeof(dvModule)); /* make scope not clean this variable */ mem_claim(v); V_TYPE(v) = ID_MODULE; V_NAME(v) = strdup(module_name); if (V_NAME(v) == NULL) { parse_error("Mem allocation error in new_module()."); free_var(v); return NULL; } V_MODULE(v).functions = Narray_create(10); V_MODULE(v).name = V_NAME(v); /* keep track of available modules */ if (!add_to_list_of_loaded_modules(v)) { /* Addition into the list of loaded modules failed. Abort. */ free_var(v); return NULL; } V_MODULE(v).stage = MOD_LST_ADDED; return v; }
/* * Copy an expression, return a pointer to the newly allocated expression. */ Exp *copyExp(Exp *exp) { if(isApp(exp)) { return newApp(copyExp(appFun(exp)), copyExp(appArg(exp))); } else if(isAbs(exp)) { return newAbs(copyExp(absBody(exp))); } else if(isVar(exp)) { return newVar(varBind(exp)); } else if(isCon(exp)) { return newCon(conTy(exp), conVal(exp)); } else if(isOpn(exp)) { return newOpn(opnType(exp)); } else { printf("Error - unrecognised expression type in copyExp()\n"); assert(false); } }
int SAT::getLazyVar(ChannelInfo ci) { int v; if (var_free_list.size()) { v = var_free_list.last(); var_free_list.pop(); fprintf(stderr, "reuse %d\n", v); assert(assigns[v] == toInt(l_Undef)); assert(watches[2*v].size() == 0); assert(watches[2*v+1].size() == 0); assert(num_used[v] == 0); c_info[v] = ci; activity[v] = 0; polarity[v] = 1; flags[v] = 7; } else { v = newVar(1, ci); num_used.push(0); } // flags[v].setDecidable(false); return v; }
//__________________________________________________________________________________ void _Variable::ClearConstraints (void) { if (IsCategory ()) { _Variable newVar (*GetName(), IsGlobal()); newVar.SetValue ((_PMathObj)Compute()->makeDynamic(),false); ReplaceVar ( &newVar); /*_Matrix * modelMatrix = (_Matrix*)LocateVar(modelMatrixIndices.lData[1])->GetValue(); for (long k=0; k<4; k++) for (long k2 = 0; k2<4; k2++) if (k!=k2) { StringToConsole (*(_String*)modelMatrix->GetFormula(k,k2)->toStr()); BufferToConsole ("\n"); } */ } else { if (!IsIndependent()) { SetValue ((_PMathObj)Compute()->makeDynamic(),false); } SetBounds (DEFAULTLOWERBOUND,DEFAULTUPPERBOUND); } }
Var* linear_interp(Var* v0, Var* v1, Var* v2, float ignore) { Var* s = NULL; float *x = NULL, *y = NULL, *fdata = NULL; size_t i, count = 0; float x1, y1, x2, y2, w; float *m = NULL, *c = NULL; /* slopes and y-intercepts */ size_t fromsz, tosz; /* number of elements in from & to arrays */ fromsz = V_DSIZE(v0); tosz = V_DSIZE(v2); x = (float*)calloc(fromsz, sizeof(float)); y = (float*)calloc(fromsz, sizeof(float)); count = 0; for (i = 0; i < fromsz; i++) { x[count] = extract_float(v1, i); y[count] = extract_float(v0, i); if (is_deleted(x[count]) || is_deleted(y[count]) || x[count] == ignore || y[count] == ignore) continue; if (count && x[count] <= x[count - 1]) { parse_error("Error: data is not monotonically increasing x1[%d] = %f", i, x[count]); free(fdata); free(x); free(y); return (NULL); } count++; } fdata = (float*)calloc(tosz, sizeof(float)); m = (float*)calloc(fromsz - 1, sizeof(float)); c = (float*)calloc(fromsz - 1, sizeof(float)); /* evaluate & cache slopes & y-intercepts */ for (i = 1; i < fromsz; i++) { m[i - 1] = (y[i] - y[i - 1]) / (x[i] - x[i - 1]); c[i - 1] = y[i - 1] - m[i - 1] * x[i - 1]; } for (i = 0; i < tosz; i++) { w = extract_float(v2, i); /* output wavelength */ if (is_deleted(w)) { fdata[i] = -1.23e34; } else if (w == ignore) { fdata[i] = ignore; } else { /* ** Locate the segment containing the x-value of "w". ** Assume that x-values are monotonically increasing. */ size_t st = 0, ed = fromsz - 1, mid; while ((ed - st) > 1) { mid = (st + ed) / 2; if (w > x[mid]) { st = mid; } else if (w < x[mid]) { ed = mid; } else { st = ed = mid; } } x2 = x[ed]; y2 = y[ed]; x1 = x[st]; y1 = y[st]; if (y2 == y1) { fdata[i] = y1; } else { /* m = (y2-y1)/(x2-x1); */ /* fdata[i] = m[st]*w + (y1 - m[st]*x1); */ fdata[i] = m[st] * w + c[st]; } } } s = newVar(); V_TYPE(s) = ID_VAL; V_DATA(s) = (void*)fdata; V_DSIZE(s) = V_DSIZE(v2); V_SIZE(s)[0] = V_SIZE(v2)[0]; V_SIZE(s)[1] = V_SIZE(v2)[1]; V_SIZE(s)[2] = V_SIZE(v2)[2]; V_ORG(s) = V_ORG(v2); V_FORMAT(s) = DV_FLOAT; free(x); free(y); return (s); }
void ParameterEdit::newItem() { NewVariant newVar(this); if(newVar.exec() == QDialog::Accepted) { QString varType = newVar._type->currentText(); QString name = newVar._name->text(); bool active = false; if(_params.contains(name)) { QMessageBox::warning(this, tr("Name already exists"), tr("The name for the parameter you specified already exists in the list.")); } BoolEdit * be = 0; IntEdit * ie = 0; DoubleEdit * de = 0; StringEdit * se = 0; ListEdit * le = 0; if(varType == tr("String")) { se = new StringEdit(this); se->_name->setText(name); if(se->exec() == QDialog::Accepted) { _params[name] = QVariant(se->_value->text()); active = se->_active->isChecked(); } delete se; se = 0; } else if(varType == tr("Int")) { ie = new IntEdit(this); ie->_name->setText(name); if(ie->exec() == QDialog::Accepted) { _params[name] = QVariant(ie->_value->text().toInt()); active = ie->_active->isChecked(); } delete ie; ie = 0; } else if(varType == tr("Double")) { de = new DoubleEdit(this); de->_name->setText(name); if(de->exec() == QDialog::Accepted) { _params[name] = QVariant(de->_value->text().toDouble()); active = de->_active->isChecked(); } delete de; de = 0; } else if(varType == tr("Bool")) { be = new BoolEdit(this); be->_name->setText(name); if(be->exec() == QDialog::Accepted) { _params[name] = QVariant((bool)be->value()); active = be->_active->isChecked(); } delete be; be = 0; } else if(varType == tr("List")) { le = new ListEdit(this); le->_name->setText(name); if(le->exec() == QDialog::Accepted) { _params[name] = QVariant(le->list()); active = le->_active->isChecked(); } delete le; le = 0; } else { QMessageBox::warning(this, tr("Unknown Type"), QString(tr("I do not understand the type %1.")).arg(varType)); return; } int r = _table->rowCount(); _table->setRowCount(r+1); QTableWidgetItem * ctItem = 0; ctItem = new QTableWidgetItem(); ctItem->setFlags(Qt::ItemIsUserCheckable); ctItem->setCheckState((active ? Qt::Checked : Qt::Unchecked)); _table->setItem(r, 0, ctItem); _table->setItem(r, 1, new QTableWidgetItem(name)); QVariant var = _params[name]; _table->setItem(r, 2, new QTableWidgetItem(var.typeName())); _table->setItem(r, 3, new QTableWidgetItem(var.toString())); } }
void ListEdit::newItem() { NewVariant newVar(this); newVar._lblName->hide(); newVar._name->hide(); if(newVar.exec() == QDialog::Accepted) { QString varType = newVar._type->currentText(); BoolEdit * be = 0; IntEdit * ie = 0; DoubleEdit * de = 0; StringEdit * se = 0; ListEdit * le = 0; if(varType == tr("String")) { se = new StringEdit(this); se->_lblName->hide(); se->_name->hide(); se->_active->hide(); if(se->exec() == QDialog::Accepted) { new QListBoxVariant(_list, QVariant(se->_value->text())); } delete se; se = 0; } else if(varType == tr("Int")) { ie = new IntEdit(this); ie->_lblName->hide(); ie->_name->hide(); ie->_active->hide(); if(ie->exec() == QDialog::Accepted) { new QListBoxVariant(_list, QVariant(ie->_value->text().toInt())); } delete ie; ie = 0; } else if(varType == tr("Double")) { de = new DoubleEdit(this); de->_lblName->hide(); de->_name->hide(); de->_active->hide(); if(de->exec() == QDialog::Accepted) { new QListBoxVariant(_list, QVariant(de->_value->text().toDouble())); } delete de; de = 0; } else if(varType == tr("Bool")) { be = new BoolEdit(this); be->_lblName->hide(); be->_name->hide(); be->_active->hide(); if(be->exec() == QDialog::Accepted) { new QListBoxVariant(_list, QVariant(be->value(), 0)); } delete be; be = 0; } else if(varType == tr("List")) { le = new ListEdit(this); le->_lblName->hide(); le->_name->hide(); le->_active->hide(); if(le->exec() == QDialog::Accepted) { new QListBoxVariant(_list, QVariant(le->list())); } delete le; le = 0; } else { QMessageBox::warning(this, tr("Unknown Type"), QString(tr("I do not understand the type %1.")).arg(varType)); } } }
void RenderWindow::sAdd() { bool ok = false; bool active = false; QString name; QString varType; QVariant var; NewVariant newVar(this); while(!ok) { if(newVar.exec() != QDialog::Accepted) return; name = newVar._name->text(); varType = newVar._type->currentText(); ok = !_params.contains(name); if(!ok) QMessageBox::warning(this, tr("Name already exists"), tr("The name for the parameter you specified already exists in the list.")); } BoolEdit * be = 0; IntEdit * ie = 0; DoubleEdit * de = 0; StringEdit * se = 0; ListEdit * le = 0; if(varType == NewVariant::tr("String")) { se = new StringEdit(this); se->_name->setText(name); ok = (se->exec() == QDialog::Accepted); var = QVariant(se->_value->text()); active = se->_active->isChecked(); delete se; se = 0; } else if(varType == NewVariant::tr("Int")) { ie = new IntEdit(this); ie->_name->setText(name); ok = (ie->exec() == QDialog::Accepted); var = QVariant(ie->_value->text().toInt()); active = ie->_active->isChecked(); delete ie; ie = 0; } else if(varType == NewVariant::tr("Double")) { de = new DoubleEdit(this); de->_name->setText(name); ok = (de->exec() == QDialog::Accepted); var = QVariant(de->_value->text().toDouble()); active = de->_active->isChecked(); delete de; de = 0; } else if(varType == NewVariant::tr("Bool")) { be = new BoolEdit(this); be->_name->setText(name); ok = (be->exec() == QDialog::Accepted); var = QVariant(be->value(), 0); active = be->_active->isChecked(); delete be; be = 0; } else if(varType == NewVariant::tr("List")) { le = new ListEdit(this); le->_name->setText(name); ok = (le->exec() == QDialog::Accepted); var = QVariant(le->list()); active = le->_active->isChecked(); delete le; le = 0; } else { QMessageBox::warning(this, tr("Unknown Type"), QString(tr("I do not understand the type %1.")).arg(varType)); return; } if(!ok) return; _params[name] = var; int r = _table->numRows(); _table->setNumRows(r+1); Q3CheckTableItem * ctItem = new Q3CheckTableItem(_table, QString::null); ctItem->setChecked(active); _table->setItem(r, 0, ctItem); _table->setText(r, 1, name); _table->setText(r, 2, var.typeName()); _table->setText(r, 3, var.toString()); sSelectionChanged(); }