
I'm trying to compile the puzzle 8 given in this link http://www.cs.rpi.edu/~beevek/research/astar_bgl04.pdf using astar_search_no_init() but I get this error "error C2106: '=' : left operand must be l-value" I'm using VS2010. Can someone please help me Here is my entire code #include<boost/graph/adjacency_list.hpp> #include<boost/graph/astar_search.hpp> #include<iostream> #include<vector> #include<list> using namespace std; using namespace boost; class puzzle_state_t: public vector<int> { public: int m_row,m_col; // row and columns puzzle_state_t(){} puzzle_state_t(int r,int c): vector<int>(r*c),m_row(r),m_col(c){} //another ctor with some iterator template<typename IteratorType> puzzle_state_t(int r,int c,IteratorType beg,IteratorType en): vector<int>(beg,en)m_row(r),m_col(c){} //find the cell in the vector // rows are numbered 0,1,2 // cols are numbered 0,1,2 inline int cell(int r, int c) const { return r*m_col+c; //gives the index of vector } //get value of a cell inline int get(int r, int c) const { int index= cell(r,c); return operator[] (index);// returns value } //move between two cells inline void move(int i,int j) { int tmp=operator[] (j); operator[](j)=operator[](i); operator[](i)=tmp; } //find coordinates of an offset inline void coords(int i, int &r, int &c) const { r=i/m_col; c=i%m_col; } friend ostream& operator <<(ostream &out, const puzzle_state_t &p) { for(int i = 0; i < p.m_row; ++i) { for(int j = 0; j < p.m_col; ++j) { if(p.get(i, j) > 0) cout << p.get(i, j)<<"\t" ; else cout << "-"<<"\t"; } cout << endl; } return out; } }; //1. find out the cell with zero void generate_children(const puzzle_state_t &p, list<puzzle_state_t> &children ) { puzzle_state_t::const_iterator const_it= find(p.begin(),p.end(),0); int soffset= const_it-p.begin(); //index of array int sr,sc; p.coords(soffset,sr,sc);// got the cell if(sc>0) {//mode tile to left children.push_back(p); children.back().move(soffset,p.cell(sr,sc-1) ); } if(sc<p.m_col-1) {//move to right children.push_back(p); children.back().move(soffset,p.cell(sr,sc+1)); } if(sr>0) {//move tile to above children.push_back(p); children.back().move(soffset,p.cell(sr-1,sc) ); } if(sr<p.m_row-1) { children.push_back(p); children.back().move(soffset,p.cell(sr+1,sc) ); } } //Graph and related types //a new property tag struct vertex_puzzle_state_t { typedef vertex_property_tag kind; }; //define VertexProperties typedef property<vertex_color_t, default_color_type, property<vertex_rank_t, unsigned int, property<vertex_distance_t, unsigned int, property<vertex_predecessor_t, unsigned int, property<vertex_puzzle_state_t, puzzle_state_t, property<vertex_index_t,unsigned int> > > > > > VertexProperties; //define EdgeProperties typedef property<edge_weight_t, unsigned int> EdgeProperties; //Define Graph_type typedef adjacency_list<listS,vecS,undirectedS,VertexProperties,EdgeProperties,no_property,listS> graph_t; typedef graph_traits<graph_t>::vertex_descriptor vertex_t; typedef graph_traits<graph_t>::edge_descriptor edge_t; typedef graph_traits<graph_t>::vertex_iterator vit; typedef graph_traits<graph_t>::edge_iterator eit; //property maps //Named Parameter version //IN:weight_map- length of each edge //IN: vertex_index_map- typedef property_map<graph_t,edge_weight_t>::type WeightMap; typedef property_map<graph_t,vertex_index_t>:: type IndexMap; //OUT: predecessor_map //Out: distance_map //OUT: rank_map //OUT: color_map typedef property_map<graph_t,vertex_predecessor_t>::type PredMap; typedef property_map<graph_t,vertex_distance_t>::type DistanceMap; typedef property_map<graph_t,vertex_rank_t>::type RankMap; typedef property_map<graph_t,vertex_color_t>::type ColorMap; // custom mpa typedef property_map<graph_t,vertex_puzzle_state_t>::type StateMap; struct found_goal{}; template<typename Vertex> class puzzle_visitor : public boost::default_astar_visitor { private: list<vertex_t> &m_verticesList; puzzle_state_t &m_goal_state; public: puzzle_visitor(list<vertex_t> & vlist,puzzle_state_t &goal): m_verticesList(vlist),m_goal_state(goal){} template <class Graph> void examine_vertex(Vertex u, Graph& g) {// add states and break if it reached goal state StateMap smap= get(vertex_puzzle_state_t,g); WeightMap wmap= get(edge_weight_t,g); ColorMap cmap= get(vertex_color_t,g); if(smap[u]==m_goal) throw found_goal(); //add successors of state list<puzzle_state_t> new_vertices; generate_children(smap[u],new_vertices ); list<puzzle_state_t>::iterator it; for(it=new_vertices.begin(); it != new_vertices.end(); ++it) { //make sure this is a new state vit vi,vend; for(tie(vi,vend)=vertices(g); vi != vend; ++vi) { if(*vi== *it ) break; } if(vi != vend)//not new { pair<edge_t,bool> eAdded=add_edge(u,*vi,g); if(eAdded) put(wmap,eAdded.first); }else {//new Vertex v= add_vertex(g); put(cmap,v,white_color); pair<edge_t,bool> eAdded=add_edge(u,v,g); if(eAdded) put(wmap,eAdded.first) } } } }; // the distance huristics // sum of (row_goal-row_current) + (col_goal-col_current) for all tiles class manhattan_dist: public astar_heuristic<graph_t,unsigned int> { puzzle_state_t &m_goal_state; StateMap m_smap; inline unsigned int myabs(int i) { return static_cast<unsigned int> (i<0 ? -i:i); } public: manhattan_dist(puzzle_state_t &goal, StateMap &smap): m_goal_state(goal),m_smap(smap){} unsigned int operator() (vertex_t u) { unsigned int md=0; puzzle_state_t::const_iterator it_i,it_j; int ir,ic,jr,jc; for(it_i=m_smap[u].begin(); it_i != m_smap[u].end(); ++it_i) { it_j=find(m_goal_state.begin(),m_goal_state.end(),*it_i); m_smap[u].coords(it_i - m_smap[u].begin(), ir, ic); m_goal_state.coords(it_j - m_goal_state.begin(), jr, jc); md += myabs(jr - ir) + myabs(jc - ic); } return md; } }; int main() { //set up start_state and goal_puzzle state graph_t g; list<vertex_t> examine_seq; //maps //IN IndexMap indexMap= get(vertex_index,g); WeightMap wmap= get(edge_weight_t (),g); //OUT DistanceMap dmap= get(vertex_distance,g); ColorMap cmap= get(vertex_color,g); PredMap predessors= get(vertex_predecessor,g); RankMap rmap= get(vertex_rank,g); //custom map StateMap smap= get(vertex_puzzle_state_t (),g); //add first vertex vertex_t start = add_vertex(g); put(cmap,start,white_color); put(dmap,start,0); // int sstart []= {1,3,4,8,0,2,7,6,5}; int sgoal []= {1,2,3,8,0,4,7,6,5}; //smap[start]= puzzle_state_t(3,3,&sstart[0],&sstart[9] ); puzzle_state_t p(3,3); puzzle_state_t goal(3,3); for(int i=0; i<9; ++i) { p[i]=sstart[i]; goal[i]=sgoal[i]; } smap[start]= p; cout<<"Start state"<<endl<<endl; cout<< smap[start]<<endl; cout<<"Goal state"<<endl<<endl; cout<<goal<<endl; // puzzle_visitor<vertex_t> vis(examine_seq,goal); manhattan_dist m_dist_heuristic(goal,smap); astar_search_no_init(g, start, //source m_dist_heuristic,// heuristic visitor(vis).// vis vertex_index_map(indexMap).// IN: index_map weight_map(wmap).//IN: weight_map predecessor_map(predessors).//OUT distance_map(dmap).//OUT color_map(cmap).//OUT rank_map(rmap)//OUT ); return 0; } -- View this message in context: http://boost.2283326.n4.nabble.com/astar-search-no-init-tp3680535p3680535.ht... Sent from the Boost - Users mailing list archive at Nabble.com.

On Wed, 20 Jul 2011, anilpanicker wrote:
I'm trying to compile the puzzle 8 given in this link
http://www.cs.rpi.edu/~beevek/research/astar_bgl04.pdf
using astar_search_no_init()
but I get this error "error C2106: '=' : left operand must be l-value" I'm using VS2010. Can someone please help me
What is the full error message you get, including the instantiation stack? Which version of Boost are you using? -- Jeremiah Willcock

I use boost 1.46.1 The full error code is too long, so I did not put it. It looks like color map needs to know the number of vertices (so expecting a vector): The full error message is here ------ Build started: Project: implicit_astar, Configuration: Debug Win32 ------ 1> implicit_astar_test1.cpp 1>c:\program files (x86)\boost\boost_1_46_1\boost\property_map\property_map.hpp(361): error C2106: '=' : left operand must be l-value 1> c:\program files (x86)\boost\boost_1_46_1\boost\graph\breadth_first_search.hpp(72) : see reference to function template instantiation 'void boost::put<boost::vec_adj_list_vertex_id_map<Property,Vertex>,Vertex,unsigned int,boost::default_color_type>(const boost::put_get_helper<Reference,LvaluePropertyMap> &,K,const V &)' being compiled 1> with 1> [ 1> Property=boost::property<boost::vertex_color_t,boost::default_color_type,boost::property<boost::vertex_rank_t,unsigned int,boost::property<boost::vertex_distance_t,unsigned int,boost::property<boost::vertex_predecessor_t,unsigned int,boost::property<vertex_puzzle_state_t,puzzle_state_t,boost::property<boost::vertex_index_t,unsigned int>>>>>>, 1> Vertex=unsigned int, 1> Reference=unsigned int, 1> LvaluePropertyMap=boost::vec_adj_list_vertex_id_map<boost::property<boost::vertex_color_t,boost::default_color_type,boost::property<boost::vertex_rank_t,unsigned int,boost::property<boost::vertex_distance_t,unsigned int,boost::property<boost::vertex_predecessor_t,unsigned int,boost::property<vertex_puzzle_state_t,puzzle_state_t,boost::property<boost::vertex_index_t,unsigned int>>>>>>,unsigned int>, 1> K=unsigned int, 1> V=boost::default_color_type 1> ] 1> c:\program files (x86)\boost\boost_1_46_1\boost\graph\astar_search.hpp(260) : see reference to function template instantiation 'void boost::breadth_first_visit<VertexListGraph,MutableQueue,boost::detail::astar_bfs_visitor<AStarHeuristic,UniformCostVisitor,UpdatableQueue,PredecessorMap,CostMap,DistanceMap,WeightMap,ColorMap,BinaryFunction,BinaryPredicate>,ColorMap>(const IncidenceGraph &,unsigned int,Buffer &,BFSVisitor,ColorMap)' being compiled 1> with 1> [ 1> VertexListGraph=graph_t, 1> AStarHeuristic=manhattan_dist, 1> UniformCostVisitor=puzzle_visitor<vertex_t>, 1> UpdatableQueue=MutableQueue, 1> PredecessorMap=boost::vec_adj_list_vertex_property_map<graph_t,graph_t *,unsigned int,unsigned int &,boost::vertex_predecessor_t>, 1> CostMap=boost::vec_adj_list_vertex_property_map<graph_t,graph_t *,unsigned int,unsigned int &,boost::vertex_rank_t>, 1> DistanceMap=boost::vec_adj_list_vertex_property_map<graph_t,graph_t *,unsigned int,unsigned int &,boost::vertex_distance_t>, 1> WeightMap=boost::adj_list_edge_property_map<boost::undirected_tag,unsigned int,unsigned int &,unsigned int,boost::property<boost::edge_weight_t,unsigned int>,boost::edge_weight_t>, 1> ColorMap=boost::vec_adj_list_vertex_id_map<boost::property<boost::vertex_color_t,boost::default_color_type,boost::property<boost::vertex_rank_t,unsigned int,boost::property<boost::vertex_distance_t,unsigned int,boost::property<boost::vertex_predecessor_t,unsigned int,boost::property<vertex_puzzle_state_t,puzzle_state_t,boost::property<boost::vertex_index_t,unsigned int>>>>>>,unsigned int>, 1> BinaryFunction=boost::closed_plus<D>, 1> BinaryPredicate=std::less<D>, 1> IncidenceGraph=graph_t, 1> Buffer=MutableQueue, 1> BFSVisitor=boost::detail::astar_bfs_visitor<manhattan_dist,puzzle_visitor<vertex_t>,MutableQueue,boost::vec_adj_list_vertex_property_map<graph_t,graph_t *,unsigned int,unsigned int &,boost::vertex_predecessor_t>,boost::vec_adj_list_vertex_property_map<graph_t,graph_t *,unsigned int,unsigned int &,boost::vertex_rank_t>,boost::vec_adj_list_vertex_property_map<graph_t,graph_t *,unsigned int,unsigned int &,boost::vertex_distance_t>,boost::adj_list_edge_property_map<boost::undirected_tag,unsigned int,unsigned int &,unsigned int,boost::property<boost::edge_weight_t,unsigned int>,boost::edge_weight_t>,boost::vec_adj_list_vertex_id_map<boost::property<boost::vertex_color_t,boost::default_color_type,boost::property<boost::vertex_rank_t,unsigned int,boost::property<boost::vertex_distance_t,unsigned int,boost::property<boost::vertex_predecessor_t,unsigned int,boost::property<vertex_puzzle_state_t,puzzle_state_t,boost::property<boost::vertex_index_t,unsigned int>>>>>>,unsigned int>,boost::closed_plus<D>,std::less<D>> 1> ] 1> c:\program files (x86)\boost\boost_1_46_1\boost\graph\astar_search.hpp(373) : see reference to function template instantiation 'void boost::astar_search_no_init<VertexListGraph,AStarHeuristic,const Arg,boost::vec_adj_list_vertex_property_map<Graph,GraphPtr,ValueType,Reference,Tag>,boost::vec_adj_list_vertex_property_map<Graph,GraphPtr,ValueType,Reference,boost::vertex_rank_t>,boost::vec_adj_list_vertex_property_map<Graph,GraphPtr,ValueType,Reference,boost::vertex_distance_t>,boost::adj_list_edge_property_map<Directed,Value,Ref,Vertex,Property,boost::edge_weight_t>,boost::vec_adj_list_vertex_id_map<boost::property<boost::vertex_color_t,T,Base>,Vertex>,boost::vec_adj_list_vertex_property_map<Graph,GraphPtr,boost::default_color_type,boost::default_color_type &,boost::vertex_color_t>,const Default,boost::closed_plus<D>,unsigned int,unsigned int>(const VertexListGraph &,unsigned int,AStarHeuristic,AStarVisitor,PredecessorMap,CostMap,DistanceMap,WeightMap,ColorMap,VertexIndexMap,CompareFunction,CombineFunction,CostInf,CostZero)' being compiled 1> with 1> [ 1> VertexListGraph=graph_t, 1> AStarHeuristic=manhattan_dist, 1> Arg=const puzzle_visitor<vertex_t>, 1> Graph=graph_t, 1> GraphPtr=graph_t *, 1> ValueType=unsigned int, 1> Reference=unsigned int &, 1> Tag=boost::vertex_predecessor_t, 1> Directed=boost::undirected_tag, 1> Value=unsigned int, 1> Ref=unsigned int &, 1> Vertex=unsigned int, 1> Property=boost::property<boost::edge_weight_t,unsigned int>, 1> T=boost::default_color_type, 1> Base=boost::property<boost::vertex_rank_t,unsigned int,boost::property<boost::vertex_distance_t,unsigned int,boost::property<boost::vertex_predecessor_t,unsigned int,boost::property<vertex_puzzle_state_t,puzzle_state_t,boost::property<boost::vertex_index_t,unsigned int>>>>>, 1> Default=const std::less<D>, 1> AStarVisitor=const puzzle_visitor<vertex_t>, 1> PredecessorMap=const boost::vec_adj_list_vertex_property_map<graph_t,graph_t *,unsigned int,unsigned int &,boost::vertex_predecessor_t>, 1> CostMap=boost::vec_adj_list_vertex_property_map<graph_t,graph_t *,unsigned int,unsigned int &,boost::vertex_rank_t>, 1> DistanceMap=boost::vec_adj_list_vertex_property_map<graph_t,graph_t *,unsigned int,unsigned int &,boost::vertex_distance_t>, 1> WeightMap=boost::adj_list_edge_property_map<boost::undirected_tag,unsigned int,unsigned int &,unsigned int,boost::property<boost::edge_weight_t,unsigned int>,boost::edge_weight_t>, 1> ColorMap=boost::vec_adj_list_vertex_id_map<boost::property<boost::vertex_color_t,boost::default_color_type,boost::property<boost::vertex_rank_t,unsigned int,boost::property<boost::vertex_distance_t,unsigned int,boost::property<boost::vertex_predecessor_t,unsigned int,boost::property<vertex_puzzle_state_t,puzzle_state_t,boost::property<boost::vertex_index_t,unsigned int>>>>>>,unsigned int>, 1> VertexIndexMap=boost::vec_adj_list_vertex_property_map<graph_t,graph_t *,boost::default_color_type,boost::default_color_type &,boost::vertex_color_t>, 1> CompareFunction=const std::less<D>, 1> CombineFunction=const boost::closed_plus<D>, 1> CostInf=const std::numeric_limits<unsigned int>::_Ty, 1> CostZero=const D 1> ] 1> c:\cppprojects\implicit_astar\implicit_astar\implicit_astar_test1.cpp(269) : see reference to function template instantiation 'void boost::astar_search_no_init<graph_t,manhattan_dist,RankMap,boost::vertex_rank_t,boost::bgl_named_params<T,Tag,Base>>(const VertexListGraph &,unsigned int,AStarHeuristic,const boost::bgl_named_params<RankMap,boost::vertex_rank_t,boost::bgl_named_params<T,Tag,Base>> &)' being compiled 1> with 1> [ 1> T=ColorMap, 1> Tag=boost::vertex_color_t, 1> Base=boost::bgl_named_params<DistanceMap,boost::vertex_distance_t,boost::bgl_named_params<PredMap,boost::vertex_predecessor_t,boost::bgl_named_params<WeightMap,boost::edge_weight_t,boost::bgl_named_params<IndexMap,boost::vertex_index_t,boost::bgl_named_params<puzzle_visitor<vertex_t>,boost::graph_visitor_t,boost::no_property>>>>>, 1> VertexListGraph=graph_t, 1> AStarHeuristic=manhattan_dist 1> ] ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== On Wed, Jul 20, 2011 at 8:09 PM, Jeremiah Willcock <jewillco@osl.iu.edu>wrote:
On Wed, 20 Jul 2011, anilpanicker wrote:
I'm trying to compile the puzzle 8 given in this link
using astar_search_no_init()
but I get this error "error C2106: '=' : left operand must be l-value" I'm using VS2010. Can someone please help me
What is the full error message you get, including the instantiation stack? Which version of Boost are you using?
-- Jeremiah Willcock ______________________________**_________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/**mailman/listinfo.cgi/boost-**users<http://lists.boost.org/mailman/listinfo.cgi/boost-users>

On Wed, 20 Jul 2011, Anil Ramapanicker wrote:
I use boost 1.46.1 The full error code is too long, so I did not put it. It looks like color map needs to know the number of vertices (so expecting a vector):
I tried to compile your code, and it has many problems. Is this the first error message you get out of it? Is there a newer version of the code for me to try? -- Jeremiah Willcock
participants (3)
-
Anil Ramapanicker
-
anilpanicker
-
Jeremiah Willcock