创建自定义的互动离散进化分布 [英] Creating a custom interated discrete evolutionary distribution
问题描述
我已经解决了这个问题几天了。我运行一个进化模型,使用物种之间的相互作用的分布。我在这里粘贴了函数。我需要使用模板:
I have been tackling this issue for days now. I am running an evolutionary model which uses a distribution for interactions between species. I pasted the function here. I need to use the template:
模板< class InputIt>
如果我直接在函数声明之前粘贴它,函数不会识别模板。如果我在main()之前粘贴它,模板被识别,但我得到单个错误:
The function does not recognize the template if I paste it directly before the function declaration. If I paste it before main(), the template is recognized, but I get the single error:
错误2错误LNK1120:1未解决的外部
Error 2 error LNK1120: 1 unresolved externals
代码:
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;
}
推荐答案
链接器,因为一个方法(在这种情况下是构造函数)被调用的签名与类中的任何特殊化都不匹配。
The error is reported by the linker because a method (in this case the constructor) is called with a signature that does not match any of the specialisations in the class.
std :: discrete_distribution 文档表明有4个专用构造函数可用,这些可能涵盖您需要的情况。
The std::discrete_distribution documentation indicates that there are 4 specialised constructors available and these may cover the case that you require.
您最接近您尝试调用的对象的引用需要 [InputInterator] [2]
不整数
边界。
The one that you appear closest to the one you attempted to call requires [InputInterator][2]
references, not integer
bounds.
示例表示此构造函数在Microsoft平台上不可用,但提供了具有下限和上限的等效解决方案。
The example for Visual C++ indicates that this constructor is not available on the Microsoft platform but provides an equivalent solution with lower and upper bounds.
这篇关于创建自定义的互动离散进化分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!