Exemple #1
0
        public List <int> sortStands(I2Points g)
        {
            dtoStand   stand;
            List <int> arr = new List <int>
            {
                Capacity = ExtraStand.Count()
            };
            Point midOfG = UtilitiesFunctions.MidPoint(g.P1, g.P2);
            Point closerer;

            if (UtilitiesFunctions.CalculteDist(midOfG, P1) < UtilitiesFunctions.CalculteDist(midOfG, P2))
            {
                closerer = P1;
            }
            else
            {
                closerer = P2;
            }
            for (int i = 0; i < ExtraStand.Count(); i++)
            {
                /* מחשב מרחק לכל סטנד*/
                calculateDistances(closerer);
                ExtraStand.Keys.ToList().Sort();
                stand = Converts.ToDtoStand(ExtraStand.Keys.Where(x => !arr.Contains(x.Code)).First());
                arr.Add(stand.Code);
                closerer = UtilitiesFunctions.MidPoint(stand.P1, stand.P2);
            }
            return(arr);
        }
Exemple #2
0
        public static int MinDist(I2Points s1, I2Points s2)
        {
            Point ps1 = MidPoint(s1.P1, s1.P2);
            Point ps2 = MidPoint(s2.P1, s2.P2);

            return(CalculteDist(ps1, ps2));
        }
Exemple #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);
        }
Exemple #4
0
 /*
  * //למיין סטנדים פסי
  * public static Dictionary<Stand, List<ProductShop>> OrderStandsByGetaway(I2Points g, Dictionary<Stand, List<ProductShop>> extraStand)
  * {
  *
  *  List<OrderStand> orders = new List<OrderStand>();
  *  OrderStand minOrder = new OrderStand() { s = null, dist = int.MaxValue };
  *  int dist;
  *  I2Points before = null;
  *  for (int i = 0; i < extraStand.Count(); i++)
  *  {
  *      foreach (var item in extraStand)
  *      {
  *          if (orders.Where(x => x.s.Code == item.Key.Code).Count() == 0)
  *          {
  *              dist = MinDist(Converts.ToDtoStand(item.Key), g);
  *              if (dist < minOrder.dist) { before = Converts.ToDtoStand(item.Key); minOrder.dist = dist; minOrder.s = item.Key; }
  *          }
  *      }
  *      orders.Add(minOrder);
  *      g = before;
  *  }
  *  Dictionary<Stand, List<ProductShop>> liststand = new Dictionary<Stand, List<ProductShop>>();
  *  for (int i = 0; i < extraStand.Count; i++)
  *      liststand.Add(orders[i].s, orders[i].listproduct);
  *  extraStand = liststand;
  *  return liststand;
  * }
  *
  */
 public static Point MidPoint(I2Points i2)
 {
     return(MidPoint(i2.P1, i2.P2));
 }