Ejemplo n.º 1
0
void ChowLiuTree::createBaseEdges(std::list<info>& edges, double infoThreshold) {

    int nWords = imgDescriptors[0].cols;

#pragma omp parallel for schedule(dynamic, 500)
    for(int word1 = 0; word1 < nWords; word1++) {
        std::list<info> threadEdges;
        info mutInfo;
        for(int word2 = word1 + 1; word2 < nWords; word2++) {
            mutInfo.word1 = (short)word1;
            mutInfo.word2 = (short)word2;
            mutInfo.score = (float)calcMutInfo(word1, word2);
            if(mutInfo.score >= infoThreshold)
            threadEdges.push_back(mutInfo);
        }
#pragma omp critical
        {
            edges.splice(edges.end(), threadEdges);
        }

        // Status
        if (nWords >= 10 && (word1+1)%(nWords/10) == 0)
            std::cout << "." << std::flush;
    }
    edges.sort(sortInfoScores);
}
Ejemplo n.º 2
0
SDL_Surface* QuickSaveImageCache::get(std::string image_name) {
    std::map<std::string, cache_iter_t>::iterator it = m_images.find(image_name);
    if (it != m_images.end()) {
        // found it: move to front of list
        m_used.splice(m_used.begin(), m_used, it->second);
        return it->second->second;
    }
    
    // didn't find: load image
    FileSpecifier f;
    f.SetToQuickSavesDir();
	f.AddPart(image_name + ".sgaA");
	
	WadImageDescriptor desc;
	desc.file = f;
	desc.checksum = 0;
	desc.index = SAVE_GAME_METADATA_INDEX;
	desc.tag = SAVE_IMG_TAG;
	
	SDL_Surface *img = WadImageCache::instance()->get_image(desc, PREVIEW_WIDTH, PREVIEW_HEIGHT);
	if (img) {
        m_used.push_front(cache_pair_t(image_name, img));
        m_images[image_name] = m_used.begin();
        
        // enforce maximum cache size
        if (m_used.size() > k_max_items) {
            cache_iter_t lru = m_used.end();
            --lru;
            m_images.erase(lru->first);
            SDL_FreeSurface(lru->second);
            m_used.pop_back();
        }
    }
    return img;
}
Ejemplo n.º 3
0
void Rect::connectRects(std::list<std::pair<GEOMETRY_Object*, Rect> >& rects)
{
	for(std::list<Rect>::iterator i = rects.begin(); i != rects.end(); ++i)
		for(std::list<Rect>::iterator j = rects.begin(); j != rects.end(); )
			if(i == j)
				++j;
			else if(i->isRectInside(*j))
				j = rects.erase(j);
			else if((j->getWidth() == 0) || (j->getHeight() == 0))
				j = rects.erase(j);
			else
			{
				std::list<Rect> t_list;
				bool change = false;
				t_list = i->connectRect(*j, change);
				if(change)
				{
					rects.erase(i);
					rects.erase(j);
					rects.splice(rects.begin(), t_list);
					j = rects.begin();
					i = rects.begin();
				} else ++j;
			}
			TODO

}
void DataClassManager::BuildDependencyList(std::list<DataClass *> &dependencies, DataClassKind kind)
{
   for(auto& i : m_map)
   {
      DataClass* dc = i.second;

      if (dc->GetType()->GetKind() == kind)
      {
         std::list<DataClass*> current;

         //see if something already depends on current dc
         std::list<DataClass*>::iterator di;
         for(di = dependencies.begin(); di != dependencies.end(); ++di)
         {
            if (*di == dc)
            {
               break;
            }
         }
         if (di == dependencies.end())
         {
            current.push_back(dc); // new to the fray
         }
         else
         {
            //splice off current node and everything that depends on it
            current.splice(current.begin(), dependencies, di, dependencies.end());
         }

         std::list<DataClass*> dependsOn;
         dc->GetDirectDependencies(dependsOn);

         //add depends on to the list if DNE
         for(DataClass* d : dependsOn)
         {
            bool found = false;
            for(DataClass* e : dependencies)
            {
               if (e == d)
               {
                  found = true;
                  break;
               }
            }
            if (!found)
            {
               dependencies.push_back(d);
            }
         }

         //now splice in the current and list of everything that depends on it
         dependencies.splice(dependencies.end(), current);
      }
   }
}
Ejemplo n.º 5
0
// By design, succeed only if the entire request is in a single cached chunk
int ChunksCache::Read(void* pDest, PX_off_t offset, int length) {
	for (auto it = m_entries.begin(); it != m_entries.end(); it++) {
		CacheEntry* e = *it;
		if (e && offset >= e->offset && (offset + length) <= (e->offset + e->coverage)) {
			if (it != m_entries.begin())
				m_entries.splice(m_entries.begin(), m_entries, it); // Move to top (MRU)
			return CopyAvailable(e->data, e->offset, e->size, pDest, offset, length);
		}
	}
	return -1;
}
Ejemplo n.º 6
0
Archivo: main.cpp Proyecto: CCJY/coliru
typename std::list<T, Allocator>::iterator
list_partition(std::list<T, Allocator>& list, Predicate predicate) {
  auto first = list.begin();
  auto last = list.end();

  for (;;) {
    for (; first != last && predicate(*first); ++first) {}
    for (; first != last && !predicate(*std::prev(last)); --last) {}
    if (first == last) {
      return first;
    }

    auto next = std::next(first);
    auto prev = std::prev(last);
    list.splice(last, list, first);
    list.splice(next, list, prev);
    last = first;
    first = next;
  }
}
Ejemplo n.º 7
0
void DownloadsObserver::GetList(std::list<ObserverDownloadInfo>& lst)
{
	wxMutexLocker lock(mutex);
	std::list<IDownload*>::iterator it;
	for (it = m_dl_list.begin(); it != m_dl_list.end(); ++it) {
		ObserverDownloadInfo di = GetInfo((*it));
		if (di.size > 0)
			lst.push_back(di);
	}

	lst.splice(lst.begin(), m_finished_list);
}
Ejemplo n.º 8
0
				/** Bump a certain UIListener, such that it becomes the first in the line of all listeners.
				  * This may be required in situations where UIListeners need to (temporarily) ensure
				  * that they receive all input defined in their InputSet with absolute priority.
				  * Since it is not possible to return the InputSet to its original position, the only
				  * ways to reverse the change are:
				  * - Calling the same function for whatever UIListener receives conflicting input
				  *   (this is difficult);
				  * - Only using this function for UIListeners that have limited effect and that, on
				  *   specific input, will remove (nearly) all keys it defines in its InputSet, such
				  *   that the input can again be received by its usual recipient (recommended).
				  */
				void bump(intf::UIListener * listener)
				{
					for(ListenerIterator it = listeners.begin(); it != listeners.end(); it++)
						if(*it == listener)
						{
							// Move the listener to the front of the list.
							listeners.splice(listeners.begin(), listeners, it);
							return;
						}
					std::cout << " InputInterpreter::bump() :";
					std::cout << " WARNING: Listener not found in keySets!"<<std::endl;
				}
