/** * Does the closure of the formula, by adding the variables to the list of * prefix sets * * @param prefix: list of second-order variables corresponding to the prefix * @param freeVars: list of free variables in formula * @param negationIsTopMost: whether the prefix had negation on left or no */ void closePrefix(PrefixListType & prefix, IdentList* freeVars, bool negationIsTopmost) { unsigned int quantifiedSize; unsigned value; unsigned int prefixSize = prefix.size(); // phi = neg exists X ... // we will add new level of quantification if (negationIsTopmost) { VariableSet set; quantifiedSize = freeVars->size(); for (unsigned i = 0; i < quantifiedSize; ++i) { value = freeVars->get(i); set.push_back(varMap[value]); } prefix.push_back(set); } else { int index = prefix.size() - 1; quantifiedSize = freeVars->size(); for (unsigned i = 0; i < quantifiedSize; ++i) { value = freeVars->get(i); prefix[index].insert(prefix[index].begin()+i, varMap[value]); } } }
void Variable::assignValue(std::string value) { VariableSet *vs = VariableSet::instance(); vs->loadIfNeeded(); m_imp->m_value = value; try { vs->commit(); } catch (...) { } }
VariableSet::VariableSet(const VariableSet &vs) { for (int var = 0; var<vs.getNumVariables(); var++) { mVariables.push_back(new SearchVariable(vs.getVariable(var))); } for (int par=0; par<(int)vs.mParameters.size(); par++) { mParameters.push_back(SearchParameter(vs.mParameters[par])); } mHand = vs.mHand; }
void GeneralConstraint::stackVariables( VariableList& varList, const VariableSet& varSet ) { for(VariableSet::const_iterator it= varSet.begin(); it!=varSet.end(); ++it) { varList.push_back(*it); } } // End of method 'GeneralConstraint::stackVariables()'
/** * Takes formula, the prefix, and converts it to the set of sets of second * order variables, according to the variable map; * * @param formula: formula corresponding to the prefix * @return: list of lists of second-order variables */ PrefixListType convertPrefixFormulaToList(ASTForm* formula) { PrefixListType list; VariableSet set; unsigned int quantifiedSize; unsigned int value; bool isFirstNeg = true; // empty prefix is just one empty list if (formula->kind == aTrue) { list.push_front(set); return list; } ASTForm* iterator = formula; // while we are not at the end of the prefix while (iterator->kind != aTrue) { //iterator->dump(); //std::cout << "\n"; // Add to set if (iterator->kind == aEx2) { ASTForm_Ex2* exf = (ASTForm_Ex2*) iterator; quantifiedSize = (exf->vl)->size(); for (unsigned i = 0; i < quantifiedSize; ++i) { value = (exf->vl)->get(i); //std::cout << value << " -> " << varMap[value] << "\n"; set.push_back(varMap[value]); } iterator = exf->f; isFirstNeg = false; // Create new set } else if (iterator->kind == aNot) { if (!isFirstNeg) { list.push_front(set); set.clear(); } else { isFirstNeg = false; } ASTForm_Not* notf = (ASTForm_Not*) iterator; iterator = notf->f; // Fail, should not happen } else { assert(false); } } if (set.size() != 0) { list.push_front(set); } return list; }
VariableSet GeneralConstraint::unionVariables( const VariableSet& vs1, const VariableSet& vs2 ) { VariableSet tempSet(vs1); for(VariableSet::const_iterator it=vs2.begin(); it!=vs2.end(); ++it) { tempSet.insert(*it); } return tempSet; } // End of method 'GeneralConstraint::unionVariables()'
void TeXDisplay::printTeXVariableSet(const VariableSet & x) { d_sink.put(" $\\{$ "); Variable var; bool b = x.firstVariable(var); if(b) { d_sink.put(var); b = x.nextVariable(var); while(b) { d_sink.put(','); d_sink.put(var); b = x.nextVariable(var); }; }; d_sink.put(" $\\}$ "); };
VariableSet AdmWithLevels::variablesInOrder() const { VariableSet result; typedef vector<vector<Variable> >::const_iterator VI; VI w = d_v.begin(), e = d_v.end(); while(w!=e) { const vector<Variable> & V = *w; vector<Variable>::const_iterator ww = V.begin(), ee = V.end(); while(ww!=ee) { result.insert(*ww); ++ww; }; ++w; }; return result; };
VariableSet GeneralConstraint::getVariables( const SatID& sat, const TypeID& type ) { VariableSet vset; VariableSet varSet = getVariables(sat); for(VariableSet::iterator itv=varSet.begin(); itv!=varSet.end(); ++itv) { if( (itv->getType()==type) ) vset.insert(*itv); } return vset; } // End of method 'GeneralConstraint::getVariables(const SatID& sat,...)'
inline std::string asString(const VariableSet& vset) { std::ostringstream oss; for( VariableSet::const_iterator it = vset.begin(); it != vset.end(); ++it ) { oss << it->getType() << " " << it->getSource() << " " << it->getSatellite() << " " << it->getTypeIndexed() << " " << it->getSourceIndexed() << " " << it->getSatIndexed()<< std::endl; } return oss.str(); }
VariableSet VariableSet::operator*(const VariableSet& o) const { VariableSet result(capacity_); for(unsigned i = 0; i < size_; i++) { if(o.contains(vars_[i])) result += vars_[i]; } return result; }
VariableSet GeneralConstraint::getVariables( const SatID& sat, const TypeIDSet& typeSet ) { VariableSet vset; VariableSet varSet = getVariables(sat); for(VariableSet::iterator itv=varSet.begin(); itv!=varSet.end(); ++itv) { TypeIDSet::const_iterator it = typeSet.find(itv->getType()); if( (it!=typeSet.end()) ) vset.insert(*itv); } return vset; } // End of method 'GeneralConstraint::getVariables(...'
VariableSet GeneralConstraint::getVariables( const SourceIDSet& sourceSet ) { VariableSet vset; VariableSet unkSet( getVariables() ); for( VariableSet::const_iterator itv = unkSet.begin(); itv != unkSet.end(); ++itv ) { SourceIDSet::const_iterator it = sourceSet.find( (*itv).getSource() ); if( it!=sourceSet.end() ) vset.insert( *itv ); } return vset; } // End of method 'GeneralConstraint::getVariables(...'
void Polynomial::variablesIn(VariableSet & result) const { const int len = numberOfTerms(); // Bypass the reordering of the polynomial PolynomialIterator j = _terms.begin(); for(int i=1;i<=len&&!result.full();++i,++j) { (*j).MonomialPart().variablesIn(result); } };
Vector<double> GeneralConstraint::getSolution( const VariableSet& varSet ) { Vector<double> solution(varSet.size(),0.0); int i(0); for(VariableSet::const_iterator it=varSet.begin(); it!=varSet.end(); ++it) { solution[i] = solver.getSolution(*it); i++; } return solution; } // End of method 'GeneralConstraint::getSolution(...'
OptionalMessageList UndeclaredVariableCheck::visitLambdaDefinition(const LambdaDefinitionAddress& lambdaDef) { OptionalMessageList res; VariableSet recFunctions; for_each(lambdaDef.getAddressedNode()->getDefinitions(), [&recFunctions](const LambdaBindingPtr& cur) { recFunctions.insert(cur->getVariable()); }); for_each(lambdaDef->getDefinitions(), [&](const LambdaBindingAddress& cur) { // assemble set of defined variables VariableSet declared; // add recursive function variables declared.insert(recFunctions.begin(), recFunctions.end()); // add parameters auto paramList = cur.getAddressedNode()->getLambda()->getParameterList(); declared.insert(paramList.begin(), paramList.end()); // run check on body ... VarDeclarationCheck check(declared); // trigger check addAll(res, conductCheck(check, cur->getLambda())); }); return res; }
void merge( VariableSet &vs, const VariableSet &other ) { if ( vs.empty() ) vs = other; else { for ( auto i: other ) { auto cur = vs.find( i.first ); if ( cur == vs.end() ) { vs.emplace( std::make_pair( i.first, i.second ) ); } else cur->second.merge( i.second ); } } }
VariableSet GeneralConstraint::getVariables( const SourceID& source, const SatIDSet& satSet, const TypeID& type ) { VariableSet vset; VariableSet varSet = getVariables(source,type); for(VariableSet::iterator itv=varSet.begin(); itv!=varSet.end(); ++itv) { SatIDSet::const_iterator it = satSet.find(itv->getSatellite()); if( it != satSet.end() ) vset.insert(*itv); } return vset; } // End of method 'GeneralConstraint::getVariables(...'
void Item::extractVariables( VariableSet &vs ) const { ItemPtr i = getParent(); if ( i ) i->extractVariables( vs ); for ( auto x = myVariables.begin(); x != myVariables.end(); ++x ) vs.emplace( std::make_pair( x->first, x->second ) ); }
VariableSet GeneralConstraint::getVariables( const SourceIDSet& sourceSet, const TypeID& type ) { VariableSet vset; VariableSet varSet = getVariables(sourceSet); for(VariableSet::iterator itv=varSet.begin(); itv!=varSet.end(); ++itv) { if( (itv->getType()==type) && itv->getSourceIndexed() ) { vset.insert(*itv); } } return vset; } // End of method 'GeneralConstraint::getVariables(...'
Variable GeneralConstraint::getVariable( const SourceID& source, const SatID& sat, const TypeID& type ) { VariableSet vset; VariableSet varSet = getVariables(source,type); for(VariableSet::iterator itv=varSet.begin(); itv!=varSet.end(); ++itv) { if( itv->getType()==type ) return (*itv); } Exception e("The desirable variable not exist int the solver."); GPSTK_THROW(e); return Variable(); } // End of method 'GeneralConstraint::getVariables(...'
VariableSet GeneralConstraint::getVariables( const SourceID& source ) { VariableSet vset; VariableSet unkSet( getVariables() ); if(source==Variable::allSources) return unkSet; for( VariableSet::const_iterator itv = unkSet.begin(); itv != unkSet.end(); ++itv ) { if( (itv->getSource() == source) && itv->getSourceIndexed() ) { vset.insert( *itv ); } } return vset; } // End of method 'GeneralConstraint::getVariables(const SourceID& source)'
void Item::extractVariablesExcept( VariableSet &vs, const std::set<std::string> &vl ) const { ItemPtr i = getParent(); if ( i ) i->extractVariablesExcept( vs, vl ); for ( auto x = myVariables.begin(); x != myVariables.end(); ++x ) { if ( vl.find( x->first ) == vl.end() ) vs.emplace( std::make_pair( x->first, x->second ) ); } }
bool operator()(const VariableSet & m,const VariableSet & n) const { bool result = false; int msz = m.size(); int nsz = n.size(); if(msz!=nsz) { result = msz< nsz; } else if(msz>0) { result = false; // perhaps they are equal Variable v1,v2; bool b1 = m.firstVariable(v1); bool b2 = n.firstVariable(v2); if(v1==v2) { while(b1&&b2) { b1 = m.nextVariable(v1); b2 = n.nextVariable(v2); if(b1) { if(v1!=v2) { result = operator()(v1,v2); }; } else break; }; } else { result = operator()(v1,v2); }; if(b1!=b2) errorh(__LINE__); }; return result; };
Matrix<double> GeneralConstraint::getCovariance( const VariableSet& varSet ) { Matrix<double> covariance(varSet.size(),varSet.size(),0.0); int i(0); for(VariableSet::const_iterator iti=varSet.begin(); iti!=varSet.end(); ++iti) { int j(0); for(VariableSet::const_iterator itj=varSet.begin(); itj!=varSet.end(); ++itj) { covariance[i][j] = solver.getCovariance(*iti,*itj); j++; } i++; } return covariance; } // End of method 'GeneralConstraint::getCovariance(...'
VariableSet GeneralConstraint::intersectionVariables(const VariableSet& vs1, const VariableSet& vs2 ) { VariableSet tempSet; for(VariableSet::const_iterator it=vs1.begin(); it!=vs1.end(); ++it) { VariableSet::const_iterator it2 = vs2.find(*it); if(it2!=vs2.end()) tempSet.insert(*it); } return tempSet; } // End of method 'GeneralConstraint::intersectionVariables()'
void AdmWithLevels::sortIntoKnownsAndUnknowns(const VariableSet & x, VariableSet & knowns,VariableSet & unknowns) const { knowns.clear(); unknowns.clear(); Variable v; bool b = x.firstVariable(v); while(b) { if(d_knowns.present(v)) { knowns.insert(v); } else { unknowns.insert(v); }; b = x.nextVariable(v); }; };
VariableSet GeneralConstraint::getVariables( const SatID& sat ) { VariableSet vset; VariableSet unkSet( getVariables() ); if(sat==Variable::noSats) return vset; for( VariableSet::const_iterator itv = unkSet.begin(); itv != unkSet.end(); ++itv ) { if( !(!itv->getSourceIndexed() && itv->getSatIndexed()) ) { continue; } if(sat==Variable::allSats) { vset.insert(*itv); } else if(sat==Variable::allGPSSats) { if(itv->getSatellite().system==SatID::systemGPS) vset.insert(*itv); } else if(sat==Variable::allGlonassSats) { if(itv->getSatellite().system==SatID::systemGlonass) vset.insert(*itv); } else if(sat==Variable::allGalileoSats) { if(itv->getSatellite().system==SatID::systemGalileo) vset.insert(*itv); } else { if(itv->getSatellite()==sat) vset.insert(*itv); } } return vset; } // End of method 'GeneralConstraint::getVariables(const SatID& sat)'
void Stepper::unregisterProcess( Process* aProcess ) { ProcessVector::iterator ip( std::find( theProcessVector.begin(), theProcessVector.end(), aProcess ) ); if( ip == theProcessVector.end() ) { THROW_EXCEPTION_INSIDE( NotFound, asString() + ": Failed to dissociate [" + aProcess->asString() + "] (no such Process is " "associated to this stepper)" ); } typedef std::set< Variable* > VariableSet; VariableSet aVarSet; Process::VariableReferenceVector const& aVarRefVector( aProcess->getVariableReferenceVector() ); std::transform( aVarRefVector.begin(), aVarRefVector.end(), inserter( aVarSet, aVarSet.begin() ), std::mem_fun_ref( &VariableReference::getVariable ) ); VariableVector aNewVector; VariableVector::size_type aReadWriteVariableOffset, aReadOnlyVariableOffset; for( VariableVector::iterator i( theVariableVector.begin() ), e( theVariableVector.begin() + theReadWriteVariableOffset ); i != e; ++i ) { VariableSet::iterator j( aVarSet.find( *i ) ); if ( j != aVarSet.end() ) aVarSet.erase( j ); else aNewVector.push_back( *i ); } aReadWriteVariableOffset = aNewVector.size(); for( VariableVector::iterator i( theVariableVector.begin() + theReadWriteVariableOffset ), e( theVariableVector.begin() + theReadOnlyVariableOffset ); i != e; ++i ) { VariableSet::iterator j( aVarSet.find( *i ) ); if ( j != aVarSet.end() ) aVarSet.erase( j ); else aNewVector.push_back( *i ); } aReadOnlyVariableOffset = aNewVector.size(); for( VariableVector::iterator i( theVariableVector.begin() + theReadOnlyVariableOffset ), e( theVariableVector.end() ); i != e; ++i ) { VariableSet::iterator j( aVarSet.find( *i ) ); if ( j != aVarSet.end() ) aVarSet.erase( j ); else aNewVector.push_back( *i ); } theVariableVector.swap( aNewVector ); theReadWriteVariableOffset = aReadWriteVariableOffset; theReadOnlyVariableOffset = aReadOnlyVariableOffset; theProcessVector.erase( ip ); }
GeneralConstraint& GeneralConstraint::changeState( const VariableList& varList, const Matrix<double>& convertMat) { VariableSet allVariable = getCurrentUnknowns(); // check input int varNum(0); for(VariableList::const_iterator it = varList.begin(); it!=varList.end(); ++it) { if(allVariable.find(*it)==allVariable.end()) { Exception e("The variable doesn't exist in the solver."); GPSTK_THROW(e); } varNum++; } if(varNum!=convertMat.rows() || varNum!=convertMat.cols()) { Exception e("The size of input doesn't match."); GPSTK_THROW(e); } const int numOfVar(varNum); Vector<double> vectorOfSolution(numOfVar,0.0); Matrix<double> matrixOfCovariance(numOfVar,numOfVar,0.0); int i = 0; for(VariableList::const_iterator iti = varList.begin(); iti != varList.end(); ++iti) { vectorOfSolution(i) = solver.getSolution(*iti); VariableList tempList(varList); int j(0); for(VariableList::iterator itj = tempList.begin(); itj!=tempList.end(); ++itj) { matrixOfCovariance(i,j) = solver.getCovariance(*iti,*itj); j++; } i++; } Vector<double> solution = convertMat*vectorOfSolution; Matrix<double> covariance = convertMat*matrixOfCovariance *transpose(convertMat); i = 0; for(VariableList::const_iterator iti=varList.begin(); iti!=varList.end(); ++iti) { setSolution(*iti,solution(i)); std::list<Variable> tempList(varList); int j(0); for(std::list<Variable>::iterator itj = tempList.begin(); itj!=tempList.end(); ++itj) { setCovariance(*iti,*itj,covariance(i,j)); j++; } i++; } return (*this); } // Ebd if method 'GeneralConstraint::changeState()'