Вы находитесь на странице: 1из 75

Traffic Control with Standard Genetic Algorithm

A simulated optimization control of a Traffic Intersection


Master of Science Thesis/ Thesis work in Intelligent Systems Design

GUSTAF JANSSON
epartment of Applied Information Technolog! C"A#$%&S UNI'%&SIT( OF T%C"NO#OG( Gothen)urg* Sweden* +,-, &eport No. +,-,/-+0 ISSN/ -12-34015

&%6O&T NO. +,-,7-+0

Traffic Control with Standard Genetic Algorithm


A simulated optimization control of a Traffic Intersection GUSTAF JANSSON

epartment of Applied Information Technolog! C"A#$%&S UNI'%&SIT( OF T%C"NO#OG( G8te)org* Sweden +,-,

Genetic Algorithm controlled Traffic Intersection A practical use of Standard Genetic Algorithm for Traffic Intersection control GUSTAF JANSSON 9 GUSTAF JANSSON* +,-, $aster:s Thesis report no +,-,/-+0 ISSN/ -12-34015 epartment of Applied Information Technolog! Chalmers Uni;ersit! of Technolog! S%34-+ 51 G8te)org Sweden Telephone < 41 =,>?-300+ -,,,

Co;er/ Figure of the traffic intersection* also found on page -+ &eproser;ice 7 epartment of Applied Information Technolog! G8te)org* Sweden +,-,

Genetic Algorithm controlled Traffic Intersection A practical use of Standard Genetic Algorithm for Traffic Intersection control GUSTAF JANSSON epartment of Applied Information Technolog! Chalmers Uni;ersit! of Technolog!

Abstract
In this master@s thesis* the possi)ilit! to use genetic algorithms to sol;e real world pro)lem is tested and e;aluated. The t!pe of genetic algorithm considered in this thesis is the standard genetic algorithm* and the chosen pro)lem in;ol;es traffic control of an intersection with road ;ehicle* tram and pedestrian traffic. Genetic algorithms are stochastic and )iolog! inspired search techniAues mostl! used in science related worB to find optimal solutions. The! are usuall! ;er! resource taBing in terms of C6U time and memor! size. A hardware issue* relating to how to implement the genetic algorithms into an em)edded s!stem* is also co;ered. The maCor part in this worB is concerned with appl!ing genetic algorithms to find optimized scheduling solutions for efficient traffic flow. The traffic intersection is used to illustrate pro)lems where optimal scheduling for dri;e order is needed* thus the results produced )! the genetic algorithm depend on the present situation in the intersection. An additional search method called epth First Search = FS> is used to ;erif! the results from the genetic algorithm. The pro)lems with constraint rules affecting this worB are also co;ered. F6GA and microcontroller are )oth suita)le hardware for genetic algorithm implementation* this worB will onl! co;er implementation of the microcontroller. The control of the intersection is assumed to )e directl! from this hardware implementation* and )eing totall! independent from an! outside control s!stem. The traffic intersection* which is not a real eDisting intersection* is independent from adCacent intersections. All simulation programs acts as controller programs for the intersection. There are three different simulation programs in total* all coded in programming language C. This worB will not present a complete final result* for eDample a hardware implementation read! to use. It sta!s on simulation programs onl!.

Ee!words/ Standard Genetic Algorithm* Traffic Intersection* %m)edded S!stems* F6GA* $icrocontroller* epth First Search* Constraint &ules.

iii

i;

Content
A)stract............................................................................................................................iii AcBnowledgement...........................................................................................................;ii - Introduction...................................................................................................................+ escription of Standard GA..........................................................................................? +.- Standard GA description........................................................................................? +.-.- Initialization...................................................................................................4 +.-.+ ecoding........................................................................................................2 +.-.? %;aluation......................................................................................................2 +.-.4 Fitness function..............................................................................................1 +.-.2 %litism............................................................................................................1 +.-.1 Tournament selection.....................................................................................0 +.-.0 Crosso;er........................................................................................................0 +.-.F $utation.........................................................................................................0 +.+ 6rogram details for Standard GA...........................................................................F +.? Search space...........................................................................................................5 ? Traffic intersection.......................................................................................................-?.- escription of the intersection.............................................................................-?.+ General functionalit!...........................................................................................-+ ?.? %as! worBing eDample.........................................................................................-? ?.4 etails and modifications....................................................................................-1 4 6rograms......................................................................................................................-0 4.- Standard GA ;ersions..........................................................................................-0 4.+ FS ;ersion.........................................................................................................-F 2 &ule pro)lems..............................................................................................................-5 2.- %Dample of rule pro)lems....................................................................................-5 2.+ Solutions for this pro)lem....................................................................................+, 1 %m)edded solutions.....................................................................................................+1.- F6GA...................................................................................................................+1.+ $icrocontroller....................................................................................................++ 0 Simulations..................................................................................................................+2 0.- A)out the simulations..........................................................................................+2 0.+ 6erformed simulations.........................................................................................+0 0.+.- Computed Standard GA simulations............................................................+0 0.+.+ $icrocontrolled Standard GA simulations...................................................+F 0.+.? FS ;ersion simulations..............................................................................+5 0.? Simulation results.................................................................................................?F Conclusion...................................................................................................................?2 F.- Simulation conclusion..........................................................................................?2 F.+ Future impro;ements...........................................................................................?2 F.? Summar!..............................................................................................................?1 5 &eferences...................................................................................................................?0 5.- GooBs...................................................................................................................?0 5.+ ocuments...........................................................................................................?0 5.? Internet.................................................................................................................?F -, AppendiD....................................................................................................................?5 AppendiD A Traffic intersection dri;e orders chart....................................................4AppendiD G $athematical fitness functions..............................................................4? AppendiD C 6ropositional logic for outputs..............................................................42 ;

AppendiD AppendiD % AppendiD F AppendiD G AppendiD "

6ropositional logic for dri;e order seAuence.........................................40 6rogram windows of Standard GA........................................................45 6rogram windows of FS ;ersion.........................................................26rogram code of Standard GA..............................................................2? 6rogram code of FS ;ersion...............................................................1-

;i

Acknowledgement
This master:s thesis is carried out in Chalmers and IT Uni;ersit! in Gothen)urg during +,-,. From m! point of ;iew it has )een ;er! inspiring to do this worB. Se;eral new ideas and perspecti;es ha;e coming up along this worB. $ore than a dozen millions artificial indi;iduals ha;e passing )! on de;elopments and simulations. Special thanBs to m! eDaminer and super;isor to this worB Claes StrannegHrd. I would also thanB class and famil! mem)ers for additional supports.

;ii

;iii

1 Introduction
The aim of this master:s thesis worB is twofold. The first is to find a wa! to implement a genetic algorithm =GA>* into an em)edded s!stem. The second and the maCor part* is to sol;e a real world pro)lem with this GA. This pro)lem is to find good traffic flow in the traffic intersection crossed with road ;ehicles* trams and pedestrians. The specific GA used in this worB is a Standard GA. GAs is an adapti;e and efficient heuristics that are a)le to sol;e optimization pro)lems. This is a stochastic search techniAue to looB for optimal solution. $ost GA is used in research and science related worB to looB for optimal solutions. The! usuall! run on powerful computers as GAs generall! are resources taBing in term of C6U time and memor! size. Some methods GA uses are selection* crosso;er and mutation inspired from e;olution in the real nature. A GA produced solutions comes out from one of man! artificial indi;iduals that contain the highest fitness ;alue. Out from this indi;idual a hopefull! good to perfect answer of the specified pro)lem can )e found. The main purpose of this worB is to test if a GA can )e used out in the field. To do this* it will )e applied and tested on a reasona)l! simple pro)lem. This worB also includes finding simpler hardware for implementation. This traffic intersection comes into illustrate a real world pro)lem to worB with. Optimal scheduling will )e the worB method to produce dri;e order seAuence depending up on the present situation. There are three simulation programs in totalI computed Standard GA* microcontrolled Standard GA and a computed FS ;ersion. The last one use depth first search = FS> algorithm. The FS will )e used to find the real answer in the search space. This answer will then )e compared with the results from )oth the other Standard GAs simulations. All simulation programs are coded in programming language C. The em)edded s!stem used during this worB is a microcontroller that must use C language. In terms of controlling the intersection with GA* onl! independent control from hardware implementation will )e considered in this worB. No other outside control s!stem will )e considered. The intersection will also )e assessed in isolation* meaning* not considering adCacent intersections.

2 Description of Standard GA
The specific Bind of GA used throughout this worB is a Standard GA JKahde* +,,FL. A Standard GA is one t!pe of different GAs. In a )ig ;iew GAs is one under group to the term of e;olutionar! algorithms. In general GAs is a search algorithm )ased on the natural selection and genetics JGold)erg* -5F5L. It uses a num)er of artificial indi;iduals looBing through a compleD search space )! using functions of selection* crosso;er and mutation. The purpose to use GA is searching and finding optimal or good enough solution. This solution will hide in a )ig search space to looB through. Is no guarant! to find an! eDact solutions when using a GA. Some result can e;en )e far from optimal when GA gets stucB in so called local optimum in the search space.

2.1 Standard GA description


This general description includes how GA worBs and special the Standard GA. Some detailed functionalit! for the simulation programs is also included. The Standard GA starts )! initial a population with certain num)er of indi;iduals to worB on. %ach indi;idual consist a num)er of chromosomes depending on the pro)lem to sol;e. %ach chromosome consists of certain num)er of genes =see Figure +.->. The genes are )inar! represented in the chromosome and the! are decoded to get out a special parameter ;alue to worBing on.

Figure +.-/ One indi;idual with +4 genes and three chromosomes Khen entire indi;iduals are decoded* all results from each chromosome are e;aluated for fitness calculation. After decoding and e;aluating all indi;iduals from entire population* the )est indi;idual is compared to the )est one so far. If this new indi;idual is )etter than the pre;ious )est indi;idual* it will )e sa;ed to the neDt generation and entitled as the new )est one so far. Khat is considered the fittest one depends on the pro)lem defined )! user. One eDample can )e a two ;aria)le function when the )est result is the minimum ;alue of the function. In this case the )est result is the smallest and =the result need to )e in;erted )! fitness=1/y>. In this worB* onl! maDimum ;alues are considered. Gefore the neDt generation is produced* three procedures will taBe place ?

to create a new population including selection* crosso;er and mutation. These are descri)ed in more detail further down and Figure +.+ shows the Standard GA worB flow. If a )est or good enough indi;idual is found* the Standard GA can terminate. In case of when the maDimum num)er of a generation run out without finding a )est or good enough solution* the )est indi;idual that is found will )e presented as the solution.

Figure +.+/ KorB flow o;er Standard GA The program starts with initialization and then )eginning the first generation in a loop )! decoding* e;aluation and fitness measure. After that loop is finish a new population are created )! first do elitism and there after selection )! tournament. #ast following two procedures is crosso;er and mutation )efore neDt generation )egins. The following descriptions for used Standard GA ha;e source code in AppendiD G.

2.1.1 Initialization
Initialization in;ol;es settings the parameters for the algorithm* set up input ;alues for the simulation* and creating population of indi;iduals to the first generation. The most )asic set up are the num)er of genes and chromosomes* the num)er of generations as well as the num)er of indi;iduals per population. The num)er of indi;iduals is prefera)l! e;en num)ered. Other adCusta)le settings for an! GA are the pro)a)ilities of crosso;er* mutation and tournament. These floating ;aria)le ;alues need smaller changes when impro;ing the performance of the GA. Other ;aria)les are to )e descri)ed in each part where the! )elong. Arra! population is gi;en random ;alues , and - to each gene and that maBes )inar! ;alues to each chromosome. A gene can for an eDample ha;e other ;alues for eDample natural num)er representing something as cities 4

in the Tra;elling Salesman 6ro)lem =TS6> JStuart M Nor;ig* +,,?L. A special ;ector in this program called inputValue containing Nreal world sensor inputsO from the intersection to simulate on. Arra! inputValues ha;e up to eight stored inputs for eight future time periods for simulations. All simulations do ten time periods* where the last two time periods are input free.

2.1.2 Decoding
After initialization* the program enters the main loop of Standard GA* commencing the decoding of the chromosomes. The decoding is user defina)le. For eDample* one chromosome can represent man! different ;alues* as demonstrated in Figure +.?.

Figure +.?/ Three different wa!s to decode one )inar! chromosome In this program each chromosome ha;e four )inar! genes representing )inar! num)er from , to -2* pro;iding -1 separate solutions representing dri;e orders for the intersection =see AppendiD A>. The arguments population and i* identifies certain indi;iduals to read from. The num)er of genes and chromosomes* and actual chromosome order* tells where to read on the actual indi;idual. The first gene on the chromosome is the #east Significant Git =#SG> and the resulting num)er is returned and stored in ;aria)le called parameterValue(chromosome number .

2.1.3

!aluation

The purpose of e;aluation is to determine the fitness of each indi;idual in a generation. The e;aluation function applies a mathematical function to calculate the fitness ;alues =see eDample in Figure +.4>. %ach calculated fitness ;alue will )e returned from the function called %;aluateIndi;idual. The arguments to the function contain chromosome ;alues* input ;ector and the pre;ious dri;e order.

Figure +.4/ Fitness calculation eDample from indi;idual with three chromosomes

The fitness calculation process is the same for all programs* and uses three calculation stages. %;aluation of present situation at the intersection are calculated according to inputs sensors from the site* older inputs with added priorit! and the pre;ious dri;e order that occurred. The first calculation stage* are summar! points cnInputs from new and old inputs )! mathematical functions =see AppendiD G>. These ;alues are retrie;ed from inputValue containing input ;alues from the intersection. The ;alues range from , to 1* where , is non3reAuesting sensor* - is new input and other ;alues are older remaining reAuests. The input is set to zero in the main code when the eAual output* of that input* is Bnown to )e eDecuted. In simulation ;iew will )e a road ;ehicle that ha;e dri;en awa! and then left the sensor. Also in main code is the priorit! )oost for non3eDecuted reAuests* is done )! adding ;alue one until neDt time period. The second calculation stage is dependent on the pre;ious dri;e order* ;aria)le pre!ious"#cecution and a set of rules* listed in AppendiD . The propositional rules onl! tell what pre;ious dri;e orders that will gi;e eDtra credits of two points or not )! sn. The purpose is to fa;our certain seAuence of dri;e orders that are good for the traffic flow. On e;er! simulation start are pre!ious"#cecution eAual to ;alue -1 that is a non3 ;alid zero credit dri;e order. In case of same dri;e order repeats itself* a penalt! calculation will )e used )! su)tract minus fi;e points to a;oid repetition. The last calculation stage summarise all chromosome points )! following eAuation/ 1 f = 0 n c nInputs s n n=This function is the actual fitness calculation returned )! the e;aluation function. %ach chromosome cn is a summar! from the pre;ious two stage calculations. %Dample of chromosome two is c$ = %(c$Inputs&s$ . The aim for the solution is to eDecute man! reAuests earliest as possi)le. So each chromosome is multiplied )! a num)er from siD and down* to fa;our higher points on the earl! time periods rather the last ones.

2.1." #itness function


After an indi;idual has )een decoded and e;aluated it has )een gi;en a fitness ;alue. If this ;alue is more =not eAual> than the present maDimum fitness ;alue* this fitness ;alue will )ecome the new maDimum fitness ;alue. In addition to updating the maDimum fitness ;alue in ;aria)le ma#'itness* each parameter ;alue from this indi;idual is also stored under the siD ;aria)les best(arameter!alue(chromosome number .

2.1.$

litism

Khen all indi;iduals ha;e )een e;aluated* the one with the highest fitness ;alue is stored unchanged in the first row in the neDt population arra!. This is done )ecause the following procedures for the other indi;iduals are going through tournament selection* 1

crosso;er and mutation. The last two will destro! or hopefull! impro;e current indi;iduals in the neDt generation.

2.1.% &ournament selection


At the )eginning of generating the neDt population* all indi;iduals are taBen through a selection procedure called tournament selection. In this procedure* indi;iduals are compared against each other in a tournament where indi;iduals with the highest fitness ;alue ha;e a higher pro)a)ilit! to )e selected. The tournament pro)a)ilit! is a fiDed ;alue in ;aria)le tournament(robability. In this program ?, indi;iduals are taBen through the selection* two indi;iduals per tournament* resulting in -2 tournaments )etween randoml! selected indi;iduals.

2.1.' Crosso!er
Crosso;er and mutation are the two procedures that )ring new e;olutionar! material for the GA to worB on. In the crosso;er procedure two indi;iduals are chosen from the population to create new offspring. This is achie;ed )! choosing one or two randoml! chosen crosso;er point =one in this program> along the )it strings. The crosso;er points indicate where eDchange of ;alues )etween the indi;idual are to occur to create the new indi;iduals. In this case* the first section =)efore the crosso;er point> of the )it string of a new offspring of an indi;idual remains unchanged while the end section =after the crosso;er point> eDchanges ;alues with the other indi;idual. Khen a second crosso;er point is used the remaining third part is from same indi;idual again =see Figure +.2>. The pro)a)ilit! to do crosso;ers is defined )! ;aria)le crosso!er(robability which let most of all indi;iduals to undertaBe the crosso;er procedure.

Figure +.2/ %Dample of crosso;er )! two crosso;er points

2.1.( )utation
The mutation operation maBes small changes to an indi;idual and is used to maintain genetic di;ersit! from one generation to neDt. In this worB* the mutation operation in;ol;es generating a random ;aria)le for each )it in a seAuence. This random ;aria)le mutation(robability tells whether or not a particular )it will )e modified. Therefore* mutations might or might not ha;e an effect on an indi;idual =as shown in Figure +.1>. Khen a ;er! low mutation pro)a)ilit! is used* then this operation )ecomes rare. In the long3run* mutation )rings new and more different indi;iduals that hopefull! gi;e )etter fitness ;alue. 0

Figure +.1/ $utation on first indi;idual and no mutation on the other one

2.2 *rogram details for Standard GA


This section will outline a general description how this Standard GA worBs in the simulation program. The settings are the same in all Standard GA simulations eDcept for the microcontroller =see Chapter 1.+>. Num)er of genes in one indi;idual are +4 di;ided on siD chromosomes gi;es )inar! ;alue to decoding on each from , to -2. %ach population ha;e ?, indi;iduals and new population is created to e;er! generation that is maDimum -,, for one time period simulation. So e;er! generation do ?, e;aluations multiplied with -,, generations will )e ?,,, e;aluated indi;iduals. Gut )ecause of elitism is used approD +5 uniAue indi;iduals are eDpected per population. Settings for crosso;er pro)a)ilit! are F2P* mutation pro)a)ilit! 4P and tournament pro)a)ilit! 5,P. The Standard GA is a main part inside the loop that re3run e;er! time period. Gefore the loop starts* an initiation will taBe place and the inputValue* for the present time period to )e simulated* )rought in. Following this* the actual Standard GA loop will start running* worBing according to the description in Chapter +.-. Khen finished* the )est indi;idual is to )e stored in a specific arra! called goo)In)i!i)uals for future use. This is a Bind of elitism* when sa;ing indi;iduals unchanged after each complete Standard GA run. In order to store an indi;idual to goo)In)i!i)uals arra!* the )est indi;idual:s ma#'itness needs to )e higher than totalMa#'itness from the entire ongoing simulation. This arra! will then contain some of the )est pre;ious indi;iduals which are copied to arra! population in e;er! new Standard GA loop. &eusing pre;iousl! identified good solution for future needs allows for faster and impro;ed results. In that wa! the simulation program is self3learning. In the simulations there are up to eight sets of inputs and the program runs the Standard GA ten times in total. After some tests of worst case scenarios* it was concluded that at least siD chromosomes are needed per indi;idual to easil! read enough predicted dri;e orders. 6redicted dri;e orders can )e represented as a forecast o;er possi)le upcoming dri;e orders. This forecast is )ased upon the present situation. Khen the actual time F

period has )een eDecuted* the Standard GA will start searching for a solution for the following time period. epending on the inputs to the new time period* this new solution ma! or ma! not )e eAual to the pre;ious predicted one for this actual time period. The result is presented in a s!m)olic wa! )! printout on the screen onl! =see AppendiD % and AppendiD F>. The final code for this description* and )elonging simulation inputs of *orst case one* are included in AppendiD G.

2.3 Searc+ space


Goth the Standard GA and the FS ;ersion =descri)ed in Chapter 4.+> are worBing on a search space containing large num)ers of possi)le solutions. ue to rule pro)lems =Chapter 2>* a limited search space is use in this worB. This search space is the same for all simulations. The num)er of possi)le solutions for this search space* when looBing at a siD time period into the future* is up to -.0Q-,0 solutions. This eAuals the num)er of )ottom nodes on the search tree =see Figure +.0> resem)ling an upside down tree* where each node groo;ing with -1 )ranches. This figure illustrates one simulation )! FS with pre;ious eDecuted dri;e order -+. Gecause the pre;ious eDecuted dri;e order needs to )e included in the e;aluation calculation* the total search space is actuall! -1 times )igger* gi;ing +.0Q-,F solutions. Onl! one of these -1 is used for each time period simulation* depending on the pre;ious eDecuted one. Note that all simulations starts from non3;alid dri;e order -1. This simulated search space + is calculated )! siD le;els deep ) and each of all nodes ha;e -1 )ranches b. That maBes a siD le;els search tree on following eAuation/ +(b) , b = 1-, ) = -, 1-- . 1/01120 This concludes to -0 millions of possi)le solutions to looB through. The Standard GA will onl! conduct up to ?,,, e;aluations out of this search space.

Figure +.0/ Search space for all simulations 5

-,

3 &raffic intersection
The purpose of this worB is to assess the potential of appl!ing GA to sol;e a real world pro)lem. In this worB* it is represented )! a traffic intersection. This choice is )ased on the )asis the function and purpose of an intersection is easil! understood and still pro;ides an ad;anced enough pro)lem to worB on. T!picall! intersections eAual to this* with limited space and tramwa!s* are found in large cities. The purpose is to find an optimal schedule for optimal dri;e order seAuence. The time duration of the traffic lights is supposed to )e fiDed. The assumption maid in this worB* is the use of a controller unit with implemented hardware in form of an em)edded s!stem* contains the Standard GA program controlling the intersection in the realit!. Inputs to the controller are all sensors and push )utton around the intersection and the output is the actual light poles. The actual traffic lights are not printed on Figure ?.- )ut the output ;aria)les are mentioned in AppendiD A and listed in AppendiD C. The location of the input sensors are* for pedestrians the push )uttons =)lacB dots>* for road ;ehicles the sensors under the road lane edge where the! stops for red lights =under the arrows>* and for trams Cust )efore the turn out on tram line where the! usuall! stop for there red lights. There are se;eral worBs that ha;e pro;ided inspiration to this worB with GA and traffic controlling. One eDample is JGuan* et al.* +,,FL* a paper discussing signal time optimization tested on ?, intersections in Changchun cit!. !namic signal control is also used in J(ang* et al.* +,,1L* a paper a)out one isolated intersections onl!. A different )ut inspiriting paper is traffic flow for lane closures to minimize tra;el dela! J$a* et al.* +,,4L. In another paper with d!namic traffic lights time control for pedestrian and passing road ;ehicles on one intersection JTurB!* et al.* +,,5L. Gut almost all of these are outside the intention to do scheduling )! dri;e orders. Additional inspiration for scheduling has )een drawn from paper JFissgusL.

