Presentation is loading. Please wait.

Presentation is loading. Please wait.

GA – Rosenbrock(10) for Example. Public methods (for general user) Init() – (4 polymorphism) –Init (int PopulationSize, int VariableDimension, double.

Similar presentations


Presentation on theme: "GA – Rosenbrock(10) for Example. Public methods (for general user) Init() – (4 polymorphism) –Init (int PopulationSize, int VariableDimension, double."— 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 double Fitness(double[] Solution) –public override double Run (int Iteration)

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 { class Rosenbrock : GA { } Include our MetaYourWay library Create a problem solver class Rosenbrock which inheritance GA class

8 Step 3 using … namespace Testing { class Rosenbrock : GA { static void Main(string[] args) { Rosenbrock myga = new Rosenbrock(); } public void Read()… } Create object.

9 Step 4 using … namespace Testing { class Rosenbrock : GA { static void Main(string[] args) { Rosenbrock myga = new Rosenbrock(); } 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 { class Rosenbrock : GA { double Up = 10; double Low = 0; static void Main(string[] args) { Rosenbrock myga = new Rosenbrock(); myga.Init(PopulationSize, VariableDimension, Up, Low, EncodeType, RepeatbleOption, Subject2Minima); } public override double Fitness(double[] pos)… } If you want the optimal value of GbestFitness is minimized Set this option to true User can use arrays to input lower bound and upper bound for each variable. Define variable upper / lower bound.

11 Step 6 – Simple Call using … namespace Testing { class Rosenbrock : GA { double Up = 10; double Low = 0; static void Main(string[] args) { Rosenbrock myga = new Rosenbrock (); 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 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(); } If default GA strategy routine cannot satisfy your needs You could also customize your own strategy To do this, you must override the default Run() Method You can customize your own ECODING and GA Strategy ENCODING Customization STRATEGY Customization GA revolution interations

13 Parameter requirement for GA For example : Rosenbrock (Real Number) problem User 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) “BINARY” “NUMETRIC” “REALNUMBER” “Repeatble” “Nonrepeatable”

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 double Fitness(double[] Solution) –public override double Run (int Iteration)

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

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

21 Step 3 using … namespace Testing { class TSP : GA { double[,] distance = new double[10, 10]; static void Main(string[] args) { } public void TspRead() { StreamReader sr = new StreamReader(@” 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 { class TSP : GA { double[,] distance = new double[10, 10]; static void Main(string[] args) { TSP myga = new TSP(); } public void Read()… } Creating object.

23 Step 6 using … namespace Testing { class TSP : GA { double[,] distance = new double[10, 10]; static void Main(string[] args) { TSP myga = new TSP(); } 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 { class TSP : 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) { TSP myga = new TSP(); myga.Init(PopulationSize, VariableDimension, Up, Low, EncodeType, RepeatbleOption, Subject2Minima); } public void Read()… public override double Fitness(double[] solution)… } If you wanna minimize the GbestFitness Set 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 { class TSP : GA { double[,] distance = new double[10, 10]; static void Main(string[] args) { TSP myga = new TSP(); 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 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(); } If default GA strategy routine cannot satisfy your needs You could also customize your own strategy To do this, you must override the default Run() Method You can customize your own ECODING and GA Strategy ENCODING Customization STRATEGY Customization GA revolution interations

27 Parameter requirement for GA For example : TSP problem User 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) “BINARY” “NUMETRIC” “REALNUMBER” “Repeatble” “Nonrepeatable”


Download ppt "GA – Rosenbrock(10) for Example. Public methods (for general user) Init() – (4 polymorphism) –Init (int PopulationSize, int VariableDimension, double."

Similar presentations


Ads by Google