⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ---random combinations and permutations.nlogo

📁 NETLOGO
💻 NLOGO
📖 第 1 页 / 共 4 页
字号:
         st
       ]
    ]
  ]
  [
    set pcolor-of my-guess-block-buddy item ( random length color-rotation ) color-rotation
  ]
end

;; if a non-correspondence was found between the guessed and original combi, this specific search trial is registered as failed
to check  ;; patches-in-set-block procedure
  let my-color-help my-color
  let my-shape-help my-shape 
  ifelse dice?
  [
    ask my-guess-block-buddy
      [ ask dice-here [ if shape != my-shape-help [ set all-combi-match? false ] ] ]
  ]
  [
     ask my-guess-block-buddy
       [ if pcolor != my-color-help [ set all-combi-match? false ] ]
  ]
end

;; For the permutation search, we have earlier made a list of how many times each choice appears in the combination. 
;; Now we create the guessed-combination list, then compare these two lists.
to check-permis
  let rotation-counter 0
  set permis-choices-check []
  repeat num-choices
  [
    ifelse dice?
      [ set permis-choices-check lput count dice with 
        [ ( pycor < 0 )  and ( shape = item rotation-counter dice-rotation ) ] permis-choices-check ]
      [ set permis-choices-check lput count patches-in-guess-block with 
        [ pcolor =  item rotation-counter color-rotation ] permis-choices-check ]
    set rotation-counter rotation-counter + 1
  ]
  
  set rotation-counter 0
  ifelse permis-choices-check = permis-choices
    [ set all-permis-match? true ]
    [ set all-permis-match? false ]
end

;; toggles between hiding and revealing the patches-in-set-block
to hide/reveal
  ifelse not combi-exists? [
     user-message "Please first create a combination." stop
   ] [
     ifelse hide?
       [ hide-set-block ]
       [ reveal-set-block]
   ]
end

to hide-set-block
  if dice?
    [ ask patches-in-set-block [ ask dice-here [ ht ] ] ]
  ask patches-in-set-block [set pcolor grey - 2 ]
 set hide? false 
end

;; procedure that re-assigns to patches-in-set-block the appearance properties of the original combination
to reveal-set-block
  ifelse dice?
    [ ask dice with [ pycor > 0 ] [ set pcolor green st ] ]
    [ ask patches-in-set-block [ set pcolor my-color ] ]
 set hide? true
end

to alert-forgot-choice
  set instructions "You are in Dice mode." + " Please make sure you pick dice faces for each and every one of the squares"
end

to alert-setup
   set instructions "Please work this way: press Setup, and then Create Combi."
end

to plot-sample
  set samples-counter samples-counter + 1 
  set #combi-successes-per-sample-list fput count-combi-successes #combi-successes-per-sample-list
  set #permis-successes-per-sample-list fput count-permis-successes #permis-successes-per-sample-list
  set-current-plot "Successes per Sample Distribution"
  ifelse Analysis-Type = "both"
  [
    ;; this line regulates the appearance of the plot -- it centers the two histograms
    set-plot-x-range 0  max ( list ( round 1.5 * ceiling ( mean  #permis-successes-per-sample-list ) ) 
                                  ( 1 + max #permis-successes-per-sample-list ) .1 )
  ]
  [
    ifelse Analysis-Type = "combination"
      [set-plot-x-range 0 max ( list ( 2 * ceiling ( mean  #combi-successes-per-sample-list ) ) 
                                    ( 1 + max #combi-successes-per-sample-list ) .1 ) ]
      [set-plot-x-range 0 max (list ( 2 * ceiling ( mean  #permis-successes-per-sample-list ) ) 
                                    ( 1 + max #permis-successes-per-sample-list ) .1 ) ]
  ]
 
  ;; In order to collapse two procedures into one, we use (below) the do-plot procedure.
  ;; Here, we assign values for this procedure according to the two conditions of search (combi and permis).
  if Analysis-Type != "permutations"
    [ do-plot #combi-successes-per-sample-list "combination" ]  
  if Analysis-Type != "combination"
    [ do-plot #permis-successes-per-sample-list "permutations" ] 
end

;; plotting procedure
to do-plot [ event-list current-plot-name ]
  if Analysis-Type = "combination" [ set-current-plot-pen "combination" plot-pen-reset ]
  if Analysis-Type = "permutations"  [ set-current-plot-pen "permutations" plot-pen-reset ]
  set-current-plot-pen current-plot-name
  ifelse bars? [ set-plot-pen-mode 1 ] [ set-plot-pen-mode 0 ]
  histogram-list event-list
  set count-steps 0
  set count-permis-successes 0
  set count-combi-successes 0
end

;; procedure for running repeatedly between the #1 thru #6 monitors and updating their values.
to-report # [ index ]
  ifelse ( num-choices >= index )  
    [ report item ( index - 1 ) permis-choices ] 
    [ report "N/A" ]  
end

to-report ratio
  ;; we want the ratio to be rounded after two decimal points
  let ratio-help precision ( mean #permis-successes-per-sample-list / mean #combi-successes-per-sample-list ) 2
  report "1 : " + ratio-help
end

; *** NetLogo Model Copyright Notice ***
;
; This model was created as part of the project:
; PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN
; CLASSROOMS.  The project gratefully acknowledges the support of the
; National Science Foundation (REPP program) -- grant number REC #9814682.
;
; Copyright 2002 by Uri Wilensky.  Updated 2002.  All rights reserved.
;
; Permission to use, modify or redistribute this model is hereby granted,
; provided that both of the following requirements are followed:
; a) this copyright notice is included.
; b) this model will not be redistributed for profit without permission
;    from Uri Wilensky.
; Contact Uri Wilensky for appropriate licenses for redistribution for
; profit.
;
; To refer to this model in academic publications, please use:
; Wilensky, U. (2002).  NetLogo Random Combinations and Permutations model.
; http://ccl.northwestern.edu/netlogo/models/Random Combinations and Permutations.
; Center for Connected Learning and Computer-Based Modeling,
; Northwestern University, Evanston, IL.
;
; In other publications, please use:
; Copyright 1998 by Uri Wilensky.  All rights reserved.  See
; http://ccl.northwestern.edu/netlogo/models/Random Combinations and Permutations
; for terms of use.
;
; *** End of NetLogo Model Copyright Notice ***
@#$#@#$#@
GRAPHICS-WINDOW
508
61
718
292
2
2
40.0
1
10
1
1
1
0
1
1
1

CC-WINDOW
5
503
727
598
Command Center
0

SLIDER
254
104
346
137
#choices
#choices
2
6
2
1
1
NIL

MONITOR
568
405
715
454
#Steps in This Sample
count-steps
3
1

MONITOR
8
270
102
319
Combination
count-combi-successes
3
1

SWITCH
8
208
143
241
single-success?
single-success?
1
1
-1000

MONITOR
497
405
565
454
#Samples
samples-counter
0
1

SWITCH
8
456
106
489
bars?
bars?
0
1
-1000

MONITOR
417
321
467
370
NIL
# 1
3
1

MONITOR
465
321
515
370
NIL
# 2
3
1

MONITOR
516
321
566
370
NIL
# 3
3
1

MONITOR
566
321
616
370
NIL
# 4
3
1

MONITOR
616
321
666
370
NIL
# 5
3
1

MONITOR
667
321
717
370
NIL
# 6
3
1

MONITOR
103
270
205
319
Permutation
count-permis-successes
3
1

TEXTBOX
408
301
703
319
Sample Space and Numbers of Choices by Type:

BUTTON
7
60
143
93
Setup
Setup
NIL
1
T
OBSERVER
T
NIL

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -