Example #1
0
        private void SelectCircleOrCreateWay(int[] clickCoords)
        {
            MyCircle wasSelectedCircle = circles.FirstOrDefault(c => c.IsSelected);

            if (wasSelectedCircle != null)
            {
                wasSelectedCircle.IsSelected = false;

                if (!wasSelectedCircle.IsNearClick(clickCoords))
                {
                    foreach (MyCircle c in circles)
                    {
                        if (c.IsNearClick(clickCoords))
                        {
                            ways.Add(new Way(wasSelectedCircle, c));
                            break;
                        }
                    }
                }
            }
            else
            {
                foreach (MyCircle c in circles)
                {
                    if (c.IsNearClick(clickCoords))
                    {
                        c.IsSelected = true;
                        break;
                    }
                }
            }
        }
        public void Calc()
        {
            MyCircle startCircle = cs.FirstOrDefault(c => c.typ == CircleType.Start);

            endCircle = cs.FirstOrDefault(c => c.typ == CircleType.End);

            if (startCircle == null || endCircle == null)
            {
                return;
            }

            minWayLen = 1000000000.0;

            LinkedList <int> currentWayIndexses = new LinkedList <int>();

            GreedyAlg(startCircle, currentWayIndexses, 0.0);
        }
Example #3
0
        private void SetStartOrStopCircle(int[] clickCoords, CircleType typ)
        {
            MyCircle clickedCircle = circles.FirstOrDefault(c => c.IsNearClick(clickCoords));

            if (clickedCircle != null)
            {
                foreach (MyCircle c in circles)
                {
                    if (c.typ == typ)
                    {
                        c.typ = CircleType.Usual;
                    }
                }

                clickedCircle.typ = typ;
            }
        }
        private void GreedyAlg(MyCircle curCircle, LinkedList <int> currentWayIndexes, double currentWayLen) //, int[] checkedWaysIndexes,  int minWayCurrent, int minWayBest) {
        {
            for (int i = 0; i < ws.Count; i++)
            {
                if (WasCheckedWay(i, currentWayIndexes))
                {
                    continue;
                }

                for (int j = 0; j < ws[i].circlePair.Length; j++)
                {
                    if (curCircle == ws[i].circlePair[j])
                    {
                        int anotherCircleIndex = Math.Abs(j - 1);
                        currentWayLen += ws[i].WayLen;
                        currentWayIndexes.AddLast(i);

                        if (ws[i].circlePair[anotherCircleIndex].typ == CircleType.End)
                        {
                            if (currentWayLen < minWayLen)
                            {
                                minWayLen       = currentWayLen;
                                bestWayIndexses = new int[currentWayIndexes.Count];
                                currentWayIndexes.CopyTo(bestWayIndexses, 0);
                            }
                            else
                            {
                                currentWayIndexes.RemoveLast();
                            }
                        }
                        else
                        {
                            GreedyAlg(ws[i].circlePair[anotherCircleIndex], currentWayIndexes, currentWayLen);
                        }
                    }
                }
            }
        }
 public Way(MyCircle firstCircle, MyCircle secondCircle)
 {
     circlePair = new MyCircle[] { firstCircle, secondCircle };
     isBest     = false;
     WayLen     = GetWayLen();
 }