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

Slides:



Advertisements
Similar presentations
COMP 110: Introduction to Programming Tyler Johnson Mar 25, 2009 MWF 11:00AM-12:15PM Sitterson 014.
Advertisements

Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Basic Java Constructs and Data Types – Nuts and Bolts
Introduction to Java 2 Programming Lecture 5 Array and Collections.
Lecture 4 More on Java® Data Types, Control Structures.
Towers of Hanoi Move n (4) disks from pole A to pole C such that a disk is never put on a smaller disk A BC ABC.
Recursion Chapter 14. Overview Base case and general case of recursion. A recursion is a method that calls itself. That simplifies the problem. The simpler.
Particle Swarm Optimization (PSO)
The ArrayList Class and the enum Keyword
1 / / / /. 2 (Object) (Object) –, 10 (Class) (Class) –, –, – (Variables) [ Data member Field Attribute](, ) – (Function) [ Member function Method Operation.
1 Lecture 16/3/11: Contents Example of an array of user-defined objects: Car and Carr Constructor Providing functionalities for a user- defined object.
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
Chapter 8: Arrays.
EXAMPLES (Arrays). Example Many engineering and scientific applications represent data as a 2-dimensional grid of values; say brightness of pixels in.
1.A computer game is an example of A.system software; B.a compiler; C.application software; D.hardware; E.none of the above. 2.JVM stands for: A.Java Virtual.
Firefly Synchronisation Java Demo in 1D Array. 1 Dimension Firefly in Java two neighbors 1. Initialization: 2.
1 Arrays An array is a special kind of object that is used to store a collection of data. The data stored in an array must all be of the same type, whether.
Purpose : To convert this string to a new character array. Return Type : char[ ] Parameters : none Declaration : public char[ ] toCharArray() Returns.
Review BP Dari slide pak cahyo pertemuan 7 dan pertemuan 2 dengan sedikit modifikasi.
Chapter 5 Arrays F Introducing Arrays F Declaring Array Variables, Creating Arrays, and Initializing Arrays F Passing Arrays to Methods F Copying Arrays.
Introduction to Arrays Chapter What is an array? An array is an ordered collection that stores many elements of the same type within one variable.
Java POWERED BY: ARVIND DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING RADHA GOVIND GROUP OF INSTITUTIONS,MEERUT.
Polymorphism Method overriding Method overloading Dynamic binding 1.
Air Force Institute of Technology Electrical and Computer Engineering
The Line Class Suppose you are involved in the development of a large mathematical application, and this application needs an object to represent a Line.
1 MATH METHODS THAT RETURN VALUES. 2 JAVA'S MATH CLASS.
Objects contains data and methods Class – type of object Create class first Then object or instance String – defined class String s; // creates instance.
Java Programming 2 Dr. Priti Srinivas Sajja Introductory concepts of java programming as specified in PGDCA 203:Object Technology, S P University.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Lecture 15.1 Static Methods and Variables. © 2006 Pearson Addison-Wesley. All rights reserved Static Methods In Java it is possible to declare.
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
CS324e - Elements of Graphics and Visualization A Little Java A Little Python.
Hand Crafting your own program By Eric Davis for CS103.
ACO - TSP for Example. User can use methods Init() - polymorphism –Init(int PopulationSize, int VariableDimension, double VariableLowerbound, double VariableUpperbound,
GA – Rosenbrock(10) for Example. Public methods (for general user) Init() – (4 polymorphism) –Init (int PopulationSize, int VariableDimension, double.
Review CSC 171 FALL 2004 LECTURE 21. Topics Objects and Classes Fundamental Types Graphics and Applets Decisions Iteration Designing Classes Testing and.
TS - TSP for Example. User can use methods Init() - polymorphism –Init(int NeighborSize,int VariableDimension, int VaraibleLowerbound, int VariableUpperbound,
10 ThinkOfANumber program1July ThinkOfANumber program CE : Fundamental Programming Techniques.
Using FangEngine The FangEngine is created by Brian C. Ladd & Jam Jenkins Presentation by Pepper With much credit to: Jenkins, Jam & Brian C. Ladd. Introductory.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
1 Review of Java Higher Level Language Concepts –Names and Reserved Words –Expressions and Precedence of Operators –Flow of Control – Selection –Flow of.
C# Programming Fundamentals of Object-Oriented Programming Fundamentals of Object-Oriented Programming Introducing Microsoft.NET Introducing Microsoft.NET.
Hongfeng Wang Pusan, Korea.  Introduction  General framwork of GA  An example of GA programming 2.
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
Core Java: Essential Features 08/05/2015 Kien Tran.
Applied Computing Technology Laboratory QuickStart C# Learning to Program in C# Amy Roberge & John Linehan November 7, 2005.
Calculations Chapter 11 Library of math functions, and constants cos, sin, tan, abs, min, max, log, random, sqrt, pow, exp Constants.PI,.E Use care with.
1 CSC 201: Computer Programming I Lecture 2 B. S. Afolabi.
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
11/2: Math.random, more methods About DrawLine.java modifications –allow user input –draw a curve Method definitions Math.random()
Chapter 3A Strings. Using Predefined Classes & Methods in a Program To use a method you must know: 1.Name of class containing method (Math) 2.Name of.
7/31: Math.random, more methods About DrawLine.java modifications –allow user input –draw a curve Method definitions Math.random()
Java Programming Final Keyword In Java. final keyword The final keyword in java is used to restrict the user. The final keyword can be used in many context.
1 Advanced Programming Examples Output. Show the exact output produced by the following code segment. char[,] pic = new char[6,6]; for (int i = 0; i
Classes - Intermediate
Mid-Year Review. Coding Problems In general, solve the coding problems by doing it piece by piece. Makes it easier to think about Break parts of code.
E-commerce customization Petr Vozak, Technical Leader.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
 Introduction  Particle swarm optimization  PSO algorithm  PSO solution update in 2-D  Example.
using System; namespace Demo01 { class Program
Particle Swarm Optimization
PSO -Introduction Proposed by James Kennedy & Russell Eberhart in 1995
Java Programming: Guided Learning with Early Objects
CS360 Windows Programming
Chapter 2.
Multi-band impedance matching using an evolutionary algorithm
Conditional Statements
class PrintOnetoTen { public static void main(String args[]) {
Object-Oriented Programming
Random Numbers while loop
Presentation transcript:

PSO – Rosenbrock(10) for Example

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)

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)

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

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

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.

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 * 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.

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.

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

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.

User requirement 1 for Rosenbrock(10) User requirement. –PopulationSize = 40, VariableDimension = 10, VariableLowerbound = -10, VariableUpperbound = 10, RepeatableOption = “Repeatable”. –Iteration = –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).

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)… }

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)… }

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)… }

