public static DirectedGraphWithPointID GetInducedSubgraph(DirectedGraphWithPointID CurrentGraph, IEnumerable <Point> PointCollection) { DirectedGraphWithPointID OutGraph = new DirectedGraphWithPointID(String.Format("Induced \"{0}\"", CurrentGraph.GraphName), CurrentGraph.PointNamePrefix, new AbstractEdgeEqualityComparer <PointWithID>()); IEnumerable <EdgePointID> edgeCollection = CurrentGraph.EdgeCollection.Where(i1 => PointCollection.Contains(i1.StartPoint) && PointCollection.Contains(i1.EndPoint)); foreach (PointWithID p in PointCollection) { OutGraph.AddPoint(p); } foreach (EdgePointID e in edgeCollection) { OutGraph.AddEdge(e); } return(OutGraph); }
public static DirectedGraphWithPointID GetSpanningSubgraph(DirectedGraphWithPointID CurrentGraph, SelectionCondition <EdgePointID> EdgeSelectionCondition) { DirectedGraphWithPointID OutGraph = new DirectedGraphWithPointID(String.Format("Spanning \"{0}\"", CurrentGraph.GraphName), CurrentGraph.PointNamePrefix, new AbstractEdgeEqualityComparer <PointWithID>()); IEnumerable <EdgePointID> edgeCollection = CurrentGraph.EdgeCollection.Where(i1 => EdgeSelectionCondition(i1)); foreach (PointWithID p in CurrentGraph.PointCollection) { OutGraph.AddPoint(p); } foreach (EdgePointID e in edgeCollection) { OutGraph.AddEdge(e); } return(OutGraph); }
public static DirectedGraphWithPointID GenerateRandomDirectedGraphWithPointID(string GraphName, string PointNamePrefix, int PointCount, int EdgeCount) { if (EdgeCount > Math.Pow(PointCount, 2)) { throw new Exception("Count of > PointCount^2"); } DirectedGraphWithPointID OutGraph = GenerateEmptyDirectedGraphWithPointID(GraphName, PointNamePrefix, PointCount); List <PointWithID> ListPoints = OutGraph.PointCollection.ToList(); for (int i = 1; i <= EdgeCount;) { if (OutGraph.AddEdge(new EdgePointID(GraphName + "_" + i.ToString(), ListPoints[GlobalRandom.Next(0, ListPoints.Count)], ListPoints[GlobalRandom.Next(0, ListPoints.Count)]))) { i++; } } return(OutGraph); }