Exemplo n.º 1
0
def exportNewRegularGraphsToDat(edgesArray=[10, 20, 50, 100, 500]):
    """
    This function exports to files 5 or more regular graph without crossing edges
    or also parallel edges.

    There will be files in dat directory with at least the number of nodes passed
    as parameter divided by 2 in edges.
    """
    graph_generator = RandomGraphGenerator()

    for i in edgesArray:
        set_of_edges = graph_generator.random_regular_graph(1, i)
        dict_of_edges = graph_generator.convertSetToOrderedDict(set_of_edges)
        FileReader.writef('dat' + os.path.sep + 'results_' + str(i) + '_nodes' + '.dat', 'edges=' + str(dict_of_edges))
Exemplo n.º 2
0
def main(argv):

    try:
        opts, args = getopt.getopt(argv, "h|f|d|e", ['--floyd-warshall', '--edsger-dijkstra'])
    except getopt.GetoptError:
        command_help_text()
        raise Warning("warning: did you forget parameters?")
    for opt, arg in opts:
        if opt in ['-h', '--help']:
            command_help_text()
            sys.exit()
        elif opt in ("-f", "--floyd-warshall"):
            if os.path.exists(args[0]):
                number_of_files, data_files_list = FileReader.readFiles(args[0])
                start_samu_threadings_floyd(edges_list=data_files_list, threads_number=number_of_files, accident_location=args)
                print('visit results_floyd directory to see your results\n')
                if not os.path.exists('results_floyd'):
                    try:
                        os.makedirs('results_floyd')
                    except IOError:
                        raise Exception("it was impossible to create the given directory name\n")
                for ambulances in list_of_ambulances:
                    FileReader.writef('results_floyd' + os.path.sep + 'results_floyd_{}.txt'.format(ambulances.name), ambulances.__str__())
            else:
                raise Exception("such directory called {} doesnt exist!".format(args[0]))
        elif opt in ("-d", "--edsger-dijkstra"):
            if os.path.exists(args[0]):
                number_of_files, data_files_list = FileReader.readFiles(args[0])
                start_samu_threadings_dijkstra(edges_list=data_files_list, threads_number=number_of_files, accident_location=args)
                print('visit results_dijkstra directory to see your results\n')
                if not os.path.exists('results_dijkstra'):
                    try:
                        os.makedirs('results_dijkstra')
                    except IOError:
                        raise Exception("it was impossible to create the given directory name\n")
                for ambulances in list_of_ambulances:
                    FileReader.writef('results_dijkstra' + os.path.sep + 'results_dijkstra_{}.txt'.format(ambulances.name), ambulances.__str__())
            else:
                raise Exception("such directory called {} doesnt exist!".format(args[0]))
        elif opt in ("-e", "--export"):
            if not os.path.exists('dat'):
                try:
                    os.makedirs('dat')
                except IOError:
                    raise Exception("it was impossible to create the given directory name\n")
            exportNewRegularGraphsToDat()