User Tools

Site Tools


dehau:solution_homework1_exercise2
Critères Commentaire(s) Points attribués
(2) Algo (justesse) BFS / file 2
(2) Code (structure) Bien 2
(2) Code (lisibilité) Voir commentaires 1
(1) Paramétrage (choix sommet départ) Départ sommet sélectionné 1
(1) Mise à disposition Fichier Tulip compressé. 1
(8) Total 7
  • Algo: juste, bonne utilisation des particularités python sur les listes pour utiliser une file.
  • Lisibilité: vous laissez traîner des portions de code inutile dans le main(). Aucun commentaire dans le code ne dit si vous implémentez un BFS ou un DFS … Vos commentaires sont inexacts. Vous n'utiilisez pas une “stack”, mais une file “FIFO queue”.

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


# Powered by Python 2.7

# To cancel the modifications performed by the script # on the current graph, click on the undo button.

# Some useful keyboards shortcuts : # * Ctrl + D : comment selected lines. # * Ctrl + Shift + D : uncomment selected lines. # * Ctrl + Space : run script. # * Ctrl + F : find selected text. # * Ctrl + R : replace selected text.

from tulip import *

# the updateVisualization(centerViews = True) function can be called # during script execution to update the opened views

# the pauseScript() function can also be called to pause the script execution. # To resume the script execution, you will have to click on the “Run script ” button.

# the main(graph) function must be defined # to run the script on the current graph

def main(graph) :

degre =  graph.getDoubleProperty("degre")
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")
viewMetric =  graph.getDoubleProperty("viewMetric")
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")
rouge = tlp.Color(255, 0, 0)
vert = tlp.Color(0, 255, 0)

q = []
visite = {}

# All nodes are not visited
for n in graph.getNodes():
	print n
	visite[n] = False
	viewColor.setNodeValue(n, rouge)
for e in graph.getEdges() :
	viewColor.setEdgeValue(e, rouge)
	
# given nodes(selected).
for n in graph.getNodes() :
	if viewSelection.getNodeValue(n) :
		q.append(n)	
		viewColor.setNodeValue(n, vert) # Add to subgraph.
		visite[n] = True

while q != []: # while the stack is not empty
	n = q.pop(0) # grab a node from the stack and delete it from the stack	
	for u in graph.getInOutNodes(n) : # put its neighbors on the stack (if they are not already in the stack)
		if visite[u] == False : 
			q.append(u) #Add u to the stack if not already visited
		
			e = graph.existEdge(n,u)
			if not e.isValid():
				e = graph.existEdge(u,n)
			viewColor.setEdgeValue(e, vert)
			
		visite[u] = True#Add to visited
		viewColor.setNodeValue(u, vert) # Add to subgraph
		
		updateVisualization()

print("vide")
/net/html/perso/melancon/Visual_Analytics_Course/data/pages/dehau/solution_homework1_exercise2.txt · Last modified: 2012/03/09 21:49 by melancon