Exemplo n.º 1
0
 public static Wall ToWall(dtoWall dtoWall)
 {
     return(new Wall()
     {
         Code = dtoWall.Code, CodeShop = dtoWall.CodeShop, X1 = dtoWall.P1.X, X2 = dtoWall.P2.X, Y1 = dtoWall.P1.Y, Y2 = dtoWall.P2.Y, Alias = Converts.ToAlias(dtoWall.Alias), Shop = null, CodeAlias = dtoWall.CodeAlias
     });
 }
Exemplo n.º 2
0
        public static List <KeyValuePair <KeyArea, Area> > Level3ConvertDictToList(Point pStart, Dictionary <KeyArea, Area> productArea, int [][] matShop, List <GetawayProcI_Result> getaways, List <Connection> connections, List <Wall> cashes, int CodeStartGetaway, List <Stand> stands, Shop shop)
        {
            //level 3: אחרי שקבצנו עלינו:
            //להוסיף אזור התחלה, להוסיף אינדקס של רשימה
            //ולחשב נקודת התחלה וסוף לכל אזור
            List <KeyValuePair <KeyArea, Area> > productAreaList = new List <KeyValuePair <KeyArea, Area> >();
            //ראשית כל אזור א' הוא אזור ההתחלה
            KeyArea SPkeyArea = new KeyArea()
            {
                Getaways = UtilitiesFunctions.StartPointManagment(pStart, matShop, getaways, CodeStartGetaway, stands, shop)
            };

            //אזור ההתחלה הוא ללא סטנדים /מוצרים כלל
            productAreaList.Add(new KeyValuePair <KeyArea, Area>(SPkeyArea, new Area()
            {
                P1 = pStart, P2 = pStart
            }));
            foreach (var pair in productArea)
            {
                //חישוב נקודות התחלה וסוף של אזור
                pair.Value.calculatePoints();
                //מעבירים לרשימה
                productAreaList.Add(pair);
            }
            //נקודות סיום
            foreach (var c in cashes)
            {
                KeyArea EPkeyArea2 = new KeyArea()
                {
                    Getaways = Converts.ToGetawayProcResult(connections.Where(x => x.TypeDest == Convert.ToInt32(eTypeConnection.wall) && x.CodeDest == c.Code).ToList().Select(x => x.Getaway).ToList(), getaways), Nearestes = null
                };
                dtoWall w = Converts.ToDtoWall(c);
                //אזור הסוף הוא ללא סטנדים /מוצרים כלל
                productAreaList.Add(new KeyValuePair <KeyArea, Area>(EPkeyArea2, new Area()
                {
                    P1 = w.P1, P2 = w.P2
                }));
            }
            return(productAreaList);
        }
