public Boolean equals(Arc arc) { //La valeur est unique à chaque Noeud. if(this.cost == arc.cost && this.origin == arc.getOrigin() && this.edge == arc.getEdge()) return true; else return false; }
/// <summary> /// Ajoute un arc au graphe: void addArc(Arc) /// </summary> public void addArc(Arc arc) { _arcs.Add(arc); sortArcList(); //replace l'arc dans le tableau int x = 0, y = 0; x = arc.getOrigin().getIndex(); y = arc.getEdge().getIndex(); costMatrix.setValueAt(arc.getCost(), x, y); }
public void addLinkedArc(Arc arc, bool ingress) { if (ingress) { sortArcList(this.ingressArc); this.ingressArc.Add(arc); } else { sortArcList(this.egressArc); this.egressArc.Add(arc); } }
public void deleteArc(Arc arc) { //On enlève l'arc des noeuds lui étant liés arc.getOrigin().removeLinkedArc(arc, false); arc.getEdge().removeLinkedArc(arc, true); //On actualise la valeur dans la matrice int x = arc.getOrigin().getIndex(); int y = arc.getEdge().getIndex(); costMatrix.setValueAt(int.MaxValue, x, y); //On enlève l'arc du graphe _arcs.Remove(arc); //On actualise l'ordre des arbres dans la liste sortArcList(); }
//Permet de générer un graphe à partir de la matrice des coûts public void generateGraph(Object[,] costM) { if (costM != null) { if (costM.GetLength(0) == costM.GetLength(1) - 1) // On vérifie que la matrice est carrée { //Création des sommets for (int i = 0; i < costM.GetLength(0); i++) _nodes.Add(new Node(i, (String)costM[i,0])); for (int i = 0; i < costM.GetLength(0); i++) { for (int j = 1; j < costM.GetLength(1); j++) { if (costM[i, j] != null) { if ((Int32)costM[i, j] != 0 && (Int32)costM[i, j] != int.MaxValue) //Si la valeur est de 0, c-à-d d'un sommet vers lui même avec un chemin de valeur 0, alors il n'y a pas d'arcs. { Arc a = new Arc((Int32)costM[i, j], _nodes[i], _nodes[j - 1]); _nodes[i].addLinkedArc(a, false); //ajout d'un degré sortant au noeud d'origine de l'arc _nodes[j - 1].addLinkedArc(a, true); //ajout d'un degré entrant au noeud d'extrémité de l'arc _arcs.Add(a); } } } } } else Console.WriteLine("Erreur: La matrice n'est pas carrée."); } }
public void removeLinkedArc(Arc arc, bool ingress) { if (ingress) this.ingressArc.Remove(arc); else this.egressArc.Remove(arc); }