extensions [table]

globals 
 [axioms 
  targets 
  dummy-vars 
  poss-vars 
  connectives    ;; table from string -> arity
  m-connectives  ;; all connectives with non-zero arity
  var-table
  published      ;; table from fmla -> number times cited
  index-table    ;; table from fmla -> [journal year]
  found 
  secs-per-tick 
  current-fmla 
  ]

breed [researchers researcher]
breed [journals journal]

researchers-own [beliefs techniques num-published num-found source-table derivation-table reference-table]
journals-own [publish-table citation-table submissions]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; The procedure to initialise the simulation ;;
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to setup 
  clear-all ;; this clears everything at the start - a clean slate
  init-variables
  set connectives table:make 
  foreach connectives-list [table:put connectives first ? second ?]
  set m-connectives map [first ?1] filter [second ?1 > 0] table:to-list connectives
  foreach poss-vars [table:put connectives first ? 0]
  ;; standarise axiom list
  set axioms map [standardise ?] axiom-list
  set published table:make
  foreach axioms [
    if check-fmla? [check-fmla ?]
    table:put published ? 0
  ]
  set index-table table:make
  foreach axioms [table:put index-table ? list nobody 0]
  set found []
  
  ;; standardise target list and set (0, infinity) value and put in targets table
  set targets table:make
  foreach target-list [
    if check-fmla? [check-fmla ?]
    table:put targets standardise ? floor (1 / (1 - random-float 1))
  ]
  
  ;; create researchers
  if debug? [show (word "Start creating researchers")]
  create-researchers num-researchers [
    set beliefs n-of-list max-beliefs axioms
    set techniques n-of-list max-techniques axioms
    set num-published 0
    set num-found 0
    set source-table table:make ;; table of fmla -> kind ("axiom"/"deduction"/"journal")
    foreach beliefs [table:put source-table ? "axiom"]
    set derivation-table table:make ;; table of fmla -> list of fmlas used to deduce it
    set reference-table table:make ;; table of fmla -> [journal-name tick]
    set shape "face neutral"
    set size 0.5
    st
    setxy random-float max-pxcor 0.25 + random-float 2.5
  ]
  
  ;; create journals
  if debug? [show (word "Start creating journals")]
  create-journals num-journals [
    set publish-table table:make   ;; table of tick -> list of published at that tick
    set citation-table table:make  ;; table of item published -> references
    set shape "square"
    setxy random-float max-pxcor 4
  ]
  
  reset-ticks                            ;; this initialises the simulation time system and graphs
  set secs-per-tick 0
  reset-timer
  if debug? [show (word "Setup finished")]
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Next we have the procedure to progress the simulation one time step
;; this is executed when one presses the "step" button or repeatedly
;; if one presses the "go" button

to go
  let minor []  let major []  let conclusion []  let submit-list []  let chosen-fmla [] let found-one? false
  ask journals [set submissions []]

  ask researchers [
    if check-fmla? [foreach beliefs [check-fmla ?]]
    ;; researchers make deductions
    if debug? [show (word "Start making deductions")]
    repeat work-rate [
      set minor random-from beliefs
      set major random-from techniques
      set conclusion standardise mp minor major
      if not empty? conclusion [
        if check-fmla? [check-fmla conclusion]
        if not member? conclusion beliefs [
          set beliefs fput conclusion beliefs
          if not member? conclusion table:keys source-table [
            if debug? [show (word "MP successful, storing: " conclusion)]
            table:put source-table conclusion "deduction"
            table:put derivation-table conclusion list minor major
          ]
        ]
      ]
    ]

    ;; submit to journal
    if debug? [show (word "Journal Submissions")]
    set submit-list shuffle beliefs
    set found-one? false
    while [not empty? submit-list and not found-one?] [
      set chosen-fmla first submit-list
      set submit-list but-first submit-list
      if not member? chosen-fmla table:keys published [
        submit-to one-of journals chosen-fmla
        set found-one? true
      ]
    ]
  ]
  
  ;; now journals publish
  if debug? [show (word "Journals consider submissions and publish")]
  let sofar-published 0 let chosen-submission [] let author nobody let citation-list []
  ask journals [
    table:put publish-table ticks []
    set submissions rank submissions
    if debug? [show (word "Current submissions to: " self " " submissions)]
    while [not empty? submissions and sofar-published < num-publish] [
      set chosen-submission first submissions
      set submissions but-first submissions
      set chosen-fmla first chosen-submission
      if check-fmla? [check-fmla chosen-fmla]
      set author second chosen-submission
      if not empty? chosen-fmla and not member? chosen-fmla table:keys citation-table [
        ;; publish it
        table:put publish-table ticks (fput chosen-fmla table:get publish-table ticks)
        set citation-list citation-list-from chosen-fmla author
        table:put citation-table chosen-fmla citation-list
        foreach citation-list [
          table:put published ? (table:get published ?) + 1
        ]
        table:put published chosen-fmla 0
        table:put index-table chosen-fmla list self ticks
        ask author [set num-published num-published + 1 set size 1.02 * size]
        ;; if on target-list
        if is-target? chosen-fmla and not member? chosen-fmla found [
          output-print (word ticks ": " author " found: " chosen-fmla)
          set found fput chosen-fmla found
          ask author [set num-found num-found + 1 set shape "face happy"]
        ]
      ]
    ]
  ]
  
  ;; collate all recently published stuff
  if debug? [show (word "Current published fmal")]
  set current-fmla []
  
  ask journals [
    ;; does not currently include citation information - fmla, journal, age
    set current-fmla fmanyput current-fmla join-lists expand-first map [(list (second ?) self (ticks - first ?))] table:to-list publish-table 
  ]
  if debug? [show (word "Current published fmal are: " current-fmla)]

  ;; researchers now read from recently published stuff, then get rid of excesses
  if debug? [show (word "Reading by researchers")]
  let promote-list []
  ask researchers [
     read-articles
     ;; maybe promote a belief to a technique
     if debug? [show (word "Maybe promote belief to technique")]
     if prob innovate-technique-prob [
       set promote-list remove-list beliefs techniques
       if not empty? promote-list
          [set techniques fput random-from promote-list techniques]
     ]
     ;; drop a belief or a technique if too many
     if debug? [show (word "Drop excess beliefs and techniques")]
     if length beliefs > max-beliefs 
       [set beliefs n-of-list max-beliefs axioms]
     if length techniques > max-techniques 
       [set techniques n-of-list max-techniques axioms]
  ]
  
  if max-time > 0 and ticks >= max-time [stop]
  tick 
  set secs-per-tick timer
  reset-timer
end

