void SpinPointSpace::updateAddPeak( Spin* s ) { // Dasselbe wie refill, aber nur für einen einzelnen Spin if( !d_st.isNull() ) { const bool showLink = d_showLinks && d_noesy != DimUndefined && d_st->getDimCount() > 1; ElementSet inf; if( d_showInferred || showLink ) inferPeaks( inf, s->getSystem(), s->getLabel() ); ElementSet links; ElementSet::const_iterator j; if( d_showInferred && !showLink ) { for( j = inf.begin(); j != inf.end(); ++j ) _merge( this, d_res, (*j) ); }else if( showLink && !d_showInferred ) { fillLinks( inf, links ); for( j = links.begin(); j != links.end(); ++j ) _merge( this, d_res, (*j) ); }else if( showLink && d_showInferred ) { fillLinks( inf, links ); for( j = inf.begin(); j != inf.end(); ++j ) links.insert( (*j) ); for( j = links.begin(); j != links.end(); ++j ) _merge( this, d_res, (*j) ); } } }
void SpinPointSpace::refill() { d_res.clear(); if( !d_st.isNull() ) { const bool showLink = d_showLinks && d_noesy != DimUndefined && d_st->getDimCount() > 1; ElementSet resTuples; if( d_showInferred || showLink ) { const SpinBase::SpinSystemMap& sm = d_spins->getSystems(); SpinBase::SpinSystemMap::const_iterator sysIter; for( sysIter = sm.begin(); sysIter != sm.end(); ++sysIter ) { Element elem; SpinSystem* sys = 0; if( d_doPathsim ) { sys = (*sysIter).second; elem.setInfer(); // nur hier handelt es sich um echte Pfadsimulation; sonst cross-product } NmrExperiment* e = d_types->inferExperiment2( d_st, sys, d_spec ); // std::strstream out; // e->printTable(out); // qDebug() << out.str(); const PathTable& tbl = e->getTable(); PathTable::Table::const_iterator rowIter; for( rowIter = tbl.begin(); rowIter != tbl.end(); ++rowIter ) fillTuples( elem, (*sysIter).second, (*rowIter), resTuples, DimX ); // fillTuples wird in jedem Fall mit dem System aufgerufen } } ElementSet resLinks; ElementSet::const_iterator j; if( d_showInferred && !showLink ) { for( j = resTuples.begin(); j != resTuples.end(); ++j ) d_res.insert( (*j) ); }else if( showLink && !d_showInferred ) { fillLinks( resTuples, resLinks ); for( j = resLinks.begin(); j != resLinks.end(); ++j ) d_res.insert( (*j) ); }else if( showLink && d_showInferred ) { fillLinks( resTuples, resLinks ); for( j = resTuples.begin(); j != resTuples.end(); ++j ) resLinks.insert( (*j) ); for( j = resLinks.begin(); j != resLinks.end(); ++j ) d_res.insert( (*j) ); } } SpinSpace::Update m( this, SpinSpace::Update::All ); notifyObservers( m ); }
void SpinPointSpace::updateNeighbour(SpinSystem* sys, SpinLabel l, bool removeFirst ) { if( d_showOffs && sys && !l.isNull() && l.getOffset() == 0 ) { ElementSet inf; l.setOffset( -1 ); if( removeFirst && sys->getSucc() ) { const SpinSystem::Spins& s = sys->getSucc()->getSpins(); SpinSystem::Spins::const_iterator i; for( i = s.begin(); i != s.end(); ++i ) { if( (*i)->getLabel() == l ) updateForceRemove( (*i) ); } } inferPeaks( inf, sys->getSucc(), l ); l.setOffset( +1 ); if( removeFirst && sys->getPred() ) { const SpinSystem::Spins& s = sys->getPred()->getSpins(); SpinSystem::Spins::const_iterator i; for( i = s.begin(); i != s.end(); ++i ) { if( (*i)->getLabel() == l ) updateForceRemove( (*i) ); } } inferPeaks( inf, sys->getPred(), l ); ElementSet::const_iterator j; for( j = inf.begin(); j != inf.end(); ++j ) _merge( this, d_res, (*j) ); } }
ConstantPropLatticeElement* ConstantPropLattice::join(vector <LatticeElement*>& list_) { ConstantPropLatticeElement* first = static_cast<ConstantPropLatticeElement*>(list_[0]); ConstantPropLatticeElement* second = static_cast<ConstantPropLatticeElement*>(list_[1]); ElementSet firstElementSet = first->getLatticeElement(); ElementSet secondElementSet = second->getLatticeElement(); secondElementSet.insert(firstElementSet.begin(), firstElementSet.end()); return new ConstantPropLatticeElement(secondElementSet); }
ConstantPropLatticeElement* ConstantPropLattice::merge(vector <LatticeElement*>& list_) { ConstantPropLatticeElement* first = static_cast<ConstantPropLatticeElement*>(list_[0]); ConstantPropLatticeElement* second = static_cast<ConstantPropLatticeElement*>(list_[1]); ElementSet firstElementSet = first->getLatticeElement(); ElementSet secondElementSet = second->getLatticeElement(); ElementSet::const_iterator itr1, itr2; for ( itr1 = firstElementSet.begin(); itr1 != firstElementSet.end(); ++itr1 ) { itr2 = secondElementSet.find(*itr1); if ( itr2 != firstElementSet.end() ) { firstElementSet.erase(itr2); } } for ( itr1 = secondElementSet.begin(); itr1 != secondElementSet.end(); ++itr1 ) { itr2 = firstElementSet.find(*itr1); if ( itr2 != secondElementSet.end() ) { secondElementSet.erase(itr2); } } return new ConstantPropLatticeElement(secondElementSet); }
void SpinPointSpace::fillLinks(const ElementSet& inf, ElementSet& res) { #ifdef _DEBUG assert( d_st && d_st->getDimCount() > 1 && d_noesy != DimUndefined ); #endif // Finde zuerst raus, zwischen welchen Dim es Noesy gibt. // Wir gehen hier davon aus, dass immer nur ein Noesy-Step vorhanden ist. // 8.3.04 Fred meint, showAll sei nicht nötig und es genüge, die Links // auf NOESY zu beschränken. // Eigentlich könnte man den NOESY-Step sogar auf den letzten Step beschränken. const Dimension dim = d_st->getDimCount(); const AtomType noesyColor = d_st->getColor( d_noesy ); for( ElementSet::const_iterator i = inf.begin(); i != inf.end(); ++i ) { // Gehe durch alle Points, die durch Pathsim gefunden wurden Element p = (*i); for( Dimension d = 0; d < dim; d++ ) { p.reset(); if( d != d_noesy ) { p.setLink( d, d_noesy ); Spin* me = p.d_point[ d ]; // Suche für jeden Pathsim-Point alle Links zur Noesy-Dim for( Spin::Links::const_iterator l = me->getLinks().begin(); l != me->getLinks().end(); ++l ) { Spin* other; if( (*l)->getRhs() != me->getId() ) other = d_spins->getSpin( (*l)->getRhs() ); else other = d_spins->getSpin( (*l)->getLhs() ); if( other && other->getAtom() == noesyColor ) { if( d_showInferred ) // Trick, damit die intraresiduellen infered bleiben. p.setInfer( me->getSystem() == other->getSystem() ); p.d_point[ d_noesy ] = other; res.insert( p ); } } } } } }
void SpinPointSpace::updateAddLink( Spin* lhs, Spin* rhs ) { if( !d_st.isNull() ) { const bool showLink = d_showLinks && d_noesy != DimUndefined && d_st->getDimCount() > 1; if( !showLink ) return; ElementSet inf; inferPeaks( inf, lhs->getSystem(), lhs->getLabel() ); inferPeaks( inf, rhs->getSystem(), rhs->getLabel() ); ElementSet links; ElementSet::const_iterator j; fillLinks( inf, links ); for( j = links.begin(); j != links.end(); ++j ) _merge( this, d_res, (*j) ); } }
void SysFilterSpace::refill() { d_res.clear(); if( d_sys ) { ElementSet res; SpinSpace::Iterator i, _end = d_host->end(); SpinSpace::Element e; for( i = d_host->begin(); i != _end; ++i ) { d_host->fetch( i, e ); e.setHigher(); e.setLower(); bool ok = false; const Dimension dim = d_host->getDimCount(); for( Dimension d = 0; d < dim; d++ ) { if( e.d_point[ d ]->getSystem() == d_sys ) { e.setHigher( false ); e.setLower( false ); ok = true; break; } } if( d_showGhosts ) ok = true; if( ok ) res.insert( e ); } ElementSet::const_iterator j; for( j = res.begin(); j != res.end(); ++j ) d_res.insert( (*j) ); } SpinSpace::Update m( this, SpinSpace::Update::All ); notifyObservers( m ); }
ElementSet Evaluator::eval( const ElementSet& elements, Env* env) { assert(env); std::vector<std::shared_ptr<Elem> > retVec; if(elements.size() >= 1) { auto element = elements[0]; if (element->type == DATA_TYPE::NILL) { std::shared_ptr<Elem> retVal(new Elem()); retVal->type = DATA_TYPE::NILL; retVec.push_back(retVal); return retVec; } else if (element->type == SYMBOL) { std::shared_ptr<Elem> retVal(new Elem()); assert(element->valExp.size() == 0); Env* foundEnv = env->findInHier(element->valStr); if (!foundEnv) throw std::runtime_error("No such variable found:" + element->valStr); auto map = foundEnv->getMap(); for_each(map.begin(),map.end(),[](std::pair<const std::basic_string<char>, std::shared_ptr<Elem> > i) { std::cout << "key:" << i.first << " val:" << i.second << std::endl; }); std::shared_ptr<Elem> foundElem = foundEnv->find(element->valStr); if (bool(foundEnv) != false) { switch (foundElem->type) { case DATA_TYPE::INT: retVal->valInt = foundElem->valInt; retVal->type = DATA_TYPE::INT; break; case DATA_TYPE::DOUBLE: retVal->valDbl = foundElem->valDbl; retVal->type = DATA_TYPE::DOUBLE; break; case DATA_TYPE::STRING: retVal->valStr = foundElem->valStr; retVal->type = DATA_TYPE::STRING; break; default: throw std::runtime_error("Incorect type for data"); break; } retVec.push_back(retVal); return retVec; } else { throw std::runtime_error("No Env with Given Var"); } } else if (element->type == DATA_TYPE::INT || element->type == DATA_TYPE::STRING || element->type == DATA_TYPE::DOUBLE) { retVec.push_back(element); return retVec; } else if (element->type == QUOTE) { retVec.assign(elements.begin()+1, elements.end()); return retVec; } else if (element->type == SET) { assert(element->valExp.size() == 2); auto elementVar = element->valExp[0]; auto elementVal = element->valExp[1]; Env* foundEnv = env->findInHier(elementVar->valStr); if (foundEnv == nullptr) { env->insert(elementVar->valStr,elementVal); return retVec; } else { throw std::runtime_error("No Env with Given Var"); } } else if (element->type == DATA_TYPE::PROC) { auto retVal = eval(element->valExp, env); retVec.insert(retVec.end(), retVal.begin(), retVal.end()); return retVec; } else { throw std::runtime_error("I dont know what to do!!"); } } return retVec; }
void RangeFilterSpace::refill() { d_res.clear(); ElementSet res; const Dimension dim = d_host->getDimCount(); if( d_dim >= DimX && d_dim < dim ) { SpinSpace::Iterator i, _end = d_host->end(); SpinSpace::Element e; PpmRange inner( d_orig + d_width * 0.5, d_orig - d_width * 0.5 ); PpmRange outer = inner; if( d_showGhosts && d_planes > 0.0 ) outer.expand( d_planes - d_width ); bool ok; bool ghost; PPM shift; Dimension d; for( i = d_host->begin(); i != _end; ++i ) { d_host->fetch( i, e ); shift = e.d_point[ d_dim ]->getShift( d_host->getSpec() ); e.setHigher(); e.setLower(); ghost = true; if( inner.contains( shift ) ) { ok = true; ghost = false; }else if( d_showGhosts && outer.contains( shift ) ) { if( shift > inner.first ) e.setLower( false ); if( shift < inner.second ) e.setHigher( false ); ok = true; }else ok = false; if( d_sys && ok ) { ok = false; for( d = 0; d < dim; d++ ) { if( e.d_point[ d ]->getSystem() == d_sys ) { e.setHigher( false ); e.setLower( false ); ok = true; break; } } if( d_showGhosts ) ok = true; }else if( ok && !ghost ) { e.setHigher( false ); e.setLower( false ); } if( ok ) res.insert( e ); } } ElementSet::const_iterator j; for( j = res.begin(); j != res.end(); ++j ) d_res.insert( (*j) ); SpinSpace::Update m( this, SpinSpace::Update::All ); notifyObservers( m ); }