3.1 Description of t+e intersection


The structure of the intersection is )ased on general intersection that can )e found in an! cit! around the world. In general this is a four3wa! intersection from north to south and west to east =see Figure ?.->. Some traffic rules applied on this intersection are as follow. &oad ;ehicles can turn in an! direction eDcept )acB to where the! come from* so U3turns are not allowed in this test. &oad ;ehicles turning left or right ha;e to gi;e wa! for pedestrians at pedestrian crossings. Goth road ;ehicles and pedestrians are to go north)ound and south)ound at the same time* or in the same manner* west)ound and east)ound traffic at the same time. The tram3wa! tra;els in all directions eDcept turning )etween west and south* assuming this cur;e is not reAuired in the intersection. The north and south going street is considered to )e the main road* carr!ing the maCorit! of the traffic load. The street to the west has moderate traffic and slightl! more tram traffic. Finall!* the small street to the east* has a low traffic load )ut trams are more freAuent. All four streets ha;e pedestrian crossings* linBing the pedestrian paths )etween the pa;ements on either side of each --

street. ue to hea;! traffic and the width of the streets* three of the crossings are di;ided up into three separate sections =road ;ehicle lane* tram lane* road ;ehicle lane>. Two push )uttons are pro;ided for each section. The intersection will not )e dependent on other adCacent intersections near)!. This scenario could )e assessed in a potential eDtension of this worB. The Standard GA is onl! to sol;e optimal dri;e order seAuences for this intersection.

Figure ?.-/ Image o;er the intersection

3.2 General functionalit,


The source code contains all the inputs and outputs ;aria)les represented )! the intersection. The inputs are retrie;ed from inputValues arra!s and the outputs are printed on the screen. All dri;e orders allow certain pedestrian* trams and road ;ehicles to go safel!. $ost importantl!* to a;oid accidents* -1 prepared dri;e orders ha;e )een assigned as safe output solutions =see AppendiD A>. %ach sensor input can )e seen as a reAuest from the acti;ator that gi;es a numerical ;alue one. A reAuest needs to )e eDecuted* )! its eAual output* through an appropriate dri;e order. Outputs ha;e onl! a s!m)olic function in the code* although it can )e seen as Goolean representations true for eDecute otherwise false. Note that red and green lights are dependent on the eDecuting dri;e order. -+

Sets of mathematical functions and logic rules e;aluate each dri;e order to Bnow how ;alua)le the! are to )e eDecuted. ri;e order that eDecuting man! reAuests is )etter than less eDecuting ones. %Decuted reAuests get there input ;alue set to zero. For each new time period* outputs for eDecuting the reAuests are alwa!s coming from chromosome num)er one c1. Non3eDecuted reAuests will get their ;alue added )! one to get higher priorit!. This process pro;ides a )etter chance to get higher fitness ;alue in the neDt time period. The mathematical functions are listed in AppendiD G* additional logic rules in AppendiD and outputs according to certain dri;e order in AppendiD C. Further down is a list of letters that form the ;aria)le names of inputs reAuests and their eAual outputs. An eDample* a))re;iations meaning road ;ehicles going from south to north and east would )e called 3S4". Output ;aria)le name of this will then )e +3S4"* and corresponding input reAuest ;aria)le I3S4". First letter/ I for input O for output Second letter/ 6 for pedestrians T for trams & for road ;ehicles Third letter/ N from north)ound direction S from south)ound direction K from west)ound direction % from east)ound direction Forth letter/ N to north)ound direction S to south)ound direction K to west)ound direction % to east)ound direction Fifth letter/ K also to west)ound direction % also to east)ound direction

3.3

as, working e-ample

The following eDample scenario has )een created to further descri)e the functionalit!. This case has one of each pedestrian* tram and road ;ehicle reAuest. %ntire simulation taBes three time periods to complete. The pedestrian reAuest is (*1 on the north3west pa;ement. A push )utton acts as sensor input and input'alue I(*1 eAuals true. G! then is this pedestrian lane reAuested. This pedestrian lane will cause interference to the tram e;entuall!. 6edestrian lane (*$ might )e acti;ated there after. Assume a tram standing from east acti;ating sensor IT"** tempting to go west. Also assuming that the tram dri;er somehow can gi;e a direction order* depending on where the tram route going. Onl! one direction is possi)le to reAuest. On road lane 3S4"* a car coming to stop for red light and sensor I3S4" is acti;ated. "ow man! other road ;ehicles standing )ehind on this lane doesn:t matter. There is nothing that tells where this road ;ehicles going north* east or )oth* the! are allowed for )oth. Although the 3S4" reAuests do interfering the trams reAuest an!wa!. -?

This )eginning situation is shown on Figure ?.+. The car and the pedestrian do not interfering each others* the tram do. Onl! the tram or )oth pedestrian and the car can go on first time period. Two solutions are possi)le )! resulting seAuences F3-,3-2 and -,3 F3-2. $ost fitness do F3-,3-2 ha;e where the tram go first on dri;e order F. Output ;aria)le +T"* sets to true* eAuals to eDecute the tram reAuest. The second predicted dri;e order -, will )e neDt eDecuta)le* where )oth +(*1 and +3S4" are set to true. In theor! the pedestrian needs to acti;ate I(*$ although is not necessar!. The logical seAuence rule 31% in AppendiD gi;ing credits when dri;e order -2 comes after -,. No reAuest for (*$ is needed due this )ecomes eDecuted )! dri;e order -2 an!wa!. The second solution -,3F3-2 is an eDample of a result not as good as what could )e eDpected. The tram needs to wait and there are no eDtra credits for pre;ious dri;e order. For this simple eDample it doesn:t matter who goes first. Otherwise* it:s more crucial in hea;ier traffic situations. The real simulation result of this "#ample case is shown in Chapter 0.+.

Figure ?.+/ Geginning of "#ample case

-4

Ta)le ?.?/ Two different fitness calculations on each dri;e order seAuence
Tram first &. f=c1+c2+c3 &1 f=c1+c2+c3 P & R first &. f=c1+c2+c3 1. 18 ( 6 1. 48 *1 1. 40 1$ 10 *1 ( 10 *2 1$ 8 ( 0 *2 1$ 0 28 58 fitness 54 fitness

A close looB in Ta)le ?.? and a calculation eDample following. This ta)le show the second solution seAuence -,3F3-2. Kh! it:s second )est is simple pro;en )! ;erif!ing the fitness results +F against 24. Note that* in )oth solutions* dri;e order -, ha;e higher ;alue than F. This does not matter when the total fitness ;alue counts for the final result. In the ta)les* on T1 is eDecuta)le " dri;e order -,. Chromosome one c1 ha;e a total ;alue 4F* this ;alue is calculated further down. Note the pre;iousl! dri;e order on T2 is F. First calculation is to summarise inputs )elonging dri;e order -,* in following eAuation =see AppendiD G>/ c1Inputs = I(4$ & I(*1 & I(*$ & I(*5 & I(S$ & I(" & I34* & I34S & $I3S4" Note that the 3S4" is weighted with multiplication )! two. Goth (*1 and 3S4" ha;e ;alue one from pre;ious time period. Until this time period their input ;alues are added )! priorit! with one more point as follow/ c1Inputs = 2 & $ & 2 & 2 & 2 & 2 & 2 & 2 & $6$ = Second calculation ma! gi;e a credit of two points. Is depends on logic rules for dri;e order seAuence from AppendiD . The dri;e order -, has following seAuence rule/ 312 (12 7 ("(8 9 "(: ; <Two(oints

This gi;e in Goolean representation due is true that pre;iousl! dri;e order was F/ 312 true 7 (true 9 false ; true

As the result is Goolean <Two(oints R true* that is eAual to s1 = $ in the e;aluation function. This gi;e the first chromosome c1 = -(c1Inputs&s1 = -(-&$ = =8. The final fitness functions summarise all ;alues )! eAuation/ 1 f = 0 n c nInputs s n n=The second chromosome ha;e no more reAuests left and c$Inputs = 2* pre;ious dri;e order was -, gi;es s$ = $. Total chromosome ;alue is c$ = %(c$Inputs&s$ = 12. Then the total -2

fitness ;alue for T1 is f = =8&12 = %8. The outputs for dri;e order -, when it eDecutes are/ "12 ; +(4$ 7 +(*1 7 +(*$ 7 +(*5 7 +(S$ 7 +(" 7 +34* 7 +34S 7 +3S4" As all of these output ;aria)les are set to true* the pedestrian from (*1 can continue walBing directl! on to (*$ as this too* has green light.

3." Details and modifications


Throughout the testing process* a few adCustments ha;e )een made to impro;e the program. These adCustments in;ol;e weighting of inputs ;aria)les in the e;aluation function. The reason for the weighting is to fa;our some of the rarel! used dri;e orders. The most used dri;e orders include 0* F* -+ and -?* who are often presented )! the Standard GA* and therefore the most strategic dri;e order used. One reason for this is due to the fact that some trams and road ;ehicles reAuests are harder to eDecute. For eDample* tram +T"* =two cases possi)le> and road ;ehicles +3S* =onl! one case possi)le>. Another reason is the amount of pedestrian inputs* as these accumulate man! points )! )eing superior in num)ers. To adCust for these rarel! used dri;e orders* some ;aria)les get weighted )! multipl!ing with a certain num)er. The! get higher pro)a)ilit! to )e used as smarter options in low traffic situations. Further down is an eDample of more hea;! multiplied inputs ;alues to get a chance to )e selected. Note that tram IT"4 and IT4" are multiplied with four which is the highest multiplied ;alue used. Following eAuation is an eDample for dri;e order 1/ cnInputs = =IT4" & =IT"4 & I(45 & I(*1 & I(*$ & I(*5 & I(S$ & I(S5 & I34* & I34S & I34"

-1

" *rograms
The programs that simulate the intersection =computed and microcontroller implemented>* )oth uses Standard GA to find the optimal dri;e order to eDecute. In this worB* an additional program with another search algorithm* epth First Search = FS> JStewart M Nor;ig* +,,?L* is used to ;erif! the performance of )oth Standard GAs. The specific simulation program used is called N FS ;ersionO. The results from the FS ;ersion will )e compared to the results deri;ed from each Standard GA program. The FS onl! looBs for one solution at the time and goes down all le;els in the search tree. The FS can )e programmed to terminate the search if a good solution is found. In this worB* the FS ;ersion will search trough the entire search space to find the )est answer =a complete path to )ottom le;el siD>. This path* representing the dri;e order seAuence* is illustrated in Figure +.0. In summar! the main characteristics of each search method are/ The Standard GA =computed and microcontroller implemented> is fast* although cannot guarantee a )est solution is identified. Otherwise* a good enough solution can )e found. The FS ;ersion will find the )est solution to the cost of eDtensi;e use of time and computation.

In addition to these three simulation programs there are four more ;ersions of simulations to e;aluate. All simulations are eDplained in Chapter 0 and the! are called "#ample case =from Chapter ?.?>* 4ormal case* *orst case one and *orst case two. #isted source codes are Standard GA ;ersion of *orst case one on AppendiD G and FS ;ersion of 4ormal case on AppendiD ". All programs are coded in program language C.

".1 Standard GA !ersions


The following description of the Standard GA ;ersion is for )oth computed and microcontrolled one. Functions used in the program include ecodeChromosome* %;aluateIndi;idual* &eturn&esult* TournamentSelect and &andFunBtion. ecodeChromosome returning the numerical ;alue of a chromosome. %;aluateIndi;idual calculates fitness ;alue for incoming parameters ;alues. &eturn&esult is called after each completed GA loop to list the )est parameters ;alue results. As this is a simulation program* the outputs are onl! represented in a s!m)olic eDpression. TournamentSelect doing the tournaments.

-0

&andFunBtion is called from se;eral places in the main code whene;er a random ;alue is needed. A good random function is essential for all GAs to worB properl!.

In main* the initializations are done in the )eginning. For simulation reasons* up to eight sets of input ;alues for each time period are used. The main loop runs ten times* starting with reading and updating present input ;alues for that time period. Then the Standard GA loop goes through all generations up to the num)ered ;alue of maDGeneration. Inside the Standard GA loop is the traditional worB flow with decoding* e;aluation* fitness measuring* elitism* tournament select* crosso;er and mutation. In the end is a special arra! list goodIndi;iduals that store the )est indi;idual for future time periods. The neDt new population will get the content from this list. In the long run* this list will contain )etter and more impro;ed indi;iduals. This list is a part of the self3learning process in this program. Khen the loop is completed* all )est parameter ;alues are send to function &eturn&esult for print out. In the simulations* the program is run through ten time periods in a so called Nfor loopO. In realit!* where the program is supposed to run continuousl! a Nwhile loopO will )e used.

".2 D#S !ersion


This FS ;ersion is smaller than the Standard GA ;ersion as man! of the GA procedures are then not reAuired. The code is listed in AppendiD ". The onl! functions used are %;aluateIndi;idual and &eturn&esult eAual to the same functions in the Standard GA ;ersion. In main the usual initialization* input ;alues and main loop are almost the same as for the Standard GA ;ersion. Instead of a GA loop there is a FS search with Nnested for loopsO running through the entire search space. This program goes through search down se;en le;els in the search space* where the last siD represent the solution. The first le;el onl! contains one start node* that ;alue is the pre;ious dri;e order. The second le;el will hold the eDecuta)le dri;e order. Finall! the third and lower le;els are predicted dri;e orders =see Figure +.0>. The size of the search space is calculated in Chapter +.?. Khen the first search is completed the result is printed through &eturn&esult. Following this* the second simulation loop commences to search for second eDecuta)le dri;e orders until the neDt time period. There is no guarantee that the pre;ious predicted dri;e order will )e the neDt eDecuta)le one. The program is finished when all ten time periods are simulated. This program will find the optimal solution with cost of time. And time consumption is a maCor draw)acB in certain application.

-F

$ /ule problems
This chapter discuss eDperiences encountered during this worB related to rules and how the! can worB against the GA. The rules considered in this worB are Ofitness measuring rulesO and Nconstraint rulesO. The! are represented with propositional logic. Goth are supposed to )e applied in the e;aluation function to grade indi;iduals according to these rules. This chapter eDplains the constraint rules and the pro)lem the! cause. Constraint rules are strict and must )e fulfilled. Situation ma! occur where indi;iduals )reaB constrained rules. Khen this happens these indi;iduals ma! not )e allowed to sur;i;e and* to discard them* their fitness ;alues are simpl! set to zero. To eDclude or for)id indi;iduals and their solutions could )e considered wasted* )oth of computing time and other s!stem resources* as these solutions are not needed. Constrained relations are mentioned in JGold)erg* -5F5L where it is eDplained that constrains can )e fine* although finding a feasi)le solution can )e almost as difficult as finding the )est one. $ore reading and details in this area is found on J(oonL. In science research constrains are generall! not causing an! maCor pro)lems. The! generall! ha;e sufficient computation as the importance of finding good results are essential. Although constraint rules do not appear to )e a )ig issue* the! do cause a certain pro)lem in this worB. Significant time loss and memor! usage are to )e eDpected on the small* computerised s!stem used in this worB. Theoreticall! constraint rules ma! not )e needed in a well3defined pro)lem. $ore often than not the! cannot )e a;oided. Although a few constraint rules will ha;e little effect* the! ma! cause a real pro)lem in finding decent solutions if the! )ecome more in num)ers.

$.1

-ample of rule problems

Imagine an indi;idual with one chromosome c containing three )inar! represented genes. That gi;es a search space of eight possi)le solutions. The )inar! genes are called g1* g$ and g5. Assume that if the com)ination of g$ and g5 is true and the g1 ;alue doesn:t matter* then =D--> will result in high fitness ;alue. Also assume a constraint rule declaring that if g1 is true =-DD> then that indi;idual must )e for)idden. The outcome will )e a half population )eing for)idden. If GA finds an indi;idual with content =--->* then that produced result will )e wasted. Otherwise content =,--> is not and can )e used. Assume the change of the constrained rule to onl! for)id when g1 is true and g$ is false =-,D>. G! this rule two solutions are gained )acB from the search space =--,> and =--->. #eft is =-,,> and =-,-> which represent +2P of the search space. The loss of possi)le solutions caused )! constrained rules depends on their amount and formulation. A Standard GA* worBing with )oth fitness rules and constrained rules* was used in earl! attempt in this worB. Fitness and constrained rules were )oth propositional logic* representing true or false ;alues. The! also shared and worBed with the same input ;aria)les. These ;aria)les were representing all inputs from the intersection and represented )! one single chromosome containing +5 genes. The search space had a)out -5

++5 S 2.4Q-,0 different solutions as a maDimum. The outcome from this attempt resulted in a serious loss of solutions e;en were onl! one set of constrained rules is used. Following eDample demonstrates how rule 31 for)id a solution when it )ecomes satisfied )! true ;alue/ 31 = I(41 7 (I34* 9 I34" 9 I34S To pass a non for)idden solution the rule 31 must )e unsatisfied )! false. This rule is satisfied when gene one I(41 is true and at least one of the other genes +, =I34*>* +- =I34"> and ++ =I34S> are true. All of the three last genes must )e false to ensure a safe traffic situation. The rule 31 is liBel! to )e satisfied when I(41 is true and at least one or more of the other genes are true =or holding ;alue -> in the following calculation/
0 I (*1 I 34* I I + 34S 34" + ok = = ,.44 + + 4 F F

ApproDimatel! 44P of the search space + will )e satisfied and therefore for)idden. If the last three genes are not included in this rule* the chance will )e Cust 2,P. The last genes actuall! gi;e )acB 1P of the search space* increasing possi)le solution to 21P. To ha;e in mind is that this eDample contains the first rule of +5 in total. Together the! drop the chances )! finding an! descent solution to almost nothing. The following worB will use another strateg! to a;oid all forms of constrained rules* with the one eDception of a single Nif statementO that acts as constrained rule. This statement a;oids chromosome c1 to get ;alue zero. If that happens* the first dri;e order will not eDecute an! reAuests and that would )e a pointless solution.

$.2 Solutions for t+is problem


A prefera)le method to a;oid pro)lems is to ensure that all the possi)le solutions that the GA )rings up are without an! conflict* or at least Beep the amount of constrained rules to a minimum. The onl! rules that should eDist are fitness measuring rules that increase the fitness ;alue. A draw)acB with remo;ing constrained rules is less optimal formulation of the pro)lem to sol;e. That is* the freedom to reall! get into the pro)lem might )e limited and the optimal solution ma! )ecome unreacha)le. Although a good enough solution can still )e found. In this worB constraints are remo;ed with -1 prepared solutions. This appear not so man! to worB with* otherwise in a seAuence of siD the! instead )ecome ;ast in num)er of com)inations.

+,

mbedded solutions

One part of this worB in;ol;es worBing out how GA can )e implemented into an em)edded s!stem. Two main t!pes of em)edded s!stems* F6GA and microcontrollers* ha;e )een considered. This hardware implementation is one fundamental part of this worB. In realit! it would )e unrealistic for a control unit or rela! )oD* used to control the traffic intersection* to contain an ordinar! computer. It would )e more reasona)le to ha;e an electronic circuit )oard with one of the two mentioned em)edded s!stems. The two main reasons for this include component costs and more secure functionalit!. The aim in this worB is to test the potential to use GA in this t!pe of alternati;e application. Though the am)ition is to maBe it worB* it might not )e achie;a)le due to C6U and memor! limitations of the GA. ue to time constraints and necessar! resources not )eing a;aila)le* F6GAs will not )e tested in this worB* instead some earlier worB will )e presented. On other hand* a microcontroller and )elonging de;elop Bit JAtmel STE2,,L is a;aila)le. A draw)acB with the microcontroller is that its memor! size potentiall! is too small for what is reAuired for this application. Otherwise* with a few modifications* it can still achie;e some success. The microcontroller uses programming language C* thus all simulation programs will )e coded in C from the )eginning.

%.1 #*GA
F6GA =Field 6rogramma)le Gate Arra!> is a ;ersatile integrated circuit that can )e designed for specific functionalities. The most commonl! used program language is '" # ='er! high speed integrated circuit "ardware escription #anguage>* for more readings see J'" #L. Some earlier worB has )een done to implement GA into F6GA JAporntewan M Chongstit;atana* +,,-L and JShacBleford* et al.* +,,-L. In JAporntewan M Chongstit;atana* +,,-L a speed comparison was done using Compact GA running as software on +,, $"z computer and the +, $"z F6GA hardware. The result in this stud! was that the hardware ;ersion was -,,, times faster than software ;ersion. A similar comparison JShacBleford* et al.* +,,-L used - $"z F6GA and -,, $"z computer. The F6GA was more than ++,, times faster. Goth studies show faster and more effecti;e results )! the hardware. A draw)acB is when reconfiguration of the fitness function is reAuired* as that can taBe hours to do. Though the resulting effecti;eness appears promising* it is a different stor! when comes to computers. The worB stations used in these studies* around +,,,* was up to +,, $"z and this worB is done in +,-, using a computer with + G"z. Although the clocB speed on F6GAs has also impro;ed during the !ears. For more reading a)out F6GA see manufactures JTilinDL and JAlteraL.

+-

%.2 )icrocontroller
A microcontroller can )e eDplained as a small computer inside one single integrated circuit. The main components include processor* memor! and programma)le input and output peripherals. The microcontroller used in this worB is an ATmega-1 JAtmel Atmega-1L* programmed through a starter de;elopment Bit s!stem* called STE2,, JAtmel STE2,,L from Atmel JAtmelL. Kith a program memor! of -1 E)!tes it )ecomes difficult to fit in a reasona)le simulation program. The simulation program FS ;ersion =descri)ed in Chapter 4> will not )e implemented in a microcontroller* as it is not needed. It would )e possi)le to do so* although the result would )e the same as the computed one. In Figure 1.- is a picture of the entire set up for the simulations. Figure 1.+ illustrates a close up picture of the presented results. The Standard GA for the microcontroller will reAuire some smaller program changes in order to worB properl!. Small modifications are made in random and print out functions. %speciall! in the print out function as there is no computer screen to show the results on* onl! a #C displa!. The population is reduced from ?, to four indi;iduals as a direct conseAuence of the smaller memor! size. Goth the computed and the microcontrolled Standard GA will perform ?,,, indi;iduals per simulated time period. The microcontroller will compensate with 02, generations rather than -,,. One draw)acB is the num)er of performed elitism in each simulation. There is one elitism performed in each generation* now 02, rather that onl! -,,* in the microcontrolled Standard GA. %litism itself does not contri)ute with new material in the e;olutionar! process* with the conseAuence of potential limitation in performance.

++

Figure 1.-/ %ntire simulation set up

Figure 1.+/ &esult print out on displa!

+?

+4

