Ejemplo n.º 1
0
 def setParameter(self,parametername,parametervalue):
     if not parametername in ['randomseed']:
         print __doc__
         raise Exception("Invalid parameter '%s' for gameguidance." % parametername)
     GuidanceBase.setParameter(self,parametername,parametervalue)
     if parametername=='randomseed':
         self._rndchoose=random.Random(parametervalue).choice
Ejemplo n.º 2
0
 def __init__(self):
     GuidanceBase.__init__(self)
     self.setParameter('lookahead',15)
     self.setParameter('randomseed',time.time())
     self.setParameter('rerouteafter',1)
     self._lastroute=[]
     self._steps_to_reroute=0
Ejemplo n.º 3
0
 def setParameter(self,parametername,parametervalue):
     if not parametername in ['maxdepth','mindepth','randomseed']:
         print __doc__
         raise Exception("Invalid parameter '%s' for gameguidance." % parametername)
     GuidanceBase.setParameter(self,parametername,parametervalue)
     if parametername=='randomseed':
         self._rndchoose=random.Random(parametervalue).choice
Ejemplo n.º 4
0
 def __init__(self):
     GuidanceBase.__init__(self)
     self._NUM_TABU_ACTIONS = None
     self._NUM_TABU_STATES = None
     self._NUM_TABU_TRANSITIONS = None
     self._tabulist_action = None
     self._tabulist_state = None
     self._tabulist_transition = None
Ejemplo n.º 5
0
 def __init__(self):
     GuidanceBase.__init__(self)
     self._guidances = []
     self._guidanceOpts = []
     self._covs = []
     self._currIndex = -1
     self._model = None
     self._filename = None
Ejemplo n.º 6
0
 def __init__(self):
     GuidanceBase.__init__(self)
     self._guidances = []
     self._guidanceOpts = []
     self._covs = []
     self._currIndex = -1
     self._model = None
     self._filename = None
Ejemplo n.º 7
0
 def __init__(self):
     GuidanceBase.__init__(self)
     self._NUM_TABU_ACTIONS = None
     self._NUM_TABU_STATES = None
     self._NUM_TABU_TRANSITIONS = None
     self._tabulist_action = None
     self._tabulist_state = None
     self._tabulist_transition = None
Ejemplo n.º 8
0
 def setParameter(self,parametername,parametervalue):
     if not parametername in ['lookahead','randomseed','rerouteafter']:
         print __doc__
         raise Exception("Invalid parameter '%s' for gameguidance." % parametername)
     GuidanceBase.setParameter(self,parametername,parametervalue)
     if parametername=='randomseed':
         self._rndchoose=random.Random(parametervalue).choice
     elif parametername=='rerouteafter':
         self._steps_to_reroute=self.getParameter(parametername)
Ejemplo n.º 9
0
 def __init__(self):
     GuidanceBase.__init__(self)
     # default parameters:
     self.setParameter("transitionweight", 0)
     self.setParameter("searchdepth", 10)
     self.setParameter("searchorder", "shortestfirst")
     self.setParameter("maxtransitions", 10000)
     self.setParameter("greedy", 0)
     self.setParameter("searchconstraint", "noloops")
Ejemplo n.º 10
0
 def __init__(self):
     GuidanceBase.__init__(self)
     # default parameters:
     self.setParameter("transitionweight", 0)
     self.setParameter("searchdepth", 10)
     self.setParameter("searchorder", "shortestfirst")
     self.setParameter("maxtransitions", 10000)
     self.setParameter("greedy", 0)
     self.setParameter("searchconstraint", "noloops")
Ejemplo n.º 11
0
 def setParameter(self, paramname, paramvalue):
     accepted = ("numtabuactions", "numtabustates", "numtabutransitions")
     if paramname == "numtabuactions":
         self._NUM_TABU_ACTIONS = self._parseSize(paramname, paramvalue)
     elif paramname == "numtabustates":
         self._NUM_TABU_STATES = self._parseSize(paramname, paramvalue)
     elif paramname == "numtabutransitions":
         self._NUM_TABU_TRANSITIONS = self._parseSize(paramname, paramvalue)
     else:
         print __doc__
         raise Exception("Invalid parameter '%s' for tabuguidance. Accepted parameters: %s" % paramname, accepted)
     GuidanceBase.setParameter(self, paramname, paramvalue)