Exemplo n.º 3
0
        public static Cell[,] Level4ComputeDistanceMatrix(List <KeyValuePair <KeyArea, Area> > productAreaList, Cell[,] baseDistanceMatrix, Point pStart, List <Wall> cashes)
        {
            int numCashes = cashes.Count();
            //שלב 4 מרחיבים את טבלת המרחקים הבסיסית של החנות
            //תוך התחשבות בכך ש'אזור' ההתחלה הוא ה'איזור' הראשון של טבלת החנות
            int LenBaseDistanceMatrix = baseDistanceMatrix.GetLength(1);
            int lenBig = LenBaseDistanceMatrix + productAreaList.Count();

            Cell[,] BigMatrix = new Cell[lenBig, lenBig];
            //מעתיקים את המטריצה של הדיקסטרה למטריצה הגדולה
            for (int i = 0; i < LenBaseDistanceMatrix; i++)
            {
                for (int j = 0; j < LenBaseDistanceMatrix; j++)
                {
                    BigMatrix[i, j] = baseDistanceMatrix[i, j];
                }
            }
            //עובר על האיזורים, א,ב,ג
            for (int i = LenBaseDistanceMatrix; i < lenBig; i++)
            {
                #region מילוי מטריצה מאיזור לשערים שלו
                //עובר על רשימת שערים של האיזור ומשבץ מרחק במטריצה
                foreach (GetawayProcI_Result getway in productAreaList[i - LenBaseDistanceMatrix].Key.Getaways)
                {
                    Cell c = new Cell();
                    //עבור האזור הראשון או האחרון המרחק מתמלא באופן ייחודי, מלשאר האזורים
                    //או אתה מנקודות הסיום       || או שאתה נקודת התחלה
                    if (i == LenBaseDistanceMatrix || i >= lenBig - numCashes && i < lenBig)
                    {
                        Point p;
                        if (i == LenBaseDistanceMatrix)
                        {
                            p = pStart;
                        }
                        else
                        {
                            dtoWall dtoWall = Converts.ToDtoWall(cashes[i - lenBig + numCashes]);
                            p = UtilitiesFunctions.MidPoint(dtoWall.P1, dtoWall.P2);
                        }
                        c.distance = UtilitiesFunctions.getDistanceFromSP(getway, p);
                    }
                    else //אם זה איזור רגיל ולא נקודת התחלה/סיום
                    {
                        c.distance = UtilitiesFunctions.MinDist(productAreaList[i - LenBaseDistanceMatrix].Value, Converts.ToDtoGetawayI(getway));
                    }

                    c.i      = i;
                    c.j      = Convert.ToInt32(getway.I);
                    c.Parent = Convert.ToInt32(getway.I); /*כי יש לי קשת אליו, כי זה גיטוואי שלי*/
                    BigMatrix[i, Convert.ToInt32(getway.I)] = c;
                    //לצד המקביל
                    BigMatrix[Convert.ToInt32(getway.I), i] = c;
                }
                #endregion
                #region מילוי מטריצה מהאיזור לכל השערים הזרים
                for (int j = 1; j < LenBaseDistanceMatrix; j++)
                {
                    //בודקת איך הכי קצר להגיע אליך מנקודות הגישה שלי
                    double min     = int.MaxValue;
                    Cell   minCell = new Cell();
                    minCell.i = i;
                    minCell.j = j;
                    //אם אתה נקודת גישה שלי תמשיך כי  שחישבתי קודם
                    if (BigMatrix[i, j] != null)
                    {
                        continue;
                    }
                    else //אם אתה לא אחד מנקודות הגישה שלי
                    {
                        foreach (GetawayProcI_Result getway in productAreaList[i - LenBaseDistanceMatrix].Key.Getaways)
                        {
                            //המרחק א' לבי+המרחק מבי לסי
                            if (BigMatrix[Convert.ToInt32(getway.I), j].distance + BigMatrix[i, Convert.ToInt32(getway.I)].distance < min)
                            {
                                min = BigMatrix[Convert.ToInt32(getway.I), j].distance + BigMatrix[i, Convert.ToInt32(getway.I)].distance;
                                minCell.distance = Convert.ToInt32(min);
                                minCell.Parent   = Convert.ToInt32(getway.I);
                            }
                        }
                    }
                    BigMatrix[i, j] = minCell;
                    BigMatrix[j, i] = minCell;//לצד המקביל
                }
                #endregion
                // תמלא את המרחק שלך לעצמך, 0
                Cell c2 = new Cell();
                c2.distance     = 0;
                c2.Parent       = 0;
                c2.i            = i;
                c2.j            = i;
                BigMatrix[i, i] = c2;
            }
            //בשלב זה המטריצה הגדולה מלאה בחציה. חושב המרחק מכל איזור לכל השערים. יש לחשב מרחק בין איזור לאיזור

            //להגיע מאיזור לאיזור, א,ב, ג,
            for (int i = LenBaseDistanceMatrix; i < lenBig; i++)
            {
                for (int j = LenBaseDistanceMatrix; j < lenBig; j++)
                {
                    if (i != j && BigMatrix[i, j] == null)
                    {
                        int  min = int.MaxValue;
                        Cell c   = new Cell();
                        c.i = i;
                        c.j = j;
                        // במקרה שאזורים אלו בעלי אותם השערים - זה אומר שאפשר לגשת ישירות ביניהם. נחשב אמצע קטע של איזור ראשון ואמצע קטע של איזור שני ופשוט נחשב מרחק
                        if (UtilitiesFunctions.IsSame(productAreaList[i - LenBaseDistanceMatrix].Key.Getaways, productAreaList[j - LenBaseDistanceMatrix].Key.Getaways))
                        {
                            //אם כל נקודת גישה של א היא גם נקודת גישה של ב
                            //א=i
                            //ב=j
                            c.Parent = i;
                            //להגיע מאיזור לאיזור כשהם צמודים ולא צריך לעבור דרך שער
                            //אם אחד מהם זה נקודת התחלה אין לו ערך, נחשב לחוד
                            I2Points a = productAreaList[i - LenBaseDistanceMatrix].Value;
                            I2Points b = productAreaList[j - LenBaseDistanceMatrix].Value;

                            c.distance      = UtilitiesFunctions.MinDist(a, b);
                            BigMatrix[i, j] = c;
                            Cell c2 = new Cell()
                            {
                                i = j, j = i, distance = c.distance, Parent = j
                            };
                            BigMatrix[j, i] = c2;
                        }
                        //אם האיזורים אינם בעלי אותם שערים, תעבור על השערים של המקור, של אי
                        else
                        {
                            foreach (GetawayProcI_Result getway in productAreaList[i - LenBaseDistanceMatrix].Key.Getaways)
                            {
                                if (BigMatrix[j, Convert.ToInt32(getway.I)].distance + BigMatrix[i, Convert.ToInt32(getway.I)].distance < min)
                                {
                                    c.Parent   = Convert.ToInt32(getway.I);
                                    min        = BigMatrix[j, Convert.ToInt32(getway.I)].distance + BigMatrix[i, Convert.ToInt32(getway.I)].distance;
                                    c.distance = min;
                                }
                            }
                            BigMatrix[i, j] = c;
                            //לצד המקביל
                            Cell c2 = new Cell()
                            {
                                i = j, j = i, distance = c.distance, Parent = c.Parent
                            };
                            BigMatrix[j, i] = c2;
                        }
                    }
                }
            }
            // printMat(BigMatrix); ;
            return(BigMatrix);
        }