Почему NetLo go работает по-разному с одинаковым синтаксисом и логами c в два периода - PullRequest
1 голос
/ 27 апреля 2020

все! Я борюсь с процедурами NetLo go. Код кажется правильным, но модель не может работать. Я надеюсь, что любой может помочь мне с этим. Я разработал эту модель как:

Period1: день> 0 и день <30 и время> 1, черепахи go для некоторых патчей (патч 1, патч 2, патч 3, ...) и остановка согласно правилам, каждый патч имеет максимальное хранилище черепах, если патч достигает своего максимального хранилища, попросите всех черепах на этом патче d ie.

Period2: if day> = 31 и day < 60 и время> 1, попросите вновь созданных черепах go к одним и тем же патчам в Period1, и каждый патч имеет различную максимальную память, если патч достигнет своего максимального объема, попросите всех черепах в этом патче d ie.

Логики c и синтаксис одинаковы в Period1 и Period2, единственная разница - это значение параметров. Однако Period1 работает, Period2 не работает. Я имею в виду, что в Period1 черепахи могут go к заплатам и d ie правильно; Черепахи даже не могут двигаться, и в Period2 ничего не произошло, но тики по-прежнему работают и без каких-либо напоминаний об ошибках. Почему это случилось? Кто-нибудь может дать мне несколько советов?

Любые комментарии и предложения будут по достоинству оценены. Код следующий:

globals [time day randomSeedVar]
breed [RiverVolumes RiverVolume]                        ;; ceate a breed to represent river volumes
breed [WaterVolumes WaterVolume]              ;; ceate a breed to represent irrigation volumes
breed [Crops Crop]
patches-own[CurrentStorage QgateMaxR QgateMaxR1 QgateMaxL QgateMaxL1]

to setup
  clear-all
  import-pcolors "patches.png"
  ifelse Seed?
  [
    random-seed RandomSeed
  ]
  [
    set randomSeedVar (random 2147483646)
    random-seed randomSeedVar
  ]
  set-default-shape RiverVolumes "default"
  set-default-shape WaterVolumes "drop"
  reset-ticks
end

to go
  set time ticks mod 24                                                                  ;; there are 24 ticks per day, one tick is equal to 1 hour
  set day floor (ticks / 24) + 1
  tick
  RiverInflow
  set-label
 if day > 0 and day < 30 and time > 1
  [
    FirstIrrigation
    RCropGrowth-1
    LCropGrowth-1
    DeathOfFirstWaterVolumes
    set-label
  ]

  if day = 30
  [
    ask patches with [pcolor = 64.2]
    [
      set CurrentStorage 0
    ]
  ]

  if day > 30 and day < 60 and time > 1
  [
    SecondIrrigation
    RCropGrowth-2
    LCropGrowth-2
    DeathOfSecondWaterVolumes
    set-label
  ]
end

to RiverInflow
  ask RiverVolumes [fd 1]
  create-RiverVolumes 1000
  [
    setxy 18 1
    set color blue - 2                                                              ;; set color of turtle to dark blue
    set size 0.5                                                                    ;; set size of turtle to 0.5
    set heading 180
  ]
end

to FirstIrrigation                                                                             ;; means flow the water to canals
  ifelse [CurrentStorage] of patch 35 1 < FirstStorage
  [
    move-to-right-canal1-1
    RGateCapacity-1
    RGateFlow1-1
    RFieldStorage-1
    RFieldStorageOverFlow-1
  ]
  [
    ifelse [CurrentStorage] of patch 1 1 < FirstStorage
    [
      move-to-left-canal1-1
      LGateCapacity-1
      LGateFlow1-1
      LFieldStorage-1
      LFieldStorageOverFlow-1
    ]
    [
       ask patches with [pycor = 0]
       [
         if any? RiverVolumes-here
         [
           ask RiverVolumes [die]
         ]

       ]
     ]
   ]
end

to move-to-right-canal1-1
  ask patches with [pcolor = 95.1]
  [
    if pxcor = 18 and pycor = 0
    [
      ask n-of QgateMaxFixed1 RiverVolumes-here
      [
        lt 90
        fd 1
      ]
    ]
  ]
end

