# GasLab Benchmark

No preview image

Model was written in NetLogo 4.1pre1
•
Viewed 159 times
•
Downloaded 20 times
•
Run 0 times

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)

### VERSION

$Id: GasLab Benchmark.nlogo 38506 2008-03-05 23:59:14Z tisue $

## Comments and Questions

Please start the discussion about this model!
(You'll first need to log in.)

Click to Run Model

globals [ fast average slow ;; current counts avg-speed avg-energy ;; current averages avg-speed-init avg-energy-init ;; initial averages vsplit vclock ;; clock variables box-edge ;; patch coords of box's edge result ] turtles-own [ speed mass energy new-speed ;; turtle info v1t v1l tmp-turtle ;; collision info (turtle 1) heading2 mass2 speed2 v2t v2l turtle2 ;; collision info (turtle 2) theta ;; collision info (both turtles) ] patches-own [ box? ] to benchmark random-seed 361 reset-timer setup repeat 800 [ go ] set result timer end to setup ca set box-edge (round (max-pxcor * box-size-percent / 100)) make-box set vclock 0 cro number ask turtles [ set new-speed initspeed set mass initmass if who != 0 [ random-position ] rt random 360 recolor-turtle turtle who ] update-variables set avg-speed-init avg-speed set avg-energy-init avg-energy setup-plots setup-histograms do-plotting do-histograms end to update-variables ask turtles [ set speed new-speed set energy (0.5 * speed * speed * mass) ] set average count turtles with [color = green ] set slow count turtles with [color = blue] set fast count turtles with [color = red] set avg-speed mean [speed ] of turtles set avg-energy mean [energy] of turtles set vsplit (round ((max [speed] of turtles) * 1.2)) end to go ask turtles [ bounce ] ask turtles [ move ] set vclock (vclock + 1) if (vclock = vsplit) [ tick set vclock 0 update-variables do-plotting do-histograms ask patches [ fade ] ] end to bounce ;;turtle procedure ; check: hitting top or bottom wall? if ((pycor = box-edge) and ((heading > 270) or (heading < 90))) or ((pycor = (0 - box-edge)) and ((heading > 90) and (heading < 270))) ; if so, reflect heading around y axis [ set heading (180 - heading) ] ; check: hitting left or right wall? if ((pxcor = box-edge) and ((heading > 0) and (heading < 180))) or ((pxcor = (0 - box-edge)) and ((heading > 180))) ; if so, reflect heading around x axis [ set heading (0 - heading) ] end to move ;;turtle procedure jump ( speed / vsplit ) check-for-collision if trace? and ( who = 0 ) and not box? [ set pcolor yellow] end to check-for-collision ;;turtle procedure if not box? and (count other turtles-here = 1) [ set tmp-turtle one-of other turtles-here if ((who > [who] of tmp-turtle) and (turtle2 != tmp-turtle)) [ collide recolor-turtle turtle who ] ] end to collide ;;turtle procedure get-turtle2-info calculate-velocity-components set-new-speed-and-headings end to get-turtle2-info ;;turtle procedure set turtle2 tmp-turtle set mass2 [mass] of turtle2 set speed2 [new-speed] of turtle2 set heading2 [heading] of turtle2 end to calculate-velocity-components set theta ( random 360 ) set v1l ( new-speed * ( sin ( theta - heading ) ) ) set v1t ( new-speed * ( cos ( theta - heading ) ) ) set v2l ( speed2 * ( sin ( theta - heading2 ) ) ) set v2t ( speed2 * ( cos ( theta - heading2 ) ) ) let vcm ( ( ( mass * v1t ) + ( mass2 * v2t ) ) / ( mass + mass2 ) ) set v1t ( vcm + vcm - v1t ) set v2t ( vcm + vcm - v2t ) end to set-new-speed-and-headings ;;turtle procedure set new-speed sqrt (( v1t * v1t ) + ( v1l * v1l )) ifelse ( ( v1l >= 0 ) and ( v1t >= 0 ) ) [set heading ( theta - ( atan v1l v1t ) )] [ifelse ( ( v1l < 0 ) and ( v1t < 0 ) ) [set heading ( ( theta + 180 ) - ( atan v1l v1t ) )] [ifelse ( ( v1l >= 0 ) and ( v1t < 0 ) ) [set heading ( ( theta + 180 ) - ( atan v1l v1t ) ) ] [if ( ( v1l < 0 ) and ( v1t >= 0 ) ) [set heading ( theta - ( atan v1l v1t ) )] ] ] ] let new-new-speed sqrt (( v2t * v2t) + ( v2l * v2l)) ask turtle2 [ set new-speed new-new-speed ] ifelse ( ( v2l >= 0 ) and ( v2t >= 0 ) ) [set heading2 ( theta - ( atan v2l v2t ) )] [ifelse ( ( v2l < 0 ) and ( v2t < 0 ) ) [set heading2 ( ( theta + 180 ) - ( atan v2l v2t ) )] [ifelse ( ( v2l >= 0 ) and ( v2t < 0 ) ) [set heading2 ( ( theta + 180 ) - ( atan v2l v2t ) )] [if ( ( v2l < 0 ) and ( v2t >= 0 ) ) [set heading2 ( theta - ( atan v2l v2t ) ) ] ] ] ] let new-heading heading2 ask turtle2 [ set heading new-heading ] recolor-turtle turtle2 end to recolor-turtle [the-turtle] ifelse [new-speed] of the-turtle < (0.5 * initspeed) [ ask the-turtle [ set color blue ] ] [ ifelse [new-speed] of the-turtle > (1.5 * initspeed) [ ask the-turtle [ set color red ] ] [ ask the-turtle [ set color green ] ] ] end to fade if (not box?) and (pcolor != black ) [ set pcolor ( pcolor - 0.4 ) if (round pcolor = 40) [ set pcolor black ] ] end to make-box ask patches [ set box? false if ((abs pxcor = box-edge) and (abs pycor <= box-edge)) or ((abs pycor = box-edge) and (abs pxcor <= box-edge)) [ set pcolor red set box? true ] ] end to random-position ;; turtle procedure setxy ((1 - box-edge) + random ((2 * box-edge) - 2)) ((1 - box-edge) + random ((2 * box-edge) - 2)) end to setup-plots set-current-plot "Speed Counts" set-plot-y-range 0 number end to do-plotting set-current-plot "Speed Counts" set-current-plot-pen "fast" plot fast set-current-plot-pen "average" plot average set-current-plot-pen "slow" plot slow end to setup-histograms set-current-plot "Speed Histogram" set-plot-x-range 0 (initspeed * 2) set-plot-y-range 0 round (number / 6) set-current-plot-pen "average" set-histogram-num-bars 32 set-current-plot-pen "slow" set-histogram-num-bars 32 set-current-plot-pen "fast" set-histogram-num-bars 32 set-current-plot "Energy Histogram" set-plot-x-range 0 (0.5 * (initspeed * 2) * (initspeed * 2) * initmass) set-plot-y-range 0 round (number / 6) set-current-plot-pen "average" set-histogram-num-bars 32 set-current-plot-pen "slow" set-histogram-num-bars 32 set-current-plot-pen "fast" set-histogram-num-bars 32 end to do-histograms set-current-plot "Speed Histogram" set-current-plot-pen "average" histogram [ speed ] of turtles with [ color = green ] set-current-plot-pen "slow" histogram [ speed ] of turtles with [ color = blue ] set-current-plot-pen "fast" histogram [ speed ] of turtles with [ color = red ] set-current-plot-pen "Vert-Line" plot-pen-reset draw-vert-line avg-speed gray draw-vert-line avg-speed-init black set-current-plot "Energy Histogram" set-current-plot-pen "average" histogram [ energy ] of turtles with [ color = green ] set-current-plot-pen "slow" histogram [ energy ] of turtles with [ color = blue ] set-current-plot-pen "fast" histogram [ energy ] of turtles with [ color = red ] set-current-plot-pen "Vert-Line" plot-pen-reset draw-vert-line avg-energy gray draw-vert-line avg-energy-init black end ; draws a vertical line of color linecolor on plot plotname, at xval to draw-vert-line [xval linecolor] set-plot-pen-color linecolor plotxy xval plot-y-min plot-pen-down plotxy xval plot-y-max plot-pen-up end

There are 2 versions of this model.

## Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.