コード例 #1
0
ファイル: kmeans.cpp プロジェクト: annoviko/pyclustering
void kmeans::update_clusters(const dataset & p_centers, cluster_sequence & p_clusters) {
    const dataset & data = *m_ptr_data;

    p_clusters.clear();
    p_clusters.resize(p_centers.size());

    /* fill clusters again in line with centers. */
    if (m_ptr_indexes->empty()) {
        std::vector<std::size_t> winners(data.size(), 0);
        parallel_for(std::size_t(0), data.size(), [this, &p_centers, &winners](std::size_t p_index) {
            assign_point_to_cluster(p_index, p_centers, winners);
        });

        for (std::size_t index_point = 0; index_point < winners.size(); index_point++) {
            const std::size_t suitable_index_cluster = winners[index_point];
            p_clusters[suitable_index_cluster].push_back(index_point);
        }
    }
    else {
        /* This part of code is used by X-Means and in case of parallel implementation of this part in scope of X-Means
           performance is slightly reduced. Experiments has been performed our implementation and Intel TBB library. 
           But in K-Means case only - it works perfectly and increase performance. */
        std::vector<std::size_t> winners(data.size(), 0);
        parallel_for_each(*m_ptr_indexes, [this, &p_centers, &winners](std::size_t p_index) {
            assign_point_to_cluster(p_index, p_centers, winners);
        });

        for (std::size_t index_point : *m_ptr_indexes) {
            const std::size_t suitable_index_cluster = winners[index_point];
            p_clusters[suitable_index_cluster].push_back(index_point);
        }
    }

    erase_empty_clusters(p_clusters);
}
コード例 #2
0
ファイル: quackletest.cpp プロジェクト: gokceneraslan/quackle
void testAdvanceToEnd(Quackle::Game &game)
{
	UVcout << "now advancing to end..." << endl;

	game.advanceToNoncomputerPlayer();

	UVcout << game.currentPosition();

	Quackle::PlayerList winners(game.currentPosition().leadingPlayers());
	for (Quackle::PlayerList::const_iterator it = winners.begin(); it != winners.end(); ++it)
		UVcout << *it << " wins!!" << endl;
}
コード例 #3
0
/** Creates 2 groups: one from winners and one from loosers
 */
QList< Group* > SwissGroup::split( ) const
{
  if ( _matches.count() < 2 ) { // nothing to split
    return QList< Group* >();
  }

  QList< Group* > ret;
  PlayerList w = winners(), l = loosers();

  // number of winnders and loosers can be non-even, when group consists,
  // for example, from 6 persons. We need to add 'bye' players 
  if ( w.count() & 1 ) w << byePlayer;
  if ( l.count() & 1 ) l << byePlayer;

  qDebug() << "Winners:";
  for ( int i = 0; i < w.count(); i ++ ) {
    qDebug() << w.at( i ).name();
  }

  qDebug() << "Loosers:";
  for ( int i = 0; i < l.count(); i ++ ) {
    qDebug() << l.at( i ).name();
  }

  // winners group
  if ( !isPlayerListByed( w ) ) {
    ret << new SwissGroup( _fromPlace, _stage + 1, w ); 
  }

  // loosers group
  if ( !isPlayerListByed( l ) ) {
    ret << new SwissGroup( _fromPlace + _players.count() / 2, 
                           _stage + 1, l );
  }

  foreach( Group *g, ret ) {
    const TournAlgo *a = _tournData->algo();
    Q_CHECK_PTR( a );
 
    g->setTournData( _tournData );
    g->setQualif( isQualif() );
    dynamic_cast<SwissGroup*>(g)->permuteMatches( a->breakAlgo() );

    // if there is at least one bye player, we should notify that
    // at least one game is fakely played.
    if ( g->const_players().contains( byePlayer ) ) {
      _tournData->groupChanged( g );
    }
  }
 
  return ret; 
}