to RGateCapacity-1
  ask patches with [pcolor = 48.8]                                                      ;; gates at the right side of the river
  [
    ifelse pxcor = 19
    [
      set QgateMaxR1 QgateMaxFixed1                                                     ;; set the capacity of the first right gate is QgateMaxFixed1
    ]
    [
      set QgateMaxR QgateMaxFixed
    ]
  ]
end

to RGateFlow1-1
  ask patches with [pcolor = 48.8 and pycor = 0]                               ;; gates at the right side of the river
  [
    ifelse pxcor = 19
    [
      ask n-of QgateMaxFixed1 RiverVolumes-here [fd 1]
    ]
    [
      ifelse CurrentStorage < FirstStorage
      [
        ifelse (count RiverVolumes-here - QgateMaxR) > 0
        [
          ask n-of QgateMaxFixed RiverVolumes-here [lt 90]
        ]
        [
          ask n-of (count RiverVolumes-here) RiverVolumes-here [lt 90]
        ]
      ]
      [
      ]
    ]
  ]
end

to RFieldStorage-1
  ask patches with [pcolor = 64.2]                                     ;; ask the fields at the right side of the river
  [
    set CurrentStorage (CurrentStorage + count RiverVolumes-here)
    sprout-WaterVolumes (count RiverVolumes-here)
    ask WaterVolumes-here
    [
      set color 97
      set size 0.8
      set heading 0
    ]
    ask RiverVolumes-here [die]
  ]
end

to RFieldStorageOverFlow-1
  ask patches with [pcolor = 64.2]
  [
    if CurrentStorage > FirstStorage
    [
      ask n-of (CurrentStorage - FirstStorage) WaterVolumes-here [die]
      set CurrentStorage FirstStorage
    ]
  ]
end

to move-to-left-canal1-1
  ask patches with [pcolor = 95.1]
  [
    if pxcor = 18 and pycor = 0
    [
        ask n-of QgateMaxFixed1 RiverVolumes-here
        [
          rt 90
          fd 1
        ]
    ]
  ]
end

to LGateCapacity-1
  ask patches with [ pcolor = 47.4]                                                     ;; gates at the left side of the river
  [
    ifelse pxcor = 17
    [
      set QgateMaxL1 QgateMaxFixed1                                                     ;; set the capacity of the first right gate is QgateMaxFixed1
    ]
    [
      set QgateMaxL QgateMaxFixed
    ]
  ]
end

to LGateFlow1-1
  ask patches with [pcolor = 47.4 and pycor = 0]                               ;; gates at the left side of the river
  [
    ifelse pxcor = 17
    [
      ask n-of QgateMaxFixed1 RiverVolumes-here [fd 1]
    ]
    [
      ifelse CurrentStorage < FirstStorage
      [
        ifelse (count RiverVolumes-here - QgateMaxL) > 0
        [
          ask n-of QgateMaxFixed RiverVolumes-here [rt 90]
        ]
        [
          ask n-of (count RiverVolumes-here) RiverVolumes-here [rt 90]
        ]
      ]
      [
      ]
    ]
  ]
end

to LFieldStorage-1
  ask patches with [pcolor = 64.2]                                     ;; ask the fields at the right side of the river
  [
    set CurrentStorage (CurrentStorage + count RiverVolumes-here)
    sprout-WaterVolumes (count RiverVolumes-here)
    ask WaterVolumes-here
    [
      set color 97
      set size 0.8
      set heading 0
    ]
    ask RiverVolumes-here [die]
  ]
end

to LFieldStorageOverFlow-1
  ask patches with [pcolor = 64.2]                                   ;; ask the one of the fields which used to store the irrigation water
  [
    if CurrentStorage > FirstStorage                                                       ;; if the current storage exceeds the maximum storage
    [
      ask n-of (CurrentStorage - FirstStorage) WaterVolumes-here [die]                ;; ask the extra storage volumes to die (so they go out the system)
      set CurrentStorage FirstStorage                                                      ;; set current storage to the FirsIrrigationDemand
    ]
  ]
end

to RCropGrowth-1
  ask patches with [pcolor = 22.6]
  [
    if pxcor > 20 and ([CurrentStorage] of patch (pxcor - 1) pycor) = FirstStorage
    [
      sprout-Crops 1
      [
        set shape "plant"
        set size 0.1
        set color green
      ]
    ]
  ]
end

