public override void RunGA( State Situation, Population P ) { double NumerositySum = 0.0; double TimeStampSum = 0.0; foreach( Classifier C in this.CList ) { NumerositySum += C.N; TimeStampSum += C.Ts * C.N; } if( Configuration.T - TimeStampSum / NumerositySum > Configuration.Theta_GA ) { foreach( Classifier C in this.CList ) { C.Ts = Configuration.T; } Classifier Parent_1 = this.SelectOffspring(); Classifier Parent_2 = this.SelectOffspring(); Classifier Child_1 = new SigmaNormalClassifier( ( SigmaNormalClassifier )Parent_1 ); Classifier Child_2 = new SigmaNormalClassifier( ( SigmaNormalClassifier )Parent_2 ); ///nakata added Child_1.F /= Child_1.N; Child_2.F /= Child_2.N; ////////////// Child_1.N = Child_2.N = 1; Child_1.Exp = Child_2.Exp = 0; Child_1.St = Child_2.St = 0; Child_1.M = Child_2.M = 0; Child_1.S = Child_2.S = 0; //Child_1.Epsilon_0 = Child_2.Epsilon_0 = Configuration.Epsilon_0; SigmaNormalClassifier SNP1 = ( SigmaNormalClassifier )Parent_1; SigmaNormalClassifier SNP2 = ( SigmaNormalClassifier )Parent_2; SigmaNormalClassifier SNC1 = ( SigmaNormalClassifier )Child_1; SigmaNormalClassifier SNC2 = ( SigmaNormalClassifier )Child_2; // 交叉 if( Configuration.MT.NextDouble() < Configuration.Chai ) { Child_1.Crossover( Child_2 ); Child_1.P = ( Parent_1.P + Parent_2.P ) / 2; //Child_1.Epsilon = Parent_1.Epsilon + Parent_2.Epsilon; Child_1.Epsilon = ( Parent_1.Epsilon + Parent_2.Epsilon ) / 2; Child_1.F = ( Parent_1.F + Parent_2.F ) / 2; //Child_1.M = ( Parent_1.M + Parent_2.M ) / 2; //Child_1.S = ( Parent_1.S + Parent_2.S ) / 2; Child_1.Epsilon_0 = ( Parent_1.Epsilon_0 + Parent_2.Epsilon_0 ) / 2; //Child_1.Epsilon_0 = Math.Min(Parent_1.Epsilon_0, Parent_2.Epsilon_0); Child_2.P = Child_1.P; Child_2.Epsilon = Child_1.Epsilon; Child_2.F = Child_1.F; //Child_2.M = Child_1.M; //Child_2.S = Child_1.S; Child_2.Epsilon_0 = Child_1.Epsilon_0; for( int i = 0; i < SNC1.WinningRate.Count(); i++ ) { SNC1.WinningRate[i] = SNC2.WinningRate[i] = ( SNP1.WinningRate[i] + SNP2.WinningRate[i] ) / 2; } } Child_1.F *= 0.1; Child_2.F *= 0.1; for( int i = 0; i < SNC1.WinningRate.Count(); i++ ) { SNC1.WinningRate[i] *= 0.1; SNC2.WinningRate[i] *= 0.1; } // bothChild Child_1.Mutation( Situation ); Child_2.Mutation( Situation ); if( Configuration.DoGASubsumption ) { if( Parent_1.DoesSubsume( Child_1 ) ) { Parent_1.N++; } else if( Parent_2.DoesSubsume( Child_1 ) ) { Parent_2.N++; } else { P.Insert( Child_1 ); } P.Delete(); if( Parent_1.DoesSubsume( Child_2 ) ) { Parent_1.N++; } else if( Parent_2.DoesSubsume( Child_2 ) ) { Parent_2.N++; } else { P.Insert( Child_2 ); } P.Delete(); } else { P.Insert( Child_1 ); P.Delete(); P.Insert( Child_2 ); P.Delete(); } } }
public override void RunGA(State Situation, Population P) { double NumerositySum = 0.0; double TimeStampSum = 0.0; foreach (Classifier C in this.CList) { NumerositySum += C.N; TimeStampSum += C.Ts * C.N; } if (Configuration.T - TimeStampSum / NumerositySum > Configuration.Theta_GA) { foreach (Classifier C in this.CList) { C.Ts = Configuration.T; } Classifier Parent_1 = this.SelectOffspring(); Classifier Parent_2 = this.SelectOffspring(); Classifier Child_1 = new NormalClassifier(( NormalClassifier )Parent_1); Classifier Child_2 = new NormalClassifier(( NormalClassifier )Parent_2); Child_1.N = Child_2.N = 1; Child_1.Exp = Child_2.Exp = 0; Child_1.St = Child_2.St = 0; Child_1.M = Child_2.M = 0; Child_1.S = Child_2.S = 0; if (Configuration.MT.NextDouble() < Configuration.Chai) { Child_1.Crossover(Child_2); Child_1.P = (Parent_1.P + Parent_2.P) / 2; Child_1.Epsilon = (Parent_1.Epsilon + Parent_2.Epsilon) / 2; Child_1.F = (Parent_1.F + Parent_2.F) / 2; //Child_1.M = ( Parent_1.M + Parent_2.M ) / 2; //Child_1.S = ( Parent_1.S + Parent_2.S ) / 2; Child_2.P = Child_1.P; Child_2.Epsilon = Child_1.Epsilon; Child_2.F = Child_1.F; //Child_2.M = Child_1.M; //Child_2.S = Child_1.S; } Child_1.F *= 0.1; Child_2.F *= 0.1; // bothChild Child_1.Mutation(Situation); Child_2.Mutation(Situation); if (Configuration.DoGASubsumption) { if (Parent_1.DoesSubsume(Child_1)) { Parent_1.N++; } else if (Parent_2.DoesSubsume(Child_1)) { Parent_2.N++; } else { P.Insert(Child_1); } P.Delete(); if (Parent_1.DoesSubsume(Child_2)) { Parent_1.N++; } else if (Parent_2.DoesSubsume(Child_2)) { Parent_2.N++; } else { P.Insert(Child_2); } P.Delete(); } else { P.Insert(Child_1); P.Delete(); P.Insert(Child_2); P.Delete(); } } }
public override void RunGA(State Situation, Population P) { double NumerositySum = 0.0; double TimeStampSum = 0.0; foreach (Classifier C in this.CList) { NumerositySum += C.N; TimeStampSum += C.Ts * C.N; } if (Configuration.T - TimeStampSum / NumerositySum > Configuration.Theta_GA) { foreach (Classifier C in this.CList) { C.Ts = Configuration.T; } Classifier Parent_1 = this.SelectOffspring(); Classifier Parent_2 = this.SelectOffspring(); Classifier Child_1 = new SigmaNormalClassifier(( SigmaNormalClassifier )Parent_1); Classifier Child_2 = new SigmaNormalClassifier(( SigmaNormalClassifier )Parent_2); ///nakata added Child_1.F /= Child_1.N; Child_2.F /= Child_2.N; ////////////// Child_1.N = Child_2.N = 1; Child_1.Exp = Child_2.Exp = 0; Child_1.St = Child_2.St = 0; Child_1.M = Child_2.M = 0; Child_1.S = Child_2.S = 0; //Child_1.Epsilon_0 = Child_2.Epsilon_0 = Configuration.Epsilon_0; SigmaNormalClassifier SNP1 = ( SigmaNormalClassifier )Parent_1; SigmaNormalClassifier SNP2 = ( SigmaNormalClassifier )Parent_2; SigmaNormalClassifier SNC1 = ( SigmaNormalClassifier )Child_1; SigmaNormalClassifier SNC2 = ( SigmaNormalClassifier )Child_2; // 交叉 if (Configuration.MT.NextDouble() < Configuration.Chai) { Child_1.Crossover(Child_2); Child_1.P = (Parent_1.P + Parent_2.P) / 2; //Child_1.Epsilon = Parent_1.Epsilon + Parent_2.Epsilon; Child_1.Epsilon = (Parent_1.Epsilon + Parent_2.Epsilon) / 2; Child_1.F = (Parent_1.F + Parent_2.F) / 2; Child_1.Epsilon_0 = (Parent_1.Epsilon_0 + Parent_2.Epsilon_0) / 2; //Child_1.Epsilon_0 = Math.Min(Parent_1.Epsilon_0, Parent_2.Epsilon_0); Child_2.P = Child_1.P; Child_2.Epsilon = Child_1.Epsilon; Child_2.F = Child_1.F; Child_2.Epsilon_0 = Child_1.Epsilon_0; for (int i = 0; i < SNC1.WinningRate.Count(); i++) { SNC1.WinningRate[i] = SNC2.WinningRate[i] = (SNP1.WinningRate[i] + SNP2.WinningRate[i]) / 2; } } Child_1.F *= 0.1; Child_2.F *= 0.1; for (int i = 0; i < SNC1.WinningRate.Count(); i++) { SNC1.WinningRate[i] *= 0.1; SNC2.WinningRate[i] *= 0.1; } // bothChild Child_1.Mutation(Situation); Child_2.Mutation(Situation); if (Child_1.C.state[4] == '0' & Child_1.C.state[7] == '1')//"bath0 rehabi1" { Configuration.Problem.WriteLine(Child_1.C.state + "," + Configuration.T + "," + Child_1.P + "," + Child_1.M + "," + Child_1.Epsilon + "," + Child_1.F + "," + Child_1.N + "," + Child_1.Exp + "," + Child_1.Ts + "," + Child_1.As + "," + Child_1.Kappa + "," + Child_1.Epsilon_0 + "," + Child_1.St + "," + Child_1.GenerateTime + ", child 2 "); Configuration.Problem.WriteLine(Parent_1.C.state + "," + Configuration.T + "," + Parent_1.P + "," + Parent_1.M + "," + Parent_1.Epsilon + "," + Parent_1.F + "," + Parent_1.N + "," + Parent_1.Exp + "," + Parent_1.Ts + "," + Parent_1.As + "," + Parent_1.Kappa + "," + Parent_1.Epsilon_0 + "," + Parent_1.St + "," + Parent_1.GenerateTime + ",Parent1"); Configuration.Problem.WriteLine(Parent_2.C.state + "," + Configuration.T + "," + Parent_2.P + "," + Parent_2.M + "," + Parent_2.Epsilon + "," + Parent_2.F + "," + Parent_2.N + "," + Parent_2.Exp + "," + Parent_2.Ts + "," + Parent_2.As + "," + Parent_2.Kappa + "," + Parent_2.Epsilon_0 + "," + Parent_2.St + "," + Parent_2.GenerateTime + ",Parent2"); } if (Child_2.C.state[4] == '0' & Child_2.C.state[7] == '1')//"bath0 rehabi1" { Configuration.Problem.WriteLine(Child_2.C.state + "," + Configuration.T + "," + Child_2.P + "," + Child_2.M + "," + Child_2.Epsilon + "," + Child_2.F + "," + Child_2.N + "," + Child_2.Exp + "," + Child_2.Ts + "," + Child_2.As + "," + Child_2.Kappa + "," + Child_2.Epsilon_0 + "," + Child_2.St + "," + Child_2.GenerateTime + ",child 2"); Configuration.Problem.WriteLine(Parent_1.C.state + "," + Configuration.T + "," + Parent_1.P + "," + Parent_1.M + "," + Parent_1.Epsilon + "," + Parent_1.F + "," + Parent_1.N + "," + Parent_1.Exp + "," + Parent_1.Ts + "," + Parent_1.As + "," + Parent_1.Kappa + "," + Parent_1.Epsilon_0 + "," + Parent_1.St + "," + Parent_1.GenerateTime + ",Parent1"); Configuration.Problem.WriteLine(Parent_2.C.state + "," + Configuration.T + "," + Parent_2.P + "," + Parent_2.M + "," + Parent_2.Epsilon + "," + Parent_2.F + "," + Parent_2.N + "," + Parent_2.Exp + "," + Parent_2.Ts + "," + Parent_2.As + "," + Parent_2.Kappa + "," + Parent_2.Epsilon_0 + "," + Parent_2.St + "," + Parent_2.GenerateTime + ",Parent2"); } if (Configuration.DoGASubsumption) { if (Parent_1.DoesSubsume(Child_1)) { Parent_1.N++; } else if (Parent_2.DoesSubsume(Child_1)) { Parent_2.N++; } else { P.Insert(Child_1); } P.Delete(); if (Parent_1.DoesSubsume(Child_2)) { Parent_1.N++; } else if (Parent_2.DoesSubsume(Child_2)) { Parent_2.N++; } else { P.Insert(Child_2); } P.Delete(); } else { P.Insert(Child_1); P.Delete(); P.Insert(Child_2); P.Delete(); } } }
public override void RunGA( State Situation, Population P ) { double NumerositySum = 0.0; double TimeStampSum = 0.0; foreach( Classifier C in this.CList ) { NumerositySum += C.N; TimeStampSum += C.Ts * C.N; } if( Configuration.T - TimeStampSum / NumerositySum > Configuration.Theta_GA ) { foreach( Classifier C in this.CList ) { C.Ts = Configuration.T; } Classifier Parent_1 = this.SelectOffspring(); Classifier Parent_2 = this.SelectOffspring(); Classifier Child_1 = new NormalClassifier( ( NormalClassifier )Parent_1 ); Classifier Child_2 = new NormalClassifier( ( NormalClassifier )Parent_2 ); Child_1.N = Child_2.N = 1; Child_1.Exp = Child_2.Exp = 0; Child_1.St = Child_2.St = 0; Child_1.M = Child_2.M = 0; Child_1.S = Child_2.S = 0; if( Configuration.MT.NextDouble() < Configuration.Chai ) { Child_1.Crossover( Child_2 ); Child_1.P = ( Parent_1.P + Parent_2.P ) / 2; Child_1.Epsilon = ( Parent_1.Epsilon + Parent_2.Epsilon ) / 2; Child_1.F = ( Parent_1.F + Parent_2.F ) / 2; //Child_1.M = ( Parent_1.M + Parent_2.M ) / 2; //Child_1.S = ( Parent_1.S + Parent_2.S ) / 2; Child_2.P = Child_1.P; Child_2.Epsilon = Child_1.Epsilon; Child_2.F = Child_1.F; //Child_2.M = Child_1.M; //Child_2.S = Child_1.S; } Child_1.F *= 0.1; Child_2.F *= 0.1; // bothChild Child_1.Mutation( Situation ); Child_2.Mutation( Situation ); if( Configuration.DoGASubsumption ) { if( Parent_1.DoesSubsume( Child_1 ) ) { Parent_1.N++; } else if( Parent_2.DoesSubsume( Child_1 ) ) { Parent_2.N++; } else { P.Insert( Child_1 ); } P.Delete(); if( Parent_1.DoesSubsume( Child_2 ) ) { Parent_1.N++; } else if( Parent_2.DoesSubsume( Child_2 ) ) { Parent_2.N++; } else { P.Insert( Child_2 ); } P.Delete(); } else { P.Insert( Child_1 ); P.Delete(); P.Insert( Child_2 ); P.Delete(); } } }