Code: Difference between revisions

From Control Systems Technology Group
Jump to navigation Jump to search
No edit summary
No edit summary
Line 3: Line 3:
== Sleep Model ==
== Sleep Model ==
   globals [y
   globals [y
        Tgem
          Tgem
        start
          start
        T
          T
        p
          p
        rc
          rc
        x
          x
        R
          R
        time
          time
        stage
          stage
        test]
          test]
 
 
   to Setup
   to Setup
  clear-all
    clear-all
  set y 100
    set y 100
  set Tgem (90 * 60)
    set Tgem (90 * 60)
  reset-ticks
    reset-ticks
   end
   end
 
 
   to Go
   to Go
  foreach [1 2] [
    foreach [1 2] [
    set start y
      set start y
    set T -1
      set T -1
    while [T < 0] [set T (random-normal Tgem 1800)]
      while [T < 0] [set T (random-normal Tgem 1800)]
    set p (random-float 1.0)
      set p (random-float 1.0)
    set rc (4 / (1 + exp((ticks - (2.5 * Tgem)) / 20000)) - 2)
      set rc (4 / (1 + exp((ticks - (2.5 * Tgem)) / 20000)) - 2)
    ifelse rc > 0
      ifelse rc > 0
      [set x (0.5 - (1 / rc) + sqrt((2.0 / rc) * p + (rc ^ -2) - (rc ^ -1) + 0.25))]
        [set x (0.5 - (1 / rc) + sqrt((2.0 / rc) * p + (rc ^ -2) - (rc ^ -1) + 0.25))]
      [set x (0.5 - (1 / rc) - sqrt((2.0 / rc) * p + (rc ^ -2) - (rc ^ -1) + 0.25))]
        [set x (0.5 - (1 / rc) - sqrt((2.0 / rc) * p + (rc ^ -2) - (rc ^ -1) + 0.25))]
    ifelse ? = 1
      ifelse ? = 1
      [set R (x * start / 2)]
        [set R (x * start / 2)]
      [set R ((x - 1) * (100 - start) / 2)]
        [set R ((x - 1) * (100 - start) / 2)]
    set time (n-values (T / 2) [?])
      set time (n-values (T / 2) [?])
    foreach time [
      foreach time [
      set y (R * (cos (360 * ? / T)) + start - R)
        set y (R * (cos (360 * ? / T)) + start - R)
      set stage ((y - (y mod 25)) / 25 - 3)
        set stage ((y - (y mod 25)) / 25 - 3)
      set test (1 / (1 + exp(ticks)))
        set test (1 / (1 + exp(ticks)))
       tick
        tick
       ]
     ]
     ]
  ]
   end
   end

Revision as of 23:35, 27 February 2016

Room Brightness Control

Temperature Control

Sleep Model

 globals [y
          Tgem
          start
          T
          p
          rc
          x
          R
          time
          stage
          test]
 
 to Setup
   clear-all
   set y 100
   set Tgem (90 * 60)
   reset-ticks
 end
 
 to Go
   foreach [1 2] [
     set start y
     set T -1
     while [T < 0] [set T (random-normal Tgem 1800)]
     set p (random-float 1.0)
     set rc (4 / (1 + exp((ticks - (2.5 * Tgem)) / 20000)) - 2)
     ifelse rc > 0
       [set x (0.5 - (1 / rc) + sqrt((2.0 / rc) * p + (rc ^ -2) - (rc ^ -1) + 0.25))]
       [set x (0.5 - (1 / rc) - sqrt((2.0 / rc) * p + (rc ^ -2) - (rc ^ -1) + 0.25))]
     ifelse ? = 1
       [set R (x * start / 2)]
       [set R ((x - 1) * (100 - start) / 2)]
     set time (n-values (T / 2) [?])
     foreach time [
       set y (R * (cos (360 * ? / T)) + start - R)
       set stage ((y - (y mod 25)) / 25 - 3)
       set test (1 / (1 + exp(ticks)))
       tick
     ]
   ]
 end