• R/O
  • SSH
  • HTTPS

wheretrainbuild: Commit


Commit MetaInfo

Revision49 (tree)
Zeit2020-06-29 12:07:43
Autordangerouswoo

Log Message

(empty log message)

Ändern Zusammenfassung

Diff

--- WhereTrainBuild/AI/LineWalker.cs (revision 48)
+++ WhereTrainBuild/AI/LineWalker.cs (revision 49)
@@ -63,6 +63,7 @@
6363 public PointF Vector;
6464 public double AngleDiff;
6565 public double Distance;
66+ public double Diff;
6667 }
6768
6869 /// <summary>
@@ -163,13 +164,13 @@
163164 {
164165 var findlist = new List<ThreshPack>();
165166
166- for (float fDistance = 2.0f; fDistance <= 60.0f; fDistance += 4.0f)
167+ for (float fDistance = 2.0f; fDistance <= 60.0f; fDistance += 2.0f)
167168 {
168169 double dDeltaR = 1 / fDistance * 2.0;
169170
170171 //とりあえず、前方向をサーチ
171172 List<double> loopsrc = new List<double>();
172- for (double iD = -40.0; iD <= 40.0; iD += dDeltaR)
173+ for (double iD = -45.0; iD <= 45.0; iD += dDeltaR)
173174 loopsrc.Add(iD);
174175
175176 Parallel.ForEach(loopsrc, (iD) =>
@@ -187,7 +188,7 @@
187188 }
188189 });
189190
190- if (findlist.Count > 0 && fDistance > 30.0f)
191+ if (findlist.Count > 0 && fDistance > 10.0f)
191192 break;
192193 }
193194
@@ -198,6 +199,120 @@
198199 //ライン候補
199200 findlist.Sort((x, y)=>
200201 {
202+ var bSortResult = x.Distance.CompareTo(y.Distance);
203+ if (bSortResult != 0)
204+ return bSortResult;
205+ return x.AngleDiff.CompareTo(y.AngleDiff);
206+ });
207+
208+ //集団分布
209+ var mothertable = new Dictionary<int, List<ThreshPack>>();
210+ foreach( var pack in findlist)
211+ {
212+ bool bFind = false;
213+ //母集合内で近い集団見つける
214+ foreach( var grp in mothertable)
215+ {
216+ //各集団より 相応しい集団を発見する
217+ foreach (var fpack in grp.Value)
218+ {
219+ var fDistance = latlontool.calcS(fpack.Position, pack.Position);
220+ if (fDistance < 3.0f )
221+ {
222+ //集団を発見したので、ここに含める
223+ grp.Value.Add(pack);
224+ //元位置よりの距離を計算しておく
225+ pack.Diff = latlontool.calcS(fpack.Position, nlatlng);
226+ bFind = true;
227+ break;
228+ }
229+ }
230+ if (bFind == true)
231+ break;
232+ }
233+
234+ //みつからない場合、新集団とする
235+ if (bFind == false)
236+ {
237+ var grp = new List<ThreshPack>();
238+ grp.Add(pack);
239+ //元位置よりの距離を計算しておく
240+ pack.Diff = latlontool.calcS(pack.Position, nlatlng);
241+ mothertable[mothertable.Count] = grp;
242+ }
243+ }
244+
245+ var mothermintable = new Dictionary<int, double>();
246+ //各グループ内で最も近い点を持っている集団の中で最も近い点を採用する
247+ foreach ( var grp in mothertable)
248+ mothermintable[grp.Key] = grp.Value.Min(ppp => ppp.Diff);
249+ var motherkey = mothermintable.Where(dr => dr.Value == mothermintable.Min(dr2 => dr2.Value)).First().Key;
250+ var linestable = mothertable[motherkey];
251+
252+ //最近距離を採用する
253+ var finalpacklist = linestable.Where(lp => Math.Abs(lp.AngleDiff) == linestable.Min(lpp => Math.Abs(lpp.AngleDiff))).ToArray();
254+ var next = finalpacklist[finalpacklist.Length / 2];
255+
256+ m_walking++;
257+ walkinglist.Add(next.Position);
258+ //次の位置へ更新
259+ nlatlng = next.Position;
260+ nvector = next.Vector;
261+
262+ //終点チェック
263+ if (latlontool.calcS(nlatlng, end) < 10.0f)
264+ return walkinglist;
265+
266+ if (m_walking >= MaxWalking)
267+ return walkinglist;
268+ }
269+ }
270+
271+ /// <summary>
272+ /// 解析
273+ /// </summary>
274+ /// <param name="start">始点</param>
275+ /// <param name="end">終点</param>
276+ public List<latlontool.latlng> Walk3(latlontool.latlng start, PointF vector, latlontool.latlng end)
277+ {
278+ var walkinglist = new List<latlontool.latlng>();
279+
280+ m_walking = 0;
281+
282+ var nvector = vector;
283+ var nlatlng = start;
284+
285+ while (true)
286+ {
287+ var findlist = new List<ThreshPack>();
288+
289+ for (float fDistance = 2.0f; fDistance <= 50.0f; fDistance += 2.0f)
290+ {
291+ (bool Result, latlontool.latlng next) result;
292+
293+ double dDeltaR = 1 / fDistance * 2.0;
294+
295+ //とりあえず、前方向をサーチ
296+ for (double iD = -40.0; iD <= 40.0; iD += dDeltaR)
297+ {
298+ var vdo = latlontool.ToRadian(latlontool.ToAngle(Math.Atan2(nvector.Y, nvector.X)) + iD);
299+ var testvector = new PointF((float)Math.Cos(vdo), (float)Math.Sin(vdo));
300+ result = Move(nlatlng, testvector, fDistance);
301+ if (result.Result == true)
302+ {
303+ //発見
304+ findlist.Add(new ThreshPack() { Position = result.next, Vector = testvector, AngleDiff = iD, Distance = fDistance });
305+ }
306+ }
307+ }
308+
309+ if (findlist.Count <= 0)
310+ //見つからない
311+ return walkinglist;
312+
313+ //ライン候補
314+ findlist.Sort((x, y) =>
315+ {
201316 var bSortResult = x.AngleDiff.CompareTo(y.AngleDiff);
202317 if (bSortResult != 0)
203318 return bSortResult;
@@ -209,9 +324,9 @@
209324 var linestable = new List<ThreshPack>();
210325 var lines = new List<ThreshPack>();
211326 ThreshPack iLastPoint = null;
212- foreach ( var pack in findlist)
327+ foreach (var pack in findlist)
213328 {
214- if(iLastPoint == null )
329+ if (iLastPoint == null)
215330 {
216331 iLastPoint = pack;
217332 lines.Add(pack);
@@ -219,12 +334,12 @@
219334 else
220335 {
221336 var dDiffDistance = latlontool.calcS(iLastPoint.Position, pack.Position);
222- if (dDiffDistance > 1.0f )
337+ if (dDiffDistance > 1.0f)
223338 {
224339 //連続性が無いので、別ライン候補
225340 var pppp = (lines.Where(lp => Math.Abs(lp.AngleDiff) == lines.Min(lpp => Math.Abs(lpp.AngleDiff)))).ToArray();
226341 //貯めたライン達の真ん中のやつを候補とする。
227- linestable.Add(pppp[pppp.Length/2]);
342+ linestable.Add(pppp[pppp.Length / 2]);
228343
229344 lines.Clear();
230345 iLastPoint = null;
@@ -236,7 +351,7 @@
236351 }
237352 }
238353 }
239- if(lines.Count>0)
354+ if (lines.Count > 0)
240355 {
241356 var pppp = (lines.Where(lp => Math.Abs(lp.AngleDiff) == lines.Min(lpp => Math.Abs(lpp.AngleDiff)))).ToArray();
242357 linestable.Add(pppp[pppp.Length / 2]);
@@ -260,6 +375,7 @@
260375 }
261376 }
262377
378+
263379 /// <summary>
264380 /// キャッシュ
265381 /// </summary>
--- WhereTrainBuild/MapForm.cs (revision 48)
+++ WhereTrainBuild/MapForm.cs (revision 49)
@@ -1037,10 +1037,18 @@
10371037 ToolStripMenuItem linewalker2item = new ToolStripMenuItem("線路解析2");
10381038 linewalker2item.Click += (sender, args) =>
10391039 {
1040- WalkLine(crossresult, true );
1040+ WalkLine(crossresult, 1 );
10411041 };
10421042 popupmenu.Items.Add(linewalker2item);
10431043
1044+ //線路解析3
1045+ ToolStripMenuItem linewalker3item = new ToolStripMenuItem("線路解析3");
1046+ linewalker3item.Click += (sender, args) =>
1047+ {
1048+ WalkLine(crossresult, 2);
1049+ };
1050+ popupmenu.Items.Add(linewalker3item);
1051+
10441052 popupmenu.Show(Cursor.Position);
10451053 }
10461054
@@ -1048,7 +1056,7 @@
10481056 /// ライン解析
10491057 /// </summary>
10501058 /// <param name="crossresult"></param>
1051- protected void WalkLine(OnCrossLineResult crossresult, bool bSecondFunc = false )
1059+ protected void WalkLine(OnCrossLineResult crossresult, int iFunc = 0 )
10521060 {
10531061 latlontool.latlng prevposition = null, targetposition = null, startposition = null, endposition = null;
10541062 int iInterIdx = 0;
@@ -1113,11 +1121,21 @@
11131121 var walker = new LineWalker(MapViewCnt.TileManager);
11141122
11151123 List<latlontool.latlng> walklist = null;
1116- if( bSecondFunc == true )
1117- walklist = walker.Walk2(startposition, vector, endposition);
1118- else
1119- walklist = walker.Walk(startposition, vector, endposition);
1124+ switch(iFunc)
1125+ {
1126+ case 1:
1127+ walklist = walker.Walk2(startposition, vector, endposition);
1128+ break;
11201129
1130+ case 2:
1131+ walklist = walker.Walk3(startposition, vector, endposition);
1132+ break;
1133+
1134+ default:
1135+ walklist = walker.Walk(startposition, vector, endposition);
1136+ break;
1137+ }
1138+
11211139 //最適化
11221140 walklist = walker.Optimisation(walklist);
11231141
Show on old repository browser