Exemplo n.º 1
0
rectMatrix = []
graphs=["camel","cat","heart","rabbit","telephone","sailboat", "custom2","1","2","3","4","5"]
print "Pick a picture:"
print "1: camel \n2: cat \n3: heart \n4: rabbit \n5: telephone \n6: sailboat\n7: custom\n8: 1 \n9: 2 \n 10: 3 \n 11: 4 \n 12: 5 "
graph = "nono-"
graph += graphs[int(raw_input(""))-1]
graph += ".txt"

cols_size, rows_size = readfile.getSizes(graph)
cols_px, rows_px = calculate_size(cols_size, rows_size)
color_matrix = initialise_color_matrix()
app = QApplication([])
circles = Draw()
rectMatrix = generate_rectMatrix(color_matrix)

t = Thread(target=worker)
t.start()
circles.show()
start_state, rows, cols = readfile.read_graph(graph)
#k = Thread(target=AstarGac.Astar, args=(start_state,rows,cols))
#k.start()
AstarGac.Astar(start_state,rows,cols)
app.exec_()







Exemplo n.º 2
0
        constraints_coordinates[k][1] = (int(
            round(float(state.nodes[cons_pair[0]].y))))
        constraints_coordinates[k][2] = (int(
            round(float(state.nodes[cons_pair[1]].x))))
        constraints_coordinates[k][3] = (int(
            round(float(state.nodes[cons_pair[1]].y))))
        k = k + 1
    return constraints_coordinates


#z
print("Graph number:")
graph = "graph"
graph += raw_input("")
graph += ".txt"
state, cons = readfile.read_graph(graph)
t = Thread(target=worker)
t.start()
# Setting up lists and variables used by the GUI to draw the graph
circle_matrix = generate_circle_matrix(state)
constraints_coordinates = generate_coordinates(state, cons)
lowest_x, lowest_y, highest_x, highest_y = findLowestAndHighestValues(
    circle_matrix)
y_multi = ((window_size_y - 100) / highest_y)
x_multi = ((window_size_x - 100) / highest_x)

app = QApplication([])
circles = Draw()
circles.show()
Astar_GAC.show_gui = True
Astar_GAC.Astar(state, cons)
Exemplo n.º 3
0
def deg_main(graph_adj, num_seeds, ratio, rounds, final_name):
    k = int(num_seeds * ratio)
    degree_info = degree_centrality(graph_adj)
    top_k_nodes = select_top_k(degree_info, k)
    random_choice_out(rounds, num_seeds, top_k_nodes, final_name)


if __name__ == "__main__":

    filename = sys.argv[1]
    num_seeds = int(sys.argv[2])
    final_name = "_".join(filename.split('.')) + "_deg.txt"

    ratio = 1.5
    rounds = 50
    graph_adj = readfile.read_graph(filename)

    deg_main(graph_adj, num_seeds, ratio, rounds, final_name)

    # k = int(num_seeds * ratio)

    # degree_info = degree_centrality(graph_adj)
    # # print "degree: ", degree_info
    # top_k_nodes = select_top_k(degree_info, k)
    # print "top k: ", top_k_nodes

    # indices = list(range(num_seeds))

    # fid = open(final_name, 'w')
    # for i in range(rounds):
    # 	shuffled_indices = np.random.permutation(indices)
Exemplo n.º 4
0
    return color_matrix


color_matrix = []
rectMatrix = []
graphs = [
    "camel", "cat", "heart", "rabbit", "telephone", "sailboat", "custom2", "1",
    "2", "3", "4", "5"
]
print "Pick a picture:"
print "1: camel \n2: cat \n3: heart \n4: rabbit \n5: telephone \n6: sailboat\n7: custom\n8: 1 \n9: 2 \n 10: 3 \n 11: 4 \n 12: 5 "
graph = "nono-"
graph += graphs[int(raw_input("")) - 1]
graph += ".txt"

cols_size, rows_size = readfile.getSizes(graph)
cols_px, rows_px = calculate_size(cols_size, rows_size)
color_matrix = initialise_color_matrix()
app = QApplication([])
circles = Draw()
rectMatrix = generate_rectMatrix(color_matrix)

