示例#1
0
        public List <CPoint> GetWay()
        {
            // בדיקה אם הדייקסטרה עובד
            CPoint        ps    = pointService.GetPointById(1);
            Points        psp   = mapper.Map <Points>(ps);
            Vertex        s     = new Vertex(psp);
            CPoint        pd    = pointService.GetPointById(5);
            Points        pdp   = mapper.Map <Points>(pd);
            Vertex        d     = new Vertex(pdp);
            List <Vertex> list  = algoritmService.FindWay(s, d, DateTime.Now.AddHours(1));
            List <CPoint> clist = new List <CPoint>()
            {
                new CPoint()
                {
                    PointId = list[0].GetIndex(), PointName = list[0].GetName()
                },
                new CPoint()
                {
                    PointId = list[1].GetIndex(), PointName = list[1].GetName()
                },
                new CPoint()
                {
                    PointId = list[2].GetIndex(), PointName = list[2].GetName()
                },
                new CPoint()
                {
                    PointId = list[3].GetIndex(), PointName = list[3].GetName()
                }
            };

            return(clist);
        }
示例#2
0
        public List <CPointInWay> GetPointsInWay(int idSource, int idTarget, DateTime flightTime)
        {
            //מציאת 2 קודקודי קצה של המסלול-מקור ויעד
            CPoint        s = pointService.GetPointById(idSource);
            CPoint        t = pointService.GetPointById(idTarget);
            List <CPoint> sourceAndTarget = new List <CPoint>()
            {
                s, t
            };
            List <Points> points = mapper.Map <List <Points> >(sourceAndTarget);

            vertexSource = new Vertex(points[0]); //יצירת צומת לקודקוד המקור
            vertexTarget = new Vertex(points[1]); //יצירת צומת לקודקוד היעד

            //שליחה לפונקצית האלגוריתם הראשי שמוצאת את הדרך הקצרה
            List <Vertex> pointsInWay = new List <Vertex>();

            pointsInWay = algoritmService.FindWay(vertexSource, vertexTarget, flightTime);

            //רשימה שבה יש את השמות של הנקודות המרכיבות את המסלול
            List <CPointInWay> lstPointsInWay = new List <CPointInWay>();

            //אם יש מספיק זמן ללכת את המסלול עד לזמן הטיסה
            if (pointsInWay.Count() > 0)
            {
                for (int i = 0; i < pointsInWay.Count() - 1; i++)
                {
                    int sId    = pointsInWay[i].GetIndex();
                    int tId    = pointsInWay[i + 1].GetIndex();
                    int length = edgeService.GetEdgeBySourceAndTarget(sId, tId).Weight;
                    if (i == 0)
                    {
                        lstPointsInWay.Add(new CPointInWay()
                        {
                            Name        = pointsInWay[0].GetName(),
                            Length      = 0,
                            WalkingTime = 0
                        });
                    }
                    TimeSpan time = TimeCalculation.CalculateTime(length);
                    lstPointsInWay.Add(new CPointInWay()
                    {
                        Name        = pointsInWay[i + 1].GetName(),
                        Length      = length,
                        WalkingTime = time.Hours * 3600 + time.Minutes * 60 + time.Seconds
                    });;
                }
            }
            //אחרת-התרעה למשתמש
            else
            {
                lstPointsInWay.Add(new CPointInWay()
                {
                    Name = "no time", Length = 0, WalkingTime = 0
                });
            }
            return(lstPointsInWay);
        }