Esempio n. 1
0
def simulforallbabies(time, seed_simul, nodes, number_simul, seed):
        global env
        env = simpy_mine.Environment()

        found = -10
        file1 = 'nodes' + str(nodes) + '_' + str(seed)
        file2 = 'edges' + str(nodes) + '_' + str(seed)
        directory = 'graphdata/'
        allgraphs = Graph_Plot.graph_number_babies(nodes, seed) + 1
        print "Famille",seed, "avec", allgraphs
        if allgraphs == 1:
            return 0

        for filename1 in os.listdir(directory):
            if filename1.startswith(file1):
                end = filename1.rsplit('_', 1)[1]
                end2 = end.rsplit('.', 1)[0]
                for filename2 in os.listdir(directory):
                    if filename2.startswith(file2) and filename2.endswith(end):
                        g = Graph_Plot.addmygraph(filename1, filename2)
                        allgraphs -= 1
                        # print allgraphs
                        if allgraphs == 0:
                            found = 1
                        for i in range(number_simul):
                            name_res = start_my_code.DIRECTORY_SIM + "results" + str(nodes) + end + 'simul' + str(seed_simul + i) + ".txt"
                            name_pdf = 'disrupted' + str(nodes) + 'simul' + str(seed_simul + i) + 'famille' + end2
                            start_sim_no_plot_but_name(g, seed_simul + i, name_res, name_pdf)
        env.run(until=time)
        return found
Esempio n. 2
0
 def training_data_button_click(self):
     Graph_Plot.Plot(Login.MySQL.get_error())
Esempio n. 3
0
    def run(self):

        file_ext = self.file
        file_ext.write("Number of suppliers is " + str(len(self.netw.graph.nodes())-1) + "\n" + "\n" + "Time Manufacturer Suppliers " + "\n" + "t  ")
        for i in range(0, len(self.netw.graph.nodes())):
            if i < 10:
                file_ext.write("   " + str(i))
            elif i < 100:
                file_ext.write("  " + str(i))
            else:
                file_ext.write(" " + str(i))
        file_ext.write("\n")

        #file = open("storytelling.txt", 'w')
        file = 0   # does not mean anything but for not to many files open

        mynodes = self.netw.mynodes

        self.indextrack.append(startmysimul(self.netw, self.track, self.seed, self.plot))

        while True:
            #  Write the beginning of the line
            if env.now < 10:
                file_ext.write(str(env.now) +"  ")
            elif env.now > 99:
                file_ext.write(str(env.now))
            else:
                file_ext.write(str(env.now) +" ")

            for i in range(0, len(mynodes)):

                # Write the delay of the node
                node = mynodes[i]
                if node.delay < 10:
                    file_ext.write("   " + str(node.delay))
                elif node.delay < 100:
                    file_ext.write("  " + str(node.delay))
                else:
                    file_ext.write(" " + str(node.delay))

                if node.label != 0 and node.state:  #  If node disrupted and not manuf
                    newdelay = amplifyDis(node, self.delays)
                    recovery_time = start_my_code.recovery_time(node.rating)
                    time_since_started = self.locations[node.label]

                    if time_since_started >= recovery_time or newdelay == 0:   # If has receovered of if new dealy is zero
                        self.locations[node.label] = 0
                        node.state = False
                        node.delay = 0
                        if self.plot:
                            print "Disruption solved at time", self.env.now, "at location", node.label
                        #file.write("Disruption solved at time " + str(self.env.now) + " at location " + str(node.label)+"\n")

                        if self.track and self.indextrack.count(node.label) > 0:
                            self.indextrack.remove(node.label)

                    else:
                        self.locations[node.label] += 1
                        node.delay = newdelay
                        if time_since_started > 0 and time_since_started % 5 == 0:  #node.lead_time
                            propagateDis(node, self.netw, file, self.delays, newdelay, self.track, self.indextrack, self.seed, self.plot)

            if self.env.now == start_my_code.TIME_SIMUL-1 :
                #print "done, final delays manuf", self.delays[0]
                file_ext.close()
                if self.plot:
                    Graph_Plot.plotprettydis(self.netw.graph, self.delays, self.name)

            yield self.env.timeout(1)
            file_ext.write("\n")
        file_ext.close()
