A Framework for Genetic Algorithms in Games



Similar documents
Alpha Cut based Novel Selection for Genetic Algorithm

Evolutionary SAT Solver (ESS)

Improving the Performance of a Computer-Controlled Player in a Maze Chase Game using Evolutionary Programming on a Finite-State Machine

New Modifications of Selection Operator in Genetic Algorithms for the Traveling Salesman Problem

Introduction To Genetic Algorithms

A Robust Method for Solving Transcendental Equations

Applying Design Patterns in Distributing a Genetic Algorithm Application

A Genetic Algorithm Processor Based on Redundant Binary Numbers (GAPBRBN)

Genetic Algorithms commonly used selection, replacement, and variation operators Fernando Lobo University of Algarve

College of information technology Department of software

Model-based Parameter Optimization of an Engine Control Unit using Genetic Algorithms

Modified Version of Roulette Selection for Evolution Algorithms - the Fan Selection

Asexual Versus Sexual Reproduction in Genetic Algorithms 1

Evolutionary Algorithms Software

Genetic algorithms for changing environments

Memory Allocation Technique for Segregated Free List Based on Genetic Algorithm

A Fast Computational Genetic Algorithm for Economic Load Dispatch

HYBRID GENETIC ALGORITHMS FOR SCHEDULING ADVERTISEMENTS ON A WEB PAGE

Genetic Algorithm. Based on Darwinian Paradigm. Intrinsically a robust search and optimization mechanism. Conceptual Algorithm

Original Article Efficient Genetic Algorithm on Linear Programming Problem for Fittest Chromosomes

Comparison of Major Domination Schemes for Diploid Binary Genetic Algorithms in Dynamic Environments

Solving Banana (Rosenbrock) Function Based on Fitness Function

International Journal of Software and Web Sciences (IJSWS)

Evolutionary Detection of Rules for Text Categorization. Application to Spam Filtering

International Journal of Emerging Technologies in Computational and Applied Sciences (IJETCAS)

Empirically Identifying the Best Genetic Algorithm for Covering Array Generation

A Parallel Processor for Distributed Genetic Algorithm with Redundant Binary Number

Genetic Algorithm Performance with Different Selection Strategies in Solving TSP

ISSN: ISO 9001:2008 Certified International Journal of Engineering Science and Innovative Technology (IJESIT) Volume 2, Issue 3, May 2013

A GENETIC ALGORITHM FOR RESOURCE LEVELING OF CONSTRUCTION PROJECTS

A Non-Linear Schema Theorem for Genetic Algorithms

Curriculum Map. Discipline: Computer Science Course: C++

Chapter 3 Chapter 3 Service-Oriented Computing and SOA Lecture Note

Proposal and Analysis of Stock Trading System Using Genetic Algorithm and Stock Back Test System

A HYBRID GENETIC ALGORITHM FOR THE MAXIMUM LIKELIHOOD ESTIMATION OF MODELS WITH MULTIPLE EQUILIBRIA: A FIRST REPORT

Cellular Automaton: The Roulette Wheel and the Landscape Effect

A Study of Crossover Operators for Genetic Algorithm and Proposal of a New Crossover Operator to Solve Open Shop Scheduling Problem

A hybrid Approach of Genetic Algorithm and Particle Swarm Technique to Software Test Case Generation

Goldberg, D. E. (1989). Genetic algorithms in search, optimization, and machine learning. Reading, MA:

New binary representation in Genetic Algorithms for solving TSP by mapping permutations to a list of ordered numbers

CS MidTerm Exam 4/1/2004 Name: KEY. Page Max Score Total 139

Lab 4: 26 th March Exercise 1: Evolutionary algorithms

COMPARISON OF GENETIC OPERATORS ON A GENERAL GENETIC ALGORITHM PACKAGE HUAWEN XU. Master of Science. Shanghai Jiao Tong University.

Intelligent Modeling of Sugar-cane Maturation

Volume 3, Issue 2, February 2015 International Journal of Advance Research in Computer Science and Management Studies

Spatial Interaction Model Optimisation on. Parallel Computers

Genetic Algorithms for Bridge Maintenance Scheduling. Master Thesis

Numerical Research on Distributed Genetic Algorithm with Redundant

Holland s GA Schema Theorem

IES - Introduction to Software Engineering

Leran Wang and Tom Kazmierski

A Review And Evaluations Of Shortest Path Algorithms

Multiobjective Multicast Routing Algorithm

