Exemplo n.º 1
0
        public VertexMap(int[,] map)
        {
            DimX = map.GetLength(1);
            DimY = map.GetLength(0);

            Map = new Vertex[DimY, DimX];

            for (int i = 0; i < DimY; i++)
            {
                for (int j = 0; j < DimX; j++)
                {
                    Map[i, j] = new Vertex(this, i, j, map[i, j]);
                }
            }

            ProcessMap();
        }
Exemplo n.º 2
0
        public VertexMap(StreamReader reader)
        {
            string[] lineSeparator = new string[] { " " };
            string line = null;

            if (reader.Peek() <= 0) throw new ArgumentException("Can't read from reader");

            line = reader.ReadLine();
            string[] parts = line.Split(lineSeparator, StringSplitOptions.None);
            if (parts.Length != 2) throw new ArgumentException(string.Format("Expected line with two integers, got invalid line '{0}'", line));

            DimY = int.Parse(parts[0]);
            DimX = int.Parse(parts[1]);

            Map = new Vertex[DimY, DimX];

            int i = 0, j = 0, value;

            while (reader.Peek() > 0)
            {
                line = reader.ReadLine();
                if (string.IsNullOrEmpty(line)) continue;

                parts = line.Split(lineSeparator, StringSplitOptions.None);
                if (parts.Length != DimX) throw new ArgumentException(string.Format("Wrong number of elements: {0}, expected {1}", parts.Length, DimX));

                j = 0;
                foreach (string valueStr in parts)
                {
                    if(!int.TryParse(valueStr, out value))throw new ArgumentException(String.Format("Invalid parameter in line [{0}, {1}] - not an int {2}", i,j, valueStr));

                    Map[i, j] = new Vertex(this, i, j, value);
                    j++;
                }
                i++;
            }

            ProcessMap();
        }
Exemplo n.º 3
0
 public Route(Vertex vertex)
 {
     Vertexes.Add(vertex);
     vertex.LongestRoute = this;
 }
Exemplo n.º 4
0
        private Route FindLongestRoute(Vertex vertex)
        {
            if (vertex.Processed)
            {
                return vertex.LongestRoute;
            }

            vertex.Processed = true;

            Route bestRoute = null, neighborRoute = null;
            foreach (Vertex neighbor in vertex.GetNeighbors())
            {
                if (neighbor.Height < vertex.Height)
                {
                    neighborRoute = FindLongestRoute(neighbor);
                    if (bestRoute == null || neighborRoute.isBetterThan(bestRoute)) bestRoute = neighborRoute;
                }
            }

            vertex.LongestRoute.AppendRoute(bestRoute);

            return vertex.LongestRoute;
        }
Exemplo n.º 5
0
 public Neighbors(Vertex v)
 {
     vertex = v;
 }