Пример #1
0
 public Link GetLink(string name)
 {
     return(Links.ContainsKey(name) ? Links[name] : null);
 }
Пример #2
0
        public override void Calc()
        {
            map  = input.Replace("\r", "") + " ";
            mapW = map.IndexOf("\n") + 1;
            mapH = map.Length / mapW;


            LocatePoints();

/*
 *          for (int i = 0; i < mapH; i++)
 *          {
 *              for (int j = 0; j < mapW; j++)
 *              {
 *                  Console.Write(pos(j, i));
 *              }
 *              Console.WriteLine();
 *
 *          }
 */
            var lst = KeyPoints.ToList();

            for (int i = 0; i < lst.Count; i++)
            {
                var p = lst[i];

                if (p.Value == "AA")
                {
                    entrance = p.Key;
                }
                if (p.Value == "ZZ")
                {
                    exit = p.Key;
                }

                var pp = p.Key;
                if (pp.X <= 3 || pp.X >= mapW - 3 || pp.Y <= 3 || pp.Y >= mapH - 3)
                {
                    KeyPoints[p.Key] += "_O";
                }
                else
                {
                    KeyPoints[p.Key] += "_I";
                }

                if (!Links.ContainsKey(KeyPoints[p.Key]))
                {
                    Link l = new Link();
                    l.from = KeyPoints[p.Key];
                    Links.Add(KeyPoints[p.Key], l);
                }
            }
            // Console.WriteLine(entrance);
            // Console.WriteLine(exit);

            Scan();

            lst = KeyPoints.ToList();
            for (int i = 0; i < lst.Count; i++)
            {
                var p = lst[i];
                if (p.Value == "AA_O" || p.Value == "ZZ_O")
                {
                    continue;
                }
                string dir  = p.Value.Substring(3, 1);
                string name = p.Value.Substring(0, 2);

                if (dir == "O")
                {
                    name += "_I";
                }
                else
                {
                    name += "_O";
                }

                Links[p.Value].addLink(name, 1);
            }

            foreach (var item in Links)
            {
                for (int i = 0; i < item.Value.To.Count; i++)
                {
                    //  Console.WriteLine("Path from {0} to {1} takes {2}", item.Value.from, item.Value.To[i], item.Value.Lengths[i]);
                }
            }


            Links["AA_O"].minPath = 0;

            paths.Add(new state(0, "AA_O"), 0);
            toUpdate.Enqueue(new state(0, "AA_O"));

            while (toUpdate.Count > 0)
            {
                var s = toUpdate.Dequeue();

                //Console.WriteLine(s.node+" "+s.layer);

                Links[s.node].Update(s.layer);
            }



            output = "" + (paths[new state(0, "ZZ_O")]);
        }
Пример #3
0
        private void AddLink(Association association, ObjectPlusPlus linkedObject, object qualifier, int counter)
        {
            if (counter < 1)
            {
                return;
            }
            if (linkedObject == null)
            {
                return;
            }
            if (association == null)
            {
                return;
            }
            // sprawdzenie czy ta asocjacja została zdefiniowana
            if (!LegalAssociations.Any(x => x.Role.Equals(association.Role)))
            {
                throw new Exception("Association is not legal");
            }
            // sprawdzenie czy typ obiektu do którego dodajesz powiązanie zgadza się ze wzroem asocjacji
            if (this.GetType() != association.StartClassifier)
            {
                throw new Exception("This object type is not correct");
            }
            // sprawdzenie czy typ obiektu który chcesz powiązać zgadza się ze wzorem asocjacji
            if (linkedObject.GetType() != association.EndClassifier)
            {
                throw new Exception("Linked object type is not correct");
            }
            Dictionary <object, ObjectPlusPlus> roleLinks;

            // sprawdzenie czy istnieją powiązania dla roli
            if (Links.ContainsKey(association.Role))
            {
                roleLinks = Links[association.Role];
            }
            else
            {
                roleLinks = new Dictionary <object, ObjectPlusPlus>();
                Links.Add(association.Role, roleLinks);
            }
            // sprawdzenie czy powiązania dla roli zawierają obiekt, który chcemy powiązać
            if (!roleLinks.ContainsKey(linkedObject))
            {
                // stworzenie odwrotnej asocjacji do połączenie zwrotnego
                Association reverseAssociation = association.GetReversedAssociation();
                // sprawdzenie liczności asocjacji dla obiektu, który chcemy powiązać
                switch (association.EndMultiplicityLimit)
                {
                // jeżeli nie ma limitu liczności asocjacji
                case -1:
                    roleLinks.Add(qualifier, linkedObject);
                    if (reverseAssociation != null)
                    {
                        // stworzenie połączenia zwrotnego
                        linkedObject.AddLink(reverseAssociation, this, this, counter - 1);
                    }
                    break;

                // przypadek, w którym limit liczność to 1
                case 0:
                    if (roleLinks.Count != 0)
                    {
                        throw new Exception("Multiplicity limit has been reached");
                    }
                    roleLinks.Add(qualifier, linkedObject);
                    // stworzenie połączenia zwrotnego
                    linkedObject.AddLink(reverseAssociation, this, this, counter - 1);
                    break;

                // przypadek, w którym limit liczności to x
                default:
                    if (roleLinks.Count >= association.EndMultiplicityLimit)
                    {
                        throw new Exception("Multiplicity limit has been reached");
                    }
                    roleLinks.Add(qualifier, linkedObject);
                    // stworzenie połączenia zwrotnego
                    linkedObject.AddLink(reverseAssociation, this, this, counter - 1);
                    break;
                }
            }
        }