Skip to main content
. 2018 Apr 22;18(4):1287. doi: 10.3390/s18041287
Algorithm 1 Timed Protocol for Cooperation with Disagreement Correction (code for pi)
  • 1:

    Constants:

  • 2:

    members={p1,p2,,pn}: the system vehicles.

  • 3:

    ⊥: the unavailability symbol denotes a void entry, and the default return value.

  • 4:

    Sbound: the maximum offset among vehicles.

  • 5:

    D: the maximum time that a message time can live in the network.

  • 6:

    Rlength>2Sbound+D: round size

  • 7:

    Variables:

  • 8:

    r0: Current communication round.

  • 9:

    data[n]={}: Application data where data[k] is a set that consists of the current operative mode and the state of vehicle k at round r from member pk.

  • 10:

    Interface

  • 11:

    gossipSend(): Disseminate information to the members.

  • 12:

    gossipReceive(): Dispatch arriving messages.

  • 13:

    readState(): Return the state of the vehicle.

  • 14:

    pathPlanning(): Computes the path according to the operational mode and the state of the system.

  • 15:

    Upon gossipReceive(j,<rj,dataj>)

  • 16:

    if (r=rj) then

  • 17:

    for all pkmembers do

  • 18:

      if (dataj[k] and ik) or (k=j) then

  • 19:

       data[k]dataj[k]

  • 20:

      end if

  • 21:

    end for

  • 22:

    end if

  • 23:

    loop

  • 24:

    if clock()(Rlength·r+Sbound,Rlength·(r+1)(Sbound+D)) then

  • 25:

      gossipSend(i,<r,data>)

  • 26:

    end if

  • 27:

    if r<clock()÷Rlength then

  • 28:

      (s,r)(data,clock()÷Rlength)

  • 29:

      data{,}

  • 30:

      modeautonomous

  • 31:

      if s[i].mode=s[j].modepjmembers then

  • 32:

       modecooperative

  • 33:

      end if

  • 34:

      data[i]{mode,readState()}

  • 35:

      pathPlanning(s,mode)

  • 36:

    end if

  • 37:

    end loop