Browse Source

优化最小路径算法

zzj 5 years ago
parent
commit
93aee9d2d6
2 changed files with 19 additions and 0 deletions
  1. 2 0
      ant.cpp
  2. 17 0
      card_path.cpp

+ 2 - 0
ant.cpp

@@ -373,6 +373,8 @@ void sit_list::read_ant_path(int id)
 
 	card_path::init();
 
+	test_find_path(card_path::inst(),point(4727,-8.06),point(2200,-75));
+	test_find_path(card_path::inst(),point(4727,-8.06),point(2600,-100));
 	test_find_path(card_path::inst(),point(4727,-8.06),point(5427.04,-304.02));
 	test_find_path(card_path::inst(),point(4714.70,-8.06),point(5427.04,-304.02));
 }

+ 17 - 0
card_path.cpp

@@ -811,6 +811,23 @@ struct graph
 		}
 
 		std::reverse(rc.begin(),rc.end());
+		rc.push_back(to);
+		auto bp=from;
+		auto it1=rc.begin();
+		for(auto it2=it1+1;it1!=rc.end() && it2!=rc.end();it2++)
+		{
+			if(line(bp,*it1).dist(*it2)<0.1)
+			{
+				*it1=*it2;
+			}
+			else
+			{
+				bp=*it1++;
+				*it1=*it2;
+			}
+		}
+
+		rc.erase(it1,rc.end());
 
 		return std::move(rc);
 	}