Keywords revenue management, yield management, genetic algorithm, airline reservation

CLOUD DATABASE ROUTE SCHEDULING USING COMBANATION OF PARTICLE SWARM OPTIMIZATION AND GENETIC ALGORITHM

Non-Uniform Mapping in Binary-Coded Genetic Algorithms

APPLICATION OF ADVANCED SEARCH- METHODS FOR AUTOMOTIVE DATA-BUS SYSTEM SIGNAL INTEGRITY OPTIMIZATION

CHAPTER 6 GENETIC ALGORITHM OPTIMIZED FUZZY CONTROLLED MOBILE ROBOT

CHAPTER 3 SECURITY CONSTRAINED OPTIMAL SHORT-TERM HYDROTHERMAL SCHEDULING

PROCESS OF LOAD BALANCING IN CLOUD COMPUTING USING GENETIC ALGORITHM

A Fast and Elitist Multiobjective Genetic Algorithm: NSGA-II

The Adomaton Prototype: Automated Online Advertising Campaign Monitoring and Optimization

Improving proposal evaluation process with the help of vendor performance feedback and stochastic optimal control

Course Outline Department of Computing Science Faculty of Science. COMP Applied Artificial Intelligence (3,1,0) Fall 2015

A Service Revenue-oriented Task Scheduling Model of Cloud Computing

Overview. Swarms in nature. Fish, birds, ants, termites, Introduction to swarm intelligence principles Particle Swarm Optimization (PSO)

HYBRID GENETIC ALGORITHM PARAMETER EFFECTS FOR OPTIMIZATION OF CONSTRUCTION RESOURCE ALLOCATION PROBLEM. Jin-Lee KIM 1, M. ASCE

Heuristics for the Sorting by Length-Weighted Inversions Problem on Signed Permutations

Teaching Introductory Artificial Intelligence with Pac-Man

Comparative Study: ACO and EC for TSP

Estimation of the COCOMO Model Parameters Using Genetic Algorithms for NASA Software Projects

OmniFunds. About OmniFunds. About Alpha 2.0: About VisualTrader 11 Pro. Alpha Released September 24, 2015

Vol. 35, No. 3, Sept 30,2000 ملخص تعتبر الخوارزمات الجينية واحدة من أفضل طرق البحث من ناحية األداء. فبالرغم من أن استخدام هذه الطريقة ال يعطي الحل

A Hybrid Tabu Search Method for Assembly Line Balancing

Architecture bits. (Chromosome) (Evolved chromosome) Downloading. Downloading PLD. GA operation Architecture bits

A Genetic Algorithm Approach for Solving a Flexible Job Shop Scheduling Problem

Metodi Numerici per la Bioinformatica

A Survey on Search-Based Software Design

A Client-Server Interactive Tool for Integrated Artificial Intelligence Curriculum

Battleships Searching Algorithms

A Brief Study of the Nurse Scheduling Problem (NSP)

Optimization in Strategy Games: Using Genetic Algorithms to Optimize City Development in FreeCiv

Maintenance scheduling by variable dimension evolutionary algorithms

A SURVEY ON GENETIC ALGORITHM FOR INTRUSION DETECTION SYSTEM

Spare Parts Inventory Model for Auto Mobile Sector Using Genetic Algorithm

GA as a Data Optimization Tool for Predictive Analytics

Evaluation of Different Task Scheduling Policies in Multi-Core Systems with Reconfigurable Hardware

Solving the Vehicle Routing Problem with Genetic Algorithms

Programming Risk Assessment Models for Online Security Evaluation Systems

Neural Networks and Back Propagation Algorithm

Evaluating OO-CASE tools: OO research meets practice

HOST SCHEDULING ALGORITHM USING GENETIC ALGORITHM IN CLOUD COMPUTING ENVIRONMENT

Transcription:

