gochatai/pachi_py/pachi/uct/slave.c
/* Select from stats_queue at most shared_nodes candidates with
 * biggest increments. Return a binary array sorted by coord path. */
Select from stats_queue at most shared_nodes candidates with
biggest increments. Return a binary array sorted by coord path.
Select from stats_queue at most shared_nodes candidates with biggest increments . Return a binary array sorted by coord path .
static struct incr_stats *
select_best_stats(struct stats_candidate *stats_queue, int stats_count,
		  int shared_nodes, int *byte_size)
{
	static struct incr_stats *out_stats = NULL;
	if (!out_stats)
		out_stats = malloc2(shared_nodes * sizeof(*out_stats));
	int out_count = 0;
	int min_incr = MAX_BUCKETS;
	do {
		out_count += bucket_count[--min_incr];
	} while (min_incr > 1 && out_count < shared_nodes);
	int min_count = bucket_count[min_incr] - (out_count - shared_nodes);
	struct incr_stats *os = out_stats;
	out_count = 0;
	for (int count = 0; count < stats_count; count++) {
		int delta = stats_queue[count].playout_incr - min_incr;
		if (delta < 0 || (delta == 0 && --min_count < 0)) continue;
		struct tree_node *node = stats_queue[count].node;
		os->incr = node->u;
		stats_rm_result(&os->incr, node->pu.value, node->pu.playouts);
		if (os->incr.playouts > 0) {
			node->pu = node->u;
			os->coord_path = stats_queue[count].coord_path;
			assert(os->coord_path > 0);
			os++;
			out_count++;
		}
		assert (out_count <= shared_nodes);
	}
	*byte_size = (char *)os - (char *)out_stats;
	qsort(out_stats, out_count, sizeof(*os), coord_cmp);
	return out_stats;
}
static struct incr_stats * select_best_stats ( struct stats_candidate * stats_queue , int stats_count , int shared_nodes , int * byte_size ) { static struct incr_stats * out_stats = NULL ; if ( ! out_stats ) out_stats = malloc2 ( shared_nodes * sizeof ( * out_stats ) ) ; int out_count = 0 ; int min_incr = MAX_BUCKETS ; do { out_count += bucket_count [ -- min_incr ] ; } while ( min_incr > 1 && out_count < shared_nodes ) ; int min_count = bucket_count [ min_incr ] - ( out_count - shared_nodes ) ; struct incr_stats * os = out_stats ; out_count = 0 ; for ( int count = 0 ; count < stats_count ; count ++ ) { int delta = stats_queue [ count ] . playout_incr - min_incr ; if ( delta < 0 || ( delta == 0 && -- min_count < 0 ) ) continue ; struct tree_node * node = stats_queue [ count ] . node ; os -> incr = node -> u ; stats_rm_result ( & os -> incr , node -> pu . value , node -> pu . playouts ) ; if ( os -> incr . playouts > 0 ) { node -> pu = node -> u ; os -> coord_path = stats_queue [ count ] . coord_path ; assert ( os -> coord_path > 0 ) ; os ++ ; out_count ++ ; } assert ( out_count <= shared_nodes ) ; } * byte_size = ( char * ) os - ( char * ) out_stats ; qsort ( out_stats , out_count , sizeof ( * os ) , coord_cmp ) ; return out_stats ; }
Select from stats_queue at most shared_nodes candidates with
 biggest increments.
Select from stats_queue at most shared_nodes candidates with biggest increments .
/* Find the minimum increment to send. The bucket with minimum
         * increment may be sent only partially. */ /* Send all all increments > min_incr plus whatever we can at min_incr. */ /* With virtual loss os->incr.playouts might be <= 0; we only
		 * send positive increments to other slaves so a virtual loss
		 * can be propagated to other machines (good). The undo of the
		 * virtual loss will be propagated later when node->u gets
		 * above node->pu. */ /* Sort the increments by increasing coord path (required by master).
	 * Can be done in linear time with radix sort if qsort is too slow. */