Beispiel #1
0
VoteProcessorUsingHash::CandidateList VoteProcessorUsingHash::findMaxCandidates(const HashTable& counts) {
	CandidateList maxCandidates;
	int maxCount = 0;

	for (auto& bucket : counts) {
		for (auto& slot : bucket) {
			std::string name = slot.first;
			int count = slot.second;

			if (count < maxCount) {
				continue;
			}

			if (count > maxCount) {
				maxCount = count;
				maxCandidates.clear();
			}

			maxCandidates.push_back(name);
		}
	}

	std::sort(maxCandidates.begin(), maxCandidates.end());
	return maxCandidates;
}
 void invalidateCandidate(int x, int y, int num, bool initList) {
   CandidateList* list = initCandidates[x][y];
   if (!initList) {
     list = currentCandidates[x][y];
   }
   
   list->invalidateCandidate(num);
 }
 //the conflicts count of x, y, number i's conflicts gets incremented by delta
 // deprecated
 void changeConflicts(int x, int y, int i, int delta, bool initialList) {
   CandidateList* list;
   if (initialList) {
     list = initCandidates[x][y];
   }
   else {
     list = currentCandidates[x][y];
   }
   list->changeConflict(i, delta);
 }
Beispiel #4
0
void BlockMatcher::FindBestMatchSubp( const int xpos, const int ypos,
                                      const CandidateList& cand_list,
                                      const MVector& mv_prediction,
                                      const float lambda)
{

    BlockDiffParams dparams;
    dparams.SetBlockLimits( m_bparams , m_pic_data , xpos , ypos);    

    //now test against the offsets in the MV list to get the lowest cost//
    //////////////////////////////////////////////////////////////////////    

    // Numbers of the lists to do more searching in
    vector<int> list_nums; 

    // Costs of the initial vectors in each list
    OneDArray<float> list_costs( cand_list.size() );

    // First test the first in each of the lists to choose which lists to pursue
    MvCostData best_costs( m_cost_array[ypos][xpos] );
    best_costs.total = 100000000.0f;
    MVector best_mv( m_mv_array[ypos][xpos] );

    MvCostData cand_costs;
    MVector cand_mv;

    for (size_t list_num=0 ; list_num<cand_list.size() ; ++list_num )
    {
        for (size_t i=0 ; i<cand_list[list_num].size() ; ++i )
        {
            cand_mv = cand_list[list_num][i];
            cand_costs.mvcost = GetVarUp( mv_prediction , cand_mv );

            m_subpeldiff[m_precision-1]->Diff( dparams,
                                               cand_mv ,
                                               cand_costs.mvcost,
                                               lambda,
                                               best_costs ,
                                               best_mv);
        }// 
    }// list_num


    // Write the results in the arrays //
    /////////////////////////////////////

     m_mv_array[ypos][xpos] = best_mv;
     m_cost_array[ypos][xpos] = best_costs;   

}
Beispiel #5
0
void CandidateList<Integer>::merge_by_val_inner(CandidateList<Integer>& NewCand, bool collect_new_elements, 
                      list<Candidate<Integer>* >& New_Elements){

    CandidateList<Integer> Coll;
    Coll.dual=dual;
    Coll.last_hyp=last_hyp;

    while(!empty() || !NewCand.empty()){
    
        if(NewCand.empty()){
            Coll.Candidates.splice(Coll.Candidates.begin(),Candidates);
            break;        
        }
        
        if(empty()){
            typename list<Candidate<Integer> >::reverse_iterator h;
            if(collect_new_elements){
                for(h=NewCand.Candidates.rbegin();h!=NewCand.Candidates.rend();++h)
                    New_Elements.push_front(&(*h));
            }
            Coll.Candidates.splice(Coll.Candidates.begin(),NewCand.Candidates);
            break;       
        }
        
        if(NewCand.Candidates.back().values==Candidates.back().values){  // if equal, new is erased
            if(NewCand.Candidates.back().mother<Candidates.back().mother)
                Candidates.back().mother=NewCand.Candidates.back().mother;
            NewCand.Candidates.pop_back();
            continue;
        }
        
        if(val_compare<Integer>(Candidates.back(),NewCand.Candidates.back())){ // old is smaller, new must be inserteed
            if(collect_new_elements){
                New_Elements.push_front(&(NewCand.Candidates.back()));
            }
            Coll.Candidates.splice(Coll.Candidates.begin(),NewCand.Candidates,--NewCand.Candidates.end());
            continue;
        }
          
        Coll.Candidates.splice(Coll.Candidates.begin(), Candidates,--Candidates.end()); // the remaining case              
    
    }

    splice(Coll);  // Coll moved to this
}
std::string
gams::elections::ElectionCumulative::get_leader(void)
{
  madara_logger_ptr_log(gams::loggers::global_logger.get(),
    gams::loggers::LOG_MAJOR,
    "gams::elections::ElectionCumulative:get_leader" \
    " getting leader from %s\n", election_prefix_.c_str());

  std::string leader;
  CandidateList leaders = get_leaders();

  if (leaders.size() > 0)
  {
    leader = leaders[0];
  }

  return leader;
}
Beispiel #7
0
void AddNewVlistD( CandidateList& vect_list , const MVector& mv , const int xr , const int yr )
{
      //As above, but using a diamond pattern

    vector<MVector> tmp_list;
    vect_list.push_back( tmp_list );

    int list_num=vect_list.size()-1;    
    int xlim;

    MVector tmp_mv( mv );
    AddVect( vect_list , tmp_mv , list_num );

    for ( int i=1 ; i<=xr ; ++i)
    {
        tmp_mv.x = mv.x + i;
        AddVect( vect_list , tmp_mv , list_num );

        tmp_mv.x = mv.x - i;        
        AddVect( vect_list , tmp_mv , list_num );    
    }

    for ( int j=1 ; j<=yr ; ++j)
    {
        xlim = xr * (yr-std::abs(j)) / yr;        
        for ( int i=-xlim ; i<=xlim ; ++i)
        {
            tmp_mv.x = mv.x + i;
            tmp_mv.y = mv.y + j;
            AddVect( vect_list , tmp_mv , list_num );

            tmp_mv.y = mv.y - j;
            AddVect( vect_list , tmp_mv , list_num );            
        }        
    }

    // If we've not managed to add any element to the list
    // remove the list so we don't ever have to check its size
    if ( vect_list[list_num].size() == 0 )                
        vect_list.erase( vect_list.begin() + list_num );
}
Beispiel #8
0
void AddNewVlist( CandidateList& vect_list, const MVector& mv, 
                  const int xr , const int yr , const int step )
{
      //Creates a new motion vector list in a square region around mv

    vector<MVector> tmp_list;
    vect_list.push_back(tmp_list);
    int list_num=vect_list.size()-1;    

    MVector tmp_mv( mv );
    AddVect(vect_list , tmp_mv , list_num );

    for ( int i=1 ; i<=xr ; ++i )
    {
        tmp_mv.x = mv.x + i*step;
        AddVect( vect_list , tmp_mv , list_num );

        tmp_mv.x = mv.x - i*step;        
        AddVect( vect_list , tmp_mv , list_num );    
    }

    for ( int j=1 ; j<=yr ; ++j)
    {
        for ( int i=-xr ; i<=xr ; ++i)
        {
            tmp_mv.x = mv.x + i*step;
            tmp_mv.y = mv.y + j*step;
            AddVect(vect_list,tmp_mv,list_num);

            tmp_mv.y = mv.y -j*step;
            AddVect(vect_list,tmp_mv,list_num);            

        }// i        
    }// j

    // If we've not managed to add any element to the list
    // remove the list so we don't ever have to check its size
    if ( vect_list[list_num].size() == 0 )
        vect_list.erase( vect_list.begin() + list_num );
}
gams::elections::CandidateList
gams::elections::ElectionCumulative::get_leaders(int num_leaders)
{
  madara_logger_ptr_log(gams::loggers::global_logger.get(),
    gams::loggers::LOG_MAJOR,
    "gams::elections::ElectionCumulative:get_leaders" \
    " getting leaders from %s\n", election_prefix_.c_str());

  CandidateList leaders;

  if (knowledge_)
  {
    knowledge::ContextGuard guard(*knowledge_);

    typedef std::map <KnowledgeRecord::Integer, CandidateList> Leaderboard;

    CandidateVotes candidates;
    Leaderboard leaderboard;

    get_votes(candidates);

    // construct the leaderboard
    for (CandidateVotes::iterator i = candidates.begin();
      i != candidates.end(); ++i)
    {
      leaderboard[i->second].push_back(i->first);
    }

    // leaderboard is in ascending order, so grab from the back
    for (Leaderboard::reverse_iterator i = leaderboard.rbegin();
      i != leaderboard.rend() &&(int) leaders.size() < num_leaders; ++i)
    {
      // if it is a tie, we could provide more than num_leaders
      leaders.insert(leaders.end(), i->second.begin(), i->second.end());
    }
  }

  return leaders;
}
Beispiel #10
0
void BlockMatcher::FindBestMatchPel(const int xpos , const int ypos ,
                                    const CandidateList& cand_list,
                                    const MVector& mv_prediction,
                                    const int list_start)
{
    BlockDiffParams dparams;
    dparams.SetBlockLimits( m_bparams , m_pic_data , xpos , ypos);
    
    //now test against the offsets in the MV list to get the lowest cost//
    //////////////////////////////////////////////////////////////////////     

    // First test the first in each of the lists to choose which lists to pursue

   
    float best_cost = m_cost_array[ypos][xpos].total;

    MVector best_mv = m_mv_array[ypos][xpos];

    for ( size_t lnum=list_start ; lnum<cand_list.size() ; ++lnum)
    {
        for (size_t i=0 ; i<cand_list[lnum].size() ; ++i)
        {
            m_peldiff.Diff( dparams , 
                            cand_list[lnum][i] , 
                            best_cost , 
                            best_mv);
        }// i
    }// num

    // Write the results in the arrays //
    /////////////////////////////////////

    m_mv_array[ypos][xpos] = best_mv;
    m_cost_array[ypos][xpos].SAD = best_cost;
    m_cost_array[ypos][xpos].mvcost = GetVar( mv_prediction , best_mv);
    m_cost_array[ypos][xpos].SetTotal( 0.0 );
}
Beispiel #11
0
void AddVect(CandidateList& vect_list,const MVector& mv,int list_num)
{

    bool is_in_list=false;
    
    size_t lnum=0;
    size_t i;    

    while( !is_in_list && lnum<vect_list.size() )
    {
        i=0;        
        while( !is_in_list && i<vect_list[lnum].size())
        {        
            if ( vect_list[lnum][i].x == mv.x && vect_list[lnum][i].y == mv.y )    
                is_in_list=true;        
            ++i;    
        }
        ++lnum;
    }

    if ( !is_in_list )
        vect_list[list_num].push_back(mv);
    
}
Beispiel #12
0
void processChoice(CandidateList& candidateList)
{
	int choice;
	cout << "\nEnter your choice: ";
	cin >> choice;

	while (choice > 0 && choice < 6)
	{
		string fName, lName;
		int division = 0,
			ssn = 0;

		switch(choice)
		{
			// Print all candidates
		case 1:
			cout << endl;
			candidateList.printAllCandidates();
            system("Pause");
			break;

			// Print a candidates's division votes
		case 2:
			cout << "\nEnter candidate's social security number (no dashes): ";
			cin >> ssn;
			cout << endl;
			candidateList.printCandidateName(ssn);
			cout << endl;
			for (int i = 0; i < NUM_OF_DIVISIONS; ++i)
				candidateList.printCandidateDivisionVotes(ssn,i);
			cout << endl;
			system("Pause");
			break;

			// Print a candidate's total votes
		case 3:
			cout << "\nEnter candidate's social security number (no dashes): ";
			cin >> ssn;
			cout << endl;
			candidateList.printCandidateName(ssn);
			cout << endl;
			candidateList.printCandidateTotalVotes(ssn);
			cout << endl;
            system("Pause");
			break;

			// Print winner
		case 4:
			ssn = candidateList.getWinner();
			if (ssn != 0)
			{
				cout << "\nElection winner: ";
				candidateList.printCandidateName(ssn);
				cout << endl;
				candidateList.printCandidateTotalVotes(ssn);
				cout << endl;
			}
			else
			{
				cout << "\nThere are no candidates." << endl;
			}
			cout << endl;
            system("Pause");
			break;
        case 5:
            candidateList.printFinalResult();
            cout << endl;
            system("Pause");
            break;

		default:
			cout << "Sorry. That is not a selection." << endl;
		}

		displayMenu();
		cout << "\nEnter your choice: ";
		cin >> choice;
	}
}
Beispiel #13
0
bool CandidateList<Integer>::reduce_by_and_insert(Candidate<Integer>& cand, const CandidateList<Integer>& Reducers){
    bool irred=!Reducers.is_reducible(cand);
    if(irred)
        Candidates.push_back(cand);
    return irred;
}
 int nextCandidate(int x, int y) {
   CandidateList* list = currentCandidates[x][y];
   return list->nextCandidate();
 }