I cant find the error here..

#include "stdafx.h"
#include <deque>
#include <list>
#include <queue>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <set>
using namespace std;

char file_name[15];
char links_file[15];
char alg[15];
char with_list[15];
char new_name[15];
int depth;
long idstart,idgoal;

class Action
{ 
	public:

	long start_node;
	long end_node;
	int distance; 
	int one_way;
	string road;

	Action();
	Action(long sn, long en, int dist, int ow, string r)
	{
		start_node=sn;
		end_node=en;
		distance=dist;
		one_way=ow;
		road=r;
	}
};

class Node
{
public:
	long state;
	int path_cost;
	Node();
	Node(long s,int p_c)
	{
		state=s;
		path_cost=p_c;
	}
};

class Problem
{
public:
 long initial_node;
 long final_node;
 int path_cost;

	bool GoalTest(Node node)
	{
		if(node.state==final_node)
			return true;
		else return false;
	}
	Problem();
	Problem(long in, long fn)
	{
	initial_node=in;
	final_node=fn;
	path_cost=0;
	
	}
bool bfs(Problem pbm);


};


Node ChildNode(Problem pbm, Node n, Action a)
{

}

void assign_value(Node n1,Node n2)
{
	n1.path_cost=n2.path_cost;
	n1.state=n2.state;
}

bool cmpNodes(Node n1, Node n2)
{
	if((n1.path_cost==n2.path_cost) && (n1.state==n2.state))
		return true;
	else return false;
}


int _tmain(int argc, _TCHAR* argv[])
{
	list<Action> actions;
	list<Action>::iterator j;
	int frontier_no=0;
	
	queue<Node> frontier;
	set<Node> explored;
	char command_line[150];
	int acts=0;

	if(argc==8)
		{
			printf("Enter: file name, links file, algorithm name(bfs/dfs/astar), closed list(Y/N), depth to search, id of the starting node, id of the goal node, name of new file: ");
			scanf("%s",command_line); //read the name of the file
			sscanf(command_line,"%s %s %s %s %d %l %l %s",file_name,links_file,alg,with_list,depth,idstart,idgoal,new_name);
			
			string start_node;
			string end_node;
			string distance; 
			string one_way;
			string road;
			string line;
			int no_links;
			int line_no;
			ifstream fp(links_file);

			if (fp.is_open())
			  {
				while (!fp.eof())
				{
				  getline (fp,line);
				  line_no++;
				}
				fp.close();
			  }
			
			
			if (fp.is_open())
			{
					while (!fp.eof())
					{
						  getline(fp,line);
						  istringstream iss(line);
						  iss >> start_node;
						  iss>>end_node;
						  iss>>distance;
						  iss>>one_way;
						  iss>>road;
						  iss>>line;
						Action a;
						a.distance=atoi(distance.c_str());
						a.end_node=atol(end_node.c_str());
						a.one_way=atoi(one_way.c_str());
						a.road=road;
						a.start_node=atol(start_node.c_str());
						//=new Action(atol(start_node.c_str()),atol(end_node.c_str()),atoi(distance.c_str()),atoi(one_way.c_str()),road);
						actions.push_back(a);
						acts++;
						 
					}
					fp.close();
				}
					else cout << "Unable to open file";
			

			Problem problem;
			problem.final_node=idgoal;
			problem.initial_node=idstart;
			//=new Problem(idstart,idgoal);
			Node child;
			Node node;
			node.path_cost=problem.path_cost;
			node.state=problem.initial_node;
			//=new Node((*problem).initial_node,(*problem).path_cost);
			if(problem.GoalTest(node)) return (1);
			
		
			bool in_queue=false;

			while(1)
			{
				if(frontier.empty()) return -1;
				assign_value(node,frontier.front());
				explored.insert(node);

				
				for(j=actions.begin();j!=actions.end();j++)
				{
				assign_value(child,ChildNode(problem,node,actions.front()));
				int i;
					for( i=0;i<acts;i++)
						{
							in_queue=cmpNodes(child,frontier.front());
							Node n;
							assign_value(n,frontier.front());
							frontier.push(n);
							frontier.pop();
							if(in_queue)
								break;
								
						}
					set<Node>::iterator it;
					it=explored.find(child);
					if(it!=explored.end()&&!in_queue)
					{
						
							if(problem.GoalTest(child))
								return (1);
							frontier.push(child);
					}
					in_queue=false;
				}
			}
			
			
		}
	return 0;
}

Recommended Answers

All 10 Replies