' Simulations
It is important to remem)er that a complete or final result is not eDpected. The aim is to test how well the GA can perform and further impro;ements will still )e reAuired. This worB will compare and assess the simulations of the three programsI computed Standard GA* microcontrolled Standard GA and FS ;ersion. %ach program has four prepared simulation cases that will gi;e -+ different results. All results and their )eha;iours will )e eDplained )riefl!. The simulation outputs actuall! looBs in two different wa!s as follow. The first and last simulation programs are computed ones* doing their printout windows on a computer screen. The second simulation program is implemented inside a microcontroller* performing printouts on a #C 3displa!. These microcontrolled printouts looB rather different and onl! ha;e two printed lines =see Figure 1.+>. %Dample of result from printout windows from the computed Standard GA and the FS ;ersion can )e found in AppendiD % and AppendiD F.

'.1 About t+e simulations


The four simulation cases are/ "#ample case 4ormal case *orst case one *orst case two %as! case with onl! three reAuests to handle. An eDpected dail! life situation or normal condition. All inputs reAuesting including easier tram reAuests. All inputs reAuesting including harder tram reAuests.

The results from the simulations are listed in pairs* in the result ta)les further down. The first ta)le contains the "#ample case and the 4ormal case. The second ta)le contains )oth *orst case one and *orst case two. The "#ample case* with one of each pedestrian* tram and road ;ehicle reAuest* has some interference* which is further descri)ed in Chapter ?.?. In the program code there are three sets of input ;aria)les* which is enough for the entire simulation. The results are listed in Ta)le 0.+* Ta)le 0.4 and Ta)le 0.1. The 4ormal case is supposed to illustrate a real simulation from the dail! life. Normall! the sensor inputs are in a moderate amount most of the time =see ta)le 0.->. Some lanes ha;e more traffic and other less. A consistent and continuous pedestrian traffic is assumed* with an e;en distri)ution o;er the corners of the intersection. Trams tend to come and go from north)ound direction. The set of input ;alues are chosen in a wa! so no duplicated tram reAuests can occur in an! simulations* that is* a tram can onl! reAuest one direction. The input ;alues for time periods F and 5 all ha;e inputs set to zero. The reason for this is to ;erif! the ending of the simulation without an! new inputs +2

affecting the result. The results are listed in Ta)le 0.+* Ta)le 0.4 and Ta)le 0.1. Ta)le 0.-/ Input ;alues for 4ormal case empt! cells ha;e ;alue ,
Inputs from pedestrians i*01 &. &1 &2 &3 &" &$ &% &' &( &2 Inputs from trams i&01 &. &1 &2 &3 &" &$ &% &' &( &2 Inputs from road sensors i/01 &. &1 &2 &3 &" &$ &% &' &( &2 1 1 1 1 1 1 1 1 1 i/0 1 i/0S 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i/10 i/1S i/ 01 i/ S i/S1 1 i/S0 1 1 1 1 1 1 1 1 1 1 1 i&0 i&0S i&10 1 i&1 i& 0 i& 1 i& S i&S0 1 i&S 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i*02 i*03 1 1 1 1 1 i*11 i*12 i*13 1 1 1 1 1 1 1 1 1 i* i*S1 i*S2 i*S3 1

+1

The following two simulations are less authentic the real world* the! can occur although not often. Khat *orst case one and *orst case two ha;e in common is that the! )oth onl! ha;e input ;alues in the first time period. The following time periods are free from an! reAuests to a;oid simulation interference. Ten time periods are used to get a complete ;iew of the sol;ed pro)lem. Goth cases ha;e all pedestrian and road ;ehicle reAuests set in the )eginning. The difference )etween the cases is the t!pe of reAuests coming from the trams. In *orst case one there is one tram on either side of the intersection waiting to go straight. These are TNS* TK%* T%K and TSN. In *orst case two* there are trams that intend to turn* resulting in more traffic )eing )locBed. These trams are TN%* TKN* T%S and TS%. The )est predicted dri;e order from *orst case one would )e 0* F* -+ and -?. This is for the first four time periods* followed )! two random dri;e orders. *orst case two reAuires siD time periods with dri;e orders of 2* 1* 0 or -,* F or --* -+ and -?. Note that some dri;e orders can complement each other to some eDtend. The results are listed in Ta)le 0.?* Ta)le 0.2 and Ta)le 0.0. Note that all simulations for each time period are dependent on the pre;ious eDecuted dri;e order. 6resent inputs with new and older prioritised reAuest ;alues will change the outcome in e;er! new time period. Also unpredicta)le results can occur along longer simulation time.

'.2 *erformed simulations


All ta)les contain two simulations each* and there are -+ simulations in total. %ach completed time period from )oth the Standard GA and the FS ;ersion* results in a solution with siD dri;e orders. The first dri;e order )ecomes the eDecuta)le one. The following one is the first predicted dri;e order* out of fi;e in total. Notes for ta)le la)els is the first time period called T2 and counting upwards. The first eDecuting dri;e order is denoted " and the following first predicted dri;e order is (1 and counting upwards. &esulting fitness ;alue is each time periods maDimum fitness ;alue denoted Mf. Underlined num)ers simpl! tells that dri;e orders do eDecute on or more reAuests. Time periods without an! waiting reAuests can hold an! random dri;e order as a result.

'.2.1 Computed Standard GA simulations


The following is a summar! of the results from the computed Standard GA simulations. The results of the "#ample >ase and 4ormal case are outlined in Ta)le 0.+ and the results from *orst case one and *orst case two in Ta)le 0.?. The resulting dri;e order seAuence in the "#ample case is F3-,3-2* the rest are non3 ;alid outputs. In the 4ormal case there is a long seAuence where 2 and -? are repeated. These two dri;e orders are repeatedl! predicted and so is 0* F and -+. Compared to the "#ample case* the 4ormal case has higher fitness ;alues as a result of the higher num)er of reAuest in;ol;ed. Time taBen to run the simulation with + G"z was a)out one second.

+0

Ta)les 0.+/ Standard GA on computer for "#ample case and 4ormal case
Standard GA -ample case *1 *2 *3 *" *$ )f &. 8 12 4 7 7 7 7 7 7 7 7 8 5 13 13 13 13 13 13 13 13 7 7 7 7 7 7 7 7 7 11 11 0 9 0 56 70 38 0 0 0 0 0 0 0 &. &2 &3 &$ &' 5 7 8 5 6 &1 10 &2 15 &3 15 &" 15 &$ 15 &% 15 &' 15 &( 15 &2 15 12 14 Standard GA 0ormal case *1 *2 *3 *" *$ )f 12 12 12 13 6 10 7 7 5 5 5 6 9 5 5 5 8 8 13 13 13 10 11 11 12 12 12 7 3 7 9 3 0 8 8 103 8 159 8 236 8 228 8 216 10 188 6 240 4 156 7 136 &1 13 12

13 15 13 15 13 15 13 15 13 15 13 15 13 15

&" 12 13 &% 13

10 15 11 202

&( 11 10 &2 10 15

*orst case one is almost as predicta)le* resulting in seAuence 03F3-+ and -?. In *orst case two it was predicted in the first time period T2 that four more dri;e orders were needed to sol;e the pro)lem. A closer looB in Ta)le 0.? re;eals that the pro)lem onl! )ecomes sol;ed in time period T%* rather than T=. In other words* one additional time period was needed to complete the simulation. Notice that dri;e order -? is first predicted in (1 for se;eral time periods. The reason for this is that the condition in each time period is affected )! pre;ious dri;e orders and new incoming reAuests. Ta)les 0.?/ Standard GA on computer for )oth worst cases
Standard GA 1orst case 1 *1 *2 *3 *" *$ )f &. &1 7 8 8 12 14 7 12 5 5 5 5 5 5 5 5 12 12 12 12 12 12 12 9 11 8 13 13 13 13 13 13 13 1 187 6 274 0 162 3 126 3 3 3 3 3 3 0 0 0 0 0 0 &. 5 12 13 5 5 5 5 5 5 5 Standard GA 1orst case 2 *1 *2 *3 *" *$ )f 13 7 6 6 6 7 5 5 5 5 5 11 6 11 180 8 240 8 230 8 238 12 166 12 12 12 12 0 0 0 0 &1 12 13 &2 11 13 &3 10 13 &" 6 13 0 0 0 0 0 &$ 13 &% 13 &' 13 &( 13 &2 13 11 10 15 240 10 15 8 11 13 13 13 13 13 12 0 5 5 5 5 5

&2 12 13 &3 13 &" 13 &$ 13 &% 13 &' 13 &( 13 &2 13

'.2.2 )icrocontrolled Standard GA simulations


ue to the limitations of the Standard GA in this microcontroller implementation* some differences in the results are to )e eDpected. The clocB speed for the microcontroller is F $"z. The time taBen to complete the simulation was approDimatel! +4 seconds. There are no underlined dri;e orders to indicate if that dri;e order will eDecute a reAuest* in Ta)le 0.4 and Ta)le 0.2. Onl! the most essential num)ers* dri;e order seAuence and maDimum fitness ;alue are presented. +F

Ta)les 0.4/ Standard GA on microcontroller for "#ample case and 4ormal case
Standard GA -ample case *1 *2 *3 *" *$ )f &. 10 &1 15 &2 8 &3 16 &" 16 &$ 16 &% 16 &' 16 &( 16 &2 16 8 8 0 0 0 0 0 0 0 7 12 0 0 0 0 0 0 0 13 8 9 0 0 0 0 0 0 0 1 10 0 0 0 0 0 0 0 3 5 0 0 0 0 0 0 0 51 46 0 0 0 0 0 0 0 &. 12 &1 &2 &3 &$ 5 8 7 5 12 14 53 Standard GA 0ormal case *1 *2 *3 *" *$ )f 5 10 10 5 7 9 9 13 6 8 7 5 3 6 1 5 9 10 13 11 12 4 9 12 1 9 102 3 139 2 199 4 274 9 203 13 230 5 304 5 330 3 192 14 11

12 14

13 12 12 13 6

&" 11

&% 12 13 &' 13 &( &2 6 5

13 14 266

11 10

11 10 11 10

Ta)les 0.2/ Standard GA on microcontroller for )oth worst cases


Standard GA 1orst case 1 *1 *2 *3 *" *$ )f &. &2 8 7 12 13 7 0 0 0 0 0 0 7 7 7 8 0 0 0 0 0 0 13 8 11 7 0 0 0 0 0 0 7 10 2 8 0 0 0 0 0 0 8 186 9 224 13 214 1 136 0 0 0 0 0 0 0 0 0 0 0 0 &. 12 &1 13 &2 6 &1 12 13 &3 13 &" 16 &$ 16 &% 16 &' 16 &( 16 &2 16 Standard GA 1orst case 2 *1 *2 *3 *" *$ )f 5 5 13 6 8 9 8 0 0 0 0 6 3 10 10 10 0 0 0 0 8 13 9 1 4 0 0 0 0 2 180 0 234 2 242 15 234 9 184 13 92 0 0 0 0 0 0 0 0 11 10

13 11

&3 13 11 &" 11 10 &$ 10 &% 16 &' 16 &( 16 &2 16 9 0 0 0 0

The general impression is that the microcontrolled Standard GA ha;e slightl! lower performance than the computed one. This is eDpected as it is affected )! man! more elitisms. The dri;e order seAuences for the microcontrolled Standard GA are different to )oth computed Standard GA and FS ;ersion. The fitness ;alues are also lower than in the other ;ersions* )ut not far )ehind the computed ones.

'.2.3 D#S !ersion simulations


The ad;antage with the FS ;ersion is that it alwa!s searches through the entire search space to find the )est results. For that reason all resulting solutions from each separate time period* can )e considered as the right answer. On the other hand* it is less certain it will get the )est outcome in long term simulations with se;eral time periods. The FS ;ersion program performs the FS process in all the ten time periods* until it is completel! finished. Time taBen to complete the simulation with + G"z from start to +5

finish was a)out - minute and 2, seconds* or a)out -- seconds per time period. Ta)le 0.1/ FS ;ersion for "#ample case and 4ormal case
D#S !ersion -ample case *1 *2 *3 *" *$ )f &. 8 10 9 5 5 5 5 5 5 5 5 9 10 12 12 12 12 12 12 12 12 10 9 5 5 5 5 5 5 5 5 9 10 11 11 11 11 11 11 11 11 10 63 4 0 0 0 0 0 0 0 0 78 38 0 0 0 0 0 0 0 &. &2 &3 5 8 7 &1 10 &2 15 &3 15 &" 15 &$ 15 &% 15 &' 15 &( 15 &2 15 &1 12 D#S !ersion 0ormal case *1 *2 *3 *" *$ )f 12 8 7 13 5 13 6 5 8 7 13 5 5 13 6 10 7 13 5 13 6 10 5 9 8 5 11 7 10 4 11 9 10 7 108 11 178 0 202 4 270 8 224 4 253 0 292 0 319 10 324 4 194

11 12

&" 11 12 &$ 12 &% &( &2 5 6 5 &' 13

11 10

11 10

In the "#ample case outlined in Ta)le 0.1 the seAuence F3-,3-2 is eDpected. All other num)ers ha;e no effect e;en though the! happen to )e in repeating order all the wa!. This is an effect in all FS simulations. After T$ no time period will ha;e an! effecti;eness. The 4ormal case uses almost the same dri;e orders as the computed Standard GA* onl! in a slightl! different order. Ta)le 0.0/ FS ;ersion for )oth worst cases
D#S !ersion 1orst case 1 *1 *2 *3 *" *$ )f &. &1 8 7 7 13 5 5 5 5 5 5 5 13 5 5 12 12 12 12 12 12 12 5 12 12 5 5 5 5 5 5 5 12 5 5 11 11 11 11 11 11 11 4 193 11 238 11 164 0 126 0 0 0 0 0 0 0 0 0 0 0 0 &. 12 &1 &3 5 6 &2 11 D#S !ersion 1orst case 2 *1 *2 *3 *" *$ )f 5 11 6 11 6 6 13 9 10 9 9 9 9 9 13 7 9 10 9 10 10 10 10 10 3 187 8 262 10 259 4 256 10 190 4 102 4 4 4 4 0 0 0 0

&2 13 12 &3 12 &" 12 &$ 12 &% 12 &' 12 &( 12 &2 12

13 10 9 10 10 10 10 10

13 10 9 9 9 9 9

&" 13 10 &$ 10 &% 10 &' 10 &( 10 &2 10

The results for *orst case one in Ta)le 0.0 show eDcellent result with eDecuted seAuence F303-?3-+. *orst case two has the same dri;e orders as the computed Standard GA* onl! in a different seAuence order.

?,

'.3 Simulation results


To come to a final conclusion* the results from all pre;ious simulations with computed Standard GA* microcontrolled Standard GA and FS ;ersion need to )e compared and ;erified. The essential data to ;erif! are the maDimum fitness ;alues* as this is the measure of their performances in each simulation. The simulations from the "#ample case and the 4ormal case are shown in Figure 0.F. And the simulations from *orst case one and *orst case two in Figure 0.5. The FS ;ersion is used as guidance of assumed )est result in each simulation case. Thus* the ideal solution from )oth computed and microcontrolled Standard GA would )e an eDact cop! of the FS ;ersion@s dri;e order seAuence. No Standard GA is eDpected to perform the same solutions as the FS ;ersion under the same conditions. To ha;e in mind that )oth ha;e the eDact same simulation cases and e;aluation function to worB with. The large amount of good solutions will ena)le the Standard GA to )ring up its own solutions* which differ from the FS ;ersion. These solutions can present different dri;e orders as earl! as in the first or second time period. This means the FS ;ersion and the Standard GA start worBing on different solutions* which are not directl! compara)le. This means a strict comparison )etween the two ;ersions is not possi)le. The comparison will instead come to rel! on indirect comparison or a general o;er;iew from the maDimum fitness ;alues Mf. The Be! factor in assessing the results is comparing the two ;ersion@s final maDimum fitness ;alues and not matching the dri;e order seAuences. The )est guideline to compare all simulations is to looB for high fitness in the )eginning and lower fitness in the end. A higher fitness indicates that more reAuests are eDecuted. ConseAuentl!* opposite results indicates less good performance. The graph in Figure 0.F shows the simulation from "#ample case and 4ormal case. In the "#ample case )oth computed simulations perform the eDact same seAuence. The microcontroller on the other hand finds a less good solution and gets lower fitness in the )eginning. In the 4ormal case something different occurs in the long run. On the first two time periods the computed Standard GA gets seAuence 23-? and the FS ;ersion has higher fitness with 23-+. It has a small difference* although in T$ the Standard GA performs much )etter than FS ;ersion/ #ower fitness ;alues* following after higher ones* means man! reAuests ha;e )een eDecuted and less reAuests remaining. All results from T5 to T: show that the computed Standard GA has less worB to do. This is an interesting result* demonstrating that the FS ;ersion do not impress in the long run in this case. In the *orst cases in Figure 0.5 there is ones again interesting results from the computed Standard GA and the FS ;ersion. In *orst case one the results gi;es a clear ;iew of good and less good performance )etween the three programs. The! ha;e almost eAual fitness in T2* then the computed Standard GA eDecute dri;e order 0 instead of the )est one F* as this is a result from FS ;ersion. In T1 the computed Standard GA has a significant higher fitness than the FS ;ersion* and then the! )ecome almost eAuals again in T$ and T5. The microcontrolled Standard GA do not performing that well which results in higher fitness ;alue in T$ and T5.

?-

Finall! in *orst case two a ;er! eAual performance is shown with onl! slightl! higher fitness ;alue in the FS ;ersion. The microcontrolled Standard GA performs ;er! well through the entire simulation* e;en slightl! )etter than the FS ;ersion in the ending. In T$ and T5 the fitness ;alue of the computed Standard GA is slightl! lower then the others. These results in much higher fitness ;alue in T= and T% compared to )oth the microcontrolled Standard GA and the FS ;ersion. Goth computed and microcontrolled Standard GA manage to a;oid getting stucB in Nlocal optimumO. A local optimum is a N)elie;edO good solution or result that is far from the reall! good one. It is pro;en )! the maDimum fitness ;alue* which will )e significant lower than the FS ;ersion fitness ;alue. If a search space could )e presented in a graph* it would appear as a mountain chain in the horizon with peaBs and ;alle!s. Khere the !3aDle is the fitness* represented )! the height of the mountains and horizon is the D3aDle. Although the highest peaB holds the )est solution* lower peaBs can mislead a GA to )elie;e the! actuall! are the highest peaB. A GA is more liBel! to continue clim)ing on the peeB it )elie;es is )eing the )est one. All simulations here do show what dri;e orders are )est for this particular intersection. It is possi)le to figure out good solutions directl! from the rules. ri;e orders 2* 1* 0* F* -+* -? and -2 are most usa)le and the )est seAuence to use in theor! is 03-?323-+3F according to the seAuence rules. Of all -1 dri;e orders some of them are rarel! or almost ne;er used as ,* -* +* ?* 4 and -4. This is )ecause their configuration easil! can )e replaced )! the others. A )rief conclusion of these simulations is summarised in Chapter F.-.

?+

Example case an n!rmal case


"tan ar #$ %!mp&ter "tan ar #$ 'icr!c!ntr!ller ()" *ersi!n

350

'axim&m fitness *al&e

300 250 200 150 100 50 0 T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T0 T1 T2 T3 T4 T5 T6 T7 T8 T9

Time peri! s

Figure 0.F/ "#ample case and 4ormal case with comparing )oth Standard GA and FS ;ersion

+!rst case !ne an t,!


"tan ar #$ %!mp&ter "tan ar #$ 'icr!c!ntr!ller ()" *ersi!n

300

'axim&m fitness *al&e

250 200 150 100 50 0 T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T0 T1 T2 T3 T4 T5 T6 T7 T8 T9

Time peri! s

Figure 0.5/ *orst case one and two with comparing )oth Standard GA and FS ;ersion

??

?4

( Conclusion
The nature of this traffic intersection )ecomes rather simple due to safet! reason. Although* it turn out to gain enough compleDit! when a seAuence of time periods are considered. Important to point out that more worB is reAuired for further impro;ements* the results from this thesis esta)lishes that Standard GA do worBs as eDpected. The test of implementing a microcontroller also turns out well.

(.1 Simulation conclusion


The outcome of the comparison* )etween results from the four different cases in Chapter 0.?* is Auite surprising. espite the fact that onl! four cases were used* performance differences )etween the cases could )e detected. The results also demonstrate that a solution that might )e the )est one in a particular moment in time might not pro;e to )e the )est solution in the long run. A good eDample is the microcontrolled Standard GA* with lower performance can perform Auite well in some circumstances. For )oth Standard GA programs* a good performance is achie;ed when their fitness is ;er! close to that of the FS ;ersion. This applies )oth for each time period comparison as well as for the general outcome in a long run simulation. To get a )etter understanding of their performances more simulations will )e reAuired. Although these simulations pro;ide an indication of how good results the! can perform. A final conclusion of the simulation results is that a GA is capa)le of finding good solutions with little effort. The Auestion is not what simulation program is the )est. In fact that the! do worB at all matters. The aim of this worB was to realise all three simulation programs and pro;e their functionalities. In particular the microcontrolled Standard GA implemented inside a simpler hardware s!stem. The limitation of the microcontrolled Standard GA was the o;er num)ered amount of elitisms which in the simulations resulted in lower performance and fitness ;alues as compared to the computed simulation programs.

(.2 #uture impro!ements


The! are room for more adCustments and there are still man! possi)ilities for further refinements and impro;ements. One eDample is to enhance the program to ena)le control of multiple intersections. Testing how the random function differs )etween computers and microcontrollers* is another potential area for impro;ements* as different random functions might gi;e different performances. A few things which were considered to do from the outset of this worB included F6GA implementation* more self learning and ro)ust functionalit! for direct control. A complete F6GA implementation would )e considered as a final result for this worB. ue to time limits and no hardware access the microcontroller implementation where realised instead. $icrocontrollers are slower than F6GAs* although the speed does not matter in the simulations. ?2

Self learning is somewhat used in a simplified wa! in this worB )! storing good indi;iduals for future use. This method maBes it faster to looB for )etter solutions. It could )e eDtended in this worB. Otherwise it worBs well despite )eing ;er! simple. $ore ro)ust functionalit! is needed for direct control in the realit!. Things to impro;e include rules settings in the e;aluation function* and con;ert the hardware ;ersion of this simulation program into a real controller program.

