Search code examples
if-statementconditional-statementsnetlogomovepatch

Netlogo: Turtle checking if it can move into a valid target


I am trying to simulate a neighbourhood visiting local businesses. There are two breeds of patches (home and businesses) and turtles (people and owners). The plan is to have people be able to visit a shop if an owner is on the business patch, and considered closed otherwise.

A day is split into three ticks: morning, afternoon, and evening. All shops are often in the morning and the afternoon, but a random number of owners go home in the evening. If shops are unavailable, owners will just go home.

After a while of running, I get the error MOVE-TO expected input to be an agent but got NOBODY instead. Pointing to the "ifelse" section of the evening-move command.

Thank you for the help!

to go
  morning-move ;Morning movement (First shopping phase)
  tick

  afternoon-move ;Afternoon movement (Second shopping phase)

  tick

  evening-move ;Evening movement (Return home)

  tick

end

to morning-move
  ask owners [move-to work-xy] ;make owners open their businesses
    ask people [ifelse any? open-busi-patches with [any? owners-here and count people-here < MaxCapacity] ;This checks if there are open businesses
    [ask people [move-to one-of open-busi-patches with [any? owners-here and count people-here < MaxCapacity]]] ;move people to businesses under capacity
    [ask people [move-to home-xy]]]
  ask open-busi-patches [set OpsProfit OpsProfit + count people-here] ;cumulative count of patrons
end

to afternoon-move
  ask people [ifelse any? open-busi-patches with [count owners-here > 0 and count people-here < MaxCapacity] ;This checks 
    [ask people [move-to one-of open-busi-patches with [any? owners-here and count people-here < MaxCapacity]]] ;move people to businesses under capacity
    [ask people [move-to home-xy]]]
  ask open-busi-patches [set OpsProfit OpsProfit + count people-here] ;cumulative count of patrons
end

to evening-move
  ask n-of random count owners owners [move-to home-xy] ;This choses a random number of owners to stay open in the evening.
  ask people [ifelse any? open-busi-patches with [any? owners-here and count people-here < MaxCapacity] ;This checks 
    [ask people [move-to one-of open-busi-patches with [any? owners-here and count people-here < MaxCapacity]]] ;move people to businesses under capacity
    [ask people [move-to home-xy]]]
  ask open-busi-patches [set OpsProfit OpsProfit + count people-here] ;cumulative count of patrons
end

Solution

  • So this is the code that is giving you the error (reformatted)

    to afternoon-move
      ask people
      [ ifelse any? open-busi-patches with [count owners-here > 0 and count people-here < MaxCapacity ]
        [ ask people ;;;; THIS LINE
          [ move-to one-of open-busi-patches with [any? owners-here and count people-here < MaxCapacity]
          ]
        ]
        [ ask people
          [ move-to home-xy]
        ]
      ]
      ask open-busi-patches [set OpsProfit OpsProfit + count people-here]
    end
    

    The basic problem is that the line I have marked is actually moving people and using up the open businesses. So the first condition tests whether there are businesses with space initially and it never gets retested.