Loading ...
Sorry, an error occurred while loading the content.

Expand Messages
  • aprilia hestiani
    hello, I have a NetLogo model created in 4.0.3 that I need to update to be compatible with 5.0.3. This is a model of beer game. I have moved the plotting
    Message 1 of 1 , Feb 13, 2013
    • 0 Attachment
      hello,
      I have a NetLogo model created in 4.0.3 that I need to update to be compatible with 5.0.3. This is a model of beer game. I have moved the plotting information to the appropriate plot edit dialogs and changed the clear-all and reset-ticks commands as suggested by the transition guide. When I try to run the model, I get an error message.

      Can anyone help me with this? 
      Thank you,


      Here is the original code, plot commands included:

      breed [ customer ]
      breed [ orders ]
      breed [ biz ]
      breed [ stockroom ]
      breed [ text ]

      globals [ticks order0 orderN tickN stock0 stockCost backorderCost Parallel? FactoryFirst? custDemand]
      biz-own [stock backorders supply demand received ordered pending lastExpected lastDemand totCost lastPhase]
      ;              +---------+   (pending)-     Biz: Order of creation reversed when FactoryFirst? true
      ;    supply <  |         |  < received |    pos   0   1   2   3   (R W D F)
      ;    demand >  |         |  > ordered  |    who   0   1   2   3   FactoryFirst? false
      ;              +---------+            -     who   3   2   1   0   FactoryFirst? true

      to setup-globals
        set-default-shape biz "house"          set-default-shape orders "barn"
        set-default-shape stockroom "rect"     set-default-shape customer "person"
        set order0 4       set stock0 12       set orderN 8        set tickN 4
        set ticks 0        set stockCost .50   set backorderCost 2.00
        set Parallel? member? "||" PlayStyle   set FactoryFirst? member? "Factory" PlayStyle
        if StopAt > 0 [foreach ["inventory" "cost" "orders"] [set-current-plot ? set-plot-x-range 0 StopAt]]
      end
      to setup
        ca
        setup-globals
        setup-biz
        setup-customer
        setup-stockrooms
        setup-patches
        setup-orders
        ask turtles [set label-color black]
      end
      to setup-biz
        cct-biz 4 [
          ifelse FactoryFirst? [setxy (9 - who * 6) 0] [setxy (-9 + who * 6) 0] ;(bizx0 +/- who * bizdx) 0
          set size 5         set color item pos who [gray lime sky red]
          set totCost 0      set stock stock0    set backorders 0    set lastExpected order0    set lastDemand order0
          ifelse Parallel? and not factory? [set pending order0 * 4] [set pending order0 * 3]
          create-label item pos who [["Retailer" .4] ["Wholesaler" .9] ["Distributor" .9] ["Factory" .4]]
          set lastPhase phase
        ]
      end
      to setup-stockrooms
        ask biz [
          hatch 1 [
            set breed stockroom    setxy xcor ycor - 3
            ask myself [update-stockroom]  ]   ]
      end
      to setup-patches
        ask patches [set pcolor gray + 4]
        (foreach [2 2 -2 -2] [1 -1 1 -1] [ask biz[ask patch-at ?1 ?2 [set pcolor gray]]])
        ask factory [ask patch-at 3 0 [set pcolor gray]]
      end
      to setup-orders
        (foreach [2 2 -2 -2] [1 -1 1 -1] [ask biz[setup-order order0 ?1 ?2]])
        ask factory [setup-order order0 3 0]
        ask retailer [ask order -2 1 [die] ask order -2 -1 [die]]
        if not Parallel? [
          ifelse FactoryFirst?
            [ask biz [if not retailer? [ask order -2  1 [die]]]]
            [ask biz [if not factory?  [ask order  2 -1 [die]]]]
        ]
      end
      to setup-order [quantity deltax deltay]
        setup-colored-order quantity deltax deltay yellow
      end
      to setup-customer
        ask retailer [
          hatch 1 [
            set breed customer setxy xcor - 4 ycor
            set size 2         set color gray      set label ""  ]  ]
      end

      ; Simulation action
      to go
        set ticks ticks + 1
        ask customer [process-customer]
        ifelse Parallel?
          [ask biz [process-player]]  [foreach [0 1 2 3] [ask turtle ? [process-player]]]
        plot-inventory
        plot-cost
        plot-orders
        plot-phase
        if ticks = StopAt [stop]
      end

      ; Ordering proceedures
      to process-player
          if OrderFirst? [calculate-ordered]
          refresh-stock
          process-demand
          if not OrderFirst? [calculate-ordered]
          place-orders
          set totCost totCost + cost      ; total cost for this turtle
      end
      to process-customer
        if ticks > 1 [ask order 2 1 [setxyrel -2 -2]]
        calculate-customer-demand
        setup-order ifelse-value (ticks > tickN) [custDemand] [order0] 2 -1
      end
      to refresh-stock
        ask order 2 1 [set received-of myself label setxyrel -2 0] ;killorder]
        ifelse factory?
          [ask order 3 0 [setxyrel -1 1] ask order 2 -1 [setxyrel 1 1]]
          [ask order 4 1 [setxyrel -2 0]]
        set pending pending - received
        set stock stock + received
        update-stockroom
      end
      to process-demand
        ask order -2 -1 [set demand-of myself label setxyrel 2 0] ;killorder]
        if order -4 -1 != nobody [ask order -4 -1 [setxyrel 2 0]]
        set backorders backorders + demand
        set supply min list stock backorders
        set stock stock - supply
        set backorders backorders - supply
        update-stockroom
        ifelse backorders = 0 [setup-order supply -2 1] [setup-colored-order supply -2 1 red]
      end
      to place-orders
        setup-order ordered 2 -1
        set pending pending + ordered
      end

      ; customer demand calculation
      to calculate-customer-demand
        set custDemand ifelse-value (ticks > tickN) [runresult ("calculate-" + DemandStyle)] [order0]
      end
      to-report calculate-Step    report orderN  end
      to-report calculate-Square  report orderN * (floor ((ticks - tickN) / 26) mod 2) end
      to-report calculate-Sine    report round ((orderN / 2) * (1 + sin (360 * (ticks - tickN) / 52))) end
      to-report calculate-Random  report random (orderN + 1) end

      ; "ordered" calculation
      to calculate-ordered
        set ordered ifelse-value (ticks > tickN) [max list 0 runresult ("calculate-" + OrderStyle)] [order0]
      end
      to-report calculate-StockGoal report stock0 + order0 - inventory - round (pending / 3) end
      to-report calculate-Customer  report demand-of retailer end; REMIND: fix .. ask the customer
      to-report calculate-Sterman
        locals [expected indicated]
        ifelse Visibility 
          [set expected ifelse-value OrderFirst? [label-of order -2 -1][demand]] 
          [set expected theta * lastDemand + (1 - theta) * lastExpected]
        set indicated expected + alpha * (Q - inventory - beta * pending)
        set lastDemand demand
        set lastExpected max list 0 round expected
        report round indicated
      end

      ; Plotting
      to plot-inventory
        set-current-plot "inventory"
        (foreach ["R" "W" "D" "F"] [0 1 2 3] [set-current-plot-pen ?1 ask turtle pos ?2 [plot inventory]])
        set-current-plot-pen "0" plot 0
      end
      to plot-cost
        set-current-plot "cost"
        (foreach ["R" "W" "D" "F"] [0 1 2 3] [set-current-plot-pen ?1 
          ask turtle pos ?2 [plot ifelse-value TotalCost? [totCost] [cost] ]])
      end
      to plot-orders
        set-current-plot "orders"
        (foreach ["R" "W" "D" "F"] [0 1 2 3] [set-current-plot-pen ?1 plot ordered-of turtle pos ?2])
        set-current-plot-pen "C" ask retailer [plot demand]
      end
      to plot-phase
        set-current-plot "PhasePlot"
        (foreach ["R" "W" "D" "F"] [0 1 2 3] 
        [set-current-plot-pen ?1 ask turtle pos ?2[plotxy phase lastPhase set lastPhase phase]])
      end

      ; Biz Utilities
      to-report retailer?      report self = retailer end
      to-report retailer       report turtle ifelse-value FactoryFirst? [3][0] end
      to-report factory?       report self = factory end
      to-report factory        report turtle ifelse-value FactoryFirst? [0][3] end
      to-report pos [i]        report ifelse-value FactoryFirst? [3 - i][i] end
      to-report inventory      report stock - backorders end
      to-report cost           report (stock * stockCost) + (backorders * backorderCost) end
      to-report phase          report run-result phaseVariable end
      to update-stockroom
        locals [sr]
        set sr one-of stockroom-at 0 -3
        set label-of sr inventory    set color-of sr ifelse-value (inventory < 0) [red][yellow]
      end
      to create-label [l]
        hatch 1 [
          set breed text     set shape "rect"    set size 1
          setxy xcor + item 1 l ycor             set label item 0 l  ]
      end

      ; Order Utilities
      to setup-colored-order [quantity deltax deltay ocolor]
        locals [neworder]
        set neworder order 0 deltay
        if neworder = nobody [
          hatch 1 [
            set neworder self  set breed orders    set size 1
            set ycor ycor + deltay ] ];if ticks > 0 [show who]  ]
        ask neworder [
          set color ocolor
          set label quantity
          setxyrel deltax 0  ]
      end
      to setxyrel [deltax deltay]
        if slowMo? and ticks > 0 [without-interruption [wait 0.25]]
        setxy xcor + deltax ycor + deltay
        set heading 90 - (ycor + 1) * 90
      end
      to-report order [deltax deltay]
        report one-of orders-at deltax deltay
      end

      ; Misc utilities
      to-report TotalCost report reduce [?1 + ?2] values-from biz [totCost] end


    Your message has been successfully submitted and would be delivered to recipients shortly.