(.3 Summar,
The result from this thesis ma! not contain a final solution* for eDample a hardware implementation read! to use* its onl! sta!s on simulation programs. Otherwise* it could )e seen as a tool or an optional idea for further de;elopment into similar pro)lems in the future. G! their nature* GAs has a somewhat unpredicted )eha;iour that ma! not fit in safet! critical en;ironments. Thus* whether or not to recommend direct control for the intersection is not straight forward. In guidance for de;elopments GA are reall! good. This is not a common area where not man! attempts are done. Usages of GAs are almost occurring in scientific area as research or optimization. A)out putting GA into a microcontroller is not ;er! common. The papers with scientific implementation of GAs on F6GAs are toda! old. The! where successful )! then and should )e e;en toda!. One aim in this worB is how to mo;e out the GAs to the real outside world for different needs. A conclusion so far is still not man! reasons to do that. Traffic intersection is )etter to )e de;eloped )! GA rather than controlled from it after all. In other hand this need of GA ma! groo;ing in the future. For eDample a hand held de;ices in car na;igator might need to sol;e Tra;elling Salesmen 6ro)lem =TS6>* which is commonl! sol;ed )! GA. The most interesting disco;er! is the constrained rules. It was hard to predict from the )eginning and a surprise when it was disco;ered. Otherwise the lesson from this is good and important to ha;e in mind when defining GA for certain pro)lems. %n;ironmental )enefits )ehind intersection control are )etter traffic flow and sa;ing time and pollution. $ost scientific worB with GA do traffic flow impro;ements through se;eral intersections* in some real cities around the world. AdCacent intersections where not considered in this worB. Is not that much worB on this area in general* and not man! other worBs to reference. Almost all scientific worBs referring to one single )ooB JGold)erg* -5F5L* that is the first real description a)out GAs. $ost of these simulation programs and rules de;eloping is made from the )eginning. At last the worB of this master:s thesis has )eing ;er! interesting to worB with. Se;eral new ideas and impro;ements to this worB ha;e coming up along the wa!. Otherwise* this worB will )e considered as good enough.

?1

2 /eferences
2.1 3ooks
JGold)erg* -5F5L Gold)erg* . %.* -5F5. ?enetic algorithm in search, optimi@ation an) machine learning/ 6u)lisher/ Addison3Kesle!. JStuart M Nor;ig* +,,?L Stuart* &. M Nor;ig* 6.* +,,?. <rtificial Intelligence < Mo)ern <pproach/ +nd ed. 6u)lisher/ 6rentice "all. JKahde* +,,FL Kahde* $.* +,,F. Aiologically inspire) optimi@ation metho)s an intro)uction/ Southampton/ KIT 6ress.

