public static AdjacencyListGraph <int> CreateShortestPathGraph1() { var vertexKeys = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; //需要无向的图啊 var graph = new AdjacencyListGraph <int>(false); var vertexs = graph.CreateVertexs(vertexKeys); var edges = new List <AdjacencyEdge <int> > { graph.CreateEdge(vertexs[0], vertexs[1], 3), graph.CreateEdge(vertexs[1], vertexs[2], 4), graph.CreateEdge(vertexs[2], vertexs[3], 1), graph.CreateEdge(vertexs[2], vertexs[0], 2), graph.CreateEdge(vertexs[3], vertexs[4], 3), graph.CreateEdge(vertexs[4], vertexs[0], 1), graph.CreateEdge(vertexs[2], vertexs[5], 1), graph.CreateEdge(vertexs[5], vertexs[6], 1), graph.CreateEdge(vertexs[6], vertexs[7], 2), graph.CreateEdge(vertexs[7], vertexs[5], 2), graph.CreateEdge(vertexs[8], vertexs[7], 9), }; graph.CreatGraph(vertexs, edges); return(graph); }
private AdjacencyListGraph <int> CreateNotConnectedComponenetsGraph1() { var vertexKeys = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8 }; var graph = new AdjacencyListGraph <int>(true); var vertexs = graph.CreateVertexs(vertexKeys); var edges = new List <AdjacencyEdge <int> > { graph.CreateEdge(vertexs[0], vertexs[1]), graph.CreateEdge(vertexs[1], vertexs[2]), graph.CreateEdge(vertexs[2], vertexs[3]), graph.CreateEdge(vertexs[2], vertexs[0]), graph.CreateEdge(vertexs[3], vertexs[4]), graph.CreateEdge(vertexs[4], vertexs[0]), graph.CreateEdge(vertexs[5], vertexs[6]), graph.CreateEdge(vertexs[6], vertexs[7]), graph.CreateEdge(vertexs[7], vertexs[5]), }; graph.CreatGraph(vertexs, edges); return(graph); }
public static AdjacencyListGraph <int> CreateStronglyConnectedGraph1() { var vertexKeys = new List <int> { 1, 2, 3, 4, 5 }; var graph = new AdjacencyListGraph <int>(true); var vertexs = graph.CreateVertexs(vertexKeys); var edges = new List <AdjacencyEdge <int> > { graph.CreateEdge(vertexs[0], vertexs[1]), graph.CreateEdge(vertexs[1], vertexs[2]), graph.CreateEdge(vertexs[2], vertexs[3]), graph.CreateEdge(vertexs[2], vertexs[0]), graph.CreateEdge(vertexs[3], vertexs[4]), graph.CreateEdge(vertexs[4], vertexs[0]), }; graph.CreatGraph(vertexs, edges); return(graph); }
public static AdjacencyListGraph <int> CreateDirectionNoCircuitGraph1(bool hasDirection = false) { var vertexKeys = new List <int> { 1, 2, 3, 4, 5 }; var graph = new AdjacencyListGraph <int>(hasDirection); var vertexs = graph.CreateVertexs(vertexKeys); var edges = new List <AdjacencyEdge <int> > { graph.CreateEdge(vertexs[0], vertexs[1]), graph.CreateEdge(vertexs[0], vertexs[4]), graph.CreateEdge(vertexs[1], vertexs[2]), graph.CreateEdge(vertexs[1], vertexs[3]), }; graph.CreatGraph(vertexs, edges); return(graph); }
public static AdjacencyListGraph <int> CreateDAGShortestPathGraph1() { var vertexKeys = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; var graph = new AdjacencyListGraph <int>(true); var vertexs = graph.CreateVertexs(vertexKeys); var edges = new List <AdjacencyEdge <int> >(); edges.Add(graph.CreateEdge(vertexs[0], vertexs[1], 3)); edges.Add(graph.CreateEdge(vertexs[1], vertexs[2], 4)); edges.Add(graph.CreateEdge(vertexs[2], vertexs[3], 1)); edges.Add(graph.CreateEdge(vertexs[3], vertexs[4], 3)); edges.Add(graph.CreateEdge(vertexs[2], vertexs[5], 1)); edges.Add(graph.CreateEdge(vertexs[5], vertexs[6], 1)); edges.Add(graph.CreateEdge(vertexs[6], vertexs[7], 2)); edges.Add(graph.CreateEdge(vertexs[8], vertexs[7], 9)); graph.CreatGraph(vertexs, edges); return(graph); }
CreateMaxFlowData() { var graph = new AdjacencyListGraph <string>(); var vertexData = new List <string>() { "A", "B", "C", "D", "E", "F", "G", }; var vertexs = new Dictionary <string, AdjacencyVertex <string> >(); foreach (var data in vertexData) { vertexs.Add(data, graph.CreateVertex(data)); } var edges = new List <FlowEdge <string> >(); edges.Add(new FlowEdge <string>(vertexs["A"], vertexs["B"], 3)); edges.Add(new FlowEdge <string>(vertexs["A"], vertexs["D"], 3)); edges.Add(new FlowEdge <string>(vertexs["B"], vertexs["C"], 4)); edges.Add(new FlowEdge <string>(vertexs["C"], vertexs["A"], 3)); edges.Add(new FlowEdge <string>(vertexs["C"], vertexs["D"], 1)); edges.Add(new FlowEdge <string>(vertexs["C"], vertexs["E"], 2)); edges.Add(new FlowEdge <string>(vertexs["D"], vertexs["E"], 2)); edges.Add(new FlowEdge <string>(vertexs["D"], vertexs["F"], 6)); edges.Add(new FlowEdge <string>(vertexs["E"], vertexs["B"], 1)); edges.Add(new FlowEdge <string>(vertexs["E"], vertexs["G"], 1)); edges.Add(new FlowEdge <string>(vertexs["F"], vertexs["G"], 9)); for (int i = edges.Count - 1; i >= 0; i--) { edges.Add(edges[i].GetRevolution()); } graph.CreatGraph(vertexs.Values, edges); return(new Tuple <AdjacencyListGraph <string> , AdjacencyVertex <string> , AdjacencyVertex <string> >(graph, vertexs["A"], vertexs["G"])); }
public static AdjacencyListGraph <int> CreateMininumSpanningTreeGraph1() { var vertexKeys = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; var graph = new AdjacencyListGraph <int>(true); var vertexs = graph.CreateVertexs(vertexKeys); var edges = new List <AdjacencyEdge <int> >(); edges.AddRange(graph.CreateNonDirectionEdge(vertexs[0], vertexs[1], 3)); edges.AddRange(graph.CreateNonDirectionEdge(vertexs[1], vertexs[2], 4)); edges.AddRange(graph.CreateNonDirectionEdge(vertexs[2], vertexs[3], 1)); edges.AddRange(graph.CreateNonDirectionEdge(vertexs[3], vertexs[4], 3)); edges.AddRange(graph.CreateNonDirectionEdge(vertexs[2], vertexs[5], 1)); edges.AddRange(graph.CreateNonDirectionEdge(vertexs[5], vertexs[6], 1)); edges.AddRange(graph.CreateNonDirectionEdge(vertexs[6], vertexs[7], 2)); edges.AddRange(graph.CreateNonDirectionEdge(vertexs[8], vertexs[7], 9)); //这时的值就是一个生成树。值是24! edges.AddRange(graph.CreateNonDirectionEdge(vertexs[0], vertexs[4], 1)); edges.AddRange(graph.CreateNonDirectionEdge(vertexs[6], vertexs[8], 8)); //新的应该是 graph.CreatGraph(vertexs, edges); return(graph); }