/// <summary> /// Adds or updates an edge. /// </summary> public sealed override void AddOrUpdateEdge(DirectedMetaGraph graph, uint vertex1, uint vertex2, uint contractedId, bool?direction, float weight) { graph.AddOrUpdateEdge(vertex1, vertex2, weight, direction, contractedId); }
public void TestAddOrUpdateEdge() { // build graph. var graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size, ContractedEdgeDataSerializer.MetaSize); graph.AddEdge(0, 1, 100, null, Constants.NO_VERTEX); // update. graph.AddOrUpdateEdge(0, 1, 99, null, Constants.NO_VERTEX); // check result. var edges = new List <MetaEdge>(graph.GetEdgeEnumerator(0).Where(x => x.Neighbour == 1)); Assert.AreEqual(1, edges.Count); Assert.AreEqual(1, edges[0].Neighbour); var edgeData = ContractedEdgeDataSerializer.Deserialize(edges[0].Data[0], edges[0].MetaData[0]); Assert.AreEqual(null, edgeData.Direction); Assert.AreEqual(Constants.NO_VERTEX, edgeData.ContractedId); Assert.AreEqual(99, edgeData.Weight); // build graph. graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size, ContractedEdgeDataSerializer.MetaSize); graph.AddEdge(0, 1, 100, null, Constants.NO_VERTEX); // update. graph.AddOrUpdateEdge(0, 1, 101, null, Constants.NO_VERTEX); // check result. edges = new List <MetaEdge>(graph.GetEdgeEnumerator(0).Where(x => x.Neighbour == 1)); Assert.AreEqual(1, edges.Count); Assert.AreEqual(1, edges[0].Neighbour); edgeData = ContractedEdgeDataSerializer.Deserialize(edges[0].Data[0], edges[0].MetaData[0]); Assert.AreEqual(null, edgeData.Direction); Assert.AreEqual(Constants.NO_VERTEX, edgeData.ContractedId); Assert.AreEqual(100, edgeData.Weight); // build graph. graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size, ContractedEdgeDataSerializer.MetaSize); graph.AddEdge(0, 1, 100, true, Constants.NO_VERTEX); // update. graph.AddOrUpdateEdge(0, 1, 99, true, Constants.NO_VERTEX); // check result. edges = new List <MetaEdge>(graph.GetEdgeEnumerator(0).Where(x => x.Neighbour == 1)); Assert.AreEqual(1, edges.Count); Assert.AreEqual(1, edges[0].Neighbour); edgeData = ContractedEdgeDataSerializer.Deserialize(edges[0].Data[0], edges[0].MetaData[0]); Assert.AreEqual(true, edgeData.Direction); Assert.AreEqual(Constants.NO_VERTEX, edgeData.ContractedId); Assert.AreEqual(99, edgeData.Weight); // build graph. graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size, ContractedEdgeDataSerializer.MetaSize); graph.AddEdge(0, 1, 100, null, Constants.NO_VERTEX); // update. graph.AddOrUpdateEdge(0, 1, 99, true, Constants.NO_VERTEX); // check result. var edge = graph.GetEdgeEnumerator(0).First(x => x.Neighbour == 1 && ContractedEdgeDataSerializer.Deserialize(x.Data[0], x.MetaData[0]).Direction == false); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], edge.MetaData[0]); Assert.AreEqual(Constants.NO_VERTEX, edgeData.ContractedId); Assert.AreEqual(100, edgeData.Weight); edge = graph.GetEdgeEnumerator(0).First(x => x.Neighbour == 1 && ContractedEdgeDataSerializer.Deserialize(x.Data[0], x.MetaData[0]).Direction == true); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], edge.MetaData[0]); Assert.AreEqual(Constants.NO_VERTEX, edgeData.ContractedId); Assert.AreEqual(99, edgeData.Weight); // build graph. graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size, ContractedEdgeDataSerializer.MetaSize); graph.AddEdge(0, 1, 100, false, Constants.NO_VERTEX); // update. graph.AddOrUpdateEdge(0, 1, 99, true, Constants.NO_VERTEX); // check result. edge = graph.GetEdgeEnumerator(0).First(x => x.Neighbour == 1 && ContractedEdgeDataSerializer.Deserialize(x.Data[0], x.MetaData[0]).Direction == false); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], edge.MetaData[0]); Assert.AreEqual(Constants.NO_VERTEX, edgeData.ContractedId); Assert.AreEqual(100, edgeData.Weight); edge = graph.GetEdgeEnumerator(0).First(x => x.Neighbour == 1 && ContractedEdgeDataSerializer.Deserialize(x.Data[0], x.MetaData[0]).Direction == true); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], edge.MetaData[0]); Assert.AreEqual(Constants.NO_VERTEX, edgeData.ContractedId); Assert.AreEqual(99, edgeData.Weight); // build graph. graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size, ContractedEdgeDataSerializer.MetaSize); graph.AddEdge(0, 1, 100, false, Constants.NO_VERTEX); graph.AddEdge(0, 1, 99, true, Constants.NO_VERTEX); // update. graph.AddOrUpdateEdge(0, 1, 98, null, Constants.NO_VERTEX); // check result. edge = graph.GetEdgeEnumerator(0).First(x => x.Neighbour == 1 && ContractedEdgeDataSerializer.Deserialize(x.Data[0], x.MetaData[0]).Direction == null); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], edge.MetaData[0]); Assert.AreEqual(Constants.NO_VERTEX, edgeData.ContractedId); Assert.AreEqual(98, edgeData.Weight); // build graph. graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size, ContractedEdgeDataSerializer.MetaSize); graph.AddEdge(0, 1, 100, false, Constants.NO_VERTEX); graph.AddEdge(0, 1, 98, true, Constants.NO_VERTEX); // update. graph.AddOrUpdateEdge(0, 1, 99, null, Constants.NO_VERTEX); // check result. edge = graph.GetEdgeEnumerator(0).First(x => x.Neighbour == 1 && ContractedEdgeDataSerializer.Deserialize(x.Data[0], x.MetaData[0]).Direction == false); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], edge.MetaData[0]); Assert.AreEqual(Constants.NO_VERTEX, edgeData.ContractedId); Assert.AreEqual(99, edgeData.Weight); edge = graph.GetEdgeEnumerator(0).First(x => x.Neighbour == 1 && ContractedEdgeDataSerializer.Deserialize(x.Data[0], x.MetaData[0]).Direction == true); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], edge.MetaData[0]); Assert.AreEqual(Constants.NO_VERTEX, edgeData.ContractedId); Assert.AreEqual(98, edgeData.Weight); // build graph. graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size, ContractedEdgeDataSerializer.MetaSize); graph.AddEdge(0, 1, 100, null, Constants.NO_VERTEX); // update. graph.AddOrUpdateEdge(0, 2, 99, null, Constants.NO_VERTEX); // check result. edge = graph.GetEdgeEnumerator(0).First(x => x.Neighbour == 2 && ContractedEdgeDataSerializer.Deserialize(x.Data[0], x.MetaData[0]).Direction == null); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], edge.MetaData[0]); Assert.AreEqual(Constants.NO_VERTEX, edgeData.ContractedId); Assert.AreEqual(99, edgeData.Weight); }