A Framework for Genetic Algorithms in Games Vinícius Godoy de Mendonça Cesar Tadeu Pozzer Roberto Tadeu Raiitz 1 Universidade Positivo, Departamento de Informática 2 Universidade Federal de Santa Maria, Departamento de Eletrônica e Computação 3 Universidade Federal do Paraná, Curso de Tecnologia e Sistemas de Informação Abstract This article describes the organization of a Genetic Algorithm Framework, techniques and optimizations used in its construction, considerations about the use of this process in games and a usage example. Keywords: artificial intelligence, genetic algorithms, biological programming, optimization techniques, evolutionary computation 1. Introduction Artificial Intelligence (AI) for Games often needs to deal with environments composed by several variables with unknown exact behavior. Take for example a game like Sim City or Civilization, where a game AI advisor could suggest for the player an administrative strategy. This strategy should try to maximize several factors like the incoming money, production rate and technological advancements while reducing problems like pollution and famine. The consequence of each variable to the global scenario is not entirely predictable but, usually, given a set of defined values, it s easy to evaluate the whole picture. Another example is in a two-player Asteroid like game. Consider that one of the players is the AI and that each asteroid has gravity. Now, take a scenario where the AI player must move in the middle of several asteroids, while faced by the enemy. What path should the IA follow? There are almost infinite solutions for this problem: the AI could flee away, go toward the adversary or an asteroid and shoot, using or not the gravity of an asteroid to help its throttle. Traditional AI offers several search mechanisms [Norvig 2003] that try to find these answers. Some of them tries to systematically search the entire search space (like breadth-first search or A*). While they surely lead to the best possible solution, they may have a very long execution time. Another option would be using a local space search, like hill climbing search or Tabu search, but they tend to be locked in local maximums. The classical genetic algorithm defined by Holland [Holland 1975] is divided into six steps [Charles, D., 2008]: population creation, fitness evaluation, chromosome mating and mutation, deletion of lowest fitness individuals and re-evaluation of the new population. The last steps are repeated until the convergence of the population to a good result. One of the greatest advantages of GA is that it can be considered a parallel search mechanism that tests several different variables simultaneously [Charles 2008]. Also, it avoids local maximums by doing mutations, and allowing searching of random areas of the solution space. Unfortunately, this technique is not well known among the game developer community. There are few books on the subject and even less containing practical game situation examples. This article presents a framework that allows developers to easily integrate genetic algorithms into their games. The purposed solution is both flexible and easy to use. The article also discusses some optimizations made in the framework. To better understanding of the purposed architecture, a sample test scenario is provided in section 4. 2. Drawbacks of Genetic Algorithms Time consuming evolution: Often evolution takes too many generations, even with a good genome designed with good operators [Schwab, 2004]. This is especially true in the presence of deceptive problems [Charles D., 2008]. Consider a situation with two alleles where: f(11) is the best individual, but f(*0) > f(*1) and f(0*) >f(1*). In this schemata, the solution looks to converge to f(00), but the maximum global is actually when all genes are 1. This situation is shown in the following graphic: Genetic Algorithms (GA), are in the last category of the above two and try to use the principle of evolution, normally found in natural systems, to search for solutions to algorithmic problems [Schwab 2004].

2. To implement a common GA interface, allowing the framework to work; 3. To act as a Mediator (Gamma, 1995), for its genome structure and manipulation. Notice that the individual models the business problem, so, it should be implemented by the framework user. Figure 1: A deceptive problem The problem is that the fitness will most likely choose individuals with 0 in their genes, and their crossing will rapidly converge to 00. Eventually, a mutation will reach 11, but even in this case, this individual will very likely to be lost, unless some elitism is involved in the process. Evaluation by experimentation: Due to the great number of crossover, mutation, selection and scaling options, and due to the random nature of GAs, the only way to find a good solution is by experimentation [Schwab, 2004]. This great number of choices can also be frightening to less informed developers. This also implies that a good genetic algorithm framework must ensure that experimenting is possible. No guarantee of optimal solution: Just like any stochastic selection algorithm [Norvig, 2008], there s no guarantee that the algorithm truly converged to the global maximum. On the other hand, in many situations finding good local maximum could be as good as choosing the global maximum especially because it could create a less predictable and more human behavior [Schwab, 2004]. Hard to debug: Due to the random nature of the algorithm, it s hard to tell why a given implementation is not working. 3. Framework description This approach has two big advantages: 1. The fitness function may use user-friendly methods to evaluate an individual, not manipulating the genome directly. This also makes the fitness function fully tolerant to genome structure changes; 2. The genetic framework does not depend upon a specific genome structure. User defined structures may be created and different implementations can be tested; The fitness function is specified by an interface, and in case of C++ implementations a functor [Vandevoorde 2003] may be used instead. 3.2. Genome classes The framework already provides the BitGenome class, that helps user s to model the problem as a bit string. This is the most common method [Schwab 2004 and Jones 2008]. BitGenome makes use of the Strategy design pattern [Gamma 1995] for its crossover and mutation methods. Two implementations of crossover are already provided: the point crossover method and a uniform crossover. Point crossover method provides a userdefined number of crossover points, and could be used as a single or multi point crossover. For the mutation method, only the random mutation is provided. The class diagram below describes this structure: This section describes the entire framework organization and design considerations. 3.1. Domain specific classes The first step when dealing with any genetic algorithm is to represent the problem in a form of a genome structure, and provide a fitness function to evaluate a specific individual. In the proposed framework, there s a clear distinction between the concepts of an Individual and of a Genome. Such is not the case in several implementations like Schwab [2004], Charles [2008] Jones [2008] and Oibitko[1998]. So, the Individual has three very important roles: 1. To provide business methods for accessing domain specific properties; Figure 2: Bit genome a possible individual internal structure 3.3. Scaling classes Scaling is a common and optional technique to avoid the so called super individuals [Schwab 2004, Charles 2008], that is, individuals with a score so high that they easily dominate the entire population. These may be a problem, since they may represent just a local

