1

I'm getting an error message saying expected command in 'choose-exit' and the issue seems to be in the line "choose-exit patch-here" within the "initialize-passengers" procedure. I've checked the code and everything seems correct, so I'm not sure what could be causing the problem.

breed [  passengers    passenger]
breed [  fire-spots  a-fire-spot]
breed [ smoke-spots a-smoke-spot]

globals [        exit1            ;;   pID
                 exit2            ;;   pID
                 exits-list       ;; [ pID ... ]
                 passenger_count  ;;   integer
  
]

passengers-own [ in-seat?         ;; boolean
                 safe?            ;; boolean
                 dead?            ;; boolean
                 panic?           ;; boolean
                 current-heading  ;; turtleHDG
                 target-exit      ;;   pID
                 my-exits-list    ;; [ pID ... ]
                 item?            ;; boolean
]

patches-own [    accessible?      ;; boolean
                 fire?            ;; boolean
]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; FUNZIONI SETUP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup
   
   __clear-all-and-reset-ticks
     ;;;;;; DEBUG
            type "----------------------------[SETUP]\n"
     ;;;;;; DEBUG
     initialize-globals
     initialize-train
     initialize-exits
     initialize-passengers
   ; initialize-fire
     reset-ticks
     
end


to initialize-globals
   
   set exit1           patch 64 -13
   set exit2           patch 13 -54
   set exits-list    ( list exit1 exit2 )
   
end


to initialize-train
   import-pcolors "C:/Users/palli/OneDrive/Desktop/Modello_base/images/ambiente.png"
   ask patches [
     if pcolor = 86.6 [set pcolor cyan]
     if pcolor =  0   [set pcolor black]
     if pcolor = 64.3 [set pcolor green]
     if pcolor =  9.9 [set pcolor white]
       
     set fire? false
     set accessible? false ; Imposta tutte le patch come inaccessibili di default
   ]
   
   ask patches with [pcolor = white] [
     set accessible? true ; Contrassegna le patch verdi come accessibili
   ]
end


to initialize-exits
  set exit1 patch 64 -13
  set exit2 patch 13 -54
  set exits-list (list exit1 exit2)
end


to initialize-passengers
  create-passengers passenger-count [
    set shape "person business"
    set size 2
    set color yellow
    set in-seat? false  ; Cambia da true a false
    set safe? false
    set dead? false
    set panic? true
    set current-heading 0
    set my-exits-list [] ; SET here, it must assign a []-list to this property BEFORE next call to choose-exit
    set target-exit nobody ; SET this as the initial target-exit
    
    ; Aggiungi il seguente blocco di codice per posizionare casualmente i passeggeri in patch accessibili
    let target one-of patches with [accessible?]
    move-to target
    set target-exit choose-exit patch-here ; Aggiorna il target-exit dopo esserti spostato sulla patch iniziale
  ]
end



to-report choose-exit [current-position]  ;; still ignore the passed parameter-value

   let possible-exits        []
   let shortest-distance 10000
   let nearest-exit          nobody

   foreach exits-list [ exitUnderTest ->

           let exit-coords (list [pxcor] of exitUnderTest [pycor] of exitUnderTest) ;; Get exit coordinates as a list
           let exit-distance distance exitUnderTest

           if  exit-distance < shortest-distance [
               set shortest-distance exit-distance
               set nearest-exit      exitUnderTest
               set possible-exits    []
           ]

           if  exit-distance = shortest-distance [
              
               set possible-exits lput exit-coords possible-exits ;; Use exit coordinates instead of the patch object
                      
           ]
   ]

   if length possible-exits = 0 [
       print "No exits found."
       report nobody
   ]

   let lucky-exit-coords    one-of     possible-exits
   let lucky-exit           patch-at ( item 0 lucky-exit-coords )
                                     ( item 1 lucky-exit-coords ) ;; Get the object using the coordinates
   set target-exit          lucky-exit
   
   
   set my-exits-list   lput lucky-exit my-exits-list
         
   report lucky-exit
