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) ); } }
/*! \fn Pin::setCurrentIfOneWire(double current) */ bool Pin::setCurrentIfOneWire() { if(m_wireList.size() == 1) { /* double current = 0; ElementList::iterator end = m_elementList.end(); for(ElementList::iterator it = m_elementList.begin(); it != end;++it) { current += (*it)->updateCurrents(); }*/ ElementSet *es = (*(m_elementList.begin()))->elementSet(); if(es && m_elementList.empty() == false) (*(m_wireList.begin()))->setCurrent( es->cNode(m_eqId)->current()); else (*(m_wireList.begin()))->setCurrent(0); return true; } else { // inform wires that they don't know their current // and have to figure it out for themselves. // TODO: if we only have ONE unknown wire, we can still compute currents... =P WireList::iterator end = m_wireList.end(); for(WireList::iterator it = m_wireList.begin(); it != end; ++it) { (*it)->setCurrentKnown(false); } return false; } }
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); }
bool it_should_give_the_number_of_the_visited_subsets () { ElementSet set ("S1", 3, 1); // |S1| = 3 CHCGA t; SubsetSum c (&set); t.set_parameters (&c, &set, true); t.get_minima_list (1); if ((t.print_list_of_visited_subsets ().size () / (set.get_set_cardinality() + 4)) >= 7) return true; else return false; }
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 ); }
bool a_random_element_should_be_removed () { unsigned int i; ElementSet set ("S1",3,2); ElementSubset X ("X", &set); X.set_complete_subset (); i = X.remove_random_element (); if (!(((!X.has_element (0)) && (X.has_element (1)) && (X.has_element (2)) && (i == 0)) || ((X.has_element (0)) && (!X.has_element (1)) && (X.has_element (2)) && (i == 1) ) || ((X.has_element (0)) && (X.has_element (1)) && (!X.has_element (2)) && (i == 2)))) return false; X.remove_random_element (); if (X.is_empty ()) return false; X.remove_random_element (); if (!X.is_empty ()) return false; if ((X.is_empty ()) && (X.remove_random_element () == set.get_set_cardinality ())) return true; else return false; }
void SpinPointSpace::fillTuples( Element& elem, SpinSystem* sys, const PathTable::Path& path, ElementSet& res, Dimension dim ) { Q_ASSERT( d_st != 0 ); Q_ASSERT( sys != 0 ); // Wandert entlang den Anchor-Dimensions und fügt zuletzt das Tuple ein, // wenn man überhaupt soweit kommt. Implizit findet auch eine // Multiplikation über alle non-final-Kombinationen statt. SpinSystem::Spins spins; const SpinLabel& label = path[ dim ]; if( false ) // dim == d_noesy ) // ab CARA 1.9.1 werden alle NOESY von NmrExperiment explizit in Atome aufgelöst { spins = sys->findNoesySpins( d_st->getColor( dim ), d_showNulls, d_showOffs ); // Dieser Schritt holt sich einfach alle Spins der gegebenen Atomfarbe aus dem System, unabhängig // vom SystemType bzw. ResidueType des Systems. }else { spins = sys->findSpins( label.getTag(), label.getOff(), d_st->getColor( dim ), d_showNulls, d_showOffs, d_showUnknown ); // Es werden auch non-finals verwendet. // Diese müssen zumindest im Label übereinstimmen if( label.getTag().isNull() ) elem.setInfer(false); // In diesem Fall hat findSpins ein cross-product gemacht; das // kommt nur vor, wenn ResiType nicht bekannt oder SpecType keine Proc hat. } // QStringList tmp; // TEST // for( SpinSystem::Spins::const_iterator i = spins.begin(); i != spins.end(); ++i ) // tmp << (*i)->getLabel().getTag().data(); // qDebug() << dim << label.getTag().data() << d_st->getColor( dim ).getAtomLabel() << tmp; const Dimension dmax = d_st->getDimCount(); SpinSystem::Spins::const_iterator spinIter; for( spinIter = spins.begin(); spinIter != spins.end(); ++spinIter ) { elem.d_point[ dim ] = (*spinIter); if( dim < dmax - 1 ) fillTuples( elem, sys, path, res, dim + 1 ); else res.insert( elem ); } }
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); }
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 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::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 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 ); }