Ejemplo n.º 1
0
    private void CreateDefaultMobilityModes(string filename)
    {
        var mode = new MobilityMode()
        {
            name = "Car"                                    /*translatable*/
        };

        mode.speeds[(int)ClassificationIndex.Highway]     = 80;
        mode.speeds[(int)ClassificationIndex.HighwayLink] = 50;
        mode.speeds[(int)ClassificationIndex.Primary]     = 50;
        mode.speeds[(int)ClassificationIndex.Secondary]   = 35;
        mode.speeds[(int)ClassificationIndex.Other]       = 15;
        mode.speeds[(int)ClassificationIndex.None]        = defaultWalkSpeed;
        mobilityModes.Add(mode);

        mode = new MobilityMode()
        {
            name = "Motorbike"                                /*translatable*/
        };
        mode.speeds[(int)ClassificationIndex.Highway]     = 60;
        mode.speeds[(int)ClassificationIndex.HighwayLink] = 40;
        mode.speeds[(int)ClassificationIndex.Primary]     = 30;
        mode.speeds[(int)ClassificationIndex.Secondary]   = 30;
        mode.speeds[(int)ClassificationIndex.Other]       = 15;
        mode.speeds[(int)ClassificationIndex.None]        = defaultWalkSpeed;
        mobilityModes.Add(mode);

        mode = new MobilityMode()
        {
            name = "Walk"                                      /*translatable*/
        };
        mode.speeds[(int)ClassificationIndex.Highway]     = 0; // Can't walk on highway
        mode.speeds[(int)ClassificationIndex.HighwayLink] = 0; // Can't walk on highway link
        mode.speeds[(int)ClassificationIndex.Primary]     = defaultWalkSpeed;
        mode.speeds[(int)ClassificationIndex.Secondary]   = defaultWalkSpeed;
        mode.speeds[(int)ClassificationIndex.Other]       = defaultWalkSpeed;
        mode.speeds[(int)ClassificationIndex.None]        = defaultWalkSpeed;
        mobilityModes.Add(mode);

        ReachabilityIO.Save(mobilityModes, filename);
    }
Ejemplo n.º 2
0
    private static List <MobilityMode> Parse(StreamReader sr)
    {
        // Parse header
        string line = sr.ReadLine();

        string[] header = line.Split(',');

        if (header == null || header.Length != ClassificationValue.Count)
        {
            return(null);
        }

        List <MobilityMode> modes = new List <MobilityMode>();

        while ((line = sr.ReadLine()) != null)
        {
            string[] cells = line.Split(',');
            if (string.IsNullOrEmpty(cells[0]))
            {
                continue;
            }

            if (cells.Length != ClassificationValue.Count)
            {
                return(null);
            }

            MobilityMode mode = new MobilityMode();
            mode.name = cells[0].Trim();

            for (int i = ClassificationValue.Count - 1; i > 0; --i)
            {
                float.TryParse(cells[i], out float value);
                mode.speeds[ClassificationValue.Count - i] = value * ReachabilityTool.kmPerHourToMetersPerMin;                   //convert from km/h to m/min
            }
            modes.Add(mode);
        }

        return(modes);
    }