示例#1
0
 def _parse_state_strings(self, state_strings):
     options = {}
     if isinstance(state_strings, str):
         state_strings = [
           line.strip()
           for line in state_strings.splitlines()
           if line.strip() and not line.strip().startswith("#")]
     init_state = BitMask.null(len(self.states))
     for set_state in state_strings:
         if set_state == "default_false":
             options['default_false'] = True
             continue
         bit = 1
         if set_state.startswith("not "):
             bit = 0
             set_state = set_state[4:]
         set_state_bit = self.state_bits[set_state]
         if init_state.is_set(set_state_bit):
             raise Exception("Tried to set state twice: %s" % set_state)
         init_state = init_state.add(set_state_bit, bit)
     return init_state, options
示例#2
0
 def __init__(self, name, exprs, bindings):
     self.name = name
     self.bindings = bindings
     self.constraints = [
       item
       for expr in exprs['constraints']
       for item in expr.expand(bindings)
     ]
     self.actions = [
       item
       for expr in exprs['actions']
       for item in expr.expand(bindings)
     ]
     self.states = [
       item
       for expr in exprs['states']
       for item in expr.expand(bindings)
     ]
     if not self.states:
         # Must be implied states, since none were given
         implied_states = set()
         for action in self.actions:
             old_implied = set(implied_states)
             implied_states.update([
                 state[4:] if state.startswith("not ") else state
                 for state in action.must + action.then])
             #print("Updated", action, "must", action.must, "then", action.then,
             #    "before", len(old_implied), "now", len(implied_states),
             #    "added", implied_states - old_implied)
         self.states = [State(name) for name in implied_states]
     self.states.sort(key=lambda x: x.name)
     for i, state in enumerate(self.states):
         state.domain = self
         state.bit = 1 << i
         state.bit_mask = BitMask(state.bit, state.bit, len(self.states))
     self.state_bits = dict((state.name, state.bit) for state in self.states)
     self.actions.sort(key=lambda x: x.action)
     self.null = BitMask.null(len(self.states))
     for action in self.actions:
         action.domain = self
         action.must_bits = BitMask.null(len(self.states))
         for must in action.must:
             bit = 1
             if must.startswith("not "):
                 bit = 0
                 must = must[4:]
             action.must_bits = action.must_bits.add(self.state_bits[must], bit)
         action.must_bits = self.apply_constraints(action.must_bits)
         action.then_bits = self.null
         for then in action.then:
             bit = 1
             if then.startswith("not "):
                 bit = 0
                 then = then[4:]
             action.then_bits = action.then_bits.add(self.state_bits[then], bit)
         try:
             action.then_bits = self.apply_constraints(action.then_bits)
         except IncompatibleConstraints as e:
             e.action = action
             raise
         action.then_bits = action.then_bits.carry_forward(action.must_bits)
     for action in self.actions:
         action.mutex = set()
         for other_action in self.actions:
             if other_action is action:
                 continue
             if action.is_mutex(other_action):
                 action.mutex.add(other_action)
示例#3
0
 def __init__(self, goal):
     self.must_bits = goal
     self.then_bits = BitMask.null(goal._width)