Exemple #1
0
        /// <summary>
        /// Read data about city from json file
        /// </summary>
        /// <returns>Data from json file as object</returns>
        SolvroCityData ReadJson()
        {
            if (!File.Exists(Consts.SOLVRO_CITY_JSON_PATH))
            {
                throw new ApplicationException("SOLVRO CITY JSON DATA not provided");
            }

            SolvroCityData SolvroCity = JsonConvert.DeserializeObject <SolvroCityData>(File.ReadAllText(Consts.SOLVRO_CITY_JSON_PATH));

            if (SolvroCity == null)
            {
                throw new ApplicationException("Bad SOLVRO CITY JSON DATA provided");
            }
            return(SolvroCity);
        }
Exemple #2
0
        /// <summary>
        /// Create graph structure
        /// </summary>
        /// <param name="solvroCity">Data that should be used to create graph</param>
        void CreateGraph(SolvroCityData solvroCity)
        {
            Nodes    = new List <SolvroCityGraphNode>();
            Directed = solvroCity.directed;
            foreach (SolvroCityNode node in solvroCity.nodes)
            {
                Nodes.Add(new SolvroCityGraphNode(node));
            }
            foreach (SolvroCityLink link in solvroCity.links)
            {
                SolvroCityGraphNode sourceNode      = Nodes.Find((node) => node.id == link.source);
                SolvroCityGraphNode destinationNode = Nodes.Find((node) => node.id == link.target);

                sourceNode.Links.Add(new SolvroCityGraphLink(link, sourceNode, destinationNode));
                destinationNode.Links.Add(new SolvroCityGraphLink(link, sourceNode, destinationNode, true, Directed ? false : true));
            }
        }
Exemple #3
0
        /// <summary>
        /// Init this class, create graph structure
        /// </summary>
        public void InitGraph()
        {
            SolvroCityData scd = ReadJson();

            CreateGraph(scd);
        }