Ejemplo n.º 9
0
TBool DviSsdpNotifierManager::TryMove(SsdpNotifierScheduler* aScheduler, std::list<Notifier*>& aFrom, std::list<Notifier*>& aTo)
{
    std::list<Notifier*>::iterator it = aFrom.begin();
    while (it != aFrom.end()) {
        if ((*it)->Scheduler() == aScheduler) {
            (*it)->SetInactive();
            aTo.splice(aTo.end(), aFrom, it);
            return true;
        }
        it++;
    }
    return false;
}
Ejemplo n.º 10
0
void VDChunkedBuffer::AllocChunk() {
	if (mFreeChunks.empty()) {
		mFreeChunks.push_back(ChunkInfo());

		ChunkInfo& ci = mFreeChunks.back();
		ci.mpChunk		= VDFile::AllocUnbuffer(mChunkSize);
		if (!ci.mpChunk)
			throw MyMemoryError();
		ci.mChunkSize	= mChunkSize;
	}

	mActiveChunks.splice(mActiveChunks.end(), mFreeChunks, mFreeChunks.begin());
}
  static void GetChildren(std::list<std::string>& target,
                          ServerIndex& index,
                          const std::list<std::string>& source)
  {
    target.clear();

    for (std::list<std::string>::const_iterator
           it = source.begin(); it != source.end(); ++it)
    {
      std::list<std::string> tmp;
      index.GetChildren(tmp, *it);
      target.splice(target.end(), tmp);
    }
  }