end


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; FUNZIONI GO ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to go
   ;;;;;; DEBUG
          type "----------------------------[GO.tick]\n"
   ;;;;;; DEBUG
     
   ask passengers [
       if panic? [
          let  target-to-exit choose-exit patch-here
          face target-to-exit
       ]
       move
   ]
   tick
end
;;;go()

to move
   
   if panic? [
      move-to target-exit
      if  patch-here = target-exit [
          set safe?    true
          set in-seat? false
      ]
   ]
end
;;;move()

I have solved the previous 2 problems, This problem occurred to me, the passengers move but do not go towards the exit in a smart way and remain in the centre moving around, they also move out of the edge of the room. How can I solve it?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
accismns
  • 37
  • 5
  • 1
    Would you mind to actually post the whole, complete, reproducible MCVE code? Fractions of code neither represent the as-is problem, nor form a standard MCVE that Stack Overflow is working for decades on. Thank you for your kind reconsideration & update – user3666197 May 19 '23 at 15:00

1 Answers1

1

enter image description here

The MCVE syntax needed a few touches, feel free to improve it further ( other components like initialize-fire remained still missing in the MCVE ) :

breed [  passengers    passenger]
breed [  fire-spots  a-fire-spot]
breed [ smoke-spots a-smoke-spot]

globals [        exit1            ;;   pID
                 exit2            ;;   pID
                 exits-list       ;; [ pID ... ]
                 passenger_count  ;;   integer
]

passengers-own [ in-seat?         ;; boolean
                 safe?            ;; boolean
                 dead?            ;; boolean
                 panic?           ;; boolean
                 current-heading  ;; turtleHDG
                 target-exit      ;;   pID
                 my-exits-list    ;; [ pID ... ]
                 item?            ;; boolean
]

patches-own [    accessible?      ;; boolean
                 fire?            ;; boolean
]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; FUNZIONI SETUP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup
   
   __clear-all-and-reset-ticks
     ;;;;;; DEBUG
            type "----------------------------[SETUP]\n"
     ;;;;;; DEBUG
     initialize-globals
     initialize-train
     initialize-exits
     initialize-passengers
   ; initialize-fire
     reset-ticks
     
end


to initialize-globals
   
   set exit1           patch 64 -13
   set exit2           patch 13 -54
   set exits-list    ( list exit1 exit2 )
   set passenger_count 2
end


to initialize-train
   
 ; import-pcolors "C:/Users/palli/OneDrive/Desktop/Modello_base/images/ambiente.png"
   ask patches [
       if pcolor = 86.6 [set pcolor cyan]
       if pcolor =  0   [set pcolor black]
       if pcolor = 64.3 [set pcolor green]
       if pcolor =  9.9 [set pcolor white]
       
       set fire? false
   ]
   ask patches [
       set accessible? false
   ]
   ask patches with [ pxcor >   5 and
                      pxcor <  64 and
                      pycor >  -5 and
                      pycor < -54 ] [
       set accessible? true
   ]
end
;;;initialise-train()

to initialize-exits
   
   set exit1        patch 64 -13
   set exit2        patch 13 -54
   set exits-list ( list exit1 exit2 )
end
;;;initialize-exits()

to initialize-passengers
   
   create-passengers passenger_count [
        ; set shape          "person business"
          set size            2
          set color           yellow
          set in-seat?        true
          set safe?           false
          set dead?           false
          set panic?          false
          set current-heading 0
          set my-exits-list   []                     ; SET here as SET target-exit calls choose-exit()-method, where this attribute must have been already assigned a list-value
          set target-exit     choose-exit patch-here ; SET this as the initial target-exit
  ]
  ask passengers [
      let     target one-of patches with [accessible?]
    ; HANDLE a case resulting in an empty agentSet { patches with ... }
      ;;;;;;; DEBUG                     face target
              type word who "-will TRY: face target\n"
              type word "AFTER:" word patches with [accessible?] "IN patches with [accessible?]\n"
              type word "WITH:" word target  "IN target\n"
      face    target
              type "EXEC'd...PASS\n\n"
      ;;;;;; DEBUG ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
      move-to target
  ]