User requirement 2 for Rosenbrock(10) User requirement. –PopulationSize = 40, VariableDimension = 10, VariableLowerbound = -10, VariableUpperbound = 10, RepeatableOption = “Repeatable”. –Iteration = –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).

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)… }

User requirement 3 for Rosenbrock(10) User requirement. –PopulationSize = 40, VariableDimension = 10, VariableLowerbound = -10, VariableUpperbound = 10, RepeatableOption = “Repeatable”. –Iteration = –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).

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)… }

PSO – TSP for Example

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)

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)

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

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

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.

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 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.

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.

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

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)… }

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.

User requirement 1 for TSP User requirement. –PopulationSize = 40, VariableDimension = 10, VariableLowerbound = 0, VariableUpperbound = 9, RepeatableOption = “Nonrepeatable”. –Iteration = –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).

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)… }

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)… }

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)… }

User requirement 2 for TSP User requirement. –PopulationSize = 40, VariableDimension = 10, VariableLowerbound = 0, VariableUpperbound = 9, RepeatableOption = “Nonrepeatable”. –Iteration = –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).

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)… }

User requirement 3 for TSP User requirement. –PopulationSize = 40, VariableDimension = 10, VariableLowerbound = 0, VariableUpperbound = 9, RepeatableOption = “Nonrepeatable”. –Iteration = –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).

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)… } }