Results 1 to 18 of 18
Thread: Navigating Bots
- 06-26-2011, 03:24 PM #1
Navigating Bots
Greetings Java Friends
Warning: This is going to be slightly long.
The Challenge:
Create Two Bots that will exit the Graph safely. The first bot called ( QuickBot ) will aim to exit the Graph as fast as possible. The second bot called ( GreedyBot ) will aim to exit the graph with the highest amount of resource possible.
A bot can not reach a resource level of 0 << it will die if that happens.
My Solution:
The Bot will always land at the Entrance node. There I will make the bot look through the graph via the getMap() method (returns Hashtable<Node<Adjustment>, ArrayList<Node<Adjustment>>>) and somehow get all the available paths to the Exit node. Each one of these will be saved in an ArrayList<Stack<String>>, the Stack represents a single path. Once that is done, The Bot will go through each of the available stacked paths and see which ones cause the Bot to die, and delete those. The Bot will then somehow calculate which of the Stack Paths gives the shortest route possible (for Quick) or the route that deducts least resources (for Greedy) to the Exit node.
Once the ideal stack path is calculated (depending on nature of the Bot, Quick or Greedy), that stack will be left as a message at the Entrance node of the Graph. This way all the nodes entering later, can read the Stack from the message and follow the path specified in the Stack, and they too can Exit according to the Bot's nature.
Relax ! I know that was a lot to take in
. For me personally images always help. I hope it is the same for you. Here's a particular Graph. Called Graph5.

I hope you appreciate my handy photoshop work, it took me 20 minutes to create that.gif)
So that's what the Graph looks like on Paper. But in Code it is represented as a Hashtable. Here's an image representation of the Hashtable.

On the left the Key representing a node. On the right are the values and they are an ArrayList of the neighbouring nodes.
And now my code:
Where I'm Stuck:Java Code:/** * The stuff in this method is run when the Bot is present at the node. */ public void visitNodeActions() throws BotError { if(isAtEntrance()) { // A place to store the safe paths. ArrayList<Stack<String>> paths = new ArrayList<Stack<String>>(); // The variable g stands for, and is the Graph object < which in itself is a Hashtable. Hashtable<Node<Adjustment>, ArrayList<Node<Adjustment>>> g = getMap().getAdjacencyList(); // Iterating through [g] to find safe paths. Enumeration<Node<Adjustment>> e = g.keys(); while(e.hasMoreElements()) { // e.nextElement can only be used once within the while loop. So I'm assigning it to a variable that can be used many times. Node<Adjustment> x = (Node<Adjustment>)e.nextElement(); // Check to see if we have the Start Node. if(getLocation() == x.getName()) { // A variable called [neighbours]. It represents the neighoubrs of the current node in the loop ArrayList<Node<Adjustment>> neighbours = g.get(x); // The Path [p] represented as a Stack. This will be inserted into our safe [paths] ArrayList later on. Stack<String> p = new Stack<String>(); // Iterating through the neighbours of the current node, and foreach building a path [p] from them. for(Node<Adjustment> n : neighbours) { p.push(x.getName()); p.push(n.getName()); // Adding the stacked path [p] to the safe paths list [paths] paths.add(p); // Now that the stacked path [p] has been stored, we need to clear, empty [p] for the next path. p.clear(); } } } } }
My code currently stores the following two paths successfully.
AB
AC
But what I need it to do afterwards, is get me the following paths:
ABF
ACD
Whilst still keeping the original two paths, so all in all the saved paths will be:
AB
AC
ABF
ACD
and then after that, it will be:
AB
AC
ABF
ACD
ACDE
and so on ..
I do not know how to get my code to get me results such as above.
If you think there is ill-logic in my solution to the challenge, please help point them out. If not, I would greatly appreciate any help in getting the code to do what I need it to do.
If you have any questions, or if I have not explained something clearly, please do not hesitate to ask. I have tried to make it as easy as possible for you to help me (I hope).
Thank You So Much.Last edited by Ciwan; 06-26-2011 at 07:11 PM.
>> What can be asserted without proof can be dismissed without proof. <<
- 06-26-2011, 04:17 PM #2
How do we execute your code to test it?
- 06-26-2011, 06:11 PM #3
Good Question. Because I still don't know how to execute code in Eclipse. What I do is copy it over BlueJ. There I right click on the Test Class, and choose Graph5. Here's a screenshot:

