How can we do a monte carlo simulation of netlogo and write outputs to file

135 views
Skip to first unread message

Dimitry T-

unread,
Nov 8, 2023, 1:34:31 PM11/8/23
to netlogo-users
Hi there,

Hi there, I am currently modeling a project for school ( battle of midway) and I have a few questions if you might be able to answer.

  1. I am new to the netlogo world, could you please let me know how i can model my simulation n number of times to build confidence using some type of monte carlo runs.  
  2. how do we model aircraft sorties from a carrier
  3. how are we able to include probability of kill and hit when the planes, ships turtles interact to makes sure we can represent the historic battle. do we just use a bunch of if statements, our code sample is attached bellow.
  4. Lastly, how do we write all of our output to files so we could use excel, R or python do to the data analysis. 


code sample:
;; gun attack for IJN and USN planes ( small guns only)
to-report gun-attack [h]
    let pk_rand_val (random 100)
    set h (ifelse-value
      pk_rand_val < 5 [h]
      pk_rand_val > 5 and  pk_rand_val < 25 [h - h * pk_rand_val / 100]
      pk_rand_val > 25 and pk_rand_val < 50  [h - h * pk_rand_val / 100]
      pk_rand_val > 50 and pk_rand_val < 75  [h - h * pk_rand_val / 100]
      [0])
    report h
end

;;  torpedo
to-report torpedo-attack [h n]
    let pk_rand_val (random 100)
    ifelse navy = "IJN" [
      set h (ifelse-value
        pk_rand_val < 5 [h]
        pk_rand_val > 5 and pk_rand_val < 25 [h - h * 90 / 100]
        [0])
    ][
      set h(ifelse-value
        pk_rand_val < 90 [h]
        [0])
     ]
  report h
end

;; dive bombers
to-report bomb-attack [h]
  let pk_rand_val (random 100)
    set h (ifelse-value
        pk_rand_val < 5 [h]
        pk_rand_val > 5 and pk_rand_val < 25 [h - h * 30 / 100]
        pk_rand_val > 25 and pk_rand_val < 50 [h - h * 60 / 100]
        [0])
  report h
end

;; battle ship
to-report heavy-guns [h]
  let pk_rand_val (random 100)
    set h (ifelse-value
    pk_rand_val < 5 [h]
    pk_rand_val > 5 and pk_rand_val < 10 [h - h * 40 / 100]
    pk_rand_val > 10 and pk_rand_val < 20 [h - h * 80 / 100]
    [0])
  report h
end

;; destroyer guns
to-report cannon-attack [h]
  let pk_rand_val (random 100)
    set h (ifelse-value
      pk_rand_val < 5 [h]
      pk_rand_val > 5 and pk_rand_val < 25 [h - h * 25 / 100]
      pk_rand_val > 25 and pk_rand_val < 40 [h - h * 40 / 100]
      pk_rand_val > 40 and pk_rand_val < 60 [h - h * 60 / 100]
      [0])
  report h
end

Dale Frakes

unread,
Nov 8, 2023, 2:20:30 PM11/8/23
to netlog...@googlegroups.com
Hi Dimitry,

for your experimental work (running n times, writing output files), you'll want to check into NetLogo's BehaviorSpace: https://ccl.northwestern.edu/netlogo/docs/behaviorspace.html

It's designed to do exactly that!

I'm not sure about how to handle 2 and 3.

Dale
--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/2822fac2-915d-4a77-b5f0-562b5b5b163dn%40googlegroups.com.

-- 
Dale Frakes
Adjunct Instructor, PhD Student
PSU Systems Science
dfr...@pdx.edu - http://web.pdx.edu/~dfrakes/

James Steiner

unread,
Nov 8, 2023, 2:48:33 PM11/8/23
to Dimitry T-, netlogo-users
Consider using state machines, one for the over all model, and each agent.

If your sorties include distinct squadrons, make sure there is a designated squadron leader, and that leader may have a state machine for its orders in the mission.

Your states might be going out, attacking, leaving, and waiting.

You might use a counter or the timer or the conditions of the model to determine when to switch from state to state. 

Remember that you can use breeds of turtle to represent secondary entities, and more abstract agents to keep track of statistics and other things, if needed.

Like, the carrier/carrier commander is an agent, the target is an agent, the squad leader is an agent, the aircraft/pilot is an agent.







--

Dimitry T-

unread,
Nov 8, 2023, 4:07:05 PM11/8/23
to netlogo-users
@Greg,

How would one develop a state machine in netlogo, as I mentioned before my netlogo experience is limited so I am still figuring out as I go. 

-Dimitry 

Reply all
Reply to author
Forward
0 new messages