Presentation is loading. Please wait.

Presentation is loading. Please wait.

PSO – Rosenbrock(10) for Example. User can use methods Init() - polymorphism –Init(int PopulationSize, int VariableDimension, double VariableLowerbound,

Similar presentations


Presentation on theme: "PSO – Rosenbrock(10) for Example. User can use methods Init() - polymorphism –Init(int PopulationSize, int VariableDimension, double VariableLowerbound,"— Presentation transcript:

1 PSO – Rosenbrock(10) for Example

2 User can use methods Init() - polymorphism –Init(int PopulationSize, int VariableDimension, double VariableLowerbound, double VariableUpperbound, string RepeatableOption) –Init(int PopulationSize, int VariableDimension, double[] VariableLowerbound, double[] VariableUpperbound, string RepeatableOption) Run() –Run(int Iteration) Update() - polymorphism –Update(string FirstGuidingPoint, string SecondGuidingPoint) –Update(string FirstGuidingPoint, string SecondGuidingPoint, string ThirdGuidingPoint)

3 User can override attributes and methods Attribute (lSize default is 3 and RefSet default is 10) –public override int lSize { get { return 5; } } –public override int RefSetSize { get { return 20; }} Method –public override double Fitness(double[] sol)

4 PSOOption Class User used PSOOption when having no idea to determine problem options or strategy options. PSOOption –RepeatableOption Repeatable, Nonrepeatable –FirstGuidingPoint Pbest, Lbest, Gbest, Random, RefSet –SecondGuidingPoint Pbest, Lbest, Gbest, Random, RefSet –ThirdGuidingPoint Pbest, Lbest, Gbest, Random, RefSet

5 PSOOption Class PSOOption.RepeatableOption.Repeatable PSOOption.RepeatableOption.Nonrepeatable PSOOption.FirstGuidingPoint.Pbset PSOOption.FirstGuidingPoint.Lbset PSOOption.FirstGuidingPoint.Gbset PSOOption.FirstGuidingPoint.RefSet PSOOption.FirstGuidingPoint.Random PSOOption.SecondGuidingPoint.Pbset PSOOption.SecondGuidingPoint.Lbset PSOOption.SecondGuidingPoint.Gbset PSOOption.SecondGuidingPoint.RefSet PSOOption.SecondGuidingPoint.Random PSOOption.ThirdGuidingPoint.Pbset PSOOption.ThirdGuidingPoint.Lbset PSOOption.ThirdGuidingPoint.Gbset PSOOption.ThirdGuidingPoint.RefSet PSOOption.ThirdGuidingPoint.Random

6 Step 1 and 2 using System; using System.Collections.Generic; using System.Text; using Metaheuristic; namespace Testing { class Rosenbrock : PSO { } Step 1: Include Metaheuristic. Step2: Problem class must inherit PSO.

7 Step 3 and 4 using … namespace Testing { class Rosenbrock : PSO { static void Main(string[] args) { Rosenbrock bird = 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; } Step 3: Creating object. Step 4: To override Fitness function.

8 Step 5 using … namespace Testing { class Rosenbrock : PSO { double[] Low = new double[10] { -10, -10, …, -10 }; double[] Up = new double[10] { 10, 10, …, 10 }; static void Main(string[] args) { Rosenbrock bird = new Rosenbrock(); bird.Init(40, 10, -10, 10, PSOOption.RepeatableOption.Repeatable); //bird.Init(40, 10, Low, Up, “Repeatable”); } public override double Fitness(double[] pos)… } User can use arrays to input lower bound and upper bound for each variable. Polymorphism RepeatableOption has two expressions of PSOOption and string.

9 Step 6 – Simple Call using … namespace Testing { class Rosenbrock : PSO { static void Main(string[] args) { Rosenbrock bird = new Rosenbrock(); bird.Init(40, 10, -10, 10, “Repeatable”); bird.Run(4000); } public override double Fitness(double[] pos)… } Default is Constriction Factor PSO

10 Step 6 – Advanced Call using … namespace Testing { class Rosenbrock : PSO { static void Main(string[] args) { //public override int lSize { get { return 5; } } //public override int RefSetSize { get { return 20; }} Rosenbrock bird = new Rosenbrock(); bird.Init(40, 10, -10, 10, “Repeatable”); for (int iter = 1; iter <= 4000; iter++) bird.Update(); //bird.Update(“Pbest”, PSOOption.SecondGuidingPoint.Lbest); //bird.Update(PSOOption.FirstGuidingPoint.Pbest, “Gbest", “RefSet"); } public override double Fitness(double[] pos)… } Polymorphism FirstGuidingPoint, SecondGuidingPoint and ThirdGuidingPoint have two expressions of PSOOption and string. If user used Lbest or RefSet as guiding point, user would override lSize and RefSetSize.

11 User requirement 1 for Rosenbrock(10) User requirement. –PopulationSize = 40, VariableDimension = 10, VariableLowerbound = -10, VariableUpperbound = 10, RepeatableOption = “Repeatable”. –Iteration = 4000. –Using two guiding points of pbest and gbest. We will give three examples to satisfy him if user has requirement above. User can access public attributes for Gbest (the best sol for global) and GbestFitness (the best fitness for global).

12 Example 1 – Simple Call using … namespace Testing { class Rosenbrock : PSO { static void Main(string[] args) { Rosenbrock bird = new Rosenbrock(); bird.Init(40, 10, -10, 10, PSOOption.RepeatableOption.Repeatable ); bird.Run(4000); } public override double Fitness(double[] pos)… }

13 Example 2 – Advanced Call using … namespace Testing { class Rosenbrock : PSO { static void Main(string[] args) { Rosenbrock bird = new Rosenbrock(); bird.Init(40, 10, -10, 10, PSOOption.RepeatableOption.Repeatable ); for (int iter = 1; iter <= 4000; iter++) bird.Update(); } public override double Fitness(double[] pos)… }

14 Example 3 – Advanced Call using … namespace Testing { class Rosenbrock : PSO { static void Main(string[] args) { Rosenbrock bird = new Rosenbrock(); bird.Init(40, 10, -10, 10, PSOOption.RepeatableOption.Repeatable ); for (int iter = 1; iter <= 4000; iter++) bird.Update(PSOOption.FirstGuidingPoint.Pbest, PSOOption.SecondGuidingPoint.Gbest); } public override double Fitness(double[] pos)… }

15 User requirement 2 for Rosenbrock(10) User requirement. –PopulationSize = 40, VariableDimension = 10, VariableLowerbound = -10, VariableUpperbound = 10, RepeatableOption = “Repeatable”. –Iteration = 4000. –Using two guiding points of pbest and lbest. We will give an example to satisfy him if user has requirement above. User can access public attributes for Gbest (the best sol for global) and GbestFitness (the best fitness for global).

16 Example 1 – Advanced Call using … namespace Testing { class Rosenbrock : PSO { public override int lSize { get { return 5; } } static void Main(string[] args) { Rosenbrock bird = new Rosenbrock(); bird.Init(40, 10, -10, 10, PSOOption.RepeatableOption.Repeatable ); for (int iter = 1; iter <= 4000; iter++) bird.Update(PSOOption.FirstGuidingPoint.Pbest, PSOOption.SecondGuidingPoint.Lbest); } public override double Fitness(double[] pos)… }

17 User requirement 3 for Rosenbrock(10) User requirement. –PopulationSize = 40, VariableDimension = 10, VariableLowerbound = -10, VariableUpperbound = 10, RepeatableOption = “Repeatable”. –Iteration = 4000. –Using three guiding points of pbest, gbest and RefSet. We will give an example to satisfy him if user has requirement above. User can access public attributes for Gbest (the best sol for global) and GbestFitness (the best fitness for global).

18 Example 1 – Advanced Call using … namespace Testing { class Rosenbrock : PSO { public override int RefSetSize { get { return 20; } } static void Main(string[] args) { Rosenbrock bird = new Rosenbrock(); bird.Init(40, 10, -10, 10, PSOOption.RepeatableOption.Repeatable ); for (int iter = 1; iter <= 4000; iter++) bird.Update(PSOOption.FirstGuidingPoint.Pbest, PSOOption.SecondGuidingPoint.Gbest PSOOption.ThirdGuidingPoint.RefSet); } public override double Fitness(double[] pos)… }

19 PSO – TSP for Example

20 User can use methods Init() - polymorphism –Init(int PopulationSize, int VariableDimension, double VariableLowerbound, double VariableUpperbound, string RepeatableOption) –Init(int PopulationSize, int VariableDimension, double[] VariableLowerbound, double[] VariableUpperbound, string RepeatableOption) Run() –Run(int Iteration) Update() - polymorphism –Update(string FirstGuidingPoint, string SecondGuidingPoint) –Update(string FirstGuidingPoint, string SecondGuidingPoint, string ThirdGuidingPoint)

21 User can override attributes and methods Attribute (lSize default is 3 and RefSet default is 10) –public override int lSize { get { return 5; } } –public override int RefSetSize { get { return 20; }} Method –public override double Fitness(double[] sol)

22 PSOOption Class User used PSOOption when having no idea to determine problem options or strategy options. PSOOption –RepeatableOption Repeatable, Nonrepeatable –FirstGuidingPoint Pbest, Lbest, Gbest, Random, RefSet –SecondGuidingPoint Pbest, Lbest, Gbest, Random, RefSet –ThirdGuidingPoint Pbest, Lbest, Gbest, Random, RefSet

23 PSOOption Class PSOOption.RepeatableOption.Repeatable PSOOption.RepeatableOption.Nonrepeatable PSOOption.FirstGuidingPoint.Pbset PSOOption.FirstGuidingPoint.Lbset PSOOption.FirstGuidingPoint.Gbset PSOOption.FirstGuidingPoint.RefSet PSOOption.FirstGuidingPoint.Random PSOOption.SecondGuidingPoint.Pbset PSOOption.SecondGuidingPoint.Lbset PSOOption.SecondGuidingPoint.Gbset PSOOption.SecondGuidingPoint.RefSet PSOOption.SecondGuidingPoint.Random PSOOption.ThirdGuidingPoint.Pbset PSOOption.ThirdGuidingPoint.Lbset PSOOption.ThirdGuidingPoint.Gbset PSOOption.ThirdGuidingPoint.RefSet PSOOption.ThirdGuidingPoint.Random

24 Step 1 and 2 using System; using System.Collections.Generic; using System.Text; using Metaheuristic; namespace Testing { class TSP : PSO { } Step 1: Include Metaheuristic. Step2: Problem class must inherit PSO.

25 Step 3 using … namespace Testing { class TSP : PSO { double[,] distance = new double[10, 10]; static void Main(string[] args) { } public void Read() { 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(); } To read city distance.

26 Step 4 and 5 using … namespace Testing { class TSP : ACO { double[,] distance = new double[10, 10]; static void Main(string[] args) { TSP bird = new TSP(); } public void Read()… public override double Fitness(double[] sol) { double sum = 0; for (int j = 0; j < sol.GetLength(0) - 1; j++) sum = sum + distance[(int)Math.Round(sol[j]), (int)Math.Round(sol[j + 1])]; sum = sum + distance[(int)Math.Round(sol[sol.GetLength(0) - 1]), (int)Math.Round(sol[0])]; return sum; } Step 4: Creating object. Step 5: To override Fitness function.

27 Step 6 using … namespace Testing { class TSP : PSO { 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 bird = new TSP(); bird.Init(40, 10, 0, 9, PSOOption.RepeatableOption.Nonrepeatable); //bird.Init(40, 10, Low, Up, “Nonrepeatable”); } public void Read()… public override double Fitness(int[] sol)… } User can use arrays to input lower bound and upper bound for each variable. RepeatableOption has two expressions of PSOOption and string. Polymorphism

28 Step 7 - Simple Call using … namespace Testing { class TSP : PSO { double[,] distance = new double[10, 10]; static void Main(string[] args) { TSP bird = new TSP(); bird.Init(40, 10, 0, 9, PSOOption.RepeatableOption.Nonrepeatable); bird.Run(4000); } public void Read()… public override double Fitness(int[] sol)… }

29 Step 7 - Advanced Call using … namespace Testing { class TSP : PSO { double[,] distance = new double[10, 10]; //public override int lSize { get { return 5; } } //public override int RefSetSize { get { return 20; }} static void Main(string[] args) { TSP bird = new TSP(); bird.Init(40, 10, 0, 9, PSOOption.RepeatableOption.Nonrepeatable); for (int iter = 1; iter <= 4000; iter++) bird.Update(); //bird.Update(“Pbest”, PSOOption.SecondGuidingPoint.Lbest); //bird.Update(PSOOption.FirstGuidingPoint.Pbest, “Gbest", “RefSet"); } public void Read()… public override double Fitness(int[] sol)… } Polymorphism FirstGuidingPoint, SecondGuidingPoint and ThirdGuidingPoint have two expressions of PSOOption and string. If user used Lbest or RefSet as guiding point, user would override lSize and RefSetSize.

30 User requirement 1 for TSP User requirement. –PopulationSize = 40, VariableDimension = 10, VariableLowerbound = 0, VariableUpperbound = 9, RepeatableOption = “Nonrepeatable”. –Iteration = 4000. –Using two guiding points of pbest and gbest. We will give three examples to satisfy him if user has requirement above. User can access public attributes for Gbest (the best sol for global) and GbestFitness (the best fitness for global).

31 Example 1 – Simple Call using … namespace Testing { class TSP : PSO { double[,] distance = new double[10, 10]; static void Main(string[] args) { TSP bird = new TSP(); bird.Init(40, 10, 0, 9, “Nonrepeatable”); bird.Run(4000); } public void Read()… public override double Fitness(int[] sol)… }

32 Example 2 – Advanced Call using … namespace Testing { class TSP : PSO { double[,] distance = new double[10, 10]; static void Main(string[] args) { TSP bird = new TSP(); bird.Init(40, 10, 0, 9, “Nonrepeatable”); for (int iter = 1; iter <= 4000; iter++) bird.Update(); } public void Read()… public override double Fitness(int[] sol)… }

33 Example 3 – Advanced Call using … namespace Testing { class TSP : PSO { double[,] distance = new double[10, 10]; static void Main(string[] args) { TSP bird = new TSP(); bird.Init(40, 10, 0, 9, “Nonrepeatable”); for (int iter = 1; iter <= 4000; iter++) bird.Update(“Pbest”, “Gbest”); } public void Read()… public override double Fitness(int[] sol)… }

34 User requirement 2 for TSP User requirement. –PopulationSize = 40, VariableDimension = 10, VariableLowerbound = 0, VariableUpperbound = 9, RepeatableOption = “Nonrepeatable”. –Iteration = 4000. –Using two guiding points of pbest and lbest. We will give an example to satisfy him if user has requirement above. User can access public attributes for Gbest (the best sol for global) and GbestFitness (the best fitness for global).

35 Example 1 – Advanced Call using … namespace Testing { class TSP : PSO { public override int lSize { get { return 5; } } static void Main(string[] args) { TSP bird = new TSP(); bird.Init(40, 10, 0, 9, “Nonrepeatable”); for (int iter = 1; iter <= 4000; iter++) bird.Update(“Pbest”, “Lbest”); } public void Read()… public override double Fitness(int[] sol)… }

36 User requirement 3 for TSP User requirement. –PopulationSize = 40, VariableDimension = 10, VariableLowerbound = 0, VariableUpperbound = 9, RepeatableOption = “Nonrepeatable”. –Iteration = 4000. –Using three guiding points of pbest, gbest and RefSet. We will give an example to satisfy him if user has requirement above. User can access public attributes for Gbest (the best sol for global) and GbestFitness (the best fitness for global).

37 Example 1 – Advanced Call using … namespace Testing { class TSP : PSO { public override int RefSetSize { get { return 20; } } static void Main(string[] args) { TSP bird = new TSP(); bird.Init(40, 10, 0, 9, “Nonrepeatable”); for (int iter = 1; iter <= 4000; iter++) bird.Update(“Pbest”, “Gbest”, “RefSet”); public void Read()… public override double Fitness(int[] sol)… } }


Download ppt "PSO – Rosenbrock(10) for Example. User can use methods Init() - polymorphism –Init(int PopulationSize, int VariableDimension, double VariableLowerbound,"

Similar presentations


Ads by Google