用NetLogo模拟交通路段的“放车”不能正常工作是怎么回事?

时间:2019-03-30 11:33:27

标签: multiple-users patch user-agent simulation

在映像look i create the code"place car" but not found the cars 下创建环境NetLogo之后 此代码不起作用!  看一下代码:

to place-cars

  ;make a random placement of cars
  ask n-of (num-of-cars / 5) patches with [meaning = "road-up"] [
    if not any? cars-on patch pxcor (pycor + 1) and not any? cars-here and not any? cars-on patch pxcor (pycor - 1) and not any? patches with [meaning = "crossing"] in-radius 2 [
      sprout-cars 1 [
        set size 2
        set will-turn? "maybe"
        set will-stop? "maybe"
        set shape "car top"
        set heading 0
        let s random 10
        if s < 7 [set maxSpeed speed-limit - 15 + random 16]
        if s = 7 [set maxSpeed speed-limit - 20 + random 6]
        if s > 7 [set maxSpeed speed-limit + random 16]
        set speed maxSpeed - random 20
      ]
    ]
  ]

  ask n-of (num-of-cars / 3) patches with [meaning = "road-down" and count turtles-on neighbors = 0] [
    if not any? cars-on patch pxcor (pycor + 1) and not any? cars-here and not any? cars-on patch pxcor (pycor - 1) and not any? patches with [meaning = "crossing"] in-radius 2 [
      sprout-cars 1 [
        set size 2
        set shape "car top"
        set politeness basic-politeness + random (101 - basic-politeness)
        if random 100 > basic-politeness [set politeness random 21]
        set heading 180
        set will-turn? "maybe"
        set will-stop? "maybe"
        let s random 10
        if s < 7 [set maxSpeed speed-limit - 15 + random 16]
        if s = 7 [set maxSpeed speed-limit - 20 + random 6]
        if s > 7 [set maxSpeed speed-limit + random 16]
        set speed maxSpeed - random 20
      ]
    ]
  ]

  ask n-of (num-of-cars / 3) patches with [meaning = "road-left" and count turtles-on neighbors = 0] [
    if not any? cars-on patch (pxcor + 1) pycor and not any? cars-here and not any? cars-on patch (pxcor - 1) pycor and not any? patches with [meaning = "crossing"] in-radius 2 [
      sprout-cars 1 [
        set will-turn? "maybe"
        set will-stop? "maybe"
        set size 2
        set shape "car top"
        set heading 270
        let s random 10
        if s < 7 [set maxSpeed speed-limit - 15 + random 16]
        if s = 7 [set maxSpeed speed-limit - 20 + random 6]
        if s > 7 [set maxSpeed speed-limit + random 16]
        set speed maxSpeed - random 20
      ]
    ]
  ]

  while [count cars < num-of-cars] [
    ask one-of patches with [meaning = "road-right"] [
      if not any? cars-on patch (pxcor + 1) pycor and not any? cars-here and not any? cars-on patch (pxcor - 1) pycor and not any? patches with [meaning = "crossing"] in-radius 2 [
        sprout-cars 1 [
          set will-turn? "maybe"
          set will-stop? "maybe"
          set size 2
          set shape "car top"

          set heading 90
          let s random 10
          if s < 7 [set maxSpeed speed-limit - 15 + random 16]
          if s = 7 [set maxSpeed speed-limit - 20 + random 6]
          if s > 7 [set maxSpeed speed-limit + random 16]
          set speed maxSpeed - random 20
        ]
      ]
    ]
  ]

end

0 个答案:

没有答案