2.2 Documents
JAporntewan M Chongstit;atana* +,,-L Aporntewan* C. and Chongstit;atana* 6.* +,,-. A hardware Implementation Of The Compact Genetic Algorithm* -* pp. 1+4U1+5 JFissgusL Fissgus* U.* Scheduling Using Genetic Algorithms. JGuan* et al.* +,,FL Guan* V.* (ang* W.* Kang* (.* "u* J.* Vin* J.* +,,F. &esearch on the Coordination Optimization $ethod )etween Traffic Control and Traffic Guidance )ased on Genetic Algorithm* pp. ?+,3?+2. J$a* et al.* +,,4L $a* K.* Cheu* &. #.* #ee* 3".* +,,4. Scheduling of #ane Closures Using Genetic Algorithms with Traffic Assignments and istri)uted Simulations* Bournal of Transportation "ngineering* $a! -* -?, =?>* pp. ?++3?+5. JShacBleford* et al.* +,,-L ShacBleford* G.* Snider* G.* Carter* &.* OBushi* %.* (asuda* $.* Seo* E.* (asuura* ".* +,,-. A "igh36erformance* 6ipelined* F6GA3Gased Genetic Algorithm $achine* ?enetic (rogramming <n) "!ol!able Machines, +* pp. ??31, JTurB!* et al.* +,,5L TurB!* A. $.* Ahmad* $.S.* (usoff* $.W.$.* "ammad* G. T.* +,,5. Using Genetic Algorithm for Traffic #ight Control S!stem with a 6edestrian Crossing* pp. 2-+U2-5.

?0

J(ang* et al.* +,,1L (ang* W.* "uang* T.* #iu* ".* Tiang* C.* +,,1. $ulti3phase Traffic Signal Control for Isolated Intersections Gased on Genetic Fuzz! #ogic* pp. ??5-3??52. J(oonL (oon* J. 6.* TechniAues for ata and &ule 'alidation in Enowledge Gased S!stems* Department of "lectrical "ngineering Cni!ersity of 'lori)a, ?aines!ille, 'D 5$-1 I * pp. 1+30,.

2.3 Internet
JAlteraL A;aila)le at/ http/77www.altera.com7 JAccessed -5 $a! +,-,L. JAtmelL A;aila)le at/ http/77www.atmel.com7 JAccessed -5 $a! +,-,L. JAtmel ATmega-1L Atmel Corporation* +,,5. 8Ebit Microcontroller with 1-F Aytes InESystem (rogrammable 'lash, Jinternet L Atmel Corporation* A;aila)le at/ http/77www.atmel.com7d!n7resources7prodXdocuments7doc+411.pdf JAccessed -5 $a! +,-,L. JAtmel STE2,,L A;aila)le at/ http/77www.atmel.com7d!n7products7toolsXcard.aspYtoolXidR+0?2 JAccessed -5 $a! +,-,L. J'" #L A;aila)le at/ http/77www.eda.org7;asg7 JAccessed +, June +,-,L. JTilinDL A;aila)le at/ http/77www.DilinD.com7 JAccessed -5 $a! +,-,L.

?F

1. Appendi-

Appendix A. Appendix B. Appendix C. Appendix D. Appendix E. Appendix ". Appendix !. Appendix #.

Traffic intersection drive orders chart Mathematical fitness functions Propositional logic for outputs Propositional logic for drive order sequence Program windows of tandard !A Program windows of D" version Program code of tandard !A Program code of D" version

?5

4,

Appendi- A &raffic intersection dri!e orders c+art

Figure A/ Chart contain all -1 prepared dri;e order outputs

4-

4+

Appendi- 3 )at+ematical fitness functions


#ist of fitness calculation for ;aria)le cnInputs each dri;e order. ri;e order ,/ cnInputs = IT4* & IT"4 & ITS" & I(41 & I(4$ & I(45 & I(S1 & I(S5 & I34* ri;e order -/ cnInputs = IT4* & IT"4 & IT*" & I(45 & I(*1 & I(S1 & I(S$ & I(S5 & I3*S" ri;e order +/ cnInputs = IT4S & IT"4 & ITS" & I(*1 & I(*$ & I(*5 & I(45 & I(S5 & I34* & I34S ri;e order ?/ cnInputs = IT4* & ITS4 & I(*1 & I(*5 & I(" & I(S1 & I34* & I3S4" ri;e order 4/ cnInputs = IT"* & ITS" & I(41 & I(4$ & I(45 & I(*5 & I(S1 & I(S5 & I3"4* ri;e order 2/ cnInputs = IT4* & IT*4 & IT"S & ITS" & I(45 & I(*1 & I(*5 & I(S1 & I(S5 & I34* ri;e order 1/ cnInputs = IT4" & IT"4 & I(45 & I(*1 & I(*$ & I(*5 & I(S$ & I(S5 & I34* & I34S & I34" ri;e order 0/ cnInputs = IT4S & ITS4 & I(*1 & I(*$ & I(*5 & I(" & I34* & I34S & I3S4" ri;e order F/ cnInputs = IT*" & IT"* & I(41 & I(4$ & I(45 & I(S1 & I(S$ & I(S5 & I3"4* & I3*S" ri;e order 5/ cnInputs = IT4* & IT*4 & I(41 & I(45 & I(*1 & I(S1 & I(S$ & I(S5 & $I3*4 & I3*S" ri;e order -,/ cnInputs = I(4$ & I(*1 & I(*$ & I(*5 & I(S$ & I(" & I34* & I34S & $I3S4"

4?

ri;e order --/ cnInputs = I(41 & I(4$ & I(45 & I(*$ & I(S1 & I(S$ & I(S5 & $I3"4* & $I3*S" ri;e order -+/ cnInputs = I(4$ & I(45 & I(*1 & I(*$ & I(*5 & I(" & I(S1 & I(S$ & $I34" & $I3S* ri;e order -?/ cnInputs = I(41 & I(4$ & I(45 & I(*1 & I(*$ & I(S1 & I(S$ & I(S5 & $I3*4 & $I3"S ri;e order -4/ cnInputs = ITS" & IT"S & I(41 & I(4$ & I(45 & I(*1 & I(*$ & I(*5 & I(S1 & I(S5 & I3"S ri;e order -2/ cnInputs = IT4" & IT"4 & I(41 & I(45 & I(*1 & I(*$ & I(S1 & I(S$ & I(S5 & $I3*S"

44

Appendi- C *ropositional logic for outputs


#ist of logical outputs for each dri;e order that eDecutes )! "n. ri;e order ,/ "2 ; +T4* 7 +T"4 7 +TS" 7 +(41 7 +(4$ 7 +(45 7 +(S1 7 +(S5 7 +34* ri;e order -/ "1 ; +T4* 7 +T"4 7 +T*" 7 +(45 7 +(*1 7 +(S1 7 +(S$ 7 +(S5 7 +3*S" ri;e order +/ "$; +T4S 7 +T"4 7 +TS" 7 +(*1 7 +(*$ 7 +(*5 7 +(45 7 +(S5 7 +34* 7 +34S ri;e order ?/ "5 ; +T4* 7 +TS4 7 +(*1 7 +(*5 7 +(" 7 +(S1 7 +34* 7 +3S4" ri;e order 4/ "= ; +T"* 7 +TS" 7 +(41 7 +(4$ 7 +(45 7 +(*5 7 +(S1 7 +(S5 7 +3"4* ri;e order 2/ "% ; +T4* 7 +T*4 7 +T"S 7 +TS" 7 +(45 7 +(*1 7 +(*5 7 +(S1 7 +(S5 7 +34* ri;e order 1/ "- ; +T4" 7 +T"4 7 +(45 7 +(*1 7 +(*$ 7 +(*5 7 +(S$ 7 +(S5 7 +34* 7 +34S 7 +34" ri;e order 0/ "0 ; +T4S 7 +TS4 7 +(*1 7 +(*$ 7 +(*5 7 +(" 7 +34* 7 +34S 7 +3S4" ri;e order F/ "8 ; +T*" 7 +T"* 7 +(41 7 +(4$ 7 +(45 7 +(S1 7 +(S$ 7 +(S5 7 +3"4* 7 +3*S" ri;e order 5/ ": ; +T4* 7 +T*4 7 +(41 7 +(45 7 +(*1 7 +(S1 7 +(S$ 7 +(S5 7 +3*4 7 +3*S" ri;e order -,/ "12 ; +(4$ 7 +(*1 7 +(*$ 7 +(*5 7 +(S$ 7 +(" 7 +34* 7 +34S 7 +3S4"

42

ri;e order --/ "11 ; +(41 7 +(4$ 7 +(45 7 +(*$ 7 +(S1 7 +(S$ 7 +(S5 7 +3"4* 7 +3*S" ri;e order -+/ "1$ ; +(4$ 7 +(45 7 +(*1 7 +(*$ 7 +(*5 7 +(" 7 +(S1 7 +(S$ 7 +34" 7 +3S* ri;e order -?/ "15 ; +(41 7 +(4$ 7 +(45 7 +(*1 7 +(*$ 7 +(S1 7 +(S$ 7 +(S5 7 +3*4 7 +3"S ri;e order -4/ "1= ; +TS" 7 +T"S 7 +(41 7 +(4$ 7 +(45 7 +(*1 7 +(*$ 7 +(*5 7 +(S1 7 +(S5 7 +3"S ri;e order -2/ "1% ; +T4" 7 +T"4 7 +(41 7 +(45 7 +(*1 7 +(*$ 7 +(S1 7 +(S$ 7 +(S5 7 +3*S"

41

Appendi- D *ropositional logic for dri!e order se4uence


6ropositional logic descri)es what dri;e order seAuence that gi;es addition of two points to the fitness ;alue calculation )! ;aria)le sn. %Dample rule 31* if (1 and "(15 are true* <Two(oints will also )e true and that is eAual to ;aria)le sn = $ in the e;aluation function. 6re;ious eDecuted dri;e order R "(n 6resent dri;e order R (n Addition of two points true or false R <Two(oints 31 3$ 35 3= 3% 330 38 3: 312 311 31$ 315 31= 31% (1 7 ("(11 9 "(15 ; <Two(oints ($ 7 ("(11 9 "(15 ; <Two(oints (5 7 ("(11 9 "(15 ; <Two(oints (= 7 ("(12 9 "(1$ ; <Two(oints (% 7 ("(1$ 9 "(15 ; <Two(oints (- 7 ("(11 9 "(15 ; <Two(oints (0 7 ("(8 9 "(15 ; <Two(oints (8 7 ("(0 9 "(1$ ; <Two(oints (: 7 ("(12 9 "(1= ; <Two(oints (12 7 ("(8 9 "(: ; <Two(oints (11 7 ("(% 9 "(0 ; <Two(oints (1$ 7 ("(% 9 "(8 ; <Two(oints (15 7 ("(% 9 "(0 ; <Two(oints (1= 7 ("(: 9 "(1$ ; <Two(oints (1% 7 ("(12 9 "(15 ; <Two(oints

40

4F

Appendi-

*rogram windows of Standard GA

Two printout windows and the first window are Figure %.A and last window Figure %.G.

Figure %.A/ 6rint out image one with *orst case one results

45

Figure AppendiD %.G/ 6rint out image two with *orst case one results

2,

Appendi- # *rogram windows of D#S !ersion


Two printout windows and the first window are Figure F.A and last window Figure F.G.

Figure F.A/ 6rint out image one with 4ormal case results

2-

Figure F.G/ 6rint out image two with 4ormal case results

2+

Appendi- G *rogram code of Standard GA


Source code for Standard GA with *orst case one inputs implemented.
7Z Standard GA worst case one Z7 case ?/ [include \stdio.h] [include \conio.h] [include \math.h] [include \stdli).h] int ecodeChromosome=int populationJ?,LJ+4L* int i* int num)erOfGenes* int chromosomeOrder* int num)erOfChromosomes> ^ int D R ,I int nCdi; R num)erOfGenes7num)erOfChromosomesI77Set lengh of genes in one chromosome chromosomeOrder33I D R D < populationJiLJ, < nCdi;ZchromosomeOrderLZ-I D R D < populationJiLJ- < nCdi;ZchromosomeOrderLZ+I D R D < populationJiLJ+ < nCdi;ZchromosomeOrderLZ4I D R D < populationJiLJ? < nCdi;ZchromosomeOrderLZFI return DI _ int %;aluateIndi;idual=int c-* int c+* int c?* int c4* int c2* int c1* int input'alueJ+5L* int pre;ious%Dcecution> ^ int f R ,* i R ,* D R ,* p R ,* points R ,* pre;iousOrderI int i6N- R input'alueJ,LI int i6N+ R input'alueJ-LI int i6N? R input'alueJ+LI int i6K- R input'alueJ?LI int i6K+ R input'alueJ4LI int i6K? R input'alueJ2LI int i6% R input'alueJ1LI int i6S- R input'alueJ0LI int i6S+ R input'alueJFLI int i6S? R input'alueJ5LI int iTNK R input'alueJ-,LI int iTN% R input'alueJ--LI int iTNS R input'alueJ-+LI int iTKN R input'alueJ-?LI int iTK% R input'alueJ-4LI int iT%N R input'alueJ-2LI int iT%K R input'alueJ-1LI int iT%S R input'alueJ-0LI int iTSN R input'alueJ-FLI int iTS% R input'alueJ-5LI int i&NK R input'alueJ+,LI int i&N% R input'alueJ+-LI int i&NS R input'alueJ++LI int i&KN R input'alueJ+?LI int i&KS% R input'alueJ+4LI int i&%NK R input'alueJ+2LI int i&%S R input'alueJ+1LI int i&SK R input'alueJ+0LI int i&SN% R input'alueJ+FLI D R pre;ious%DcecutionI for=i R ,I i \R 1 3 -I i<<> ^ pre;iousOrder R DI if=i RR ,> ^D R c-I_ if=i RR -> ^D R c+I_ if=i RR +> ^D R c?I_ if=i RR ?> ^D R c4I_ if=i RR 4> ^D R c2I_ if=i RR 2> ^D R c1I_ points R ,I 77Inputs functions calculations switch=D> ^ case ,/ points R iTNK < iT%N < iTS% < i6N- < i6N+ < i6N? < i6S- < i6S? < i&NKI iTNK R ,I iT%N R ,I iTS% R ,I i6N- R ,I i6N+ R ,I i6N? R ,I i6S- R ,I i6S? R ,I i&NK R ,I )reaBI case -/ points R iTNK < iT%N < iTK% < i6N? < i6K- < i6S- < i6S+ < i6S? < i&KS%I iTNK R ,I iT%N R ,I iTK% R ,I i6N? R ,I i6K- R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KS% R ,I )reaBI case +/ points R iTNS < iT%N < iTS% < i6K- < i6K+ < i6K? < i6N? < i6S? < i&NK < i&NSI iTNS R ,I iT%N R ,I iTS% R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6N? R ,I i6S? R ,I i&NK R ,I i&NS R ,I points R iTNK < iTSN < i6K- < i6K? < i6% < i6S< i&NK < i&SN%I iTNK R ,I iTSN R ,I i6K- R ,I i6K? R ,I i6% R ,I i6S- R ,I i&NK R ,I i&SN% R ,I )reaBI case 4/ points R iT%K < iTS% < i6N- < i6N+ < i6N? < i6K? < i6S- < i6S? < i&%NKI iT%K R ,I iTS% R ,I i6N- R ,I i6N+ R ,I i6N?R ,I i6K? R ,I i6S- R ,I i6S? R ,I i&%NK R ,I )reaBI case 2/ points R +ZiTNK < +ZiTKN < +ZiT%S < ?ZiTS% < i6N? < i6K- < i6K? < i6S- < i6S? < i&NKI iTNK R ,I iTKN R ,I iT%S R ,I iTS% R ,I i6N? R ,I i6K- R ,I i6K? R ,I i6S- R ,I i6S? R ,I i&NK R ,I )reaBI case 1/ points R 4ZiTN% < 4ZiT%N < i6N? < i6K- < i6K+ < i6K? < i6S+ < i6S? < i&NK < i&NS < i&N%I iTN% R ,I iT%N R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6S+ R ,I i6S? R ,I i&NK R ,I i&NS R ,I i&N% R ,I )reaBI case 0/ points R +ZiTNS < +ZiTSN < i6K- < i6K+ < i6K? < i6% < i&NK < i&NS < i&SN%I iTNSR ,I iTSN R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6% R ,I i&NK R ,I i&NS R ,I i&SN% R ,I )reaBI case F/ points R ?ZiTK% < ?ZiT%K < i6N- < i6N+ < i6N? < i6S- < i6S+ < i6S? < i&%NK < i&KS%I iTK% R ,I iT%K R ,I i6N- R ,I i6N+ R ,I i6N? R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&%NK R ,I i&KS% R ,I )reaBI case 5/ points R iTNK < iTKN < i6N- < i6N? < i6K- < i6S- < i6S+ < i6S? < +Zi&KN < i&KS%I iTNK R ,I iTKN R ,I i6N- R ,I i6N? R ,I i6K- R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KN R ,I i&KS% R ,I )reaBI case -,/ points R i6N+ < i6K- < i6K+ < i6K? < i6S+ < i6% < i&NK < i&NS < +Zi&SN%I i6N+ R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6S+ R ,I i6% R ,I i&NK R ,I i&NS R ,I i&SN% R ,I )reaBI case --/ points R i6N- < i6N+ < i6N? < i6K+ < i6S- < i6S+ < i6S? < +Zi&%NK < +Zi&KS%I i6N- R ,I i6N+ R ,I i6N? R ,I i6K+ R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&%NK R ,I i&KS% R ,I )reaBI case -+/ points R i6N+ < i6N? < i6K- < i6K+ < i6K? < i6% < i6S- < i6S+ < +Zi&N% < +Zi&SKI i6N+ R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6% R ,I i6S- R ,I i6S+ R ,I i&N% R ,I i&SK R ,I )reaBI case -?/ points R i6N- < i6N+ < i6N? < i6K- < i6K+ < i6S- < i6S+ < i6S? < +Zi&KN < +Zi&%SI i6N- R ,I i6N+ R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KN R ,I i&%S R ,I )reaBI case -4/ points R iTS% < iT%S < i6N- < i6N+ < i6N? < i6K< i6K+ < i6K? < i6S- < i6S? < i&%SI iTS% R ,I iT%S R ,I i6N- R ,I i6N+ R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6S- R ,I i6S? R ,I i&%S R ,I )reaBI case -2/ points R iTN% < iT%N < i6N- < i6N? < i6K- < i6K+ < i6S- < i6S+ < i6S? < +Zi&KS%I iTN% R ,I iT%N R ,I i6N- R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KS% R ,I )reaBI case -1/ points R ,I )reaBI _ 776re;ious order calculations switch=D> ^ case ,/ if==pre;iousOrder RR --> `` =pre;iousOrder RR -?>> ^points R points < +I_ if=pre;iousOrder RR ,> ^points R points 3 2I_ )reaBI

2?

)reaBI case -/ if==pre;iousOrder RR --> `` =pre;iousOrder RR -?>> ^points R points < +I_ if=pre;iousOrder RR -> ^points R points 3 2I_ )reaBI case +/ if==pre;iousOrder RR --> `` =pre;iousOrder RR -?>> ^points R points < +I_ if=pre;iousOrder RR +> ^points R points 3 2I_ )reaBI case ?/ if==pre;iousOrder RR --> `` =pre;iousOrder RR -?>> ^points R points < +I_ if=pre;iousOrder RR ?> ^points R points 3 2I_ )reaBI case 4/ if==pre;iousOrder RR -,> `` =pre;iousOrder RR -+>> ^points R points < +I_ if=pre;iousOrder RR 4> ^points R points 3 2I_ )reaBI case 2/ if==pre;iousOrder RR -+> `` =pre;iousOrder RR -?>> ^points R points < +I_ if=pre;iousOrder RR 2> ^points R points 3 2I_ )reaBI case 1/ if==pre;iousOrder RR --> `` =pre;iousOrder RR -?>> ^points R points < +I_ if=pre;iousOrder RR 1> ^points R points 3 2I_ )reaBI case 0/ if==pre;iousOrder RR F> `` =pre;iousOrder RR -?>> ^points R points < +I_ if=pre;iousOrder RR 0> ^points R points 3 2I_ )reaBI case F/ if==pre;iousOrder RR 0> `` =pre;iousOrder RR -+>> ^points R points < +I_ if=pre;iousOrder RR F> ^points R points 3 2I_ )reaBI case 5/ if==pre;iousOrder RR -,> `` =pre;iousOrder RR -4>> ^points R points < +I_ if=pre;iousOrder RR 5> ^points R points 3 2I_ )reaBI case -,/ if==pre;iousOrder RR F> `` =pre;iousOrder RR 5>> ^points R points < +I_ if=pre;iousOrder RR -,> ^points R points 3 2I_ )reaBI case --/ if==pre;iousOrder RR 2> `` =pre;iousOrder RR 0>> ^points R points < +I_ if=pre;iousOrder RR --> ^points R points 3 2I_ )reaBI case -+/ if==pre;iousOrder RR 2> `` =pre;iousOrder RR F>> ^points R points < +I_ if=pre;iousOrder RR -+> ^points R points 3 2I_ )reaBI case -?/ if==pre;iousOrder RR 2> `` =pre;iousOrder RR 0>> ^points R points < +I_ if=pre;iousOrder RR -?> ^points R points 3 2I_ )reaBI case -4/ if==pre;iousOrder RR 5> `` =pre;iousOrder RR -+>> ^points R points < +I_ if=pre;iousOrder RR -4> ^points R points 3 2I_ )reaBI case -2/ if==pre;iousOrder RR -,> `` =pre;iousOrder RR -?>> ^points R points < +I_ if=pre;iousOrder RR -2> ^points R points 3 2I_ )reaBI _ if=i RR ,> ^f R 1ZpointsI_ if=i RR -> ^f R f < 2ZpointsI_ if=i RR +> ^f R f < 4ZpointsI_ if=i RR ?> ^f R f < ?ZpointsI_ if=i RR 4> ^f R f < +ZpointsI_ if=i RR 2> ^f R f < pointsI_ if=i RR , MM points \R +> ^p R -I_ _ if=p RR -> ^f R ,I_77if p- R , 3] f R , return fI _ ;oid &eturn&esult=int )est6arameter'alue-* int )est6arameter'alue+* int )est6arameter'alue?* int )est6arameter'alue4* int )est6arameter'alue2* int )est6arameter'alue1* int input'alueJ+5L* int maDFitness> ^ int f R ,* D R ,* points R ,* pre;iousOrderI int i6N- R input'alueJ,LI int i6N+ R input'alueJ-LI int i6N? R input'alueJ+LI int i6K- R input'alueJ?LI int i6K+ R input'alueJ4LI int i6K? R input'alueJ2LI

int i6% R input'alueJ1LI int i6S- R input'alueJ0LI int i6S+ R input'alueJFLI int i6S? R input'alueJ5LI int iTNK R input'alueJ-,LI int iTN% R input'alueJ--LI int iTNS R input'alueJ-+LI int iTKN R input'alueJ-?LI int iTK% R input'alueJ-4LI int iT%N R input'alueJ-2LI int iT%K R input'alueJ-1LI int iT%S R input'alueJ-0LI int iTSN R input'alueJ-FLI int iTS% R input'alueJ-5LI int i&NK R input'alueJ+,LI int i&N% R input'alueJ+-LI int i&NS R input'alueJ++LI int i&KN R input'alueJ+?LI int i&KS% R input'alueJ+4LI int i&%NK R input'alueJ+2LI int i&%S R input'alueJ+1LI int i&SK R input'alueJ+0LI int i&SN% R input'alueJ+FLI printf=abn 666 666 6 666 TTT TT TTT TT &&& && && &&bna>I printf=a NNN KKK % SSS NNN KK %%% SS NNN KK %% SSbna>I printf=a -+? -+? -+? K%S N% NKS N% K%S NS NS KNbna>I printf=a ``` ``` ` ``` ``` `` ``` `` ``` `% K` `%bna>I printf=ai PdPdPd.PdPdPd.Pd.PdPdPd / PdPdPd.PdPd.PdPdPd. PdPd / PdPdPd.PdPd.PdPd.PdPd $aD fitness/ Pdbna* i6N-* i6N+* i6N?* i6K-* i6K+* i6K?* i6%* i6S-* i6S+* i6S?* iTNK* iTN%* iTNS* iTKN* iTK%* iT%N* iT%K* iT%S* iTSN* iTS%* i&NK* i&N%* i&NS* i&KN* i&KS%* i&%NK* i&%S* i&SK* i&SN%* maDFitness>I for=int i R ,I i \R 1 3 -I i<<> ^ pre;iousOrder R DI if=i RR ,> ^D R )est6arameter'alue-I_ if=i RR -> ^D R )est6arameter'alue+I_ if=i RR +> ^D R )est6arameter'alue?I_ if=i RR ?> ^D R )est6arameter'alue4I_ if=i RR 4> ^D R )est6arameter'alue2I_ if=i RR 2> ^D R )est6arameter'alue1I_ points R ,I 77Inputs functions calculations switch=D> ^ case ,/ points R iTNK < iT%N < iTS% < i6N- < i6N+ < i6N? < i6S- < i6S? < i&NKI iTNK R ,I iT%N R ,I iTS% R ,I i6N- R ,I i6N+ R ,I i6N? R ,I i6S- R ,I i6S? R ,I i&NK R ,I )reaBI case -/ points R iTNK < iT%N < iTK% < i6N? < i6K- < i6S- < i6S+ < i6S? < i&KS%I iTNK R ,I iT%N R ,I iTK% R ,I i6N? R ,I i6K- R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KS% R ,I )reaBI case +/ points R iTNS < iT%N < iTS% < i6K- < i6K+ < i6K? < i6N? < i6S? < i&NK < i&NSI iTNS R ,I iT%N R ,I iTS% R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6N? R ,I i6S? R ,I i&NK R ,I i&NS R ,I )reaBI case ?/ points R iTNK < iTSN < i6K- < i6K? < i6% < i6S< i&NK < i&SN%I iTNK R ,I iTSN R ,I i6K- R ,I i6K? R ,I i6% R ,I i6S- R ,I i&NK R ,I i&SN% R ,I )reaBI case 4/ points R iT%K < iTS% < i6N- < i6N+ < i6N? < i6K? < i6S- < i6S? < i&%NKI iT%K R ,I iTS% R ,I i6N- R ,I i6N+ R ,I i6N?R ,I i6K? R ,I i6S- R ,I i6S? R ,I i&%NK R ,I )reaBI case 2/ points R +ZiTNK < +ZiTKN < +ZiT%S < +ZiTS% < i6N? < i6K- < i6K? < i6S- < i6S? < i&NKI iTNK R ,I iTKN R ,I iT%S R ,I iTS% R ,I i6N? R ,I i6K- R ,I i6K? R ,I i6S- R ,I i6S? R ,I i&NK R ,I )reaBI case 1/ points R +ZiTN% < 4ZiT%N < i6N? < i6K- < i6K+ < i6K? < i6S+ < i6S? < i&NK < i&NS < i&N%I iTN% R ,I iT%N R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6S+ R ,I i6S? R ,I i&NK R ,I i&NS R ,I i&N% R ,I )reaBI case 0/ points R +ZiTNS < +ZiTSN < i6K- < i6K+ < i6K? < i6% < i&NK < i&NS < i&SN%I iTNSR ,I iTSN R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6% R ,I i&NK R ,I i&NS R ,I i&SN% R ,I )reaBI case F/ points R +ZiTK% < +ZiT%K < i6N- < i6N+ < i6N? < i6S- < i6S+ < i6S? < i&%NK < i&KS%I iTK% R ,I iT%K R ,I i6N- R ,I i6N+ R ,I i6N? R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&%NK R ,I i&KS% R ,I

24

)reaBI case 5/ points R iTNK < iTKN < i6N- < i6N? < i6K- < i6S- < i6S+ < i6S? < +Zi&KN < i&KS%I iTNK R ,I iTKN R ,I i6N- R ,I i6N? R ,I i6K- R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KN R ,I i&KS% R ,I )reaBI case -,/ points R i6N+ < i6K- < i6K+ < i6K? < i6S+ < i6% < i&NK < i&NS < +Zi&SN%I i6N+ R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6S+ R ,I i6% R ,I i&NK R ,I i&NS R ,I i&SN% R ,I )reaBI case --/ points R i6N- < i6N+ < i6N? < i6K+ < i6S- < i6S+ < i6S? < +Zi&%NK < +Zi&KS%I i6N- R ,I i6N+ R ,I i6N? R ,I i6K+ R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&%NK R ,I i&KS% R ,I )reaBI case -+/ points R i6N+ < i6N? < i6K- < i6K+ < i6K? < i6% < i6S- < i6S+ < +Zi&N% < +Zi&SKI i6N+ R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6% R ,I i6S- R ,I i6S+ R ,I i&N% R ,I i&SK R ,I )reaBI case -?/ points R i6N- < i6N+ < i6N? < i6K- < i6K+ < i6S- < i6S+ < i6S? < +Zi&KN < +Zi&%SI i6N- R ,I i6N+ R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KN R ,I i&%S R ,I )reaBI case -4/ points R iTS% < iT%S < i6N- < i6N+ < i6N? < i6K< i6K+ < i6K? < i6S- < i6S? < i&%SI iTS% R ,I iT%S R ,I i6N- R ,I i6N+ R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6S- R ,I i6S? R ,I i&%S R ,I )reaBI case -2/ points R iTN% < iT%N < i6N- < i6N? < i6K- < i6K+ < i6S- < i6S+ < i6S? < +Zi&KS%I iTN% R ,I iT%N R ,I i6N- R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KS% R ,I )reaBI case -1/ points R ,I )reaBI _ 776re;ious order calculations switch=D> ^ case ,/ if==pre;iousOrder RR --> `` =pre;iousOrder RR -?>> ^points R points < +I_ )reaBI case -/ if==pre;iousOrder RR --> `` =pre;iousOrder RR -?>> ^points R points < +I_ )reaBI case +/ if==pre;iousOrder RR --> `` =pre;iousOrder RR -?>> ^points R points < +I_ )reaBI case ?/ if==pre;iousOrder RR --> `` =pre;iousOrder RR -?>> ^points R points < +I_ )reaBI case 4/ if==pre;iousOrder RR -,> `` =pre;iousOrder RR -+>> ^points R points < +I_ )reaBI case 2/ if==pre;iousOrder RR -+> `` =pre;iousOrder RR -?>> ^points R points < +I_ )reaBI case 1/ if==pre;iousOrder RR --> `` =pre;iousOrder RR -?>> ^points R points < +I_ )reaBI case 0/ if==pre;iousOrder RR F> `` =pre;iousOrder RR -?>> ^points R points < +I_ )reaBI case F/ if==pre;iousOrder RR 0> `` =pre;iousOrder RR -+>> ^points R points < +I_ )reaBI case 5/ if==pre;iousOrder RR -,> `` =pre;iousOrder RR -4>> ^points R points < +I_ )reaBI case -,/ if==pre;iousOrder RR F> `` =pre;iousOrder RR 5>> ^points R points < +I_ )reaBI case --/ if==pre;iousOrder RR 2> `` =pre;iousOrder RR 0>> ^points R points < +I_ )reaBI case -+/ if==pre;iousOrder RR 2> `` =pre;iousOrder RR F>> ^points R points < +I_ ^points R points < +I_

)reaBI case -?/ if==pre;iousOrder RR 2> `` =pre;iousOrder RR 0>> )reaBI case -4/ if==pre;iousOrder RR 5> `` =pre;iousOrder RR -+>> ^points R points < +I_ )reaBI case -2/ if==pre;iousOrder RR -,> `` =pre;iousOrder RR -?>> ^points R points < +I_ )reaBI case -1/ 77 )reaBI _ if=i RR ,> ^f R 1ZpointsI_ if=i RR -> ^f R f < 2ZpointsI_ if=i RR +> ^f R f < 4ZpointsI_ if=i RR ?> ^f R f < ?ZpointsI_ if=i RR 4> ^f R f < +ZpointsI_ if=i RR 2> ^f R f < pointsI_ printf=acPd PdPdPd.PdPdPd.Pd.PdPdPd / PdPdPd.PdPd. PdPdPd.PdPd / PdPdPd.PdPd.PdPd.PdPd Order R P+d 6oints R P+dbna* i<-* i6N-* i6N+* i6N?* i6K-* i6K+* i6K?* i6%* i6S-* i6S+* i6S?* iTNK* iTN%* iTNS* iTKN* iTK%* iT%N* iT%K* iT%S* iTSN* iTS%* i&NK* i&N%* i&NS* i&KN* i&KS%* i&%NK* i&%S* i&SK* i&SN%* D *points>I _ printf=abna>I 77Output print out switch=)est6arameter'alue-> ^ case ,/ printf=a%Decuting reAuests on dri;e order Pd/bnoTNK* oT%N* oTS%* o6N-* o6N+* o6N?* o6S-* o6S?* o&NKbna* )est6arameter'alue->I )reaBI case -/ printf=a%Decuting reAuests on dri;e order Pd/bnoTNK* oT%N* oTK%* o6N?* o6K-* o6S-* o6S+* o6S?* o&KS%bna* )est6arameter'alue->I )reaBI case +/ printf=a%Decuting reAuests on dri;e order Pd/bnoTNS* oT%N* oTS%* o6K-* o6K+* o6K?* o6N?* o6S?* o&NK* o&NSbna* )est6arameter'alue->I )reaBI case ?/ printf=a%Decuting reAuests on dri;e order Pd/bnoTNK* oTSN* o6K-* o6K?* o6%* o6S-* o&NK* o&SN%bna* )est6arameter'alue->I )reaBI case 4/ printf=a%Decuting reAuests on dri;e order Pd/bnoT%K* oTS%* o6N-* o6N+* o6N?* o6K?* o6S-* o6S?* o&%NKbna* )est6arameter'alue->I )reaBI case 2/ printf=a%Decuting reAuests on dri;e order Pd/bnoTNK* oTKN* oT%S* oTS%* o6N?* o6K-* o6K?* o6S-* o6S?* o&NKbna* )est6arameter'alue->I )reaBI case 1/ printf=a%Decuting reAuests on dri;e order Pd/bnoTN%* oT%N* o6N?* o6K-* o6K+* o6K?* o6S+* o6S?* o&NK* o&NS* o&N%bna* )est6arameter'alue->I )reaBI case 0/ printf=a%Decuting reAuests on dri;e order Pd/bnoTNS* oTSN* o6K-* o6K+* o6K?* o6%* o&NK* o&NS* o&SN%bna* )est6arameter'alue->I )reaBI case F/ printf=a%Decuting reAuests on dri;e order Pd/bnoTK%* oT%K* o6N-* o6N+* o6N?* o6S-* o6S+* o6S?* o&%NK* o&KS%bna* )est6arameter'alue->I )reaBI case 5/ printf=a%Decuting reAuests on dri;e order Pd/bnoTNK* oTKN* o6N-* o6N?* o6K-* o6S-* o6S+* o6S?* o&KN* o&KS%bna* )est6arameter'alue->I )reaBI case -,/ printf=a%Decuting reAuests on dri;e order Pd/bno6N+* o6K-* o6K+* o6K?* o6S+* o6%* o&NK* o&NS* o&SN%bna* )est6arameter'alue->I )reaBI case --/ printf=a%Decuting reAuests on dri;e order Pd/bno6N-* o6N+* o6N?* o6K+* o6S-* o6S+* o6S?* o&%NK* o&KS%bna* )est6arameter'alue->I )reaBI case -+/ printf=a%Decuting reAuests on dri;e order Pd/bno6N+* o6N?* o6K-* o6K+* o6K?* o6%* o6S-* o6S+* o&N%* o&SKbna* )est6arameter'alue->I )reaBI case -?/ printf=a%Decuting reAuests on dri;e order Pd/bno6N-* o6N+* o6N?* o6K-* o6K+* o6S-* o6S+* o6S?* o&KN* o&%Sbna* )est6arameter'alue->I )reaBI case -4/ printf=a%Decuting reAuests on dri;e order Pd/bnoTS%* oT%S* o6N-* o6N+* o6N?* o6K-* o6K+* o6K?* o6S-* o6S?* o&%Sbna* )est6arameter'alue->I )reaBI case -2/

22

printf=a%Decuting reAuests on dri;e order Pd/bnoTN%* oT%N* o6N-* o6N?* o6K-* o6K+* o6S-* o6S+* o6S?* o&KS%bna* )est6arameter'alue->I )reaBI case -1/ printf=a o not eDecuting an! dri;e order.bna>I )reaBI _ printf=abna>I _ int TournamentSelect=int fitnessJ?,L* int populationSize* float tournament6ro)a)ilit!> ^ int ind;I int itemp- R - < rand=> P=populationSize 3 ->I int itemp+ R - < rand=> P=populationSize 3 ->I float r R ,I int ri R ,I ri R rand=> P55I r R ==float>ri7-,,>I if=r \R tournament6ro)a)ilit!> ^ if=fitnessJitemp-L ]R fitnessJitemp+L> ^ ind; R itemp-I _ else ^ ind; R itemp+I _ _ else ^ if=fitnessJitemp-L ]R fitnessJitemp+L> ^ ind; R itemp+I _ else ^ ind; R itemp-I _ _ return ind;I _ float &andFunBtion=;oid> ^ float r R ,I int ri R rand=> P55I return r R ==float>ri7-,,>I _ ;oid 6rintOutFunBtion=int msgOrder* int num)er%;alutaions6erformed* int generationN)r* int maDFitness* int )est6arameter'alue-* int )est6arameter'alue+* int )est6arameter'alue?* int )est6arameter'alue4* int )est6arameter'alue2* int )est6arameter'alue1> ^ if=msgOrder RR ,> ^ printf=aStart bna>I _ else if=msgOrder RR -> ^ printf=aGeneration/ P?d %;aluation/ P?d $aD fitness/ P?d bna* generationN)r* num)er%;alutaions6erformed* maDFitness>I _ else if=msgOrder RR +> ^ printf=a&esult generation P?d/ c- R Pd c+ R Pd c? R Pd c4 R Pd c2 R Pd c1 R Pd Fitness R Pdbna* generationN)r* )est6arameter'alue-* )est6arameter'alue+* )est6arameter'alue?* )est6arameter'alue4* )est6arameter'alue2* )est6arameter'alue1* maDFitness>I _ else if=msgOrder RR ?> ^ printf=abn%nd or Termination Criterion is reached. bnbna>I _ else ^ printf=a%rrorcbnbna>I _ _ int main=> ^ int populationSize R ?,I int num)erOfGenes R +4I int num)erOfChromosomes R 1I float crosso;er6ro)a)ilit! R ,.F2I float mutation6ro)a)ilit! R ,.,?I float tournament6ro)a)ilit! R ,.5,I int input'alueJ+5LI int input'aluesJ-,LJ+5LI77 JRsimLJ+5L int maDGeneration R -,,I int num)er%;alutaions6erformed R ,I int maDFitness R ,I int total$aDFitness R ,I int fitnessJpopulationSizeLI

int populationJpopulationSizeLJnum)erOfGenesLI int temp6opulationJpopulationSizeLJnum)erOfGenesLI int goodIndi;idualsJpopulationSizeLJnum)erOfGenesLI int newIndi;idual-Jnum)erOfGenesLI int newIndi;idual+Jnum)erOfGenesLI int tempIndi;idualJnum)erOfGenesLI int parameter'alue- R ,I int parameter'alue+ R ,I int parameter'alue? R ,I int parameter'alue4 R ,I int parameter'alue2 R ,I int parameter'alue1 R ,I int )estIndu;idual R ,I int )est6arameter'alue- R ,I int )est6arameter'alue+ R ,I int )est6arameter'alue? R ,I int )est6arameter'alue4 R ,I int )est6arameter'alue2 R ,I int )est6arameter'alue1 R ,I int pre;ious%Dcecution R -1I77Store c- =%> from pre;ious time period int sim R -,I77Num)er of simulations 77 Other ;aria)les int generationN)r* i R ,* C R ,* h R ,* ind;-* ind;+I float r R ,I int msgOrder R ,* m%Int R ,I float m%float R ,I for=C R ,I C \R +FI C<<> ^ input'alueJCL R ,I _ for=i R ,I i \R sim 3 -I i<<> ^ for=C R ,I C \R +FI C<<> ^ input'aluesJiLJCL R ,I _ _ 77Onl! 2 first is filled with inputs 77Init input'alue , input'aluesJ,LJ,L R -I 7Z 6N- Z7 input'aluesJ,LJ-,L R ,I 7Z TNK Z7 input'aluesJ,LJ+,L R -I 7Z &NK Z7 input'aluesJ,LJ-L R -I 7Z 6N+ Z7 input'aluesJ,LJ--L R ,I 7Z TN% Z7 input'aluesJ,LJ+-L R -I 7Z &N% Z7 input'aluesJ,LJ+L R -I 7Z 6N? Z7 input'aluesJ,LJ-+L R -I 7Z TNS Z7 input'aluesJ,LJ++L R -I 7Z &NS Z7 input'aluesJ,LJ?L R -I 7Z 6K- Z7 input'aluesJ,LJ-?L R ,I 7Z TKN Z7 input'aluesJ,LJ+?L R -I 7Z &KN Z7 input'aluesJ,LJ4L R -I 7Z 6K+ Z7 input'aluesJ,LJ-4L R -I 7Z TK% Z7 input'aluesJ,LJ+4L R -I 7Z &KS% Z7 input'aluesJ,LJ2L R -I 7Z 6K? Z7 input'aluesJ,LJ-2L R ,I 7Z T%N Z7 input'aluesJ,LJ+2L R -I 7Z &%NK Z7 input'aluesJ,LJ1L R -I 7Z 6% Z7 input'aluesJ,LJ-1L R -I 7Z T%K Z7 input'aluesJ,LJ+1L R -I 7Z &%S Z7 input'aluesJ,LJ0L R -I 7Z 6S- Z7 input'aluesJ,LJ-0L R ,I 7Z T%S Z7 input'aluesJ,LJ+0L R -I 7Z &SK Z7 input'aluesJ,LJFL R -I 7Z 6S+ Z7 input'aluesJ,LJ-FL R -I 7Z TSN Z7 input'aluesJ,LJ+FL R -I 7Z &SN% Z7 input'aluesJ,LJ5L R -I 7Z 6S? Z7 input'aluesJ,LJ-5L R ,I 7Z TS% Z7 77Init input'alue input'aluesJ-LJ,L R ,I 7Z 6N- Z7 input'aluesJ-LJ-,L R ,I 7Z TNK Z7 input'aluesJ-LJ+,L R ,I 7Z &NK Z7 input'aluesJ-LJ-L R ,I 7Z 6N+ Z7 input'aluesJ-LJ--L R ,I 7Z TN% Z7 input'aluesJ-LJ+-L R ,I 7Z &N% Z7 input'aluesJ-LJ+L R ,I 7Z 6N? Z7 input'aluesJ-LJ-+L R ,I 7Z TNS Z7 input'aluesJ-LJ++L R ,I 7Z &NS Z7 input'aluesJ-LJ?L R ,I 7Z 6K- Z7 input'aluesJ-LJ-?L R ,I 7Z TKN Z7 input'aluesJ-LJ+?L R ,I 7Z &KN Z7 input'aluesJ-LJ4L R ,I 7Z 6K+ Z7 input'aluesJ-LJ-4L R ,I 7Z TK% Z7 input'aluesJ-LJ+4L R ,I 7Z &KS% Z7 input'aluesJ-LJ2L R ,I 7Z 6K? Z7 input'aluesJ-LJ-2L R ,I 7Z T%N Z7 input'aluesJ-LJ+2L R ,I 7Z &%NK Z7 input'aluesJ-LJ1L R ,I 7Z 6% Z7 input'aluesJ-LJ-1L R ,I 7Z T%K Z7 input'aluesJ-LJ+1L R ,I 7Z &%S Z7 input'aluesJ-LJ0L R ,I 7Z 6S- Z7 input'aluesJ-LJ-0L R ,I 7Z T%S Z7 input'aluesJ-LJ+0L R ,I 7Z &SK Z7 input'aluesJ-LJFL R ,I 7Z 6S+ Z7 input'aluesJ-LJ-FL R ,I 7Z TSN Z7 input'aluesJ-LJ+FL R ,I 7Z &SN% Z7 input'aluesJ-LJ5L R ,I 7Z 6S? Z7 input'aluesJ-LJ-5L R ,I 7Z TS% Z7 77Init input'alue + input'aluesJ+LJ,L R ,I 7Z 6N- Z7 input'aluesJ+LJ-,L R ,I 7Z TNK Z7 input'aluesJ+LJ+,L R ,I 7Z &NK Z7 input'aluesJ+LJ-L R ,I 7Z 6N+ Z7 input'aluesJ+LJ--L R ,I 7Z TN% Z7 input'aluesJ+LJ+-L R ,I 7Z &N% Z7 input'aluesJ+LJ+L R ,I 7Z 6N? Z7 input'aluesJ+LJ-+L R ,I 7Z TNS Z7 input'aluesJ+LJ++L R ,I 7Z &NS Z7 input'aluesJ+LJ?L R ,I 7Z 6K- Z7 input'aluesJ+LJ-?L R ,I 7Z TKN Z7 input'aluesJ+LJ+?L R ,I 7Z &KN Z7 input'aluesJ+LJ4L R ,I 7Z 6K+ Z7 input'aluesJ+LJ-4L R ,I 7Z TK% Z7 input'aluesJ+LJ+4L R ,I 7Z &KS% Z7 input'aluesJ+LJ2L R ,I 7Z 6K? Z7 input'aluesJ+LJ-2L R ,I 7Z T%N Z7 input'aluesJ+LJ+2L R ,I 7Z &%NK Z7 input'aluesJ+LJ1L R ,I 7Z 6% Z7 input'aluesJ+LJ-1L R ,I 7Z T%K Z7 input'aluesJ+LJ+1L R ,I 7Z &%S Z7 input'aluesJ+LJ0L R ,I 7Z 6S- Z7 input'aluesJ+LJ-0L R ,I 7Z T%S Z7 input'aluesJ+LJ+0L R ,I 7Z &SK Z7 input'aluesJ+LJFL R ,I 7Z 6S+ Z7 input'aluesJ+LJ-FL R ,I 7Z TSN Z7 input'aluesJ+LJ+FL R ,I 7Z &SN% Z7

