private void iteration(Title_Vertex workV) { //доки існують неопрацьовані ребра for (Title_Edge workE = _m.getMinNoMarkEdge(workV.index); workE != null; workE = _m.getMinNoMarkEdge(workV.index)) { Title_Vertex nextV; if (workV.index == workE.v1.index) { nextV = workE.v2; } else { nextV = workE.v1; } //Рахуємо шлях до наступної вершини if (nextV.weigth > workV.weigth + workE.edge.Weight) { //шлях, що розглядається коротший за існуючий nextV.weigth = workV.weigth + workE.edge.Weight; nextV.wayV = new List <Vertex>(workV.wayV); nextV.wayV.Add(nextV.vertex); nextV.wayE = new List <Edge>(workV.wayE); nextV.wayE.Add(workE.edge); } workE.state = true; } }
private void startAlgoritm() { //Позначаємо в матриці початкову точку _m.setStartVertex(startVertex); for (Title_Vertex workV = _m.getMinNoMarkPoit(); workV != null; workV = _m.getMinNoMarkPoit()) { iteration(workV); workV.state = true; } }
/// <summary> /// Повертає не опрацьовану точку з найменшою вагою /// </summary> /// <returns></returns> public Title_Vertex getMinNoMarkPoit() { int w = int.MaxValue; Title_Vertex result = null; foreach (Title_Vertex vertex in _vertices) { //якщо точка не опрацьована if (!vertex.state) { if (vertex.weigth < w) { w = vertex.weigth; result = vertex; } } } return(result); }