コード例 #1
0
ファイル: Bellman.cs プロジェクト: T-Dnzt/Graphe-Sharp
 //Fonctionnel
 public Bellman(Graph graph, Node origine)
 {
     path = new Dictionary<Node, Dictionary<List<Node>, Int32>>();
     this.g = graph;
     this.o = origine;
     execute(g, o);
 }
コード例 #2
0
ファイル: Graph.cs プロジェクト: T-Dnzt/Graphe-Sharp
        public void addNode(Node nodes)
        {
            refreshIndex();//On s'assure de la bonne position des index

            int index = 0;
            if(_nodes.Count > 0)
                index = _nodes.Last().getIndex() + 1;
            nodes.setIndex(index);
            _nodes.Add(nodes);
            updateMatrix();
        }
コード例 #3
0
ファイル: TreeDepthFirst.cs プロジェクト: T-Dnzt/Graphe-Sharp
        public TreeDepthFirst(Graph graph, Node origine)
        {
            depthFirstTree = new Graph();
            depthFirstTree.setMatrix(graph.getMatrix());
            this.graph = graph;
            this.origine = origine;

            foreach (Node n in graph.getNodeList())
            {
                n.unmarkNode();
            }
        }
コード例 #4
0
ファイル: Dijkstra.cs プロジェクト: T-Dnzt/Graphe-Sharp
        public void definePath(Node n)
        {
            if (n.getName() != n.getPredecessor().getName())
            {

                    if (n.getPredecessor().getPredecessor().getName() != n.getPredecessor().getName())
                    {
                        listNodePath.Add(n.getPredecessor());
                    }
                    definePath(n.getPredecessor());

            }
        }
コード例 #5
0
ファイル: Arc.cs プロジェクト: T-Dnzt/Graphe-Sharp
 public void setEdge(Node edge)
 {
     bool exist = false;
     int i = 0;
     //On vérifie qu'il n'y a pas déjà un arc existant entre le sommet d'origine et d'extrêmité.
     while (!exist && i < edge.getIngressArc().Count())
     {
         if (this.origin == edge.getIngressArc().ElementAt(i).getOrigin())
             exist = true;
         i++;
     }
     if (!exist)
         this.edge = edge;
        else
         Console.WriteLine("This arc already exist");
 }
コード例 #6
0
        private void strongConnect(Graph g, Node n)
        {
            n.setIndexSCC(index);
            n.setLowlink(index);

            index++;

            s.Add(n);

            foreach (Arc a in g.getArcList())
            {
                if (a.getOrigin() == n)
                {
                    if (a.getEdge().getIndexSCC() == int.MaxValue)
                    {
                        strongConnect(g, a.getEdge());
                        n.setLowlink(Math.Min(n.getLowlink(), a.getEdge().getLowlink()));
                    }
                    else if(s.Contains(a.getEdge()))
                    {
                        n.setLowlink(Math.Min(n.getLowlink(), a.getEdge().getIndexSCC()));

                    }

                }

            }

            if (n.getLowlink() == n.getIndexSCC())
            {

               scc.Add(new List<Node>());
               Node w = new Node();

                do
                {
                    w = s.Last();

                    s.Remove(s.Last());
                    scc.Last().Add(w);

                }
                while (n != w);

            }
        }
コード例 #7
0
ファイル: TreeDepthFirst.cs プロジェクト: T-Dnzt/Graphe-Sharp
        public void execute(Graph graph, Node node)
        {
            //On marque le noeud
                node.markNode();

                //On copie les caractéristiques du noeud dans un nouveau noeud
                 Node n = new Node(node.getIndex(), node.getName());

                //On ajoute ce dernier au graphe
                 depthFirstTree.addNode(n);

                //Pour chaque arc partant du noeud :
                foreach (Arc a in node.getEgressArc())
                {
                    if (a.getEdge().getNodeState() == false)
                    {
                        Node e = new Node(a.getEdge().getIndex(), a.getEdge().getName());
                        depthFirstTree.addArc(new Arc(a.getCost(), n, e));
                        execute(graph, a.getEdge());
                    }
                }
        }
