public void traversel(object parentAndChild) { // Console.WriteLine("IN traversal"); if (!isDynamic) { parentChild obj = (parentChild)parentAndChild; if (obj.Child1.Connected.IsVisited || obj.Child1.Connected.IsDead) { //Console.WriteLine("Child visited"); return; } else { obj.Child1.Connected.IsNewBorn = false; obj.Child1.Connected.Parent = obj.Parent; obj.Child1.Connected.TotalVisits++; obj.Child1.Connected.IsVisited = true; obj.Child1.EWeigth *= 2; var li = obj.Child1.Connected.AdjacencyList; foreach (edge e in li) { if (e.Connected == obj.Parent) { e.EWeigth *= 2; } } iputStimuliObj i = new iputStimuliObj(); i.Source = obj.Child1.Connected; i.Stimuli = obj.I; if (obj.Child1.Connected.Weigth.Equals(obj.I)) { //Console.WriteLine("\n===============================\n"); Console.WriteLine("Moving to dynamic on stilmuli " + obj.I + "\n===================="); this.isDynamic = true; this.dynamicApproach(obj.I); } else if (obj.Child1.Connected.Weigth < obj.I) { //Console.WriteLine("child weigth is less..."+obj.Child1.Connected.Weigth); obj.Child1.Connected.Weigth = (obj.I - obj.Child1.Connected.Weigth); //Console.WriteLine("child weigth is less update..." + obj.Child1.Connected.Weigth); //Console.WriteLine("Edge Weight" + obj.Child1.EWeigth); this.minStimuli(i); } else { //Console.WriteLine("child weigth is greater" + obj.Child1.Connected.Weigth); obj.Child1.Connected.Weigth += obj.I; //Console.WriteLine("child weigth is greater update" + obj.Child1.Connected.Weigth); //Console.WriteLine("Edge Weight" + obj.Child1.EWeigth); this.minStimuli(i); } } } return; }
public void minStimuli(object ob) { iputStimuliObj obj = (iputStimuliObj)ob; var sorted = obj.Source.AdjacencyList.OrderBy(x => x.EWeigth); float smallestWeight = 0; foreach (edge v in sorted) { if (!v.Connected.IsVisited) { smallestWeight = v.EWeigth; break; } } if (smallestWeight.Equals(0)) { return; } foreach (edge c in sorted) { if (c.EWeigth.Equals(smallestWeight)) { parentChild p = new parentChild(); p.I = obj.Stimuli; // Console.WriteLine("obj.Stimuli" + obj.Stimuli); p.Parent = obj.Source; p.Child1 = c; //Console.WriteLine("Creating thread"); //Thread t = new Thread(this.traversel); //t.Start(p); // Console.WriteLine("Ending thread"); //t.Abort(); this.traversel(p); } } }
public void stimuliOccur(float i) { //var sort = this.startNode.AdjacencyList.OrderByDescending(x => x.EWeigth); //startNode = sort.First().Connected; if (this.totalVisits.Equals(0)) { //Console.WriteLine("First Visit"); this.totalVisits++; iputStimuliObj obj = new iputStimuliObj(); obj.Stimuli = i; obj.Source = this.parentSource; obj.Source.IsVisited = true; if (this.parentSource.Weigth < i) { this.parentSource.Weigth = (i - this.parentSource.Weigth); } else { this.parentSource.Weigth += i; } this.minStimuli(obj); } else { this.clearGraph(); this.totalVisits++; var sortedSource = this.startNode.AdjacencyList.OrderByDescending(x => x.EWeigth); float largest = sortedSource.First().EWeigth; //Console.WriteLine("Next parent" + sortedSource.First().Connected.Weigth); foreach (edge e in sortedSource) { if (e.EWeigth.Equals(largest)) { iputStimuliObj obj = new iputStimuliObj(); obj.Stimuli = i; obj.Source = e.Connected; e.Connected.IsVisited = true; if (e.Connected.Weigth < i) { e.Connected.Weigth = (i - e.Connected.Weigth); } else { e.Connected.Weigth += i; } // Thread f = new Thread(this.minStimuli); //f.Start(obj); this.minStimuli(obj); } } } if (!isDynamic) { //Console.WriteLine("Node not found creating now...."); vertex c = this.addNewNode(i); this.graphNode.Add(c); } this.isDynamic = false; this.ClearDead(); }