Creating a custom interated discrete evolutionary distribution

假装没事ソ 提交于 2019-12-13 08:43:52

问题


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:

template <class InputIt>

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:

Error 2 error LNK1120: 1 unresolved externals

The code:

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;
}

回答1:


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.

The std::discrete_distribution documentation indicates that there are 4 specialised constructors available and these may cover the case that you require.

The one that you appear closest to the one you attempted to call requires [InputInterator][2] references, not integer bounds.

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.



来源:https://stackoverflow.com/questions/31169695/creating-a-custom-interated-discrete-evolutionary-distribution

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!