mvoltin
mvoltin

Reputation: 15

AnyLogic - cannot resolve or is not a field issue

I am adding a new agent and agent population (Shop/shops) to AnyLogic model and replicating existing code for Work/works. Everything works except shop (lowercase). Searched entire software to find where work (with lowercase) is defined (in order to do the same for shop) to no avail; cannot find anything that would explain why work is interpreted and not shop. (sorry, I know the question is not framed in a best way - total beginner here). This maybe AnyLogic specific question?

Here is the problem line (shop right after p.)

p.shop = shops.get( uniform_discr( 0, shops.size()-1 ) );

and here is the full code:

//setup work locations
for( int i=0; i<works.size(); i++ ) {
    Work w = works.get(i);
    w.X = 540 + 65 * ( i % 3 );
    w.Y = 30 + 50* ( i / 3);
}
for( int i=0; i<shops.size(); i++ ) {
    Shop s = shops.get(i);
    s.X = 750 + 65 * ( i % 3 );
    s.Y = 30 + 50* ( i / 3);
}
//setup families
for( int i=0; i<TotalFamilies; i++ ) {
    //create a Family object
    Family f = add_families();
    //set home location
    f.X = 50 * ( i % 10 );
    f.Y = 40 * ( i / 10 );
    //add family members
    int size = uniform_discr( 2, 5 );
    for( int j=0; j<size; j++ ) {
        //create a person
        Person p = add_people();
        //add to the family
        f.members.add( p );
        p.family = f;
        if (p.old == true) 
        {f.elderHome = true;
        nOld++;};
        //set its home location (in family house)
        p.XHome = f.X + 5 + 5 * ( j % 3 );
        p.YHome = f.Y + 6 - 5 * ( j / 3 ) ;
        p.jumpTo( p.XHome, p.YHome );
        //assign work and shops
        p.shop = shops.get( uniform_discr( 0, shops.size()-1 ) );
        p.work = works.get( uniform_discr( 0, works.size()-1 ) );
    }
} 
//infect three random people at the beginning of the simulation

for( int i=0; i<3; i++ )
    people.get( uniform_discr( people.size()-1 )).
        illness.receiveMessage( "Infection" );

Upvotes: 1

Views: 2029

Answers (1)

Benjamin
Benjamin

Reputation: 12660

work is defined in agent type Person as a parameter or variable.

If you error is flagging that for shop, it means your agent type Person has no variable shop (that is of type Shop). Add it and the error will go away.

PS: Do some more tutorials and read up on object-oriented programming to understand the basic principles better :)

Upvotes: 2

Related Questions