जावा में चौड़ाई पहली खोज को लागू करने के लिए मेरे पास स्कूल के उत्कृष्टता के रूप में है। मैं लगभग सब कुछ को लागू किया है लेकिन समस्या यह है कि मेरी खोज काम नहीं कर रहा है और मैं नहीं कर सकते मुझे सलाह और मुझे जहां अंतिम समस्या हो सकती है पर कुछ दिशा-निर्देश देने के लिए आप पूछ समस्या :(तो इम लगता है।ब्रेडथ फर्स्ट सर्च - जावा
public ArrayList<SearchNode> search(Problem p) {
// The frontier is a queue of expanded SearchNodes not processed yet
frontier = new NodeQueue();
/// The explored set is a set of nodes that have been processed
explored = new HashSet<SearchNode>();
// The start state is given
GridPos startState = (GridPos) p.getInitialState();
// Initialize the frontier with the start state
frontier.addNodeToFront(new SearchNode(startState));
// Path will be empty until we find the goal.
path = new ArrayList<SearchNode>();
// The start NODE
SearchNode node = new SearchNode(startState);
// Check if startState = GoalState??
if(p.isGoalState(startState)){
path.add(new SearchNode(startState));
return path;
}
do {
node = frontier.removeFirst();
explored.add(node);
ArrayList reachable = new ArrayList<GridPos>();
reachable = p.getReachableStatesFrom(node.getState());
SearchNode child;
for(int i = 0; i< reachable.size(); i++){
child = new SearchNode((GridPos)reachable.get(i));
if(!(explored.contains(child) || frontier.contains(child))){
if(p.isGoalState(child.getState())){
path = child.getPathFromRoot() ;
return path;
}
frontier.addNodeToFront(child);
}
}
}while(!frontier.isEmpty());
return path;
}
आप
यह कैसे काम नहीं कर रहा है? सटीक होना। – Borgleader
ऐसा लगता है कि यह "गलत" नोड्स और पथ की खोज कर रहा है। – mrjasmin
आपके पास बहुत सी विधियां हैं जिन्हें आप हमें नहीं दिखा रहे हैं। ऐसा लगता है कि आप दो अलग-अलग सरणी/सूचियों से नोड्स निकालने और पहुंचने योग्य नोड्स को केवल एक में डालने लगते हैं। आपकी हालत भी अजीब है, आपको क्लासिक कार्यान्वयन में केवल 'एक्सप्लोरर्ड' सूची की जांच करनी चाहिए। मूल विचार यह है कि: सूची की शुरुआत से पहले नोड निकालें, अपने सभी पड़ोसियों को एक ही सूची के अंत में जोड़ें। जब सूची खाली हो या जब आप उस सूची में गंतव्य नोड जोड़ते हैं तो रोकें। – IVlad