21

input'aluesJ+LJ5L R ,I 7Z 6S? Z7 TS% Z7

input'aluesJ+LJ-5L R ,I 7Z

77Init input'alue ? input'aluesJ?LJ,L R ,I 7Z 6N- Z7 input'aluesJ?LJ-,L R ,I 7Z TNK Z7 input'aluesJ?LJ+,L R ,I 7Z &NK Z7 input'aluesJ?LJ-L R ,I 7Z 6N+ Z7 input'aluesJ?LJ--L R ,I 7Z TN% Z7 input'aluesJ?LJ+-L R ,I 7Z &N% Z7 input'aluesJ?LJ+L R ,I 7Z 6N? Z7 input'aluesJ?LJ-+L R ,I 7Z TNS Z7 input'aluesJ?LJ++L R ,I 7Z &NS Z7 input'aluesJ?LJ?L R ,I 7Z 6K- Z7 input'aluesJ?LJ-?L R ,I 7Z TKN Z7 input'aluesJ?LJ+?L R ,I 7Z &KN Z7 input'aluesJ?LJ4L R ,I 7Z 6K+ Z7 input'aluesJ?LJ-4L R ,I 7Z TK% Z7 input'aluesJ?LJ+4L R ,I 7Z &KS% Z7 input'aluesJ?LJ2L R ,I 7Z 6K? Z7 input'aluesJ?LJ-2L R ,I 7Z T%N Z7 input'aluesJ?LJ+2L R ,I 7Z &%NK Z7 input'aluesJ?LJ1L R ,I 7Z 6% Z7 input'aluesJ?LJ-1L R ,I 7Z T%K Z7 input'aluesJ?LJ+1L R ,I 7Z &%S Z7 input'aluesJ?LJ0L R ,I 7Z 6S- Z7 input'aluesJ?LJ-0L R ,I 7Z T%S Z7 input'aluesJ?LJ+0L R ,I 7Z &SK Z7 input'aluesJ?LJFL R ,I 7Z 6S+ Z7 input'aluesJ?LJ-FL R ,I 7Z TSN Z7 input'aluesJ?LJ+FL R ,I 7Z &SN% Z7 input'aluesJ?LJ5L R ,I 7Z 6S? Z7 input'aluesJ?LJ-5L R ,I 7Z TS% Z7 77Init input'alue 4 input'aluesJ4LJ,L R ,I 7Z 6N- Z7 input'aluesJ4LJ-,L R ,I 7Z TNK Z7 input'aluesJ4LJ+,L R ,I 7Z &NK Z7 input'aluesJ4LJ-L R ,I 7Z 6N+ Z7 input'aluesJ4LJ--L R ,I 7Z TN% Z7 input'aluesJ4LJ+-L R ,I 7Z &N% Z7 input'aluesJ4LJ+L R ,I 7Z 6N? Z7 input'aluesJ4LJ-+L R ,I 7Z TNS Z7 input'aluesJ4LJ++L R ,I 7Z &NS Z7 input'aluesJ4LJ?L R ,I 7Z 6K- Z7 input'aluesJ4LJ-?L R ,I 7Z TKN Z7 input'aluesJ4LJ+?L R ,I 7Z &KN Z7 input'aluesJ4LJ4L R ,I 7Z 6K+ Z7 input'aluesJ4LJ-4L R ,I 7Z TK% Z7 input'aluesJ4LJ+4L R ,I 7Z &KS% Z7 input'aluesJ4LJ2L R ,I 7Z 6K? Z7 input'aluesJ4LJ-2L R ,I 7Z T%N Z7 input'aluesJ4LJ+2L R ,I 7Z &%NK Z7 input'aluesJ4LJ1L R ,I 7Z 6% Z7 input'aluesJ4LJ-1L R ,I 7Z T%K Z7 input'aluesJ4LJ+1L R ,I 7Z &%S Z7 input'aluesJ4LJ0L R ,I 7Z 6S- Z7 input'aluesJ4LJ-0L R ,I 7Z T%S Z7 input'aluesJ4LJ+0L R ,I 7Z &SK Z7 input'aluesJ4LJFL R ,I 7Z 6S+ Z7 input'aluesJ4LJ-FL R ,I 7Z TSN Z7 input'aluesJ4LJ+FL R ,I 7Z &SN% Z7 input'aluesJ4LJ5L R ,I 7Z 6S? Z7 input'aluesJ4LJ-5L R ,I 7Z TS% Z7 77Set ;alues to population for=i R ,I i \R populationSize 3 -I i<<> ^ for=C R ,I C \R num)erOfGenes 3 -I C<<> ^ if==rand=> P 1> ]R ?> ^ populationJiLJCL R -I _ else ^ populationJiLJCL R ,I _ _ _ 77Set ;alues to temp6opulation for=i R ,I i \R populationSize 3 -I i<<> ^ for=C R ,I C \R num)erOfGenes 3 -I C<<> ^ temp6opulationJiLJCL R ,I _ _ for=C R ,I C \R +FI C<<> ^ input'alueJCL R ,I _ 77Start main program 6rintOutFunBtion=msgOrder* m%Int* m%Int* m%Int* m%Int* m%Int* m%Int* m%Int* m%Int* m%Int>I for=h R ,I h \R sim 3 -I h<<> ^ printf=abnZZZZ Standard GA ZZZZbna>I printf=a6re;ious eDecuted dri;e order/ Pd* Simulation/ TPdbnbna* pre;ious%Dcecution* h>I for=i R ,I i \R sim 3 -I i<<> ^ for=C R ,I C \R num)erOfGenes 3 -I C<<> ^ populationJiLJCL R goodIndi;idualsJiLJCLI _ _ 77UpdateInput'alue=input'alue* )est6arameter'alue-* h>I if=-> ^ int i6N- R input'alueJ,LI int i6N+ R input'alueJ-LI int i6N? R input'alueJ+LI int i6K- R input'alueJ?LI int i6K+ R input'alueJ4LI

int i6K? R input'alueJ2LI int i6% R input'alueJ1LI int i6S- R input'alueJ0LI int i6S+ R input'alueJFLI int i6S? R input'alueJ5LI int iTNK R input'alueJ-,LI int iTN% R input'alueJ--LI int iTNS R input'alueJ-+LI int iTKN R input'alueJ-?LI int iTK% R input'alueJ-4LI int iT%N R input'alueJ-2LI int iT%K R input'alueJ-1LI int iT%S R input'alueJ-0LI int iTSN R input'alueJ-FLI int iTS% R input'alueJ-5LI int i&NK R input'alueJ+,LI int i&N% R input'alueJ+-LI int i&NS R input'alueJ++LI int i&KN R input'alueJ+?LI int i&KS% R input'alueJ+4LI int i&%NK R input'alueJ+2LI int i&%S R input'alueJ+1LI int i&SK R input'alueJ+0LI int i&SN% R input'alueJ+FLI switch=)est6arameter'alue-> ^ case ,/ iTNK R ,I iT%N R ,I iTS% R ,I i6N- R ,I i6N+ R ,I i6N? R ,I i6S- R ,I i6S? R ,I i&NK R ,I )reaBI case -/ iTNK R ,I iT%N R ,I iTK% R ,I i6N? R ,I i6K- R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KS% R ,I )reaBI case +/ iTNS R ,I iT%N R ,I iTS% R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6N? R ,I i6S? R ,I i&NK R ,I i&NS R ,I )reaBI case ?/ iTNK R ,I iTSN R ,I i6K- R ,I i6K? R ,I i6% R ,I i6S- R ,I i&NK R ,I i&SN% R ,I )reaBI case 4/ iT%K R ,I iTS% R ,I i6N- R ,I i6N+ R ,I i6N?R ,I i6K? R ,I i6S- R ,I i6S? R ,I i&%NK R ,I )reaBI case 2/ iTNK R ,I iTKN R ,I iT%S R ,I iTS% R ,I i6N? R ,I i6K- R ,I i6K? R ,I i6S- R ,I i6S? R ,I i&NK R ,I )reaBI case 1/ iTN% R ,I iT%N R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6S+ R ,I i6S? R ,I i&NK R ,I i&NS R ,I i&N% R ,I )reaBI case 0/ iTNSR ,I iTSN R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6% R ,I i&NK R ,I i&NS R ,I i&SN% R ,I )reaBI case F/ iTK% R ,I iT%K R ,I i6N- R ,I i6N+ R ,I i6N? R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&%NK R ,I i&KS% R ,I )reaBI case 5/ iTNK R ,I iTKN R ,I i6N- R ,I i6N? R ,I i6K- R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KN R ,I i&KS% R ,I )reaBI case -,/ i6N+ R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6S+ R ,I i6% R ,I i&NK R ,I i&NS R ,I i&SN% R ,I )reaBI case --/ i6N- R ,I i6N+ R ,I i6N? R ,I i6K+ R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&%NK R ,I i&KS% R ,I )reaBI case -+/ i6N+ R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6% R ,I i6S- R ,I i6S+ R ,I i&N% R ,I i&SK R ,I )reaBI case -?/ i6N- R ,I i6N+ R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KN R ,I i&%S R ,I )reaBI case -4/ iTS% R ,I iT%S R ,I i6N- R ,I i6N+ R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6S- R ,I i6S? R ,I i&%S R ,I )reaBI case -2/ iTN% R ,I iT%N R ,I i6N- R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KS% R ,I )reaBI case -1/ )reaBI _ 77 &ewrite input'alue input'alueJ,L R i6N-I input'alueJ-L R i6N+I input'alueJ+L R i6N?I input'alueJ?L R i6K-I input'alueJ4L R i6K+I input'alueJ2L R i6K?I

20

input'alueJ1L R i6%I input'alueJ0L R i6S-I input'alueJFL R i6S+I input'alueJ5L R i6S?I input'alueJ-,L R iTNKI input'alueJ--L R iTN%I input'alueJ-+L R iTNSI input'alueJ-?L R iTKNI input'alueJ-4L R iTK%I input'alueJ-2L R iT%NI input'alueJ-1L R iT%KI input'alueJ-0L R iT%SI input'alueJ-FL R iTSNI input'alueJ-5L R iTS%I input'alueJ+,L R i&NKI input'alueJ+-L R i&N%I input'alueJ++L R i&NSI input'alueJ+?L R i&KNI input'alueJ+4L R i&KS%I input'alueJ+2L R i&%NKI input'alueJ+1L R i&%SI input'alueJ+0L R i&SKI input'alueJ+FL R i&SN%I for=C R ,I C \R +FI C<<> ^ if=input'alueJCL cR ,> ^input'alueJCL R input'alueJCL < -I_77 Add priorit! to remaining inputs else ^input'alueJCL R input'alueJCL < input'aluesJhL JCLI_77 Add new inputs if there are an! _ _ 77Start of standard GA loop for =generationN)r R ,I generationN)r \R maDGeneration 3 -I generationN)r<<> ^ for=i R ,I i \R populationSize 3 -I i<<> ^ parameter'alue- R ecodeChromosome=population* i* num)erOfGenes* -* num)erOfChromosomes>I parameter'alue+ R ecodeChromosome=population* i* num)erOfGenes* +* num)erOfChromosomes>I parameter'alue? R ecodeChromosome=population* i* num)erOfGenes* ?* num)erOfChromosomes>I parameter'alue4 R ecodeChromosome=population* i* num)erOfGenes* 4* num)erOfChromosomes>I parameter'alue2 R ecodeChromosome=population* i* num)erOfGenes* 2* num)erOfChromosomes>I parameter'alue1 R ecodeChromosome=population* i* num)erOfGenes* 1* num)erOfChromosomes>I fitnessJiL R %;aluateIndi;idual=parameter'alue-* parameter'alue+* parameter'alue?* parameter'alue4* parameter'alue2* parameter'alue1* input'alue* pre;ious%Dcecution>I num)er%;alutaions6erformed R num)er%;alutaions6erformed < -I if ==fitnessJiL ]R maDFitness> MM =fitnessJiL cR maDFitness>>77fitness ] maDFitness ^ maDFitness R fitnessJiLI )estIndu;idual R iI )est6arameter'alue- R parameter'alue-I )est6arameter'alue+ R parameter'alue+I )est6arameter'alue? R parameter'alue?I )est6arameter'alue4 R parameter'alue4I )est6arameter'alue2 R parameter'alue2I )est6arameter'alue1 R parameter'alue1I msgOrder R -I 6rintOutFunBtion=msgOrder* num)er%;alutaions6erformed* generationN)r < -* maDFitness* )est6arameter'alue-* )est6arameter'alue+* )est6arameter'alue?* )est6arameter'alue4* )est6arameter'alue2* )est6arameter'alue1>I _ _ num)er%;alutaions6erformed R ,I for=i R ,I i \R populationSize 3 -I i<<>77cop! arra!/ temp6opulation R populationI ^ for=C R ,I C \R num)erOfGenes 3 -I C<<> ^ temp6opulationJiLJCL R populationJiLJCLI _ _ for=i R ,I i \R populationSize 3 -I i R i < +> ^ ind;- R TournamentSelect=fitness* populationSize* tournament6ro)a)ilit!>I ind;+ R TournamentSelect=fitness* populationSize* tournament6ro)a)ilit!>I r R &andFunBtion=>I if=r \R crosso;er6ro)a)ilit!> ^ int C* cp R rand=> Pnum)erOfGenes 3 -I 77Get crosso;er position. for=C R ,I C \R num)erOfGenes 3 -I C<<> ^ if=C \R cp> ^

newIndi;idual-JCL R populationJind;-LJCLI newIndi;idual+JCL R populationJind;+LJCLI _ else ^ newIndi;idual-JCL R populationJind;+LJCLI newIndi;idual+JCL R populationJind;-LJCLI _ _77end of crosso;er for=C R ,I C \R num)erOfGenes 3 -I C<<> ^ temp6opulationJiLJCL R newIndi;idual-JCLI temp6opulationJi < -LJCL R newIndi;idual+JCLI _ _ else ^ for=C R ,I C \R num)erOfGenes 3 -I C<<> ^ temp6opulationJiLJCL R populationJind;-LJCLI temp6opulationJi < -LJCL R populationJind;+LJCLI _ _ _ 77Set )est indi;idual first into temp6opulation for=C R ,I C \R num)erOfGenes 3 -I C<<> ^ temp6opulationJ,LJCL R populationJ)estIndu;idualL JCLI _ for=i R -I i \R populationSize 3 -I i<<> ^ for=C R ,I C \R num)erOfGenes 3 -I C<<> ^ tempIndi;idualJCL R temp6opulationJiLJCLI r R &andFunBtion=>I if =r \R mutation6ro)a)ilit!> ^ r R &andFunBtion=>I if=r ]R ,.2> ^ tempIndi;idualJCL R -I _ else ^ tempIndi;idualJCL R ,I _ _ temp6opulationJiLJCL R tempIndi;idualJCLI _ _ for=i R ,I i \R populationSize 3 -I i<<>77cop! arra! population R temp6opulation ^ for=C R ,I C \R num)erOfGenes 3 -I C<<> ^ populationJiLJCL R temp6opulationJiLJCLI _ _ 77New population is made for neDt generation )estIndu;idual R ,I77 &esets until neDt generation if ==maDFitness ]R total$aDFitness> MM =maDFitness cR total$aDFitness>>77maDFitness ] total$aDFitness ^ for=C R ,I C \R num)erOfGenes 3 -I C<<> ^ goodIndi;idualsJhLJCL R temp6opulationJ,LJCLI _ total$aDFitness R maDFitnessI _ _ &eturn&esult=)est6arameter'alue-* )est6arameter'alue+* )est6arameter'alue?* )est6arameter'alue4* )est6arameter'alue2* )est6arameter'alue1* input'alue* maDFitness>I printf=a...............................................................................bna>I pre;ious%Dcecution R )est6arameter'alue-I maDFitness R ,I77 &esets until neDt generation _ printf=abnGood indi;iduals in )inar! form/bnbna>I for=int h R ,I h \R sim 3 -I h<<> ^ for=C R ,I C \R num)erOfGenes 3 -I C<<> ^ printf=aPda* goodIndi;idualsJhLJCL>I _ )est6arameter'alue- R ecodeChromosome=goodIndi;iduals* h*

2F

num)erOfGenes* -* num)erOfChromosomes>I )est6arameter'alue+ R ecodeChromosome=goodIndi;iduals* h* num)erOfGenes* +* num)erOfChromosomes>I )est6arameter'alue? R ecodeChromosome=goodIndi;iduals* h* num)erOfGenes* ?* num)erOfChromosomes>I )est6arameter'alue4 R ecodeChromosome=goodIndi;iduals* h* num)erOfGenes* 4* num)erOfChromosomes>I )est6arameter'alue2 R ecodeChromosome=goodIndi;iduals* h* num)erOfGenes* 2* num)erOfChromosomes>I )est6arameter'alue1 R ecodeChromosome=goodIndi;iduals* h* num)erOfGenes* 1* num)erOfChromosomes>I printf=a R P+d 3 P+d 3 P+d 3 P+d 3 P+d 3 P+dbna*

)est6arameter'alue-* )est6arameter'alue+* )est6arameter'alue?* )est6arameter'alue4* )est6arameter'alue2* )est6arameter'alue1>I _ msgOrder R ?I 6rintOutFunBtion=msgOrder* m%Int* m%Int* m%Int* m%Int* m%Int* m%Int* m%Int* m%Int* m%Int>I printf=abna>I 77getchar=>I To stop command window. _

25

1,

Appendi- 5 *rogram code of D#S !ersion


