BehaviorSpace Output - PullRequest
       34

BehaviorSpace Output

0 голосов
/ 01 марта 2020

Я моделирую классную комнату, чтобы найти общее потребление энергии от приборов классной комнаты. Теперь я хочу запустить симуляцию в 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: мера выполняется с использованием этих репортеров I Я ставлю расчет энергии, но в таблице все показывает ноль. Почему это происходит? Когда я вижу расчет энергии в мониторе, он показывает значение. Что я хочу сделать, так это запустить этот код несколько раз с разными номерами учеников и каждый раз получать различные расчеты энергии. Или я должен использовать сохранение файла в .csv для этой ситуации?

Любое предложение будет очень полезно! Спасибо.

1 Ответ

1 голос
/ 06 марта 2020

Вы написали 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 или вы можете просто заменить его репортером, который сообщает о его значении, будет зависеть от того, как иначе энергия используется в коде.

Но я на самом деле удивлен, что эксперимент BehaviorSpace вообще пытается запустить. BehaviorSpace должен поймать, что energy-calculation не является репортером, и выдать ошибку.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...