end
;;;initialize-passengers()

to-report choose-exit [current-position]  ;; you still ignore the passed parameter-value

   let possible-exits        []
   let shortest-distance 10000
   let nearest-exit          nobody

   foreach exits-list [ exitUnderTest ->

           let exit-coords (list [pxcor] of exitUnderTest [pycor] of exitUnderTest) ;; Get exit coordinates as a list
           let exit-distance distance exitUnderTest

           if  exit-distance < shortest-distance [
               set shortest-distance exit-distance
               set nearest-exit      exitUnderTest
               set possible-exits    []
           ]

           if  exit-distance = shortest-distance [
               ;;;;;; DEBUG                     set possible-exits lput exit-coords possible-exits
                      type word who "-will TRY: set possible-exits lput exit-coords possible-exits\n"
                      type word "WITH:" word exit-coords          "IN exit-coords\n"
                      type word "WITH:" word possible-exits       "IN possible-exits\n"
               set possible-exits lput exit-coords possible-exits ;; Use exit coordinates instead of the patch object
                      type "EXEC'd...PASS\n\n"
               ;;;;;; DEBUG ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
           ]
   ]

   if length possible-exits = 0 [
       print "No exits found."
       report nobody
   ]

   let lucky-exit-coords    one-of     possible-exits
   let lucky-exit           patch-at ( item 0 lucky-exit-coords )
                                     ( item 1 lucky-exit-coords ) ;; Get the object using the coordinates
   set target-exit          lucky-exit
   
   ;;;;;; DEBUG                     set my-exits-list lput lucky-exit my-exits-list
          type word who "-will TRY: set my-exits-list lput lucky-exit my-exits-list\n"
          type word "WITH:" word lucky-exit     "IN lucky-exit\n"
          type word "WITH:" word my-exits-list  "IN my-exits-list\n"
   set my-exits-list   lput lucky-exit my-exits-list
          type "EXEC'd...PASS\n\n"
   ;;;;;; DEBUG ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
   report lucky-exit
end
;;;report choose-exit()

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; FUNZIONI GO ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to go
   ;;;;;; DEBUG
          type "----------------------------[GO.tick]\n"
   ;;;;;; DEBUG
     
   ask passengers [
       if panic? [
          let  target-to-exit choose-exit patch-here
          face target-to-exit
       ]
       move
   ]
   tick
end
;;;go()

to move
   
   if panic? [
      move-to target-exit
      if  patch-here = target-exit [
          set safe?    true
          set in-seat? false
      ]
   ]
end
;;;move()

This works with respect to failing to meet the lput-syntax with a list-instance ( the call to-initialize-passengers asked a not-yet assigned passenger-property [my-exits-list], which was until its later 1st assignment pre-initialised with a system default integer value of 0 )

Q/A-PASS-ed

A next problem is straightforward in the debug-report :
Q/A-FAIL-s

----------------------------[SETUP]
0-will TRY: set possible-exits lput exit-coords possible-exits
WITH:         [-2 -13] IN exit-coords
WITH:               [] IN possible-exits
EXEC'd...PASS

0-will TRY: set my-exits-list lput lucky-exit my-exits-list
WITH:   (patch -2 -13) IN lucky-exit
WITH:               [] IN my-exits-list
EXEC'd...PASS

1-will TRY: set possible-exits lput exit-coords possible-exits
WITH:         [-2 -13] IN exit-coords
WITH:               [] IN possible-exits
EXEC'd...PASS

1-will TRY: set my-exits-list lput lucky-exit my-exits-list
WITH:   (patch -2 -13) IN lucky-exit
WITH:               [] IN my-exits-list
EXEC'd...PASS

1-will TRY: face target
AFTER:   (agentset, 0 patches) IN patches with [accessible?]
WITH:                   nobody IN target

A good, robust code has to assume corner-cases, where empty-[]-instances might crash an otherwise reasonably meant code.