コード例 #8
0
ファイル: Bellman.cs プロジェクト: T-Dnzt/Graphe-Sharp
        //Méthode implémentant l'algorithme de Bellman-Ford
        public Dictionary<Node, Dictionary<List<Node>, Int32>> execute(Graph graph, Node origine)
        {
            //Pour chaque noeud contenu dans le graphe
            foreach (Node n in graph.getNodeList())
            {
                //Si le noeud est égal à l'origine(passée en paramètre)
                if (n.Equals(origine))
                {
                    //La distance est donc de 0
                    n.setDistance(0);
                    //On définit le prédécesseur de l'origine à lui même
                    n.setPredecessor(n);
                }
                else
                {
                    //Si le noeud n'est pas l'origine, on définit une valeur correspondant à "l'infini"
                    n.setDistance(2000000000);
                    //On vide les variables predecessor de noeuds
                    n.setPredecessor(null);
                }
            }

            //Pour le nombre de noeud contenu dans le graphe
            for (Int32 i = 1; i < graph.getNodeList().Count; i++)
            {

                //Pour chaque arc du graphe
                foreach (Arc az in graph.getArcList())
                {
                    //On définit l'origine de l'arc en cours dans le noeud a
                    Node a = az.getOrigin();
                    //On définit l'extrémité de l'arc en cours dans le noeud z
                    Node z = az.getEdge();

                    //Si la distance pour atteindre le noeud a + le coût de l'arc en cours est inférieur à la distance pour atteindre le noeud z
                    if (a.getDistance() + az.getCost() < z.getDistance())
                    {
                        //Alors on définit une nouvelle distance pour atteindre z égale à la distance pour atteindre le noeud a + le coût de l'arc en cours
                        z.setDistance(a.getDistance() + az.getCost());
                        //De plus, on définit l'origine de l'arc en cours en tant que prédécesseur de l'extrémité z
                        z.setPredecessor(a);

                        //Création d'une chaîne de caractères qui contiendra les noeuds de passage
                        //chemin = "";
                        //Ajoute des informations dans le tableau listString
                        //listString.Add("Origine : "+node.getName()+" - Extrémité : "+z.getName()+" - Distance : "+z.getDistance()+" - Par "+definePath(z));

                        Dictionary<List<Node>, Int32> dtemp = new Dictionary<List<Node>, Int32>();
                        listNodePath = new List<Node>();

                            if (path.Keys.Contains(z))
                            {
                                dtemp.Remove(listNodePath);
                                path.Remove(z);
                                definePath(z);
                                listNodePath.Add(origine);
                                dtemp.Add(listNodePath, z.getDistance());
                                path.Add(z, dtemp);

                            }
                            else
                            {

                                definePath(z);
                                listNodePath.Add(origine);
                                dtemp.Add(listNodePath, z.getDistance());
                                path.Add(z, dtemp);

                            }

                    }
                }
            }

            //Boucle foreach permettant de vérifier que le graphe ne contient pas de cycle de poids négatif
            foreach (Arc az in graph.getArcList())
            {
                Node a = az.getOrigin();
                Node z = az.getEdge();
                if (a.getDistance() + az.getCost() < z.getDistance())
                {
                    Console.WriteLine("Le graphe contient un cycle de poids négatif");
                }
            }

            return path;
        }
コード例 #9
0
ファイル: Actions.cs プロジェクト: T-Dnzt/Graphe-Sharp
 //Floyd
 public String Floyd(ref Graph graph, ref Node node)
 {
     return "";
 }
コード例 #10
0
ファイル: DepthFirst.cs プロジェクト: T-Dnzt/Graphe-Sharp
        //Parcours en profondeur du graph à partir du noeud passé en paramètre
        public void executeDFS(Graph graph, Node origine)
        {
            origine.markNode();

            foreach (Arc a in origine.getEgressArc())
            {

                if (a.getEdge().getNodeState() == false)
                {
                    depthFirstPath.Add(a.getEdge(), a.getOrigin());
                    executeDFS(graph, a.getEdge());
                }
            }
        }