Ejemplo n.º 12
0
void ofxWidget::setParent(std::shared_ptr<ofxWidget>& p_)
{
	if (auto p = mParent.lock()) {
		// TODO: handle already parented widgets 
		// how weird! this widget has a parent already.
		// delete the widgets from the parent's child list
		ofLogWarning() << "Widget already has parent!";
		return;
	}

	// find ourselves in widget list
	auto itMe = findIt(mThis, sAllWidgets.begin(), sAllWidgets.end());
	// find parent in widget list
	weak_ptr<ofxWidget> tmpParent = p_;
	auto itParent = findIt(tmpParent, sAllWidgets.begin(), sAllWidgets.end());

	/*

	When an object gets a parent,

	1. move it to the beginning of the parent's child range.
	2. set its parent pointer
	3. increase parent's child count by number of (own children + 1 ), recursively.

	*/

	if (itParent != sAllWidgets.end()) {
		// move current element and its children to the front of the new parent's child range
		if (auto parent = itParent->lock()) {

			sAllWidgets.splice(
				std::prev(itParent, parent->mNumChildren), 				// where to move elements to -> front of parent range
				sAllWidgets, 											// where to take elements from
				std::prev(itMe, mNumChildren), std::next(itMe));		// range of elements to move -> range of current element and its children

			mParent = parent; // set current widget's new parent
			// now increase the parents child count by (1+mNumChildren), recursively

			parent->mNumChildren += (1 + mNumChildren);

			while (parent = parent->mParent.lock()) {
				// travel up parent hierarchy and increase child count for all ancestors
				parent->mNumChildren += (1 + mNumChildren);
			}
		}
	}

	ofxWidget::bVisibleListDirty = true;
}
Ejemplo n.º 13
0
static void remove_internal( const std::function<bool( item & )> &filter, item &node, int &count,
                             std::list<item> &res )
{
    for( auto it = node.contents.begin(); it != node.contents.end(); ) {
        if( filter( *it ) ) {
            res.splice( res.end(), node.contents, it++ );
            if( --count == 0 ) {
                return;
            }
        } else {
            remove_internal( filter, *it, count, res );
            ++it;
        }
    }
}
 void append(K const& key, VV&& value) {
     std::unique_lock<std::mutex> lock(mutex);
     
     if (map.find(key) != map.end()) {
         map[key]->second = std::forward<VV>(value);
         lst.splice(lst.begin(), lst, map[key]);
     } else {
         lst.emplace_front(key, std::forward<VV>(value));
     }
     
     map[key] = lst.begin();
     
     if (lst.size() > max_size) {
         map.erase(lst.back().first);
         lst.pop_back();
     }
 }
Ejemplo n.º 15
0
//TODO: use path intersection stuff!
void uncross(std::list<Point> &loop){
    std::list<Point>::iterator b0 = loop.begin(),a0,b1,a1;
    if ( b0 == loop.end() ) return;
    a0 = b0;
    ++b0;
    if ( b0 == loop.end() ) return;
    //now a0,b0 are 2 consecutive points.
    while ( b0 != loop.end() ){
        b1 = b0;
        ++b1;
        if ( b1 != loop.end() ) {
            a1 = b1;
            ++b1;
            if ( b1 != loop.end() ) {
                //now a0,b0,a1,b1 are 4 consecutive points.
                Point c;
                while ( b1 != loop.end() ){
                    if ( intersect(*a0,*b0,*a1,*b1,c) ){
                        if ( c != (*a0) && c != (*b0) ){
                            loop.insert(b1,c);
                            loop.insert(b0,c);
                            ++a1;
                            std::list<Point> loop_piece;
                            loop_piece.insert(loop_piece.begin(), b0, a1 );
                            loop_piece.reverse();
                            loop.erase( b0, a1 );
                            loop.splice( a1, loop_piece );
                            b0 = a0;
                            ++b0;
                            //a1 = b1; a1--;//useless
                        }else{
                            //TODO: handle degenerated crossings...
                        }
                    }else{
                        a1=b1;
                        ++b1;
                    }
                }
            }
        }
        a0 = b0;
        ++b0;
    }
    return;//We should never reach this point.
}
Ejemplo n.º 16
0
void VDAVIOutputSegmentedVideoStream::ScheduleSamples(uint32 samples) {
	std::list<Run>::iterator it(mPendingRuns.begin()), itEnd(mPendingRuns.end());
	for(; it!=itEnd; ++it) {
		const Run& run = *it;
		if (!run.mbClosed)
			break;

		uint32 n = (uint32)run.mBlocks.size();

		if (n > samples)
			break;

		samples -= n;
		mScheduledSamples += n;
	}

	if (it != mPendingRuns.begin())
		mClearedRuns.splice(mClearedRuns.end(), mPendingRuns, mPendingRuns.begin(), it);
}
Ejemplo n.º 17
0
/**
 * Deterministic selection algorithm
 * Linear running time
 * 
 * @param diff List of differences between ratings
 * @param k Which positioned difference to select
 * @return The k-th smallest difference
 */