maximum. The framework provides two common kinds of scaling: a rank scale and a sigma truncation scale [Schwab, 2004]. 3.4. Selection function The framework provides three selection methods proposed by Schwab [2004]: Tournament Selection, Roulette Wheel Selection and Stochastic Selection. The traditional roulette wheel selection is described as follows [Obitko, 1998]: 1. Calculate sum of all chromosome fitness in population sum S; 2. For each individual in population 2.1. Take a random number in the interval (0,S) r 2.2. Go through the population and sum fitness s from 0 sum s. When s is greater than r, stop and return the chromosome where you are. Exactly the same implementation is also found in Jones, 2008. This implementation assumes that the population is sorted in descending order. The problem with this approach is that iterates through the population every time an individual must be selected. Since iteration is a time-consuming task, using this approach could be time killing for games. So an optimized implementation of the same algorithm was provided, allowing the iteration to occur only once: 1. Calculate the sum of all chromosome fitness in population sum S; 2. Take n random numbers in the interval (0,S) r1, r2, r3,, rn, where n is the number of individuals to be selected; 3. Sort these random numbers in ascending order; 4. Go through the population and sum fitness from 0 sum s. While s is greater than the lowest r, add the current individual to a list and remove r. Stop when the population finishes or there are no more random numbers to pick. 5. Return the list of selected individuals A good approach is to store all generated random numbers in a heap, avoiding costs in step 3. 3.5. Asymptotic selection The framework also includes a new algorithm called Asymptotic Selection. The algorithm work as follows: 1. Sort the individuals in descending order; 2. Choose an index using the formula: *size, where r is a random number in the interval [0,1), n is a chosen constant and size is the count of individuals; 3. This is the selected individual index. Notice that, since the random number is smaller than one, all possible results will describe an asymptote, tending towards zero if n is bigger than 0. Which means that a greater N will be more elitist, while a smaller N will prior slower convergence. Experiments show that N must be a number between 0.8 and 1.2. Since this algorithm uses the individual index instead of score, it implicitly uses rank scaling, so all scaling that does not change individuals position in the sorted list may be avoided, sparing time. 3.5. Generation control The mechanic of the genetic algorithm is controlled by the Generation class. The generation must be constructed with a random population that is immediately evaluated. Each call to next() will run the genetic algorithm logics and create a new evaluated generation. Each generation has also a number and methods to obtain the best scored individuals. The generation class also has ways to parameterize elitism, crossover rates and mutation rates. The last one is only necessary if the genome does not implement its specific mutation politics. Other useful methods, such as advancing until a certain score, for a certain time or for a given number of generations are also provided. 3.6. Other design considerations 1. The random seed of all algorithms in this framework are configurable. This allows programmers to generate a deterministic behavior, if desired. Such is the case in synchronized simulation network games, to avoid transmission of AI information [Smed, 2006]. 2. In C++, the internal mechanics of the framework uses smart pointers [Vandervoorde 2003] for individuals, instead of working with copy; 3. The generation class also provides several defaults, based in the common options [Schwab, 2004]. These are: a crossover rate of 75%, an elitism rate of 5%, a, mutation rate of 100% (but it considers that user will use the BitGenome, which default is 1% per bit), Roulette Wheel Selection and no scaling; 4. BitGenome fully implements the Individual interface, so it could be used directly. Off course, this will remove the benefits described in section 3.1, but allow a very simple usage of the framework; 4. Usage sample To exemplify the usage of the framework, let s consider a Sim City like game where the player must manage the plantation of sugar maple (for biodiesel) and food. Player uses industry and food taxes to

