Beispiel #1
0
        //public static T DeepCopy<T>(T item)
        //{
        //    BinaryFormatter formatter = new BinaryFormatter();
        //    MemoryStream stream = new MemoryStream();
        //    formatter.Serialize(stream, item);
        //    stream.Seek(0, SeekOrigin.Begin);
        //    T result = (T)formatter.Deserialize(stream);
        //    stream.Close();
        //    return result;

        //}

        private List <string> getCaminho(string point, string target, int rota, List <Node> nodes)
        {
            try
            {
                bool          repeat = false;
                bool          found  = false;
                List <string> lista  = new List <string>();

                while (!repeat && !found)
                {
                    Node node = nodes.ToList().FirstOrDefault(p => p.ToString().Equals(point));
                    Node n    = node.Conexoes[rota];

                    Node nextNode;
                    if (lista.Count == 0)
                    {
                        nextNode = nodes.FirstOrDefault(p => p.ToString().Equals(n.ToString()));
                    }
                    else
                    {
                        nextNode = nodes.FirstOrDefault(p => p.ToString().Equals(lista[lista.Count - 1]));
                    }

                    lista.Add(nextNode.Conexoes[rota].ToString());

                    if (nextNode.Conexoes[rota].ToString().Equals(point))
                    {
                        repeat = true;
                    }
                    if (nextNode.Conexoes[rota].ToString().Equals(target))
                    {
                        found = true;
                    }
                }
                return(lista);
            }
            catch
            {
                return(new List <string>());
            }
        }
 /// <summary>
 /// Converts the edge to at string between to nodes
 /// </summary>
 /// <returns>String representation of the edge</returns>
 public override string ToString()
 {
     return(String.Format("{0}->{1}, km: {2}", from.ToString(), to.ToString(), km.ToString()));
 }
 /// <summary>
 /// Adds the given node to the graph.
 /// </summary>
 /// <param name="node"></param>
 public void AddNode(Node <T> node)
 {
     Nodes.Add(node.ToString(), node);
 }