public WeightMatrixEdge(WeightMatrixNode <T> n1, WeightMatrixNode <T> n2, float w, bool bidirectional) { m_node1 = n1; m_node2 = n2; weight = w; undirected = bidirectional; }
public override bool Equals(object obj) { if (obj is WeightMatrixNode <T> ) { WeightMatrixNode <T> node = obj as WeightMatrixNode <T>; return(index == node.index); } return(false); }
public IGraphEdge <T> AddDirectedEdge(IGraphNode <T> node1, IGraphNode <T> node2, float weight = 1) { Debug.Assert(node1 is WeightMatrixNode <T>); Debug.Assert(node2 is WeightMatrixNode <T>); WeightMatrixNode <T> n1 = node1 as WeightMatrixNode <T>; WeightMatrixNode <T> n2 = node2 as WeightMatrixNode <T>; ++EdgeCount; weights[n1.index, n2.index] = weight; return(new WeightMatrixEdge <T>(n1, n2, weight, false)); }
public IEnumerable <IGraphEdge <T> > GetEdges(IGraphNode <T> node) { Debug.Assert(node is WeightMatrixNode <T>); WeightMatrixNode <T> n1 = node as WeightMatrixNode <T>; int i = n1.index; for (int j = 0; j < weights.GetLength(1); ++j) { if (weights[i, j] < Mathf.Infinity) { WeightMatrixNode <T> n2 = new WeightMatrixNode <T>(j, nodeValues[j]); yield return(new WeightMatrixEdge <T>(n1, n2, weights[i, j], weights[i, j] == weights[j, i])); } } }
public IGraphEdge <T> GetEdge(IGraphNode <T> node1, IGraphNode <T> node2) { Debug.Assert(node1 is WeightMatrixNode <T>); Debug.Assert(node2 is WeightMatrixNode <T>); WeightMatrixNode <T> n1 = node1 as WeightMatrixNode <T>; WeightMatrixNode <T> n2 = node2 as WeightMatrixNode <T>; float weight = weights[n1.index, n2.index]; if (weight == Mathf.Infinity) { return(null); } return(new WeightMatrixEdge <T>(n1, n2, weight, weight == weights[n2.index, n1.index])); }