1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
| 'projet InterfaceVB
'-------------------
'-namespace est "InterfaceVB" (voir projet Fortran)
'classe Arc sert à stocker les arcs du programme fortran
Public Class Arc
Public premNoeudVB, deuxNoeudVB As String
Public Longueur As Double
Public Sub New()
Me.premNoeudVB = ""
Me.deuxNoeudVB = ""
Me.Longueur = 0.0
End Sub
End Class
'projet principal frmGraphe
'--------------------------
'-ajouter un controle TextBox
'-ajouter un controle Button
'-ajouter un controle GVIEWER MS GLEE(selectionner : Microsoft.GLEE.Gviewer.dll)
'-referencer Microsoft.GLEE.dll,Microsoft.GLEE.DRAWING.dll
'-referencer QUICKGRAPH.DLL , QUICKGRAPH.GLEE.DLL
'-dependences : projet frmGraphe depend du projet InterfaceVB et du projet Fortran
'-dependences : projet Fortran depend du projet InterfaceVB
'-ordre de generation:InterfaceVB,projet Fortran,frmGraphe
Option Explicit On
Option Compare Text
Imports System
Imports System.Globalization
Imports System.Threading
Imports System.Windows
Imports System.Collections
Imports System.Drawing
'Microsoft GLEE
Imports Microsoft
Imports Microsoft.Glee
Imports Microsoft.Glee.GleeGraph
Imports Microsoft.Glee.Drawing
Imports Microsoft.Glee.GraphViewerGdi
Imports Microsoft.Glee.Splines
Imports Microsoft.Glee.DataBase
Imports Microsoft.Glee.NativeMethods
'QuickGraph
Imports QuickGraph
Imports Algo_Extension = QuickGraph.Algorithms.AlgorithmExtensions
Imports Algo_PredObservSommetEnreg = QuickGraph.Algorithms.Observers.VertexPredecessorRecorderObserver(Of String, QuickGraph.Edge(Of String))
Imports Algo_SommetDistObservEnreg = QuickGraph.Algorithms.Observers.VertexDistanceRecorderObserver(Of String, QuickGraph.Edge(Of String))
Imports BFS = QuickGraph.Algorithms.Search.BreadthFirstSearchAlgorithm(Of String, QuickGraph.Edge(Of String))
Imports Algo_PredObservArcEnreg = QuickGraph.Algorithms.Observers.EdgeRecorderObserver(Of String, QuickGraph.Edge(Of String))
Imports Algo_Connexite = QuickGraph.Algorithms.ConnectedComponents.StronglyConnectedComponentsAlgorithm(Of String, QuickGraph.Edge(Of String))
' QuickGraph.Glee(pour methodes d'extension)
Imports QuickGraph.Glee
Imports InterfaceVB
Imports FortrLib
Public Class frmGraphe
'Variables pour appel a subroutine fortran
'------------------------------------------
Public lstArcs() As Arc
Public monArc As Arc
'declare un graphe d'adjacence simple
Dim monGraph As AdjacencyGraph(Of String, Edge(Of String))
'Gestion du Graphe
'-----------------
'declare "ArcGraph" de type QUICKGRAPH
Dim ArcGraph As QuickGraph.Edge(Of String)
'declare variable "cout Arc" de type Dictionnaire (ArcGraph,longueur)
Dim edgeCost As Dictionary(Of Edge(Of String), Double)
'Exploration du graphe
'--------------------
' declare Algorithme type "BFS"
Dim monBFS As BFS
' declare "sommet Observateur" (chemin d'exploration sommet)
Dim predecessorObserverSommet As Algo_PredObservSommetEnreg = New Algo_PredObservSommetEnreg()
'declare "arc Observateur" (chemin d'exploration arc)
Dim predecessorObserverArc As Algo_PredObservArcEnreg = New Algo_PredObservArcEnreg()
'declare "Observateur Distance" pour avoir la longueur du chemin explore
Dim distObserver As Algo_SommetDistObservEnreg
'Interface Graphique
'-------------------
'declare "Schema Visuel" de type MS GLEE
Dim schemaVisuel As Microsoft.Glee.Drawing.Graph
Public Sub New()
' Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent()
End Sub
Private Sub btnFichierArcs_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFichierArcs.Click
Dim nomFichierArcs As String = ""
Dim dlgOuvreFichier As OpenFileDialog = New OpenFileDialog
dlgOuvreFichier.Filter = "Fichier Arcs(*.txt)|*.txt"
If dlgOuvreFichier.ShowDialog = Forms.DialogResult.OK Then
nomFichierArcs = dlgOuvreFichier.SafeFileName
If Len(nomFichierArcs) = 0 Then
MessageBox.Show("entrer un nom de fichier svp...")
Exit Sub
Else
Call AfficheGraph(nomFichierArcs)
End If
End If
End Sub
Sub AfficheGraph(ByVal nomFichierArcs As String)
' Lit les arcs avec dll fortran
Call FortrLib.ArcsFor(nomFichierArcs, monArc, lstArcs)
'Peuple le "graphe simple " à partir des donnes arcs
monGraph = New AdjacencyGraph(Of String, Edge(Of String))
edgeCost = New Dictionary(Of Edge(Of String), Double)(monGraph.EdgeCount)
Call Peupler_Graphe(monGraph)
'Initiliase Algo BFS
monBFS = New BFS(monGraph)
predecessorObserverSommet.Attach(monBFS)
predecessorObserverArc.Attach(monBFS)
distObserver = New Algo_SommetDistObservEnreg(Algo_Extension.GetIndexer(edgeCost))
distObserver.Attach(monBFS)
'Execute Algo "BFS" avec noeud "SOURCE" comme racine
monBFS.Compute("SOURCE")
'declare evenements noeudAjoute and arcAjoute
Dim noeudAjoute As New QuickGraph.Glee.GleeVertexNodeEventHandler(Of String)(AddressOf populator_NodeAdded)
Dim arcAjoute As New QuickGraph.Glee.GleeEdgeEventHandler(Of String, Edge(Of String))(AddressOf populator_EdgeAdded)
Dim populator As QuickGraph.Glee.GleeGraphPopulator(Of String, QuickGraph.Edge(Of String)) = _
GleeGraphExtensions.CreateGleePopulator(monGraph)
populator.Compute()
'Obtient le graphe pour le controle MS GLEE
schemaVisuel = populator.VisitedGraph.ToGleeGraph(noeudAjoute, arcAjoute)
'Affiche Noeuds et Arcs du Chemin BFS
Call AfficheCheminGraphVisite()
'Presentation Graphique
'Activation Options de Sauvegarde & Scroll
GViewer_BFS.SaveButtonVisible = True
GViewer_BFS.AutoScroll = True
'Affiche le "schemaVisuel" dans le control MS GLEE
GViewer_BFS.Graph = schemaVisuel
End Sub
Sub Peupler_Graphe(ByVal GraphCourant As AdjacencyGraph(Of String, Edge(Of String)))
For Each elem As Arc In lstArcs
'Ajoute Sommets et Arcs au graphe
ArcGraph = New QuickGraph.Edge(Of String)(elem.premNoeudVB, elem.deuxNoeudVB)
GraphCourant.AddVerticesAndEdge(ArcGraph)
'Ajoute "cout arc" Fonction Dictionnaire "edgeCost"
edgeCost.Add(ArcGraph, Double.Parse(elem.Longueur))
Next
End Sub
Sub populator_NodeAdded(ByVal sender As Object, ByVal e As QuickGraph.Glee.GleeVertexEventArgs(Of String))
Dim NoeudStyle As New Microsoft.Glee.Drawing.Style
NoeudStyle = Microsoft.Glee.Drawing.Style.Rounded
Dim nomNoeud As String
nomNoeud = e.Vertex
If nomNoeud = "SOURCE" Then
e.Node.Attr.Color = Microsoft.Glee.Drawing.Color.Black
e.Node.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.Yellow
e.Node.Attr.LineWidth = 2.0
e.Node.Attr.Shape = Microsoft.Glee.Drawing.Shape.Box
e.Node.Attr.AddStyle(NoeudStyle)
e.Node.Attr.FontName = "VERDANA"
e.Node.Attr.Fontcolor = Microsoft.Glee.Drawing.Color.Red
e.Node.Attr.FontName = "Arial"
e.Node.Attr.Fontsize = 10
e.Node.Attr.Label = "Racine: " & nomNoeud
Else
e.Node.Attr.Color = Microsoft.Glee.Drawing.Color.Black
e.Node.Attr.Fillcolor = Microsoft.Glee.Drawing.Color.GreenYellow
e.Node.Attr.LineWidth = 1.0
e.Node.Attr.Shape = Microsoft.Glee.Drawing.Shape.Box
e.Node.Attr.AddStyle(NoeudStyle)
e.Node.Attr.Fontcolor = Microsoft.Glee.Drawing.Color.Black
e.Node.Attr.FontName = "Times New Roman"
e.Node.Attr.Fontsize = 8
e.Node.Attr.Label = nomNoeud
End If
End Sub
Sub populator_EdgeAdded(ByVal sender As Object, ByVal e As QuickGraph.Glee.GleeEdgeEventArgs(Of String, Edge(Of String)))
Dim ArcStyle As New Microsoft.Glee.Drawing.Style
ArcStyle = Microsoft.Glee.Drawing.Style.Solid
Dim Arc As Microsoft.Glee.Drawing.Edge
Arc = e.GEdge
Arc.Attr.Color = Microsoft.Glee.Drawing.Color.Blue
Arc.Attr.LineWidth = 1.0
Arc.Attr.AddStyle(ArcStyle)
ArcStyle = Microsoft.Glee.Drawing.Style.Dashed
Arc.Attr.AddStyle(ArcStyle)
Arc.Attr.FontName = "Verdana"
Arc.Attr.Fontsize = 8
Arc.Attr.Fontcolor = Microsoft.Glee.Drawing.Color.Red
Arc.Attr.Label = "non visite"
'Si Arc dans predecessorObserverArc Changer Couleur("arc dans arbre BFS explore")
If predecessorObserverArc.Edges.Contains(e.Edge) Then
Arc.Attr.Color = Microsoft.Glee.Drawing.Color.Red
Arc.Attr.ClearStyles()
ArcStyle = Microsoft.Glee.Drawing.Style.Solid
Arc.Attr.AddStyle(ArcStyle)
Arc.Attr.LineWidth = 3.0
Arc.Attr.Label = "visite :" & Format(edgeCost(e.Edge), "000.00")
End If
End Sub
Sub AfficheCheminGraphVisite()
'compte Noeuds et Arcs du "graphe visite"
TextBox1.ForeColor = System.Drawing.Color.Red
TextBox1.Font = New Font("courier new", 10, FontStyle.Bold)
TextBox1.Text = "nombre Noeuds :" & (predecessorObserverSommet.VertexPredecessors.Count + 1).ToString & vbCrLf & vbCrLf
TextBox1.Text = TextBox1.Text & "nombre Arcs :" & (predecessorObserverArc.Edges.Count).ToString & vbCrLf & vbCrLf
'affiche Liste des "arcs visites"
For Each CheminArc In predecessorObserverArc.Edges
TextBox1.Text = TextBox1.Text & CheminArc.Source & " -" & CheminArc.Target & vbCrLf
Next
End Sub
End Class |
Partager