// Update is called once per frame
 void Update()
 {
     if (path == null && search.Finished())
     {
         Debug.Log("Visited: " + search.problem.GetVisited().ToString());
         Debug.Log("Expanded: " + search.problem.GetExpanded().ToString());
         path = search.GetActionPath();
         if (path != null)
         {
             Debug.Log("Path Length: " + path.Count.ToString());
             Debug.Log("[" + string.Join(",", path.ConvertAll <string> (Actions.ToString).ToArray()) + "]");
         }
     }
 }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            search.StartRunning();
        }

        if (path == null && search.Finished())
        {
            Debug.Log("Visited: " + search.problem.GetVisited().ToString());
            Debug.Log("Expanded: " + search.problem.GetExpanded().ToString());
            LOGGER.Log("Visited: {0}", search.problem.GetVisited().ToString());
            LOGGER.Log("Expanded: {0}", search.problem.GetExpanded().ToString());

            LOGGER.Log("Building solution path");
            path = search.GetActionPath();

            total_actions = path.Count;

            LOGGER.Log("Saving path!");
            savePath(path);

            LOGGER.Log("done.. !");
            LOGGER.Log("[{0}]", string.Join(",", path.ConvertAll <string> (Actions.ToString).ToArray()));

            if (path != null)
            {
                Debug.Log("Path Length (Number of Actions): " + path.Count.ToString());
                Debug.Log("[" + string.Join(",", path.ConvertAll <string> (Actions.ToString).ToArray()) + "]");
            }

            // if on batchmode terminate the application
            if (batchmode)
            {
                LOGGER.Log("Finished.");
                LOGGER.Flush();
                Application.Quit();
            }
        }

        visitedText.text  = "Visited: " + search.problem.GetVisited().ToString();
        expandedText.text = "Expanded: " + search.problem.GetExpanded().ToString();
        LOGGER.Flush();
    }
Example #3
0
    // Update is called once per frame
    void Update()
    {
        if (!isDead)
        {
            if ((Input.GetKeyDown(KeyCode.Space) || autorun) && !agentRunning)
            {
                agentRunning = true;
                search.StartRunning();
                uniText      = GameObject.Find(GridMap.instance.prefixUiText + this.name).GetComponent <Text> ();
                uniText.text = this.name + ": Searching... ";
                //print (GridMap.instance.NodeFromWorldPoint(search.startPos));
            }

            if (debugExpandedNodes && search.GetRunning() && !search.Finished())
            {
                GridMap.instance.ColorNodes(search.GetVisitedNodes(), agentColor);
                nodesExpanded = search.GetNumberOfNodesExpanded();
                nodesVisited  = search.GetVisitedNodes().Count;
                pathCost      = search.pathCost;
                uniText.text  = this.name + ": Searching... ";
                uniText.text += "expanded: " + nodesExpanded + " visited: " + nodesVisited;
            }

            if (search.Finished() && !algorithmFinished)
            {
                uniText.text  = this.name + ": Moving... ";
                nodesExpanded = search.GetNumberOfNodesExpanded();
                nodesVisited  = search.GetVisitedNodes().Count;
                pathCost      = search.pathCost;
                uniText.text += "expanded: " + nodesExpanded + " visited: " + nodesVisited + " pathcost: " + pathCost;
                if (path == null)
                {
                    if (search.FoundPath())
                    {
                        path = search.RetracePath();
                        TestWriter.writeResultLine(search.FoundPath(), (int)search.Solution.f, search.numberOfVisited, search.numberOfExpandedNodes, search.maxListSize, search.currentState.depth, search.getExtra());
                        if (debugPath)
                        {
                            GridMap.instance.ColorNodes(path, agentColor);
                        }
                    }
                    else
                    {
                        algorithmFinished = true;
                    }
                }

                if (targets.Count > 0 && moveToNext)
                {
                    // clear visited nodes
                    if (debugExpandedNodes)
                    {
                        GridMap.instance.ClearColorNodes(search.GetVisitedNodes());
                    }
                    //move to next target
                    GridMap.instance.ClearColorNode(GridMap.instance.NodeFromWorldPoint(search.targetPos));
                    UpdateStartTargetPositions();
                    search.StartRunning();

                    path        = null;
                    currentCost = 0;
                    moveToNext  = false;
                    isAtTarget  = false;
                }
                if (targets.Count == 0 && search.Finished() && search.FoundPath() && path != null)
                {
                    TestSceneControl.ChangeScene();
                }
            }
            if (!isMoving)
            {
                UpdateEnergy();
                if (isAtTarget && IsFullyLoaded())
                {
                    moveToNext = true;
                }
            }
        }
    }
Example #4
0
    private void computeCosts()
    {
        if (!search.GetRunning() && (!search.Finished() && !search.FoundPath()))
        {
            Debug.Log("[ComputeCosts] Start search for: " + keys[currentStartPos] + " -> " + keys[currentTargetPos]);
            search.StartRunning();
            uniText = GameObject.Find(GridMap.instance.prefixUiText + this.name).GetComponent <Text>();
        }

        if (search.GetRunning())
        {
            uniText.text  = this.name + ": Searching... ";
            uniText.text += "expanded: " + nodesExpanded + " visited: " + nodesVisited;
        }

        // generate list of lists of costs
        if (search.FoundPath())
        {
            Dictionary <string, int> novo = new Dictionary <string, int>();

            path = search.RetracePath();

            novo.Add(keys[currentTargetPos], 0 + search.GetPathCost());

            if (dMatrix.ContainsKey(keys[currentStartPos]))
            {
                dMatrix[keys[currentStartPos]].Add(keys[currentTargetPos], 0 + search.GetPathCost());
            }
            else
            {
                dMatrix.Add(keys[currentStartPos], novo);
            }

            //Debug.Log(dMatrix);
            //Debug.Log("Ended! cost : "+ dMatrix[keys[currentStartPos]][keys[currentTargetPos]] +
            //	" search for: " + keys[currentStartPos] + "-> " + keys[currentTargetPos]);

            currentTargetPos++;
            if (currentTargetPos == keys.Count)
            {
                currentTargetPos = 0;

                currentStartPos++;
                if (currentStartPos == keys.Count)
                {
                    costsNotComputed = false;                     // computed!
                    exportCosts();
                    search.setRunning(false);
                    search.setFinished(false);
                    path = null;
                    Debug.Log("Computed and exported to: " +
                              (Application.dataPath + "/Resources/Maps/" + GridMap.instance.mapCosts.name + "costs.csv"));

                    return;
                }
            }

            search.startPos  = allTargets[currentStartPos].transform.position;
            search.targetPos = allTargets[currentTargetPos].transform.position;
            Debug.Log("[ComputeCosts] Start search for: " + keys[currentStartPos] + " -> " + keys[currentTargetPos]);
            search.StartRunning();
        }
    }