What error are you getting?

From looking at your code it looks like

Action();

the above way of defining your default constructor could be the problem.

If you would post the actual compilation error, I would be able to help you better.

Error 4 error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const Node' c:\program files\microsoft visual studio 8\vc\include\functional 143

Error 5 error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const Node' c:\program files\microsoft visual studio 8\vc\include\functional 143

Error 6 error C2784: 'bool std::operator <(const _Elem *,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const _Elem *' from 'const Node' c:\program files\microsoft visual studio 8\vc\include\functional 143

Error 7 error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const Node' c:\program files\microsoft visual studio 8\vc\include\functional 143

Error 8 error C2784: 'bool std::operator <(const std::queue<_Ty,_Container> &,const std::queue<_Ty,_Container> &)' : could not deduce template argument for 'const std::queue<_Ty,_Container> &' from 'const Node' c:\program files\microsoft visual studio 8\vc\include\functional 143

Error 9 error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const Node' c:\program files\microsoft visual studio 8\vc\include\functional 143

Error 10 error C2784: 'bool std::operator <(const std::list<_Ty,_Ax> &,const std::list<_Ty,_Ax> &)' : could not deduce template argument for 'const std::list<_Ty,_Ax> &' from 'const Node' c:\program files\microsoft visual studio 8\vc\include\functional 143

Error 11 error C2784: 'bool std::operator <(const std::deque<_Ty,_Alloc> &,const std::deque<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::deque<_Ty,_Alloc> &' from 'const Node' c:\program files\microsoft visual studio 8\vc\include\functional 143

Error 12 error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const Node' c:\program files\microsoft visual studio 8\vc\include\functional 143

Error 13 error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const Node' c:\program files\microsoft visual studio 8\vc\include\functional 143

Error 14 error C2676: binary '<' : 'const Node' does not define this operator or a conversion to a type acceptable to the predefined operator c:\program files\microsoft visual studio 8\vc\include\functional 143

Thank you for helping me!

What error are you getting?

From looking at your code it looks like

Action();

the above way of defining your default constructor could be the problem.

If you would post the actual compilation error, I would be able to help you better.

Please take a look at istringstream function usage.

I guess you would need to specify the second variable since you are using the

explicit istringstream ( const string & str, openmode which = ios_base::in );

function

I tried

istringstream iss(line,istringstream::in);

and still getting the same errors.
Thank you so much for helping me out!

Please take a look at istringstream function usage.

I guess you would need to specify the second variable since you are using the

explicit istringstream ( const string & str, openmode which = ios_base::in );

function

Could you please post the errors that you are getting now and start from Error 1?

Your previous post starts from Error4

1,2 and 3 are warnings, but I'll post them:

Warning 1 warning C4996: 'scanf' was declared deprecated c:\documents and settings\donevska\my documents\visual studio 2005\projects\searchalgorithms\searchalgorithms\searchalgorithms.cpp 116

Warning 2 warning C4996: 'sscanf' was declared deprecated c:\documents and settings\donevska\my documents\visual studio 2005\projects\searchalgorithms\searchalgorithms\searchalgorithms.cpp 117
Warning 3 warning C4101: 'no_links' : unreferenced local variable c:\documents and settings\donevska\my documents\visual studio 2005\projects\searchalgorithms\searchalgorithms\searchalgorithms.cpp 125
Error 4 error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const Node' c:\program files\microsoft visual studio 8\vc\include\functional 143


This is how they go... up to 14. Eleven errors in the project.

I believe the problem is due to the set used. It is trying to do an internal sort operation. You could try to fix the problem by overloading '<' operator for Node class.

Thank you for helping me out! I will try that.

Finally got a VC++ 2008 compiler and ran this code through that.

The < operator needs to be overloaded as per the instructions given here.

Giving the code below.

class Node
      {
  
                       public:
  
                                      long state;
  
                                      int path_cost;
  
	                Node()
                       {
                                   //To be implemented
                       }
  
                        Node(long s,int p_c)
  
                       {
  
                                    state=s;
  
                                     path_cost=p_c;
  
                      }

	               friend bool operator<(const Node& x, const Node& y);
  
      };

       bool operator<(const Node& x, const Node& y)
      {

                  //To be implemented
		  return true;

      }

My overloaded operator is just returning true. You should implement the code as per your requirement.

I had to rename main and the args to main.

Default constructors needs to be defined for all the classes.

Some other minor errors are there which can be fixed by reading the error messages.

Thanks, u saved my life! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.