!!!---tileworldzavala.nlogo

来自「NETLOGO」· NLOGO 代码 · 共 660 行 · 第 1/2 页

NLOGO
660
字号
      set y ycor      set distance-robot-tile (distancexy (xcor-of closest-tile) ycor) + (distancexy xcor (ycor-of closest-tile))        setxy xcor-of closest-tile ycor-of closest-tile      set distance-tile-hole (distancexy (xcor-of closest-hole) ycor) + (distancexy ycor (ycor-of closest-hole))       setxy x y      if ((distance-robot-tile + distance-tile-hole) > time-to-live-of closest-tile)        [         ifelse(random 1.0 < .5)        [                  set aux closest-tile            set closest-tile min-one-of (tiles with [who != who-of aux]) [distance myself]            ifelse (closest-tile = nobody)                [set closest-hole min-one-of holes [distance myself]                 stop]            [set closest-hole min-one-of holes [distance aux]                if (closest-hole != nobody and closest-tile != nobody)             [                          set x xcor              set y ycor              set distance-robot-tile (distancexy (xcor-of closest-tile) ycor) + (distancexy xcor (ycor-of closest-tile))                setxy xcor-of closest-tile ycor-of closest-tile              set distance-tile-hole (distancexy (xcor-of closest-hole) ycor) + (distancexy ycor (ycor-of closest-hole))               setxy x y              if ((distance-robot-tile + distance-tile-hole) > time-to-live-of closest-tile)               [               set closest-tile nobody]            ]            ]            stop        ]        [set closest-tile nobody        stop]        ]        if ((distance-robot-tile + distance-tile-hole) > time-to-live-of closest-hole)        [            set aux closest-hole            set aux2 closest-tile            set closest-hole min-one-of (holes with [who != who-of aux]) [distance aux2]            if (closest-hole != nobody)              [                  set x xcor                  set y ycor                  set distance-robot-tile (distancexy (xcor-of closest-tile) ycor) + (distancexy xcor (ycor-of closest-tile))                  setxy xcor-of closest-tile ycor-of closest-tile                  set distance-tile-hole (distancexy (xcor-of closest-hole) ycor) + (distancexy ycor (ycor-of closest-hole))                   setxy x y                  if ((distance-robot-tile + distance-tile-hole) > time-to-live-of closest-hole)                  [                      ;set closest-hole min-one-of holes [distance myself]                       set closest-tile nobody                  ]              ]                    ]     ]end;moves the agent one step with in the absolute heading h. ;It makes sure that any tile or robot that was in the destination location also moves, and so on recursively.;If a tile moves into a hole, both die.to move-one [h]  locals [pushed-agents oldh]  set oldh heading  set heading h  set pushed-agents (turtles-at dx dy) with [(breed = robots) or (breed = tiles)]  if (any pushed-agents) [    ask pushed-agents [move-one h]]  if (breed = tiles and (any holes-at dx dy))[    set holes-filled holes-filled + 1    ask holes-at dx dy [die]    die]  fd 1  set heading oldhend  @#$#@#$#@GRAPHICS-WINDOW2931360832817179.011000CC-WINDOW295502706622Command CenterBUTTON21487295120NILsetupNIL1TOBSERVERBUTTON214121295154NILupdateNIL1TOBSERVERBUTTON214155295188NILupdateT1TOBSERVERSLIDER41017643num-robotsnum-robots11002011NILSLIDER44317676tile-birth-probtile-birth-prob010.50.011NILSLIDER4109176142hole-birth-probhole-birth-prob010.50.011NILSLIDER476176109tile-lifetimetile-lifetime11005011NILSLIDER4142176175hole-lifetimehole-lifetime01005011NILMONITOR1028672335Scorescore21PLOT10334287623NILIterationScore0.0100.00.0100.0truefalsePENS"score" 1.0 0 -16777216 trueSLIDER4175176208delaydelay050.00.11NILMONITOR186286287335NILhighest-score31SWITCH2051329546watchwatch11-1000BUTTON1905229585def-paramsdefaultsNIL1TOBSERVERTEXTBOX297335941501The "def-params" button sets the parameters to the default values .\nWhen "watch" switch is on, you can see how robots move individually but they are not executed concurrently. However the score is similar.\nThe parameter "delay" is the number of seconds that the program waits before each iteration if "watch" is off. It is the number of seconds that the program waits before each robot movement if "watch" is on.\nIf the "group-size" parameter is set to a value bigger than or equal to num-robots, no grouping technique is used. If it's set to a value smaller than num-robots, group-technique heuristic is used.  (See Information for more details on the heuristic)SLIDER4208176241group-sizegroup-size1100411NIL@#$#@#$#@Name: Rosa L. Zavala-Gutierrezemail: zavalagu@engr.sc.eduID: 5555I understand that it is the responsibility of every member of theCarolina community to uphold an maintain the academic standards andintegrity of the University of South Carolina. Any member of theUniversity community, who has reasonable grounds to believe that aninfraction of the Code of Student Academic Responsibility hasoccurred, has an obligation to report the alleged violation.I certify that I have neither given nor received unauthorized aid on this problem set.----------------------------------------------------------The strategy consist in some modifications to the greedy strategy:The agents still look for the closest tile but sometimes (according to some rules and heuristics) the robot decides  not to go for the tile. This strategy improves the greedy by avoiding to end upwith all of the robots getting in each others' way. The modifications are:1. Choosing the closest-hole.	In the original program a robot look for the closest-tile and when it is found, the robot look for the closest-hole to him and then try to put  the tile in it. In some cases the closest-tile has a hole nearer to him than the robot抯 closest-hole and the robot loses time trying to put the tile in the wrong hole. For example, when the turtles are in the following position:H   TRHThe robot 慠

⌨️ 快捷键说明

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