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

📄 ---hammingerror.nlogo

📁 NETLOGO
💻 NLOGO
📖 第 1 页 / 共 2 页
字号:
    ]  ask patches with [ column = 1 ]    [ set here-x pxcor ]  ask digit with [ xcor < here-x ]    [   set heading 90        repeat 4          [  fd 1             wait slow-motion          ]     ]  ask digit with [ xcor < here-x ]    [             if not any? digit-at 2 0          [  repeat 2                [  fd 1                   wait slow-motion                ]          ]    ]  ask digit with [ xcor < here-x ]    [                 if not any? digit-at 2 0          [  repeat 2                [  fd 1                   wait slow-motion                ]          ]    ]   ask patches with [ column > 8 ]     [ set plabel "" ]   explain 2 "Data = " + add-space get-number   ask digit with [ color != white ]     [  set color white        set label-color black     ]   ask patches with [ plabel-color = green ]     [  set plabel ""     ]   set step step + 1endto flip [ col ]  locals [ here-x ]  ask digit with [ color = red ]    [  set color yellow       set label-color black    ]  ask patches with [ column = col ]    [ set here-x pxcor ]  ask digit with [ xcor = here-x ]    [  set color red       wait slow-motion * 5       ifelse label = "0 "         [ set label "1 " ]         [ set label "0 " ]       set color green       set label-color white       ask patch-at 0 -2           [ set plabel "Fixed"              set plabel-color green           ]    ]end;  do whatever step comes next, then wait until user wants to continueto one-step  locals [ which ]  if step < 11    [  set which (word "step" step)       run which    ]end; this is the go button, that when pressed, goes through the entire simulationto go  locals [  which-step]  set which-step "step" + step  ifelse  step < 11    [ run which-step      set which-step "step" + step      wait slow-motion    ]    [  stop    ]endto show-again  locals [ current n]  set start-x 12  set current 1    set n 1    explain 1 (word add-space from-number " was sent using Hamming SEC (even).")  explain 2 "Was there an error in transmission?"  set step 1  ask turtles [ die ]  ask patches with [ pycor > -3 ]    [set plabel ""]    setup-bits from-number  setup-arrowend;  ask a quiz questionto quiz  locals [ save-slow ]  set save-slow slow-motion  set slow-motion 0  without-interruption [ setup ]  wait .5  ask-other  set slow-motion save-slowendto ask-other   locals [ guess target question line]  without-interruption [ set question from-number ]  set question add-space question  set guess user-yes-or-no? (word add-space from-number " was sent using Hamming SEC (even).\nWas there an error in transmission?")  set target calc  ifelse guess = target     [ user-message random-one-of praise ]    [ set line "I'm sorry, but an error "      ifelse target         [  set line line + "WAS detected."         ]         [  set line line + "was NOT detected."         ]      user-message line   ]endto-report calc  locals [  which-step result]  set which-step "step" + step  while  [step < 11]    [ run which-step      set which-step "step" + step    ]  set result error-found?  report resultend; *** NetLogo Model Copyright Notice ***;; Copyright 2004 by Teresa W. Carrigan.  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 Teresa W. Carrigan.; Contact Teresa W. Carrigan for appropriate licenses for redistribution ; for profit.;; To refer to this model in academic publications, please use:; Carrigan, T. (2004).  Hamming Error Detection Simulation; Blackburn College, Carlinville, IL.;; In other publications, please use:; Copyright 2004 by Teresa W. Carrigan.  All rights reserved.  ;; *** End of NetLogo Model Copyright Notice ***@#$#@#$#@GRAPHICS-WINDOW131069831613525.0118111CC-WINDOW27459564629Command CenterBUTTON1331876351NILsetupNIL1TOBSERVERTSLIDER386319558352slow-motionslow-motion010.40.11NILBUTTON78317141350stepone-stepNIL1TOBSERVERTBUTTON143318206351NILgoT1TOBSERVERTBUTTON209318272351NILquizNIL1TOBSERVERTBUTTON279319377352NILshow-againNIL1TOBSERVERT@#$#@#$#@WHAT IS IT?-----------This model demonstrates detection and correction of single bit errors, using Hamming SEC (single-error-correction, even parity) with eight data bits. HOW IT WORKS------------First a random 12-bit pattern is generated.  This represents either stored data or a message received, that is already in Hamming SEC.  Next the check bits are marked; they will be the bits that occupy positions 1, 2, 4, and 8.  Each position is then marked with the binary equivalent of the position number.  This will help us determine easily which bits are checked by which check bit.  Each check bit has a single one in the binary equivalent of its position number, and checks all bits that have a one in that same place in the binary equivalent.  Next we check the parity of each check bit group.  If any group has odd parity, we know that there is an error in one of the bits in that group, and we mark its check bit in red.After checking every check bit group, if there are no red check bits, then no error occurred and we can just strip the check bits to get the data.  If there was an error, we add the position numbers of all the red check bits to get the position of the bit that has been flipped.  If the sum of the red check bit positions is greater than the number of bits we have, then multiple errors occurred and we cannot fix the error.  Otherwise, we simply flip the erroneous bit, and then strip the check bits to give the correct data bits.HOW TO USE IT-------------The setup button generates a random 12-bit pattern.The step button demonstrates the next step, and then stops so you can take notes.  This is useful when you are first learning the method.The go button does every remaining step, at a speed determined by the slow-motion slider.  This is useful when you do not need to take notes between each step.The show-again button starts the exact problem from the beginning.  You may then click either the step button or the go button to see the same demonstration.The quiz button will generate a random problem and ask you to determine whether or not an error in transmission is detected. The slow-motion slider is an easy way to adjust the speed of the display.  Set it to zero if you want to show the final result as quickly as possible.  0.3 is a good setting for most purposes.THINGS TO NOTICE----------------The group of bits checked by a check bit is easily determined by looking at the binary equivalent of the position number.  Each bit in that group will have a 1 in the same place.In order to use the original data, we must not only correct any possible error but also strip the check bits to get the original data back.THINGS TO TRY-------------Set slow-motion to 0.3, click setup, and then click go.Click setup.  Work each step by hand, and then click the step button to check your answer.EXTENDING THE MODEL-------------------Allow the user to input the starting bit-pattern.Allow the user to input the starting bit pattern.Allow for a different number of data bits, set by a slider.Modify the model to use a Hamming double-error-correcting code.NETLOGO FEATURES----------------one-step uses the NetLogo run command combined with a global integer variable step to run the next step, without needing nested ifelse blocks. The arrow uses "other-BREED-here" to interact with the yellow bits.RELATED MODELS--------------Parity Error Detection, Hamming Code SimulationCREDITS AND REFERENCES----------------------This model was written by Teresa W. Carrigan, 2004.  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 Teresa W. Carrigan.Contact Teresa W. Carrigan for appropriate licenses for redistribution for profit.To refer to this model in academic publications, please use: Carrigan, T. (2004). Hamming Error Detection SimulationBlackburn College, Carlinville, IL.In other publications, please use: Copyright 2004 by Teresa W. Carrigan.  All rights reserved.  FOR MORE INFORMATION--------------------For more information on Hamming Codes, see one of the following textbooks:[1] Null, L. and Lobur, J. "Essentials of Computer Organization and Architecture", First Edition. Jones and Bartlett. pages 77-82. [2] Murdocca, M. and Heuring, V. "Principles of Computer Architecture", First Edition. Prentice Hall, pages 359-365.@#$#@#$#@defaulttrue0Polygon -7566196 true true 150 5 40 250 150 205 260 250arrowtrue0Polygon -7566196 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150boxtrue0Polygon -7566196 true true 45 255 255 255 255 45 45 45circlefalse0Circle -7566196 true true 35 35 230@#$#@#$#@NetLogo 2.0.1@#$#@#$#@@#$#@#$#@@#$#@#$#@

⌨️ 快捷键说明

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