Ejemplo n.º 1
0
        public static IDictionary<MultplePrimKey, int> LoadInputs(string path)
        {
            Dictionary<MultplePrimKey, int> roads = new Dictionary<MultplePrimKey, int>();
            using (StreamReader sr = new StreamReader(path))
            {
                string line = sr.ReadToEnd();
                if (line.Equals(string.Empty)) return roads;
                else
                {
                    line = line.Replace("Graph:", "");
                    string[] paths = line.Split(new char[]{',', ' ', '\t'}, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < paths.Length;i++ )
                    {
                        MultplePrimKey key = new MultplePrimKey();
                        char[] items = paths[i].ToCharArray();
                        if (items.Length == 3)
                        {
                            key.Key1 = items[0].ToString();
                            key.Key2 = items[1].ToString();
                            int value;
                            if(int.TryParse(items[2].ToString(), out value))
                                roads.Add(key, value);
                            else
                                throw new Exception(ConstStr.BADINPUTGRAPHERROR);
                        }
                        else
                        {
                            throw new Exception(ConstStr.BADINPUTGRAPHERROR);
                        }
                    }
                }
            }

            return roads;
        }
Ejemplo n.º 2
0
        private List<MultplePrimKey> ParseQuestion(string question)
        {
            List<MultplePrimKey> list = new List<MultplePrimKey>();
            string[] tempArray = question.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (tempArray.Length == 0) return list;

            string lastStr = tempArray[tempArray.Length - 1].Trim(new char[] { '.' });
            string[] stops = lastStr.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
            if (stops.Length < 2)
                return list;

            for (int i = 0; i < stops.Length - 1; i++)
            {
                MultplePrimKey key = new MultplePrimKey() { Key1 = stops[i], Key2 = stops[i + 1] };
                list.Add(key);
            }

            return list;
        }
Ejemplo n.º 3
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (ReferenceEquals(this, obj))
            {
                return(true);
            }

            MultplePrimKey otherKey = (obj as MultplePrimKey);

            if ((otherKey != null) && (otherKey.Key1 == this.Key1) && (otherKey.Key2 == Key2))
            {
                return(true);
            }

            return(false);
        }