首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >BehaviorSpace的结果

BehaviorSpace的结果
EN

Stack Overflow用户
提问于 2020-02-20 01:18:24
回答 1查看 36关注 0票数 1

我正在模拟一个教室,以求出教室电器的总能耗。现在我想在BehaviorSpace中运行模拟,这样我就可以通过改变教室中的学生数量来获得能量消耗。

代码语言:javascript
复制
         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

在BehaviorSpace: measure中,使用这些记者,我将能量计算放在电子表格中,但在电子表格中,所有内容都显示为零。为什么会发生这种情况?

EN

回答 1

Stack Overflow用户

发布于 2020-02-20 09:30:37

阿卜杜拉

我不能运行您提供的代码,但我怀疑问题出在您的go过程中。BehaviorSpace将go过程视为一个永久按钮,也就是说,它将一直运行,直到滴答次数超过Time limit,或者直到被其他用户提供的条件停止。此外,BS仅在go过程的每次迭代结束时运行Measure runs using these reporters下列出的报告程序。它假设每一次迭代都需要一个滴答。但是,您的go过程只运行一次。while循环被执行time次,但这都是在go的第一次(也是唯一一次)迭代中执行的,在第一次迭代之后,stop命令将停止模拟。我不确定您为什么要使用simulation-timer而不是ticks来节省时间,但让我建议一个go过程,它将完成我怀疑您想要的事情。

代码语言:javascript
复制
to go    
  move-students
  tick 
  if ticks > time [ stop ]
end

在这种情况下,go将继续运行,BS将在go的每次迭代结束时报告能量计算,直到迭代次数(滴答)超过time。如果将BS中的Time limit设置为time,则if语句将是多余的,但如果还在BS外部运行模型,则不会。(如果您从界面选项卡运行,则go按钮应该是一个“永久”按钮。)

appliance-on过程的末尾还有一个冗余的stop

我可能在你正在尝试做的事情中遗漏了一些重要的东西,但这可能会让你开始解决你的问题。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60305898

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档