public CycleList GetAllCycle(ref CycleList cycles) { foreach (PathFinder path in childPath) { path.GetAllCycle(ref cycles); } foreach (Cycle cycle in this.cycles) { cycles.Add(cycle); } return(cycles); }
public CycleList GetAllIrregularCycle() { CycleList outCycleListComplete = new CycleList(); foreach (Cycle cycle in this) { if (cycle.IsIrregular()) { outCycleListComplete.Add(cycle); } } return(outCycleListComplete.EliminateImplicitIrregularities()); }
public CycleList EliminateImplicitIrregularities() { CycleList outCycleList = new CycleList(); for (int cycleSizeToCheck = minMemoryCycle; cycleSizeToCheck < maxMemoryCycle; cycleSizeToCheck++) { var cycleListToCheck = this.Where(Cycle => Cycle.GetAllNode().Count == cycleSizeToCheck); foreach (Cycle cycleToCheck in cycleListToCheck) { bool isSubCycleSameAsSmallerCycle = false; for (int startingNode = 0; startingNode < cycleSizeToCheck; startingNode++) { for (int subCircleSize = 4; subCircleSize < cycleSizeToCheck; subCircleSize++) { List <Node> subMemory = new List <Node>(); for (int k = 1; k < subCircleSize; k++) { subMemory.Add(cycleToCheck.GetAllNode().ElementAt((startingNode + k) % cycleSizeToCheck)); } Cycle subCycle = new Cycle(cycleToCheck.GetAllNode().ElementAt(startingNode), cycleToCheck.GetAllNode().ElementAt(startingNode), subMemory); foreach (Cycle smallerCycle in outCycleList) { if (subCycle.IsSameCycleAs(smallerCycle)) { isSubCycleSameAsSmallerCycle = true; } } } } if (!isSubCycleSameAsSmallerCycle) { outCycleList.Add(cycleToCheck); } } } return(outCycleList); }
static void Main(string[] args) { Node ann = new Node("Ann"); Node betty = new Node("Betty"); Node cynthia = new Node("Cynthia"); Node diana = new Node("Diana"); Node emily = new Node("Emily"); Node felicia = new Node("Felicia"); Node helen = new Node("Helen"); Node georgia = new Node("Georgia"); // -- graphe irréguliers ann.AddNeighbors(betty, cynthia, emily, felicia, georgia); betty.AddNeighbors(cynthia, helen); cynthia.AddNeighbors(diana, emily, helen); diana.AddNeighbors(emily); emily.AddNeighbors(felicia); helen.AddNeighbors(georgia); // - graphes réguliers /* ann.AddNeighbors(betty); * betty.AddNeighbors(diana,cynthia,emily); * cynthia.AddNeighbors( emily, georgia); * diana.AddNeighbors(emily,felicia); * emily.AddNeighbors(felicia,georgia); * felicia.AddNeighbors(georgia);*/ /* ann.AddNeighbors(betty,cynthia,diana); * betty.AddNeighbors(diana, cynthia, emily); * cynthia.AddNeighbors(emily, georgia); * diana.AddNeighbors(emily, felicia); * emily.AddNeighbors(felicia, georgia); * felicia.AddNeighbors(georgia); * A.AddArcs(B, C, D); * B.AddArcs(A, C); * C.AddArcs(B, A, D, F, E); * D.AddArcs(A, C, F, E); * E.AddArcs(C, D); * F.AddArcs(D, C, G); * G.AddArcs(F);*/ List <Node> everyone = new List <Node>(); everyone.Add(ann); everyone.Add(betty); everyone.Add(cynthia); everyone.Add(diana); everyone.Add(emily); everyone.Add(felicia); everyone.Add(helen); everyone.Add(georgia); foreach (Node person in everyone) { Console.Out.WriteLine(person.ToString()); } PathFinder annToAnnPath = new PathFinder(georgia, emily, null, true); CycleList cycles = new CycleList(); annToAnnPath.GetAllCycle(ref cycles); List <Path> paths = new List <Path>(); annToAnnPath.GetAllCompletedPath(ref paths); foreach (Cycle cycle in cycles) { Console.Out.WriteLine(cycle.ToString()); } Console.Out.WriteLine(); Console.Out.WriteLine("-------------------------------------------------------------------------------------------------------"); Console.Out.WriteLine("-------------------------------------CYCLES IRREGULIERS------------------------------------------------"); Console.Out.WriteLine("-------------------------------------------------------------------------------------------------------"); foreach (Cycle cycle in cycles.GetAllIrregularCycle()) { Console.Out.WriteLine(cycle.ToString()); } Console.Out.WriteLine(); Console.Out.WriteLine("-------------------------------------------------------------------------------------------------------"); Console.Out.WriteLine("----------------------------------------PATH COMPLET---------------------------------------------------"); Console.Out.WriteLine("-------------------------------------------------------------------------------------------------------"); foreach (Path cycle in paths) { Console.Out.WriteLine(cycle.ToString()); } Console.Out.WriteLine(); Console.ReadLine(); }
public PathFinder(Node start, Node end, List <Node> memory = null, bool isOrigin = false, Node current = null) { this.start = start; cycles = new CycleList(); childPath = new List <PathFinder>(); completedPath = new List <Path>(); this.current = (current == null)?start:current; this.end = end; if (memory == null) { this.memory = new List <Node>(); } else { this.memory = memory; } if (!isOrigin) { this.memory.Add(current); } string outString = "Start of " + current + ". Memory is composed of "; foreach (Node node in this.memory) { outString += node.Name + ", "; } Console.Out.WriteLine(outString); //Console.Out.WriteLine(ToString()); foreach (Node neighbor in this.current.Neighbors) { if (!this.memory.Contains(neighbor)) { if (neighbor == start) { if (!(this.memory.Count <= 1)) { cycles.Add(new Cycle(start, end, this.memory)); } } else if (neighbor == end) { completedPath.Add(new Path(start, end, this.memory)); childPath.Add(new PathFinder(start, end, this.memory, false, neighbor)); } else { childPath.Add(new PathFinder(start, end, this.memory, false, neighbor)); } } } this.memory.Remove(current); outString = "End of " + current + ". Memory is composed of "; foreach (Node node in this.memory) { outString += node.Name + ", "; } Console.Out.WriteLine(outString); }