User Tools

Site Tools


boissier:solution_homework1_exercise2
Critères Commentaire(s) Points attribués
(2) Algo (justesse) DFS / file 2
(2) Code (structure) Bien 2
(2) Code (lisibilité) Voir commentaires 1.5
(1) Paramétrage (choix sommet départ) Aucun. Utilisation de la fct getOneNode() 0
(1) Mise à disposition Il m'a fallu copier coller depuis le wiki … pas de fichier joint. 0
(8) Total 5.5
  • Algo et code: coloration des arêtes bonne idée pour “visualiser” l'arbre implicitement calculé par l'algo.
  • Lisibilité: vous laissez traîner des portions de code inutile dans le main().

Guy Melançon 2012/03/09 21:17


from tulip import *
from collections import deque
import random
import time

def main(graph) : 
	viewBorderColor =  graph.getColorProperty("viewBorderColor")
	viewBorderWidth =  graph.getDoubleProperty("viewBorderWidth")
	viewColor =  graph.getColorProperty("viewColor")
	viewFont =  graph.getStringProperty("viewFont")
	viewFontSize =  graph.getIntegerProperty("viewFontSize")
	viewLabel =  graph.getStringProperty("viewLabel")
	viewLabelColor =  graph.getColorProperty("viewLabelColor")
	viewLabelPosition =  graph.getIntegerProperty("viewLabelPosition")
	viewLayout =  graph.getLayoutProperty("viewLayout")
	viewMetaGraph =  graph.getGraphProperty("viewMetaGraph")
	viewRotation =  graph.getDoubleProperty("viewRotation")
	viewSelection =  graph.getBooleanProperty("viewSelection")
	viewShape =  graph.getIntegerProperty("viewShape")
	viewSize =  graph.getSizeProperty("viewSize")
	viewSrcAnchorShape =  graph.getIntegerProperty("viewSrcAnchorShape")
	viewSrcAnchorSize =  graph.getSizeProperty("viewSrcAnchorSize")
	viewTexture =  graph.getStringProperty("viewTexture")
	viewTgtAnchorShape =  graph.getIntegerProperty("viewTgtAnchorShape")
	viewTgtAnchorSize =  graph.getSizeProperty("viewTgtAnchorSize")

	for n in graph.getNodes():
		print n

	bfs(graph)

	updateVisualization()


def bfs(graph):
	first_node = graph.getOneNode()
	visited_list = []
	queue = deque([])

	visited_list.append(first_node)
	color_one_node(graph, first_node)
	queue.append(first_node)

	while (len(queue) != 0):
		my_node = queue.popleft()
		for i in graph.getInOutNodes(my_node):
			if (not (i in visited_list)):
				test_edge = graph.existEdge(my_node, i)
				if (not (test_edge.isValid())):
					test_edge = graph.existEdge(i, my_node)
				color_one_edge(graph, test_edge)
				visited_list.append(i)
				color_one_node(graph, i)
#				VISUAL
				updateVisualization()
				time.sleep(0.05)
#				FIN VISUAL
				queue.append(i)
#		VISUAL
		updateVisualization()
		time.sleep(0.05)
#		FIN VISUAL



def color_one_edge(graph, edge):
	color = graph.getColorProperty("viewColor")
	color.setEdgeValue(edge, tlp.Color(0, 255, 0 , 255));

def color_one_node(graph, node):
	color = graph.getColorProperty("viewColor")
	color.setNodeValue(node, tlp.Color(0, 255, 0 , 255));
/net/html/perso/melancon/Visual_Analytics_Course/data/pages/boissier/solution_homework1_exercise2.txt · Last modified: 2012/03/09 22:09 by melancon