Outcome of BehaviorSpace

守給你的承諾、 提交于 2020-05-30 10:51:05

问题


I am simulating a classroom to find the total energy consumption from appliances of a classroom. Now I want to run the simulation in BehaviorSpace so that I get the energy consumption by varying the number of students in the classroom.

         globals[
        temp1 a s simulation-timer number-of-seats number-of-lights 
       number-of-fans number-of-acs gap row col x-cor y-cor half half2 
       student-no t-light t-fan t-ac t-energy
              ]
          breed [seats seat]
         breeed [seat-teachers seat-teacher]
         breed [lights light]
         breed [fans fan]
         breed [acs ac ]
         breed [students student ]

         to setup
         clear-all

          ask patches [ set pcolor 9 ]
          set gap floor ((max-pxcor) / (no-of-row-or-col) )
          set half ceiling (gap / 2)
          set half2 floor (gap / 2)
          place-seat-teachers
          place-seats-students
          place-lights
          place-fans
          place-acs
          ask patches with [ pxcor = 3 * gap + half2 ] [ set pcolor 4 ]
          ask patches with [ pxcor = 6 * gap + half2 ] [ set pcolor 4 ]
          create-students-classroom
          reset-ticks
          reset-timer
          end


          to go
          while [simulation-timer < time ] [

          move-students
          set simulation-timer simulation-timer + 1
          tick ]
           stop
            end

            to create-students-classroom                                    
            create-students number-of-students [
             set entry-time random threshold + 1                         ; 
              set random-entry time to each student

            let stu-no sort-on [who] students                          
            foreach stu-no [x -> ask x [ show (word x " -> " entry-time ) 
            ] ]  
            set shape "person"
            set color 3
               ]
           set s sort [who] of seats                                       
          set a first s

          end

           to move-students                                               

           let l length s

           set temp1 simulation-timer
           tick

          ask students [ if ( entry-time = temp1 )                   
              [
    move-to seat a                                          
   set color red
    appliance-on                                             
    show (word temp1 "," l "," a)
    set s remove a s
    set a a + 1
    set l length s
  ]
]
  end

   to appliance-on                                                    

     ask lights with [not l-on? and any? students in-radius 4]
     [ switch-light-on ]
      ask fans with [not f-on? and any? students in-radius 4]
      [ switch-fan-on]
        ask acs with [ not a-on? and any? students in-radius 9]
      [ switch-ac-on]

        stop

         end
         to switch-light-on                                             
         set color green
         set l-on? true
          set light-turned-on simulation-timer
         set light-on-duration light-on-duration + (time - light-turned-on 
          )
            type "light on duration " print light-on-duration
           end

            to-report energy-calculation

           ask lights [ ifelse ( l-on? )  [ set l-energy (light-on- 
            duration * light-wattage) ][ set l-energy 0 ] ]
             ask fans [ ifelse ( f-on? ) [ set f-energy ( fan-on-duration 
            * fan-wattage )] [ set f-energy 0 ] ]
            ask acs [ ifelse ( a-on? ) [ set a-energy (ac-on-duration * 
             ac-wattage) ] [ set a-energy 0 ] ]

             let light-e sum [l-energy] of lights
              let fan-e sum [f-energy] of fans
              let ac-e sum [a-energy] of acs

              set t-light ( light-e / (60000))
              set t-fan ( fan-e / (60000))
              set t-ac ( ac-e / ( 60000 ) )

              show (word "sum of ac energy = " ac-e )

               report ( t-light + t-fan + t-ac )

                  end

In the BehaviorSpace: measure runs using these reporters I am putting energy-calculation but in the spreadsheet everything is showing zero. Why is this happening?


回答1:


Abdullah,

I can't run your code as you've provided it, but I suspect that the problem lies in your go procedure. BehaviorSpace treats the go procedure as a forever button, that is it keeps running until either the number of ticks exceeds the Time limit or until it is stopped by some other user-supplied condition. Moreover, BS runs the reporters listed under Measure runs using these reporters only at the end of each iteration of the go procedure. It assumes each iteration takes a tick. Your go procedure, however, only runs once. The while loop is executed time times, but that is all within the first (and only) iteration of go, after which the simulation is stopped by the stop command. I'm not sure why you are using simulation-timer instead of ticks to keep tract of the time, but let me suggest a go procedure that will do what I suspect you want.

to go    
  move-students
  tick 
  if ticks > time [ stop ]
end

In this case, go will keep going, and BS will report energy-calculation at the end of each iteration of go, until the number of iterations (ticks) exceeds time. If you set Time limit in BS to time, the if statement will be redundant, but not if you are also running the model outside of BS. (If you are running from the interface tab, the go button should be a "forever" button.)

You also have a redundant stop at the end of your appliance-on procedure.

I may have missed something important in what you are trying to do, but perhaps this will get you started in solving your problem.

Charles



来源:https://stackoverflow.com/questions/60305898/outcome-of-behaviorspace

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!