Submit: Your group source code to mooshak

Similar documents
Evolutionary Computation, 2018/2019 Programming assignment 3

Suppose you have a problem You don t know how to solve it What can you do? Can you use a computer to somehow find a solution for you?

Multi-objective Optimization

Genetic Algorithms for Vision and Pattern Recognition

Genetic Algorithms. Kang Zheng Karl Schober

Genetic Algorithms. Genetic Algorithms

Genetic Algorithms Variations and Implementation Issues

Introduction to Genetic Algorithms. Based on Chapter 10 of Marsland Chapter 9 of Mitchell

CHAPTER 6 REAL-VALUED GENETIC ALGORITHMS

A New Selection Operator - CSM in Genetic Algorithms for Solving the TSP

GENETIC ALGORITHM with Hands-On exercise

Project C: Genetic Algorithms

Chapter 14 Global Search Algorithms

Artificial Intelligence Application (Genetic Algorithm)

COMP 110 Programming Exercise: Simulation of the Game of Craps

Evolutionary Computation. Chao Lan

Genetic Algorithms. PHY 604: Computational Methods in Physics and Astrophysics II

Automata Construct with Genetic Algorithm

Genetic Algorithms. Chapter 3

GENETIC ALGORITHM VERSUS PARTICLE SWARM OPTIMIZATION IN N-QUEEN PROBLEM

ARTIFICIAL INTELLIGENCE (CSCU9YE ) LECTURE 5: EVOLUTIONARY ALGORITHMS

What is GOSET? GOSET stands for Genetic Optimization System Engineering Tool

[Premalatha, 4(5): May, 2015] ISSN: (I2OR), Publication Impact Factor: (ISRA), Journal Impact Factor: 2.114

An elementary introduction to Matlab programming for stochastic optimization

4/22/2014. Genetic Algorithms. Diwakar Yagyasen Department of Computer Science BBDNITM. Introduction

Introduction to Optimization

Introduction to Optimization

Introduction to Genetic Algorithms

Computational Intelligence

Heuristic Optimisation

The Binary Genetic Algorithm. Universidad de los Andes-CODENSA

A THREAD BUILDING BLOCKS BASED PARALLEL GENETIC ALGORITHM

Comparative Analysis of Genetic Algorithm Implementations

Genetic Algorithms: Setting Parmeters and Incorporating Constraints OUTLINE OF TOPICS: 1. Setting GA parameters. 2. Constraint Handling (two methods)

A Steady-State Genetic Algorithm for Traveling Salesman Problem with Pickup and Delivery

Santa Fe Trail Problem Solution Using Grammatical Evolution

Neural Network Weight Selection Using Genetic Algorithms

Pseudo-code for typical EA

Using Genetic Algorithm to Break Super-Pascal Knapsack Cipher

Genetic Algorithms Presented by: Faramarz Safi (Ph.D.) Faculty of Computer Engineering Islamic Azad University, Najafabad Branch.

Planning and Search. Genetic algorithms. Genetic algorithms 1

Adaptive Crossover in Genetic Algorithms Using Statistics Mechanism

Midterm Examination CS540-2: Introduction to Artificial Intelligence

Lecture 6: Genetic Algorithm. An Introduction to Meta-Heuristics, Produced by Qiangfu Zhao (Since 2012), All rights reserved

CHAPTER 4 GENETIC ALGORITHM

A Genetic Algorithm for Graph Matching using Graph Node Characteristics 1 2

A Hybrid Genetic Algorithm for a Variant of Two-Dimensional Packing Problem

A Genetic Algorithm-Based Approach for Energy- Efficient Clustering of Wireless Sensor Networks

Optimization of Test Scheduling and Test Access for ITC-02 SOC Benchmark Circuits

Information Fusion Dr. B. K. Panigrahi

CS5401 FS2015 Exam 1 Key

Mutations for Permutations

CS 116. Lab Assignment # 1 1

Genetic Algorithms for EQ-algebras Automatic Generation

The Genetic Algorithm for finding the maxima of single-variable functions

Genetic Algorithms For Vertex. Splitting in DAGs 1

Using Genetic Algorithms to Solve the Box Stacking Problem

Partitioning Sets with Genetic Algorithms

CHAPTER 4 FEATURE SELECTION USING GENETIC ALGORITHM

Tutorial 03. Exercise 1: CSC111 Computer Programming I

Improvement of Web Search Results using Genetic Algorithm on Word Sense Disambiguation

International Journal of Scientific & Engineering Research Volume 8, Issue 10, October-2017 ISSN

