#NEWLINE# def add_objective( self , expr , name = None , scope = None ) : #NEWLINE# #INDENT# 'Adds an objective to the driver.\n\n        expr: string\n            String containing the objective expression.\n\n        name: string (optional)\n            Name to be used to refer to the objective in place of the expression\n            string.\n\n        scope: object (optional)\n            The object to be used as the scope when evaluating the expression.\n\n         ' #NEWLINE# if ( ( self . _max_objectives > 0 ) and ( len ( self . _objectives ) >= self . _max_objectives ) ) : #NEWLINE# #INDENT# self . parent . raise_exception ( ( "Can't add objective '%s'. Only %d objectives are allowed" % ( expr , self . _max_objectives ) ) , RuntimeError ) #NEWLINE# #UNINDENT# expr = _remove_spaces ( expr ) #NEWLINE# if ( expr in self . _objectives ) : #NEWLINE# #INDENT# self . parent . raise_exception ( ( "Trying to add objective '%s' to driver, but it's already there" % expr ) , AttributeError ) #NEWLINE# #UNINDENT# if ( ( name is not None ) and ( name in self . _objectives ) ) : #NEWLINE# #INDENT# self . parent . raise_exception ( ( "Trying to add objective '%s' to driver using name '%s', but name is already used" % ( expr , expreval ) ) , AttributeError ) #NEWLINE# #UNINDENT# scope = self . _get_scope ( scope ) #NEWLINE# try : #NEWLINE# #INDENT# expreval = Objective ( expr , scope ) #NEWLINE# #UNINDENT# except Exception as err : #NEWLINE# #INDENT# self . parent . raise_exception ( str ( err ) , type ( err ) ) #NEWLINE# #UNINDENT# name = ( expr if ( name is None ) else name ) #NEWLINE# if IDriver . providedBy ( self . parent ) : #NEWLINE# #INDENT# self . parent . config_changed ( ) #NEWLINE# #UNINDENT# self . _objectives [ name ] = expreval