Exemplo n.º 1
0
//*********************************************************
bool Turn(QueueType & pQueue, VecSetType & squadSetVec, MapSquadType & squadMap, ArsenalType & arsenal){
  bool over= false;
  Player * p;
  p= pQueue.front();
  pQueue.pop();
  

  p->ResetMomentum();
    
  if( p->IsHuman())
  {
    HumanTurn(squadMap, arsenal, p);
  }
  else
  {
    BugTurn(squadMap, arsenal, p); 
  }
    
  pQueue.push(p);  
  
  DeletePlayers(pQueue, squadSetVec, squadMap);
  over= CheckOver(squadSetVec);
  
  
  return over;
}
        void PrioritizedSweeping<M>::stepUpdateQ(size_t s, size_t a) {
            auto & values = std::get<VALUES>(vfun_);
            { // Update q[s][a]
                double newQValue = 0;
                for ( size_t s1 = 0; s1 < S; ++s1 ) {
                    double probability = model_.getTransitionProbability(s,a,s1);
                    if ( checkDifferentSmall( probability, 0.0 ) )
                        newQValue += probability * ( model_.getExpectedReward(s,a,s1) + model_.getDiscount() * values[s1] );
                }
                qfun_(s, a) = newQValue;
            }

            double p = values[s];
            {
                // Update value and action
                values[s] = qfun_.row(s).maxCoeff(&std::get<ACTIONS>(vfun_)[s]);
            }

            p = std::fabs(values[s] - p);

            // If it changed enough, we're going to update its parents.
            if ( p > theta_ ) {
                auto it = queueHandles_.find(s);

                if ( it != std::end(queueHandles_) && std::get<PRIORITY>(*(it->second)) < p )
                    queue_.increase(it->second, std::make_tuple(p, s));
                else
                    queueHandles_[s] = queue_.push(std::make_tuple(p, s));
            }
        }
Exemplo n.º 3
0
//*********************************************************
void End(QueueType & pQueue, ArsenalType & arsenal, MapSquadType & squadMap, VecSetType & squadSetVec){
  GameOver(pQueue, squadSetVec, squadMap, arsenal);
  int qSize= pQueue.size();
  Player * p;
  for (int i= 0; i < qSize; i++)
  {
    p= pQueue.front(); 
    pQueue.pop();
    delete p;
  }
  return;
}
Exemplo n.º 4
0
unsigned UnwrappedLineFormatter::analyzeSolutionSpace(LineState &InitialState,
                                                      bool DryRun) {
  std::set<LineState *, CompareLineStatePointers> Seen;

  // Increasing count of \c StateNode items we have created. This is used to
  // create a deterministic order independent of the container.
  unsigned Count = 0;
  QueueType Queue;

  // Insert start element into queue.
  StateNode *Node =
      new (Allocator.Allocate()) StateNode(InitialState, false, nullptr);
  Queue.push(QueueItem(OrderedPenalty(0, Count), Node));
  ++Count;

  unsigned Penalty = 0;

  // While not empty, take first element and follow edges.
  while (!Queue.empty()) {
    Penalty = Queue.top().first.first;
    StateNode *Node = Queue.top().second;
    if (!Node->State.NextToken) {
      DEBUG(llvm::dbgs() << "\n---\nPenalty for line: " << Penalty << "\n");
      break;
    }
    Queue.pop();

    // Cut off the analysis of certain solutions if the analysis gets too
    // complex. See description of IgnoreStackForComparison.
    if (Count > 10000)
      Node->State.IgnoreStackForComparison = true;

    if (!Seen.insert(&Node->State).second)
      // State already examined with lower penalty.
      continue;

    FormatDecision LastFormat = Node->State.NextToken->Decision;
    if (LastFormat == FD_Unformatted || LastFormat == FD_Continue)
      addNextStateToQueue(Penalty, Node, /*NewLine=*/false, &Count, &Queue);
    if (LastFormat == FD_Unformatted || LastFormat == FD_Break)
      addNextStateToQueue(Penalty, Node, /*NewLine=*/true, &Count, &Queue);
  }

  if (Queue.empty()) {
    // We were unable to find a solution, do nothing.
    // FIXME: Add diagnostic?
    DEBUG(llvm::dbgs() << "Could not find a solution.\n");
    return 0;
  }

  // Reconstruct the solution.
  if (!DryRun)
    reconstructPath(InitialState, Queue.top().second);

  DEBUG(llvm::dbgs() << "Total number of analyzed states: " << Count << "\n");
  DEBUG(llvm::dbgs() << "---\n");

  return Penalty;
}
        void PrioritizedSweeping<M>::batchUpdateQ() {
            for ( unsigned i = 0; i < N; ++i ) {
                if ( queue_.empty() ) return;

                // The state we extract has been processed already
                // So it is the future we have to backtrack from.
                size_t s1;
                std::tie(std::ignore, s1) = queue_.top();

                queue_.pop();
                queueHandles_.erase(s1);

                for ( size_t s = 0; s < S; ++s )
                    for ( size_t a = 0; a < A; ++a )
                        if ( checkDifferentSmall(model_.getTransitionProbability(s,a,s1), 0.0) )
                            stepUpdateQ(s, a);
            }
        }