stimulate or decelerate each one of these plantation options. Increasing the sugar maple fields will stimulate the industry, so the player will earn more money with taxes and the population will have more jobs. On the other hand, too many maple fields mean that the food will get more expensive, and it s quite possible that some people will get hungry. Increasing the food fields allow the player to make food cheaper, but it will slow down the industry. This could generate unemployment, and no working people will not buy any food or pay any taxes. They also generate other problems, such as crimes, not considered in our analysis. The exact impact of each parameter variation was configured by the game designer, in a script. Now, let s consider an implementation of an advisor that suggests for the player a good approach about how to configure these taxes. The first step is to configure an individual that contains all parameters that can be changed. They are the biodiesel industry tax and the food tax. We use the BitGenome structure to represent these taxes. The first 7 bits are used to store the industry tax and the last 7 bits to store the food tax. After that, we will create the Fitness Function. The fitness function will use a game function that given the two taxes calculate the incoming money, rate of hungry people and rate of unemployed people. Notice that this function is commonly found in this kind of game, since it is also used for the game mechanics and to give support to the player decision. The advisor will prefer individuals that contain: 1. No unemployment: People that don t work are hungry, do not contribute to the incoming taxes, and generate social problems, so they will be avoided to the maximum; 2. The biggest income as possible; 3. Little famine; So, our fitness function could be: unsigned calculate(individual individual) { //First, discard invalid taxes if (individual.getindustrytax() > 100) return 0; if (individual.getfoodtax() > 100) return 0; //Finally, calculate the score int score = proj.earnedmoney * 1 (proj.faminerate() + 5 * proj.unemploymentrate()); //Limit the lowest score to zero. return (unsigned) max(0, score); } Figure 3: Advisor fitness function We can see that this advisor rejects unemployment five times more than famine. Also, earned money has a linear impact over the overall score and this impact is amortized by famine and unemployment. Finally, let s include a sample of the suggest function. To demonstrate how simple it could be, the function will use the genetic algorithm defaults. Taxes is our individual class. We will use an optional generation constructor that receives an Abstract Factory [Gamma 1995] and generate n individuals using this factory. Taxes Advisor::suggest() { //Create a generation Generation<Taxes> generation(factory, 30); //Calls next() many times, for 500ms generation.nextuntiltime(500); //Returns the best individual return generation.bestindividual(); } Figure 4: A sample advisor implementation Even if a local maximum is returned, it has good chances to be a good advice. That s ok for this implementation, since a human advisor is not perfect either, and could not see the best solution sometimes. 5. Conclusion In this work, a genetic algorithm framework was presented, as well as its possible uses for games. Some optimization techniques were described, as well as several design considerations over the framework. There are several options for future work, including increasing algorithm options in every step, introducing parallel processing and thread-safety to the framework or even creating self-adapting genome schemes. The framework implementation is public and can be found in: https://sourceforge.net/projects/sofiaia/ //Then calculate the projection Projection proj = calculateprojection( individual.getindustrytax(), individual.getfoodtax());

References CHARLES D. ET AL, 2008. Biologically Inspired Artificial Intelligence for Computer Games, IGI Publishing, 105-138. JONES, M. T., 2008. Artificial Intelligence: A Systems Approach. Infinity Science Press Inc., 195-247. SMED, J., HAKONNEN, H., 2006. Algorithms and Networking for Computer Games. John Willey and Sons, 205. SCHWAB, B., 2004, AI Game Engine Programming, Thomson Delmar Learning, 413-452. NORVIG, P. AND RUSSEL, S.J., 2003. Artificial Intelligence: A Modern Approach, Prentice Hall, 116-119. VANDEVOORDE D., JOSUTTIS N. M., 2003. C++ Templates The complete guide, Addison Wesley, 417-474 GAMMA E., RICHARD H. JOHNSON, R, VLISSIDES, J. 1995. Design Patterns Elements of reusable object-oriented software, Addinson-Wesley Longman Inc. OBITKO., MAREK. 1998. Introduction to Genetic Algorithms, [online],hochschule für Technik und Wirtschaft Dresden. Available from: http://obitko.com/tutorials/geneticalgorithms/ [accessed August, 2008]. HOLLAND, J. H., 1975. Adaptation in natural and artificial systems, Ann Arbor MI, University of Michigan Press.