The reason I use, Eclipse is because of all the advanced features like Auto Code Completion and a list of methods for each object as one is typing ! It would be nice if I could do the Unit testing in Eclipse, Unfortunately I have no idea how. >> That's another issue though. My main concern now is the problem I'm having above..gif)
Ooops ! How do YOU execute my code to test it. !! erm .. I don't know ! what do you suggest ? I don't think I can attach zip files to my posts !Last edited by Ciwan; 06-26-2011 at 06:28 PM.
>> What can be asserted without proof can be dismissed without proof. <<
- 06-26-2011, 06:34 PM #4
I would compile it with the javac command and execute it with the java command.How do YOU execute my code to test it
- 06-26-2011, 06:37 PM #5
Hehe you are a Pro, your skills are light years ahead of mine. I've never really used the Java Command.
Are you saying you would take the time to test my code ? that would mean the world to me.
If Yes ... how do you suppose I provide the code to you and others so that they can test it ?
Thanks>> What can be asserted without proof can be dismissed without proof. <<
- 06-26-2011, 06:47 PM #6
That's a problem with how you were taught. The first lesson should be how to use the javac and java commands to compile and execute a program. Later the IDE could be brought in.
Starting with an IDE leaves a big hole in your knowledge of what is happening. Too much magic done by the IDE.
Yes, but my approach is not to tell you what the problem is, if I find it, but rather tell you how to find the problem. Most often that is by telling you to add printlns to the code to see what is happening.Are you saying you would take the time to test my code
You appear to have a logic problem. You need to learn how to solve these kinds of problems. If you have an interactive debugger, that will make some of it easier. Otherwise you can use printlns. Its a very iterative process.
You print out some variables, see what is happening but realize you need more info and go back and add more printlns. Sometimes you have to add some special debugging code to show what the code is doing.
- 06-26-2011, 06:56 PM #7
>> What can be asserted without proof can be dismissed without proof. <<
- 06-26-2011, 07:00 PM #8
I have not looked at your code
Go Advanced button and add an attachment. Usually a zip of the source.how do people usually share projects files on here ?
- 06-26-2011, 07:12 PM #9
- 06-26-2011, 07:33 PM #10
There are over 30 java files there. I don't know when or if I'll try to wade thru all that.
- 06-26-2011, 07:36 PM #11
You're right, even I myself don't know what the use of two thirds of them are. I've been told to only work on Quick and Greedy Bot.
>> What can be asserted without proof can be dismissed without proof. <<
- 06-26-2011, 08:09 PM #12
You are really in the control of your environment. The code you posted does not have a main method where execution starts. The is no way to execute the code you posted.
What kind of course are you taking? Are you supposed to be learning Java programming? Your IDE or BlueJ isolates you from the real world.
I suspect that what you have posted will only work with the tools that you are using.
- 06-26-2011, 08:16 PM #13
I know, like I said I don't know what to put in the Main Static Method to get the execution rolling.
The course is about Internet Systems, but there are certain modules (like this one) where I honestly can't see any relations to the Web Development world.
I did really good on the Web Development modules (e.g. ASP.NET MVC3, Ruby on Rails, SQL) but on this one, I did really bad.
I would love to be able to work from Eclipse only, but I don't know how to make the Unit tests he (the tutor) has provided to work in Eclipse.>> What can be asserted without proof can be dismissed without proof. <<
- 06-26-2011, 08:20 PM #14
Exactly the problem that I was describing in my last post. Some magic thing that you give your code to.the Unit tests he (the tutor) has provided to work in Eclipse
I can't see any easy way to simulate the Unit test code. It must have 'hooks' that connect to your code and execute it.
Good luck.
- 06-26-2011, 09:09 PM #15
Thanks I'll need it
>> What can be asserted without proof can be dismissed without proof. <<
- 06-26-2011, 10:55 PM #16
@OP:
I tried to run it, but didn't succeed. I'll give you my comment-file, made in the process:
The Main-class didn't do anything
Made packages to organize the code.
Classnames should indicate category (BotDeath is an error)
StrippedBot is not extending Bot
StrippedNode is not extending Node
Class NodeInfo doesn't exist (compiler doesn't complain because of existing superclass Value)
I made some errorconstructors public (needed because of my moving)
The Maze-constructor needs a maze-specificationfile (not included) <--please provide one for the formatLast edited by Jodokus; 06-27-2011 at 12:44 AM. Reason: spelling
No bug ever had to calculate its fitnessfunction.
- 07-02-2011, 02:41 AM #17
Member
- Join Date
- Jul 2011
- Posts
- 1
- Rep Power
- 0
I can test if you like?
Regards
- 07-02-2011, 03:35 AM #18
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
@OP: "public static void main" should be one of the first thing that is taught in java programming.
You might want to read The Really Big Index
Similar Threads
-
navigating between jsp
By newto in forum New To JavaReplies: 5Last Post: 05-12-2010, 01:38 PM -
Creating and Navigating a 2D Array from .dat file
By RobertF in forum New To JavaReplies: 0Last Post: 03-10-2009, 05:44 PM -
Blank Screen while navigating from one screen to another
By mohana.krishna in forum Java ServletReplies: 0Last Post: 03-03-2009, 05:03 PM -
Navigating a URL
By Paul77 in forum New To JavaReplies: 0Last Post: 11-16-2008, 09:01 PM


LinkBack URL
About LinkBacks
Reply With Quote


Bookmarks