コード例 #11
0
ファイル: Dijkstra.cs プロジェクト: T-Dnzt/Graphe-Sharp
        public Dictionary<Node, Dictionary<List<Node>, Int32>> execute(Graph g, Node origine)
        {
            Queue = new List<Node>();

            foreach (Node n in g.getNodeList())
            {
                Queue.Add(n);

                if (n.Equals(origine))
                {
                    n.setDistance(0);
                    n.setPredecessor(n);

                }
                else
                {
                    n.setDistance(2000000000);
                    n.setPredecessor(null);
                }

            }

            while (Queue.Count > 0)
            {
                Node u = getSmallest(Queue);

                if (u.getDistance() == 2000000000)
                {
                    break;
                }

                Queue.Remove(u);

                foreach (Arc a in g.getArcList())
                {
                    if (a.getOrigin() == u && Queue.Contains(a.getEdge()))
                    {

                        Node z = a.getEdge();

                       // Console.WriteLine(o.getName() + " -- " + z.getName());

                        Int32 tempDistance = u.getDistance() + a.getCost();
                       // Console.WriteLine("Distance origine : "+u.getDistance()+" - Cout arc : "+a.getCost()+ " tmp : "+tempDistance+" - Distance extremite : "+z.getDistance());
                        if (tempDistance < z.getDistance())
                        {
                            z.setDistance(tempDistance);
                            z.setPredecessor(u);

                            Dictionary<List<Node>, Int32> dtemp = new Dictionary<List<Node>, Int32>();
                            listNodePath = new List<Node>();

                            if (path.Keys.Contains(z))
                            {
                                dtemp.Remove(listNodePath);
                                path.Remove(a.getEdge());

                                definePath(z);
                                listNodePath.Add(origine);
                                dtemp.Add(listNodePath, z.getDistance());
                                path.Add(z, dtemp);
                               // Console.WriteLine("lol distance : "+z.getName()+" = "+z.getDistance());

                            }
                            else
                            {
                                definePath(a.getEdge());
                                listNodePath.Add(origine);
                                dtemp.Add(listNodePath, z.getDistance());
                                path.Add(z, dtemp);
                                //Console.WriteLine("lol2 distance : " + z.getName() + " = " + z.getDistance());
                            }

                        }
                      //  Console.WriteLine();

                    }
                }
            }

            return path;
        }
コード例 #12
0
ファイル: Arc.cs プロジェクト: T-Dnzt/Graphe-Sharp
 public void setOrigin(Node origin)
 {
     this.origin = origin;
 }
コード例 #13
0
ファイル: Arc.cs プロジェクト: T-Dnzt/Graphe-Sharp
 public Arc(Int32 cost, Node origin, Node edge)
 {
     this.cost = cost;
     this.origin = origin;
     this.edge = edge;
 }
コード例 #14
0
ファイル: Arc.cs プロジェクト: T-Dnzt/Graphe-Sharp
 public Arc(Int32 cost, Node origin)
 {
     this.cost = cost;
     this.origin = origin;
     this.edge = null;
 }
コード例 #15
0
ファイル: Arc.cs プロジェクト: T-Dnzt/Graphe-Sharp
 public Arc()
 {
     this.cost = 0;
     this.origin = null;
     this.edge = null;
 }
コード例 #16
0
ファイル: Node.cs プロジェクト: T-Dnzt/Graphe-Sharp
 public void setPredecessor(Node n)
 {
     predecessor = n;
 }
コード例 #17
0
ファイル: Graph.cs プロジェクト: T-Dnzt/Graphe-Sharp
 // NOT OK
 public void insertNode(Node nodes)
 {
     _nodes.Insert(nodes.getIndex(), nodes);
     refreshIndex();
     updateMatrix();
 }
コード例 #18
0
ファイル: Actions.cs プロジェクト: T-Dnzt/Graphe-Sharp
 //Bellman
 public String Bellman(ref Graph graph, ref Node node)
 {
     return "";
 }
コード例 #19
0
ファイル: Graph.cs プロジェクト: T-Dnzt/Graphe-Sharp
        public void deleteNode(Node node)
        {
            Console.WriteLine("Suppresion du noeud: " + node.getName());

            //Suppression des arcs liés au sommet supprimé
            List<Arc> arcToDelete = new List<Arc>(); //Liste des arcs qui seront supprimés.

            foreach(Arc val in node.getIngressArc())
                arcToDelete.Add(val);
            foreach (Arc val in node.getEgressArc())
                arcToDelete.Add(val);
            foreach (Arc val in arcToDelete)
                deleteArc(val);

            _nodes.Remove(node);
            //updateMatrix();
            costMatrix.removeNode(node.getIndex());
            refreshIndex();
        }
コード例 #20
0
ファイル: Actions.cs プロジェクト: T-Dnzt/Graphe-Sharp
 //Recherche d'un arbre couvrant à partir d'un sommet racine par parcours en profondeur.
 //Ajout d'un sommet d'arrivé en option ?
 public String depthFirst(ref Graph graph, ref Node node)
 {
     return "";
 }
コード例 #21
0
ファイル: Actions.cs プロジェクト: T-Dnzt/Graphe-Sharp
 //Algorithmes de recherche du plus court chemin
 //Dijkstra: Ne prend pas les valeurs négatives
 public String dijkstra(ref Graph graph, ref Node node)
 {
     return "";
 }
コード例 #22
0
ファイル: DepthFirst.cs プロジェクト: T-Dnzt/Graphe-Sharp
        public DepthFirst(Graph graph, Node origine)
        {
            depthFirstPath = new Dictionary<Node, Node>();
            this.g = graph;
            this.o = origine;

            foreach (Node n in graph.getNodeList())
            {
                n.unmarkNode();
            }

            executeDFS(g, o);
        }