Esempio n. 4
0
def myfunctionsuperkey(test, graph, simul, learn):

    #  Commands for the fit of the nodes
    if test == -1:
        Graph_Plot.check_right_number_graphs(start_my_code.NUMBER_OF_NODES, start_my_code.NUMBER_OF_GRAPHS, start_my_code.INIT_SEED, 1483)

    if test == 1:
        Graph_Plot.calculatemystats(start_my_code.NUMBER_OF_NODES, start_my_code.NUMBER_OF_TIER_1, start_my_code.LENGTH, start_my_code.SIG_FACT, 500)
        Graph_Plot.findmyfactor(start_my_code.NUMBER_OF_NODES, start_my_code.NUMBER_OF_TIER_1, start_my_code.LENGTH, 500)

    #  Create a new random graph
    if graph == 1:
        G = Graph_Plot.build_my_random_net(start_my_code.NUMBER_OF_NODES, start_my_code.NUMBER_OF_TIER_1, start_my_code.LENGTH, start_my_code.SIG_FACT, start_my_code.GAMMA, start_my_code.FACTOR,  True)
        G.writemygraph(Graph_Plot.getnamenodes(start_my_code.INIT_SEED), Graph_Plot.getnameedges(start_my_code.INIT_SEED), start_my_code.INIT_SEED)
        Graph_Plot.plotpretty(G.graph, G.nodelayer,  Graph_Plot.getmygraphname(start_my_code.INIT_SEED))

    #  Load an existing graph (Careful with existing disruptions!, txt file should be topological)
    if graph == 2:
        G = Graph_Plot.addmygraph(Graph_Plot.getnamenodes(start_my_code.INIT_SEED), Graph_Plot.getnameedges(start_my_code.INIT_SEED))
        #Graph_Plot.plotpretty(G.graph, G.nodelayer,  Graph_Plot.getmygraphname(start_my_code.INIT_SEED))

    #  Start a simulation
    if simul == 1:
        my_code_simul.StartMySimul(start_my_code.TIME_SIMUL, G, True, True, start_my_code.INIT_SEED_SIMUL)

    #  Start a lot of simul
    if simul == 2:
        my_code_simul.startall(start_my_code.TIME_SIMUL, G, True, True, start_my_code.INIT_SEED_SIMUL, start_my_code.NUMBER_OF_SIMUL)

    #  Compute statistics with a lot of simulations
    if test == 2:
        my_code_simul.analysemytrack("500trackdis1234.txt")
        my_code_simul.stats_lot(start_my_code.NUMBER_OF_SIMUL)

    #  Generate a lot of graphs for the learning and check for duplicates
    if graph == 3:
        Graph_Plot.generatealotofgraphs(start_my_code.NUMBER_OF_GRAPHS, True, start_my_code.INIT_SEED, 0)

    #  Get the babies
    if graph == 4:
        Graph_Plot.getmybabies(start_my_code.NUMBER_OF_GRAPHS, start_my_code.INIT_SEED)
        Graph_Plot.getallsiblings(start_my_code.NUMBER_OF_GRAPHS, start_my_code.INIT_SEED)

    #  Start simulations for all the graphs in the directory graphdata. Stores all in.
    if simul == 3:
        left = start_my_code.NUMBER_OF_GRAPHS
        current_seed_simul3 = start_my_code.INIT_SEED
        while left > 0:
            for i in range(start_my_code.NUMBER_OF_SIMUL):
                print "current simulation", i
                test = my_code_simul.simulforallbabies(start_my_code.TIME_SIMUL, start_my_code.INIT_SEED_SIMUL + i, start_my_code.NUMBER_OF_NODES, 1, current_seed_simul3)
            if test == 0:
                current_seed_simul3 += 1
            if test == 1:
                current_seed_simul3 +=1
                left -= 1
            if test == -10:
                print "Erreur de data graphs"
                break

    #   Learning, preprocessing of data
    if learn == 1:

        #learning.check_right_number(start_my_code.NUMBER_OF_NODES, start_my_code.NUMBER_OF_GRAPHS, start_my_code.INIT_SEED, 1483)
        #learning.get_feature_one_family(start_my_code.NUMBER_OF_NODES, start_my_code.INIT_SEED, start_my_code.INIT_SEED_SIMUL, start_my_code.NUMBER_OF_TIER_1, start_my_code.NUMBER_OF_SIMUL)
        data = learning.get_feature_all_families(start_my_code.NUMBER_OF_NODES, start_my_code.INIT_SEED, start_my_code.INIT_SEED_SIMUL, start_my_code.NUMBER_OF_TIER_1, start_my_code.NUMBER_OF_SIMUL, start_my_code.NUMBER_OF_GRAPHS)
        learning.check_identical_rows(data[0])
        learning.store_data_print_size(data[0], data[1], 'features', 'label')

    if learn == 2:

        learn_algo.main(1)

    if learn == 3:

        compare_features.main()

    print "done", test, graph, simul, learn

    """