public static GWGraph <NodeData, EdgeData, GraphData> Torus <NodeData, EdgeData, GraphData>(int dimX, int dimY) { var graph = new GWGraph <NodeData, EdgeData, GraphData>("Torus (" + dimX + "," + dimY + ")"); var grid = new GWNode <NodeData, EdgeData, GraphData> [dimX, dimY]; for (int x = 0; x < dimX; x++) { for (int y = 0; y < dimY; y++) { //for (int z = 0; z < numberNodes; z++) { var node = graph.CreateNode(); grid[x, y] = node; } } } for (int x = 0; x < dimX; x++) { for (int y = 0; y < dimY; y++) { //for (int z = 0; z < numberNodes; z++) { if (x < dimX) { graph.CreateEdge(grid[x, y], grid[(x + 1) % dimX, y]); } if (y < dimY) { graph.CreateEdge(grid[x, y], grid[x, (y + 1) % dimY]); } } } } return(graph); }
public void RemoveNode(GWNode <NodeData, EdgeData, GraphData> node) { Nodes.Remove(node); foreach (GWEdge <NodeData, EdgeData, GraphData> edge in node.Edges.ToList()) { edges.Remove(edge); (edge.Head as GWNode <NodeData, EdgeData, GraphData>).edges.Remove(edge); (edge.Foot as GWNode <NodeData, EdgeData, GraphData>).edges.Remove(edge); } }
public GWEdge <NodeData, EdgeData, GraphData> CreateEdge(GWNode <NodeData, EdgeData, GraphData> foot, GWNode <NodeData, EdgeData, GraphData> head) { var newEdge = new GWEdge <NodeData, EdgeData, GraphData>(foot, head); foot.AddOutEdge(newEdge); head.AddInEdge(newEdge); edges.Add(newEdge); return(newEdge); }
public GWNode <NodeData, EdgeData, GraphData> CreateNode() { var node = new GWNode <NodeData, EdgeData, GraphData>(this); node.GraphId = NodeCounter; NodeCounter++; nodes.Add(node); return(node); }
public static GWGraph <NodeData, EdgeData, GraphData> Cube <NodeData, EdgeData, GraphData>(int dimX, int dimY, int dimZ) { var graph = new GWGraph <NodeData, EdgeData, GraphData>("Cube (" + dimX + "x" + dimY + "x" + dimZ + ")"); var cube = new GWNode <NodeData, EdgeData, GraphData> [dimZ][, ]; for (int z = 0; z < dimZ; z++) { cube[z] = new GWNode <NodeData, EdgeData, GraphData> [dimX, dimY]; } for (int x = 0; x < dimX; x++) { for (int y = 0; y < dimY; y++) { for (int z = 0; z < dimZ; z++) { var node = graph.CreateNode(); cube[z][x, y] = node; } } } for (int x = 0; x < dimX; x++) { for (int y = 0; y < dimY; y++) { for (int z = 0; z < dimZ; z++) { if (x < dimX - 1) { graph.CreateEdge(cube[z][x, y], cube[z][x + 1, y]); } if (y < dimY - 1) { graph.CreateEdge(cube[z][x, y], cube[z][x, y + 1]); } if (z < dimZ - 1) { graph.CreateEdge(cube[z][x, y], cube[z + 1][x, y]); } } } } return(graph); }
public static GWGraph <NodeData, EdgeData, GraphData> Grid <NodeData, EdgeData, GraphData>(int dimensionX, int dimensionY) { var graph = new GWGraph <NodeData, EdgeData, GraphData>("Grid (" + dimensionX + "," + dimensionY + ")"); var grid = new GWNode <NodeData, EdgeData, GraphData> [dimensionX, dimensionY]; for (int x = 0; x < dimensionX; x++) { for (int y = 0; y < dimensionY; y++) { //for (int z = 0; z < numberNodes; z++) { var node = graph.CreateNode(); grid[x, y] = node; } } } for (int x = 0; x < dimensionX; x++) { for (int y = 0; y < dimensionY; y++) { //for (int z = 0; z < numberNodes; z++) { if (x < dimensionX - 1) { graph.CreateEdge(grid[x, y], grid[x + 1, y]); } if (y < dimensionY - 1) { graph.CreateEdge(grid[x, y], grid[x, y + 1]); } } } } return(graph); }
public GWGraph <SGLNodeData, SGLEdgeData, SGLGraphData> CreateGraph(ErdösGraphCreationParameter parameter) { GWGraph <SGLNodeData, SGLEdgeData, SGLGraphData> graph = new GWGraph <SGLNodeData, SGLEdgeData, SGLGraphData>(); graph.Data = new SGLGraphData(); graph.Data.NumberCategories = parameter.NumberCategories; for (int i = 0; i < parameter.NumberNodes; i++) { graph.CreateNode(); } //put each node in category s.t. no empty categories bool hasEmptyCategory = true; while (hasEmptyCategory) { List <int> categoriesUsed = new List <int>(); for (int i = 0; i < parameter.NumberCategories; i++) { categoriesUsed.Add(i); } foreach (var node in graph.Nodes) { node.Data = new SGLNodeData(); //put node in random category var category = random.Next(parameter.NumberCategories); node.Data.Category = category; categoriesUsed.Remove(category); } if (categoriesUsed.Count == 0) { hasEmptyCategory = false; } } var nodes = graph.Nodes.ToList(); //connect nodes for (int i = 1; i < nodes.Count; i++) { GWNode <SGLNodeData, SGLEdgeData, SGLGraphData> currentNode = nodes[i]; //create edge to previous nodes with defined probabilty for (int j = 0; j < i; j++) { if (currentNode.Data.Category == nodes[j].Data.Category) { double probabilty = random.NextDouble(); if (probabilty <= parameter.IntraConnectivityDegree) { GWEdge <SGLNodeData, SGLEdgeData, SGLGraphData> edge = graph.CreateEdge(currentNode, nodes[j]); edge.Data = new SGLEdgeData(); edge.Data.Type = EdgeType.Intra; } } //nodes are in different category else if (currentNode.Data.Category != nodes[j].Data.Category) { double probabilty = random.NextDouble(); if (probabilty <= parameter.InterConnectivityDegree) { GWEdge <SGLNodeData, SGLEdgeData, SGLGraphData> edge = graph.CreateEdge(currentNode, nodes[j]); edge.Data = new SGLEdgeData(); edge.Data.Type = EdgeType.Inter; } } } } return(graph); }
public GWEdge(GWNode <NodeData, EdgeData, GraphData> foot, GWNode <NodeData, EdgeData, GraphData> head) { Head = head; Foot = foot; }