to LCropGrowth-1
  ask patches with [pcolor = 22.6]
  [
    if pxcor < 16 and ([CurrentStorage] of patch (pxcor + 1) pycor) = FirstStorage
    [
      sprout-Crops 1
      [
        set shape "plant"
        set size 0.1
        set color green
      ]
    ]
  ]
end

to DeathOfFirstWaterVolumes
  ask patches with [pcolor = 64.2 and pxcor > 20 and pycor = 1]
  [
    if any? Crops-on patch 36 1
    [
      ask WaterVolumes-here [die]
    ]
  ]

  ask patches with [pcolor = 64.2 and pxcor < 16  and pycor = 1]
  [
    if any? Crops-on patch 0 1
    [
      ask WaterVolumes-here [die]
    ]
  ]
end

to SecondIrrigation                                                                             ;; means flow the water to canals
  ifelse [CurrentStorage] of patch 35 1 < SecondStorage
  [
    move-to-right-canal1-2
    RGateCapacity-2
    RGateFlow1-2
    RFieldStorage-2
    RFieldStorageOverFlow-2
  ]
  [
    ifelse [CurrentStorage] of patch 1 1 < SecondStorage
    [
      move-to-left-canal1-2
      LGateCapacity-2
      LGateFlow1-2
      LFieldStorage-2
      LFieldStorageOverFlow-2
    ]
    [
      ask patches with [pycor = 0]
      [
        if any? RiverVolumes-here
        [
          ask RiverVolumes [die]
        ]
      ]
    ]
  ]
end

to move-to-right-canal1-2
  ask patches with [pcolor = 95.1]
  [
    if pxcor = 18 and pycor = 0
    [
      ask n-of QgateMaxFixed1 RiverVolumes-here
      [
        lt 90
        fd 1
      ]
    ]
  ]
end

to RGateCapacity-2
  ask patches with [pcolor = 48.8]                                                      ;; gates at the right side of the river
  [
    ifelse pxcor = 19
    [
      set QgateMaxR1 QgateMaxFixed1                                                     ;; set the capacity of the first right gate is QgateMaxFixed1
    ]
    [
      set QgateMaxR QgateMaxFixed
    ]
  ]
end

to RGateFlow1-2
  ask patches with [pcolor = 48.8 and pycor = 0]                               ;; gates at the right side of the river
  [
    ifelse pxcor = 19
    [
      ask n-of QgateMaxFixed1 RiverVolumes-here [fd 1]
    ]
    [
      ifelse CurrentStorage < SecondStorage
      [
        ifelse (count RiverVolumes-here - QgateMaxR) > 0
        [
          ask n-of QgateMaxFixed RiverVolumes-here [lt 90]
        ]
        [
          ask n-of (count RiverVolumes-here) RiverVolumes-here [lt 90]
        ]
      ]
      [
      ]
    ]
  ]
end

to RFieldStorage-2
  ask patches with [pcolor = 64.2]                                     ;; ask the fields at the right side of the river
  [
    set CurrentStorage (CurrentStorage + count RiverVolumes-here)
    sprout-WaterVolumes (count RiverVolumes-here)
    ask WaterVolumes-here
    [
      set color 97
      set size 0.8
      set heading 0
    ]
    ask RiverVolumes-here [die]
  ]
end

to RFieldStorageOverFlow-2
  ask patches with [pcolor = 64.2]
  [
    if CurrentStorage > SecondStorage                                                       ;; if the current storage exceeds the maximum storage
    [
      ask n-of (CurrentStorage - SecondStorage) WaterVolumes-here [die]                ;; ask the extra storage volumes to die (so they go out the system)
      set CurrentStorage SecondStorage
    ]
  ]
end

to move-to-left-canal1-2
  ask patches with [pcolor = 95.1]
  [
    if pxcor = 18 and pycor = 0
    [
        ask n-of QgateMaxFixed1 RiverVolumes-here
        [
          rt 90
          fd 1
        ]
    ]
  ]
end

to LGateCapacity-2
  ask patches with [ pcolor = 47.4]                                                     ;; gates at the left side of the river
  [
    ifelse pxcor = 17
    [
      set QgateMaxL1 QgateMaxFixed1                                                     ;; set the capacity of the first right gate is QgateMaxFixed1
    ]
    [
      set QgateMaxL QgateMaxFixed
    ]
  ]
