1 / 18

ACO - TSP for Example

ACO - TSP for Example. User can use methods. Init() - polymorphism Init( int PopulationSize, int VariableDimension, double VariableLowerbound, double VariableUpperbound, string RepeatableOption, string CycleOption)

vlad
Télécharger la présentation

ACO - TSP 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. ACO - TSP for Example

  2. User can use methods • Init() - polymorphism • Init(int PopulationSize, int VariableDimension, double VariableLowerbound, double VariableUpperbound, string RepeatableOption, string CycleOption) • Init(int PopulationSize, int VariableDimension, double[] VariableLowerbound, double[] VariableUpperbound, string RepeatableOption, string CycleOption) • Run() - polymorphism • Run(int Iteration) • Run(int Iteration, double Alpha, double Beta, double GlobalPersisitenceRate, double GlobalConstant) • Run(int Iteration, double Alpha, double Beta, double LocalPersistenceRate, double LocalConstant, double GlobalPersistenceRate, double GlobalConstant) • GenerateAntPath() - polymorphism • GenerateAntPath(double Alpha, double Beta) • GenerateAntPath(double Alpha, double Beta, double LocalPersistenceRate, double LocalConstant) • GlobalPheromoneUpdate() • GlobalPheromoneUpdate(double GlobalPersistenceRate, double GlobalConstant)

  3. User can override methods • Method • public override doubleInitVisibility() • public override double Fitness(int[] solution)

  4. ACOOption Class • User used ACOOption when having no idea to determine problem options or strategy options. • ACOOption • RepeatableOption • Repeatable, Nonrepeatable • CycleOption • Cycle, Noncycle.

  5. ACOOption Class ACOOption.RepeatableOption.Repeatable ACOOption.RepeatableOption.Nonrepeatable ACOOption.CycleOption.Cycle ACOOption.CycleOption.Noncycle

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

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

  8. Step 4 and 5 • using … • namespace Testing • { • classTSP : ACO • { • double[,] distance = new double[10, 10]; • static void Main(string[] args) • { • TSPant = newTSP(); • } • public void Read()… • public override void InitVisibility() • { • for (int i = 0; i < Visibility.GetLength(0); i++) • for (int j = 0; j < Visibility.GetLength(1); j++) • Visibility[i, j] = 1 / distance[i, j]; • } • } • } Step 3: Creating object. Step 4: To override InitVisibility.

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

  10. Step 7 • using … • namespace Testing • { • classTSP : ACO • { • 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) • { • TSPant = newTSP(); • ant.Init(100, 10, 0, 9, ACOOption.RepeatableOption.Nonrepeatable, “Cycle”); • //ant.Init(100, 10, Low, Up, “Nonrepeatable”, ACOOption.RepeatableOption.Cycle); • } • public void Read()… • public override void InitVisibility()… • public override double Fitness(int[] solution)… • } • } RepeatableOption and CycleOption have two expressions of ACOOption and string. Polymorphism User can use arrays to input lower bound and upper bound for each variable.

  11. Step 8 – Simple Call • using … • namespace Testing • { • classTSP : ACO • { • double[,] distance = new double[10, 10]; • static void Main(string[] args) • { • TSPant = newTSP(); • ant.Init(100, 10, 0, 9, ACOOption.RepeatableOption.Nonrepeatable, “Cycle”); • ant.Run(1000); • //ant.Run(1000, 1, 5, 0.9, 1); • //ant.Run(1000, 1, 5, 0.9, 0.001, 0.9, 1); • } • public void Read()… • public override void InitVisibility()… • public override double Fitness(int[] solution)… • } • } Polymorphism

  12. Step 8 – Advanced Call • using … • namespace Testing • { • classTSP : ACO • { • double[,] distance = new double[10, 10]; • static void Main(string[] args) • { • TSPant = newTSP(); • ant.Init(100, 10, 0, 9, ACOOption.RepeatableOption.Nonrepeatable, “Cycle”); • for (int iter = 1; iter <= 1000; iter++) • { • ant.GenerateAntPath(1, 5); • //ant.GenerateAntPath(1, 5, 0.9, 0.001); • ant.GlobalPheromoneUpdate(0.9, 1); • } • } • public void Read()… • public override void InitVisibility()… • public override double Fitness(int[] solution)… • } • } Polymorphism

  13. User requirement 1 for TSP • User requirement. • PopulationSize = 100, VariableDimension = 10, VariableLowerbound = 0, VariableUpperbound = 9, RepeatableOption = “Nonrepeatable”, CycleOption = “Cycle”. • Iteration = 1000. • State transition rule • Alpha = 1, Beta = 5 • Global pheromone update. • GlobalPersisitenceRate = 0.9, GlobalConstant = 1. • We will give two examples to satisfy him if user has requirement above. • User can access public attributes for Gbest (the best solution for global) and GbestFitness (the best fitness for global).

  14. Example 1 - Simple Call • using … • namespace Testing • { • classTSP : ACO • { • double[,] distance = new double[10, 10]; • static void Main(string[] args) • { • TSPant = newTSP(); • ant.Init(100, 10, 0, 9, ACOOption.RepeatableOption.Nonrepeatable, • ACOOption.RepeatableOption.Cycle); • ant.Run(1000, 1, 5, 0.9, 1); • } • public void Read()… • public override void InitVisibility()… • public override double Fitness(int[] solution)… • } • }

  15. Example 2 - Advanced Call • using … • namespace Testing • { • classTSP : ACO • { • double[,] distance = new double[10, 10]; • static void Main(string[] args) • { • TSPant = newTSP(); • ant.Init(100, 10, 0, 9, ACOOption.RepeatableOption.Nonrepeatable, • ACOOption.RepeatableOption.Cycle); • for (int iter = 1; iter <= 1000; iter++) • { • ant.GenerateAntPath(1, 5); • ant.GlobalPheromoneUpdate(0.9, 1); • } • } • public void Read()… • public override void InitVisibility()… • public override double Fitness(int[] solution)… • } • }

  16. User requirement 2 for TSP • User requirement. • PopulationSize = 100, VariableDimension = 10, VariableLowerbound = 0, VariableUpperbound = 9, RepeatableOption = “Nonrepeatable”, CycleOption = “Cycle”. • Iteration = 1000. • State transition rule • Alpha = 1, Beta = 5 • Local pheromone update. • LocalPersisitenceRate = 0.9, LocalConstant = 0.001. • Global pheromone update. • GlobalPersisitenceRate = 0.9, GlobalConstant = 1. • We will give two examples to satisfy him if user has requirement above. • User can access public attributes for Gbest (the best solution for global) and GbestFitness (the best fitness for global).

  17. Example 1 - Simple Call • using … • namespace Testing • { • classTSP : ACO • { • double[,] distance = new double[10, 10]; • static void Main(string[] args) • { • TSPant = newTSP(); • ant.Init(100, 10, 0, 9, ACOOption.RepeatableOption.Nonrepeatable, • ACOOption.RepeatableOption.Cycle); • ant.Run(1000, 1, 5, 0.9, 0.001, 0.9, 1); • } • public void Read()… • public override void InitVisibility()… • public override double Fitness(int[] solution)… • } • }

  18. Example 2 - Advanced Call • using … • namespace Testing • { • classTSP : ACO • { • double[,] distance = new double[10, 10]; • static void Main(string[] args) • { • TSPant = newTSP(); • ant.Init(100, 10, 0, 9, ACOOption.RepeatableOption.Nonrepeatable, • ACOOption.RepeatableOption.Cycle); • for (int iter = 1; iter <= 1000; iter++) • { • ant.GenerateAntPath(1, 5, 0.9, 0.001); • ant.GlobalPheromoneUpdate(0.9, 1); • } • } • public void Read()… • public override void InitVisibility()… • public override double Fitness(int[] solution)… • } • }

More Related