HypothesesGraph* SingleTimestepTraxel_HypothesesBuilder::add_edges_at(HypothesesGraph* graph, int timestep) const { const HypothesesGraph::node_timestep_map& timemap = graph->get( node_timestep()); typedef property_map<node_traxel, HypothesesGraph::base_graph>::type traxelmap_t; const traxelmap_t& traxelmap = graph->get(node_traxel()); const TraxelStoreByTimeid& traxels_by_timeid = ts_->get<by_timeid>(); const TraxelStoreByTimestep& traxels_by_timestep = ts_->get<by_timestep>(); //// find k nearest neighbors in next timestep // init nearest neighbor search pair<TraxelStoreByTimestep::const_iterator, TraxelStoreByTimestep::const_iterator> traxels_at = traxels_by_timestep.equal_range(timestep + 1); for (TraxelStoreByTimestep::const_iterator it = traxels_at.first; it != traxels_at.second; ++it) { assert(it->Timestep == (timestep+1)); } NearestNeighborSearch nns(traxels_at.first, traxels_at.second); // establish transition edges between a current node and appropriate nodes in next timestep for (HypothesesGraph::node_timestep_map::ItemIt curr_node(timemap, timestep); curr_node != lemon::INVALID; ++curr_node) { assert(timemap[curr_node] == timestep); assert(traxelmap[curr_node].Timestep == timestep); // search map<unsigned int, double> nearest_neighbors = nns.knn_in_range( traxelmap[curr_node], options_.distance_threshold, options_.max_nearest_neighbors); //// connect current node with k nearest neighbor nodes for (map<unsigned int, double>::const_iterator neighbor = nearest_neighbors.begin(); neighbor != nearest_neighbors.end(); ++neighbor) { // connect with one of the neighbor nodes TraxelStoreByTimeid::iterator neighbor_traxel = traxels_by_timeid.find( boost::make_tuple(timestep + 1, neighbor->first)); assert(neighbor_traxel->Timestep == (timestep + 1)); assert(neighbor_traxel->Timestep != traxelmap[curr_node].Timestep); traxelmap_t::ItemIt neighbor_node(traxelmap, *neighbor_traxel); assert(curr_node != neighbor_node); graph->addArc(curr_node, neighbor_node); } } return graph; }
void dijkstra(const graph &g, const std::string &start_vtx, bfs_tree &tree, int shortest_path_estimate) { init_single_source(g, start_vtx, tree, shortest_path_estimate); bfs_tree_node_min_heap min_heap; bfs_tree_node_min_heap::handle_type handles[g.m_headers.size()]; for (size_t i = 0; i != g.m_headers.size(); ++i) { if (g.m_headers[i] != NULL) handles[i] = min_heap.push(bfs_tree_node(shortest_path_estimate, "", i+1)); } int curr_No = g.m_map.at(start_vtx); bfs_tree_node curr_node(0, "", curr_No); string curr_name; int next_No; string next_name; min_heap.decrease(handles[curr_No-1], curr_node); while (!min_heap.empty()) { curr_node = min_heap.top(); min_heap.pop(); curr_No = curr_node.m_No; curr_name = g.m_map_iters[curr_No-1]->first; tree[curr_name].m_dist = curr_node.m_dist; tree[curr_name].m_path = curr_node.m_path; header_vertex *hvtxptr = g.m_headers[curr_No-1]; for (graph::edge_list_type::iterator iter = hvtxptr->begin(); iter != hvtxptr->end(); ++iter) { next_No = (*iter)->m_No; next_name = g.m_map_iters[next_No-1]->first; if (edge_relax(curr_name, next_name, (*iter)->m_weight, tree)) min_heap.decrease(handles[next_No-1], tree[next_name]); } } }
void CrackFrontDefinition::getCrackFrontNodes(std::set<unsigned int>& nodes) { ConstBndNodeRange & bnd_nodes = *_mesh.getBoundaryNodeRange(); for (ConstBndNodeRange::const_iterator nd = bnd_nodes.begin() ; nd != bnd_nodes.end(); ++nd) { const BndNode * bnode = *nd; BoundaryID boundary_id = bnode->_bnd_id; if (hasBoundary(boundary_id)) { nodes.insert(bnode->_node->id()); } } if (_treat_as_2d) { if (nodes.size() > 1) { //Delete all but one node if they are collinear in the axis normal to the 2d plane unsigned int axis0; unsigned int axis1; switch (_axis_2d) { case 0: axis0 = 1; axis1 = 2; break; case 1: axis0 = 0; axis1 = 2; break; case 2: axis0 = 0; axis1 = 1; break; } Real node0coor0; Real node0coor1; for (std::set<unsigned int>::iterator sit=nodes.begin(); sit != nodes.end(); ++sit) { Node & curr_node = _mesh.node(*sit); if (sit == nodes.begin()) { node0coor0 = curr_node(axis0); node0coor1 = curr_node(axis1); } else { if ((std::abs(curr_node(axis0) - node0coor0) > _tol) || (std::abs(curr_node(axis1) - node0coor1) > _tol)) { mooseError("Boundary provided in CrackFrontDefinition contains "<<nodes.size()<<" nodes, which are not collinear in the "<<_axis_2d<<" axis. Must contain either 1 node or collinear nodes to treat as 2D."); } } } std::set<unsigned int>::iterator second_node = nodes.begin(); ++second_node; nodes.erase(second_node,nodes.end()); } } }