Esempio n. 1
0
def main():
    """
    Test Cohen-Sadeh algorithm

    Arguments:
        infile - project file
    """
    # Parse arguments and options
    parser = argparse.ArgumentParser()
    parser.add_argument('infile')
    args = parser.parse_args()

    # Open the input file collecting the required information.
    activities, _, _, _ = fileFormats.load_with_some_format(args.infile, [fileFormats.PPCProjectFileFormat(),
                                                                          fileFormats.PSPProjectFileFormat()])
    successors = dict(((act[1], act[2]) for act in activities))

    gg1 = cohen_sadeh(graph.successors2precedents(successors))
    #subgraph = gg1.focus(787, 875) # Error en Large Tavares

    window = graph.Test()
    window.add_image(graph.pert2image(gg1))
    graph.gtk.main()
    print gg1
    print validation.check_validation(successors, gg1)
    return 0
Esempio n. 2
0
def main():
    """
    Test Mouhoub algorithm

    Arguments:
        infile - project file
    """
    # Parse arguments and options
    parser = argparse.ArgumentParser()
    parser.add_argument('infile')
    args = parser.parse_args()

    # Open the input file collecting the required information.
    activities, _, _, _ = fileFormats.load_with_some_format(args.infile, [fileFormats.PPCProjectFileFormat(),
                                                                          fileFormats.PSPProjectFileFormat()])
    successors = dict(((act[1], act[2]) for act in activities))
    
    pert_graph = mouhoub(graph.successors2precedents(successors))
    
    window = graph.Test()
    window.add_image(graph.pert2image(pert_graph))
    graph.gtk.main()
    print pert_graph
    print validation.check_validation(successors, pert_graph)
    return 0   
def main():
    """
    Test Syslo algorithm

    Arguments:
        infile - project file
    """
    # Parse arguments and options
    parser = argparse.ArgumentParser()
    parser.add_argument("infile")
    args = parser.parse_args()

    # Open the input file collecting the required information.
    activities, _, _, _ = fileFormats.load_with_some_format(
        args.infile, [fileFormats.PPCProjectFileFormat(), fileFormats.PSPProjectFileFormat()]
    )
    successors = dict(((act[1], act[2]) for act in activities))

    pert_graph = sysloPolynomial(graph.successors2precedents(successors))
    # subgraph = gg1.focus(787, 875) # Error en Large Tavares

    window = graph.Test()
    window.add_image(graph.pert2image(pert_graph))
    graph.gtk.main()
    print pert_graph
    print validation.check_validation(successors, pert_graph)
    return 0