;; process a list of lists: each being a list first with a set of constants
to-report expand-first [lstoflsts]
  if empty? lstoflsts [report []]
  let expanded-first-item expand-first-item first lstoflsts
  ifelse empty? expanded-first-item
    [report expand-first but-first lstoflsts]
    [report fput expanded-first-item expand-first but-first lstoflsts]
end

;; make a list of lists by taking each of first in list in turn and appending it to the rest 
to-report expand-first-item [explst]
  if empty? explst [report []]
  let firstlst first explst
  if empty? firstlst [report []]
  report fput (fput first firstlst but-first explst) expand-first-item (fput but-first firstlst but-first explst)
end

;; what happens when a researcher submits to a journal: fmla author
to submit-to [jrnl fmla]
  if debug? [show (word "Calling: submit-to: " jrnl " " fmla)]
  if check-fmla? [check-fmla fmla]
  ask jrnl [
    set submissions fput list fmla myself submissions
  ]  
end

;; the algorithm for a journal to sort submission list into best first
to-report rank [pairlst]
  if debug? [show (word "Calling: rank: " pairlst)]
  if ranking-method = "random" [
    report shuffle pairlst
  ]
  if ranking-method = "shortest" [
    report sort-by [length flatten first ?1 < length flatten first ?2] pairlst
  ]
  if ranking-method = "fewest variables" [
    report sort-by [length vars-in first ?1 < length vars-in first ?2] pairlst
  ]
end

;; to extract citation list for a published formula
to-report citation-list-from [fmla rsrchr]
  if debug? [show (word "Calling: citation-list-from: " fmla " " rsrchr)]
  let results []
  ask rsrchr [
    set results find-citations-of fmla
  ]
  if debug? [show (word "Results from: citation-list-from: " fmla " " rsrchr " are: " results)]
  report results 
end

;; reports a list of (non-axiomatic) fmla used in a fmla's derivation
;; note: does not indicate which journals it is from ATM
to-report find-citations-of [fmla]
  if debug? [show (word "Calling: find-citations-of: " fmla)]
  if empty? fmla [report []]
  let fmla-type table:get source-table fmla
  if debug? [show (word "table:get source-table of: " fmla " gives result: " fmla-type)]
  if fmla-type = "axiom" [report []]
  if fmla-type = "journal" [report (list fmla)]
  if fmla-type = "deduction" [
    report join-lists map [find-citations-of ?] table:get derivation-table fmla 
  ]
  if not member? fmla-type ["axiom" "journal" "deduction"] [error (word fmla " is not of type axiom/journal/deduction!")]
  report []
end

;; reading articles
to read-articles
  let selected-reading [] let fmla-list [] let score-list [] let pair-list []
  ;; first ? = fmla, second ? = journal, third ? = age
  if reading-method = "only recent" [
    set selected-reading n-of-list num-read filter [not member? ? beliefs and not member? ? techniques] filter [third ? = 0] current-fmla
  ]
  if reading-method = "random" [
    set selected-reading n-of-list num-read filter [not member? ? beliefs and not member? ? techniques] current-fmla
  ]
  ;; select with a bias towards recent articles but a mix of others
  if reading-method = "recent bias" [
    let target-age 0
    let num-done 0
    let itm-found? false
    let year-list []
    repeat num-read [
      while [target-age < ticks and not itm-found?] [
        ifelse prob 0.5 [
          set target-age target-age + 1 
        ] [
          set year-list filter [not member? ? beliefs and not member? ? techniques] filter [third ? = target-age] current-fmla
          ifelse empty? year-list [
            set target-age target-age + 1
          ] [
            set selected-reading fput (random-from year-list) selected-reading
            set itm-found? true
          ]
        ]
      ]
    ]
  ]
  if reading-method = "cited bias" [
    set pair-list sort-by [second ?1 > second ?2] table:to-list published
    set fmla-list map [first ?] pair-list
    set score-list map [1 + second ?] pair-list
    let num-done 0
    repeat num-read [
       set selected-reading fput (item chooseProbilistically score-list fmla-list) selected-reading
    ]
    set selected-reading map [fput ? table:get index-table ?] selected-reading
  ]
  if reading-method = "shortest bias" [
    (error "Shortest bias ranking not yet implemented!")
  ]
  if reading-method = "fewest vars bias" [
    (error "Fewest vars bias ranking not yet implemented!")
  ]
  if debug? [show (word "selected reading is: " selected-reading)]
  foreach selected-reading [
      ;; add formula to beliefs
      if check-fmla? [check-fmla first ?]
      set beliefs fput first ? beliefs
      table:put source-table first ? "journal"
      table:put reference-table first ? list second ? third ?
  ]
end

to-report is-target? [fmla]
;;  member? stadardise fmla targets
  let found? false
  let targets-copy table:keys targets
  while [not empty? targets-copy and not is-instance-of? first targets-copy fmla] 
    [set targets-copy but-first targets-copy]
  report not empty? targets-copy
end

to i [nm]
  inspect researcher nm
end

to rr [nm]
  ask researcher nm [
    show (word "beliefs: " beliefs)
    show (word "bechniques: " techniques)
    show (word "source-table: " table:to-list source-table)
    show (word "derivation-table: " table:to-list derivation-table)
    show (word "reference-table: " table:to-list reference-table)
  ]
end

to rj [nm]
  ask journal nm [
    show (word "submissions: " submissions)
    show (word "publish-table: " table:to-list publish-table)
    show (word "citation-table: " table:to-list citation-table)
  ] 
end

to rh
  show [list length beliefs length techniques] of researchers
end  

;;;;;;;;;;;;;;;;;;;;;;
;;; specify logic ;;;;
;;;;;;;;;;;;;;;;;;;;;;
to A-LOGIC-SETUP end

to init-variables
  set poss-vars ["A" "B" "C" "D" "E" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R"]  ;; note T and F are primitives, not variables
  set dummy-vars ["Z1" "Z2" "Z3" "Z4" "Z5" "Z6" "Z7" "Z8" "Z9" "Z10" "Z11" "Z12" "Z13" "Z14" "Z15" "Z16" "Z17"]
end

to-report connectives-list
  report (list
     ["T" 0]
     ["F" 0]
     ["~" 1]
     ["->" 2]
     ["&" 2]
     ["v" 2]
     ["<->" 2]
  )
end

to-report axiom-list
  report (list
    ["v" "A" ["~" "A"]]
    ["->" "A" "A"]
    ["->" "A" ["->" "B" "A"]]
    ["->" ["->" "A" ["->" "A" "B"]] ["->" "A" "B"]]
    ["->" ["->" "A" ["->" "B" "C"]] ["->" "B" ["->" "A" "C"]]]
    ["->" ["->" "A" "B"] ["->" ["->" "B" "C"] ["->" "A" "C"]]]
    ["->" ["&" "A" "B"] "A"]
    ["->" ["&" "A" "B"] "B"]
    ["->" ["->" "A" "B"] ["->" ["->" "A" "C"] ["->" "A" ["&" "B" "C"]]]]
    ["->" "A" ["v" "A" "B"]]
    ["->" "A" ["v" "B" "A"]]
    ["->" ["->" "A" "B"] ["->" ["->" "C" "B"] ["->" ["v" "A" "C"] "B"]]]
    ["->" ["->" "A" "B"] ["->" ["->" "A" ["~" "B"]] ["~" "A"]]]
    ["->" ["~" "A"] ["->" "A" "B"]]
    ["->" ["&" ["->" "A" "B"] ["->" "B" "A"]] ["<->" "A" "B"]]
    ["->" ["<->" "A" "B"] ["&" ["->" "A" "B"] ["->" "B" "A"]]]
    ["<->" ["v" "A" ["~" "A"]] ["T"]]
    ["<->" ["~" "F"] ["T"]]
  )
end
    
to-report target-list
  report (list
    ["<->" ["&" ["&" "A" "B"] "C"] ["&" "A" ["&" "B" "C"]]]
    ["->" ["->" "A" ["&" "B" "C"]] ["&" ["->" "A" "B"] ["->" "A" "C"]]]
    ["<->" [ "v" ["&" "A" "B"]"C"] ["v" ["&" "A" "B"] ["&" "A" "C"]]]
    ["<->" ["&" ["->" "A" "B"] "C"] ["->" "A" ["&" "B" "C"]]]
    ["<->" ["&" ["~" "A"] "A"] ["F"]]
    ["<->" ["&" ["v" "B" "C"] "A"] ["v" ["&" "B" "A"] ["&" "C" "A"]]]
    ["<->" ["&" "A" ["&" "A" "B"]] ["&" "A" "B"]]
    ["<->" ["&" "A" ["&" "B" "C"]] ["&" "B" ["&" "A" "C"]]]
    ["<->" ["&" "A" ["~" "A"]] ["F"]]
    ["<->" ["&" "A" ["v" "B" "C"]] ["v" ["&" "A" "B"] ["&" "A" "C"]]]
    ["<->" ["&" "A" "A"] "A"]
    ["<->" ["&" "A" "B"] ["&" "B" "A"]]
    ["<->" ["&" "A" ["F"]] ["F"]]
    ["<->" ["&" "A" ["F"]] ["F"]]
    ["<->" ["&" "A" ["T"]] "A"]
    ["<->" ["&" ["F"] "A"] ["F"]]
    ["<->" ["&" ["T"] "A"] "A"]
    ["<->" ["&" ["v" "A" "B"] "C"] ["v" ["&" "A" "C"] ["&" "B" "C"]]]
    ["<->" ["<->" ["<->" "A" "B"] "C"] ["<->" "A" ["<->" "B" "C"]]]
    ["<->" ["<->" ["->" "A" "B"] ["->" "A" "C"]] ["->" "A" ["<->" "B" "C"]]]
    ["<->" ["<->" ["->" "A" "C"] ["->" "B" "C"]] ["v" [ "<->" "A" "B"] "C"]]
    ["<->" ["<->" ["~" "A"] ["~" "B"]] ["<->" "A" "B"]]
    ["<->" ["<->" "A" "B"] ["&" ["v" "B" ["~" "A"]] ["v" ["~" "B"] "A"]]]
    ["<->" ["<->" "A" "B"] ["<->" "B" "A"]]
    ["<->" ["<->" "A" ["F"]] ["~" "A"]]
    ["<->" ["<->" "A" ["T"]] "A"]
    ["<->" ["<->" ["F"] "A"] ["~" "A"]]
    ["<->" ["->" ["&" "A" "B"] "C"] ["->" "A" ["->" "B" "C"]]]
    ["<->" ["->" ["~" "A"] "A"] "A"]
    ["<->" ["->" ["v" "A" "B"] "C"] ["v" ["->" "A" "C"] ["->" "B" "C"]]]
    ["<->" ["->" "A" ["~" "A"]] ["~" "A"]]
    ["<->" ["->" "A" "A"] ["T"]]
    ["<->" ["->" "A" "B"] ["->" ["~" "B"] ["~" "A"]]]
    ["<->" ["->" "A" "B"] ["v" ["~" "A"] "B"]]
    ["<->" ["->" "A" ["F"]] ["~" "A"]]
    ["<->" ["->" "A" ["T"]] ["T"]]
    ["<->" ["->" ["F"] "A"] ["T"]]
    ["<->" ["->" ["T"] "A"] "A"]
    ["<->" ["~" ["&" "A" "B"]] ["v" ["~" "A"] ["~" "B"]]]
    ["<->" ["~" ["<->" "A" "B"]] ["<->" "A" ["~" "B"]]]
    ["<->" ["~" ["->" "A" "B"]] ["&" "A" ["~" "B"]]]
    ["<->" ["~" ["~" "A"]] "A"]
    ["<->" ["~" ["v" "A" "B"]] ["&" ["~" "A"] ["~" "B"]]]
    ["<->" ["~" ["F"]] ["T"]]
    ["<->" ["~" ["T"]] ["F"]]
    ["<->" ["v" ["&" "A" "B"] "C"] ["&" ["v" "A" "C"] ["v" "B" "C"]]]
    ["<->" ["v" ["->" "A" "B"] "C"] [ "->" "A"["v" "B" "C"]]]
    ["<->" ["v" ["~" "A"] "B"] ["->" "A" "B"]]
    ["<->" ["v" ["v" "A" "B"] "C"] ["v" "A" ["v" "B" "C"]]]
    ["<->" ["v" "A" ["&" "B" "C"]] ["&" ["v" "A" "B"] ["v" "A" "C"]]]
    ["<->" ["v" "A" ["v" "A" "B"]] ["v" "A" "B"]]
    ["<->" ["v" "A" ["v" "B" "C"]] ["v" "B" ["v" "A" "C"]]]
    ["<->" ["v" "A" "A"] "A"]
    ["<->" ["v" "A" "B"] ["v" "B" "A"]]
    ["<->" ["v" "A" ["F"]] "A"]
    ["<->" ["v" "A" ["T"]] ["T"]]
    ["<->" ["v" "B" ["->" "A" "C"]] ["->" "A" ["v" "B" "C"]]]
    ["<->" ["v" ["F"] "A"] "A"]
    ["<->" ["v" ["T"] "A"] ["T"]]
    ["<->" "A" "A"]
    ["->" ["->" ["->" "A" "A"] "A"] "A"]
    ["->" ["->" ["->" "A" "A"] "B"] "B"]
    ["->" ["->" ["->" "A" "B"] ["->" "B" "C"]] ["->" "A" "C"]]
    ["->" ["->" ["->" "A" "B"] ["->" "C" "A"]] ["->" "C" "B"]]
    ["->" ["->" ["->" "A" "B"] "A"] "A"]
    ["->" ["->" ["->" "A" "C"] ["->" "B" "C"]] ["->" "A" ["->" "B" "C"]]]
    ["->" ["->" ["~" "A"] ["~" "B"]] ["->" "B" "A"]]
    ["->" ["->" ["~" "A"] "A"] "A"]
    ["->" ["->" ["~" "A"] "B"] ["->" ["~" "B"] "A"]]
    ["->" ["->" "A" ["->" ["->" "B" "C"] "D"]] ["->" ["->" "B" "C"] ["->" "A" "D"]]]
    ["->" ["->" "A" ["->" "A" "B"]] ["->" "A" "B"]]
    ["->" ["->" "A" ["->" "B" ["->" "C" "A"]]] ["->" "A" ["->" "B" "C"]]]
    ["->" ["->" "A" ["->" "B" ["->" "C" "D"]]] ["->" "A" ["->" "C" ["->" "B" "D"]]]]
    ["->" ["->" "A" ["->" "B" "B"]] ["->" "A" ["->" "A" ["->" "B" "B"]]]]
    ["->" ["->" "A" ["->" "B" "C"]] ["->" ["->" "A" "B"] ["->" "A" "C"]]]
    ["->" ["->" "A" ["->" "B" "C"]] ["->" ["->" "C" "D"] ["->" "A" ["->" "B" "D"]]]]
    ["->" ["->" "A" ["->" "B" "C"]] ["->" ["->" "D" "B"] ["->" "A" ["->" "D" "C"]]]]
    ["->" ["->" "A" ["->" "B" "C"]] ["->" "A" ["->" ["->" "C" "D"] ["->" "B" "D"]]]]
    ["->" ["->" "A" ["->" "B" "C"]] ["->" "A" ["->" ["->" "D" "B"] ["->" "D" "C"]]]]
    ["->" ["->" "A" ["->" "B" "C"]] ["->" "B" ["->" "A" "C"]]]
    ["->" ["->" "A" ["~" "A"]] ["~" "A"]]
    ["->" ["->" "A" ["~" "B"]] ["->" "B" ["~" "A"]]]
    ["->" ["->" "A" "A"] ["->" ["->" "A" "A"] ["->" "A" "A"]]]
    ["->" ["->" "A" "A"] ["->" "A" "A"]]
    ["->" ["->" "A" "B"] ["->" ["->" ["->" "A" "B"] "C"] "C"]]
    ["->" ["->" "A" "B"] ["->" ["->" "A" ["->" "B" "C"]] ["->" "A" "C"]]]
    ["->" ["->" "A" "B"] ["->" ["->" "A" "B"] ["->" "A" "B"]]]
    ["->" ["->" "A" "B"] ["->" ["->" "B" "A"] ["->" "A" "B"]]]
    ["->" ["->" "A" "B"] ["->" ["->" "B" "A"] ["->" "B" "A"]]]
    ["->" ["->" "A" "B"] ["->" ["->" "B" "C"] ["->" "A" "C"]]]
    ["->" ["->" "A" "B"] ["->" ["->" "C" ["->" ["->" "A" "B"] "D"]] ["->" "C" "D"]]]
    ["->" ["->" "A" "B"] ["->" ["->" "C" "A"] ["->" "C" "B"]]]
    ["->" ["->" "A" "B"] ["->" ["->" "C" "B"] ["->" "A" ["->" "C" "B"]]]]
    ["->" ["->" "A" "B"] ["->" ["~" "B"] ["~" "A"]]]
    ["->" ["->" "B" "C"] ["->" ["->" "A" ["->" ["->" "B" "C"] "D"]] ["->" "A" "D"]]]
    ["->" ["~" ["->" "A" "B"]] ["->" "B" "A"]]
    ["->" ["~" ["~" ["~" "A"]]] ["~" "A"]]
    ["->" ["~" ["~" "A"]] "A"]
    ["->" ["~" "A"] ["~" ["~" ["~" "A"]]]]
    ["->" "A" ["->" ["->" "A" "B"] ["->" ["->" "B" "C"] "C"]]]
    ["->" "A" ["->" ["->" "A" "B"] "B"]]
    ["->" "A" ["->" "A" ["->" "A" "A"]]]
    ["->" "A" ["~" ["~" "A"]]]
    ["->" "A" "A"]
    ["~" ["<->" "A" ["~" "A"]]]
    ["~" ["F"]]
    ["v" ["->" "A" "B"] ["->" "B" "A"]]
    ["v" ["~" "A"] "A"]
    ["v" "A" ["~" ["~" ["~" "A"]]]]
    ["v" "A" ["~" "A"]]
  )
end

;;;;;;;;;;;;;;;;;;;;;
;;; logic stuff!  ;;;
;;;;;;;;;;;;;;;;;;;;;
to A-LOGIC-OPS end

to check-fmla [fmla]
  ifelse is-list? fmla 
    [check-fmla-rec fmla]
    [error (word "Error: " fmla " is not well formed")]
end

;; outputs a standardised version of a fmla
to-report standardise [fmla]
  if debug? [show (word "Calling: standardise " fmla)]
  set fmla naive-rename-vars fmla (sort vars-in fmla) dummy-vars
  report naive-rename-vars fmla (sort vars-in fmla) poss-vars
end

;; outputs a list of all variables in fmla
to-report vars-in [fmla]
;;  if debug? [show (word "Calling: vars-in " fmla)]
  report remove-list (remove-duplicates vars-in-rec fmla []) m-connectives
end

;; replaces a variable (tar) with repl
to-report rename-var [fmla tar repl]
;;  if debug? [show (word "Calling: rename-var " fmla " " tar " " repl)]
  if empty? fmla [report []]
  if fmla = tar [report repl]
  if is-list? fmla 
    [report fput 
             rename-var (first fmla) tar repl 
             rename-var (but-first fmla) tar repl]
  report fmla
end

;; checks if fmla is an instance of gen-fmla
to-report is-instance-of? [fmla gen-fmla]
;;  if debug? [show (word "Calling: is-instance-of? " fmla " " gen-fmla)]
  set var-table table:make
  report iio fmla gen-fmla
end

;;  modus ponens - applies major premise form-maj to minor premise form-min if possible (o.w. outputs [])
to-report mp [form-min form-maj]
  if debug? [show (word "Calling: mp " form-min " " form-maj)]
  if not (first form-maj = "->" and length form-maj = 3) [report []]  
  set form-min rename-without form-min vars-in form-maj
  let ant second form-maj
  let cons third form-maj
  set var-table table:make
  ifelse iio form-min ant [
    report subs-from-var-table cons
  ] [
    report []
  ]
end

;; substitutes all occurneces of vr by sbs in fml
to-report subs [vr sbs fml]
;;  if debug? [show (word "Calling: subs " vr " " sbs " " fml)]
  if empty? fml [report fml]
  if (is-string? fml) [
    ifelse vr = fml 
      [report sbs]
      [report fml]
  ]
  if is-list? fml 
    [report map [subs vr sbs ?] fml]
  error (word fml " is not a string or lis!")
end

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; stuff used in logic ;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to A-LOGIC-DETAIL end

;; recursive details of check-fmla
to check-fmla-rec [fmla]
;;  if debug? [show (word "Calling: check-fmla-rec " fmla)]
  ifelse not is-list? fmla [
    if not member? fmla table:keys connectives 
      [error (word "Error: " fmla " is not a recognised connective!")]
    if not (0 = table:get connectives fmla)
      [error (word "Error: " fmla " needs more arguments!")]
  ] [
    let fitem first fmla
    let ritem but-first fmla
    if not member? fitem table:keys connectives
      [error (word "Error: " fitem " is not a recognised connective in " fmla " !")]
    if not ((length ritem) = table:get connectives fitem)
      [error (word "Error: " fitem " does not have the right number of arguments in " fmla " !")]
    foreach ritem [check-fmla-rec ?]
  ]
end

;; used by mp
;; uses var-table created by iio call in mp
to-report subs-from-var-table [fmla]
  if debug? [show (word "Calling: subs-from-var-table " fmla)]
  let op-fmla fmla
  foreach table:to-list var-table [
    set op-fmla subs first ? second ? op-fmla
  ]
  report op-fmla
end

;; rename so as not to mention the variables in the second arg
to-report rename-without [fmla excl-var-list]
  if debug? [show (word "Calling: rename-without " fmla " " excl-var-list)]
  let vars-in-fmla vars-in fmla
  let repl-vars intersect vars-in-fmla excl-var-list
  let dvrs sublist dummy-vars 0 length repl-vars
  report naive-rename-vars (naive-rename-vars fmla repl-vars dvrs) dvrs (remove-list poss-vars excl-var-list)
end

;; recursive bit of vars-in
to-report vars-in-rec [fmla opl]
;;  if debug? [show (word "Calling: vars-in-rec " fmla " " opl)]
  if empty? fmla [report opl]
  ifelse (is-string? fmla) [
    report fput fmla opl
;;    ifelse member? fmla opl
;;      [report opl]
;;      [report fput fmla opl]
  ] [
    report vars-in-rec but-first fmla (vars-in-rec first fmla opl)
  ]
;;  error (word fmla " is not a string or list!")
end

;; renames from a list of vars to a list of replacements
;; does this sequentially rather than "in parallel"
to-report naive-rename-vars [fmla tar-lis rep-lis]
;;  if debug? [show (word "Calling: naive-rename-vars " fmla " " tar-lis " " rep-lis)]
  if length rep-lis < length tar-lis [error (word "too few replacements for targets in naive-rename-vars: " fmla " " tar-lis " " rep-lis)]
  if empty? tar-lis [report fmla]
  report naive-rename-vars 
            (rename-var fmla first tar-lis first rep-lis) 
            but-first tar-lis 
            but-first rep-lis
end

;;  is-instance-of? using an initially blank table
to-report iio [f g]
;;  if debug? [show (word "Calling: iio " f " " g)]
  if is-connective? g [report f = g]
  if is-string? g [
    ifelse table:has-key? var-table g
      [report (table:get var-table g) = f]
      [table:put var-table g f report true]
  ]
  if not is-list? g [report false]
  if length g != length f [report false]
  if not (first f = first g) [report false]
  if length g > 1 [
    report and-list (map [iio ?1 ?2] but-first f but-first g)
  ]
  ;; report var-table
  report true
end

;; used in iio - reports if any of the substitutions failed
to-report and-list [lst]
  if member? false lst [report false]
  report true
end

to-report is-connective? [str]
  if not is-string? str [report false]
  report member? str ["->" "v" "&" "~" "<->" "T" "F"]
end


;;;;;;;;;;;;;;;;;;;;;;;
;; general utilities ;;
;;;;;;;;;;;;;;;;;;;;;;;
to A-UTILS end

to-report union [lst1 lst2]
  report remove-duplicates sentence lst1 lst2
end

to-report intersect [lst1 lst2]
  ifelse length lst2 < length lst1
    [report intersect0 lst2 lst1]
    [report intersect0 lst1 lst2]
end

;; used by intersect
;; might be less inefficient if lst2 is much shorter than lst1
to-report intersect0 [lst1 lst2]
  if empty? lst1 [report []]
  ifelse member? first lst1 lst2
    [report fput first lst1 intersect0 but-first lst1 lst2]
    [report intersect0 but-first lst1 lst2]
end

to-report prob [num]
  ;; returns value "TRUE" with probability determined by input
  report random-float 1 < num
end

to-report random-from [lst]
  if empty? lst [error "Can't find a random element from an empty list!"]
  report item random length lst lst
end

to spread
  setxy 
    pxcor - 0.4 + random-float 0.8
    pycor - 0.4 + random-float 0.8
end

to-report remove-list [lis rem-lis]
  if empty? rem-lis [report lis]
  report remove first rem-lis (remove-list lis but-first rem-lis)
end

to-report second [ls]
  report first but-first ls
end

to-report third [ls]
  report first but-first but-first ls
end

to-report remove-one [lst]
  report remove random-from lst lst
end

to-report n-of-list [n lst]
  if length lst <= n [report lst]
  report sublist shuffle lst 0 n 
end

to-report XXX
  error "XXX!"
end

to-report join-lists [lstoflsts]
  if empty? lstoflsts [report []]
  report sentence first lstoflsts join-lists but-first lstoflsts
end

to-report showpass [itm]
  show itm
  report itm
end

to-report fmanyput [putlist tarlist]
  if empty? putlist [report tarlist]
  report fput first putlist fmanyput but-first putlist tarlist
end

to-report flatten [lst]
  if empty? lst [report []]
  ifelse is-list? first lst
    [report sentence flatten first lst flatten but-first lst]
    [report sentence first lst flatten but-first lst]
end

to-report chooseProbilistically [numList]
  report findPos (random-float 1) cummulateList scaleList numList
end

to-report chooseReverseProbilistically [numList]
  if length numList = 1 [report 0]
  report findPos (random-float 1) cummulateList reverseProbList scaleList numList
end

to-report reverseProbList [numList]
  report map [1 - ?1] numList
end

to-report cummulateList [numList]
  report cummulateListR numList 0
end

to-report cummulateListR [numList cumm]
  if empty? numList [report []]
  let newCumm cumm + first numList
  report fput newCumm cummulateListR but-first numList newCumm
end

to-report scaleList [numList]
  let sumList sum numList
  if sumList = 0 [report numList]
  report map [?1 / sumList] numList
end

to-report findPos [vl numList]
  report findPosR vl numList 0
end

to-report findPosR [vl numList  pos]
  if empty? numList [report pos]
  if vl <= (first numList) [report pos]
  report findPosR vl but-first numList (1 + pos)
end

to-report freqOfIn [lis allList]
  report reduce [fput (numOfIn ?2 lis) ?1 ] (fput [] allList)
end  
  
to-report freqOf [lis]
  if empty? lis [report []]
  report fput (list (numOfIn first lis lis) (first lis)) (freqOf remove first lis lis)
end

to-report freqRep [lis]
  report sort-by [first ?1 > first ?2] filter [first ? > 1] freqOf lis 
end

to-report numOfIn [itm lis]
  report length (filter [itm = ?] lis)
end

to-report safeDiv [nm dn]
  if dn = 0 [report 0]
  report nm / dn
end
@#$#@#$#@
GRAPHICS-WINDOW
184
10
661
187
-1
-1
29.2
1
10
1
1
1
0
1
1
1
0
15
0
4
1
1
1
ticks
30.0

BUTTON
126
10
181
43
NIL
go
T
1
T
OBSERVER
NIL
NIL
NIL
NIL
1

BUTTON
9
10
64
43
NIL
setup
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1

BUTTON
67
10
122
43
step
go
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1

SWITCH
667
10
757
43
debug?
debug?
1
1
-1000

SLIDER
9
45
182
78
num-researchers
num-researchers
1
100
100
1
1
NIL
HORIZONTAL

SLIDER
9
82
182
115
num-journals
num-journals
1
10
1
1
1
NIL
HORIZONTAL

SLIDER
9
119
182
152
max-beliefs
max-beliefs
0
50
50
1
1
NIL
HORIZONTAL

SLIDER
9
155
182
188
max-techniques
max-techniques
0
10
5
1
1
NIL
HORIZONTAL

OUTPUT
186
190
649
438
10

SLIDER
9
192
182
225
num-publish
num-publish
0
10
2
1
1
NIL
HORIZONTAL

SLIDER
9
228
182
261
num-read
num-read
0
20
5
1
1
NIL
HORIZONTAL

SLIDER
7
265
180
298
work-rate
work-rate
0
10
5
1
1
NIL
HORIZONTAL

SLIDER
8
304
182
337
innovate-technique-prob
innovate-technique-prob
0
1
0.04
0.01
1
NIL
HORIZONTAL

MONITOR
854
10
921
56
Published
length table:keys published - length axioms
0
1
11

MONITOR
923
10
974
55
Found
length found
0
1
11

PLOT
743
58
975
192
Log 10 1 + Cumm. Published/Found
NIL
NIL
0.0
1.0
0.0
1.0
true
false
"" ""
PENS
"published" 1.0 0 -16777216 false "" "plot log (1 + length table:keys published - length axioms) 10"
"found" 1.0 0 -2674135 true "" "plot log (1 + length found) 10"
"citations" 1.0 0 -13840069 true "" "plot log (1 + (sum map [second ?] table:to-list published)) 10"

MONITOR
669
152
732
194
Secs/tck
secs-per-tick
2
1
10

CHOOSER
6
342
181
387
ranking-method
ranking-method
"random" "shortest" "fewest variables"
1

CHOOSER
6
390
180
435
reading-method
reading-method
"only recent" "random" "recent bias" "cited bias" "shortest bias" "fewest vars bias"
2

INPUTBOX
668
47
738
107
max-time
80
1
0
Number

PLOT
654
196
814
316
Num Published
NIL
NIL
0.0
10.0
0.0
10.0
true
false
"" ""
PENS
"published" 1.0 1 -16777216 true "" "set-plot-x-range 0 max list 1 [num-published] of max-one-of researchers [num-published]\nhistogram [num-published] of researchers"

PLOT
818
196
978
316
Num Found
NIL
NIL
0.0
10.0
0.0
10.0
true
false
"" ""
PENS
"default" 1.0 1 -16777216 true "" "set-plot-x-range 0 max list 1 1 + [num-found] of max-one-of researchers [num-found]\nhistogram [num-found] of researchers"

PLOT
654
319
816
439
Hist. Citations
NIL
NIL
0.0
10.0
0.0
10.0
true
false
"" ""
PENS
"default" 1.0 1 -16777216 true "" "let npl map [second ?] table:to-list published\nset-plot-x-range 0 max list 1 max npl\nhistogram npl"

SWITCH
760
10
852
43
check-fmla?
check-fmla?
1
1
-1000

MONITOR
669
109
729
151
Fnd/Pub
safeDiv (length found) \n  (length table:keys published - length axioms)
3
1
10

PLOT
818
318
979
439
Citations/Published
NIL
NIL
0.0
1.0
0.0
0.01
true
false
"" ""
PENS
"default" 1.0 0 -16777216 true "" "plot safeDiv (sum map [second ?] table:to-list published) \n  (length table:keys published - length axioms)"

@#$#@#$#@
## WHAT IS IT?

This is a model of formal scientists trying to discover significant formal theories.  The base problem they are trying to solve is a Hilbert type formal logic.  The targets are published "theorems" in this logic.

The agents here are representing formal scientists, they have two crucial internal stores: one of their knowledge (a list of formulas they have) and one a set of techniques (another list of formulas used as the major premise in mp to transform beliefs into other beliefs).

Each iteraction the scientists do some reasoning (applying Modus Ponens) to make new formulas, then submit some of their knowledge to the journals for publication.  The journals select from submissions and publish some.  Scientists then read some of the articles published and store these.  Scientists have a maximum they can remember and so if have too many forget some.

## HOW TO USE IT

The target logic and theorems are specifed in the code under the "specify logic" section.

Parameters and options are set using the sliders.  Then press "setup" to initialise the simulation, followed by "go" to run it.  The simulation will run until the number of iterations specified by "max-time".

## THINGS TO NOTICE

The journal publishing more, or reading articles based on their number of citations does not increase the productivity of discovery (measured by number of target formulas published) in this model!

## PARAMETERS/SETTINGS

* num-researchers -- how many researcher agents there are
* num-journals -- how many journals there are
* max-beliefs -- the most number of beliefs a researcher can hold
* max-techniques -- the most number of techniques a researcher can hold
* num-publish -- how many formulas are published each tick by each journal
* num-read -- how many formulas are read by each researcher each tick
* work-rate -- how many inferences researchers make each tick
* innovate-technique-prob -- the probability that a belief is "promoted" to a technique
* max-time -- the length of time a simulatio with run

# ranking-method

This is the choice of how journals rank submissions for publication
* random -- at random
* shortest -- a preference for shorter formulas
* fewest variables -- a preference for fomrulas with fewer unique variables

# reading-method

This is how the researchers direct their reading
* only recent -- only those published in the current tick
* random -- any from the entire history of the journals' publications
* recent bias -- from any, but with a bias towards those more recently published
* cited bias -- from any, but with a bias towards those with more citations
* shortest bias -- Not implemented yet
* fewest vars bias -- Not implemented yet

Plus a couple of switches to aid debugging: debug? - which turns on extensive procedure call methods, and check-fmla? - which turns on checking that formula are syntactically correct.

## OUTPUTS/GRAPHS

The text output shows when a researcher discovers a target formula and which one.

There are the following monitors:
* the number of formula published by the journals
* the number of target formula discovered
* the ration of target formula discovered to number published
* how long each tick takes

There are two graphs:
* a graph of the (Log of) number published (black), number of citations (green) and number of targets discovered (red)
* a graph of the ratio of number of citations per formula published

There are three histograms:
* of the distribution of publication success by researchers
* of the distribution of number of targets found by researchers
* of the distribution of number of citations gained by published formula

## EXTENDING THE MODEL

There are many, many wasy in which this model could be extended.  Those that come immediately to mind are:
* Determining which formulas researchers submit to publication
* Determining how researchers choose where to submit to
* Determining the forgetting method where by working knowledge is discarded
* Implementing different target formal logics/systems
* Improving the visualisation of what is happening

## NETLOGO FEATURES

List processing is used extensively in the formal logic manipulation. Formulas are respresented as nested lists.

## CREDITS AND REFERENCES

Originally presented at the ESSA 2004 Conference in Valadollid, Spain.

Published as:

Edmonds, B. (2007) Artificial Science - a Simulation to Study the Social Processes of Science.  In Edmonds, B., Hernandez, C. and Troitzsch, K. G. (eds.) (2007) Social Simulation: Technologies, Advances and New Discoveries.  IGI Publishing, 61-67.  

There is a versino at: http://cfpm.org/cpmrep138.html

This implementation by Bruce Edmonds, May 2014
http://cfpm.org/models
@#$#@#$#@
default
true
0
Polygon -7500403 true true 150 5 40 250 150 205 260 250

airplane
true
0
Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15

arrow
true
0
Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150

box
false
0
Polygon -7500403 true true 150 285 285 225 285 75 150 135
Polygon -7500403 true true 150 135 15 75 150 15 285 75
Polygon -7500403 true true 15 75 15 225 150 285 150 135
Line -16777216 false 150 285 150 135
Line -16777216 false 150 135 15 75
Line -16777216 false 150 135 285 75

bug
true
0
Circle -7500403 true true 96 182 108
Circle -7500403 true true 110 127 80
Circle -7500403 true true 110 75 80
Line -7500403 true 150 100 80 30
Line -7500403 true 150 100 220 30

butterfly
true
0
Polygon -7500403 true true 150 165 209 199 225 225 225 255 195 270 165 255 150 240
Polygon -7500403 true true 150 165 89 198 75 225 75 255 105 270 135 255 150 240
Polygon -7500403 true true 139 148 100 105 55 90 25 90 10 105 10 135 25 180 40 195 85 194 139 163
Polygon -7500403 true true 162 150 200 105 245 90 275 90 290 105 290 135 275 180 260 195 215 195 162 165
Polygon -16777216 true false 150 255 135 225 120 150 135 120 150 105 165 120 180 150 165 225
Circle -16777216 true false 135 90 30
Line -16777216 false 150 105 195 60
Line -16777216 false 150 105 105 60

car
false
0
Polygon -7500403 true true 300 180 279 164 261 144 240 135 226 132 213 106 203 84 185 63 159 50 135 50 75 60 0 150 0 165 0 225 300 225 300 180
Circle -16777216 true false 180 180 90
Circle -16777216 true false 30 180 90
Polygon -16777216 true false 162 80 132 78 134 135 209 135 194 105 189 96 180 89
Circle -7500403 true true 47 195 58
Circle -7500403 true true 195 195 58

circle
false
0
Circle -7500403 true true 0 0 300

circle 2
false
0
Circle -7500403 true true 0 0 300
Circle -16777216 true false 30 30 240

cow
false
0
Polygon -7500403 true true 200 193 197 249 179 249 177 196 166 187 140 189 93 191 78 179 72 211 49 209 48 181 37 149 25 120 25 89 45 72 103 84 179 75 198 76 252 64 272 81 293 103 285 121 255 121 242 118 224 167
Polygon -7500403 true true 73 210 86 251 62 249 48 208
Polygon -7500403 true true 25 114 16 195 9 204 23 213 25 200 39 123

cylinder
false
0
Circle -7500403 true true 0 0 300

dot
false
0
Circle -7500403 true true 90 90 120

face happy
false
0
Circle -7500403 true true 8 8 285
Circle -16777216 true false 60 75 60
Circle -16777216 true false 180 75 60
Polygon -16777216 true false 150 255 90 239 62 213 47 191 67 179 90 203 109 218 150 225 192 218 210 203 227 181 251 194 236 217 212 240

face neutral
false
0
Circle -7500403 true true 8 7 285
Circle -16777216 true false 60 75 60
Circle -16777216 true false 180 75 60
Rectangle -16777216 true false 60 195 240 225

face sad
false
0
Circle -7500403 true true 8 8 285
Circle -16777216 true false 60 75 60
Circle -16777216 true false 180 75 60
Polygon -16777216 true false 150 168 90 184 62 210 47 232 67 244 90 220 109 205 150 198 192 205 210 220 227 242 251 229 236 206 212 183

fish
false
0
Polygon -1 true false 44 131 21 87 15 86 0 120 15 150 0 180 13 214 20 212 45 166
Polygon -1 true false 135 195 119 235 95 218 76 210 46 204 60 165
Polygon -1 true false 75 45 83 77 71 103 86 114 166 78 135 60
Polygon -7500403 true true 30 136 151 77 226 81 280 119 292 146 292 160 287 170 270 195 195 210 151 212 30 166
Circle -16777216 true false 215 106 30

flag
false
0
Rectangle -7500403 true true 60 15 75 300
Polygon -7500403 true true 90 150 270 90 90 30
Line -7500403 true 75 135 90 135
Line -7500403 true 75 45 90 45

flower
false
0
Polygon -10899396 true false 135 120 165 165 180 210 180 240 150 300 165 300 195 240 195 195 165 135
Circle -7500403 true true 85 132 38
Circle -7500403 true true 130 147 38
Circle -7500403 true true 192 85 38
Circle -7500403 true true 85 40 38
Circle -7500403 true true 177 40 38
Circle -7500403 true true 177 132 38
Circle -7500403 true true 70 85 38
Circle -7500403 true true 130 25 38
Circle -7500403 true true 96 51 108
Circle -16777216 true false 113 68 74
Polygon -10899396 true false 189 233 219 188 249 173 279 188 234 218
Polygon -10899396 true false 180 255 150 210 105 210 75 240 135 240

house
false
0
Rectangle -7500403 true true 45 120 255 285
Rectangle -16777216 true false 120 210 180 285
Polygon -7500403 true true 15 120 150 15 285 120
Line -16777216 false 30 120 270 120

leaf
false
0
Polygon -7500403 true true 150 210 135 195 120 210 60 210 30 195 60 180 60 165 15 135 30 120 15 105 40 104 45 90 60 90 90 105 105 120 120 120 105 60 120 60 135 30 150 15 165 30 180 60 195 60 180 120 195 120 210 105 240 90 255 90 263 104 285 105 270 120 285 135 240 165 240 180 270 195 240 210 180 210 165 195
Polygon -7500403 true true 135 195 135 240 120 255 105 255 105 285 135 285 165 240 165 195

line
true
0
Line -7500403 true 150 0 150 300

line half
true
0
Line -7500403 true 150 0 150 150

pentagon
false
0
Polygon -7500403 true true 150 15 15 120 60 285 240 285 285 120

person
false
0
Circle -7500403 true true 110 5 80
Polygon -7500403 true true 105 90 120 195 90 285 105 300 135 300 150 225 165 300 195 300 210 285 180 195 195 90
Rectangle -7500403 true true 127 79 172 94
Polygon -7500403 true true 195 90 240 150 225 180 165 105
Polygon -7500403 true true 105 90 60 150 75 180 135 105

plant
false
0
Rectangle -7500403 true true 135 90 165 300
Polygon -7500403 true true 135 255 90 210 45 195 75 255 135 285
Polygon -7500403 true true 165 255 210 210 255 195 225 255 165 285
Polygon -7500403 true true 135 180 90 135 45 120 75 180 135 210
Polygon -7500403 true true 165 180 165 210 225 180 255 120 210 135
Polygon -7500403 true true 135 105 90 60 45 45 75 105 135 135
Polygon -7500403 true true 165 105 165 135 225 105 255 45 210 60
Polygon -7500403 true true 135 90 120 45 150 15 180 45 165 90

sheep
false
0
Rectangle -7500403 true true 151 225 180 285
Rectangle -7500403 true true 47 225 75 285
Rectangle -7500403 true true 15 75 210 225
Circle -7500403 true true 135 75 150
Circle -16777216 true false 165 76 116

square
false
0
Rectangle -7500403 true true 30 30 270 270

square 2
false
0
Rectangle -7500403 true true 30 30 270 270
Rectangle -16777216 true false 60 60 240 240

star
false
0
Polygon -7500403 true true 151 1 185 108 298 108 207 175 242 282 151 216 59 282 94 175 3 108 116 108

target
false
0
Circle -7500403 true true 0 0 300
Circle -16777216 true false 30 30 240
Circle -7500403 true true 60 60 180
Circle -16777216 true false 90 90 120
Circle -7500403 true true 120 120 60

tree
false
0
Circle -7500403 true true 118 3 94
Rectangle -6459832 true false 120 195 180 300
Circle -7500403 true true 65 21 108
Circle -7500403 true true 116 41 127
Circle -7500403 true true 45 90 120
Circle -7500403 true true 104 74 152

triangle
false
0
Polygon -7500403 true true 150 30 15 255 285 255

triangle 2
false
0
Polygon -7500403 true true 150 30 15 255 285 255
Polygon -16777216 true false 151 99 225 223 75 224

truck
false
0
Rectangle -7500403 true true 4 45 195 187
Polygon -7500403 true true 296 193 296 150 259 134 244 104 208 104 207 194
Rectangle -1 true false 195 60 195 105
Polygon -16777216 true false 238 112 252 141 219 141 218 112
Circle -16777216 true false 234 174 42
Rectangle -7500403 true true 181 185 214 194
Circle -16777216 true false 144 174 42
Circle -16777216 true false 24 174 42
Circle -7500403 false true 24 174 42
Circle -7500403 false true 144 174 42
Circle -7500403 false true 234 174 42

turtle
true
0
Polygon -10899396 true false 215 204 240 233 246 254 228 266 215 252 193 210
Polygon -10899396 true false 195 90 225 75 245 75 260 89 269 108 261 124 240 105 225 105 210 105
Polygon -10899396 true false 105 90 75 75 55 75 40 89 31 108 39 124 60 105 75 105 90 105
Polygon -10899396 true false 132 85 134 64 107 51 108 17 150 2 192 18 192 52 169 65 172 87
Polygon -10899396 true false 85 204 60 233 54 254 72 266 85 252 107 210
Polygon -7500403 true true 119 75 179 75 209 101 224 135 220 225 175 261 128 261 81 224 74 135 88 99

wheel
false
0
Circle -7500403 true true 3 3 294
Circle -16777216 true false 30 30 240
Line -7500403 true 150 285 150 15
Line -7500403 true 15 150 285 150
Circle -7500403 true true 120 120 60
Line -7500403 true 216 40 79 269
Line -7500403 true 40 84 269 221
Line -7500403 true 40 216 269 79
Line -7500403 true 84 40 221 269

wolf
false
0
Polygon -7500403 true true 135 285 195 285 270 90 30 90 105 285
Polygon -7500403 true true 270 90 225 15 180 90
Polygon -7500403 true true 30 90 75 15 120 90
Circle -1 true false 183 138 24
Circle -1 true false 93 138 24

x
false
0
Polygon -7500403 true true 270 75 225 30 30 225 75 270
Polygon -7500403 true true 30 75 75 30 270 225 225 270

@#$#@#$#@
NetLogo 5.0.4
@#$#@#$#@
@#$#@#$#@
@#$#@#$#@
@#$#@#$#@
@#$#@#$#@
default
0.0
-0.2 0 1.0 0.0
0.0 1 1.0 0.0
0.2 0 1.0 0.0
link direction
true
0
Line -7500403 true 150 150 90 180
Line -7500403 true 150 150 210 180

@#$#@#$#@
0
@#$#@#$#@
