コード例 #1
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   
コード例 #2
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
コード例 #3
0
def openProject(filename):
    """
    Open filename as a project and return activities data

    if error or format not recognized returns None
    """
    fileFormat = [
        fileFormats.PPCProjectFileFormat(),
        fileFormats.PSPProjectFileFormat(),
    ]
    activities = None
    extension = filename[filename.rfind('.') + 1:]
    # Tries to load file with formats that match its extension in format order
    try:
        for format in fileFormat:
            if extension in format.filenameExtensions:
                try:
                    activities, _, _, _ = format.load(filename)
                    break
                except fileFormats.InvalidFileFormatException:
                    pass

        return activities

    except IOError:
        return None
コード例 #4
0
def saveProject(nombre, activities, schedules, resources, asignacion):
    """
    Saves a project in ppcproject format '.ppc'
    """
    if nombre[-4:] != '.ppc':
        nombre = nombre + '.ppc'

    format = fileFormats.PPCProjectFileFormat()
    try:
        format.save((activities, schedules, resources, asignacion), nombre)
    except IOError:
        self.dialogoError(_('Error saving the file'))
コード例 #5
0
def load(filename):
    """
    Load ppcproject-compatible files (.ppc files & .sm files)

    filename (name of the file to load)

    return: data (file info)
    """
    #XXX NO USAR ESTA FUNCION (ver la generica en fileFormats)
    formatos = [
        fileFormats.PPCProjectFileFormat(),
        fileFormats.PSPProjectFileFormat()
    ]
    try:
        # Tries to load file with formats that match its extension in format order
        data = None
        extension = filename[filename.rfind('.') + 1:]

        for format in formatos:
            if extension in format.filenameExtensions:
                try:
                    data = format.load(filename)
                    break
                except fileFormats.InvalidFileFormatException:
                    pass

        # If load by extension failed, try to load files in any format independently of their extension
        if not data:
            for format in formatos:
                try:
                    data = format.load(filename)
                    break
                except fileFormats.InvalidFileFormatException:
                    pass

        #Data successfully loaded
        if data:
            return data
        else:
            raise Exception('ERROR: Formato del archivo origen no reconocido')

    except IOError:
        print 'ERROR: leyendo el archivo origen', '\n'
コード例 #6
0
def openProject(filename):
    """
    Open a project file given by filename
    """
    try:
        actividad = []
        recurso = []
        asignacion = []
        schedules = []
        fileFormat = [
            fileFormats.PPCProjectFileFormat(),
            fileFormats.PPCProjectOLDFileFormat(),
            fileFormats.PSPProjectFileFormat(),
        ]

        # Tries to load file with formats that match its extension in format order
        data = None
        extension = filename[filename.rfind('.') + 1:]

        for format in fileFormat:
            if extension in format.filenameExtensions:
                try:
                    data = format.load(filename)
                    break
                except fileFormats.InvalidFileFormatException:
                    pass

        if not data:
            print 'Can not understand file'
            sys.exit(1)

        actividad, schedules, recurso, asignacion = data
        return data[0]
    except IOError:
        print 'Error reading file:', filename
        sys.exit(1)
コード例 #7
0
def main():
    """
    The following program of simulation batch is in charge of uploading a .ppc format file and generating two files 
    from the first one. On the one hand, it generates a file with the result of simulating n times, on the other hand,
    it generates a file resulting from simulating the duration of the activities n times.

    The program shall receive the following parameters for each console:
        infile (name of the file from which data will be uploaded)
        durationsfile (name of the file in which the resulting list with the n simulations of the duration of the project will be saved)
        table_file (name of the file in charge of saving the n simulations of the durations of the activities,
                  the distribution to generate them will be that uploaded from durationsfile)
        -i (number of iterations to be performed)
    """
    # Parse arguments and options
    parser = argparse.ArgumentParser(
        description='Generates activities and project simulations')
    parser.add_argument(
        'infile',  #default=sys.stdin,
        help='Project file to simulate')
    parser.add_argument(
        '--durations-file',
        '-d',
        help=
        'Name of file to store durations list (default: <infile>_simulation.csv)'
    )
    parser.add_argument(
        '--table-file',
        '-t',
        default=None,
        help='Name of file to append test results (default: stdout)')
    parser.add_argument('-i',
                        default=1000,
                        type=int,
                        help='Number of iterations (default: 1000)')
    parser.add_argument(
        '-p',
        default=90,
        type=int,
        help=
        'Percentil de caminos criticos considerados de la simulacion (default: 90)'
    )

    args = parser.parse_args()

    if args.i < 1:
        print 'Number of iterations must be > 0'
        return 1

    if (args.p <= 0):
        print 'The argument p must be greater than 0'
        return 1

    if args.durations_file:
        durations_file = args.durations_file
    else:
        durations_file = args.infile + '_simulation.csv'

    # Load the project of the ppcproject
    format = fileFormats.PPCProjectFileFormat()
    try:
        data = format.load(args.infile)
        if not data:
            print 'ERROR: Unexpected format for file ', args.infile
            return 1
    except fileFormats.InvalidFileFormatException:
        print 'ERROR: Unexpected format for file ', args.infile
        return 1
    except IOError:
        print 'ERROR: Reading project file\n'
        return 1
    act, schedules, recurso, asignacion = data

    # Simulate project
    durations, simulation_act, graph = vectorDuraciones(args.i, act)

    # Save durations in csv format
    with open(durations_file, 'w') as f:
        simulation_csv = ''
        for dur in durations:
            f.write(str(dur) + '\n')

    # Create the result vector to be saved in the file
    resultados = kolmogorov_smirnov.evaluate_models(act,
                                                    durations,
                                                    simulation_act,
                                                    args.p,
                                                    pert_graph=graph)

    # Save the results
    if args.table_file:
        if (not os.path.isfile(args.table_file)):
            # Create and write header
            results_table_file = open(args.table_file, 'w')
            header = "'Archivo', " + str(resultados.keys())[1:-1] + '\n'
            header = header.replace("'", '"')
            results_table_file.write(header)
        else:
            # Append data to the end
            results_table_file = open(args.table_file, 'a')
    else:
        results_table_file = sys.stdout

    # Write values comma separated
    s = str(args.infile)
    for res in resultados.values():
        s += ',' + res.__repr__().replace(
            "'", '"')  # Use doble quote to enclose strings
    s += '\n'

    results_table_file.write(s)
    results_table_file.close()
    return 0