General Instructions. You can use QtSpim simulator to work on these assignments.

UNC Charlotte 2010 Comprehensive

A Comparative Study of Linear Encoding in Genetic Programming

Multi-Objective Optimization Using Genetic Algorithms

Comparative Study on VQ with Simple GA and Ordain GA

Optimization Technique for Maximization Problem in Evolutionary Programming of Genetic Algorithm in Data Mining

METAHEURISTICS Genetic Algorithm

Evolutionary Linkage Creation between Information Sources in P2P Networks

An elementary introduction to Matlab programming for stochastic optimization

METAHEURISTICS. Introduction. Introduction. Nature of metaheuristics. Local improvement procedure. Example: objective function

Genetic Algorithm for Dynamic Capacitated Minimum Spanning Tree

CSCI 136 Data Structures & Advanced Programming. Lecture 12 Fall 2018 Profs Bill & Jon

Introduction to Design Optimization: Search Methods

CMPS 11 Introduction to Programming Midterm 1 Review Problems

The Probabilistic Method

Using Genetic Algorithms in Integer Programming for Decision Support

A HYBRID APPROACH IN GENETIC ALGORITHM: COEVOLUTION OF THREE VECTOR SOLUTION ENCODING. A CASE-STUDY

Another Case Study: Genetic Algorithms

ANTICIPATORY VERSUS TRADITIONAL GENETIC ALGORITHM

Reading Input from Text File

LECTURE 3 ALGORITHM DESIGN PARADIGMS

Optimization of Function by using a New MATLAB based Genetic Algorithm Procedure

Job Shop Scheduling Problem (JSSP) Genetic Algorithms Critical Block and DG distance Neighbourhood Search

Chapter 4: Conditionals and Recursion

Dynamic Vehicle Routing Using Hybrid Genetic Algorithms

Algorithm Design Paradigms

Genetic Algorithm for optimization using MATLAB

Building Java Programs

Escaping Local Optima: Genetic Algorithm

Outline. Motivation. Introduction of GAs. Genetic Algorithm 9/7/2017. Motivation Genetic algorithms An illustrative example Hypothesis space search

Graphical Approach to Solve the Transcendental Equations Salim Akhtar 1 Ms. Manisha Dawra 2

Local Search. CS 486/686: Introduction to Artificial Intelligence Winter 2016

The k-means Algorithm and Genetic Algorithm

Artificial Intelligence

Global Optimization. for practical engineering applications. Harry Lee 4/9/2018 CEE 696

Lab1 Solution. Lab2 Solution. MathTrick.java. CoinFlip.java

An Application of Genetic Algorithms to University Timetabling

Genetic programming. Lecture Genetic Programming. LISP as a GP language. LISP structure. S-expressions

Transcription:

Tutorial 2 (Optional) Genetic Algorithms This is an optional tutorial. Should you decide to answer it please Submit: Your group source code to mooshak http://mooshak.deei.fct.ualg.pt/ up to May 28, 2018. Consider the following code that generates always the same sequence of n double random numbers between 0 and 1, and output them in a specified format. import java.util.*; import java.text.*; public class Mina { public static void main(string[] args) { Random generator = new Random(0); Scanner sc = new Scanner(System.in); int n= sc.nextint(); double d; DecimalFormatSymbols unusualsymbols = new DecimalFormatSymbols(); unusualsymbols.setdecimalseparator('.'); DecimalFormat df = new DecimalFormat("0.00", unusualsymbols); } } for (int i=0; i< n; i++) { d = generator.nextdouble(); System.out.println(df.format(d)); } sc.close(); http://w3.ualg.pt/~jvo/ia IA Lab 4-1

Problem E: Initializing a population You are going to initialize a population of N binary strings of length l. As you know, the genetic algorithm uses pseudo random numbers in its operation, and the output is non-deterministic. In order to eliminate the non-determinism, use the random number generated provided in the code above. Now, let u be random number in [0, 1). If you want to generate a random bit b, you should assume that b = 0 if u < 0.5, and b = 1 otherwise. You should use the first l random numbers to generate the first string, the next random numbers to generate the second string, and so on. The input contains 2 lines. The first line contains a natural number N that specifies the size of the population. The second line contains a natural number l that specifies the string (chromosome) length. The output should be a population of N binary strings of length l, with each string being followed by a newline character. 4 3 Sample 101 110 011 100 http://w3.ualg.pt/~jvo/ia IA Lab 4-2

