Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Netlogo中的BOIDS规则使代理在其组中聚集?_Netlogo_Flock_Boids - Fatal编程技术网

如何使用Netlogo中的BOIDS规则使代理在其组中聚集?

如何使用Netlogo中的BOIDS规则使代理在其组中聚集?,netlogo,flock,boids,Netlogo,Flock,Boids,以下是我想做的: 我需要所有代理使用BOIDS规则在一个组中向前移动 我希望他们在碰壁后能够转身(我的世界不是包裹的,他们不能穿过墙到达世界的另一边) 这是我的密码: globals [nearest-teammates teammmembers] turtles-own [ myteamset teamID myID teammatesID ] to setup-groups let teamCounter 1 ask turtles [ if myteamset =

以下是我想做的:

  • 我需要所有代理使用BOIDS规则在一个组中向前移动

  • 我希望他们在碰壁后能够转身(我的世界不是包裹的,他们不能穿过墙到达世界的另一边)

  • 这是我的密码:

    globals [nearest-teammates teammmembers]
    
    turtles-own [ myteamset teamID myID teammatesID ]
    
    to setup-groups
    
      let teamCounter 1 
      ask turtles [
        if myteamset = nobody [
          let possible-teammates other turtles with [ myteamset = nobody ]
          ifelse count possible-teammates > 1 [
            set myteamset ( turtle-set self n-of 2 possible-teammates )
            let ids sort [myID] of myteamset
            set teammmembers myteamset
            set nearest-teammates min-one-of myteamset[distance myself]
    
            let tempteam teamCounter         
            set teamCounter teamCounter + 1
            ask myteamset [
              set teammatesID ids
              set myteamset teammmembers
              set teamID tempteam
            ]
    
          ] [
            show "Not enough turtles to make a new team!"
          ]
        ]
      ]
    end
    
    植绒部分:

    to move-in-groups
    
      let teamNumbers remove-duplicates [teamID] of turtles
      foreach teamNumbers [                         
        ask one-of turtles with [ teamID = ? ] [
          if myteamset != nobody [
            ask myteamset [
            set  heading mean-heading [ heading ] of myteamset
             ifelse distance one-of turtles with [ teamID = ? ] < 3
             [separate]
             [align
               cohere]]
              fd 1 ]]]
    end
    
    我得到的错误是:

    SUM expected input to be a list but got the number -0.961261695938319 instead.
    error while turtle 4 running SUM
      called by procedure AVERAGE-FLOCKMATE-HEADING
      called by procedure ALIGN
      called by (command task from: procedure MOVE-IN-GROUPS)
      called by procedure MOVE-IN-GROUPS
      called by procedure GO
      called by Button 'go'
    

    我该怎么办?我需要帮助·'''<代码>(>▂ 您得到的错误发生在这一行:

    let x-component sum [dx] of nearest-teammates
    
    NetLogo告诉您,您试图向
    sum
    传递一个数字,而不是向其传递一个列表。怎么会发生这种情况?如果
    最近的队友
    包含一个代理,而不是一个代理集,则会发生这种情况

    让我们看看你在哪里定义了最近的队友:

    set nearest-teammates min-one-of myteamset[distance myself]
    
    你能看到问题吗?你正在使用,它只给你一个代理

    例如,如何获得10个最接近的代理,而不是一个最接近的代理?幸运的是,NetLogo有一个原语可以做到这一点:。以下是您将如何使用它:

    set nearest-teammates min-n-of 10 myteamset [ distance myself ]
    

    当然,用你想要的队友数量替换
    10

    是的,这是itt~现在我知道问题出在哪里了。但在我更改了它之后,
    中出现了一个新错误,最多转一圈(减去标题新标题)max turn
    和所述错误
    SUBTRACT-headers预期输入为一个数字,但得到的却是列表[346 213 4]。
    我试图找到列表的来源,但无济于事:'(我相信我们可以解决这个问题,但我认为您需要为这个问题单独提出一个问题,并发布更多的代码,这样我们就可以在调用
    的地方关闭
    。)。。。
    
    set nearest-teammates min-n-of 10 myteamset [ distance myself ]