Exemplo n.º 1
0
        private List<ICartesianCoordinate> LoadCSV_Coordinates(string filename)
        {
            using (var file = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                var csvInterpreter = new CsvInterpreter();

                var coordinates = new List<ICartesianCoordinate>();

                int limit;
                if (!int.TryParse(textBox1.Text, out limit))
                    limit = -1;
                
                var linesInCSV = csvInterpreter.Deserialize(file).Skip(1);
                if (limit > -1)
                    linesInCSV = linesInCSV.Take(limit);
                
                foreach (var line in linesInCSV)
                {
                    float x, y;

                    if (float.TryParse(line[0], NumberStyles.Float, CultureInfo.InvariantCulture, out x)
                        && float.TryParse(line[1], NumberStyles.Float, CultureInfo.InvariantCulture, out y))
                    {
                        x *= 100000;
                        y *= 100000;

                        coordinates.Add(new Point(x, y));
                    }
                }
                coordinates = coordinates.ToList();

                Report(coordinates.Count.ToString() + " coordinates loaded from " + filename);
    
                return coordinates;
            }
        }
Exemplo n.º 2
0
        private CostMatrix<double> LoadCSV_Costs(string filename, int dimension)
        {
            using (var file = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                var csvInterpreter = new CsvInterpreter();

                var weightmatrix = new List<double[]>();
                foreach (var line in csvInterpreter.Deserialize(file).Take(dimension))
                {
                    var costs = line.Select(col => double.Parse(col, NumberStyles.Float, CultureInfo.InvariantCulture)).Take(dimension);
                    weightmatrix.Add(costs.ToArray());
                }

                Report("costmatrix loaded from " + filename);

                return new CostMatrix<double>(weightmatrix.ToArray());
            }
        }