public override void RemoveVertextAdjustEdges(Vertex <T> v) { //Reset numEdges since we are calling AddEdge to put the current edge into the new matrix numEdges = 0; //Create a reference to the old array Edge <T>[,] oldMatrix = matrix; //Create the new larger matrix matrix = new Edge <T> [NumVertices, NumVertices]; //Copy edges from oldMatrix into new one for (int r = 0; r < oldMatrix.GetLength(0); r++) { for (int c = 0; c < oldMatrix.GetLength(1); c++) { if (oldMatrix[r, c] != null) { if (r != v.Index && c != v.Index) { AddEdge(oldMatrix[r, c]); } } } } }
/// <summary> /// ワーシャルフロイド法 /// O(N^3) /// </summary> /// <param name="edge">Edgeオブジェクト</param> /// <param name="nodeNum">ノードの数</param> /// <returns>各ノード間の最短距離を辺として持つEdgeオブジェクト</returns> public static Edge WarshallFloyd (Edge edge) { var res = new Edge (edge); foreach (var b in Enumerable.Range (0, edge.NodeNum)) { foreach (var a in Enumerable.Range (0, edge.NodeNum)) { foreach (var c in Enumerable.Range (0, edge.NodeNum)) { res.Add (a, c, Min (res.GetLength (a, c), res.GetLength (a, b) + res.GetLength (b, c))); } } } return res; }
public override IEnumerable <Vertex <T> > EnumerateNeighbours(T data) { List <Vertex <T> > neighbours = new List <Vertex <T> >(); int row = GetVertex(data).Index; for (int c = 0; c < matrix.GetLength(1); c++) { if (matrix[row, c] != null) { neighbours.Add(matrix[row, c].To); } } return(neighbours); }
/// <summary> /// Called from the parent class when a vertex is added. /// Creates room for the edges. /// </summary> /// <param name="v"></param> public override void AddVertexAdjustEdges(Vertex <T> v) { //Create a reference to the existing matrix Edge <T>[,] oldMatrix = matrix; //create the new larger matrix matrix = new Edge <T> [NumVertices, NumVertices]; //copy edges from old matrix to new matrix for (int r = 0; r < oldMatrix.GetLength(0); r++) { for (int c = 0; c < oldMatrix.GetLength(1); c++) { //copy currernt edge to new matrix matrix[r, c] = oldMatrix[r, c]; } } }
/// <summary> /// Пересчет глобального времени, переключение фаз светофоров, определение положения водителя и /// определение его скорости на данном этапе /// </summary> /// <param name="sender"></param> private void IncGlobalTime(object sender) { if (!isWait) { if (GlobalTime == 0) { start = Map.Way.ElementAt(step); end = Map.Way.ElementAt(step + 1); currEdge = Route.GetEdge(start, end, Map.edges); wayLengh = currEdge.GetLength(MakeMap.ViewPort.ScaleCoefficient); currSpeed = 60; if (driver.IsViolateTL) { currSpeed = driver.Car.Speed; } else if (currEdge.SignMaxSpeed != null) { currSpeed = Math.Min(currEdge.SignMaxSpeed.Count, driver.Car.Speed); } currSpeed *= currEdge.Coat.Coeff; currSpeed = (currSpeed /*Скорость*/ * 1000 / MakeMap.ViewPort.ScaleCoefficient) / 60 / 60 / 10 /*Interval 100ms*/; } double cos = (start.X - end.X) / wayLengh; double sin = (start.Y - end.Y) / wayLengh; path = GlobalTime * currSpeed; Drive.X = start.X - (int)(cos * path); Drive.Y = start.Y - (int)(sin * path); GlobalTime++; } if (path >= wayLengh) { if (end.TrafficLight != null && !end.TrafficLight.IsGreen) { isWait = true; } else { isWait = false; step += 2; GlobalTime = 0; } } if (step >= Map.Way.Count - 1) { ((Timer)(sender)).Stop(); } MakeMap.ViewPort.Invalidate(); }
//Called from the parent class. Allocates space for the added vertex so it can store its edges public override void AddVertexAdjustEdges(Vertex <T> v) { //Create a reference to the old array Edge <T>[,] oldMatrix = matrix; //Create the new larger matrix matrix = new Edge <T> [NumVertices, NumVertices]; //Copy edges from oldMatrix into new one for (int r = 0; r < oldMatrix.GetLength(0); r++) { for (int c = 0; c < oldMatrix.GetLength(1); c++) { //Copy the current element to the new array matrix[r, c] = oldMatrix[r, c]; } } }
/// <summary> /// Gets a list of all vertices that are neighbours of data /// </summary> /// <param name="data"></param> /// <returns></returns> public override IEnumerable <Vertex <T> > EnumerateNeighbors(T data) { List <Vertex <T> > neighbours = new List <Vertex <T> >(); //what row are the edges for data in //Stored as an index in the corresponding index containing data Vertex <T> v = GetVertex(data); //loop trhough all of the neighboues, and add them as a vertex //object to the list for (int c = 0; c < matrix.GetLength(1); c++) { //if teh current location is an edge if (matrix[v.Index, c] != null) { //add the "to" vertex to the list neighbours.Add(matrix[v.Index, c].To); } } return(neighbours); }
private void Button_Ok_Сalibration_Click(object sender, EventArgs e) { Calibration(callibrationEdge.GetLength(1)); MakeMap.ViewPort.View.MouseDown += PictureBoxMap_MouseDown; MakeMap.ViewPort.View.MouseMove += PictureBoxMap_MouseMove; MakeMap.ViewPort.View.MouseUp += PictureBoxMap_MouseUp; MakeMap.ViewPort.View.MouseDown -= Сalibration_MouseDown; MakeMap.ViewPort.View.MouseMove -= Сalibration_MouseMove; MakeMap.ViewPort.View.MouseUp -= Сalibration_MouseUp; MakeMap.ViewPort.View.Paint -= View_Paint; callibrationEdge = null; MakeMap.ViewPort.Invalidate(); button_Ok_Сalibration.Enabled = false; button_Calibration.Enabled = true; MakeMap.ViewPort.StatusLabel.Text = "Масштаб карты откалиброван..."; }
public override void RemoveVertexAdjustEdges(Vertex <T> v) { numEdges = 0; Edge <T>[,] oldMatrix = matrix; //create the new larger matrix matrix = new Edge <T> [NumVertices, NumVertices]; //copy edges from old matrix to new matrix for (int r = 0; r < oldMatrix.GetLength(0); r++) { for (int c = 0; c < oldMatrix.GetLength(1); c++) { if (oldMatrix[r, c] != null) { //if the edge does not contain vertex to remove if (r != v.Index && c != v.Index) { AddEdge(oldMatrix[r, c]); } } } } }
public Ant(ref Edge[,] costMatrix) { Debug.Assert(costMatrix.GetLength(0) > 0); this.costMatrix = costMatrix; visited = new bool[costMatrix.GetLength(0)]; route = new List<int>(costMatrix.GetLength(0)); //Generate the route. route.Add(BeginTraversal()); while (route.Count < costMatrix.GetLength(0) && route.Last() != -1) route.Add(TraverseFrom(route.Last())); complete = route.Last() != -1; if (complete) { setTotalCost(); } }
public static void Main(string[] args) { var NM = ReadInts(); var N = NM[0]; var M = NM[1]; var ab = ReadIntColumns(M); var a = ab[0]; var b = ab[1]; var edge = new Edge(N, -1); foreach (var m in Enumerable.Range(0, M)) { edge.Add(a[m] - 1, b[m] - 1, 1); edge.Add(b[m] - 1, a[m] - 1, 1); } var count = Enumerable.Range(1, N - 1).Perm(N - 1).Where(perm => perm.Prepend(0).Aggregate(0, (accm, i) => accm == -1 || edge.GetLength(accm, i) == -1 ? -1 : i) != -1) .Count(); Print(count); }
public bool Equals(Edge e) { return (Begin.Equals(e.GetBegin()) && End.Equals(e.GetEnd()) && Length == e.GetLength()); }