コード例 #1
0
ファイル: fair_encode.py プロジェクト: uuverifiers/autosat
def autFinalToFair(aut, autEnabled, options):
    '''autFinalToFair(aut, autEnabled, options) -> Automaton

Encodes fairness into an automaton representing final configurations of
a system, w.r.t. enabled transitions given by autEnabled.  The final states are
states given by aut with fairness encoded, or states corresponding to one
enabled process's counter reaching zero.  The options parameter contains
command line arguments.
'''
    ###########################################
    def encodeCntTimeout(src, symbol, dst, encoding, discardDelim):
        '''encodeCntTimeout(src, symbol, dst, encoding, discardDelim) -> [Transition]

Encodes a counter timeout in the place of the transition.
'''
        newTransitions = []
        if encoding in {CounterEncoding.unary,
                CounterEncoding.binaryLittleEndian, CounterEncoding.binaryBigEndian}:
            zeroState = dst + "Y0"
            endState = zeroState + "_end"
            newTransitions.append(Automaton.makeEpsTrans(src, zeroState))
            newTransitions.append(Automaton.makeTrans(zeroState, SYMBOL_ZERO, zeroState))
            newTransitions.append(Automaton.makeTrans(zeroState, SYMBOL_ZERO, endState))
        else:
            raise Exception("Invalid encoding: " + str(encoding))

        if discardDelim:
            newTransitions.append(Automaton.makeEpsTrans(endState, dst))
        else:
            newTransitions.append(Automaton.makeTrans(endState, SYMBOL_ENABLED, dst))

        return newTransitions
    #############################################


    aut1 = autEnabled.renameStates(lambda x: x + "Y1")
    aut1 = aut1.clearAcceptStates()

    aut2 = autEnabled.renameStates(lambda x: x + "Y2")
    aut2 = aut2.clearStartStates()

    aut3 = Automaton.autUnion(aut1, aut2)
    for (src, symb, tgt) in autEnabled.transitions:
        if symb == SYMBOL_ENABLED:
            aut3.addTrans(src + "Y1", SYMBOL_ENABLED_TIMEOUT, tgt + "Y2")

    aut4 = encodeCounter(aut3,
            encoding = options.encoding,
            discardDelim = options.discardDelimiter,
            allowZero = True
        )

    aut5 = Automaton()
    aut5.startStates = aut4.startStates[:]
    aut5.acceptStates = aut4.acceptStates[:]

    # encode the timeout condition
    for trans in aut4.transitions:
        if (not Automaton.isEpsilonTrans(trans) and
            Automaton.getSymbol(trans) == SYMBOL_ENABLED_TIMEOUT):
            (src, symb, tgt) = trans
            # zeroState = tgt + "Y0"
            # aut5.addTrans(transition = (src, zeroState))
            # aut5.addTrans(zeroState, SYMBOL_ZERO, zeroState)
            # aut5.addTrans(zeroState, SYMBOL_ZERO, tgt)

            # for the special timeout symbol
            counterTransitions = encodeCntTimeout(src, symb, tgt, options.encoding, options.discardDelimiter)
            aut5.addTransitions(counterTransitions)
        else:
            # for other symbols
            aut5.addTrans(transition = trans)

    autB = encodeCounter(aut,
            encoding = options.encoding,
            discardDelim = options.discardDelimiter,
            allowZero = True
        )

    output = Automaton.autUnion(aut5, autB)
    output = output.singleStartState(FINAL_START_STATE)

    output.transitions = list(set(output.transitions)) # kill duplicates
    return output.removeUseless()
コード例 #2
0
ファイル: fair_encode.py プロジェクト: uuverifiers/autosat
def autFinalToFair(aut, autEnabled, options):
    '''autFinalToFair(aut, autEnabled, options) -> Automaton

Encodes fairness into an automaton representing final configurations of
a system, w.r.t. enabled transitions given by autEnabled.  The final states are
states given by aut with fairness encoded, or states corresponding to one
enabled process's counter reaching zero.  The options parameter contains
command line arguments.
'''
    ###########################################
    def encodeCntTimeout(src, symbol, dst, encoding, discardDelim):
        '''encodeCntTimeout(src, symbol, dst, encoding, discardDelim) -> [Transition]

Encodes a counter timeout in the place of the transition.
'''
        newTransitions = []
        if encoding in {CounterEncoding.unary,
                CounterEncoding.binaryLittleEndian, CounterEncoding.binaryBigEndian}:
            zeroState = dst + "Y0"
            endState = zeroState + "_end"
            newTransitions.append(Automaton.makeEpsTrans(src, zeroState))
            newTransitions.append(Automaton.makeTrans(zeroState, SYMBOL_ZERO, zeroState))
            newTransitions.append(Automaton.makeTrans(zeroState, SYMBOL_ZERO, endState))
        else:
            raise Exception("Invalid encoding: " + str(encoding))

        if discardDelim:
            newTransitions.append(Automaton.makeEpsTrans(endState, dst))
        else:
            newTransitions.append(Automaton.makeTrans(endState, SYMBOL_ENABLED, dst))

        return newTransitions
    #############################################


    aut1 = autEnabled.renameStates(lambda x: x + "Y1")
    aut1 = aut1.clearAcceptStates()

    aut2 = autEnabled.renameStates(lambda x: x + "Y2")
    aut2 = aut2.clearStartStates()

    aut3 = Automaton.autUnion(aut1, aut2)
    for (src, symb, tgt) in autEnabled.transitions:
        if symb == SYMBOL_ENABLED:
            aut3.addTrans(src + "Y1", SYMBOL_ENABLED_TIMEOUT, tgt + "Y2")

    aut4 = encodeCounter(aut3,
            encoding = options.encoding,
            discardDelim = options.discardDelimiter,
            allowZero = True
        )

    aut5 = Automaton()
    aut5.startStates = aut4.startStates[:]
    aut5.acceptStates = aut4.acceptStates[:]

    # encode the timeout condition
    for trans in aut4.transitions:
        if (not Automaton.isEpsilonTrans(trans) and
            Automaton.getSymbol(trans) == SYMBOL_ENABLED_TIMEOUT):
            (src, symb, tgt) = trans
            # zeroState = tgt + "Y0"
            # aut5.addTrans(transition = (src, zeroState))
            # aut5.addTrans(zeroState, SYMBOL_ZERO, zeroState)
            # aut5.addTrans(zeroState, SYMBOL_ZERO, tgt)

            # for the special timeout symbol
            counterTransitions = encodeCntTimeout(src, symb, tgt, options.encoding, options.discardDelimiter)
            aut5.addTransitions(counterTransitions)
        else:
            # for other symbols
            aut5.addTrans(transition = trans)

    autB = encodeCounter(aut,
            encoding = options.encoding,
            discardDelim = options.discardDelimiter,
            allowZero = True
        )

    output = Automaton.autUnion(aut5, autB)
    output = output.singleStartState(FINAL_START_STATE)

    output.transitions = list(set(output.transitions)) # kill duplicates
    return output.removeUseless()