0

我正在模拟一个教室,以查找教室设备的总能耗。现在我想在 BehaviorSpace 中运行模拟,以便通过改变教室中的学生人数来获得能源消耗(能源计算)。

                globals[
             temp1 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]
     breed [seat-teachers seat-teacher]
     breed [lights light]
     breed [fans fan]
     breed [acs ac ]
     breed [students student ]


    seats-own [
    seat-color
     occupied?
       ]

    seat-teachers-own [
   seat-color

     ]

    students-own [
    entry-time
     found-seat
     ]

    lights-own [
    l-energy
     ]
    fans-own [
    f-energy
    ]
    acs-own [
      a-energy
      ]
       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 place-seat-teachers
     create-seat-teachers 1 [
     setxy ((max-pxcor - min-pxcor) / 2) 1
     set shape "square"
     set size 3
     set color red
     ]
     end


     to place-seats-students
     set row gap
     set col gap
     set x-cor 0
     set y-cor 0

    while [ x-cor <= gap * no-of-row  ]
    [
    ifelse (x-cor = row)[
   set col gap
    set y-cor 0
    while [ y-cor <= gap * no-of-row-or-col ]
  [
    ifelse (y-cor = col)[
      create-seats 1 [
        set shape "square"
        set size 1.5
        set color blue

        setxy col row
        set label who
        set number-of-seats number-of-seats + 1
        show (word row ", " col )

      ]
      set col col + gap
      set y-cor y-cor + 1
    ]
    [set y-cor y-cor + 1]
    ]
    set row row + gap
    set x-cor x-cor + 1
    ]
    [set x-cor x-cor + 1]
     ]
     end


      to place-lights
      set row gap + half2
      set col gap + half
      set x-cor 0
      set y-cor 0

       while [ x-cor <= gap * no-of-row-or-col ]
       [
       ifelse (x-cor = row)[
       set col gap + half
       set y-cor 0
       while [ y-cor <= gap * no-of-row ]
        [
       ifelse (y-cor = col)[
       create-lights 1 [
        set shape "pentagon"
        set size 1
        set color red

        setxy row col
        set number-of-lights number-of-lights + 1
        show (word row "," col )
      ]
      set col col + ( gap * 2)
       set y-cor y-cor + 1
        ]
        [set y-cor y-cor + 1]
        ]
        set row row + ( gap * 2)
        set x-cor x-cor + 1
         ]
         [set x-cor x-cor + 1]
         ]
         end

         to place-fans
         set row ( gap * 2 ) + half2
         set col gap + half
         set x-cor 0
         set y-cor 0

         while [ x-cor <= ( gap * no-of-row-or-col ) ]
         [
          ifelse (x-cor = row)[
          set col gap + half
           set y-cor 0
           while [ y-cor <= ( gap * no-of-row ) ]
            [
          ifelse (y-cor = col)[
        create-fans 1 [
        set shape "x" ;; x shape
        set size 1
        set color red

        setxy row col
        set number-of-fans number-of-fans + 1
        show (word row "," col )
      ]
      set col col + ( gap * 2)
       set y-cor y-cor + 1
       ]
        [set y-cor y-cor + 1]
         ]
         set row row + ( gap * 2)
         set x-cor x-cor + 1
          ]
          [set x-cor x-cor + 1]
            ]
          end

         to place-acs
         set row 3
         set col 13
         set x-cor 0
         set y-cor 0

          while [ y-cor <= 45 ]
             [
          ifelse (y-cor = col)[
          create-acs 1 [
         set shape "star" ;; star shape
         set size 1
         set color red

        setxy row col
        set number-of-acs number-of-acs + 1
        show (word row "," col )
          ]
        set col col + 10
         set y-cor y-cor + 1
         ]
         [set y-cor y-cor + 1]
           ]

         end
        to go
         set simulation-timer 0                              

         output-show (word "timer = "simulation-timer )    
         tick

          move-students
          while [simulation-timer < time ] [
         set simulation-timer simulation-timer + 1                       
         output-show (word "timer = "simulation-timer )
           ]
          end





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

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

         to move-students                                               
         let s sort [who] of seats
         let a first s
         let l length s
         while [ l > (number-of-seats - number-of-students )] [       
         set temp1 simulation-timer
          tick
           tick
            ask students [ if ( entry-time = temp1 )                   
            [
            move-to seat a                                          ; If it does the student moves to a seat
   set color red
    appliance-on
    energy-calculation
    show (word temp1 "," l "," a)
    set s remove a s
    set a a + 1
    set l length s

      ]
       ]
      set simulation-timer simulation-timer + 1                      
     output-show (word "timer = "simulation-timer )

      ]
       end

      to appliance-on
      ask students [ ask lights in-radius 4
      [ set color green ]]
        ask students [ ask fans in-radius 4
       [ set color green ]]
      ask students [ ask acs in-radius 9
        [ set color green ]]
        stop

         end

        to energy-calculation

         ask lights [ ifelse ( color = green ) [ set l-energy ( light- 
         wattage * (time - temp1 )) ] [ set l-energy 0 ] ]
         ask fans [ ifelse ( color = green ) [ set f-energy ( fan-wattage 
          * ( time - temp1 )) ] [ set f-energy 0 ] ]
          ask acs [ ifelse ( color = green ) [ set a-energy (ac-wattage * 
          (time - temp1 ))] [ 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 / 60 )
           set t-fan (fan-e / 60 )
           set t-ac (ac-e / 60 )
           show (word "total-ac-time = " t-ac )

            set t-energy ( t-light + t-fan + t-ac )

             end

在 BehaviorSpace:使用这些报告器进行测量运行时,我正在计算能量,但在电子表格中,一切都显示为零。为什么会这样?当我在监视器中看到能量计算时,它会显示一个值。我想要做的是用不同的学生号多次运行这段代码,每次都得到不同的能量计算。或者我应该在这种情况下使用 .csv 中的文件保存?

4

1 回答 1

1

您已将其编写energy-calculation为设置全局变量的命令,t-energy而不是t-energy向调用者报告的报告。我怀疑在您的监视器中,您使用了t-energy每次energy-calculation调用时都会重置的变量。但在 BehaviorSpace 中,衡量跑步的记者实际上必须是一名记者。它必须向 BehaviorSpace 返回一个值。这很容易通过重写energy-calculation

to-report energy-calculation

  ask lights [ ifelse ( color = green ) [ set l-energy ( light- 
    wattage * (time - temp1 )) ] [ set l-energy 0 ] ]
  ask fans [ ifelse ( color = green ) [ set f-energy ( fan-wattage 
    * ( time - temp1 )) ] [ set f-energy 0 ] ]
  ask acs [ ifelse ( color = green ) [ set a-energy (ac-wattage * 
    (time - temp1 ))] [ 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 / 60 )
  set t-fan (fan-e / 60 )
  set t-ac (ac-e / 60 )
  show (word "total-ac-time = " t-ac )

  set t-energy ( t-light + t-fan + t-ac )

  report t-energy

end

您是否仍然需要全局t-energy变量或者可以简单地用报告其值的报告器替换它,将取决于代码中如何使用 t-energy。

但是,实际上我很惊讶 BehaviorSpace 实验试图运行。BehaviorSpace 应该捕获energy-calculation不是报告者并抛出错误。

于 2020-03-06T15:09:06.773 回答