public void getRoute(double maxDistance, int startPoint) { var currentNode = NodesList.First(p => p.Position == startPoint - 1); var list = new List <int>(); currentNode.Visited = true; double currentProfit = currentNode.Profit; var notVisitedNodes = new List <Node>(NodesList); list.Add(currentNode.Position); notVisitedNodes.Remove(currentNode); double distance = 0; while (true) { Node nextNode = null; double bestResult = 0; //wez srednio najlepszy punkt. foreach (var notVisitedNode in NodesList) { if (notVisitedNode.Visited == false) { var result = notVisitedNode.Profit / NodeDistances[currentNode.Position, notVisitedNode.Position]; if (result > bestResult && distance + NodeDistances[currentNode.Position, notVisitedNode.Position] <= maxDistance) { bestResult = result; nextNode = notVisitedNode; } } } //isc randomowo po bliskich dosc dobrych miastach, i miec ok. pol odleglosci powrotnej w zapasie jak zblizymy sie do tej wartosci wracamy. if (nextNode == null) { break; } nextNode.Visited = true; currentProfit += nextNode.Profit; distance += NodeDistances[currentNode.Position, nextNode.Position]; //var pair = new Tuple<Node,Node>(currentNode,nextNode); //Connections.Add(pair); //list.Add(nextNode.Position); currentNode = nextNode; } currentSequence = list.ToArray(); }