Ejemplo n.º 12
0
    def markExecuted(self,transition_object):
        locked=0 # keeps if this function has acquired search_front_lock

        # Update advances to the 'official' coverage object
        GuidanceBase.markExecuted(self,transition_object)
        
        # Then cleanup search front: remove every entry from the
        # search front if it starts with some other than the executed
        # transition_object, and shorten entries starting with the
        # transition.

        # Shortening cannot be done if paths are too short, therefore,
        # if the thread is running, let it do its job 
        while 1:
            self.search_front_lock.acquire()
            locked=1
            if len(self.search_front[0][1])<2:
                # There is just one action in the search front, it can
                # be safely removed only if the thread is no more
                # running, that is, time_to_quit signal has been
                # given.
                if self.time_to_quit: break
                else:
                    self.search_front_lock.release()
                    locked=0
                    time.sleep(1) # give some time to the thread
                    continue
                    
                # NOTE: This may cause a livelock if there are
                # deadlocks in the model: search front is not getting
                # any deeper. There should not be deadlocks!
            else:
                break
            
        # If the thread is quitting, there is no reason to
        # cleanup the search front
        #if self.time_to_quit:
        #    if locked: self.search_front_lock.release()
        #    return

        # This function must own the lock now, search_front can be
        # edited.
        new_search_front=[]
        for points,path,reqs in self.search_front:
            if path[0]==transition_object:
                self._front_shortened=1 # message to the thread
                new_search_front.append([points,path[1:],reqs])
        self.search_front=new_search_front
        self.log("Search front reduced to length %s and depth %s" %
                 (len(self.search_front),len(self.search_front[0][1])))
        self.search_front_lock.release()
Ejemplo n.º 13
0
    def markExecuted(self, transition_object):
        locked = 0  # keeps if this function has acquired search_front_lock

        # Update advances to the 'official' coverage object
        GuidanceBase.markExecuted(self, transition_object)

        # Then cleanup search front: remove every entry from the
        # search front if it starts with some other than the executed
        # transition_object, and shorten entries starting with the
        # transition.

        # Shortening cannot be done if paths are too short, therefore,
        # if the thread is running, let it do its job
        while 1:
            self.search_front_lock.acquire()
            locked = 1
            if len(self.search_front[0][1]) < 2:
                # There is just one action in the search front, it can
                # be safely removed only if the thread is no more
                # running, that is, time_to_quit signal has been
                # given.
                if self.time_to_quit: break
                else:
                    self.search_front_lock.release()
                    locked = 0
                    time.sleep(1)  # give some time to the thread
                    continue

                # NOTE: This may cause a livelock if there are
                # deadlocks in the model: search front is not getting
                # any deeper. There should not be deadlocks!
            else:
                break

        # If the thread is quitting, there is no reason to
        # cleanup the search front
        #if self.time_to_quit:
        #    if locked: self.search_front_lock.release()
        #    return

        # This function must own the lock now, search_front can be
        # edited.
        new_search_front = []
        for points, path, reqs in self.search_front:
            if path[0] == transition_object:
                self._front_shortened = 1  # message to the thread
                new_search_front.append([points, path[1:], reqs])
        self.search_front = new_search_front
        self.log("Search front reduced to length %s and depth %s" %
                 (len(self.search_front), len(self.search_front[0][1])))
        self.search_front_lock.release()