Esempio n. 4
0
def main():
    """
    Test AOA (PERT) network generation algorithms with some given project files
    """
    # Parse arguments and options
    parser = argparse.ArgumentParser(
        description='Test AOA graph generation algorithms with given files')
    parser.add_argument('infiles', nargs='*', help='Project files to test')
    parser.add_argument(
        '--table-file',
        '-t',
        default='resultados.csv',
        help=
        'Name of file to append test results in CSV format (default: resultados.csv)'
    )
    parser.add_argument('-r',
                        '--repeat',
                        default=1,
                        type=int,
                        help='Number of repetitions (default: 1)')
    parser.add_argument('--SVG',
                        action='store_true',
                        help='Draw the graph in a SVG file')
    parser.add_argument('--no-stop',
                        action='store_true',
                        help='Do not stop when an algorithm fails')

    parser.add_argument('-c',
                        '--CohenSadeh',
                        action='store_true',
                        help='Test Cohen Sadeh algorithm')
    parser.add_argument('-s',
                        '--Sharma',
                        action='store_true',
                        help='Test Sharma algorithm')
    parser.add_argument('-l',
                        '--Salas',
                        action='store_true',
                        help='Test Lorenzo Salas algorithm')
    parser.add_argument('-g',
                        '--GentoMunicio',
                        action='store_true',
                        help='Test Gento Municio algorithm')
    parser.add_argument('-o',
                        '--Optimal',
                        action='store_true',
                        help='Test set based optimal algorithm')
    parser.add_argument('-m',
                        '--Mouhoub',
                        action='store_true',
                        help='Test Mouhoub algorithm')
    parser.add_argument('-p',
                        '--Syslo_Polynomial',
                        action='store_true',
                        help='Test Syslo Polynomial algorithm')
    parser.add_argument('-y',
                        '--Syslo_Optimal',
                        action='store_true',
                        help='Test Syslo Optimal algorithm')
    args = parser.parse_args()

    if args.repeat < 1:
        print 'Number of repetitions must be > 0'
        return 1

    try:
        f_csv = open(args.table_file, "a")
    except IOError:
        print 'Can not open table file (%s) to append results in CSV format' % (
            args.table_file, )
        return 1

    # List of name and function of each algorithm to test
    algorithms = []
    if args.CohenSadeh:
        algorithms.append(('CohenSadeh', algoritmoCohenSadeh.cohen_sadeh))
    if args.Sharma:
        algorithms.append(('Sharma', algoritmoSharma.sharma1998ext))
    if args.Optimal:
        algorithms.append(('Conjuntos', algoritmoConjuntos.algoritmoN))
    if args.GentoMunicio:
        algorithms.append(
            ('GentoMunicio', algoritmoGentoMunicio.gento_municio))
    if args.Salas:
        algorithms.append(('Salas', algoritmoSalas.salas))
    if args.Mouhoub:
        algorithms.append(('Mouhoub', algoritmoMouhoub.mouhoub))
    if args.Syslo_Polynomial:
        algorithms.append(
            ('Syslo Polinomico', algoritmoSysloPolynomial.sysloPolynomial))
    if args.Syslo_Optimal:
        algorithms.append(('Syslo Optimo', algoritmoSysloOptimal.sysloOptimal))
    # Perform tests on each file
    for filename in args.infiles:
        print "\nFilename: ", filename
        data = openProject(filename)
        if not data:
            print 'Can not read or understand file'
        else:
            # XXX Aqui habria que cortar si falla el checkeo del fichero
            check_activities(data)

            # Test each algorithm
            for name, alg in algorithms:
                print name

                # Get successors from activities table
                successors = {}
                for i in data:
                    successors[i[1]] = i[2]

                # Count prelations
                list_of_predecessors = successors.values()
                num_of_predecessors = 0
                for predecessors in list_of_predecessors:
                    num_of_predecessors += len(predecessors)

                # Get predecessors from successors
                prelaciones = graph.reversed_prelation_table(successors)

                # Run algorithm
                pert_graph = None
                itime = os.times()
                for i in range(args.repeat):
                    try:
                        pert_graph = alg(prelaciones)
                    except Exception:
                        print traceback.format_exc()
                        print " --- Algorithm failed! --- "
                        if not args.no_stop:
                            return 1
                        break

                if pert_graph:
                    ftime = os.times()
                    utime = ftime[0] - itime[0]

                    # Print test results
                    print "utime %.4f" % (utime)
                    print "utime: ", utime
                    print "numero de nodos: ", pert_graph.number_of_nodes()
                    print "numero de arcos: ", pert_graph.number_of_arcs()
                    print "numero de arcos reales: ", pert_graph.numArcsReales(
                    )
                    print "numero de arcos ficticios: ", pert_graph.numArcsFicticios(
                    )
                    print "numero de predecesors/sucesores: ", num_of_predecessors
                    print "Validation: "
                    if not validation.check_validation(
                            successors, pert_graph) and not args.no_stop:
                        return 1
                    print ""

                    # XXX ??Falta incluir aqui el numero de actividades??
                    result_line = '"' + filename + '",' + '"' + name + '",' + str(len(data)) + ',' + str(num_of_predecessors) + ',' + \
                        str(pert_graph.number_of_nodes()) + ',' + str(pert_graph.number_of_arcs()) + ',' + \
                        str(pert_graph.numArcsReales()) + ',' + str(pert_graph.numArcsFicticios()) + ',' + "%.4f"%(utime)
                    f_csv.write(result_line + "\n")

                if pert_graph == 1:
                    print "No hay resultados que mostrar"

                    # Draw graph and save in a file (*.svg)
                    if args.SVG:
                        image_text = graph.pert2image(pert_graph)
                        fsalida = open(
                            os.path.split(filename)[1] + '_' + name + '.svg',
                            'w')
                        fsalida.write(image_text)
                        fsalida.close()

    f_csv.close()
    return 0