📄 computecounts.cc
字号:
// ################################################################################
//
// name: computeCounts.cc
//
// author: Martin Pelikan
//
// purpose: functions for computing counts for all instances of a particular
// list of string positions or a list of positions created by adding
// a position from the array of positions to a particular list of
// remaining positions repeatedly
//
// last modified: February 1999
//
// ################################################################################
#include "computeCounts.h"
#include "population.h"
#include "binary.h"
// ================================================================================
//
// name: computeCounts
//
// function: compute the counts in a set of binary strings for all instances
// of an array of string positions
//
// parameters: pos..........an array of string positions to compute the counts
// of their instances for
// n............the number of the positions in the above set
// population...the set of strings where to compute the counts in
// count........the resulting array of counts ordered according to
// the ordering of instances (from 0...0 to 1...1)
//
// returns: (int) 0
//
// ================================================================================
int computeCounts(int *pos,
int n,
Population *population,
long *count)
{
long i,N;
long numConfigurations;
long configuration;
char *x;
// initialize the variables
N = population->N;
numConfigurations = (long) 1<<n;
// set counts to 0
for (i=0; i<numConfigurations; i++)
count[i]=0;
// go through all strings and do the job
for (i=0; i<N; i++)
{
x = population->x[i];
configuration = indexedBinaryToInt(x,pos,n);
count[configuration]++;
};
// get back
return 0;
};
// ================================================================================
//
// name: computeCountsForList
//
// function: compute the counts in a set of binary strings for all instances
// of an array of string positions combined with an additional
// position and each of the positions from an additional array of
// positions; the function is so special for the sake of efficiency
//
// parameters: node.........a special position to add to the set of positions
// list.........the list of positions to add to the set of positions
// numList......the length of the above list of positions
// pos..........the set of positions (to this set the special node
// with each of the above list of positions will be
// added)
// n............the number of the positions in the above set
// population...the set of strings where to compute the counts in
// count........the resulting array of arrays of counts ordered
// according to which item from the list of positions
// is added and within each of these arrays according
// to the instance (from 0...0 to 1...1)
//
// returns: (int) 0
//
// ================================================================================
int computeCountsForList(int node,
int *list,
int numList,
int *pos,
int n,
Population *population,
long **count)
{
register long i;
long N;
long numConfigurations;
long numConfigurations4;
long configuration;
char *x;
int l;
// initialize the variables
N = population->N;
numConfigurations = (long) 1<<n;
numConfigurations4 = (long) numConfigurations<<2;
// set counts to 0
for (i=0; i<numConfigurations4; i++)
for (l=0; l<numList; l++)
count[l][i]=0;
// go through all strings and do the job
for (i=0; i<N; i++)
{
x = population->x[i];
configuration = (long) indexedBinaryToInt(x,pos,n);
configuration <<= 2;
configuration += x[node];
for (l=0; l<numList; l++)
count[l][configuration+(x[list[l]]<<1)]++;
};
// get back
return 0;
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -