void TSP::successor( const search_node& iNode, vector<search_node>& avail ) { //For each city in the current state for ( unsigned long int i = 0; i < m_num_cities; i++ ) { //If that city has not been visited if ( !iNode.get_state().get_visited()[i] ) { //Then push it into the list of available states to move to avail.push_back( iNode ); //And update it to reflect what would happen after we move there avail.back().get_state().set_visited(i); avail.back().get_state().set_location(i); avail.back().m_path.push_back(i); avail.back().set_cost( iNode.cost() + m_graph[iNode.get_state().location()][avail.back().get_state().location()] ); } } return; }
void TSP::predecessor( const search_node& iNode, deque<search_node>& avail ) { //Make a copy of the current node search_node updated_node = iNode; //Set that node's location to unvisited (note: unreachable state!) updated_node.get_state().set_unvisited( updated_node.get_state().location() ); //For each city in the node for ( unsigned int i = 0; i < m_num_cities; i++ ) { //If that city is visited already if ( updated_node.get_state().get_visited()[i] ) { avail.push_back( updated_node ); avail.back().get_state().set_location(i); avail.back().m_path.push_back(i); avail.back().set_cost( iNode.cost() + m_graph[iNode.get_state().location()][avail.back().get_state().location()] + h_min_graph() ); } } return; }