Go solve these cases, with delivering some emergency-case value for those cases, where a []-instance resulted in being empty.

As per comment below - MCVE-code, without having the variable passenger-count defined (was perhaps "injected" from a GUI-interface design, likely via a field or a slider) at least as a mock-up fix, was not complete ( if you have added some other code-sections later, not published in the MCVE above, there you go and now have to remove the mock-up fix or solve the new errors introduced by/with the new code-section added as appropriate ) :

enter image description here

"People are not born in the environment I created but in the top left-hand corner and do not move. Why?"

Because the create-passengers passenger_count [...]-code does not specify any particular randomisation of the passenger-instances initial locations. Code it there and you can have whatever behaviour upon "birth" w.r.t. environment ( as per loaded picture ?)

Why the passengers do not move? Check your code and contents of variables, if you want other than the so far coded behaviour. The current code has a global named panic? which was pre-assigned a false, i.e. the if panic? [...]-clause will never execute the commands there, unless something somewhere at some unknown time switch the boolean panic? into a true-state.

halfer
  • 19,824
  • 17
  • 99
  • 186
user3666197
  • 1
  • 6
  • 50
  • 92
  • Thanks for the help, but with your code this error appear: there is already a global variable called passenger-count – accismns May 19 '23 at 16:24
  • Not in my IDE. The global was added as it was not defined otherwise in the MCVE and threw a "*Nothing named PASSENGER-COUNT has been defined.*" error otherwise. In case you added some further code-sections to the revised MCVE-code, search in those sections and/or remove the mock-up `passenger-count` fixing definition from the `globals [ ... passenger-count ]` – user3666197 May 19 '23 at 16:50
  • I have put passenger-count as comment like you and when press setup button this error appear: `LPUT expected input to be a list but got the number 0 instead. error while passenger 1 running LPUT called by procedure CHOOSE-EXIT called by procedure INITIALIZE-PASSENGERS called by procedure SETUP called by Button 'setup'` How can i fix? Edited code – accismns May 19 '23 at 16:59
  • Creeps side-ways. MCVE-code requires to have `globals [ ... passenger-count ]` as otherwise it would by syntactically wrong ( having an undefined variable ). Similarly the `choose-exit [ current-position ]`-*reporter* did not use a value, passed from caller via the `current-position` parameter at all, yet still works as needed in computing a `distance exitUnderTest` for each respective `passenger`-*agent* instance in the population. Last comment claimed an error in `lput aValue aList` yet in both of the MCVE-code appearances of `lput`-*reporter* list-parts are proper `list`-instances, not `0` – user3666197 May 19 '23 at 17:24
  • How can i fix my code to make it work? – accismns May 19 '23 at 17:30
  • Start with cross-checking, where did you define `passenger-count`-*value* once you has changed the corrected code above by commenting out the `globals [ ... passenger-count ]`-*missing-definition-fix*. Similarly next find, what has caused, in your modified code, the `list`-*parameter* inside either of the present `lput `-*reporter* clauses, as the above provided code was error-free in this ( as in either of the two cases a proper `list`-*instance* was delivered to the said `lput`-*reporter* clauses. Go through your modified code and trace the root source of the new problems – user3666197 May 19 '23 at 17:51
  • I took the code from your answer I did not change anything, all the code is what I put in the question. That's why I don't understand what could be wrong – accismns May 19 '23 at 18:07
  • My localhost IDE NetLogo 6.2.2 shows no error for corrected MCVE-code. WebBased NetLogo has also no errors ( except an obvious and trivial one -- (Line 28) Nothing named __CLEAR-ALL-AND-RESET-TICKS has been defined. ) While one cannot test my localhost IDE, anyone can test the other IDE - WebBased NetLogo and copy/paste the source-code ( and compile it error-free as a proof ) at https://www.netlogoweb.org/launch#https://www.netlogoweb.org/assets/modelslib/Sample%20Models/Networks/Preferential%20Attachment.nlogo – user3666197 May 19 '23 at 18:50