Exemplo n.º 1
0
 public static void AddEmbranchmentShippings(Embranchment from, Embranchment to, int weighting)
 {
     if (!EmbranchmentShippings.Any(a => a.From == from && a.To == to))
     {
         EmbranchmentShippings.Add(new EmbranchmentShipping(from, to, weighting));
     }
 }
Exemplo n.º 2
0
        public static Embranchment AddEmbranchment(string name)
        {
            var embranchment = Embranchments.Where(a => a.Name.Equals(name)).FirstOrDefault();

            if (embranchment == null)
            {
                embranchment = new Embranchment(name);
                Embranchments.Add(embranchment);
            }
            return(embranchment);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 递归出一个节点下指定次数的所有路径
 /// </summary>
 /// <param name="nodes">收集并反回所有节点</param>
 /// <param name="start">起始节点</param>
 /// <param name="parent">父级节点</param>
 /// <param name="level">递归层次</param>
 /// <param name="stop">终结次数</param>
 public static void ErgodicNodeFromStart(ref IList <EmbranchmentShippingNode> nodes,
                                         Embranchment start,
                                         EmbranchmentShippingNode parent, int level, int stop)
 {
     if (nodes == null)
     {
         nodes = new List <EmbranchmentShippingNode>();
     }
     if (level < stop)
     {
         //首次获取起始节点,后面取父级节点
         IList <EmbranchmentShipping> shippings = null;
         if (parent == null)
         {
             shippings = EmbranchmentShipping.EmbranchmentShippings.Where(a => a.From.Name.Equals(start.Name)).ToList();
         }
         else
         {
             shippings = EmbranchmentShipping.EmbranchmentShippings.Where(a => a.From.Name.Equals(parent.To.Name)).ToList();
         }
         foreach (var embranchmentShipping in shippings)
         {
             var node = new EmbranchmentShippingNode();
             node.From = embranchmentShipping.From;
             node.To   = embranchmentShipping.To;
             if (parent == null)
             {
                 node.Paths = new List <EmbranchmentShipping>();
                 node.Paths.Add(embranchmentShipping);
             }
             else
             {
                 var paths = parent.Paths.ToList();
                 paths.Add(embranchmentShipping);
                 node.Paths = paths;
             }
             nodes.Add(node);
             ErgodicNodeFromStart(ref nodes, start, node, level + 1, stop);
         }
     }
 }
Exemplo n.º 4
0
 private void btnImport_Click(object sender, EventArgs e)
 {
     try
     {
         var graphs = txtGraph.Text.Trim().Split(',');
         foreach (var graph in graphs)
         {
             var    processGraph = graph.Trim();
             string fromName     = processGraph.Substring(0, 1);
             var    from         = Embranchment.AddEmbranchment(fromName);
             string toName       = processGraph.Substring(1, 1);
             var    to           = Embranchment.AddEmbranchment(toName);
             int    weighting    = Convert.ToInt32(processGraph.Substring(2, 1));
             EmbranchmentShipping.AddEmbranchmentShippings(from, to, weighting);
         }
         MessageBox.Show("导入完成.");
     }
     catch (Exception ex)
     {
         MessageBox.Show("初始化数据的格式不正确." + ex.Message);
     }
 }
Exemplo n.º 5
0
 public EmbranchmentShipping(Embranchment from, Embranchment to, int duration)
 {
     this.From     = from;
     this.To       = to;
     this.Duration = duration;
 }