end

to LGateFlow1-2
  ask patches with [pcolor = 47.4 and pycor = 14]                               ;; gates at the left side of the river
  [
    ifelse pxcor = 17
    [
      ask n-of QgateMaxFixed1 RiverVolumes-here [fd 1]
    ]
    [
      ifelse CurrentStorage < SecondStorage
      [
        ifelse (count RiverVolumes-here - QgateMaxL) > 0
        [
          ask n-of QgateMaxFixed RiverVolumes-here [rt 90]
        ]
        [
          ask n-of (count RiverVolumes-here) RiverVolumes-here [rt 90]
        ]
      ]
      [
      ]
    ]
  ]
end

to LFieldStorage-2
  ask patches with [pcolor = 64.2]                                     ;; ask the fields at the right side of the river
  [
    set CurrentStorage (CurrentStorage + count RiverVolumes-here)
    sprout-WaterVolumes (count RiverVolumes-here)
    ask WaterVolumes-here
    [
      set color 97
      set size 0.8
      set heading 0
    ]
    ask RiverVolumes-here [die]
  ]
end

to LFieldStorageOverFlow-2
  ask patches with [pcolor = 64.2]
  [
    if CurrentStorage > SecondStorage                                                       ;; if the current storage exceeds the maximum storage
    [
      ask n-of (CurrentStorage - SecondStorage) WaterVolumes-here [die]                ;; ask the extra storage volumes to die (so they go out the system)
      set CurrentStorage SecondStorage
    ]
  ]
end

to RCropGrowth-2
  ask patches with [pcolor = 22.6]
  [
    if pxcor > 20 and ([CurrentStorage] of patch (pxcor - 1) pycor) = FirstStorage
    [
      sprout-Crops 1
      [
        set shape "plant"
        set size 0.2
        set color green
      ]
    ]
  ]
end

to LCropGrowth-2
  ask patches with [pcolor = 22.6]
  [
    if pxcor < 16 and ([CurrentStorage] of patch (pxcor + 1) pycor) = FirstStorage
    [
      sprout-Crops 1
      [
        set shape "plant"
        set size 0.2
        set color green
      ]
    ]
  ]
end

to DeathOfSecondWaterVolumes
  ask patches with [pcolor = 64.2 and pxcor > 20 and pycor = 1]
  [
    if any? Crops-on patch 36 1
    [
      ask WaterVolumes-here [die]
    ]
  ]

  ask patches with [pcolor = 64.2 and pxcor < 16  and pycor = 1]
  [
    if any? Crops-on patch 0 1
    [
      ask WaterVolumes-here [die]
    ]
  ]
end

to set-label
  ask patches with [pcolor = 64.2 or pcolor = 98.4 or pcolor = 47.4 or pcolor = 48.8 or pcolor = 94.5 or pcolor = 44.9 or pcolor = 95.1]
  [
    ifelse (count turtles-here) > 0
    [
      set plabel (count turtles-here)
      set plabel-color black
    ]
    [set plabel ""]
  ]
end

1 Ответ

2 голосов
/ 28 апреля 2020

Итак, я собираюсь сделать предположение, поскольку без вашей истинной процедуры настройки мы не сможем запустить модель. (Нам также потребуются значения переменных вашего интерфейса.) Но первая строка SecondProcedure - это

ifelse [CurrentStorage] of patch 35 15 < SecondStorage

Your setup или, возможно, просто использование NetLo go по умолчанию, вероятно, инициализировавшей CurrentStorage этого патча на ноль. Возможно ли, что в вашей первой процедуре CurrentStorage этого патча был заполнен до уровня, большего или равного SecondStorage, и того же уровня для патча 11? Если это так, ваш SecondProcedure, скорее всего, не даст вам желаемого результата. Вы можете проверить это (как предложил Сет), поставив

show [CurrentStorage] of patch 35 15

перед ifelse, чтобы увидеть, каково его значение на самом деле. Если я прав, это не то, что вы ожидаете, и вам нужно будет повторно инициализировать это и, вероятно, некоторые другие переменные между вашим первым и вторым периодом.

Команда show неоценима - это отладка. Я предлагаю вам использовать это свободно!

Надеюсь, это поможет, Чарльз

...