Click here to Skip to main content
16,006,475 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Tree in MFC Pin
prasad_som24-Apr-07 2:41
prasad_som24-Apr-07 2:41 
QuestionFile Issue Pin
Try24-Apr-07 2:10
Try24-Apr-07 2:10 
AnswerRe: File Issue Pin
CPallini24-Apr-07 2:27
mveCPallini24-Apr-07 2:27 
AnswerRe: File Issue Pin
David Crow24-Apr-07 2:49
David Crow24-Apr-07 2:49 
GeneralRe: File Issue Pin
Try24-Apr-07 3:14
Try24-Apr-07 3:14 
GeneralRe: File Issue Pin
David Crow24-Apr-07 3:22
David Crow24-Apr-07 3:22 
GeneralRe: File Issue Pin
Try24-Apr-07 3:27
Try24-Apr-07 3:27 
Questiona star algorithm Pin
s chiddarwar24-Apr-07 0:57
s chiddarwar24-Apr-07 0:57 
im having problem with the code..

i want to print the information of node visited while approaching to goalnode..program is not checking any of the node specified and returns without any output.. code is linking properly, without any error or warning.. code is as follows:

#include "astar.h"
#include "math.h"

#include <iostream>
#include <stdio.h>

#define DEBUG_LISTS 0
#define DEBUG_LIST_LENGTHS_ONLY 0

using namespace std;

int NumofNodes=10;
int id=1 ;


double coordination[10][3]={{1,2,3},{14,26,38} ,{10,20,30}, {25,67,45},{35,47,55}, {36,56,54}, {44,56,89}, {32,34,56},{43,56,78}, {12,32,45}};


double GetX(int id)
{
return coordination[id][0];

}

double GetY(int id)
{
return coordination[id][1];
}
double GetZ(int id)
{
return coordination[id][2];
}

class MapSearchNode
{
public:
double x; // the (x,y,z) positions of the node
double y;
double z;
double id; // the index of the node
double g; // cumulative cost from s to this node

MapSearchNode() { x = y = z = 0; id = 0; g = NumofNodes;}
MapSearchNode( double px, double py, double pz, double pid, double pg) { x=px; y=py; z=pz ;id=pid; g = pg;}

double GoalDistanceEstimate( MapSearchNode &nodeGoal );
bool IsGoal( MapSearchNode &nodeGoal );
bool GetSuccessors( AStarSearch<MapSearchNode> *astarsearch, MapSearchNode *parent_node );
double GetCost( MapSearchNode &successor );
bool IsSameState( MapSearchNode &rhs );

void PrintNodeInfo();


};

bool MapSearchNode::IsSameState( MapSearchNode &rhs )
{
// same state in a maze search is simply when (x,y,z) are the same
if( (x == rhs.x) &&
(y == rhs.y) && (z == rhs.z) && (id == rhs.id))
{
return true;
}
else
{
return false;
}

}

void MapSearchNode::PrintNodeInfo()
{

cout << "Node position :" << x << y << z;


}

// the heuristic function that estimates the distance from a Node
// to the Goal.

double MapSearchNode::GoalDistanceEstimate( MapSearchNode &nodeGoal )
{
double xd = double( ( x - nodeGoal.x ) );
double yd = double( ( y - nodeGoal.y) );
double zd = double( ( z - nodeGoal.z) );

// return xd+yd+zd;

return (double)(sqrt((xd*xd) + (yd*yd) +(zd*zd) ));


}

bool MapSearchNode::IsGoal( MapSearchNode &nodeGoal )
{

if( (x == nodeGoal.x) &&
(y == nodeGoal.y) && (z == nodeGoal.z) && id == nodeGoal.id )
{
return true;
}

return false;
}


bool MapSearchNode::GetSuccessors( AStarSearch<MapSearchNode> *astarsearch, MapSearchNode *parent_node )
{

double parent_x = 0;
double parent_y = 0;
double parent_z = 0;

double parent_id = 0;
int i;
MapSearchNode NewNode;
if( parent_node )
{
parent_x = parent_node->x;
parent_y = parent_node->y;
parent_z = parent_node->z;

parent_id = parent_node->id;
}

for(i=0; i<NumofNodes; i++)
{
if( (parent_id != i))
{
NewNode = MapSearchNode(GetX(i), GetY(i), GetZ(i), i, NumofNodes);
astarsearch->AddSuccessor(NewNode);

}
}
return 0;
}

double MapSearchNode::GetCost( MapSearchNode &successor )
{

cout << GoalDistanceEstimate(successor);
return GoalDistanceEstimate(successor);

}