Source code for FS ;ersion with 4ormal case inputs implemented.
7Z FS ;ersion normal case Z7 case 1/ [include \stdio.h] [include \conio.h] int %;aluateIndi;idual=int c-* int c+* int c?* int c4* int c2* int c1* int input'alueJ+5L* int pre;ious%Dcecution> ^ int f R ,* i R ,* D R ,* p R ,* points R ,* pre;iousOrderI int i6N- R input'alueJ,LI int i6N+ R input'alueJ-LI int i6N? R input'alueJ+LI int i6K- R input'alueJ?LI int i6K+ R input'alueJ4LI int i6K? R input'alueJ2LI int i6% R input'alueJ1LI int i6S- R input'alueJ0LI int i6S+ R input'alueJFLI int i6S? R input'alueJ5LI int iTNK R input'alueJ-,LI int iTN% R input'alueJ--LI int iTNS R input'alueJ-+LI int iTKN R input'alueJ-?LI int iTK% R input'alueJ-4LI int iT%N R input'alueJ-2LI int iT%K R input'alueJ-1LI int iT%S R input'alueJ-0LI int iTSN R input'alueJ-FLI int iTS% R input'alueJ-5LI int i&NK R input'alueJ+,LI int i&N% R input'alueJ+-LI int i&NS R input'alueJ++LI int i&KN R input'alueJ+?LI int i&KS% R input'alueJ+4LI int i&%NK R input'alueJ+2LI int i&%S R input'alueJ+1LI int i&SK R input'alueJ+0LI int i&SN% R input'alueJ+FLI D R pre;ious%DcecutionI for=i R ,I i \R 1 3 -I i<<> ^ pre;iousOrder R DI if=i RR ,> ^D R c-I_ if=i RR -> ^D R c+I_ if=i RR +> ^D R c?I_ if=i RR ?> ^D R c4I_ if=i RR 4> ^D R c2I_ if=i RR 2> ^D R c1I_ points R ,I 77Inputs functions calculations switch=D> ^ case ,/ points R iTNK < iT%N < iTS% < i6N- < i6N+ < i6N? < i6S- < i6S? < i&NKI iTNK R ,I iT%N R ,I iTS% R ,I i6N- R ,I i6N+ R ,I i6N? R ,I i6S- R ,I i6S? R ,I i&NK R ,I )reaBI case -/ points R iTNK < iT%N < iTK% < i6N? < i6K- < i6S- < i6S+ < i6S? < i&KS%I iTNK R ,I iT%N R ,I iTK% R ,I i6N? R ,I i6K- R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KS% R ,I )reaBI case +/ points R iTNS < iT%N < iTS% < i6K- < i6K+ < i6K? < i6N? < i6S? < i&NK < i&NSI iTNS R ,I iT%N R ,I iTS% R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6N? R ,I i6S? R ,I i&NK R ,I i&NS R ,I )reaBI case ?/ points R iTNK < iTSN < i6K- < i6K? < i6% < i6S< i&NK < i&SN%I iTNK R ,I iTSN R ,I i6K- R ,I i6K? R ,I i6% R ,I i6S- R ,I i&NK R ,I i&SN% R ,I )reaBI case 4/ points R iT%K < iTS% < i6N- < i6N+ < i6N? < i6K? < i6S- < i6S? < i&%NKI iT%K R ,I iTS% R ,I i6N- R ,I i6N+ R ,I i6N?R ,I i6K? R ,I i6S- R ,I i6S? R ,I i&%NK R ,I )reaBI case 2/ points R +ZiTNK < +ZiTKN < +ZiT%S < ?ZiTS% < i6N? < i6K- < i6K? < i6S- < i6S? < i&NKI iTNK R ,I iTKN R ,I iT%S R ,I iTS% R ,I i6N? R ,I i6K- R ,I i6K? R ,I i6S- R ,I i6S? R ,I i&NK R ,I points R 4ZiTN% < 4ZiT%N < i6N? < i6K- < i6K+ < i6K? < i6S+ < i6S? < i&NK < i&NS < i&N%I iTN% R ,I iT%N R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6S+ R ,I i6S? R ,I i&NK R ,I i&NS R ,I i&N% R ,I )reaBI case 0/ points R +ZiTNS < +ZiTSN < i6K- < i6K+ < i6K? < i6% < i&NK < i&NS < i&SN%I iTNSR ,I iTSN R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6% R ,I i&NK R ,I i&NS R ,I i&SN% R ,I )reaBI case F/ points R ?ZiTK% < ?ZiT%K < i6N- < i6N+ < i6N? < i6S- < i6S+ < i6S? < i&%NK < i&KS%I iTK% R ,I iT%K R ,I i6N- R ,I i6N+ R ,I i6N? R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&%NK R ,I i&KS% R ,I )reaBI case 5/ points R iTNK < iTKN < i6N- < i6N? < i6K- < i6S- < i6S+ < i6S? < +Zi&KN < i&KS%I iTNK R ,I iTKN R ,I i6N- R ,I i6N? R ,I i6K- R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KN R ,I i&KS% R ,I )reaBI case -,/ points R i6N+ < i6K- < i6K+ < i6K? < i6S+ < i6% < i&NK < i&NS < +Zi&SN%I i6N+ R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6S+ R ,I i6% R ,I i&NK R ,I i&NS R ,I i&SN% R ,I )reaBI case --/ points R i6N- < i6N+ < i6N? < i6K+ < i6S- < i6S+ < i6S? < +Zi&%NK < +Zi&KS%I i6N- R ,I i6N+ R ,I i6N? R ,I i6K+ R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&%NK R ,I i&KS% R ,I )reaBI case -+/ points R i6N+ < i6N? < i6K- < i6K+ < i6K? < i6% < i6S- < i6S+ < +Zi&N% < +Zi&SKI i6N+ R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6% R ,I i6S- R ,I i6S+ R ,I i&N% R ,I i&SK R ,I )reaBI case -?/ points R i6N- < i6N+ < i6N? < i6K- < i6K+ < i6S- < i6S+ < i6S? < +Zi&KN < +Zi&%SI i6N- R ,I i6N+ R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KN R ,I i&%S R ,I )reaBI case -4/ points R iTS% < iT%S < i6N- < i6N+ < i6N? < i6K< i6K+ < i6K? < i6S- < i6S? < i&%SI iTS% R ,I iT%S R ,I i6N- R ,I i6N+ R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6S- R ,I i6S? R ,I i&%S R ,I )reaBI case -2/ points R iTN% < iT%N < i6N- < i6N? < i6K- < i6K+ < i6S- < i6S+ < i6S? < +Zi&KS%I iTN% R ,I iT%N R ,I i6N- R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KS% R ,I )reaBI case -1/ points R ,I )reaBI _ 776re;ious order calculations switch=D> ^ case ,/ if==pre;iousOrder RR --> `` =pre;iousOrder RR -?>> ^points R points < +I_ if=pre;iousOrder RR ,> ^points R points 3 2I_ )reaBI case -/ if==pre;iousOrder RR --> `` =pre;iousOrder RR -?>> ^points R points < +I_ if=pre;iousOrder RR -> ^points R points 3 2I_ )reaBI case +/ if==pre;iousOrder RR --> `` =pre;iousOrder RR -?>> ^points R points < +I_ if=pre;iousOrder RR +> ^points R points 3 2I_ )reaBI case ?/ if==pre;iousOrder RR --> `` =pre;iousOrder RR -?>> ^points R points < +I_ if=pre;iousOrder RR ?> ^points R points 3 2I_ )reaBI case 4/ if==pre;iousOrder RR -,> `` =pre;iousOrder RR -+>> )reaBI

1-

^points R points < +I_ if=pre;iousOrder RR 4> ^points R points 3 2I_ )reaBI case 2/ if==pre;iousOrder RR -+> `` =pre;iousOrder RR -?>> ^points R points < +I_ if=pre;iousOrder RR 2> ^points R points 3 2I_ )reaBI case 1/ if==pre;iousOrder RR --> `` =pre;iousOrder RR -?>> ^points R points < +I_ if=pre;iousOrder RR 1> ^points R points 3 2I_ )reaBI case 0/ if==pre;iousOrder RR F> `` =pre;iousOrder RR -?>> ^points R points < +I_ if=pre;iousOrder RR 0> ^points R points 3 2I_ )reaBI case F/ if==pre;iousOrder RR 0> `` =pre;iousOrder RR -+>> ^points R points < +I_ if=pre;iousOrder RR F> ^points R points 3 2I_ )reaBI case 5/ if==pre;iousOrder RR -,> `` =pre;iousOrder RR -4>> ^points R points < +I_ if=pre;iousOrder RR 5> ^points R points 3 2I_ )reaBI case -,/ if==pre;iousOrder RR F> `` =pre;iousOrder RR 5>> ^points R points < +I_ if=pre;iousOrder RR -,> ^points R points 3 2I_ )reaBI case --/ if==pre;iousOrder RR 2> `` =pre;iousOrder RR 0>> ^points R points < +I_ if=pre;iousOrder RR --> ^points R points 3 2I_ )reaBI case -+/ if==pre;iousOrder RR 2> `` =pre;iousOrder RR F>> ^points R points < +I_ if=pre;iousOrder RR -+> ^points R points 3 2I_ )reaBI case -?/ if==pre;iousOrder RR 2> `` =pre;iousOrder RR 0>> ^points R points < +I_ if=pre;iousOrder RR -?> ^points R points 3 2I_ )reaBI case -4/ if==pre;iousOrder RR 5> `` =pre;iousOrder RR -+>> ^points R points < +I_ if=pre;iousOrder RR -4> ^points R points 3 2I_ )reaBI case -2/ if==pre;iousOrder RR -,> `` =pre;iousOrder RR -?>> ^points R points < +I_ if=pre;iousOrder RR -2> ^points R points 3 2I_ )reaBI _ if=i RR ,> ^f R 1ZpointsI_ if=i RR -> ^f R f < 2ZpointsI_ if=i RR +> ^f R f < 4ZpointsI_ if=i RR ?> ^f R f < ?ZpointsI_ if=i RR 4> ^f R f < +ZpointsI_ if=i RR 2> ^f R f < pointsI_ if=i RR , MM points \R +> ^p R -I_ _ if=p RR -> ^f R ,I_77if p- R , 3] f R , return fI _ ;oid &eturn&esult=int )est6arameter'alue-* int )est6arameter'alue+* int )est6arameter'alue?* int )est6arameter'alue4* int )est6arameter'alue2* int )est6arameter'alue1* int input'alueJ+5L* int maDFitness> ^ int f R ,* D R ,* points R ,* pre;iousOrderI int i6N- R input'alueJ,LI int i6N+ R input'alueJ-LI int i6N? R input'alueJ+LI int i6K- R input'alueJ?LI int i6K+ R input'alueJ4LI int i6K? R input'alueJ2LI int i6% R input'alueJ1LI int i6S- R input'alueJ0LI int i6S+ R input'alueJFLI int i6S? R input'alueJ5LI int iTNK R input'alueJ-,LI int iTN% R input'alueJ--LI int iTNS R input'alueJ-+LI int iTKN R input'alueJ-?LI int iTK% R input'alueJ-4LI int iT%N R input'alueJ-2LI int iT%K R input'alueJ-1LI int iT%S R input'alueJ-0LI int iTSN R input'alueJ-FLI int iTS% R input'alueJ-5LI int i&NK R input'alueJ+,LI int i&N% R input'alueJ+-LI int i&NS R input'alueJ++LI int i&KN R input'alueJ+?LI

int i&KS% R input'alueJ+4LI int i&%NK R input'alueJ+2LI int i&%S R input'alueJ+1LI int i&SK R input'alueJ+0LI int i&SN% R input'alueJ+FLI printf=abn 666 666 6 666 TTT TT TTT TT &&& && && &&bna>I printf=a NNN KKK % SSS NNN KK %%% SS NNN KK %% SSbna>I printf=a -+? -+? -+? K%S N% NKS N% K%S NS NS KNbna>I printf=a ``` ``` ` ``` ``` `` ``` `` ``` `% K` `%bna>I printf=ai PdPdPd.PdPdPd.Pd.PdPdPd / PdPdPd.PdPd.PdPdPd. PdPd / PdPdPd.PdPd.PdPd.PdPd $aD fitness/ Pdbna* i6N-* i6N+* i6N?* i6K-* i6K+* i6K?* i6%* i6S-* i6S+* i6S?* iTNK* iTN%* iTNS* iTKN* iTK%* iT%N* iT%K* iT%S* iTSN* iTS%* i&NK* i&N%* i&NS* i&KN* i&KS%* i&%NK* i&%S* i&SK* i&SN%* maDFitness>I for=int i R ,I i \R 1 3 -I i<<> ^ pre;iousOrder R DI if=i RR ,> ^D R )est6arameter'alue-I_ if=i RR -> ^D R )est6arameter'alue+I_ if=i RR +> ^D R )est6arameter'alue?I_ if=i RR ?> ^D R )est6arameter'alue4I_ if=i RR 4> ^D R )est6arameter'alue2I_ if=i RR 2> ^D R )est6arameter'alue1I_ points R ,I 77Inputs functions calculations switch=D> ^ case ,/ points R iTNK < iT%N < iTS% < i6N- < i6N+ < i6N? < i6S- < i6S? < i&NKI iTNK R ,I iT%N R ,I iTS% R ,I i6N- R ,I i6N+ R ,I i6N? R ,I i6S- R ,I i6S? R ,I i&NK R ,I )reaBI case -/ points R iTNK < iT%N < iTK% < i6N? < i6K- < i6S- < i6S+ < i6S? < i&KS%I iTNK R ,I iT%N R ,I iTK% R ,I i6N? R ,I i6K- R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KS% R ,I )reaBI case +/ points R iTNS < iT%N < iTS% < i6K- < i6K+ < i6K? < i6N? < i6S? < i&NK < i&NSI iTNS R ,I iT%N R ,I iTS% R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6N? R ,I i6S? R ,I i&NK R ,I i&NS R ,I )reaBI case ?/ points R iTNK < iTSN < i6K- < i6K? < i6% < i6S< i&NK < i&SN%I iTNK R ,I iTSN R ,I i6K- R ,I i6K? R ,I i6% R ,I i6S- R ,I i&NK R ,I i&SN% R ,I )reaBI case 4/ points R iT%K < iTS% < i6N- < i6N+ < i6N? < i6K? < i6S- < i6S? < i&%NKI iT%K R ,I iTS% R ,I i6N- R ,I i6N+ R ,I i6N?R ,I i6K? R ,I i6S- R ,I i6S? R ,I i&%NK R ,I )reaBI case 2/ points R +ZiTNK < +ZiTKN < +ZiT%S < +ZiTS% < i6N? < i6K- < i6K? < i6S- < i6S? < i&NKI iTNK R ,I iTKN R ,I iT%S R ,I iTS% R ,I i6N? R ,I i6K- R ,I i6K? R ,I i6S- R ,I i6S? R ,I i&NK R ,I )reaBI case 1/ points R +ZiTN% < 4ZiT%N < i6N? < i6K- < i6K+ < i6K? < i6S+ < i6S? < i&NK < i&NS < i&N%I iTN% R ,I iT%N R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6S+ R ,I i6S? R ,I i&NK R ,I i&NS R ,I i&N% R ,I )reaBI case 0/ points R +ZiTNS < +ZiTSN < i6K- < i6K+ < i6K? < i6% < i&NK < i&NS < i&SN%I iTNSR ,I iTSN R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6% R ,I i&NK R ,I i&NS R ,I i&SN% R ,I )reaBI case F/ points R +ZiTK% < +ZiT%K < i6N- < i6N+ < i6N? < i6S- < i6S+ < i6S? < i&%NK < i&KS%I iTK% R ,I iT%K R ,I i6N- R ,I i6N+ R ,I i6N? R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&%NK R ,I i&KS% R ,I )reaBI case 5/ points R iTNK < iTKN < i6N- < i6N? < i6K- < i6S- < i6S+ < i6S? < +Zi&KN < i&KS%I iTNK R ,I iTKN R ,I i6N- R ,I i6N? R ,I i6K- R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KN R ,I i&KS% R ,I )reaBI case -,/ points R i6N+ < i6K- < i6K+ < i6K? < i6S+ < i6% < i&NK < i&NS < +Zi&SN%I i6N+ R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6S+ R ,I i6% R ,I i&NK R ,I i&NS R ,I i&SN% R ,I )reaBI case --/ points R i6N- < i6N+ < i6N? < i6K+ < i6S- < i6S+ < i6S? < +Zi&%NK < +Zi&KS%I i6N- R ,I i6N+ R ,I i6N? R ,I i6K+ R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&%NK R ,I i&KS% R ,I

1+

)reaBI case -+/ points R i6N+ < i6N? < i6K- < i6K+ < i6K? < i6% < i6S- < i6S+ < +Zi&N% < +Zi&SKI i6N+ R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6% R ,I i6S- R ,I i6S+ R ,I i&N% R ,I i&SK R ,I )reaBI case -?/ points R i6N- < i6N+ < i6N? < i6K- < i6K+ < i6S- < i6S+ < i6S? < +Zi&KN < +Zi&%SI i6N- R ,I i6N+ R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KN R ,I i&%S R ,I )reaBI case -4/ points R iTS% < iT%S < i6N- < i6N+ < i6N? < i6K< i6K+ < i6K? < i6S- < i6S? < i&%SI iTS% R ,I iT%S R ,I i6N- R ,I i6N+ R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6S- R ,I i6S? R ,I i&%S R ,I )reaBI case -2/ points R iTN% < iT%N < i6N- < i6N? < i6K- < i6K+ < i6S- < i6S+ < i6S? < +Zi&KS%I iTN% R ,I iT%N R ,I i6N- R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KS% R ,I )reaBI case -1/ points R ,I )reaBI _ 776re;ious order calculations switch=D> ^ case ,/ if==pre;iousOrder RR --> `` =pre;iousOrder RR -?>> ^points R points < +I_ )reaBI case -/ if==pre;iousOrder RR --> `` =pre;iousOrder RR -?>> ^points R points < +I_ )reaBI case +/ if==pre;iousOrder RR --> `` =pre;iousOrder RR -?>> ^points R points < +I_ )reaBI case ?/ if==pre;iousOrder RR --> `` =pre;iousOrder RR -?>> ^points R points < +I_ )reaBI case 4/ if==pre;iousOrder RR -,> `` =pre;iousOrder RR -+>> ^points R points < +I_ )reaBI case 2/ if==pre;iousOrder RR -+> `` =pre;iousOrder RR -?>> ^points R points < +I_ )reaBI case 1/ if==pre;iousOrder RR --> `` =pre;iousOrder RR -?>> ^points R points < +I_ )reaBI case 0/ if==pre;iousOrder RR F> `` =pre;iousOrder RR -?>> ^points R points < +I_ )reaBI case F/ if==pre;iousOrder RR 0> `` =pre;iousOrder RR -+>> ^points R points < +I_ )reaBI case 5/ if==pre;iousOrder RR -,> `` =pre;iousOrder RR -4>> ^points R points < +I_ )reaBI case -,/ if==pre;iousOrder RR F> `` =pre;iousOrder RR 5>> ^points R points < +I_ )reaBI case --/ if==pre;iousOrder RR 2> `` =pre;iousOrder RR 0>> ^points R points < +I_ )reaBI case -+/ if==pre;iousOrder RR 2> `` =pre;iousOrder RR F>> ^points R points < +I_ )reaBI case -?/ if==pre;iousOrder RR 2> `` =pre;iousOrder RR 0>> ^points R points < +I_ )reaBI case -4/ if==pre;iousOrder RR 5> `` =pre;iousOrder RR -+>> ^points R points < +I_ )reaBI case -2/ if==pre;iousOrder RR -,> `` =pre;iousOrder RR -?>> ^points R points < +I_ )reaBI case -1/ 77 )reaBI _ if=i RR ,> ^f R 1ZpointsI_

if=i RR -> ^f R f < 2ZpointsI_ if=i RR +> ^f R f < 4ZpointsI_ if=i RR ?> ^f R f < ?ZpointsI_ if=i RR 4> ^f R f < +ZpointsI_ if=i RR 2> ^f R f < pointsI_ printf=acPd PdPdPd.PdPdPd.Pd.PdPdPd / PdPdPd.PdPd. PdPdPd.PdPd / PdPdPd.PdPd.PdPd.PdPd Order R P+d 6oints R P+dbna* i<-* i6N-* i6N+* i6N?* i6K-* i6K+* i6K?* i6%* i6S-* i6S+* i6S?* iTNK* iTN%* iTNS* iTKN* iTK%* iT%N* iT%K* iT%S* iTSN* iTS%* i&NK* i&N%* i&NS* i&KN* i&KS%* i&%NK* i&%S* i&SK* i&SN%* D *points>I _ printf=abna>I 77Output print out switch=)est6arameter'alue-> ^ case ,/ printf=a%Decuting reAuests on dri;e order Pd/bnoTNK* oT%N* oTS%* o6N-* o6N+* o6N?* o6S-* o6S?* o&NKbna* )est6arameter'alue->I )reaBI case -/ printf=a%Decuting reAuests on dri;e order Pd/bnoTNK* oT%N* oTK%* o6N?* o6K-* o6S-* o6S+* o6S?* o&KS%bna* )est6arameter'alue->I )reaBI case +/ printf=a%Decuting reAuests on dri;e order Pd/bnoTNS* oT%N* oTS%* o6K-* o6K+* o6K?* o6N?* o6S?* o&NK* o&NSbna* )est6arameter'alue->I )reaBI case ?/ printf=a%Decuting reAuests on dri;e order Pd/bnoTNK* oTSN* o6K-* o6K?* o6%* o6S-* o&NK* o&SN%bna* )est6arameter'alue->I )reaBI case 4/ printf=a%Decuting reAuests on dri;e order Pd/bnoT%K* oTS%* o6N-* o6N+* o6N?* o6K?* o6S-* o6S?* o&%NKbna* )est6arameter'alue->I )reaBI case 2/ printf=a%Decuting reAuests on dri;e order Pd/bnoTNK* oTKN* oT%S* oTS%* o6N?* o6K-* o6K?* o6S-* o6S?* o&NKbna* )est6arameter'alue->I )reaBI case 1/ printf=a%Decuting reAuests on dri;e order Pd/bnoTN%* oT%N* o6N?* o6K-* o6K+* o6K?* o6S+* o6S?* o&NK* o&NS* o&N%bna* )est6arameter'alue->I )reaBI case 0/ printf=a%Decuting reAuests on dri;e order Pd/bnoTNS* oTSN* o6K-* o6K+* o6K?* o6%* o&NK* o&NS* o&SN%bna* )est6arameter'alue->I )reaBI case F/ printf=a%Decuting reAuests on dri;e order Pd/bnoTK%* oT%K* o6N-* o6N+* o6N?* o6S-* o6S+* o6S?* o&%NK* o&KS%bna* )est6arameter'alue->I )reaBI case 5/ printf=a%Decuting reAuests on dri;e order Pd/bnoTNK* oTKN* o6N-* o6N?* o6K-* o6S-* o6S+* o6S?* o&KN* o&KS%bna* )est6arameter'alue->I )reaBI case -,/ printf=a%Decuting reAuests on dri;e order Pd/bno6N+* o6K-* o6K+* o6K?* o6S+* o6%* o&NK* o&NS* o&SN%bna* )est6arameter'alue->I )reaBI case --/ printf=a%Decuting reAuests on dri;e order Pd/bno6N-* o6N+* o6N?* o6K+* o6S-* o6S+* o6S?* o&%NK* o&KS%bna* )est6arameter'alue->I )reaBI case -+/ printf=a%Decuting reAuests on dri;e order Pd/bno6N+* o6N?* o6K-* o6K+* o6K?* o6%* o6S-* o6S+* o&N%* o&SKbna* )est6arameter'alue->I )reaBI case -?/ printf=a%Decuting reAuests on dri;e order Pd/bno6N-* o6N+* o6N?* o6K-* o6K+* o6S-* o6S+* o6S?* o&KN* o&%Sbna* )est6arameter'alue->I )reaBI case -4/ printf=a%Decuting reAuests on dri;e order Pd/bnoTS%* oT%S* o6N-* o6N+* o6N?* o6K-* o6K+* o6K?* o6S-* o6S?* o&%Sbna* )est6arameter'alue->I )reaBI case -2/ printf=a%Decuting reAuests on dri;e order Pd/bnoTN%* oT%N* o6N-* o6N?* o6K-* o6K+* o6S-* o6S+* o6S?* o&KS%bna* )est6arameter'alue->I )reaBI case -1/ printf=a o not eDecuting an! dri;e order.bna>I )reaBI _ printf=abna>I _ int main=> ^ int input'alueJ+5LI77All inputs to worB with int input'aluesJ-,LJ+5LI77#ist of all time periods inputs JRsimLJ+5L int maDFitness R ,I int fitnessI77Store fitness ;alue for each indi;idual in present generation int parameter'alue- R -1I77Temporar! parameter ;alue =-1 is for null result>

1?