Ejemplo n.º 14
0
 def setParameter(self, paramname, paramvalue):
     accepted = ("numtabuactions", "numtabustates", "numtabutransitions")
     if paramname == 'numtabuactions':
         self._NUM_TABU_ACTIONS = self._parseSize(paramname, paramvalue)
     elif paramname == 'numtabustates':
         self._NUM_TABU_STATES = self._parseSize(paramname, paramvalue)
     elif paramname == 'numtabutransitions':
         self._NUM_TABU_TRANSITIONS = self._parseSize(paramname, paramvalue)
     else:
         print __doc__
         raise Exception(
             "Invalid parameter '%s' for tabuguidance. Accepted parameters: %s"
             % paramname, accepted)
     GuidanceBase.setParameter(self, paramname, paramvalue)
Ejemplo n.º 15
0
    def markExecuted(self, transition):

        # special case: add the very first (source) state to the tabu-list
        statelist = self._tabulist_state
        if statelist and len(statelist) == 0:
            statelist.add(transition.getSourceState())

        # add actions/states/transitions to tabulists if given tabulist exists
        if self._tabulist_action is not None:
            self._tabulist_action.add(str(transition.getAction()))
        if self._tabulist_state is not None:
            self._tabulist_state.add(str(transition.getDestState()))
        if self._tabulist_transition is not None:
            self._tabulist_transition.add(str(transition))

        GuidanceBase.markExecuted(self, transition)
Ejemplo n.º 16
0
    def __init__(self):
        GuidanceBase.__init__(self)
        self.setParameter('maxdepth',100)
        self.setParameter('mindepth',1)
        self.setParameter('randomseed',time.time())
        self._lastroute=[]
        self._steps_to_reroute=0

        # search front is a list of triplets: (score, path, coverage)
        # where score is a pair: (coverage_percentage, steps since
        # last change coverage_percentage). Thus, the bigger the
        # number of steps, the faster the final coverage_percentage is
        # achieved.
        self.search_front=[]
        self._thread_id=None
        self._front_shortened=0 # msg from markExecuted to thread
Ejemplo n.º 17
0
    def markExecuted(self, transition):

        # special case: add the very first (source) state to the tabu-list
        statelist = self._tabulist_state
        if statelist and len(statelist) == 0:
            statelist.add(transition.getSourceState())

        # add actions/states/transitions to tabulists if given tabulist exists
        if self._tabulist_action is not None:
            self._tabulist_action.add(str(transition.getAction()))
        if self._tabulist_state is not None:
            self._tabulist_state.add(str(transition.getDestState()))
        if self._tabulist_transition is not None:
            self._tabulist_transition.add(str(transition))

        GuidanceBase.markExecuted(self, transition)
Ejemplo n.º 18
0
    def __init__(self):
        GuidanceBase.__init__(self)
        self.setParameter('maxdepth', 100)
        self.setParameter('mindepth', 1)
        self.setParameter('randomseed', time.time())
        self._lastroute = []
        self._steps_to_reroute = 0

        # search front is a list of triplets: (score, path, coverage)
        # where score is a pair: (coverage_percentage, steps since
        # last change coverage_percentage). Thus, the bigger the
        # number of steps, the faster the final coverage_percentage is
        # achieved.
        self.search_front = []
        self._thread_id = None
        self._front_shortened = 0  # msg from markExecuted to thread
Ejemplo n.º 19
0
 def prepareForRun(self):
     nonexit = "Nonexisting string"
     if self.getParameter("help", nonexit) != nonexit:
         print __doc__
         raise Exception("Asked only for help")
     GuidanceBase.prepareForRun(self)
     if len(self._requirements) != 1:
         raise Exception("Needs exactly one requirement")
     if not self._testmodel:
         raise Exception("Model should be given")
     self._stored_path = []
     self._to_sleep_actions =\
                self._testmodel.matchedActions(set([self._sleep_ts_re]))
     self._last_go_back = False
     self._search_state = GoodState
     self._forbiden_set = set()
     self.log("Wormguidance ready for rocking")
Ejemplo n.º 20
0
 def prepareForRun(self):
     nonexit="Nonexisting string"
     if self.getParameter("help", nonexit) != nonexit:
         print __doc__
         raise Exception("Asked only for help")
     GuidanceBase.prepareForRun(self)
     if len(self._requirements) != 1 :
         raise Exception("Needs exactly one requirement")
     if not self._testmodel :
         raise Exception("Model should be given")
     self._stored_path=[]
     self._to_sleep_actions =\
                self._testmodel.matchedActions(set([self._sleep_ts_re]))
     self._last_go_back = False
     self._search_state = GoodState
     self._forbiden_set = set()
     self.log("Wormguidance ready for rocking")
