创建自定义的交互离散进化分布

Creating a custom interated discrete evolutionary distribution

本文关键字:进化 分布 交互 自定义 创建      更新时间:2023-10-16

我已经处理这个问题好几天了。我正在运行一个进化模型,该模型使用物种之间相互作用的分布。我把函数粘贴在这里了。我需要使用模板:

template <class InputIt>

如果我直接将模板粘贴到函数声明之前,函数将无法识别模板。如果我在main()之前粘贴它,模板会被识别,但我得到一个错误:

错误2错误LNK1120:1个未解析的外部

代码:

void evolution(TeamArray& teamData)
{
default_random_engine randomGenerator((unsigned int)time(NULL));
uniform_int_distribution<int> rand120(0, 120);
int* RandA;
int* RandB;
RandA = new int[rounds];
RandB = new int[rounds];
// Time Period 1
for (int i = 0; i < rounds / 10; ++i)
{
    RandA[i] = rand120(randomGenerator); // generates random numbers from 0 to 120 (121 elements)
}
for (int i = 0; i < rounds / 10; ++i)
{
    RandB[i] = rand120(randomGenerator); // generates random numbers from 0 to 120 (121 elements)
}
for (int i = 0; i < rounds / 10; i++)
{
    interact(teamData[RandA[i]], teamData[RandB[i]]);
}
delete[] RandA;
delete[] RandB;
    // Later time periods (ERA 2 through 10)
// The inside of this loop does the rest of the interactions 
for (int t = 1; t < 10; ++t) // looping through the ERA's
{
    // Intializing distribution 
    std::vector< int> weights(121);
    for (int i = 0; i < 121; i++)
    {
        weights[i] = (teamData[i]).S();
    }
    std::discrete_distribution<int&> dist(weights.begin(), weights.end());
    for (int i = t* (rounds / 10); i < (t+1) * (rounds / 10); ++i)
    {
        RandA[i] = dist(randomGenerator); 
    }
    for (int i = t* (rounds / 10); i < (t + 1) * (rounds / 10); ++i)
    {
        RandB[i] = dist(randomGenerator); 
    }
    for (int i = t* (rounds / 10); i < (t + 1) * (rounds / 10); ++i)
    {
        interact(teamData[RandA[i]], teamData[RandB[i]]);
    }
    delete[] RandA;
    delete[] RandB;
}

链接器报告错误,因为调用方法(在本例中为构造函数)时使用的签名与类中的任何专业化都不匹配。

std::discrete_distribution文档表明有4个专门的构造函数可用,这些构造函数可能涵盖您需要的情况。

与尝试调用的对象最接近的对象需要[InputInterator][2]引用,而不是integer边界。

Visual C++的示例表明,此构造函数在Microsoft平台上不可用,但提供了一个具有下限和上限的等效解决方案。