Problem F: onemax The onemax problem is probably the most widely tested problem in the evolutionary computation field. The objective of the problem is to maximize a function that returns the number of 1s in an input string. The input has a binary string. You can assume that the string length 1000. The output should be the value returned by the onemax function, followed by a newline character. 11010011 Sample 5 http://w3.ualg.pt/~jvo/ia IA Lab 4-3

Problem G: f(x) = x 2 You should implement another fitness function. This one interprets the input string as the binary representation of an integer in base 10, and returns the square of that number. You should consider the leftmost bit to be the most significant one. The input has a binary string of length l. You can assume that l 10. The output should be the value returned by the function, followed by a newline character. 1101 Sample 169 http://w3.ualg.pt/~jvo/ia IA Lab 4-4

Problem H: binary tournament selection You should implement tournament selection. Given a population of N strings with the corresponding fitness values, you are supposed to simulate N tournaments. For each tournament you should pick 2 solutions at random from the population. The winner has the higher fitness. In case of a tie, please assume that the first solution is the winner of the tournament. In order to perform this operation on a population of size N, you are going to use 2 N random numbers. Each random number belongs to the interval [0..1), and you will need to map it into an integer random number in the [a..b] interval. (Think about what is a and b in your case). To do that you can do the following procedure. Let u be a random number in [0..1). The desired integer random number in [a..b] can be calculated as a + round(u b a) The input has 2 lines + N lines. The first line contains a natural N that specifies the size of the population. The second line contains a natural l that specifies the string length l. Each of the next N lines contain the fitness value of each string (a real number). For the purpose if this exercise, you can assume that both N and l are less or equal than 100. The output should be the population of selected strings, i.e., those that won the tournaments. You should send them to the output in the same order as the tournaments take place. That is, the first string sent to the output should be winner of the first tournament, the second string sent to the output should be the winner of the second tournament, and so on. 4 3 8 7 23 5 Sample 101 011 011 011 http://w3.ualg.pt/~jvo/ia IA Lab 4-5

Problem I: Roulette wheel selection Implement roulette wheel selection. Given a population of N bit strings with the corresponding fitness values, you are supposed to spin the roulette N times. The input has N lines. Each line contains a binary string followed by a white space, and by string s fitness value (a real number). For the purpose if this exercise, you can assume that both N less or equal than 100. The output should be the population of selected strings. You should send them to the output sorted by ascending order. 110 1.0 001 3.0 101 4.0 111 2.0 Sample 001 001 101 111 http://w3.ualg.pt/~jvo/ia IA Lab 4-6

Problem J: Stochastic universal sampling (SUS) Implement stochastic universal sampling (SUS). Given a population of N strings with the corresponding fitness values, you are supposed to spin the roulette only once. Therefore, you will only need a single random number. The input has N lines. Each line contains a binary string followed by a white space, followed by string s fitness value (a real number). For the purpose if this exercise, you can assume that the population size and the length of each individual is less or equal than 100. The output should be the population of selected strings. You should send them to the output in the same order as they appear when scanning the roulette from left to right, i.e., from the 1st to the last individual of the population. 110 1.0 001 3.0 101 4.0 111 2.0 Sample 001 001 101 110 http://w3.ualg.pt/~jvo/ia IA Lab 4-7

Problem K: one-point crossover Implement one-point crossover. You should use the random number generator to generate a random number r. You should map this number into one of the possible cross points, and do so from left to right along the string positions. The input has 4 lines. The first line contains parent1, a bit string. The second line contains parent2, another bit string. The output consists of 2 lines: child1 and child2, each followed by a newline character. 11111111 00000000 Sample 11111100 00000011 http://w3.ualg.pt/~jvo/ia IA Lab 4-8

Problem L: uniform crossover Implement uniform crossover. You should use the random number generator and map each random number r into a fair coin toss. For the purpose of this exercise, assume that r < 0.5 corresponds to head otherwise to tail. Whenever the outcome of the coin toss is head you should exchange the corresponding gene values of the parents. The input has two lines. The first line contains parent1, a bit string. The second line contains parent2, another bit string. The output consists of 2 lines: child1 and child2, each followed by a newline character. 11111111 00000000 Sample 10111001 01000110 http://w3.ualg.pt/~jvo/ia IA Lab 4-9

Problem M: bit-flip mutation Implement bit-flip mutation on a binary string. You should use the fixed random number generator and map each random number r into a biased coin toss. Let pm be the mutation probability. If r < pm then the outcome of the coin toss is head, otherwise the outcome is tail. The input has two lines. The first line contains the mutation probability. The second line contains an individual, a binary string. The output consists of the mutated string followed by a newline character. 0.25 11111111 Sample 10111111 http://w3.ualg.pt/~jvo/ia IA Lab 4-10

Problem N: Random permutation Write a computer program that given a number N generates a random permutation of the integers ranging from 0 to N 1. In order to that, you should implement the following algorithm: for( int i=0; i<n; i++) v[i] = i; for(int i=0;i<n-1;i++) { r = obtain a uniformly generated random integer in [i..n-1]; exchange the contents of v[i] with the contents of v[r] } On completion, the array v will contain a random permutation. The body of the second for loop shown above is executed N 1 times. You should map each random number in [0..1) into an appropriate distribution (just like you did in previous assignments). A line containing a natural number N. You can assume N < 100. The output is the random permutation, one element per line, followed by a newline character. 4 Sample 2 1 3 0 http://w3.ualg.pt/~jvo/ia IA Lab 4-11

Problem O: Tournament selection without replacement Implement tournament selection without replacement. You can assume that the population size N is a multiple of the tournament size s. You will need to generate a random permutation of the population s times. In each time, you use the generated permutation (from the beginning to the end) to perform N/s tournaments. The first line contains an integer s that specifies the tournament size. Each of the next N lines contain a binary string followed by a white space, followed by string s fitness value (a real number). You can assume that N is a multiple of s. The output should be the population of selected strings. You should send them to the output in the same order as the tournament winners are found. 2 110 8.0 001 7.5 101 23.0 111 5.0 Sample 101 110 101 001 http://w3.ualg.pt/~jvo/ia IA Lab 4-12

Problem P: One generation on onemax Simulate one generation of a genetic algorithm operating on the onemax problem. After reading the input, you must generate a random population and evaluate the fitness of all its individuals. Then you will do one generation of a genetic algorithm. As you know, a generation consists of applying selection, crossover, mutation, and replacement. For the purpose of this exercise, you must use: tournament selection without replacement with tournament size s onepoint crossover with probability Pc bit-flip mutation with probability Pm replace worse strategy with a replacement fraction of r The first line contains an integer N that specifies the size of the population. The second line contains an integer l that specifies the string length. The third line contains an integer s that specifies the tournament size. The fourth line contains a real number Pm that specifies the mutation probability. The fifth line contains a real number Pc that specifies the crossover probability. The sixth line contains a real number r that specifies the fraction of the worse individuals from the old population that is going to be replaced by newly created individuals. (Important: the actual number of individuals to be replaced should be rounded up to the nearest integer). You can assume that both N and l are less or equal than 100, and that N is a multiple of s. The output consists of 2 lines. In each line you should print the generation number followed by a colon and a white space, followed by the maximum, average, and minimum fitness of the population, all separated by a white space. Each of these numbers must be reported with a precision of 2 decimal points. Each line ends with a newline character. 4 5 2 0.1 0.8 0.5 Sample 0: 4.00 2.75 1.00 1: 4.00 3.50 3.00 http://w3.ualg.pt/~jvo/ia IA Lab 4-13

Problem Q: A genetic algorithm on onemax This is similar to the previous exercise, but this time you will be simulating multiple generations, just like in a complete genetic algorithm (GA). Again you will be simulating your GA on the onemax problem. Another difference from the previous exercise is that this time you will be using a full replacement strategy (it s just a particular case of the replace worse strategy with r = 1.0. You will be using the same selection, crossover, and mutation operators from the previous exercise. The first line contains an integer N that specifies the size of the population. The second line contains an integer l that specifies the string length. The third line contains an integer s that specifies the tournament size. The fourth line contains a real number Pm that specifies the mutation probability. The fifth line contains a real number Pc that specifies the crossover probability. The sixth line contains an integer g that specifies the number of generations (in addition to generation 0 which consists of a randomly generated population) to be performed. You can assume that both N and l are less or equal than 100, and that N is a multiple of s. You can also assume that g is less or equal than 30. The output consists of 1 + g lines. In each line you should print the generation number followed by a colon and a white space, followed by the maximum, average, and minimum fitness of the population, all separated by a white space. Each of these numbers must be reported with a precision of 2 decimal points. Each line ends with a newline character. 4 5 2 0.1 0.7 2 Sample 0: 4.00 2.75 1.00 1: 4.00 3.75 3.00 2: 4.00 3.25 2.00 http://w3.ualg.pt/~jvo/ia IA Lab 4-14