Chen_Han.cpp
Go to the documentation of this file.
1 // PreviousCH.cpp: implementation of the CChen_Han class.
2 //
4 #include "Chen_Han.h"
5 
6 // dsy
7 #ifndef max
8 #define max(a,b) (((a) > (b)) ? (a) : (b))
9 #endif
10 #ifndef min
11 #define min(a,b) (((a) < (b)) ? (a) : (b))
12 #endif
13 // dsy
14 
16 // Construction/Destruction
18 
19 CChen_Han::CChen_Han(const CRichModel& model, int source) : CExactDGPMethod(model, source)
20 {
21  m_nameOfAlgorithm = "CH";
22 }
23 CChen_Han::CChen_Han(const CRichModel& model, int source, int destination) : CExactDGPMethod(model, source, destination)
24 {
25  m_nameOfAlgorithm = "CH";
26 }
27 CChen_Han::CChen_Han(const CRichModel& model, int source, double R) : CExactDGPMethod(model, source, R)
28 {
29  m_nameOfAlgorithm = "CH";
30 }
31 
32 CChen_Han::CChen_Han(const CRichModel& model, const map<int, double>& sources) : CExactDGPMethod(model, sources)
33 {
34  m_nameOfAlgorithm = "CH";
35 }
36 
37 CChen_Han::CChen_Han(const CRichModel& model, const map<int, double>& sources, const set<int> &destinations) : CExactDGPMethod(model, sources, destinations)
38 {
39  m_nameOfAlgorithm = "CH";
40 }
41 
42 CChen_Han::CChen_Han(const CRichModel& model, const set<int>& sources) : CExactDGPMethod(model, sources)
43 {
44  m_nameOfAlgorithm = "CH";
45 }
46 
47 CChen_Han::CChen_Han(const CRichModel& model, const set<int>& sources, double R) : CExactDGPMethod(model, sources, R)
48 {
49  m_nameOfAlgorithm = "CH";
50 }
51 
52 CChen_Han::CChen_Han(const CRichModel& model, const set<int>& sources, const set<int>& destinations) : CExactDGPMethod(model, sources, destinations)
53 {
54  m_nameOfAlgorithm = "CH";
55 }
56 
57 
59 {
65 }
66 
68 {
69  m_QueueForWindows = queue<QuoteWindow>();
70  m_QueueForPseudoSources = queue<QuoteInfoAtVertex>();
71 }
72 
74 {
76  bool fFromQueueOfPseudoSources = UpdateTreeDepthBackWithChoice();
78  {
85  if (fFromQueueOfPseudoSources) //pseudosource
86  {
87  int indexOfVert = m_QueueForPseudoSources.front().indexOfVert;
89  ComputeChildrenOfPseudoSource(indexOfVert);
90  }
91  else
92  {
93  QuoteWindow quoteW = m_QueueForWindows.front();
94  m_QueueForWindows.pop();
95  ComputeChildrenOfWindow(quoteW);
96  delete quoteW.pWindow;
97  }
98  fFromQueueOfPseudoSources = UpdateTreeDepthBackWithChoice();
99  }
100 }
101 
103 {
104  m_memory = ((double)model.GetNumOfVerts() * sizeof (InfoAtVertex)
105  + (double)model.GetNumOfEdges() * sizeof (Window)
106  + (double)m_maxLenOfQueue * sizeof(Window *)) / 1024 / 1024;
107  for (int i = 0; i < m_scalarField.size(); ++i)
108  {
109  m_scalarField[i] = m_InfoAtVertices[i].disUptodate;
110  }
112 }
113 
115 {
116  if (model.IsStronglyConvexVert(quoteOfPseudoSource.indexOfVert))
117  return;
118  m_QueueForPseudoSources.push(quoteOfPseudoSource);
119 }
120 
122 {
123  m_QueueForWindows.push(quoteW);
125 }
126 
128 {
129  while (!m_QueueForPseudoSources.empty()
130  && m_QueueForPseudoSources.front().birthTime != m_InfoAtVertices[m_QueueForPseudoSources.front().indexOfVert].birthTimeForCheckingValidity)
132 
133  while (!m_QueueForWindows.empty())
134  {
135  const QuoteWindow& quoteW = m_QueueForWindows.front();
137  {
138  if (quoteW.pWindow->birthTimeOfParent !=
139  m_InfoAtVertices[quoteW.pWindow->indexOfBrachParent].birthTimeForCheckingValidity)
140  {
141  delete quoteW.pWindow;
142  m_QueueForWindows.pop();
143  }
144  else
145  break;
146  }
147  else
148  {
149  if (quoteW.pWindow->birthTimeOfParent ==
150  m_InfoAtAngles[quoteW.pWindow->indexOfBrachParent].birthTime)
151  break;
152  else if (quoteW.pWindow->fIsOnLeftSubtree ==
153  (quoteW.pWindow->entryPropOfParent < m_InfoAtAngles[quoteW.pWindow->indexOfBrachParent].entryProp))
154  break;
155  else
156  {
157  delete quoteW.pWindow;
158  m_QueueForWindows.pop();
159  }
160  }
161  }
162 
163  bool fFromQueueOfPseudoSources(false);
164  if (m_QueueForWindows.empty())
165  {
166  if (!m_QueueForPseudoSources.empty())
167  {
168  const InfoAtVertex& infoOfHeadElemOfPseudoSources = m_InfoAtVertices[m_QueueForPseudoSources.front().indexOfVert];
170  infoOfHeadElemOfPseudoSources.levelOnSequenceTree);
171  fFromQueueOfPseudoSources = true;
172  }
173  }
174  else
175  {
176  if (m_QueueForPseudoSources.empty())
177  {
178  const Window& infoOfHeadElemOfWindows = *m_QueueForWindows.front().pWindow;
180  infoOfHeadElemOfWindows.levelOnSequenceTree);
181  fFromQueueOfPseudoSources = false;
182  }
183  else
184  {
185  const InfoAtVertex& infoOfHeadElemOfPseudoSources = m_InfoAtVertices[m_QueueForPseudoSources.front().indexOfVert];
186  const Window& infoOfHeadElemOfWindows = *m_QueueForWindows.front().pWindow;
187  if (infoOfHeadElemOfPseudoSources.levelOnSequenceTree <=
188  infoOfHeadElemOfWindows.levelOnSequenceTree)
189  {
191  infoOfHeadElemOfPseudoSources.levelOnSequenceTree);
192  fFromQueueOfPseudoSources = true;
193  }
194  else
195  {
197  infoOfHeadElemOfWindows.levelOnSequenceTree);
198  fFromQueueOfPseudoSources = false;
199  }
200  }
201  }
202  return fFromQueueOfPseudoSources;
203 }
204 
206 {
207  cout << "Experimental results are as follows:\n";
208  cout << "Algorithm: " << m_nameOfAlgorithm << endl;
209  cout << "Memory = " << m_memory << " Mega-bytes.\n";
210  cout << "Timing = " << m_nTotalMilliSeconds << " ms.\n";
211  cout << "MaxDepth = " << m_depthOfResultingTree << " levels.\n";
212  cout << "MaxLenOfQue = " << m_maxLenOfQueue << " elements.\n";
213  cout << "TotalWindowNum = " << m_nCountOfWindows << endl;
214 }
215 
216 
218 {
219  return w.proportions[1] - w.proportions[0] < 1e-5;
220  //|| w.proportions[1] - w.proportions[0] >= 1 + LengthTolerance;
221 }
222 
223 void CChen_Han::ComputeChildrenOfSource(int indexOfSourceVert, double dis)
224 {
225  //if (!IsReachable(indexOfSourceVert))
226  // return;
227  //m_InfoAtVertices[indexOfSourceVert].fParentIsPseudoSource;
228  ++m_InfoAtVertices[indexOfSourceVert].birthTimeForCheckingValidity;
229  //m_InfoAtVertices[indexOfSourceVert].indexOfParent;
230  //m_InfoAtVertices[indexOfSourceVert].indexOfRootVertOfParent;
231  m_InfoAtVertices[indexOfSourceVert].levelOnSequenceTree = 0;
232  m_InfoAtVertices[indexOfSourceVert].indexOfAncestor = indexOfSourceVert;
233  m_InfoAtVertices[indexOfSourceVert].disUptodate = dis;
234  //m_InfoAtVertices[indexOfSourceVert].entryProp;
235 
236  int degree = (int)model.Neigh(indexOfSourceVert).size();
237  for (int i = 0; i < degree; ++i) // vertex-nodes
238  {
239  FillVertChildOfPseudoSource(indexOfSourceVert, i);
240  }
241 
242  for (int i = 0; i < degree; ++i)
243  {
244  CreateIntervalChildOfPseudoSource(indexOfSourceVert, i);
245  }
246 }
247 
249 {
250  for (map<int, double>::const_iterator it = m_sources.begin();
251  it != m_sources.end(); ++it)
252  {
253  assert(it->first < model.GetNumOfVerts());
254  //if (IsReachable(it->first))
255  ComputeChildrenOfSource(it->first, it->second);
256  }
257 }
258 
260 {
261  int degree = (int)model.Neigh(indexOfParentVertex).size();
262  const vector<pair<int, double> >& neighs = model.Neigh(indexOfParentVertex);
263  int indexOfParentOfParent = m_InfoAtVertices[indexOfParentVertex].indexOfDirectParent;
264  int subIndex = model.GetSubindexToVert(indexOfParentVertex, indexOfParentOfParent);
265  double angleSumPlus(0);
266  int indexPlus;
267  for (indexPlus = subIndex; indexPlus != (subIndex - 1 + degree) % degree; indexPlus = (indexPlus + 1) % degree)
268  {
269  angleSumPlus += neighs[indexPlus].second;
270  if (angleSumPlus > M_PI - 3 * AngleTolerance)
271  break;
272  }
273  double angleSumMinus = 0;
274  int indexMinus;
275  for (indexMinus = (subIndex - 1 + degree) % degree;
276  indexMinus == (subIndex - 1 + degree) % degree || indexMinus != (indexPlus - 1 + degree) % degree;
277  indexMinus = (indexMinus - 1 + degree) % degree)
278  {
279  angleSumMinus += neighs[indexMinus].second;
280  if (angleSumMinus > M_PI - 3 * AngleTolerance)
281  break;
282  }
283  if (indexMinus == (indexPlus - 1 + degree) % degree)
284  return;
285  //vertices;
286  for (int i = 0; i < degree; ++i)
287  //for (int i = (indexPlus + 1) % degree; i != (indexMinus + 1) % degree; i = (i + 1) % degree)
288  {
289  FillVertChildOfPseudoSource(indexOfParentVertex, i);
290  }
291 
292  //windows
293  double propPlus = 0;
294  double propMinus = 1;
295 #if 1
296  double devirationAngle = 20. * M_PI / 180.0;
297  double anglePlus = model.Neigh(indexOfParentVertex)[indexPlus].second - (angleSumPlus - M_PI);
298 
299  if (model.Edge(model.Neigh(indexOfParentVertex)[indexPlus].first).indexOfOppositeVert != -1)
300  {
301  if (model.Neigh(indexOfParentVertex)[indexPlus].second
302  < 2 * devirationAngle)
303  {
304  propPlus = 0;
305  }
306  else if (angleSumPlus - M_PI < devirationAngle
307  || abs(anglePlus - model.Neigh(indexOfParentVertex)[indexPlus].second)
308  < devirationAngle
309  || model.Neigh(indexOfParentVertex)[indexPlus].second
310  > M_PI - devirationAngle)
311  {
312  propPlus = (model.Neigh(indexOfParentVertex)[indexPlus].second - (angleSumPlus - M_PI))
313  / model.Neigh(indexOfParentVertex)[indexPlus].second
314  - devirationAngle / model.Neigh(indexOfParentVertex)[indexPlus].second;
315  //if (propPlus >= 1)
316  //{
317  // cerr << "propPlus " << __LINE__ << ": " << propPlus << endl;
318  //}
319  }
320  else
321  {
322  double angleTmp =
323  model.Edge(model.Edge(model.Edge(model.Neigh(indexOfParentVertex)[indexPlus].first).indexOfLeftEdge).indexOfReverseEdge).angleOpposite;
324  propPlus = sin(anglePlus) / sin(anglePlus + angleTmp) * model.Edge(model.Neigh(indexOfParentVertex)[indexPlus].first).length / model.Edge(model.Edge(model.Neigh(indexOfParentVertex)[indexPlus].first).indexOfRightEdge).length
325  - devirationAngle / model.Neigh(indexOfParentVertex)[indexPlus].second;
326  //if (propPlus >= 1)
327  //{
328  // cerr << "propPlus " << __LINE__ << ": " << propPlus << endl;
329  //}
330  }
331  propPlus = max(0, propPlus);
332  propPlus = min(1, propPlus);
333  }
334 
335  double angleMinus = angleSumMinus - M_PI;
336  if (model.Edge(model.Neigh(indexOfParentVertex)[indexMinus].first).indexOfOppositeVert != -1)
337  {
338  if (model.Neigh(indexOfParentVertex)[indexMinus].second
339  < 2 * devirationAngle)
340  {
341  propMinus = 1;
342  }
343  else if (angleSumMinus - M_PI < devirationAngle
344  || abs(angleSumMinus - M_PI - model.Neigh(indexOfParentVertex)[indexMinus].second)
345  < devirationAngle
346  || model.Neigh(indexOfParentVertex)[indexMinus].second
347  > M_PI - devirationAngle)
348  {
349  propMinus = (angleSumMinus - M_PI) / model.Neigh(indexOfParentVertex)[indexMinus].second
350  + devirationAngle / model.Neigh(indexOfParentVertex)[indexMinus].second;
351  //if (propMinus <= 0)
352  //{
353  // cerr << "propMinus " << __LINE__ << ": " << propMinus << endl;
354  //}
355  }
356  else
357  {
358  double angleTmp =
359  model.Edge(model.Edge(model.Edge(model.Neigh(indexOfParentVertex)[indexMinus].first).indexOfLeftEdge).indexOfReverseEdge).angleOpposite;
360  propMinus = sin(angleMinus) / sin(angleMinus + angleTmp) * model.Edge(model.Neigh(indexOfParentVertex)[indexMinus].first).length / model.Edge(model.Edge(model.Neigh(indexOfParentVertex)[indexMinus].first).indexOfRightEdge).length
361  + devirationAngle / model.Neigh(indexOfParentVertex)[indexMinus].second;
362  //if (propMinus <= 0)
363  //{
364  // cerr << "propMinus " << __LINE__ << ": " << propMinus << endl;
365  //}
366  }
367  propMinus = max(0, propMinus);
368  propMinus = min(1, propMinus);
369  }
370 #endif
371 
372  for (int i = indexPlus; i != (indexMinus + 1) % degree; i = (i + 1) % degree)
373  {
374  if (model.Edge(model.Neigh(indexOfParentVertex)[i].first).indexOfOppositeVert == -1)
375  continue;
376  double propL = 0;
377  double propR = 1;
378  if (indexPlus == i)
379  {
380  propR = 1 - propPlus;//
381  }
382  if (indexMinus == i)
383  {
384  propL = 1 - propMinus;//
385  }
386 
387  CreateIntervalChildOfPseudoSource(indexOfParentVertex, i, propL, propR);
388  }
389 }
390 
392 {
393  int degree = (int)model.Neigh(indexOfParentVertex).size();
394  const vector<pair<int, double> >& neighs = model.Neigh(indexOfParentVertex);
395  int indexOfParentOfParent = m_InfoAtVertices[indexOfParentVertex].indexOfDirectParent;
396  int leftVert = model.Edge(indexOfParentOfParent).indexOfLeftVert;
397  int rightVert = model.Edge(indexOfParentOfParent).indexOfRightVert;
398  int subIndexLeft = model.GetSubindexToVert(indexOfParentVertex, leftVert);
399  int subIndexRight = (subIndexLeft + 1) % degree;
400  double x1 = m_InfoAtVertices[indexOfParentVertex].entryProp * model.Edge(indexOfParentOfParent).length;
401  double y1 = 0;
402  double x2 = model.Edge(indexOfParentOfParent).length;
403  double y2 = 0;
404  x1 -= model.Edge(indexOfParentOfParent).coordOfOppositeVert.first;
405  y1 -= model.Edge(indexOfParentOfParent).coordOfOppositeVert.second;
406  x2 -= model.Edge(indexOfParentOfParent).coordOfOppositeVert.first;
407  y2 -= model.Edge(indexOfParentOfParent).coordOfOppositeVert.second;
408 
409  double anglePlus = acos((x1 * x2 + y1 * y2) / sqrt((x1 * x1 + y1 * y1) * (x2 * x2 + y2 * y2)));
410  double angleSumR(anglePlus);
411  int indexPlus;
412  for (indexPlus = subIndexRight; indexPlus != subIndexLeft; indexPlus = (indexPlus + 1) % degree)
413  {
414  angleSumR += neighs[indexPlus].second;
415  if (angleSumR > M_PI - 4 * AngleTolerance)
416  break;
417  }
418  double angleSumL = neighs[subIndexLeft].second - anglePlus;
419  int indexMinus;
420  for (indexMinus = (subIndexLeft - 1 + degree) % degree; indexMinus != (indexPlus - 1 + degree) % degree; indexMinus = (indexMinus - 1 + degree) % degree)
421  {
422  angleSumL += neighs[indexMinus].second;
423  if (angleSumL > M_PI - 4 * AngleTolerance)
424  break;
425  }
426  if (indexMinus == (indexPlus - 1 + degree) % degree)
427  return;
428  for (int i = 0; i < degree; ++i)//modified on 2013-10-18
429  //for (int i = (indexPlus + 1) % degree; i != (indexMinus + 1) % degree; i = (i + 1) % degree)
430  {
431  FillVertChildOfPseudoSource(indexOfParentVertex, i);
432  }
433  //windows
434  double propMinus = 1;//
435  double propPlus = 0;//
436 
437 #if 1
438  double devirationAngle = 20. * M_PI / 180.;
439  int minusEdge = model.Neigh(indexOfParentVertex)[indexMinus].first;
440  if (model.Edge(minusEdge).indexOfOppositeVert != -1)
441  {
442  double angleRemaining = angleSumL - M_PI;
443  if (model.Neigh(indexOfParentVertex)[indexMinus].second
444  < 2 * devirationAngle)
445  {
446  propMinus = 1;
447  }
448  else if (angleSumL - M_PI < devirationAngle
449  || abs(angleRemaining - model.Neigh(indexOfParentVertex)[indexMinus].second)
450  < devirationAngle
451  || model.Neigh(indexOfParentVertex)[indexMinus].second
452  > M_PI - devirationAngle)
453  {
454  propMinus = angleRemaining / model.Neigh(indexOfParentVertex)[indexMinus].second
455  + devirationAngle / model.Neigh(indexOfParentVertex)[indexMinus].second;
456  //if (propMinus <= 0)
457  //{
458  // cerr << "propMinus " << __LINE__ << ": " << propMinus << "\n";
459  // assert(0);
460  //}
461  }
462  else
463  {
464  propMinus = sin(angleRemaining) * model.Edge(minusEdge).length
465  / sin(angleRemaining +
466  model.Edge(model.Edge(model.Edge(minusEdge).indexOfLeftEdge).indexOfReverseEdge).angleOpposite)
467  / model.Edge(model.Edge(minusEdge).indexOfRightEdge).length
468  + devirationAngle / model.Neigh(indexOfParentVertex)[indexMinus].second;
469  //if (propMinus <= 0)
470  //{
471  // cerr << "propMinus " << __LINE__ << ": " << propMinus << "\n";
472  // assert(0);
473  //}
474  }
475 
476  propMinus = max(0, propMinus);
477  propMinus = min(1, propMinus);
478  }
479 
480  int rightEdge = model.Neigh(indexOfParentVertex)[indexPlus].first;
481  if (model.Edge(rightEdge).indexOfOppositeVert != -1)
482  {
483  double angleRemaining = model.Neigh(indexOfParentVertex)[indexPlus].second - (angleSumR - M_PI);
484  if (model.Neigh(indexOfParentVertex)[indexPlus].second
485  < 2 * devirationAngle)
486  {
487  propPlus = 0;
488  }
489  else if (angleSumR - M_PI < devirationAngle
490  || abs(angleRemaining) < devirationAngle
491  || model.Neigh(indexOfParentVertex)[indexPlus].second
492  > M_PI - devirationAngle)
493  {
494  propPlus = angleRemaining / model.Neigh(indexOfParentVertex)[indexPlus].second
495  - devirationAngle / model.Neigh(indexOfParentVertex)[indexPlus].second;
496  //if (propPlus >= 1)
497  //{
498  // cerr << "propPlus " << __LINE__ << ": " << propPlus << "\n";
499  // assert(0);
500  //}
501  }
502  else
503  {
504  propPlus = sin(angleRemaining)
505  * model.Edge(rightEdge).length
506  / sin(angleRemaining + model.Edge(model.Edge(model.Edge(rightEdge).indexOfLeftEdge).indexOfReverseEdge).angleOpposite)
507  / model.Edge(model.Edge(rightEdge).indexOfRightEdge).length
508  - devirationAngle / model.Neigh(indexOfParentVertex)[indexPlus].second;
509  //if (propPlus >= 1)
510  //{
511  // cerr << "propPlus " << __LINE__ << ":= " << propPlus << "\n";
512  // assert(0);
513  //}
514  }
515 
516  propPlus = max(0, propPlus);
517  propPlus = min(1, propPlus);
518  }
519 
520 #endif
521  for (int i = indexPlus; i != (indexMinus + 1) % degree; i = (i + 1) % degree)
522  {
523  if (model.Edge(model.Neigh(indexOfParentVertex)[i].first).indexOfOppositeVert == -1)
524  continue;
525  double propL = 0;
526  double propR = 1;
527 
528  if (indexPlus == i)
529  {
530  propR = 1 - propPlus;//
531  }
532  if (indexMinus == i)
533  {
534  propL = 1 - propMinus;//
535  }
536  CreateIntervalChildOfPseudoSource(indexOfParentVertex, i, propL, propR);
537  }
538 }
539 
541 {
542  const Window& w = *quoteParentWindow.pWindow;
543  const CRichModel::CEdge& edge = model.Edge(w.indexOfCurEdge);
545 
546  if (entryProp >= w.proportions[1]
547  || entryProp >= 1 - LengthTolerance)
548  {
550  return;
551  }
552 
553  if (entryProp <= w.proportions[0]
554  || entryProp <= LengthTolerance)
555  {
557  return;
558  }
560  int incidentVertex = edge.indexOfOppositeVert;
561  bool fLeftChildToCompute(false), fRightChildToCompute(false);
562  bool fWIsWinning(false);
563  double totalDis = w.disToRoot + disToAngle;
564 
565  if (m_InfoAtAngles[w.indexOfCurEdge].birthTime == -1)
566  {
567  fLeftChildToCompute = fRightChildToCompute = true;
568  fWIsWinning = true;
569  }
570  else
571  {
572  if (totalDis < m_InfoAtAngles[w.indexOfCurEdge].disUptodate
573  - 2 * LengthTolerance)
574  {
575  fLeftChildToCompute = fRightChildToCompute = true;
576  fWIsWinning = true;
577  }
578  else if (totalDis < m_InfoAtAngles[w.indexOfCurEdge].disUptodate
579  + 2 * LengthTolerance)
580  {
581  fLeftChildToCompute = fRightChildToCompute = true;
582  fWIsWinning = false;
583  }
584  else
585  {
586  fLeftChildToCompute = entryProp < m_InfoAtAngles[w.indexOfCurEdge].entryProp;
587  fRightChildToCompute = !fLeftChildToCompute;
588  fWIsWinning = false;
589  }
590 
591  }
592  if (!fWIsWinning)
593  {
594  if (fLeftChildToCompute)
595  {
597  }
598  if (fRightChildToCompute)
599  {
601  }
602  return;
603  }
604 
605  m_InfoAtAngles[w.indexOfCurEdge].disUptodate = totalDis;
606  m_InfoAtAngles[w.indexOfCurEdge].entryProp = entryProp;
607  ++m_InfoAtAngles[w.indexOfCurEdge].birthTime;
608 
611  if (//IsReachable(incidentVertex) &&
612  totalDis < m_InfoAtVertices[incidentVertex].disUptodate - LengthTolerance)
613  {
614  m_InfoAtVertices[incidentVertex].fParentIsPseudoSource = false;
615  ++m_InfoAtVertices[incidentVertex].birthTimeForCheckingValidity;
616  m_InfoAtVertices[incidentVertex].indexOfDirectParent = w.indexOfCurEdge;
617  m_InfoAtVertices[incidentVertex].indexOfRootVertOfDirectParent = w.indexOfRootVertex;
618  m_InfoAtVertices[incidentVertex].levelOnSequenceTree = w.levelOnSequenceTree + 1;
619  m_InfoAtVertices[incidentVertex].indexOfAncestor = w.indexOfAncestor;
620  m_InfoAtVertices[incidentVertex].disUptodate = totalDis;
621  m_InfoAtVertices[incidentVertex].entryProp = entryProp;
622 
623  //if (!model.IsStronglyConvexVert(incidentVertex))
624  AddIntoQueueOfPseudoSources(QuoteInfoAtVertex(m_InfoAtVertices[incidentVertex].birthTimeForCheckingValidity,
625  incidentVertex, totalDis));
626  }
627 }
628 
629 void CChen_Han::ComputeChildrenOfPseudoSource(int indexOfParentVertex)
630 {
631  if (m_InfoAtVertices[indexOfParentVertex].fParentIsPseudoSource)
633  else
634  ComputeChildrenOfPseudoSourceFromWindow(indexOfParentVertex);
635 }
636 
637 void CChen_Han::CreateIntervalChildOfPseudoSource(int source, int subIndexOfIncidentEdge, double propL/* = 0*/, double propR/* = 1*/)
638 {
639  int indexOfIncidentEdge = model.Neigh(source)[subIndexOfIncidentEdge].first;
640  if (model.IsExtremeEdge(indexOfIncidentEdge))
641  return;
642  const CRichModel::CEdge& edge = model.Edge(indexOfIncidentEdge);
643  int edgeIndex = edge.indexOfRightEdge;
644  if (model.IsExtremeEdge(edgeIndex))
645  return;
646  QuoteWindow quoteW;
647  quoteW.pWindow = new Window;
648  quoteW.pWindow->proportions[0] = propL;
649  quoteW.pWindow->proportions[1] = propR;
650  if (IsTooNarrowWindow(*quoteW.pWindow))
651  {
652  delete quoteW.pWindow;
653  return;
654  }
655  //quoteW.pWindow->fIsOnLeftSubtree;
656  quoteW.pWindow->fBrachParentIsPseudoSource = true;
657  //quoteW.pWindow->fDirectParentEdgeOnLeft;
658  quoteW.pWindow->fDirectParenIsPseudoSource = true;
659  quoteW.pWindow->birthTimeOfParent = m_InfoAtVertices[source].birthTimeForCheckingValidity;
660  quoteW.pWindow->indexOfBrachParent = source;
661  quoteW.pWindow->indexOfRootVertex = source;
662  quoteW.pWindow->indexOfCurEdge = edgeIndex;
663  quoteW.pWindow->levelOnSequenceTree = m_InfoAtVertices[source].levelOnSequenceTree + 1;
664  quoteW.pWindow->indexOfAncestor = m_InfoAtVertices[source].indexOfAncestor;
665  quoteW.pWindow->disToRoot = m_InfoAtVertices[source].disUptodate;
666  quoteW.pWindow->entryPropOfParent;
667  int reverseEdge = model.Edge(edgeIndex).indexOfReverseEdge;
669  model.Edge(reverseEdge).coordOfOppositeVert);
670  AddIntoQueueOfWindows(quoteW);
671 }
672 
673 void CChen_Han::FillVertChildOfPseudoSource(int source, int subIndexOfVert)
674 {
675  const CRichModel::CEdge& edge = model.Edge(model.Neigh(source)[subIndexOfVert].first);
676  int index = edge.indexOfRightVert;
677  //if (!IsReachable(index))
678  // return;
679  double dis = m_InfoAtVertices[source].disUptodate + edge.length;
680  if (dis >= m_InfoAtVertices[index].disUptodate - LengthTolerance)
681  return;
682  m_InfoAtVertices[index].fParentIsPseudoSource = true;
683  ++m_InfoAtVertices[index].birthTimeForCheckingValidity;
684  m_InfoAtVertices[index].indexOfDirectParent = source;
685  //m_InfoAtVertices[index].indexOfRootVertOfParent;
686  m_InfoAtVertices[index].levelOnSequenceTree = m_InfoAtVertices[source].levelOnSequenceTree + 1;
687  m_InfoAtVertices[index].indexOfAncestor = m_InfoAtVertices[source].indexOfAncestor;
688  m_InfoAtVertices[index].disUptodate = dis;
689  //m_InfoAtVertices[index].entryProp;
690  //if (!model.IsStronglyConvexVert(index))
691  AddIntoQueueOfPseudoSources(QuoteInfoAtVertex(m_InfoAtVertices[index].birthTimeForCheckingValidity,
692  index, dis));
693 }
694 
695 
697 {
699  return;
700  QuoteWindow quoteW;
701  quoteW.pWindow = new Window;
703  w.coordOfPseudoSource, w.proportions[0]) - 1e-4;
704  quoteW.pWindow->proportions[0] = max(0, quoteW.pWindow->proportions[0]);
706  w.coordOfPseudoSource, w.proportions[1]) + 1e-4;
707  quoteW.pWindow->proportions[1] = min(1, quoteW.pWindow->proportions[1]);
708  if (IsTooNarrowWindow(*quoteW.pWindow))
709  {
710  delete quoteW.pWindow;
711  return;
712  }
714  quoteW.pWindow->fDirectParenIsPseudoSource = false;
715  quoteW.pWindow->fDirectParentEdgeOnLeft = true;
717  quoteW.pWindow->disToRoot = w.disToRoot;
718 
720 
728 
729  AddIntoQueueOfWindows(quoteW);
730 }
731 
733 {
735  return;
736  QuoteWindow quoteW;
737  quoteW.pWindow = new Window;
739  w.coordOfPseudoSource, w.proportions[0]) - 1e-4;
740  quoteW.pWindow->proportions[0] = max(0, quoteW.pWindow->proportions[0]);
742  w.coordOfPseudoSource, w.proportions[1]) + 1e-4;
743  quoteW.pWindow->proportions[1] = min(1, quoteW.pWindow->proportions[1]);
744  if (IsTooNarrowWindow(*quoteW.pWindow))
745  {
746  delete quoteW.pWindow;
747  return;
748  }
750  quoteW.pWindow->fDirectParenIsPseudoSource = false;
751  quoteW.pWindow->fDirectParentEdgeOnLeft = false;
753  quoteW.pWindow->disToRoot = w.disToRoot;
755 
763 
764  AddIntoQueueOfWindows(quoteW);
765 }
766 
768 {
770  return;
771  QuoteWindow quoteW;
772  quoteW.pWindow = new Window;
774  w.coordOfPseudoSource, w.proportions[0]) - 1e-4;
775  quoteW.pWindow->proportions[0] = max(0, quoteW.pWindow->proportions[0]);
776  quoteW.pWindow->proportions[1] = 1;
777  if (IsTooNarrowWindow(*quoteW.pWindow))
778  {
779  delete quoteW.pWindow;
780  return;
781  }
783  quoteW.pWindow->fDirectParenIsPseudoSource = false;
784  quoteW.pWindow->fDirectParentEdgeOnLeft = true;
786  quoteW.pWindow->disToRoot = w.disToRoot;
788 
796 
797  AddIntoQueueOfWindows(quoteW);
798 }
799 
801 {
803  return;
804  QuoteWindow quoteW;
805  quoteW.pWindow = new Window;
806  quoteW.pWindow->proportions[0] = 0;
808  w.coordOfPseudoSource, w.proportions[1]) + 1e-4;
809  quoteW.pWindow->proportions[1] = min(1, quoteW.pWindow->proportions[1]);
810  if (IsTooNarrowWindow(*quoteW.pWindow))
811  {
812  delete quoteW.pWindow;
813  return;
814  }
816  quoteW.pWindow->fDirectParenIsPseudoSource = false;
817  quoteW.pWindow->fDirectParentEdgeOnLeft = false;
819  quoteW.pWindow->disToRoot = w.disToRoot;
821 
829 
830  AddIntoQueueOfWindows(quoteW);
831 }
832 
834 {
836  return;
837  QuoteWindow quoteW;
838  quoteW.pWindow = new Window;
840  w.coordOfPseudoSource, w.proportions[0]) - 1e-4;
841  quoteW.pWindow->proportions[0] = max(0, quoteW.pWindow->proportions[0]);
842  quoteW.pWindow->proportions[1] = 1;
843  if (IsTooNarrowWindow(*quoteW.pWindow))
844  {
845  delete quoteW.pWindow;
846  return;
847  }
848  quoteW.pWindow->fBrachParentIsPseudoSource = false;
849  quoteW.pWindow->fDirectParenIsPseudoSource = false;
850  quoteW.pWindow->fDirectParentEdgeOnLeft = true;
852  quoteW.pWindow->disToRoot = w.disToRoot;
854 
860  quoteW.pWindow->fIsOnLeftSubtree = true;
862 
863  AddIntoQueueOfWindows(quoteW);
864 }
865 
866 
868 {
870  return;
871  QuoteWindow quoteW;
872  quoteW.pWindow = new Window;
873  quoteW.pWindow->proportions[0] = 0;
875  w.coordOfPseudoSource, w.proportions[1]) + 1e-4;
876  quoteW.pWindow->proportions[1] = min(1, quoteW.pWindow->proportions[1]);
877  //quoteW.pWindow->proportions[1] = max(quoteW.pWindow->proportions[1], quoteW.pWindow->proportions[0]);
878  if (IsTooNarrowWindow(*quoteW.pWindow))
879  {
880  delete quoteW.pWindow;
881  return;
882  }
883  quoteW.pWindow->fBrachParentIsPseudoSource = false;
884  quoteW.pWindow->fDirectParenIsPseudoSource = false;
885  quoteW.pWindow->fDirectParentEdgeOnLeft = false;
887  quoteW.pWindow->disToRoot = w.disToRoot;
889 
890  quoteW.pWindow->fIsOnLeftSubtree = false;
897 
898  AddIntoQueueOfWindows(quoteW);
899 }
900 
901 //bool CChen_Han::IsReachable(int v) const
902 //{
903 // return true;
904 //}
virtual void AddIntoQueueOfWindows(QuoteWindow &quoteW)
Definition: Chen_Han.cpp:121
#define min(a, b)
Definition: Chen_Han.cpp:11
pair< double, double > coordOfPseudoSource
Definition: Chen_Han.h:44
void ComputeTheOnlyRightTrimmedChild(const Window &w)
Definition: Chen_Han.cpp:800
double entryPropOfParent
Definition: Chen_Han.h:43
double proportions[2]
Definition: Chen_Han.h:42
int indexOfBrachParent
Definition: Chen_Han.h:36
virtual void Initialize()
CChen_Han(const CRichModel &model, int source)
Definition: Chen_Han.cpp:19
#define max(a, b)
Definition: Chen_Han.cpp:8
int GetNumOfFaces() const
Definition: BaseModel.h:85
pair< double, double > GetNew2DCoordinatesByRotatingAroundLeftChildEdge(int edgeIndex, const pair< double, double > &input2DCoordinates) const
Definition: RichModel.cpp:706
vector< double > m_scalarField
map< int, double > m_sources
int levelOnSequenceTree
Definition: Chen_Han.h:39
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
__int64 m_nTotalMilliSeconds
double DistanceToOppositeAngle(int edgeIndex, const pair< double, double > &coord) const
Definition: RichModel.cpp:735
virtual void Dispose()
Definition: Chen_Han.cpp:67
virtual void Initialize()
Definition: Chen_Han.cpp:58
double ProportionOnLeftEdgeByImage(int edgeIndex, const pair< double, double > &coord, double proportion) const
Definition: RichModel.cpp:691
pair< double, double > coordOfOppositeVert
Definition: RichModel.h:30
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const AbsReturnType abs() const
const CEdge & Edge(int edgeIndex) const
Definition: RichModel.cpp:669
void FillVertChildOfPseudoSource(int source, int subIndexOfVert)
Definition: Chen_Han.cpp:673
bool fDirectParenIsPseudoSource
Definition: Chen_Han.h:34
double ProportionOnRightEdgeByImage(int edgeIndex, const pair< double, double > &coord, double proportion) const
Definition: RichModel.cpp:698
queue< QuoteInfoAtVertex > m_QueueForPseudoSources
Definition: Chen_Han.h:81
double disToRoot
Definition: Chen_Han.h:41
virtual void CollectExperimentalResults()=0
int GetSubindexToVert(int root, int neigh) const
Definition: RichModel.cpp:725
void ComputeRightTrimmedChildWithParent(const Window &w)
Definition: Chen_Han.cpp:867
bool fBrachParentIsPseudoSource
Definition: Chen_Han.h:32
void ComputeTheOnlyLeftChild(const Window &w)
Definition: Chen_Han.cpp:696
pair< double, double > GetNew2DCoordinatesByRotatingAroundRightChildEdge(int edgeIndex, const pair< double, double > &input2DCoordinates) const
Definition: RichModel.cpp:712
queue< QuoteWindow > m_QueueForWindows
Definition: Chen_Han.h:80
bool fIsOnLeftSubtree
Definition: Chen_Han.h:31
int indexOfReverseEdge
Definition: RichModel.h:26
virtual void CollectExperimentalResults()
Definition: Chen_Han.cpp:102
char birthTimeOfParent
Definition: Chen_Han.h:35
double ProportionOnEdgeByImage(int edgeIndex, const pair< double, double > &coord) const
Definition: RichModel.cpp:679
bool fDirectParentEdgeOnLeft
Definition: Chen_Han.h:33
void ComputeTheOnlyRightChild(const Window &w)
Definition: Chen_Han.cpp:732
void ComputeChildrenOfPseudoSourceFromPseudoSource(int indexOfParentVertex)
Definition: Chen_Han.cpp:259
__int64 m_nCountOfWindows
Definition: Chen_Han.h:85
void ComputeChildrenOfPseudoSourceFromWindow(int indexOfParentVertex)
Definition: Chen_Han.cpp:391
bool IsExtremeEdge(int edgeIndex) const
Definition: RichModel.cpp:659
void ComputeTheOnlyLeftTrimmedChild(const Window &w)
Definition: Chen_Han.cpp:767
const vector< pair< int, double > > & Neigh(int root) const
Definition: RichModel.cpp:674
EIGEN_DEVICE_FUNC const AcosReturnType acos() const
int GetNumOfVerts() const
Definition: BaseModel.h:80
bool IsStronglyConvexVert(int index) const
Definition: RichModel.cpp:649
void ComputeChildrenOfSource()
Definition: Chen_Han.cpp:248
void ComputeChildrenOfPseudoSource(int indexOfParentVertex)
Definition: Chen_Han.cpp:629
double angleOpposite
Definition: RichModel.h:29
const double LengthTolerance
Definition: Parameters.h:3
int indexOfOppositeVert
Definition: RichModel.h:23
pair< double, double > GetNew2DCoordinatesByReversingCurrentEdge(int edgeIndex, const pair< double, double > &input2DCoordinates) const
Definition: RichModel.cpp:720
__int64 m_nMaxLenOfPseudoSourceQueue
Definition: Chen_Han.h:84
void OutputExperimentalResults() const
Definition: Chen_Han.cpp:205
virtual bool UpdateTreeDepthBackWithChoice()
Definition: Chen_Han.cpp:127
void ComputeLeftTrimmedChildWithParent(const Window &w)
Definition: Chen_Han.cpp:833
virtual void AddIntoQueueOfPseudoSources(const QuoteInfoAtVertex &quoteOfPseudoSource)
Definition: Chen_Han.cpp:114
int indexOfRootVertex
Definition: Chen_Han.h:37
vector< InfoAtAngle > m_InfoAtAngles
Definition: Chen_Han.h:82
vector< InfoAtVertex > m_InfoAtVertices
const CRichModel & model
int GetNumOfEdges() const
Definition: RichModel.cpp:639
bool IsTooNarrowWindow(const Window &w) const
Definition: Chen_Han.cpp:217
void CreateIntervalChildOfPseudoSource(int source, int subIndexOfIncidentEdge, double propL=0, double propR=1)
Definition: Chen_Han.cpp:637
__int64 m_nMaxLenOfWindowQueue
Definition: Chen_Han.h:83
__int64 m_depthOfResultingTree
const double AngleTolerance
Definition: Parameters.h:2
void ComputeChildrenOfWindow(QuoteWindow &quoteParentWindow)
Definition: Chen_Han.cpp:540
virtual void Propagate()
Definition: Chen_Han.cpp:73
EIGEN_DEVICE_FUNC const SinReturnType sin() const


co_scan
Author(s):
autogenerated on Mon Feb 28 2022 23:00:39