parameters: (self, mode)
return_statement: return success
docstring: setMode(PlatoonMode) -> bool
  
          Returns whether the change to the requested platoon mode could be performed safely.
          Only checks for safety with regard to leaders.
          Note: safety assumptions of previous versions are dropped, now
docstring_summary: setMode(PlatoonMode) -> bool
docstring_tokens: setMode ( PlatoonMode ) - > bool
function: def setMode(self, mode):
          '''setMode(PlatoonMode) -> bool
  
          Returns whether the change to the requested platoon mode could be performed safely.
          Only checks for safety with regard to leaders.
          Note: safety assumptions of previous versions are dropped, now
          '''
          old_mode = self.getMode()
          success = False
          if mode == PlatoonMode.NONE:
              if self.size() == 1:
                  if (self._vehicles[0].isSwitchSafe(mode)):
                      self._vehicles[0].setPlatoonMode(mode)
                      success = True
                  else:
                      success = False
              else:
                  # PlatoonMode.NONE is only admissible for solitons
                  success = False
  
          elif mode == PlatoonMode.LEADER:
              if self._vehicles[0].isSwitchSafe(mode):
                  self._vehicles[0].setPlatoonMode(mode)
                  for veh in self._vehicles[1:]:
                      if veh.isSwitchSafe(PlatoonMode.FOLLOWER):
                          veh.setPlatoonMode(PlatoonMode.FOLLOWER)
                  success = True
              else:
                  success = False
  
          elif mode == PlatoonMode.CATCHUP:
              if self._vehicles[0].isSwitchSafe(mode):
                  self._vehicles[0].setPlatoonMode(mode)
                  for veh in self._vehicles[1:]:
                      if veh.isSwitchSafe(PlatoonMode.CATCHUP_FOLLOWER):
                          veh.setPlatoonMode(PlatoonMode.CATCHUP_FOLLOWER)
                  success = True
              else:
                  success = False
  
          elif mode == PlatoonMode.CATCHUP_FOLLOWER or mode == PlatoonMode.FOLLOWER:
              if self._vehicles[0].isSwitchSafe(mode):
                  self._vehicles[0].setPlatoonMode(mode)
                  for veh in self._vehicles[1:]:
                      if veh.isSwitchSafe(mode):
                          veh.setPlatoonMode(mode)
                  success = True
              else:
                  success = False
  
          else:
              raise ValueError("Unknown PlatoonMode %s" % mode)
  
          if rp.VERBOSITY >= 3 and success and not old_mode == mode:
              report("Activated mode {mode} for platoon '{pltnID}' ({pltn_members})".format(
                  mode=mode, pltnID=self.getID(), pltn_members=str([veh.getID() for veh in self.getVehicles()])))
  
          return success
function_tokens: def setMode ( self , mode ) : old_mode = self . getMode ( ) success = False if mode == PlatoonMode . NONE : if self . size ( ) == 1 : if ( self . _vehicles [ 0 ] . isSwitchSafe ( mode ) ) : self . _vehicles [ 0 ] . setPlatoonMode ( mode ) success = True else : success = False else : # PlatoonMode.NONE is only admissible for solitons success = False elif mode == PlatoonMode . LEADER : if self . _vehicles [ 0 ] . isSwitchSafe ( mode ) : self . _vehicles [ 0 ] . setPlatoonMode ( mode ) for veh in self . _vehicles [ 1 : ] : if veh . isSwitchSafe ( PlatoonMode . FOLLOWER ) : veh . setPlatoonMode ( PlatoonMode . FOLLOWER ) success = True else : success = False elif mode == PlatoonMode . CATCHUP : if self . _vehicles [ 0 ] . isSwitchSafe ( mode ) : self . _vehicles [ 0 ] . setPlatoonMode ( mode ) for veh in self . _vehicles [ 1 : ] : if veh . isSwitchSafe ( PlatoonMode . CATCHUP_FOLLOWER ) : veh . setPlatoonMode ( PlatoonMode . CATCHUP_FOLLOWER ) success = True else : success = False elif mode == PlatoonMode . CATCHUP_FOLLOWER or mode == PlatoonMode . FOLLOWER : if self . _vehicles [ 0 ] . isSwitchSafe ( mode ) : self . _vehicles [ 0 ] . setPlatoonMode ( mode ) for veh in self . _vehicles [ 1 : ] : if veh . isSwitchSafe ( mode ) : veh . setPlatoonMode ( mode ) success = True else : success = False else : raise ValueError ( "Unknown PlatoonMode %s" % mode ) if rp . VERBOSITY >= 3 and success and not old_mode == mode : report ( "Activated mode {mode} for platoon '{pltnID}' ({pltn_members})" . format ( mode = mode , pltnID = self . getID ( ) , pltn_members = str ( [ veh . getID ( ) for veh in self . getVehicles ( ) ] ) ) ) return success