Exemplo n.º 1
0
def get_information(file_path):  # using target_MDG and a benchmark, create result
    """
    Execute Each algorithm for given file and return TurboMQ, cohesion, and coupling
    :param file_path: A path of dot file
    :return: Clustering result - value of TurboMQ, A list of [Cohesion, Coupling], A list of result clusters
    """
    targetMDG = make_target_MDG(file_path)
    methods = ['WCA', 'HC', 'WCA_HC', 'SA', 'WCA_SA', 'PSO', 'WCA_PSO']
    clusters_set = []
    TMQ = []
    cohe_coup = []
    print("====WCA start====\n")
    clusters_set.append(WCA(targetMDG))
    print("====WCA end====\n\n")
    
    print("====HC start====\n")
    clusters_set.append(HC.HC(targetMDG))
    print("====HC end====\n\n")
    
    print("====WCA_HC start====\n")
    clusters_set.append(HC.WCA_HC(targetMDG, WCA(targetMDG)))
    print("====WCA_HC end====\n\n")
    
    print("====SA start====\n")
    clusters_set.append(SA.SA(targetMDG))
    print("====SA end====\n\n")
    
    print("====WCA_SA start====\n")
    clusters_set.append(SA.WCA_SA(targetMDG, WCA(targetMDG)))
    print("====WCA_SA end====\n\n")
    
    print("====PSO start====\n\n")
    clusters_set.append(PSO.PSO(targetMDG))
    print("====PSO end====\n\n")
    
    print("====WCA_PSO start====\n\n")
    clusters_set.append(PSO.WCA_PSO(targetMDG, WCA(targetMDG)))
    print("====WCA_PSO end====\n\n")
    
    # get TMQ data
    for clusters in clusters_set:
        TMQ.append(TurboMQ.calculate_fitness(clusters, targetMDG))
        cohe_coup.append(TurboMQ.get_cohesion_coupling(clusters, targetMDG))
    # write result files
    for i in range(len(methods)):
        DotParser.write_file(file_path, methods[i], clusters_set[i], targetMDG)
        
    return TMQ, cohe_coup, clusters_set
Exemplo n.º 2
0
def main():

    parser = argparse.ArgumentParser(description='Modularize given dot file')
    parser.add_argument('file_path',
                        metavar='F',
                        type=str,
                        nargs='+',
                        help='File path for dot file')
    parser.add_argument(
        '-a',
        help=
        'Algorithm for modularization. All, WCA, HC, WCA_HC, SA, WCA_SA, PSO, WCA_PSO'
    )
    args = parser.parse_args()

    file_path = args.file_path
    if args.a:
        modularizeMethod = args.a
    else:
        modularizeMethod = 'All'

    for single_file in file_path:

        targetMDG = MakeResult.make_target_MDG(single_file)
        clusters = None
        if modularizeMethod == 'WCA':
            clusters = WCA(targetMDG)
        elif modularizeMethod == 'HC':
            clusters = HC.HC(targetMDG)
        elif modularizeMethod == 'WCA_HC':
            clusters = HC.WCA_HC(targetMDG, WCA(targetMDG))
        elif modularizeMethod == 'SA':
            clusters = SA.SA(targetMDG)
        elif modularizeMethod == 'WCA_SA':
            clusters = SA.WCA_SA(targetMDG, WCA(targetMDG))
        elif modularizeMethod == 'PSO':
            clusters = PSO.PSO(targetMDG)
        elif modularizeMethod == 'WCA_PSO':
            clusters = PSO.WCA_PSO(targetMDG, WCA(targetMDG))
        elif modularizeMethod == 'All':
            MakeResult.print_result(single_file)

        if modularizeMethod != 'All':
            DotParser.write_file(single_file, modularizeMethod, clusters,
                                 targetMDG)