def IsUncertainCycle(diag_statestring_IDs,antes_fu=False):  # find uncertain loop in a given string

    if not antes_fu:
        UncertainCycle = False
        i = 0 
        Eventos_falhas = list()
        while i < len(diag_statestring_IDs): 
            j = 0
            for each in diag_statestring_IDs[i]:
                target =  DiagnoserFunctions.GetNextStatesInID(each)[0]
                if target == each or len(target) == 0 or each in DiagnoserFunctions.GetNextStatesInID(target): 
                    name = DiagnoserFunctions.GetStateName(each)
                    if DiagnoserFunctions.IsUncertain(name):
                        UncertainCycle = True
                        Eventos_falhas.append(diag_statestring_IDs[i][j])
                Next_States = DiagnoserFunctions.GetNextStatesInID(each) 
                for k in Next_States: 
                    name_next_state = DiagnoserFunctions.GetStateName(k) 
                    if DiagnoserFunctions.IsUncertain(name_next_state) and each in GetDiagReachable(k) and len(Next_States) > 1: 
                        estado_anterior = DiagnoserFunctions.GetPrevisousStatesInID(int(each))
                        nome_estado_anterior = DiagnoserFunctions.GetStateName(estado_anterior[0])
                        
                        if DiagnoserFunctions.IsUncertain(nome_estado_anterior): 
                            UncertainCycle = True
                            Eventos_falhas.append(diag_statestring_IDs[i][j])
                            break
                j += 1
            i += 1
        if UncertainCycle:
            return UncertainCycle, Eventos_falhas
        a = '-1'
        Eventos_falhas.append(a)

        return UncertainCycle, Eventos_falhas

    else:

        fu_name = FU_s.Get_FU_s()
        state_names = []
        state_ids = []
        for k in diag_statestring_IDs:
            for n in k:
                state_ids.append(n)
                state_names.append(DiagnoserFunctions.GetStateName(n))

        uncertain_cycle = False
        uncertain_state = ['-1']
        for i in range(len(state_names)):
            if DiagnoserFunctions.IsUncertain(state_names[i]):
                if state_names[i] not in fu_name:
                    uncertain_cycle = True
                    uncertain_state = [state_ids[i]]

        return uncertain_cycle, uncertain_state
Exemplo n.º 2
0
def GetFC_s_IDs(string):  # gets the FC(s) for a given string number

    FU_s_StateNames = FU_s.Get_FU_s() 

    # for this string only, getting the FU(s):
    FU_s_StateIDs = []
    FU_s_StateIDs.append(DiagnoserFunctions.GetStateId(FU_s_StateNames[string]))  

    # and getting the reachable states for this string in ID
    string_states_IDs = DefineStrings.GetDiagReachable(FU_s_StateIDs[0])  

    # getting the names
    string_states_names = []  
    for each in string_states_IDs:  
        string_states_names.append(DiagnoserFunctions.GetStateName(each)) 


    # ignoring the non-certain ones
    the_certain_IDs = [] 
    i = 0  
    while i < len(string_states_names):  
        if DiagnoserFunctions.IsCertain(string_states_names[i]):  
            the_certain_IDs.append(string_states_IDs[i])  
        i += 1  

    # getting the names
    the_certain_names = []
    for each in the_certain_IDs:
        the_certain_names.append(DiagnoserFunctions.GetStateName(each))


    previus_states_uncertain = list()
    for each in the_certain_IDs:
        a = DiagnoserFunctions.GetPrevisousStatesInID(each)
        for k in a:
            b = DiagnoserFunctions.GetStateName(k)
            if DiagnoserFunctions.IsUncertain(b):
                if FU_s_StateNames[string] == b:
                    previus_states_uncertain.append(DiagnoserFunctions.GetStateName(each))
                elif FU_s_StateNames[string] != b and b not in FU_s_StateNames:
                    previus_states_uncertain.append(DiagnoserFunctions.GetStateName(each))            

    FC_s = []
    for each in previus_states_uncertain:
        FC_s.append(DiagnoserFunctions.GetStateId(each))

    return (FC_s)