int InverseOffsetAnalyzed::selectionDet(std::list<int> &diff, int k) const {
   std::list<int> b;
   for(auto it = diff.begin(); it != diff.end();) {
      std::list<int> c;
      auto pos = it;
      int count = 0;
      while(count < 5 && it != diff.end()) {
         ++it;
         ++count;
      } // end while
      c.splice(c.begin(), diff, pos, it);

      c.sort();
      pos = c.begin();
      std::advance(pos, count/2);
      b.push_back(*pos);
      diff.splice(it, c);
   } // end for
   int medB;
   if(b.size() <= 2)
      medB = *b.begin();
   else
      medB = selectionDet(b, b.size()/2);
   std::list<int> a1;
   std::list<int> a2;
   for(int i : diff) {
      if(i < medB)
         a1.push_back(i);
      else if(medB < i)
         a2.push_back(i);
   } // end for
   if(a1.size() <= k && k < diff.size()-a2.size())
      return medB;
   if(k < a1.size())
      return selectionDet(a1, k);
   return selectionDet(a2, k-(diff.size()-a2.size()));
} // selectionDet
Ejemplo n.º 18
0
Archivo: main.cpp Proyecto: CCJY/coliru
typename std::list<T, Allocator>::iterator
stable_list_partition(std::list<T, Allocator>& list, Predicate predicate) {
  auto first = list.begin();
  auto partition_point = list.end();
  for (;;) {
    if (first == partition_point) return first;
    if (!predicate(*first)) break;
    ++first;
  }
  partition_point = first;

  if (std::next(first) == list.end()) return first;

  for(;;) {
    auto next = std::next(first);
    list.splice(list.end(), list, first);
    first = next;
    for (;;) {
      if (first == partition_point) return first;
      if (!predicate(*first)) break;
      ++first;
    }
  }
}
Ejemplo n.º 19
0
	/*
	 * Moves a given item to the front of the cache.
	 */
	void touch(LRUKey key) {
		elements.splice(elements.begin(), elements, map[key]);
	}
Ejemplo n.º 20
0
void ofxWidget::bringToFront(std::list<weak_ptr<ofxWidget>>::iterator it_)
{
	if (it_->expired())
		return;

	// ---------| invariant: element is valid

	auto element = it_->lock();

	// We're conservative with re-ordering.
	// Let's move the iterator backward to see if we are actually 
	// already sorted.
	// If the list were already sorted, then moving back from the current
	// iterator by the number of its children would bring us 
	// to the beginning of sAllWidgets. Then, there is no need to re-order.
	if (std::prev(it_, element->mNumChildren) == sAllWidgets.begin())
		return;

	// ----------| invariant: element (range) not yet at front.

	/*
	Algorithm:

	while current object range has a parent, put current object
	range to the front of parent range make parent range current
	object range.

	As soon as there is no parent anymore, put last object range
	to the front of the list

	Heuristic: parent iterator's position always to be found
	after current iterator.
	*/

	auto parent = element->mParent.lock();
	auto elementIt = it_;

	while (parent) {

		auto itParent = findIt(element->mParent, std::next(elementIt), sAllWidgets.end()); // start our search for parent after current element.

		// if element has parent, bring element range to front of parent range.
		if (std::prev(elementIt, element->mNumChildren) != std::prev(itParent, parent->mNumChildren)) {
			sAllWidgets.splice(
				std::prev(itParent, parent->mNumChildren), 					// where to move elements to -> front of parent range
				sAllWidgets, 												// where to take elements from
				std::prev(elementIt, element->mNumChildren),
				std::next(elementIt));		// range of elements to move -> range of current element and its children
		}

		// because sAllWidgets is a list, splice will only invalidate iterators 
		// before our next search range.

		elementIt = itParent;
		element = elementIt->lock();
		parent = element->mParent.lock();
	}

	// now move the element range (which is now our most senior parent element range) to the front fo the list.

	if (std::prev(elementIt, element->mNumChildren) != sAllWidgets.begin()) {
		sAllWidgets.splice(
			sAllWidgets.begin(),
			sAllWidgets,
			std::prev(elementIt, element->mNumChildren), // from the beginning of our now most senior parent element range
			std::next(elementIt));						 // to the end of our now most senior parent element range
	}

	ofxWidget::bVisibleListDirty = true;
}
Ejemplo n.º 21
0
ASR_RETVAL fpathAStarRoute(MOVE_CONTROL *psMove, PATHJOB *psJob)
{
	ASR_RETVAL      retval = ASR_OK;

	bool            mustReverse = true;

	const PathCoord tileOrig(map_coord(psJob->origX), map_coord(psJob->origY));
	const PathCoord tileDest(map_coord(psJob->destX), map_coord(psJob->destY));

	PathCoord endCoord;  // Either nearest coord (mustReverse = true) or orig (mustReverse = false).

	std::list<PathfindContext>::iterator contextIterator = fpathContexts.begin();
	for (contextIterator = fpathContexts.begin(); contextIterator != fpathContexts.end(); ++contextIterator)
	{
		if (!contextIterator->matches(psJob->blockingMap, tileDest))
		{
			// This context is not for the same droid type and same destination.
			continue;
		}

		// We have tried going to tileDest before.

		if (contextIterator->map[tileOrig.x + tileOrig.y*mapWidth].iteration == contextIterator->iteration
		 && contextIterator->map[tileOrig.x + tileOrig.y*mapWidth].visited)
		{
			// Already know the path from orig to dest.
			endCoord = tileOrig;
		}
		else
		{
			// Need to find the path from orig to dest, continue previous exploration.
			fpathAStarReestimate(*contextIterator, tileOrig);
			endCoord = fpathAStarExplore(*contextIterator, tileOrig);
		}

		if (endCoord != tileOrig)
		{
			// orig turned out to be on a different island than what this context was used for, so can't use this context data after all.
			continue;
		}

		mustReverse = false;  // We have the path from the nearest reachable tile to dest, to orig.
		break;  // Found the path! Don't search more contexts.
	}

	if (contextIterator == fpathContexts.end())
	{
		// We did not find an appropriate context. Make one.

		if (fpathContexts.size() < 30)
		{
			fpathContexts.push_back(PathfindContext());
		}
		--contextIterator;

		// Init a new context, overwriting the oldest one if we are caching too many.
		// We will be searching from orig to dest, since we don't know where the nearest reachable tile to dest is.
		fpathInitContext(*contextIterator, psJob->blockingMap, tileOrig, tileOrig, tileDest);
		endCoord = fpathAStarExplore(*contextIterator, tileDest);
		contextIterator->nearestCoord = endCoord;
	}

	PathfindContext &context = *contextIterator;

	// return the nearest route if no actual route was found
	if (context.nearestCoord != tileDest)
	{
		retval = ASR_NEAREST;
	}

	// Get route, in reverse order.
	static std::vector<Vector2i> path;  // Declared static to save allocations.
	path.clear();

	PathCoord newP;
	for (PathCoord p = endCoord; p != context.tileS; p = newP)
	{
		ASSERT_OR_RETURN(ASR_FAILED, tileOnMap(p.x, p.y), "Assigned XY coordinates (%d, %d) not on map!", (int)p.x, (int)p.y);
		ASSERT_OR_RETURN(ASR_FAILED, path.size() < (unsigned)mapWidth*mapHeight, "Pathfinding got in a loop.");

		path.push_back(Vector2i(world_coord(p.x) + TILE_UNITS / 2, world_coord(p.y) + TILE_UNITS / 2));

		PathExploredTile &tile = context.map[p.x + p.y*mapWidth];
		newP = PathCoord(p.x - tile.dx, p.y - tile.dy);
		if (p == newP)
		{
			break;  // We stopped moving, because we reached the closest reachable tile to context.tileS. Give up now.
		}
	}
	if (path.empty())
	{
		// We are probably already in the destination tile. Go to the exact coordinates.
		path.push_back(Vector2i(psJob->destX, psJob->destY));
	}
	else if (retval == ASR_OK)
	{
		// Found exact path, so use exact coordinates for last point, no reason to lose precision
		Vector2i v(psJob->destX, psJob->destY);
		if (mustReverse)
		{
			path.front() = v;
		}
		else
		{
			path.back() = v;
		}
	}

	// TODO FIXME once we can change numPoints to something larger than uint16_t
	psMove->numPoints = std::min<int>(UINT16_MAX, path.size());

	// Allocate memory
	psMove->asPath = static_cast<Vector2i *>(malloc(sizeof(*psMove->asPath) * path.size()));
	ASSERT(psMove->asPath, "Out of memory");
	if (!psMove->asPath)
	{
		fpathHardTableReset();
		return ASR_FAILED;
	}

	// get the route in the correct order
	// If as I suspect this is to reverse the list, then it's my suspicion that
	// we could route from destination to source as opposed to source to
	// destination. We could then save the reversal. to risky to try now...Alex M
	//
	// The idea is impractical, because you can't guarentee that the target is
	// reachable. As I see it, this is the reason why psNearest got introduced.
	// -- Dennis L.
	//
	// If many droids are heading towards the same destination, then destination
	// to source would be faster if reusing the information in nodeArray. --Cyp
	if (mustReverse)
	{
		// Copy the list, in reverse.
		std::copy(path.rbegin(), path.rend(), psMove->asPath);

		if (!context.isBlocked(tileOrig.x, tileOrig.y))  // If blocked, searching from tileDest to tileOrig wouldn't find the tileOrig tile.
		{
			// Next time, search starting from nearest reachable tile to the destination.
			fpathInitContext(context, psJob->blockingMap, tileDest, context.nearestCoord, tileOrig);
		}
	}
	else
	{
		// Copy the list.
		std::copy(path.begin(), path.end(), psMove->asPath);
	}

	// Move context to beginning of last recently used list.
	if (contextIterator != fpathContexts.begin())  // Not sure whether or not the splice is a safe noop, if equal.
	{
		fpathContexts.splice(fpathContexts.begin(), fpathContexts, contextIterator);
	}

	psMove->destination = psMove->asPath[path.size() - 1];

	return retval;
}
Ejemplo n.º 22
0
void laganChaining(std::list<TSeed> & chain, 
				   TSegment const & a,
				   TSegment const & b,
				   TSize q)
{
	if (((TSize)length(a) <= gaps_max) && ((TSize)length(b) <= gaps_max)) return;

	//Step 1: find seeds
	typedef typename Value<TSeed>::Type TPosition;
	typedef SeedSet<TPosition, SimpleSeed, DefaultScore> TSeedSet;
	TSeedSet seedset(limit, score_min, scoring_scheme);

	typedef Index< TSegment, IndexQGram<SimpleShape > > TQGramIndex;
	TQGramIndex index_qgram(b);

	typedef Finder<TQGramIndex> TFinder;
	TFinder finder(index_qgram);

	while (length(seedset) == 0)
	{
		if (q < q_min) return;

		resize(indexShape(index_qgram), q);
		for (unsigned int i = 0; i < length(a)-q+1; ++i)
		{
			while (find(finder, infix(a, i, i+q)))
			{
				typedef typename Position<TFinder>::Type TPosition;
				TPosition a_pos = beginPosition(a)+i;
				TPosition b_pos = beginPosition(b)+position(finder);
				if (!addSeed(seedset, a_pos, b_pos, q, 0, Merge()))
				if (!addSeed(seedset, a_pos, b_pos, q, host(a), host(b), bandwidth, Chaos()))
					 addSeed(seedset, a_pos, b_pos, q, Single());
			}
			clear(finder);
		}
		--q;
	}

	//Step 2: global chaining
	globalChaining(seedset, chain);
	clear(seedset);

	//Step 3: recursively fill gaps
	if (q > q_min)
	{
		std::list<TSeed> subchain;
		typedef typename std::list<TSeed>::iterator TIterator;

		TIterator it = chain.begin();
		TIterator it2 = it; 
		++it2;

		laganChaining(subchain, 
			infix(host(a), beginPosition(a), leftDim0(*it)), 
			infix(host(b), beginPosition(b), leftDim1(*it)), q);
		chain.splice(it, subchain);

		while(it2 != chain.end())
		{
			laganChaining(subchain, 
				infix(host(a), rightDim0(*it), leftDim0(*it2)), 
				infix(host(b), rightDim1(*it), leftDim1(*it2)), q);
			chain.splice(it2, subchain);

			it = it2;
			++it2;
		}

		laganChaining(subchain, 
			infix(host(a), rightDim0(*it), endPosition(a)), 
			infix(host(b), rightDim1(*it), endPosition(b)), q);
		chain.splice(it2, subchain);
	}
}
void eventpos::reinit(real time_, rvec r, 
                      const deque<mol> &meas_mols, 
                      const deque<mol> &ref_mols, t_pbc *pbc,
                      matrix ref_trans,
                      rvec com_meas_tot, rvec com_meas_tot_dx,
                      rvec com_ref_tot, rvec com_ref_tot_dx,
                      real weight_sigma, int closest_n, event_type type_,
                      event_direction evdir_,
                      bool calc_r_, std::list<anchor> &spare_anchor_list,
                      real ref_dist_sq_)
{
    event_happened=false;
    checked=true; // because we don't want cumulative dxes to start at t=0
    time=time_;
    type=type_;

    ref_dist_sq = ref_dist_sq_;

    // remove all the existing anchors
    spare_anchor_list.splice(spare_anchor_list.begin(), anchors);

    if (weight_sigma > 0)
    {
        weight_sigmasq = weight_sigma*weight_sigma;
        use_weights=true;
        if (closest_n > 0)
        {
            gmx_fatal(FARGS, "ERRROR: both closest_n >0 and weight_sigma >0");
        }
    }
    else if (closest_n > 0)
    {
        use_weights=true;
    }
    else
    {
        weight_sigmasq=0;
        use_weights=false;
    }
        
    weight_norm = 1./sqrt(2.*M_PI*weight_sigmasq);

    real com_weight=0.;

    evdir=evdir_;

    anchor_d=0.;

    if (use_weights)
    {
        if (closest_n > 0)
        {
            const mol* closest[closest_n];
            double dsq_max[closest_n];
            for(int i=0;i<closest_n;i++)
            {
                closest[i] = NULL;
                dsq_max[i] = 1e20;
            }
            int k=0;

            // now find the closest n mols
            for(deque<mol>::const_iterator i=ref_mols.begin(); 
                i!=ref_mols.end(); ++i)
            {
                rvec dxvec;
                rvec lcom;
                i->get_com(lcom);

                // calculate distance vector
                pbc_dx(pbc, r, lcom, dxvec); 
                // and calculate distance to base weights on
                real dsq;
                switch(evdir)
                {
                    case evdir_xyz:
                    default:
                        dsq = (dxvec[XX]*dxvec[XX] + dxvec[YY]*dxvec[YY] + 
                               dxvec[ZZ]*dxvec[ZZ]);
                        break;
                    case evdir_xy:
                        dsq = dxvec[XX]*dxvec[XX] + dxvec[YY]*dxvec[YY];
                        break;
                    case evdir_z:
                        dsq = dxvec[ZZ]*dxvec[ZZ];
                        break;
                }
                k++;
                /* check whether it's closer than any before */
                if (dsq < dsq_max[closest_n-1])
                {
                    int j;
                    for(j=closest_n - 1; j >= 0; j--)
                    {
                        if (dsq < dsq_max[j])
                        {
                            // shift everything one place up
                            if (j < closest_n - 1)
                            {
                                dsq_max[j+1] = dsq_max[j];
                                closest[j+1] = closest[j];
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    // we always overshoot by 1
                    j++;
                    dsq_max[j] = dsq;
                    closest[j] = &(*i);
                }
            }
            for(int i=0;i<closest_n;i++)
            {
                /*printf("closest[%d], dsq=%g, p=%p\n", i, sqrt(dsq_max[i]),
                       closest[i]);
                fflush(stdout);*/
                // add the anchors
                if (spare_anchor_list.empty())
                {
                    for(int i=0;i<1000;i++)
                    {
                        spare_anchor_list.push_back(anchor());
                    }
                }

                rvec lcom;
                closest[i]->get_com(lcom);
                std::list<anchor>::iterator newelem=spare_anchor_list.begin();
                newelem->reinit(closest[i], 1., lcom);
                anchors.splice(anchors.begin(), spare_anchor_list, newelem);
                com_weight += 1.;
                anchor_d += sqrt(dsq_max[i]);
            }
            anchor_d /= com_weight;
        }
        else
        {
            for(deque<mol>::const_iterator i=ref_mols.begin(); 
                i!=ref_mols.end(); ++i)
            {
                rvec dxvec;
                rvec lcom;
                i->get_com(lcom);

                // calculate distance vector
                pbc_dx(pbc, r, lcom, dxvec); 
                // and calculate distance to base weights on
                real dsq;
                switch(evdir)
                {
                    case evdir_xyz:
                    default:
                        dsq = (dxvec[XX]*dxvec[XX] + dxvec[YY]*dxvec[YY] + 
                               dxvec[ZZ]*dxvec[ZZ]);
                        break;
                    case evdir_xy:
                        dsq = dxvec[XX]*dxvec[XX] + dxvec[YY]*dxvec[YY];
                        break;
                    case evdir_z:
                        dsq = dxvec[ZZ]*dxvec[ZZ];
                        break;
                }

                real weight=weightfn( dsq );

                if (weight > 0.01)
                {
                    if (spare_anchor_list.empty())
                    {
                        for(int i=0;i<1000;i++)
                        {
                            spare_anchor_list.push_back(anchor());
                        }
                    }
                    // add the anchors
                    std::list<anchor>::iterator newelem=spare_anchor_list.begin();
                    newelem->reinit(&(*i), weight, lcom);
                    anchors.splice(anchors.begin(), spare_anchor_list, newelem);
                    //anchors.push_back(anchor(&(*i), weight, lcom));
                    com_weight += weight;
                    anchor_d += sqrt(dsq) * weight;
                }
            }
            anchor_d /= com_weight;
        }
        if (com_weight == 0.)
        {
            /*printf("ERRRORRREEEERROOORRR no weight\n");*/
            printf("WARNING no weight. Using total  COM as ref point\n");
            com_weight=1.;
        }
    }
    else
    {
        com_weight=1.;
    }

    { // calculate position relative to reference pos.
        rvec dxvec;

        pbc_dx(pbc, r, com_ref_tot, dxvec); 
        // now do reference transformation
        mvmul(ref_trans, dxvec, refp);

        //z_val_start=dxvec[ZZ];
        real_start_pos[XX] = r[XX];
        real_start_pos[YY] = r[YY];
        real_start_pos[ZZ] = r[ZZ];
    }

    // calculate r_val
    if (calc_r_)
    {
        r_val=0.;
#if 0
        r_val=FLT_MAX;
        bool found0=false;
        for(list<mol>::iterator i=meas_mols.begin(); i!=meas_mols.end(); ++i)
        {
            // calcualte the closest distance > 0
            rvec dxvec;
            rvec lcom;
            i->get_com(lcom);
            if (lcom[XX] != r[XX] || lcom[YY]!=r[YY] || lcom[ZZ]!=r[ZZ] )
            {

                // calculate distance vector
                pbc_dx(pbc, r, lcom, dxvec); 
                // and calculate distance to base weights on
                real dsq;
                switch(evdir)
                {
                    case evdir_xyz:
                    default:
                        dsq = (dxvec[XX]*dxvec[XX] + dxvec[YY]*dxvec[YY] + 
                               dxvec[ZZ]*dxvec[ZZ]);
                        break;
                    case evdir_xy:
                        dsq = dxvec[XX]*dxvec[XX] + dxvec[YY]*dxvec[YY];
                        break;
                    case evdir_z:
                        dsq = dxvec[ZZ]*dxvec[ZZ];
                        break;
                }
                if (dsq > 0 && dsq < r_val)
                {
#ifdef GMX_DOUBLE
                    r_val = sqrt(dsq);
#else
                    r_val = sqrtf(dsq);
#endif
                }
            }
            else
                found0=true;
        }
        //printf("r_val = %g\n", r_val);
        if (!found0)
        {
            printf("0 not found!\n");
            exit(1);
        }
        if (r_val > 1e5)
        {
            printf("r_val=%g!\n",r_val);
            exit(1);
        }
#endif
    }
    else
    {
        r_val=0.;
    }

    com_dx[XX] = com_dx[YY] = com_dx[ZZ] = 0;
    dx[XX] = dx[YY] = dx[ZZ] = 0;
#if 0
    printf(" r=(%g,%g,%g)\n", r[XX], r[YY], r[ZZ]);
#endif
}
Ejemplo n.º 24
0
void VDChunkedBuffer::FreeChunk() {
	mFreeChunks.splice(mFreeChunks.begin(), mActiveChunks, mActiveChunks.begin());
}
Ejemplo n.º 25
0
bool Ui0::get_characters( std::list<character> & characters ){
    characters.splice( characters.end(), _chars );
    return true;
}
Ejemplo n.º 26
0
void
node_t::calculate_lookahead_waiting_pool_for_pure_BNF_rule(
  std::list<todo_nodes_t> &todo_nodes_set_2) const
{
  assert(m_next_nodes.size() > 1);
  assert(true == m_is_rule_head);
  
  std::list<todo_nodes_t> todo_nodes_set;
  
  make_todo_node_set_from_nodes(m_next_nodes, todo_nodes_set);
  
  assert(mp_ae != 0);
  
  if (true == mp_ae->enable_left_factor())
  {
    // find the first different nodes for each alternative
    // pair. This process can be though of left factoring.
    // 
    // << NOTE >>
    // However, factorization is sometimes inhibited by the fact
    // that the semantic processing of conflicting
    // alternatives differs.
    while (todo_nodes_set.size() != 0)
    {
      todo_nodes_t &todo_nodes = todo_nodes_set.front();
      
      if (0 == todo_nodes.mp_node_a->name().compare(
            todo_nodes.mp_node_b->name()))
      {
        // Two nodes with same name.
        // I will find lookahead terminals for the children of these 2 nodes.
      
        // 'mp_node_a' & 'mp_node_b' can be the rule end node at the same time,
        // because this means that these 2 alternatives are equal
        // (i.e. duplicated).
        assert(1 == todo_nodes.mp_node_a->next_nodes().size());
        assert(1 == todo_nodes.mp_node_b->next_nodes().size());
        assert(todo_nodes.mp_node_a->rule_node() == todo_nodes.mp_node_b->rule_node());
          
#if defined(_DEBUG)
        // these 2 nodes can not be equal to the rule end node, because if so,
        // this means these 2 alternatives are the same.
        // (i.e. duplicated alternatives).
        // I should remove the duplicated alternatives at eraly stage.
        if (todo_nodes.mp_node_a->next_nodes().front() ==
            todo_nodes.mp_node_a->rule_node()->rule_end_node())
        {
          assert(todo_nodes.mp_node_b->next_nodes().front() !=
                 todo_nodes.mp_node_b->rule_node()->rule_end_node());
        }
        if (todo_nodes.mp_node_b->next_nodes().front() ==
            todo_nodes.mp_node_b->rule_node()->rule_end_node())
        {
          assert(todo_nodes.mp_node_a->next_nodes().front() !=
                 todo_nodes.mp_node_a->rule_node()->rule_end_node());
        }
#endif
          
        todo_nodes_set.push_back(
          todo_nodes_t(
            todo_nodes.mp_node_a->next_nodes().front(),
            todo_nodes.mp_node_b->next_nodes().front()));
      }
      else
      {
        todo_nodes_set_2.push_back(todo_nodes);
      }
    
      todo_nodes_set.pop_front();
    }
  }
  else
  {
    todo_nodes_set_2.splice(todo_nodes_set_2.end(), todo_nodes_set);
  }
  
  assert(0 == todo_nodes_set.size());
}