int parameter'alue+ R -1I77Temporar! parameter ;alue int parameter'alue? R -1I77Temporar! parameter ;alue int parameter'alue4 R -1I77Temporar! parameter ;alue int parameter'alue2 R -1I77Temporar! parameter ;alue int parameter'alue1 R -1I77Temporar! parameter ;alue int )est6arameter'alue- R -1I77Gest chromosome ;alue int )est6arameter'alue+ R -1I77Gest chromosome ;alue int )est6arameter'alue? R -1I77Gest chromosome ;alue int )est6arameter'alue4 R -1I77Gest chromosome ;alue int )est6arameter'alue2 R -1I77Gest chromosome ;alue int )est6arameter'alue1 R -1I77Gest chromosome ;alue int pre;ious%Dcecution R -1I77Store c- =%> from pre;ious time period int sim R -,I77Num)er of simulations int i* C* B* l* m* n* D R ,I int msgOrder R ,* m%Int R ,I float m%float R ,I77 Other ;aria)les for=C R ,I C \R +FI C<<> ^ input'alueJCL R ,I _ for=i R ,I i \R sim 3 -I i<<> ^ for=C R ,I C \R +FI C<<> ^ input'aluesJiLJCL R ,I _ _ 77Onl! 2 first is filled with inputs 77Init input'alue , input'aluesJ,LJ,L R -I 7Z 6N- Z7 input'aluesJ,LJ-,L R -I 7Z TNK Z7 input'aluesJ,LJ+,L R ,I 7Z &NK Z7 input'aluesJ,LJ-L R ,I 7Z 6N+ Z7 input'aluesJ,LJ--L R ,I 7Z TN% Z7 input'aluesJ,LJ+-L R -I 7Z &N% Z7 input'aluesJ,LJ+L R -I 7Z 6N? Z7 input'aluesJ,LJ-+L R ,I 7Z TNS Z7 input'aluesJ,LJ++L R -I 7Z &NS Z7 input'aluesJ,LJ?L R ,I 7Z 6K- Z7 input'aluesJ,LJ-?L R -I 7Z TKN Z7 input'aluesJ,LJ+?L R ,I 7Z &KN Z7 input'aluesJ,LJ4L R ,I 7Z 6K+ Z7 input'aluesJ,LJ-4L R ,I 7Z TK% Z7 input'aluesJ,LJ+4L R ,I 7Z &KS% Z7 input'aluesJ,LJ2L R -I 7Z 6K? Z7 input'aluesJ,LJ-2L R ,I 7Z T%N Z7 input'aluesJ,LJ+2L R ,I 7Z &%NK Z7 input'aluesJ,LJ1L R ,I 7Z 6% Z7 input'aluesJ,LJ-1L R ,I 7Z T%K Z7 input'aluesJ,LJ+1L R ,I 7Z &%S Z7 input'aluesJ,LJ0L R ,I 7Z 6S- Z7 input'aluesJ,LJ-0L R ,I 7Z T%S Z7 input'aluesJ,LJ+0L R -I 7Z &SK Z7 input'aluesJ,LJFL R ,I 7Z 6S+ Z7 input'aluesJ,LJ-FL R -I 7Z TSN Z7 input'aluesJ,LJ+FL R -I 7Z &SN% Z7 input'aluesJ,LJ5L R -I 7Z 6S? Z7 input'aluesJ,LJ-5L R ,I 7Z TS% Z7 77Init input'alue input'aluesJ-LJ,L R ,I 7Z 6N- Z7 input'aluesJ-LJ-,L R ,I 7Z TNK Z7 input'aluesJ-LJ+,L R -I 7Z &NK Z7 input'aluesJ-LJ-L R -I 7Z 6N+ Z7 input'aluesJ-LJ--L R ,I 7Z TN% Z7 input'aluesJ-LJ+-L R -I 7Z &N% Z7 input'aluesJ-LJ+L R ,I 7Z 6N? Z7 input'aluesJ-LJ-+L R ,I 7Z TNS Z7 input'aluesJ-LJ++L R -I 7Z &NS Z7 input'aluesJ-LJ?L R -I 7Z 6K- Z7 input'aluesJ-LJ-?L R ,I 7Z TKN Z7 input'aluesJ-LJ+?L R -I 7Z &KN Z7 input'aluesJ-LJ4L R -I 7Z 6K+ Z7 input'aluesJ-LJ-4L R ,I 7Z TK% Z7 input'aluesJ-LJ+4L R ,I 7Z &KS% Z7 input'aluesJ-LJ2L R ,I 7Z 6K? Z7 input'aluesJ-LJ-2L R ,I 7Z T%N Z7 input'aluesJ-LJ+2L R ,I 7Z &%NK Z7 input'aluesJ-LJ1L R -I 7Z 6% Z7 input'aluesJ-LJ-1L R ,I 7Z T%K Z7 input'aluesJ-LJ+1L R ,I 7Z &%S Z7 input'aluesJ-LJ0L R -I 7Z 6S- Z7 input'aluesJ-LJ-0L R ,I 7Z T%S Z7 input'aluesJ-LJ+0L R -I 7Z &SK Z7 input'aluesJ-LJFL R -I 7Z 6S+ Z7 input'aluesJ-LJ-FL R ,I 7Z TSN Z7 input'aluesJ-LJ+FL R -I 7Z &SN% Z7 input'aluesJ-LJ5L R ,I 7Z 6S? Z7 input'aluesJ-LJ-5L R ,I 7Z TS% Z7 77Init input'alue + input'aluesJ+LJ,L R ,I 7Z 6N- Z7 input'aluesJ+LJ-,L R ,I 7Z TNK Z7 input'aluesJ+LJ+,L R -I 7Z &NK Z7 input'aluesJ+LJ-L R ,I 7Z 6N+ Z7 input'aluesJ+LJ--L R ,I 7Z TN% Z7 input'aluesJ+LJ+-L R ,I 7Z &N% Z7 input'aluesJ+LJ+L R -I 7Z 6N? Z7 input'aluesJ+LJ-+L R -I 7Z TNS Z7 input'aluesJ+LJ++L R -I 7Z &NS Z7 input'aluesJ+LJ?L R -I 7Z 6K- Z7 input'aluesJ+LJ-?L R ,I 7Z TKN Z7 input'aluesJ+LJ+?L R -I 7Z &KN Z7 input'aluesJ+LJ4L R -I 7Z 6K+ Z7 input'aluesJ+LJ-4L R -I 7Z TK% Z7 input'aluesJ+LJ+4L R ,I 7Z &KS% Z7 input'aluesJ+LJ2L R ,I 7Z 6K? Z7 input'aluesJ+LJ-2L R ,I 7Z T%N Z7 input'aluesJ+LJ+2L R ,I 7Z &%NK Z7 input'aluesJ+LJ1L R ,I 7Z 6% Z7 input'aluesJ+LJ-1L R ,I 7Z T%K Z7 input'aluesJ+LJ+1L R ,I 7Z &%S Z7 input'aluesJ+LJ0L R -I 7Z 6S- Z7 input'aluesJ+LJ-0L R ,I 7Z T%S Z7 input'aluesJ+LJ+0L R ,I 7Z &SK Z7 input'aluesJ+LJFL R -I 7Z 6S+ Z7 input'aluesJ+LJ-FL R ,I 7Z TSN Z7 input'aluesJ+LJ+FL R -I 7Z &SN% Z7 input'aluesJ+LJ5L R ,I 7Z 6S? Z7 input'aluesJ+LJ-5L R ,I 7Z TS% Z7 77Init input'alue ? input'aluesJ?LJ,L R -I 7Z 6N- Z7 input'aluesJ?LJ-,L R ,I 7Z TNK Z7 input'aluesJ?LJ+,L R ,I 7Z &NK Z7 input'aluesJ?LJ-L R ,I 7Z 6N+ Z7 input'aluesJ?LJ--L R ,I 7Z TN% Z7 input'aluesJ?LJ+-L R -I 7Z &N% Z7 input'aluesJ?LJ+L R ,I 7Z 6N? Z7 input'aluesJ?LJ-+L R ,I 7Z TNS Z7 input'aluesJ?LJ++L R ,I 7Z &NS Z7 input'aluesJ?LJ?L R ,I 7Z 6K- Z7 input'aluesJ?LJ-?L R ,I 7Z

TKN Z7 input'aluesJ?LJ+?L R -I 7Z &KN Z7 input'aluesJ?LJ4L R ,I 7Z 6K+ Z7 input'aluesJ?LJ-4L R ,I 7Z TK% Z7 input'aluesJ?LJ+4L R -I 7Z &KS% Z7 input'aluesJ?LJ2L R ,I 7Z 6K? Z7 input'aluesJ?LJ-2L R ,I 7Z T%N Z7 input'aluesJ?LJ+2L R -I 7Z &%NK Z7 input'aluesJ?LJ1L R ,I 7Z 6% Z7 input'aluesJ?LJ-1L R ,I 7Z T%K Z7 input'aluesJ?LJ+1L R ,I 7Z &%S Z7 input'aluesJ?LJ0L R -I 7Z 6S- Z7 input'aluesJ?LJ-0L R ,I 7Z T%S Z7 input'aluesJ?LJ+0L R -I 7Z &SK Z7 input'aluesJ?LJFL R -I 7Z 6S+ Z7 input'aluesJ?LJ-FL R ,I 7Z TSN Z7 input'aluesJ?LJ+FL R ,I 7Z &SN% Z7 input'aluesJ?LJ5L R -I 7Z 6S? Z7 input'aluesJ?LJ-5L R ,I 7Z TS% Z7 77Init input'alue 4 input'aluesJ4LJ,L R ,I 7Z 6N- Z7 input'aluesJ4LJ-,L R ,I 7Z TNK Z7 input'aluesJ4LJ+,L R ,I 7Z &NK Z7 input'aluesJ4LJ-L R ,I 7Z 6N+ Z7 input'aluesJ4LJ--L R ,I 7Z TN% Z7 input'aluesJ4LJ+-L R -I 7Z &N% Z7 input'aluesJ4LJ+L R ,I 7Z 6N? Z7 input'aluesJ4LJ-+L R ,I 7Z TNS Z7 input'aluesJ4LJ++L R -I 7Z &NS Z7 input'aluesJ4LJ?L R -I 7Z 6K- Z7 input'aluesJ4LJ-?L R ,I 7Z TKN Z7 input'aluesJ4LJ+?L R -I 7Z &KN Z7 input'aluesJ4LJ4L R ,I 7Z 6K+ Z7 input'aluesJ4LJ-4L R ,I 7Z TK% Z7 input'aluesJ4LJ+4L R ,I 7Z &KS% Z7 input'aluesJ4LJ2L R ,I 7Z 6K? Z7 input'aluesJ4LJ-2L R ,I 7Z T%N Z7 input'aluesJ4LJ+2L R ,I 7Z &%NK Z7 input'aluesJ4LJ1L R -I 7Z 6% Z7 input'aluesJ4LJ-1L R ,I 7Z T%K Z7 input'aluesJ4LJ+1L R ,I 7Z &%S Z7 input'aluesJ4LJ0L R ,I 7Z 6S- Z7 input'aluesJ4LJ-0L R -I 7Z T%S Z7 input'aluesJ4LJ+0L R -I 7Z &SK Z7 input'aluesJ4LJFL R ,I 7Z 6S+ Z7 input'aluesJ4LJ-FL R ,I 7Z TSN Z7 input'aluesJ4LJ+FL R ,I 7Z &SN% Z7 input'aluesJ4LJ5L R ,I 7Z 6S? Z7 input'aluesJ4LJ-5L R -I 7Z TS% Z7 77Init input'alue 2 input'aluesJ2LJ,L R ,I 7Z 6N- Z7 input'aluesJ2LJ-,L R ,I 7Z TNK Z7 input'aluesJ2LJ+,L R ,I 7Z &NK Z7 input'aluesJ2LJ-L R ,I 7Z 6N+ Z7 input'aluesJ2LJ--L R -I 7Z TN% Z7 input'aluesJ2LJ+-L R ,I 7Z &N% Z7 input'aluesJ2LJ+L R ,I 7Z 6N? Z7 input'aluesJ2LJ-+L R ,I 7Z TNS Z7 input'aluesJ2LJ++L R ,I 7Z &NS Z7 input'aluesJ2LJ?L R ,I 7Z 6K- Z7 input'aluesJ2LJ-?L R ,I 7Z TKN Z7 input'aluesJ2LJ+?L R ,I 7Z &KN Z7 input'aluesJ2LJ4L R ,I 7Z 6K+ Z7 input'aluesJ2LJ-4L R ,I 7Z TK% Z7 input'aluesJ2LJ+4L R ,I 7Z &KS% Z7 input'aluesJ2LJ2L R -I 7Z 6K? Z7 input'aluesJ2LJ-2L R ,I 7Z T%N Z7 input'aluesJ2LJ+2L R ,I 7Z &%NK Z7 input'aluesJ2LJ1L R ,I 7Z 6% Z7 input'aluesJ2LJ-1L R ,I 7Z T%K Z7 input'aluesJ2LJ+1L R -I 7Z &%S Z7 input'aluesJ2LJ0L R ,I 7Z 6S- Z7 input'aluesJ2LJ-0L R ,I 7Z T%S Z7 input'aluesJ2LJ+0L R ,I 7Z &SK Z7 input'aluesJ2LJFL R ,I 7Z 6S+ Z7 input'aluesJ2LJ-FL R ,I 7Z TSN Z7 input'aluesJ2LJ+FL R -I 7Z &SN% Z7 input'aluesJ2LJ5L R -I 7Z 6S? Z7 input'aluesJ2LJ-5L R ,I 7Z TS% Z7 77Init input'alue 1 input'aluesJ1LJ,L R ,I 7Z 6N- Z7 input'aluesJ1LJ-,L R ,I 7Z TNK Z7 input'aluesJ1LJ+,L R -I 7Z &NK Z7 input'aluesJ1LJ-L R ,I 7Z 6N+ Z7 input'aluesJ1LJ--L R ,I 7Z TN% Z7 input'aluesJ1LJ+-L R ,I 7Z &N% Z7 input'aluesJ1LJ+L R ,I 7Z 6N? Z7 input'aluesJ1LJ-+L R ,I 7Z TNS Z7 input'aluesJ1LJ++L R -I 7Z &NS Z7 input'aluesJ1LJ?L R -I 7Z 6K- Z7 input'aluesJ1LJ-?L R ,I 7Z TKN Z7 input'aluesJ1LJ+?L R ,I 7Z &KN Z7 input'aluesJ1LJ4L R ,I 7Z 6K+ Z7 input'aluesJ1LJ-4L R ,I 7Z TK% Z7 input'aluesJ1LJ+4L R ,I 7Z &KS% Z7 input'aluesJ1LJ2L R ,I 7Z 6K? Z7 input'aluesJ1LJ-2L R ,I 7Z T%N Z7 input'aluesJ1LJ+2L R -I 7Z &%NK Z7 input'aluesJ1LJ1L R ,I 7Z 6% Z7 input'aluesJ1LJ-1L R ,I 7Z T%K Z7 input'aluesJ1LJ+1L R ,I 7Z &%S Z7 input'aluesJ1LJ0L R -I 7Z 6S- Z7 input'aluesJ1LJ-0L R ,I 7Z T%S Z7 input'aluesJ1LJ+0L R ,I 7Z &SK Z7 input'aluesJ1LJFL R ,I 7Z 6S+ Z7 input'aluesJ1LJ-FL R ,I 7Z TSN Z7 input'aluesJ1LJ+FL R -I 7Z &SN% Z7 input'aluesJ1LJ5L R ,I 7Z 6S? Z7 input'aluesJ1LJ-5L R ,I 7Z TS% Z7 77Init input'alue 0 input'aluesJ0LJ,L R -I 7Z 6N- Z7 input'aluesJ0LJ-,L R ,I 7Z TNK Z7 input'aluesJ0LJ+,L R ,I 7Z &NK Z7 input'aluesJ0LJ-L R ,I 7Z 6N+ Z7 input'aluesJ0LJ--L R ,I 7Z TN% Z7 input'aluesJ0LJ+-L R -I 7Z &N% Z7 input'aluesJ0LJ+L R -I 7Z 6N? Z7 input'aluesJ0LJ-+L R ,I 7Z TNS Z7 input'aluesJ0LJ++L R ,I 7Z &NS Z7 input'aluesJ0LJ?L R ,I 7Z 6K- Z7 input'aluesJ0LJ-?L R ,I 7Z TKN Z7 input'aluesJ0LJ+?L R ,I 7Z &KN Z7 input'aluesJ0LJ4L R ,I 7Z 6K+ Z7 input'aluesJ0LJ-4L R ,I 7Z TK% Z7 input'aluesJ0LJ+4L R -I 7Z &KS% Z7 input'aluesJ0LJ2L R -I 7Z 6K? Z7 input'aluesJ0LJ-2L R -I 7Z T%N Z7 input'aluesJ0LJ+2L R ,I 7Z &%NK Z7 input'aluesJ0LJ1L R -I 7Z 6% Z7 input'aluesJ0LJ-1L R ,I 7Z T%K Z7 input'aluesJ0LJ+1L R ,I 7Z &%S Z7 input'aluesJ0LJ0L R ,I 7Z 6S- Z7 input'aluesJ0LJ-0L R ,I 7Z T%S Z7 input'aluesJ0LJ+0L R ,I 7Z &SK Z7 input'aluesJ0LJFL R ,I 7Z 6S+ Z7 input'aluesJ0LJ-FL R ,I 7Z TSN Z7 input'aluesJ0LJ+FL R ,I 7Z &SN% Z7 input'aluesJ0LJ5L R ,I 7Z 6S? Z7 input'aluesJ0LJ-5L R -I 7Z TS% Z7 77Start main program printf=aStartbna>I for=int h R ,I h \R sim 3 -I h<<>

14

^ if=-> ^ int i6N- R input'alueJ,LI int i6N+ R input'alueJ-LI int i6N? R input'alueJ+LI int i6K- R input'alueJ?LI int i6K+ R input'alueJ4LI int i6K? R input'alueJ2LI int i6% R input'alueJ1LI int i6S- R input'alueJ0LI int i6S+ R input'alueJFLI int i6S? R input'alueJ5LI int iTNK R input'alueJ-,LI int iTN% R input'alueJ--LI int iTNS R input'alueJ-+LI int iTKN R input'alueJ-?LI int iTK% R input'alueJ-4LI int iT%N R input'alueJ-2LI int iT%K R input'alueJ-1LI int iT%S R input'alueJ-0LI int iTSN R input'alueJ-FLI int iTS% R input'alueJ-5LI int i&NK R input'alueJ+,LI int i&N% R input'alueJ+-LI int i&NS R input'alueJ++LI int i&KN R input'alueJ+?LI int i&KS% R input'alueJ+4LI int i&%NK R input'alueJ+2LI int i&%S R input'alueJ+1LI int i&SK R input'alueJ+0LI int i&SN% R input'alueJ+FLI switch=)est6arameter'alue-> ^ case ,/ iTNK R ,I iT%N R ,I iTS% R ,I i6N- R ,I i6N+ R ,I i6N? R ,I i6S- R ,I i6S? R ,I i&NK R ,I )reaBI case -/ iTNK R ,I iT%N R ,I iTK% R ,I i6N? R ,I i6K- R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KS% R ,I )reaBI case +/ iTNS R ,I iT%N R ,I iTS% R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6N? R ,I i6S? R ,I i&NK R ,I i&NS R ,I )reaBI case ?/ iTNK R ,I iTSN R ,I i6K- R ,I i6K? R ,I i6% R ,I i6S- R ,I i&NK R ,I i&SN% R ,I )reaBI case 4/ iT%K R ,I iTS% R ,I i6N- R ,I i6N+ R ,I i6N?R ,I i6K? R ,I i6S- R ,I i6S? R ,I i&%NK R ,I )reaBI case 2/ iTNK R ,I iTKN R ,I iT%S R ,I iTS% R ,I i6N? R ,I i6K- R ,I i6K? R ,I i6S- R ,I i6S? R ,I i&NK R ,I )reaBI case 1/ iTN% R ,I iT%N R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6S+ R ,I i6S? R ,I i&NK R ,I i&NS R ,I i&N% R ,I )reaBI case 0/ iTNSR ,I iTSN R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6% R ,I i&NK R ,I i&NS R ,I i&SN% R ,I )reaBI case F/ iTK% R ,I iT%K R ,I i6N- R ,I i6N+ R ,I i6N? R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&%NK R ,I i&KS% R ,I )reaBI case 5/ iTNK R ,I iTKN R ,I i6N- R ,I i6N? R ,I i6K- R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KN R ,I i&KS% R ,I )reaBI case -,/ i6N+ R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6S+ R ,I i6% R ,I i&NK R ,I i&NS R ,I i&SN% R ,I )reaBI case --/ i6N- R ,I i6N+ R ,I i6N? R ,I i6K+ R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&%NK R ,I i&KS% R ,I )reaBI case -+/ i6N+ R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6% R ,I i6S- R ,I i6S+ R ,I i&N% R ,I i&SK R ,I )reaBI case -?/ i6N- R ,I i6N+ R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KN R ,I i&%S R ,I )reaBI case -4/ iTS% R ,I iT%S R ,I i6N- R ,I i6N+ R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6K? R ,I i6S- R ,I i6S? R ,I i&%S R ,I )reaBI case -2/ iTN% R ,I iT%N R ,I i6N- R ,I i6N? R ,I i6K- R ,I i6K+ R ,I i6S- R ,I i6S+ R ,I i6S? R ,I i&KS% R ,I )reaBI case -1/

)reaBI _ 77 &ewrite input'alue input'alueJ,L R i6N-I input'alueJ-L R i6N+I input'alueJ+L R i6N?I input'alueJ?L R i6K-I input'alueJ4L R i6K+I input'alueJ2L R i6K?I input'alueJ1L R i6%I input'alueJ0L R i6S-I input'alueJFL R i6S+I input'alueJ5L R i6S?I input'alueJ-,L R iTNKI input'alueJ--L R iTN%I input'alueJ-+L R iTNSI input'alueJ-?L R iTKNI input'alueJ-4L R iTK%I input'alueJ-2L R iT%NI input'alueJ-1L R iT%KI input'alueJ-0L R iT%SI input'alueJ-FL R iTSNI input'alueJ-5L R iTS%I input'alueJ+,L R i&NKI input'alueJ+-L R i&N%I input'alueJ++L R i&NSI input'alueJ+?L R i&KNI input'alueJ+4L R i&KS%I input'alueJ+2L R i&%NKI input'alueJ+1L R i&%SI input'alueJ+0L R i&SKI input'alueJ+FL R i&SN%I for=C R ,I C \R +FI C<<> ^ if=input'alueJCL cR ,> ^input'alueJCL R input'alueJCL < -I_77 Add priorit! to remaining inputs else ^input'alueJCL R input'alueJCL < input'aluesJhL JCLI_77 Add new inputs if there are an! _ _ 77Start loop maDFitness R ,I for=i R ,I i \R -1 3 -I i<<> ^ for=C R ,I C \R -1 3 -I C<<> ^ for=B R ,I B \R -1 3 -I B<<> ^ for=l R ,I l \R -1 3 -I l<<> ^ for=m R ,I m \R -1 3 -I m<<> ^ for=n R ,I n \R -1 3 -I n<<> ^ parameter'alue- R i* parameter'alue+ R C* parameter'alue? R B* parameter'alue4 R l* parameter'alue2 R m* parameter'alue1 R nI fitness R %;aluateIndi;idual=parameter'alue-* parameter'alue+* parameter'alue?* parameter'alue4* parameter'alue2* parameter'alue1* input'alue* pre;ious%Dcecution>I if ==fitness ]R maDFitness> MM =fitness cR maDFitness>>77fitness ] maDFitness ^ maDFitness R fitnessI )est6arameter'alue- R parameter'alue-I )est6arameter'alue+ R parameter'alue+I )est6arameter'alue? R parameter'alue?I )est6arameter'alue4 R parameter'alue4I )est6arameter'alue2 R parameter'alue2I )est6arameter'alue1 R parameter'alue1I _ _ _ _ _ _ _ printf=aZZZZ FS ;ersion ZZZZbna>I printf=a6re;ious eDecuted dri;e order/ Pd* Simulation/ TPdbna* pre;ious%Dcecution* h>I &eturn&esult=)est6arameter'alue-* )est6arameter'alue+* )est6arameter'alue?* )est6arameter'alue4* )est6arameter'alue2* )est6arameter'alue1* input'alue* maDFitness>I printf=a...............................................................................bnbna>I pre;ious%Dcecution R )est6arameter'alue-I _ printf=abna>I 77getchar=>I To stop command window. _

12

Вам также может понравиться