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
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
def main(window): """ Test code """ import traceback successors = { 'a': ['c', 'e'], 'b': ['d'], 'c': [], 'd': [], 'e': ['d'], } successors2 = { 'a': ['c', 'e', 'd'], 'b': ['d'], 'c': ['f'], 'd': ['f', 'g'], 'e': ['g'], 'f': ['h'], 'g': ['h'], 'h': ['i', 'j', 'k'], 'i': ['l'], 'j': ['l'], 'k': [], 'l': [], } ## print graph.reversed_prelation_table(pert2[0]) ## for n in range(1,6): ## print inActivitiesR(pert2, graph.reversed_prelation_table(pert2[0]), n) ## print "OUT" ## for n in range(1,6): ## print outActivitiesR(pert2, n) ## window.images.append( graph.pert2image(pert4) ) ## print equivalentRemovingDummy(pert4, (3,4) ) ## removeDummy(pert4, (3,4) ) ## pertP = pert5 ## window.images.append( graph.pert2image(pertP) ) ## makePrelation( pertP, (1,5), (3,4) ) ## addActivity( pertP, 'nueva' ) ## makePrelation( pertP, (1,2), (7,8) ) ## makePrelation( pertP, (9,8), (6,4) ) # window.images.append( graph.pert2image(pert.Pert(pert4)) ) # window.images.append( graph2image(successors2) ) # window.images.append( graph2image(successors3) ) try: pertP = Pert() pertP.construct(successors2) window.images.append(graph.pert2image(pertP)) except Exception: traceback.print_exception(*sys.exc_info()) ## s = pertSuccessors(pertP) ## window.images.append( graph2image( roy(s) ) ) gtk.main()
'H' : ['D'], } itime=os.times() for i in range(repeticiones): g = algoritmoCohenSadeh.cohenSadeh(prelaciones1) ftime=os.times() utime = ftime[0] - itime[0] print "CohenSadeh" print "utime %.4f"% (utime) print "numero de nodos: ",g.number_of_nodes() print "numero de arcos: ",g.number_of_arcs() print "numero de arcos reales: ",g.numArcsReales() print "numero de arcos ficticios: ",g.numArcsFicticios() print image_text = graph.pert2image(g, format='png') fsalida = open('grafoCohenSadeh' + os.path.split(filename)[1] + '.png', 'w') fsalida.write(image_text) fsalida.close() itime=os.times() for i in range(repeticiones): g=algoritmoConjuntos.algoritmoN(prelaciones1) ftime=os.times() utime = ftime[0] - itime[0] print "Algoritmo Conjuntos" print "utime %.4f"% (utime) print "numero de nodos: ",g.number_of_nodes() print "numero de arcos: ",g.number_of_arcs() print "numero de arcos reales: ",g.numArcsReales() print "numero de arcos ficticios: ",g.numArcsFicticios()
# print "gg::::::", gg return gg def built_labels(node, node1, label, label1): for n in node: label = label + n + "-" for n1 in node1: label1 = label1 + n1 + "-" # l,l1 label = label[:-1] label1 = label1[:-1] # Test algorithm if __name__ == "__main__": import prueba filename = sys.argv[1] data = prueba.openProject(filename) prueba.check_activities(data) result_graph = prueba.test_algorithm(data, algoritmoN) # Draw graph on screen window = None window = graph.Test() image1 = graph.pert2image(result_graph) window.images.append(image1) graph.gtk.main()
'H': ['D'], } itime = os.times() for i in range(repeticiones): g = algoritmoCohenSadeh.cohenSadeh(prelaciones1) ftime = os.times() utime = ftime[0] - itime[0] print "CohenSadeh" print "utime %.4f" % (utime) print "numero de nodos: ", g.number_of_nodes() print "numero de arcos: ", g.number_of_arcs() print "numero de arcos reales: ", g.numArcsReales() print "numero de arcos ficticios: ", g.numArcsFicticios() print image_text = graph.pert2image(g, format='png') fsalida = open('grafoCohenSadeh' + os.path.split(filename)[1] + '.png', 'w') fsalida.write(image_text) fsalida.close() itime = os.times() for i in range(repeticiones): g = algoritmoConjuntos.algoritmoN(prelaciones1) ftime = os.times() utime = ftime[0] - itime[0] print "Algoritmo Conjuntos" print "utime %.4f" % (utime) print "numero de nodos: ", g.number_of_nodes() print "numero de arcos: ", g.number_of_arcs() print "numero de arcos reales: ", g.numArcsReales()
return gg def built_labels(node, node1, label, label1): for n in node: label = label + n + "-" for n1 in node1: label1 = label1 + n1 + "-" # l,l1 label = label[:-1] label1 = label1[:-1] # Test algorithm if __name__ == "__main__": import prueba filename = sys.argv[1] data = prueba.openProject(filename) prueba.check_activities(data) result_graph = prueba.test_algorithm(data, algoritmoN) # Draw graph on screen window = None window = graph.Test() image1 = graph.pert2image(result_graph) window.images.append(image1) graph.gtk.main()
'F' : ['D', 'L'], 'G' : ['H'], 'H' : ['E'], 'I' : ['H'], 'J' : ['H'], 'K' : ['A', 'B', 'I', 'J'], 'L' : [], } tab = successors8 if Kahn1962.check_cycles(tab): gg1 = gento_municio(tab) import validation window = graph.Test() window.add_image(graph.pert2image(gg1)) graph.gtk.main() # print gg1 # print validation.check_validation(tab, gg1) else: print "Example contains cicles!!" ##ACLARACION FUNCIONAMIENTO## #Para el tipo II incompleto. Si una o varias actividades tienen las mismas siguientes, pero alguna o algunas de las siguientes son precededidas por alguna más, entonces es seguro que: #El nudo inicio de las que no tienen otra precedente es el mismo nudo de fin de las que tienen las mismas siguientes... y. #Del nudo fin de las que tienen las mismas siguientes sale al menos una ficticia que va al nudo inicio de las que tienen más precedentes. Ahora habría que analizar si las que tienen otras precedentes tienen precedentes comunes o no comunes y sería como el tipo I (o no).
if d1[i[0]] == d1[j[0]]: visited.append(j[0]) del d[j[0]] # Add dummy activities and set activities with same begin node and same en node visited = [] for i in d1.iteritems(): for j in d1.iteritems(): if i[0] != j[0] and i[0] < b and j[0] < b and d1[i[0]] == d1[ j[0]] and i[0] not in visited: i[0], j[0] cont = cont + 1 d[a] = [d[i[0]][0], cont] d[j[0]] = [cont, d[i[0]][1]] a = a + 1 visited.append(j[0]) return d # If the program is run directly window = None if __name__ == "__main__": window = graph.Test() gg = salas(graph.prelations4) image1 = graph.pert2image(gg) window.images.append(image1) graph.gtk.main()
def main(window): """ Test code """ import traceback successors = {'a':['c','e'], 'b':['d'], 'c':[], 'd':[], 'e':['d'], } successors2 = {'a':['c','e','d'], 'b':['d'], 'c':['f'], 'd':['f','g'], 'e':['g'], 'f':['h'], 'g':['h'], 'h':['i','j','k'], 'i':['l'], 'j':['l'], 'k':[], 'l':[], } ## print graph.reversed_prelation_table(pert2[0]) ## for n in range(1,6): ## print inActivitiesR(pert2, graph.reversed_prelation_table(pert2[0]), n) ## print "OUT" ## for n in range(1,6): ## print outActivitiesR(pert2, n) ## window.images.append( graph.pert2image(pert4) ) ## print equivalentRemovingDummy(pert4, (3,4) ) ## removeDummy(pert4, (3,4) ) ## pertP = pert5 ## window.images.append( graph.pert2image(pertP) ) ## makePrelation( pertP, (1,5), (3,4) ) ## addActivity( pertP, 'nueva' ) ## makePrelation( pertP, (1,2), (7,8) ) ## makePrelation( pertP, (9,8), (6,4) ) # window.images.append( graph.pert2image(pert.Pert(pert4)) ) # window.images.append( graph2image(successors2) ) # window.images.append( graph2image(successors3) ) try: pertP = Pert() pertP.construct(successors2) window.images.append( graph.pert2image(pertP) ) except Exception: traceback.print_exception(*sys.exc_info()) ## s = pertSuccessors(pertP) ## window.images.append( graph2image( roy(s) ) ) gtk.main()
del d[j[0]] # Add dummy activities and set activities with same begin node and same en node visited = [] for i in d1.iteritems(): for j in d1.iteritems(): if i[0] != j[0] and i[0] < b and j[0] < b and d1[i[0]] == d1[j[0]] and i[0] not in visited: i[0], j[0] cont = cont + 1 d[a]=[d[i[0]][0], cont] d[j[0]] = [cont, d[i[0]][1]] a = a + 1 visited.append(j[0]) return d # If the program is run directly window = None if __name__ == "__main__": window = graph.Test() gg = salas(graph.prelations4) image1 = graph.pert2image(gg) window.images.append(image1) graph.gtk.main()
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
'D' : ['G'], 'E' : [], 'F' : ['D', 'L'], 'G' : ['H'], 'H' : ['E'], 'I' : ['H'], 'J' : ['H'], 'K' : ['A', 'B', 'I', 'J'], 'L' : [], } tab = successors8 if Kahn1962.check_cycles(tab): gg1 = gento_municio(tab) import validation window = graph.Test() window.add_image(graph.pert2image(gg1)) graph.gtk.main() # print gg1 # print validation.check_validation(tab, gg1) else: print "Example contains cicles!!" ##ACLARACION FUNCIONAMIENTO## #Para el tipo II incompleto. Si una o varias actividades tienen las mismas siguientes, pero alguna o algunas de las siguientes son precededidas por alguna más, entonces es seguro que: #El nudo inicio de las que no tienen otra precedente es el mismo nudo de fin de las que tienen las mismas siguientes... y. #Del nudo fin de las que tienen las mismas siguientes sale al menos una ficticia que va al nudo inicio de las que tienen más precedentes. Ahora habría que analizar si las que tienen otras precedentes tienen precedentes comunes o no comunes y sería como el tipo I (o no). #El patrón coincidencias sirve para saber seguro cuándo hay ficticias. Una vez que se sabe eso, el patrón tipo II incompleto y el de cadenas, te ayuda a optimizar.