1 / 27

GA – Rosenbrock (10) for Example

GA – Rosenbrock (10) for Example. Public methods (for general user). Init() – (4 polymorphism ) Init ( int PopulationSize, int VariableDimension, double VariableUpbound, double VariableLowbound, string EncodeType, string RepeatableOption, bool Minima)

wilson
Télécharger la présentation

GA – Rosenbrock (10) for Example

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GA – Rosenbrock(10) for Example

  2. Public methods (for general user) • Init() – (4 polymorphism) • Init (int PopulationSize, int VariableDimension, double VariableUpbound, double VariableLowbound, string EncodeType, string RepeatableOption, bool Minima) • Init (int PopulationSize, int VariableDimension, double VariableUpbound, double VariableLowbound, string EncodeType, string RepeatableOption) • Init (int PopulationSize, int VariableDimension, double [] VariableUpbound, double [] VariableLowbound, string EncodeType, string RepeatableOption, bool Minima) • Init (int PopulationSize, int VariableDimension, double [] VariableUpbound, double [] VariableLowbound, string EncodeType, string RepeatableOption) • GA Basic routine • Generate_Population(string Population_Type) • Evalutate_Population() • Reproduce_Population (string METHOD) • Crossover_Population (string Population_Type) • Mutation_Population (string METHOD, double PM) • Run() – (2 polymorphism) • Run (int Iteration) • Run (int Iteration, double PC, double PM)

  3. Methods can be override by user • Method • public override doubleFitness(double[] Solution) • public override double Run (intIteration)

  4. GAOption Class • When you have no idea on determine the GA strategy, you could also expand the GAOption tree to find out each possible strategy combination under specific encoding. • For example : GA basic routine • Reproduce_Population(GAOption.Select.Elite); • Crossover_Population(GAOption.Crossover.NonRepeatNumetric.Order, PC); • Mutation_Population(GAOption.Mutation.Numetric.Swap_Two_Position, PM);

  5. GAOption Class Different GA strategy combinations

  6. GAOption Class Different GA strategy combinations

  7. Step 1 and 2 • using System; • using System.Collections.Generic; • using System.Text; • using System.IO; • using Metaheuristic; • namespace Testing • { • classRosenbrock : GA • { • } • } Include our MetaYourWay library Create a problem solver class Rosenbrockwhich inheritance GA class

  8. Step 3 • using … • namespace Testing • { • classRosenbrock : GA • { • static void Main(string[] args) • { • Rosenbrockmyga = newRosenbrock(); • } • public void Read()… } • } Create object.

  9. Step 4 • using … • namespace Testing • { • classRosenbrock : GA • { • static void Main(string[] args) • { • Rosenbrockmyga = newRosenbrock(); • } • public override double Fitness(double[] pos) • { • double fitness = 0; • for (int j = 0; j < pos.Length - 1; j++) • fitness = fitness + 100 * Math.Pow(pos[j + 1] - Math.Pow(pos[j], 2), 2) + Math.Pow(pos[j] - 1, 2); • return fitness; • } • } • } Override Fitness Function

  10. Step 5 • using … • namespace Testing • { • classRosenbrock : GA • { • double Up = 10; • double Low = 0; • static void Main(string[] args) • { • Rosenbrockmyga = newRosenbrock(); • myga.Init(PopulationSize, VariableDimension, Up, Low, EncodeType, RepeatbleOption, Subject2Minima); • } • public override double Fitness(double[] pos)… • } • } Define variable upper / lower bound. If you want the optimal value of GbestFitness is minimizedSet this option to true User can use arrays to input lower bound and upper bound for each variable.

  11. Step 6 – Simple Call • using … • namespace Testing • { • classRosenbrock : GA • { • double Up = 10; • double Low = 0; • static void Main(string[] args) • { • Rosenbrockmyga = newRosenbrock (); • myga.Init(40, 10, Up, Low, “RealNumber”, “Repeatable”, true); • myga.Run(1000); //myga.Run(1000,PC,PM); • } public override double Fitness(double[] pos)… • } • } Polymorphism

  12. Step 7 – Advanced Call If default GA strategy routine cannot satisfy your needsYou could also customize your own strategy To do this, you must override the default Run() Method • public override void Run(int Iteration, double PC, double PM) • { • Generate_Population(“RealNumber”); • for (int i = 0; i < Iteration; i++) • { • Evaluate_Population(); • Reproduce_Population(GAOption.Select.Elite); • Crossover_Population(GAOption.Crossover. RealNumber.Arithmetic, PC); • Mutation_Population(GAOption.Mutation.RealNumber.Uniform, PM); • } • Evaluate_Population(); • } ENCODING Customization GA revolution interations STRATEGY Customization You can customize your own ECODING and GAStrategy

  13. Parameter requirement for GA • For example : Rosenbrock (Real Number) problemUser must define all the parameter above.. • PopulationSize = 100, • VariableDimension= 4, • VariableLowbound = 0, • VariableUpbound = 10, (In this case, variable will be generated from 0 to 9) • RepeatableOption = “Repeatable” • EncodeType = “RealNumber” (integer number) • Iteration = 1000. • PC = 0.7 (Crossover rate) • PM = 0.3 (Mutation rate) • After excuting Run(…) method, you can retrieve the latest optimal solution information by read the variables above • Gbest(Best solution) • GbestFitness(Best fitness) “Repeatble”“Nonrepeatable” “BINARY”“NUMETRIC” “REALNUMBER”

  14. GA - TSP for Example

  15. Public methods (for general user) • Init() – (4 polymorphism) • Init (int PopulationSize, int VariableDimension, double VariableUpbound, double VariableLowbound, string EncodeType, string RepeatableOption, bool Minima) • Init (int PopulationSize, int VariableDimension, double VariableUpbound, double VariableLowbound, string EncodeType, string RepeatableOption) • Init (int PopulationSize, int VariableDimension, double [] VariableUpbound, double [] VariableLowbound, string EncodeType, string RepeatableOption, bool Minima) • Init (int PopulationSize, int VariableDimension, double [] VariableUpbound, double [] VariableLowbound, string EncodeType, string RepeatableOption) • GA Basic routine • Generate_Population(string Population_Type) • Evalutate_Population() • Reproduce_Population (string METHOD) • Crossover_Population (string Population_Type) • Mutation_Population (string METHOD, double PM) • Run() – (2 polymorphism) • Run (int Iteration) • Run (int Iteration, double PC, double PM)

  16. Methods which can be override by user • Method • public override doubleFitness(double[] Solution) • public override double Run (intIteration)

  17. GAOption Class • When you have no idea on determine the GA strategy, you could also expand the GAOption tree to find out each possible strategy combination under specific encoding. • For example : GA basic routine • Reproduce_Population(GAOption.Select.Elite); • Crossover_Population(GAOption.Crossover.NonRepeatNumetric.Order, PC); • Mutation_Population(GAOption.Mutation.Numetric.Swap_Two_Position, PM);

  18. GAOption Class

  19. GAOption Class

  20. Step 1 and 2 • using System; • using System.Collections.Generic; • using System.Text; • using System.IO; • using Metaheuristic; • namespace Testing • { • classTSP : GA • { • } • } Include our MetaYourWay library Create a problem solver class TSPwhich inheritance GA class

  21. Step 3 • using … • namespace Testing • { • classTSP : GA • { • double[,] distance = new double[10, 10]; • static void Main(string[] args) • {} • publicvoid TspRead() • { • StreamReader sr = newStreamReader(@” tsp01.txt”); • string line = sr.ReadToEnd(); • string[] AllLine = line.Split(',', '\n'); • for (int i = 0; i < distance.GetLength(0); i++) • for (int j = 0; j < distance.GetLength(1); j++) • distance[i, j] = double.Parse(AllLine[i * (distance.GetLength(1)) + j]); • sr.Close(); • } • } • } Store city distance info.

  22. Step 4 and 5 • using … • namespace Testing • { • classTSP : GA • { • double[,] distance = new double[10, 10]; • static void Main(string[] args) • { • TSPmyga = newTSP(); • } • public void Read()… } • } Creating object.

  23. Step 6 • using … • namespace Testing • { • classTSP : GA • { • double[,] distance = new double[10, 10]; • static void Main(string[] args) • { • TSPmyga = newTSP(); • } • public void Read()… • public override double Fitness(double[] solution) • { • double sum = 0; • for (int j = 0; j < solution.GetLength(0) - 1; j++) • sum = sum + distance[(int)solution[j], (int) solution[j + 1]]; • sum = sum + distance[(int) solution[solution.GetLength(0) - 1], (int) solution[0]]; • return sum; • } • } • } Override Fitness Function

  24. Step 7 • using … • namespace Testing • { • classTSP : GA • { • double[,] distance = new double[10, 10]; • double[] Low = new double[10] { 0, 0, … , 0 }; • double[] Up = new double[10] { 9, 9, … , 9 }; • static void Main(string[] args) • { • TSPmyga = newTSP(); • myga.Init(PopulationSize, VariableDimension, Up, Low, EncodeType, RepeatbleOption, Subject2Minima); • } • public void Read()… public override double Fitness(double[] solution)… • } • } If you wanna minimize the GbestFitnessSet this option to true User can use arrays to input lower bound and upper bound for each variable.

  25. Step 8 – Simple Call • using … • namespace Testing • { • classTSP : GA • { • double[,] distance = new double[10, 10]; • static void Main(string[] args) • { • TSPmyga = newTSP(); • myga.Init(PopulationSize, VariableDimension, VariableUpbound, VariableLowbound, EncodeType, RepeatbleOption, Subject2Minima); • myga.Run(1000); //myga.Run(1000,PC,PM); • } • public void Read()… public override double Fitness(double[] solution)… • } • } Polymorphism

  26. Step 8 – Advanced Call If default GA strategy routine cannot satisfy your needsYou could also customize your own strategy To do this, you must override the default Run() Method • public override void Run(int Iteration, double PC, double PM) • { • Generate_Population(“NonRepeatNumetric”); • for (int i = 0; i < Iteration; i++) • { • Evaluate_Population(); • Reproduce_Population(GAMethod.Select.Elite); • Crossover_Population(GAMethod.Crossover.NonRepeatNumetric.Order, PC); • Mutation_Population(GAMethod.Mutation.Numetric.Swap_Two_Position, PM); • } • Evaluate_Population(); • } ENCODING Customization GA revolution interations STRATEGY Customization You can customize your own ECODING and GAStrategy

  27. Parameter requirement for GA • For example : TSP problemUser must define all the parameter above.. • PopulationSize = 100, • VariableDimension= 10, • VariableLowbound = 0, • VariableUpbound = 10, (In this case, variable will be generated from 0 to 9) • RepeatableOption = “Nonrepeatable” • EncodeType = “NUMETRIC” (integer number) • Iteration = 1000. • PC = 0.7 (Crossover rate) • PM = 0.3 (Mutation rate) • After excuting Run(…) method, you can retrieve the latest optimal solution information by read the variables above • Gbest(Best solution) • GbestFitness(Best fitness) “Repeatble”“Nonrepeatable” “BINARY”“NUMETRIC” “REALNUMBER”

More Related