private static IEnumerable <IPath> GetAllCircuit(INode node, IOrgraph orgraph, HashSet <INode> notAllowed, INode root, IGraphAtoFactory factory, Action <string> OnStep)
        {
            notAllowed.Add(node);
            var step = $"S = {string.Join(", ", notAllowed)}, Current node: {node}, Current arc: ";

            //OnStep($"{string.Join(", ", notAllowed)}");
            if (notAllowed.Count == orgraph.Nodes.Count && node.GetOutputArcs(orgraph).FirstOrDefault(a => a.To == root) is { } finalArc)
            {
                OnStep($"{step} {finalArc}");
                var circuit = factory.CreatePath();
                OnStep($"Add {finalArc}");
                circuit.Append(finalArc);
                yield return(circuit);

                yield break;
            }
            foreach (var arc in node.GetOutputArcs(orgraph).Where(a => a.To.NotIn(notAllowed)))
            {
                OnStep($"{step} {arc}");
                var circuits = GetAllCircuit(arc.To, orgraph, new HashSet <INode>(notAllowed), root, factory, OnStep);
                foreach (var circuit in circuits)
                {
                    OnStep($"Add {arc}");
                    circuit.Append(arc);
                    yield return(circuit);
                }
            }
        }
 private static IPath GetCircuit(INode node, IOrgraph orgraph, HashSet <INode> notAllowed, INode root, IGraphAtoFactory factory, Action <string> OnStep)
 {
     notAllowed.Add(node);
     //OnStep($"{string.Join(", ", notAllowed)}");
     if (notAllowed.Count == orgraph.Nodes.Count && node.GetOutputArcs(orgraph).FirstOrDefault(a => a.To == root) is { } finalArc)
     {
         var circuit = factory.CreatePath();
         OnStep($"Add {finalArc}");
         circuit.Append(finalArc);
         return(circuit);
     }
     foreach (var arc in node.GetOutputArcs(orgraph).Where(a => a.To.NotIn(notAllowed)))
     {
         var circuit = GetCircuit(arc.To, orgraph, notAllowed, root, factory, OnStep);
         if (circuit is null)
         {
             continue;
         }
         OnStep($"Add {arc}");
         circuit.Append(arc);
         return(circuit);
     }
     notAllowed.Remove(node);
     return(null);
 }
        public static IEnumerable <IPath> ApplayRobertsFlores(this IOrgraph orgraph)
        {
            var factory = new GraphAtoFactory();
            var node    = orgraph.GetFirstNode();

            return(GetAllCircuit(node, orgraph, new HashSet <INode>(orgraph.Nodes.Count), node, factory, s => Console.WriteLine(s)));
        }
        private static IEnumerable <IPath> GetAllCircuit(INode node, IOrgraph orgraph, HashSet <INode> notAllowed, INode root, IGraphAtoFactory factory, Action <string> OnStep)
        {
            notAllowed.Add(node);
            //OnStep($"{string.Join(", ", notAllowed)}");
            if (notAllowed.Count == orgraph.Nodes.Count && node.GetOutputArcs(orgraph).FirstOrDefault(a => a.To == root) is { } finalArc)
            {
                var circuit = factory.CreatePath();
                OnStep($"Add {finalArc}");
                circuit.Append(finalArc);
                yield return(circuit);

                yield break;
            }
            foreach (var arc in node.GetOutputArcs(orgraph).Where(a => a.To.NotIn(notAllowed)))
            {
                var circuits = GetAllCircuit(arc.To, orgraph, new HashSet <INode>(notAllowed), root, factory, OnStep);
                foreach (var circuit in circuits)
                {
                    OnStep($"Add {arc}");
                    circuit.Append(arc);
                    yield return(circuit);
                }
            }

            //private static IEnumerable<IPath> GetAllCircuit(INode node, IOrgraph orgraph, HashSet<INode> notAllowed, INode root, IGraphAtoFactory factory, Action<string> OnStep)
            //{
            //    notAllowed.Add(node);
            //    OnStep($"{string.Join(", ", notAllowed)}");
            //    if (notAllowed.Count == orgraph.Nodes.Count && node.GetOutputArcs(orgraph).FirstOrDefault(a => a.To == root) is { } finalArc)
            //    {
            //        var circuit = factory.CreatePath();
            //        circuit.Append(finalArc);
            //        return circuit;
            //    }
            //    foreach (var arc in node.GetOutputArcs(orgraph).Where(a => a.To.NotIn(notAllowed)))
            //    {
            //        var circuit = GetCircuit(arc.To, orgraph, notAllowed, root, factory, OnStep);
            //        if (circuit is null) continue;
            //        circuit.Append(arc);
            //        return circuit;
            //    }
            //    notAllowed.Remove(node);
            //    return null;
            //}
        }
Exemplo n.º 5
0
 public static INode GetFirstNode(this IOrgraph graph) => graph.Nodes.FirstOrDefault();
Exemplo n.º 6
0
 public static IEnumerable <IArcs> GetOutputArcs(this INode node, IOrgraph orgraph) => node.GetOutputArcs(orgraph.Arcs);