示例#1
0
    // Log Route
    private void LogRoute(GameObject StartNode, int MaxPath, GameObject[] WaypointNodes, List <ACOConnection> Connections)
    {
        GameObject CurrentNode = null;

        foreach (GameObject GameObjectNode in WaypointNodes)
        {
            if (GameObjectNode.Equals(StartNode))
            {
                CurrentNode = GameObjectNode;
            }
        }

        ACOConnection HighestPheromoneConnection = null;
        string        Output    = "Route (Q: " + Q + ", Alpha: " + Alpha + ", Beta: " + Beta + ", EvaporationFactor: " + EvaporationFactor + ", DefaultPheromone: " + DefaultPheromone + "):\n";
        int           PathCount = 1;

        while (CurrentNode != null)
        {
            List <ACOConnection> AllFromConnections = AllConnectionsFromNode(CurrentNode, Connections);
            if (AllFromConnections.Count > 0)
            {
                HighestPheromoneConnection = AllFromConnections[0];
                foreach (ACOConnection aConnection in AllFromConnections)
                {
                    if (aConnection.PheromoneLevel > HighestPheromoneConnection.PheromoneLevel)
                    {
                        HighestPheromoneConnection = aConnection;
                    }
                }
                CurrentNode = HighestPheromoneConnection.ToNode;
                Output     += "| FROM: " + HighestPheromoneConnection.FromNode.name + ", TO: " + HighestPheromoneConnection.ToNode.name + " (Pheromone Level: " + HighestPheromoneConnection.PheromoneLevel + ") | \n";
            }
            else
            {
                CurrentNode = null;
            }

            // If the current node is the start node at this point then we have looped
            // through the path and should stop.
            if (CurrentNode != null && CurrentNode.Equals(StartNode))
            {
                CurrentNode = null;
                Output     += "HOME (Total Nodes:" + WaypointNodes.Length + ", Nodes in Route: " + PathCount + ").\n";
            }
            // If the path count is greater than a max we should stop.
            if (PathCount > MaxPath)
            {
                CurrentNode = null;
                Output     += "MAX PATH (Total Nodes:" + WaypointNodes.Length + ", Nodes in Route: " + PathCount + ").\n";
            }
            PathCount++;
        }
        Debug.Log(Output);
    }