int main( int argc, char *argv[] )
{


AStarSearch<MapSearchNode> astarsearch;

unsigned int SearchCount = 0;

const unsigned int NumSearches = 1;

while(SearchCount < NumSearches)
{

// Create a start state
MapSearchNode nodeStart;
nodeStart.x = 1.0;
nodeStart.y = 2.0;
nodeStart.z = 3.0;

// Define the goal state
MapSearchNode nodeGoal;
nodeGoal.x = 12.0;
nodeGoal.y = 32.0;
nodeGoal.z = 45.0;

// Set Start and goal states

astarsearch.SetStartAndGoalStates( nodeStart, nodeGoal );

unsigned int SearchState = 0;
unsigned int SearchSteps = 0;
cout << "SearchState" << SearchState<< endl;
cout << "astarsearch.SearchStep()" << astarsearch.SearchStep() << endl;
cout << "searchng" << AStarSearch<MapSearchNode>::SEARCH_STATE_SEARCHING << endl;
cout << "succeeded " << AStarSearch<MapSearchNode>::SEARCH_STATE_SUCCEEDED << endl;
cout << " failed " << AStarSearch<MapSearchNode>::SEARCH_STATE_FAILED << endl;

if( SearchState == AStarSearch<MapSearchNode>::SEARCH_STATE_SEARCHING )
{
SearchState = astarsearch.SearchStep();


SearchSteps++;

#if DEBUG_LISTS

cout << "Steps:" << SearchSteps << "\n";

int len = 0;

cout << "Open:\n";
MapSearchNode *p = astarsearch.GetOpenListStart();
while( p )
{
len++;
#if !DEBUG_LIST_LENGTHS_ONLY
((MapSearchNode *)p)->PrintNodeInfo();
#endif
p = astarsearch.GetOpenListNext();

}

cout << "Open list has " << len << " nodes\n";

len = 0;

cout << "Closed:\n";
p = astarsearch.GetClosedListStart();
while( p )
{
len++;
#if !DEBUG_LIST_LENGTHS_ONLY
p->PrintNodeInfo();
#endif
p = astarsearch.GetClosedListNext();
}

cout << "Closed list has " << len << " nodes\n";
#endif

}


if( SearchState == AStarSearch<MapSearchNode>::SEARCH_STATE_SUCCEEDED )
{
cout << "Search found goal state\n";

MapSearchNode *node = astarsearch.GetSolutionStart();

#if DISPLAY_SOLUTION
cout << "Displaying solution\n";
#endif
int steps = 0;

node->PrintNodeInfo();
for( ;; )
{
node = astarsearch.GetSolutionNext();

if( !node )
{
break;
}

node->PrintNodeInfo();
steps ++;

};

cout << "Solution steps " << steps << endl;

astarsearch.FreeSolutionNodes();


}

if( SearchState == AStarSearch<MapSearchNode>::SEARCH_STATE_FAILED )
{
cout << "Search terminated. Did not find goal state\n";

}

// Display the number of loops the search went through
cout << "SearchSteps : " << SearchSteps << "\n";

SearchCount ++;

}

return 0;
}


please help me
QuestionRe: a star algorithm Pin
Maximilien24-Apr-07 2:25
Maximilien24-Apr-07 2:25 
AnswerRe: a star algorithm Pin
s chiddarwar24-Apr-07 5:07
s chiddarwar24-Apr-07 5:07 
AnswerRe: a star algorithm Pin
kakan24-Apr-07 2:37
professionalkakan24-Apr-07 2:37 
GeneralRe: a star algorithm Pin
s chiddarwar24-Apr-07 5:06
s chiddarwar24-Apr-07 5:06 
GeneralRe: a star algorithm Pin
kakan24-Apr-07 19:59
professionalkakan24-Apr-07 19:59 
AnswerRe: a star algorithm [modified] Pin
s chiddarwar25-Apr-07 23:37
s chiddarwar25-Apr-07 23:37 
GeneralRe: a star algorithm Pin
paul33333-Mar-10 2:07
paul33333-Mar-10 2:07 
QuestionProcesses creatation and termination notifications monitoring Pin
Lepon2k24-Apr-07 0:19
Lepon2k24-Apr-07 0:19 
Questiondon't send error Pin
neha.agarwal2724-Apr-07 0:09
neha.agarwal2724-Apr-07 0:09 
AnswerRe: don't send error Pin
prasad_som24-Apr-07 0:20
prasad_som24-Apr-07 0:20 
AnswerRe: don't send error Pin
kakan24-Apr-07 0:24
professionalkakan24-Apr-07 0:24 
AnswerRe: don't send error Pin
_AnsHUMAN_ 24-Apr-07 0:45
_AnsHUMAN_ 24-Apr-07 0:45 
AnswerRe: don't send error Pin
Nibu babu thomas24-Apr-07 1:43
Nibu babu thomas24-Apr-07 1:43 
QuestionHow to call Jar files from Visual C++ Pin
Nikhil Trivedi23-Apr-07 23:46
Nikhil Trivedi23-Apr-07 23:46 
AnswerRe: How to call Jar files from Visual C++ Pin
George L. Jackson24-Apr-07 0:19
George L. Jackson24-Apr-07 0:19 
GeneralRe: How to call Jar files from Visual C++ Pin
Nikhil Trivedi24-Apr-07 0:37
Nikhil Trivedi24-Apr-07 0:37 
AnswerRe: How to call Jar files from Visual C++ Pin
Nibu babu thomas24-Apr-07 0:21
Nibu babu thomas24-Apr-07 0:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.