From 0511ddb5c94d4b3d21d5cc872418c8c703c487ce Mon Sep 17 00:00:00 2001 From: srajan-kiyotaka Date: Thu, 20 Jun 2024 12:53:44 +0530 Subject: [PATCH 1/3] fix multiple goal state node color problem. --- src/traverseCraft/agent.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/traverseCraft/agent.py b/src/traverseCraft/agent.py index 13cbf0c..fadde4e 100644 --- a/src/traverseCraft/agent.py +++ b/src/traverseCraft/agent.py @@ -568,7 +568,7 @@ class GraphAgent(): _heatMapBaseColor (str): The base color of the heat map. _heatGradient (float): The gradient value for the heat map. _currentNode (GraphNode): The current node the agent is on. - _graphRoot (GraphNode): The root node of the graph. + _startState (GraphNode): The start node of the graph. algorithmCallBack (function): Callback function for the agent's algorithm. _startTime (float): The start time of the agent. _endTime (float): The end time of the agent. @@ -590,8 +590,8 @@ def __init__(self, world, agentName:str, agentColor:str="blue", startNodeId = No self._currentNode = self._worldObj.getNode(startNodeId) else: self._currentNode = self._worldObj.nodeMap[list(self._worldObj.nodeMap.keys())[0]] - self._graphRoot = self._currentNode - self._worldObj.changeNodeColor(self._graphRoot.id, self._agentColor) + self._startState = self._currentNode + self._worldObj.changeNodeColor(self._startState.id, self._agentColor) # ~~~~~~~~~~ Base Heat Map Color ~~~~~~~~~~ # if self._heatMapView: BR, BG, BB = int(self._heatMapColor[1:3], 16), int(self._heatMapColor[3:5], 16), int(self._heatMapColor[5:7], 16) @@ -635,7 +635,7 @@ def aboutAgent(self): about.add_row(["Agent Color", self._agentColor]) about.add_row(["World Name", self._worldObj._worldName]) about.add_row(["World ID", self._worldID]) - about.add_row(["Start Node ID", self._graphRoot.id]) + about.add_row(["Start Node ID", self._startState.id]) return str(about) def summary(self): @@ -666,10 +666,13 @@ def setStartState(self, nodeId): """ if nodeId in self._worldObj._position.keys(): - self._worldObj.changeNodeColor(self._graphRoot.id, self._worldObj._nodeColor) + if self._startState.isGoalState: + self._worldObj.changeNodeColor(self._startState.id, self._worldObj._goalColor) + else: + self._worldObj.changeNodeColor(self._startState.id, self._worldObj._nodeColor) self._currentNode = self._worldObj.getNode(nodeId) - self._graphRoot = self._currentNode - self._worldObj.root = self._graphRoot + self._startState = self._currentNode + self._worldObj.root = self._startState self._worldObj.changeNodeColor(nodeId, self._agentColor) else: raise ValueError("Invalid start state!") @@ -695,7 +698,7 @@ def runAlgorithm(self): """ if self.algorithmCallBack is None: raise ValueError("Algorithm Call Back Function not set!") - self._graphRoot._heatMapValue = 1 + self._startState._heatMapValue = 1 self._startTime = time.time() self.algorithmCallBack() self._endTime = time.time() From ad18cbb6db9b4ff1469cf21cc487bf999b29d1f7 Mon Sep 17 00:00:00 2001 From: srajan-kiyotaka Date: Thu, 20 Jun 2024 12:54:16 +0530 Subject: [PATCH 2/3] fix tutorial for tree world. --- tutorials/Tree World/advance.ipynb | 10 +++++----- tutorials/Tree World/beginner.ipynb | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tutorials/Tree World/advance.ipynb b/tutorials/Tree World/advance.ipynb index 44edc03..e88b321 100644 --- a/tutorials/Tree World/advance.ipynb +++ b/tutorials/Tree World/advance.ipynb @@ -155,7 +155,7 @@ "metadata": {}, "outputs": [], "source": [ - "# First let's Create a grid world object!\n", + "# First let's Create a tree world object!\n", "treeWorld = CreateTreeWorld(worldName=\"Custom Tree World\", worldInfo=treeWorldInfo, radius=25, nodeColor='green', rootColor='red', goalColor=\"gray\", width=720, height=720)" ] }, @@ -163,7 +163,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Compile our Grid World\n", + "## Compile our Tree World\n", "Since, we are sure that we don't want to do any more changes in the world, thus we will compile our world.\n", "\n", "> **Note:** *Once you compile the world you can't change the structure of the world. So make sure that you do all the changes before compiling the world.*" @@ -222,14 +222,14 @@ } ], "source": [ - "# Normal cell\n", + "# Normal node\n", "normalNode = treeWorld.nodeMap['B']\n", "print(\"Information of node B\")\n", "print(normalNode)\n", "\n", "print(\"-\"*30)\n", "\n", - "# Goal cell\n", + "# Goal node\n", "goalNode = treeWorld.nodeMap['K']\n", "print(\"Information of node K\")\n", "print(goalNode)" @@ -503,7 +503,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Let's see some basic information about our `tree Agent`.\n", + "## Let's see some basic information about our Tree Agent.\n", "you can use a simple `print()` statement or you can use the builtin function `aboutAgent()` to get the agent information as a string." ] }, diff --git a/tutorials/Tree World/beginner.ipynb b/tutorials/Tree World/beginner.ipynb index b28603a..937bc89 100644 --- a/tutorials/Tree World/beginner.ipynb +++ b/tutorials/Tree World/beginner.ipynb @@ -553,7 +553,7 @@ "outputs": [], "source": [ "def whatToDo():\n", - " print(\"I am a Grid Agent and I am going to move around the world!\")\n", + " print(\"I am a Tree Agent and I am going to move around the world!\")\n", " treeAgent.moveAgent('B')\n", " treeAgent.moveAgent('D')\n", " treeAgent.moveAgent('B')\n", From e9cfccb9260ceb4e76482a8dac399deddbe71f15 Mon Sep 17 00:00:00 2001 From: srajan-kiyotaka Date: Thu, 20 Jun 2024 12:59:27 +0530 Subject: [PATCH 3/3] fix a unit test + test version 0.9.5 build and uploaded. --- setup.py | 2 +- tests/test_graph_agent.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index eaf487e..1e7b94d 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name='TraverseCraft', - version='0.8.5', + version='0.9.5', author='Srajan Chourasia, Varun Patrikar', author_email='srajanstark.ash@gmail.com, patrikarvarun@gmail.com', maintainer='Srajan Chourasia, Varun Patrikar', diff --git a/tests/test_graph_agent.py b/tests/test_graph_agent.py index ec87542..efd7085 100644 --- a/tests/test_graph_agent.py +++ b/tests/test_graph_agent.py @@ -94,7 +94,7 @@ def test_check_goal_state(self): def test_set_start_state(self): self.agent.setStartState("B") self.assertEqual(self.agent._currentNode.id, "B") - self.assertEqual(self.agent._graphRoot.id, "B") + self.assertEqual(self.agent._startState.id, "B") self.assertEqual(self.graphWorld.root.id, "B") def test_set_start_state_invalid(self):