Ejemplo n.º 21
0
 def setParameter(self, name, value):
     accepted = ("transitionweight", "searchorder", "searchdepth",
                 "maxtransitions", "searchconstraint")
     if name == "transitionweight":
         if isinstance(value, str) and value.startswith('kw:'):
             kww = float(value[3:])
             self._transitionweight = \
                 lambda t: kww if 'kw_' in str(t.getAction()) else 0
         else:
             if value < 0:
                 self.log("WARNING! Negative transition weight " +
                          "doesn't make sense!")
             self._transitionweight = lambda t: value
     elif name == "searchorder":
         if value == "bestfirst":
             self._toHeap = lambda p, badness: (badness, len(p), p)
             self._fromHeap = lambda values: (values[2], values[0])
         elif value == "shortestfirst":
             self._toHeap = lambda p, badness: (len(p), badness, p)
             self._fromHeap = lambda values: (values[2], values[1])
         else:
             raise ValueError("Invalid searchorder: '%s'" % (value, ))
     elif name in ("searchdepth", "searchradius"):
         self._searchDepth = value
     elif name == "maxtransitions":
         self._maxTransitions = value
     elif name == "greedy":
         self._greedy = value
     elif name == "searchconstraint":
         if value == "nocrossingpaths":
             self._seco = NO_CROSSING_PATHS
         elif value == "noloops":
             self._seco = NO_LOOPS
         elif value == "noconstraint":
             self._seco = NONE
         else:
             raise ValueError("Invalid searchconstraint '%s'" % value)
     else:
         print __doc__
         raise ValueError("Invalid parameter '%s' for newguidance. " %
                          name +
                          "Accepted parameters: %s" % ",".join(accepted))
     GuidanceBase.setParameter(self, name, value)
Ejemplo n.º 22
0
 def setParameter(self, name, value):
     accepted = ("transitionweight", "searchorder", "searchdepth", "maxtransitions", "searchconstraint")
     if name == "transitionweight":
         if isinstance(value, str) and value.startswith("kw:"):
             kww = float(value[3:])
             self._transitionweight = lambda t: kww if "kw_" in str(t.getAction()) else 0
         else:
             if value < 0:
                 self.log("WARNING! Negative transition weight " + "doesn't make sense!")
             self._transitionweight = lambda t: value
     elif name == "searchorder":
         if value == "bestfirst":
             self._toHeap = lambda p, badness: (badness, len(p), p)
             self._fromHeap = lambda values: (values[2], values[0])
         elif value == "shortestfirst":
             self._toHeap = lambda p, badness: (len(p), badness, p)
             self._fromHeap = lambda values: (values[2], values[1])
         else:
             raise ValueError("Invalid searchorder: '%s'" % (value,))
     elif name in ("searchdepth", "searchradius"):
         self._searchDepth = value
     elif name == "maxtransitions":
         self._maxTransitions = value
     elif name == "greedy":
         self._greedy = value
     elif name == "searchconstraint":
         if value == "nocrossingpaths":
             self._seco = NO_CROSSING_PATHS
         elif value == "noloops":
             self._seco = NO_LOOPS
         elif value == "noconstraint":
             self._seco = NONE
         else:
             raise ValueError("Invalid searchconstraint '%s'" % value)
     else:
         print __doc__
         raise ValueError(
             "Invalid parameter '%s' for newguidance. " % name + "Accepted parameters: %s" % ",".join(accepted)
         )
     GuidanceBase.setParameter(self, name, value)
