473,748 Members | 2,793 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Java Breadth First Search problem

1 New Member
Hello lads i have a problem about the Breadth First Search . I need to do an implementation of a checking algorith that check from a Game Graph that i have create if every non-object node appears between 2 connection nodes
The code that i have done untill now is :
Can anyone helps

Expand|Select|Wrap|Line Numbers
  1.  
  2. public class StructurallyValidGraph extends GameGraph implements StructuralValidatorRules
  3. private ArrayList<Node>ToDo;
  4. private ArrayList<Node>visited;
  5.  
  6.  
  7.  
  8. public StructurallyValidGraph(String name,StartNode start,GoalNode goal) {
  9. super(name,start,goal);
  10.  
  11.  
  12. ToDo= new ArrayList<Node>();
  13. }
  14.  
  15. /**
  16. * Check that every non-object node (except perhaps the in node of the
  17. * start location and the out nodes of goal locations) appears between
  18. * two connection links.
  19. */
  20.  
  21.  
  22. public boolean nonObjectNodeValidation() throws NotImplemented {
  23. throw new NotImplemented();
  24.  
  25. return check();
  26.  
  27. }
  28.  
  29.  
  30.  
  31.  
  32. public boolean visit (Node ANode)
  33. {
  34. if(currentNode.ANode) // check if Already visited
  35. {
  36. return true;
  37. }
  38. visited.add(ANode);
  39. AllLinks =ANode.link();
  40. for ( i=0; i<AllLinks.size;i++)
  41. {
  42. Link OneLink =AllLinks.get(i);
  43. Node targetnode =OneLink.target();
  44. if (targetnode.getType()!="ObjectNode"&& OneLink.getType()!="ConnectionLink")
  45. {
  46. return false;
  47. }
  48. for ( i = 0; i<AllLinks.size(); i++)
  49. {
  50. ToDo.add((Node) AllLinks.get(i).target());
  51. }
  52. }
  53. }
  54.  
  55.  
  56. public boolean check()
  57. {
  58.  
  59. visited = new ArrayList<Node>();
  60. ToDo.add(start);
  61. while (ToDo.size()>0)
  62.  
  63.  
  64. ANode=ToDo.get(0);
  65. ToDo.remove(0);
  66. boolean pass = visit (ANode);
  67. if(pass==false)
  68. {
  69. return false;
  70. }
  71. return true;
  72. }
  73.  
Apr 2 '07 #1
1 5396
r035198x
13,262 MVP
Hello lads i have a problem about the Breadth First Search . I need to do an implementation of a checking algorith that check from a Game Graph that i have create if every non-object node appears between 2 connection nodes
The code that i have done untill now is :
Can anyone helps

Expand|Select|Wrap|Line Numbers
  1.  
  2. public class StructurallyValidGraph extends GameGraph implements StructuralValidatorRules
  3. private ArrayList<Node>ToDo;
  4. private ArrayList<Node>visited;
  5.  
  6.  
  7.  
  8. public StructurallyValidGraph(String name,StartNode start,GoalNode goal) {
  9. super(name,start,goal);
  10.  
  11.  
  12. ToDo= new ArrayList<Node>();
  13. }
  14.  
  15. /**
  16. * Check that every non-object node (except perhaps the in node of the
  17. * start location and the out nodes of goal locations) appears between
  18. * two connection links.
  19. */
  20.  
  21.  
  22. public boolean nonObjectNodeValidation() throws NotImplemented {
  23. throw new NotImplemented();
  24.  
  25. return check();
  26.  
  27. }
  28.  
  29.  
  30.  
  31.  
  32. public boolean visit (Node ANode)
  33. {
  34. if(currentNode.ANode) // check if Already visited
  35. {
  36. return true;
  37. }
  38. visited.add(ANode);
  39. AllLinks =ANode.link();
  40. for ( i=0; i<AllLinks.size;i++)
  41. {
  42. Link OneLink =AllLinks.get(i);
  43. Node targetnode =OneLink.target();
  44. if (targetnode.getType()!="ObjectNode"&& OneLink.getType()!="ConnectionLink")
  45. {
  46. return false;
  47. }
  48. for ( i = 0; i<AllLinks.size(); i++)
  49. {
  50. ToDo.add((Node) AllLinks.get(i).target());
  51. }
  52. }
  53. }
  54.  
  55.  
  56. public boolean check()
  57. {
  58.  
  59. visited = new ArrayList<Node>();
  60. ToDo.add(start);
  61. while (ToDo.size()>0)
  62.  
  63.  
  64. ANode=ToDo.get(0);
  65. ToDo.remove(0);
  66. boolean pass = visit (ANode);
  67. if(pass==false)
  68. {
  69. return false;
  70. }
  71. return true;
  72. }
  73.  
Where specifically do you need help and what steps have you taken so far?
Apr 2 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

45
16908
by: Market Mutant | last post by:
I just wonder job selections, job openings and salary level of PHP programer or Perl programmer comparing to Java programmers. Is Java programmer's salary has a minimal of 60K in US? Are there many PHP jobs?
8
7713
by: slickn_sly | last post by:
Why am i getting an error? public void breadthFirst( TreeNode tNode) { Queue q = new Queue( ); if( q.isEmpty() ) { q.enqueue( this ); }
1
9649
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
9
5325
by: News | last post by:
I am new in using Python Anyone know how to implement breadth first search using Python? Can Python create list dynamically, I want to implement a program which will read data from a file and store each line into a list, is this possible? Please send mail to me at nickyncy@yahoo.com.hk or reply this mail Thanks a lot!
2
3797
by: xandra | last post by:
i have 2 question in breadth-first traversal.your help will be appreciated. 1. what is the purpose of the queue in breath-first traversal? 2 suppose you had a function call displayAtDepthN which when given a tree and depth would display only the nodes at that depth. explain how this could be used to give a breadth-first traversal of the tree,and why it would not be as efficient as one using a queue.
3
14185
by: alaa123 | last post by:
hi plz do not ignore me I really neeed ur help I am working on a progarmme to implement First Search and Breadth Search I did the first search algorithm but I need help with implementing the Breadth Search algorithm plz help me I have the methods but i want to know what to change inorder to implemnet Breadth first search import java.util.*; public class DFS{
0
1656
by: varun aggarwal | last post by:
Hi i am doing the data structures in C++. I have seen the adjacency list implementation of depth first search/traversal that is using some recursive function to traverse the whole graph. but not able to find the same for breadth first search/traversal. All the implementation of breadth first are using adjacency matrix using queues. I am not sure if that is possible. If it is, can somebody give the code snippet of it or provide the link to it....
3
2927
by: javaboyjavaboy | last post by:
i need the coding of Breadth First Search program
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4602
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3312
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.