t = Thread(target=worker)
t.start()
circles.show()
start_state, rows, cols = readfile.read_graph(graph)
#k = Thread(target=AstarGac.Astar, args=(start_state,rows,cols))
#k.start()
AstarGac.Astar(start_state, rows, cols)
app.exec_()
Exemplo n.º 5
0
            temp, board = current_state.make_board()
            gui.rectMatrix = gui.generate_rectMatrix(
                gui.generate_color_matrix(board))
            gui.app.processEvents()
            time.sleep(algorithm_delay)

            children = generate_child_states(current_state)
            all_states[current_state.get_h()].remove(current_state)
            #
        else:
            current_state = get_best_state(all_states)
            children = generate_child_states(current_state)
            all_states[current_state.get_h() +
                       current_state.get_g()].remove(current_state)

        #


#

show_gui = True
show_gui_revise = False
show_gui_filter = True

algorithm_delay = 0
if __name__ == '__main__':

    start_state, rows, cols = rf.read_graph(
        "nono-cat.txt")  #Ikke ende her, endre i gui
    Astar(start_state, rows, cols)
Exemplo n.º 6
0
def run(delay):
	if not show_gui:
		s, c = rf.read_graph("graph6.txt")
		Astar(s, c)
	else:
		algorithm_delay = delay
Exemplo n.º 7
0
def run(delay):
    if not show_gui:
        s, c = rf.read_graph("graph6.txt")
        Astar(s, c)
    else:
        algorithm_delay = delay
Exemplo n.º 8
0
			gui.app.processEvents()
			temp, board = current_state.make_board()
			gui.rectMatrix = gui.generate_rectMatrix(gui.generate_color_matrix(board))
			gui.app.processEvents()
			time.sleep(algorithm_delay)


			children = generate_child_states(current_state)
			all_states[current_state.get_h()].remove(current_state)
			#
		else:
			current_state = get_best_state(all_states)
			children = generate_child_states(current_state)
			all_states[current_state.get_h()+current_state.get_g()].remove(current_state)

		#
#


show_gui = True
show_gui_revise = False
show_gui_filter = True


algorithm_delay = 0
if __name__ == '__main__':

	start_state, rows, cols = rf.read_graph("nono-cat.txt") #Ikke ende her, endre i gui
	Astar(start_state,rows,cols)

Exemplo n.º 9
0
	# This function makes a list containing the x and y coordinates of each pair of connected nodes
	constraints_coordinates=[[0 for x in xrange(4)] for x in xrange(len(cons))] # constraints_coordinates[0][0]= node 1 - x, [0][1] =node 1 - y, [0][2] = node 2 - x, [0][3] = node 2 -y
	k=0
	for cons_pair in cons:
		constraints_coordinates[k][0] = (int(round(float(state.nodes[cons_pair[0]].x))))
		constraints_coordinates[k][1] = (int(round(float(state.nodes[cons_pair[0]].y))))
		constraints_coordinates[k][2] = (int(round(float(state.nodes[cons_pair[1]].x))))
		constraints_coordinates[k][3] = (int(round(float(state.nodes[cons_pair[1]].y))))
		k = k + 1
	return constraints_coordinates
#z
print ("Graph number:")
graph = "graph"
graph += raw_input("")
graph += ".txt"
state, cons = readfile.read_graph(graph)
t = Thread(target=worker)
t.start()
# Setting up lists and variables used by the GUI to draw the graph
circle_matrix           = generate_circle_matrix(state)
constraints_coordinates = generate_coordinates(state, cons)
lowest_x,lowest_y,highest_x,highest_y = findLowestAndHighestValues(circle_matrix)
y_multi = ((window_size_y-100)/highest_y)
x_multi = ((window_size_x-100)/highest_x)

app = QApplication([])
circles = Draw()
circles.show()
Astar_GAC.show_gui = True
Astar_GAC.Astar(state,cons)
app.exec_()