Ejemplo n.º 23
0
    def __init__(self):
        GuidanceBase.__init__(self)

        self.began = 0

        # initializes the random number generator
        random.seed()

        # a list of suggestions
        # seach method appends a suggestion every time it makes a decision
        # about next chosen transition, and suggestAction pops suggestions
        # from the beginning of it.
        self.suggestions = []

        # tells how many keywords there are in the suggestions list
        self.keywordsInSuggestions = 0

        # the lock is acquired before accessing the variables shared by
        # suggestAction and searcher threads
        self.lock = threading.Lock()

        # the suggestion event signals for a new suggestion added to the suggestions list
        self.suggestionEvent = threading.Event()

        # the state event signals for a new root state for search thread to start searching
        # next suggestions (search waits for this after a verification action)
        self.stateEvent = threading.Event()

        # is suggestAction waiting for suggestion?
        self.waitingForSuggestion = 0

        # is searcher thread waiting for verification?
        self.waitingForVerification = 0

        # The estimated delay after a keyword execution, is updated by suggestAction.
        self.keywordDelay = 0.1
Ejemplo n.º 24
0
	def __init__(self):
		GuidanceBase.__init__(self)

		self.began = 0

		# initializes the random number generator
		random.seed()
		
		# a list of suggestions
		# seach method appends a suggestion every time it makes a decision
		# about next chosen transition, and suggestAction pops suggestions
		# from the beginning of it. 
		self.suggestions = []
		
		# tells how many keywords there are in the suggestions list
		self.keywordsInSuggestions = 0
				
		# the lock is acquired before accessing the variables shared by
		# suggestAction and searcher threads
		self.lock = threading.Lock()
		
		# the suggestion event signals for a new suggestion added to the suggestions list
		self.suggestionEvent = threading.Event()
		
		# the state event signals for a new root state for search thread to start searching
		# next suggestions (search waits for this after a verification action)
		self.stateEvent = threading.Event()
		
		# is suggestAction waiting for suggestion?
		self.waitingForSuggestion = 0
		
		# is searcher thread waiting for verification?
		self.waitingForVerification = 0
		
		# The estimated delay after a keyword execution, is updated by suggestAction.
		self.keywordDelay = 0.1
Ejemplo n.º 25
0
 def __init__(self):
     GuidanceBase.__init__(self)
     self._stored_path=[]
     self._random_select=random.Random(time.time()).choice
     self._sleep_ts_re = re.compile(r"SLEEPts.*")
Ejemplo n.º 26
0
 def __init__(self):
     GuidanceBase.__init__(self)
     self.setParameter('randomseed',time.time())
Ejemplo n.º 27
0
 def prepareForRun(self):
     GuidanceBase.prepareForRun(self)
     self.search_front_lock = thread.allocate_lock()
Ejemplo n.º 28
0
 def __init__(self):
     GuidanceBase.__init__(self)
Ejemplo n.º 29
0
 def __init__(self):
     GuidanceBase.__init__(self)
     self.setParameter('randomseed', time.time())
Ejemplo n.º 30
0
 def markExecuted(self, transition):
     self._path = self._path[1:]
     GuidanceBase.markExecuted(self,transition)
Ejemplo n.º 31
0
 def __init__(self):
     GuidanceBase.__init__(self)
     self._stored_path = []
     self._random_select = random.Random(time.time()).choice
     self._sleep_ts_re = re.compile(r"SLEEPts.*")
Ejemplo n.º 32
0
 def prepareForRun(self):
     GuidanceBase.prepareForRun(self)
     self.search_front_lock=thread.allocate_lock()
Ejemplo n.º 33
0
 def __init__(self):
     GuidanceBase.__init__(self)
Ejemplo n.º 34
0
 def __init__(self):
     GuidanceBase.__init__(self)
     self._port = None
     self._manager = None
     self._iAmTheManagerStarter = False
     self._sgParams = []
Ejemplo n.º 35
0
 def __init__(self):
     GuidanceBase.__init__(self)
     self._port = None
     self._manager = None
     self._iAmTheManagerStarter = False
     self._sgParams = []
Ejemplo n.º 36
0
 def markExecuted(self, transition):
     self._path = self._path[1:]
     GuidanceBase.markExecuted(self, transition)