Exemplo n.º 6
0
 void data_sample( const T& sample )
 {
     minit = sample;
     // read each item from the queue
     // and re-init it with sample
     for( unsigned int i = 0; i < mpool.capacity(); ++i ) {
         mpit[i].content = minit;
     }
 }
Exemplo n.º 7
0
 /**
  * Decrease the reference count of a piece of memory \a m,
  * which becomes available for allocation.
  */
 bool deallocate( pointer m )
 {
     Item* it = reinterpret_cast<Item*>(m);
     if ( oro_atomic_read(&it->rc) == 0 )
         return false;
     if( oro_atomic_dec_and_test( &(it->rc) ) )
         if ( mpool.enqueue( static_cast<void*>(m) ) == false )
             assert(false && "Deallocating more elements than allocated !");
     return true;
 }
Exemplo n.º 8
0
 /**
  * Acquire a pointer to memory of type \a T.
  */
 pointer allocate()
 {
     void* result;
     // iterate over the whole pool and try to get a free slot.
     if ( mpool.dequeue( result ) ) {
         Item* it = static_cast<Item*>(result);
         oro_atomic_inc( &(it->rc) );
         return (&it->content);
     }
     return 0;
 }
Exemplo n.º 9
0
//*********************************************************
void LoadQueue(QueueType & pQueue, vector<Player *> bugs, vector<Player *> squad){
  vector<Player *> all;
  all= SortAll(bugs, squad);
  int len= all.size();
  
  for (int i= 0; i < len; i++)
  {
    pQueue.push(all[i]);
  }
  
  all.clear();
  return;
}
Exemplo n.º 10
0
//*********************************************************
bool DeletePlayers(QueueType & pQueue, VecSetType & squadSetVec, MapSquadType & squadMap){
  Player * p;
  int qSize= pQueue.size();
  bool del= false;
  for (int i= 0; i < qSize; i++)
  {
    p= pQueue.front();
    pQueue.pop();
    
    if (p->IsDead())
    {
      if (squadSetVec[squadMap[p->Name()]].count(p->Name()))
      {
	squadSetVec[squadMap[p->Name()]].erase(p->Name());
	del= true;
      }
      //PrintVectorOfSquads(cout , squadSetVec); 
    }
 
    pQueue.push(p);
  }
  
  return del;
}
Exemplo n.º 11
0
void spsc_queue_avail_test_run(QueueType & q)
{
    BOOST_REQUIRE_EQUAL( q.write_available(), 16 );
    BOOST_REQUIRE_EQUAL( q.read_available(),   0 );

    for (size_t i = 0; i != 8; ++i) {
        BOOST_REQUIRE_EQUAL( q.write_available(), 16 - i );
        BOOST_REQUIRE_EQUAL( q.read_available(),       i );

        q.push( 1 );
    }

    // empty queue
    int dummy;
    while (q.pop(dummy))
    {}

    for (size_t i = 0; i != 16; ++i) {
        BOOST_REQUIRE_EQUAL( q.write_available(), 16 - i );
        BOOST_REQUIRE_EQUAL( q.read_available(),       i );

        q.push( 1 );
    }
}
Exemplo n.º 12
0
 size_t PrioritizedSweeping<M>::getQueueLength() const {
     return queue_.size();
 }
Exemplo n.º 13
0
 /**
  * Returns the maximum number of elements.
  */
 size_type capacity() const {
     return mpool.capacity();
 }
Exemplo n.º 14
0
 /**
  * Returns the number of elements currently available.
  */
 size_type size() const {
     return mpool.size();
 }