704 {
705 reed_shepp_generator_->reeds_sheep_last_straight_ = reeds_sheep_last_straight;
706
707 open_set_.clear();
708 close_set_.clear();
709 open_pq_ = decltype(open_pq_)();
710 final_node_ = nullptr;
711 PrintCurves print_curves;
712 std::vector<std::vector<common::math::LineSegment2d>> obstacles_linesegments_vec;
713 for (const auto& obstacle_vertices : obstacles_vertices_vec) {
714 size_t vertices_num = obstacle_vertices.size();
715 std::vector<common::math::LineSegment2d> obstacle_linesegments;
716 for (size_t i = 0; i < vertices_num - 1; ++i) {
717 common::math::LineSegment2d line_segment
718 = common::math::LineSegment2d(obstacle_vertices[i], obstacle_vertices[i + 1]);
719 obstacle_linesegments.emplace_back(line_segment);
720 }
721 obstacles_linesegments_vec.emplace_back(obstacle_linesegments);
722 }
723 obstacles_linesegments_vec_ = std::move(obstacles_linesegments_vec);
724 std::vector<std::vector<common::math::LineSegment2d>> soft_boundary_linesegments_vec;
725 for (const auto& soft_boundary_vertices : soft_boundary_vertices_vec) {
726 size_t vertices_num = soft_boundary_vertices.size();
727 std::vector<common::math::LineSegment2d> soft_boundary_linesegments;
728 for (size_t i = 0; i < vertices_num - 1; ++i) {
729 common::math::LineSegment2d line_segment
730 = common::math::LineSegment2d(soft_boundary_vertices[i], soft_boundary_vertices[i + 1]);
731 soft_boundary_linesegments.emplace_back(line_segment);
732 }
733 soft_boundary_linesegments_vec.emplace_back(soft_boundary_linesegments);
734 }
735 soft_boundary_linesegments_vec_ = std::move(soft_boundary_linesegments_vec);
736 for (size_t i = 0; i < obstacles_linesegments_vec_.size(); i++) {
737 for (auto linesg : obstacles_linesegments_vec_[i]) {
738 std::string name = std::to_string(i) + "roi_boundary";
739 print_curves.AddPoint(name, linesg.start());
740 print_curves.AddPoint(name, linesg.end());
741 }
742 }
743 Vec2d sposition(sx, sy);
744 Vec2d svec_to_center(
747 Vec2d scenter(sposition + svec_to_center.rotate(sphi));
748 Box2d sbox(scenter, sphi, vehicle_param_.
length(), vehicle_param_.
width());
749 print_curves.AddPoint("vehicle_start_box", sbox.GetAllCorners());
750 Vec2d eposition(ex, ey);
751 print_curves.AddPoint("end_position", eposition);
752 Vec2d evec_to_center(
755 Vec2d ecenter(eposition + evec_to_center.rotate(ephi));
756 Box2d ebox(ecenter, ephi, vehicle_param_.
length(), vehicle_param_.
width());
757 print_curves.AddPoint("vehicle_end_box", ebox.GetAllCorners());
758 XYbounds_ = XYbounds;
759
760 start_node_.reset(new Node3d({sx}, {sy}, {sphi}, XYbounds_, planner_warm_start_config_));
761 end_node_.reset(new Node3d({ex}, {ey}, {ephi}, XYbounds_, planner_warm_start_config_));
762 AINFO <<
"start node" << sx <<
"," << sy <<
"," << sphi;
763 AINFO <<
"end node " << ex <<
"," << ey <<
"," << ephi;
764 if (!ValidityCheck(start_node_)) {
765 AERROR <<
"start_node in collision with obstacles";
766 AERROR << start_node_->GetX() <<
"," << start_node_->GetY() <<
"," << start_node_->GetPhi();
767 print_curves.PrintToLog();
768 return false;
769 }
770 if (!ValidityCheck(end_node_)) {
771 AERROR <<
"end_node in collision with obstacles";
772 print_curves.PrintToLog();
773 return false;
774 }
776 grid_a_star_heuristic_generator_->GenerateDpMap(
777 ex, ey, XYbounds_, obstacles_linesegments_vec_, soft_boundary_linesegments_vec_);
779
780 open_set_.insert(start_node_->GetIndex());
781 open_pq_.emplace(start_node_, start_node_->GetCost());
782
783 size_t explored_node_num = 0;
784 size_t available_result_num = 0;
785 auto best_explored_num = explored_node_num;
786 auto best_available_result_num = available_result_num;
788 double heuristic_time = 0.0;
789 double rs_time = 0.0;
790 double node_generator_time = 0.0;
791 double validity_check_time = 0.0;
793 size_t desired_explored_num = std::min(
795 static constexpr int kMaxNodeNum = 200000;
796 std::vector<std::shared_ptr<Node3d>> candidate_final_nodes;
797 while (!open_pq_.empty() && open_pq_.size() < kMaxNodeNum && available_result_num < desired_explored_num
798 && explored_node_num < max_explored_num) {
799 std::shared_ptr<Node3d> current_node = open_pq_.top().first;
800 if (current_node->GetPreNode() != nullptr) {
801 AINFO <<
"print_open_pq:" <<
"(" << current_node->GetPreNode()->GetX() <<
", "
802 << current_node->GetPreNode()->GetY() << ")" << ";" << "(" << current_node->GetX() << ", "
803 << current_node->GetY() << ");";
804 }
805 open_pq_.pop();
807 std::shared_ptr<Node3d> final_node = nullptr;
808 if (AnalyticExpansion(current_node, &final_node)) {
809 if (final_node_ == nullptr || final_node_->GetTrajCost() > final_node->GetTrajCost()) {
810 final_node_ = final_node;
811 best_explored_num = explored_node_num + 1;
812 best_available_result_num = available_result_num + 1;
813 }
814 available_result_num++;
815 }
816 explored_node_num++;
818 rs_time += rs_end_time - rs_start_time;
819 close_set_.insert(current_node->GetIndex());
820
822 && available_result_num > 0) {
823 break;
824 }
825
826 size_t begin_index = 0;
827 size_t end_index = next_node_num_;
828 std::unordered_set<std::string> temp_set;
829 for (size_t i = begin_index; i < end_index; ++i) {
831 std::shared_ptr<Node3d> next_node = Next_node_generator(current_node, i);
833
834
835 if (next_node == nullptr) {
836 continue;
837 }
838
839 if (close_set_.count(next_node->GetIndex()) > 0) {
840 continue;
841 }
842
844 if (!ValidityCheck(next_node)) {
845 continue;
846 }
848 if (open_set_.count(next_node->GetIndex()) == 0) {
850 CalculateNodeCost(current_node, next_node);
852 heuristic_time += end_time - start_time;
853 temp_set.insert(next_node->GetIndex());
854 open_pq_.emplace(next_node, next_node->GetCost());
855 }
856 }
857 open_set_.insert(temp_set.begin(), temp_set.end());
858 }
859
860 if (final_node_ == nullptr) {
861 AERROR <<
"Hybird A* cannot find a valid path";
862 print_curves.PrintToLog();
863 return false;
864 }
865
866 AINFO <<
"open_pq_.empty()" << (open_pq_.empty() ?
"true" :
"false");
867 AINFO <<
"open_pq_.size()" << open_pq_.size();
868 AINFO <<
"desired_explored_num" << desired_explored_num;
869 AINFO <<
"min cost is : " << final_node_->GetTrajCost();
870 AINFO <<
"max_explored_num is " << max_explored_num;
871 AINFO <<
"explored node num is " << explored_node_num <<
"available_result_num " << available_result_num;
872 AINFO <<
"best_explored_num is " << best_explored_num <<
"best_available_result_num is "
873 << best_available_result_num;
874 AINFO <<
"cal node time is " << heuristic_time <<
"validity_check_time " << validity_check_time
875 << "node_generator_time " << node_generator_time;
876 AINFO <<
"reed shepp time is " << rs_time;
878
879 print_curves.AddPoint("rs_point", final_node_->GetXs().front(), final_node_->GetYs().front());
880 if (!GetResult(result)) {
881 AERROR <<
"GetResult failed";
882 print_curves.PrintToLog();
883 return false;
884 }
885 for (size_t i = 0; i < result->x.size(); i++) {
886 print_curves.AddPoint("warm_path", result->x[i], result->y[i]);
887 }
888
889
890
891
892
893 print_curves.PrintToLog();
894 return true;
895}
static double NowInSeconds()
gets the current time in second.
optional double left_edge_to_center
optional double back_edge_to_center
optional double front_edge_to_center
optional double right_edge_to_center
optional int32 max_explored_num
optional int32 desired_explored_num
optional double astar_max_search_time