STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

59
STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS USING GENETIC ALGORITHM FOR DESIGN ANALYSIS Thesis submitted in partial fulfillment of requirements for the award of Degree of Bachelor of Engineering in Mechanical Enginering By ABHIJIT BANERJEE BAPPADITTYA KUNDU DIBYENDU ROY SANTANU GHOSAL SNEHASIS DAS SOMENATH DEY SUJIT KUMAR MARANDI SUMAN SOURAV GHOSH Under The Guidance of Ambuj Kumar Mitra, Sr.lecturer,Mechanical Engineering Department Department Of Mechanical Engineering National Institute Of Technology Durgapur, West Bengal Durgapur – 713209 2006

description

STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS USING GENETIC ALGOARITHM IS A CASE STUDY HOW GENETIC ALGRITHM CAN BE USED TO SOLVE DESIGN PRBLEMS WITH FUZZY CONSTRAINTS FOR OPTIMIZATION

Transcript of STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

Page 1: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

USING GENETIC ALGORITHM FOR DESIGN ANALYSIS

Thesis submitted in partial fulfillment of requirements

for the award of Degree of Bachelor of Engineering

in

Mechanical Enginering

By

ABHIJIT BANERJEE BAPPADITTYA KUNDU

DIBYENDU ROY SANTANU GHOSAL

SNEHASIS DAS SOMENATH DEY

SUJIT KUMAR MARANDI SUMAN SOURAV GHOSH

Under The Guidance of

Ambuj Kumar Mitra, Sr.lecturer,Mechanical Engineering Department

Department Of Mechanical Engineering National Institute Of Technology

Durgapur, West Bengal Durgapur – 713209

2006

Page 2: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

A

ACKNOWLEDGEMENTS

We are thankful to prof.Ambuj Kumar Mitra, Mechanical Engineering Department, NIT-Durgapur for his kind guidance to carry out the project. We also extend our thanks to the Head of the Mechanical Engineering Dept., NIT-Durgapur, and other professors for their invaluable suggestions for completion of our B.E.Project. Last but not the least, we would like to acknowledge our institution NIT, Durgapur for the knowledge it has given to us during our B.E.course and for all the changes it has brought in us.

Page 3: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

B

Department Of Mechanical Engineering National Institute Of Technology

(Deemed University) Durgapur – 713209

I hereby forward the thesis titled “ STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS USING GENETIC ALGORITHM FOR DESIGN ANALYSIS ” prepared under my guidance, in partial fulfillment of the requirement for thr Degree of Bachelor of Engineering (Mechanical) from National Institute of Technology (Deemed University),Durgapur (A.K. Mitra) Sr. Lecturer, Mech. Engg. Dept. NIT, Durgapur COUNTERSIGNED Director, Head of the Department, NIT, Durgapur Mechanical Engineering, NIT, Durgapur

Page 4: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

C

CONTENTS PAGE NO CHAPTER 1

1. 1.INTRODUCTION 1 1. 2.ENGINEERING APPLICATION OF OPTIMIZATION 1 1. 3. OPTIMIZATION CONCEPTS 2 1. 4. OPTIMIZATION ISSUES 4 1. 5. OPTIMIZATION ALGORITHMS 6

1. 6. OBJECTIVE FUNCTION 7 1. 7. CONSIDERATION OF CONSTRAINTS 7

CHAPTER 2 A. GENETIC ALGORITHMS 11 2. A.1.GENETIC ALGORITHMS 11 2. A.2. SOME GENETIC ALGORITHM TERMINOLOGY 11 2. A.3.WORKING PRINCIPLES 13 2. A.4. AN EXAMPLE 16 B. FUZZY –THEORY 18 2.B.1.FUZZY SETS-INTRODUCTION 18 2.B.2. CLASSICAL SETS AND FUZZY SETS 18 2.B.3. MEMBERSHIP FUNCTIONS 19 2.B.4. WHY USE FUZZY SET IN DESIGN 19 C. OPTIMIZATION TECHNIQUES 20 2.C.1.GENETIC ALGORITHM 20 2.C.2. PATTERN SEARCH 20 CHAPTER 3 3.1. UNCONSTRAINT OPTIMIZATION IN MATLAB 22 3.2. CONSTRAINT OPTIMIZATION IN MATLAB 24 3.3. FUZZY CONSTRAINT OPTIMIZATION IN MATLAB 26 CHAPTER 4 4.1. DISCUSSION 31 4.2. CONCLUSION 31 4.3. FUTURE SCOPE OF STUDY 31 BIBLIOGRAPHY 32 APPENDIX APX.1. A FUZZY LOGIC PROBLEM 33 APX.2. MATLAB PROGRAMS 37

Page 5: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

CHAPTER-1

INTRODUCTION TO

OPTIMIZATION

Page 6: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

1

CHAPTER 1 INTRODUCTION TO OPTIMIZATION

1. 1.INTRODUCTION Optimization is the act of obtaining the best result under given circumstances. In design, construction, and maintenance of any engineering system, engineers have to take many technological and managerial decisions at several stages. The ultimate goal of all such decisions is either to minimize the effort required or to maximize the desired benefit. Since the effort required or the benefit desired in any practical situation can be expressed as a function of certain decision variables, optimization can be defined as the process of finding the conditions that give the maximum or minimum value of function. 1. 2. ENGINEERING APPLICATION OF OPTIMIZATION Optimization, in its broad sense, can be applied to solve any engineering problem. Some typical applications from different engineering disciplines are given below:

1. Optimum design of linkages, cams, gears, machine tools, and other mechanical components. 2. Selection of machining conditions in metal-cutting processes for minimum production cost. 3. Design of material handling equipment such as conveyors, trucks, and cranes for minimum cost. 4. Design of pumps, turbines, and hest transfer equipment for maximum efficiency. 5. Optimal production planning, controlling, and scheduling. 6. Inventory control. 7. Allocation of resources or service among several activities to maximize the benefit. 8. Controlling the idle times and queuing in production lines to reduce the costs. 9. Planning the best strategy to obtain maximum profit in the presence of competitor. 10. Optimum design of control systems. 11. Selection of site for an industry. 12. Design of aircraft and aerospace structures for minimum weight. 13. Finding the optimal trajectories of space vehicles. 14. Design of civil engineering structures such as frames, foundations, bridges, towers, chimneys, and

dams for minimum cost. 15. Minimum weight design of structures for earthquake, wind and other types of random loading. 16. Optimal plastic design of structures. 17. Optimal design of electrical machinery such as motors, generators, and transformers. 18. Optimal design of electrical networks. 19. Shortest route taken by a salesperson visiting various cities during the tour. 20. Optimum design of chemical processing equipment and plants. 21. Planning of maintenance and replacement of equipment in reducing operating cost.

Page 7: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

2

1.3. OPTIMIZATION CONCEPTS:- a) LINEARIZATION OF NONLINEAR EQUATIONS:- i. One dimensional equation: Let’s consider the nonlinear equation shown below.

This equation can be “linearized” by assuming a straight line approximation from point a to any point x.

Fig.1-1 The slope of the line in the above figure is defined as

For the case where the first derivative is known, we can estimate the slope by using the first derivative evaluated at point a. We then obtain the following linearized approximation

Where f ’(a) is df/dx evaluated at point “a” .This equation is typically used in trial-and-error solutions where the function and its first derivative are evaluated at a known point a. The value of the function at another point x is then estimated using the above approximation. ii. Two dimensional equations: The above equation can be extended to problems involving more than one dimension, say wind chill that is dependent on both the air temperature (let’s call it x) and wind speed (let’s call it y).

Linearization concepts for a two dimensional function are shown.

Instead of line segment, linearization here requires the use of a plane. Equation for a plane is

Fig.1-2 defined as (A, B, and C are general constants) and therefore

Let’s now use approximation to the tangents at f(a,b) to determine the unknown terms. Consider the intersection of the plane with another vertical plane corresponding to y = b and the intersection with another vertical plane corresponding to x = a. We then obtain

and

Finally, if we approximate the slope terms by the partial derivatives evaluate at point (a,b), we obtain the linearized approximation

Page 8: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

3

b) TAYLOR SERIES EXPANSION:- i. One dimensional problems: Linear approximations to nonlinear equations can be improved by using Taylor series expansion. For one-dimensional problems, the derivation is straightforward. Consider the following integration

where f ’= df/dx has been used.

Let’s now evaluate f ’ in the above equation by considering the integration

where f ’’= df ’/dx has been used. By substituting this result for f ’(x) into the previous equation, our original f(x) is further evaluated as

By repeating this logic for f ’’, we further obtain

This process can be continued to infinity (assuming continuous functions). Graphic interpretation of the concept is shown . ii. Two dimensional problems: Let’s consider a process that is a function of two variables, say x1 and x2,

Fig.1-3 By following a similar procedure given for one dimensional problems, Taylor series expansion around some point a and b can be derived as

Fig. 1-4

Page 9: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

4

1.4. OPTIMIZATION ISSUES:- Numerical approach:- Let’s consider the following one dimensional equation

Maximum and minimum values can be obtained by a trial and inspection approach. The simplest (conceptual) approach is to solve the above equation for different x values. The largest and smallest values of f(x) then correspond to the minimum and maximum values. Clever algorithms have been developed to obtain the solution(s) with a minimum number (ideally) of x values. Analytical approach for one dimensional problems:- For linear systems, an analytical solution is possible and preferred over a trial-and-error approach. A necessary, but insufficient, condition is which for the above problem has n-1 roots as shown . Some of these values are likely minimum values, others are not. Fig. 1-5 The sufficient condition is obtained from the second derivative. Insight here can be obtained by considering points surrounding the roots obtained from f ’(x) = 0. For points close to a, the third order terms in Taylor series can be neglected so we obtain

For f '(a) = 0, we can rearrange terms as

Since the denominator is always positive, the minimum value corresponds to a positive value, and the maximum value corresponds to a negative value. We therefore obtain Local Minimum: f''(xa) > 0 Local Maximum: f''(xa) < 0 Inflection: f''(xa) = 0 Insight into the inflection point can be obtained from the equation which the first derivative and second derivative at x=2 can be evaluated as

Clearly this is not a maximum or minimum value. Imagine it as a local maximum from one direction and a local minimum from the other direction as shown below.

Page 10: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

5

Fig. 1-6 Analytical approach for two dimensional problems:- Let’s consider the first derivative for f(x1,x2). From the chain rule, we obtain

A necessary, but insufficient, condition for minimum or maximum point is df=0 The evaluation is easily done by using the following finite approximation

which is valid for any Δx1 and Δx2 values. If Δx1 and Δx2 are independent, then it is possible to vary them independently. Consider the special cases shown below.

Therefore, for any arbitrary selection of Δx1 and Δx2 , the conditions necessary for df=0 are

The sufficient condition is again obtained from second derivative information. Let’s consider points surrounding point (a,b) where f ’(a,b) = 0. For points close to (a,b), the third order terms in Taylor series can be neglected so we obtain

For f'(a,b) = 0, we can rearrange terms as

For a minimum value, the right hand side is always positive as one moves from (a,b). For a maximum value, the right hand side is always negative as one moves from (a,b). Similar to the one dimensional problems, the following are sufficient conditions for maximum and minimum conditions.

Page 11: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

6

1.5. OPTIMIZATION ALGORITHMS:

These are basically divided into two groups i. Traditional methods ii. Non traditional methods i. Traditional methods:- These are helpful in finding the optimum solution of continuous & differentiable functions these methods are analytical & make use of the techniques of differential calculus. It provides a good understanding of the properties of the minimum & maximum points in a function & how optimization algorithm works iteratively to find the optimum point in a problem. It is classified into 2 categories. 1 .Direct method:-

Bracketing methods Exhaustive search method Bounding phase method Region-elimination method Interval halving method Fibonasi search method Point estimation method Successive quadratic method

2. Gradient method:-

Newton raphson method Bisection method Secant method Cubic search method

ii. Nontraditional optimization algorithm:- These are quite new methods & are becoming popular day by day. Two such algorithms are

Genetic Algorithm Simulated Annealing

GAs versus Traditional Methods

From the above discussion, it can be seen that the GA differs substantially from more traditional search and optimization methods. The four most significant differences are:

GAs search a population of points in parallel, not a single point. GAs do not require derivative information or other auxiliary knowledge; only the objective

function and corresponding fitness levels influence the directions of search. GAs use probabilistic transition rules, not deterministic ones. GAs work on an encoding of the parameter set rather than the parameter set itself (except in where

real-valued individuals are used).

Page 12: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

7

1.6. OBJECTIVE FUNCTION The conventional design procedures aim at finding an acceptable or adequate design, which merely satisfies the functional and other requirements of the problem. In general, there will be more than one acceptable design, and the purpose of optimization is to choose the best one of the many acceptable design, and the purpose of optimization is to choose the best one of many acceptable designs. Thus a criterion has to be chosen for comparing the different alternative and for selecting the best one. The criterion with respect to design is optimized, when expressed as a function of the design variables, is known as the criterion of merit or objective function. The choice of objective function is governed by the nature of problem.

1.7. CONSIDERATION OF CONSTRAINTS:-

DEFINITION: Here we are interested in the solution of an objective function,

Restricted by the following constraints:

, and where c1, c2 and c3 are constants.

Simple example:- Let’s consider the objective function defined as subject to the constraint that The solutions obtained using the unconstraint optimization results of the previous section are

and

Since neither value lies on the ellipse given by the constraint, these are not the correct solutions. a) CONSTRAINT APPROACH FOR TWO-DIMENSIONAL FUNCTIONS Revisit example problem:-Let’s examine the failed solution of the previous section more carefully. The condition for optimal value is defined as which can be rearranged as If x2 is independent of x1 then dx2 /dx1 =0 and For the restricted example problem, x2 is not, however, independent of x1. By using the constraint equation, x2 is functionally related to x1 as

Solution approach:- Let’s seek a solution that does not require the condition of dx2 /dx1 =0 by evaluating the constraint equation in terms of dx1 and dx2. Since dg = 0 (i.e., c is a constant), we obtain

Page 13: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

8

The optimization problem can now be written as the solution for the following two equations:

By multiplying the second equation by

and by subtracting this equation from the first, we obtain We now have three equations to solve for the three unknowns (x1, x2 and 8). The three equations are:

Example problem:- Let’s now apply this approach to the example problem of the previous section. The system of equation is defined as By eliminating l from the first two equations we conclude that By using this result in the third equation, the following four sets of points are obtained

Second derivative information are needed to determine whether these points are maximum, minimum or saddle points. Method of Lagrange multipliers The method of Lagrange multipliers generalizes the above concepts for more than two dimensions and for more than one constraint. The objective is to define a function to minimize that also includes constraint condition information. For a n-dimensional problem with k-constraints, the method of Lagrange multipliers defines a new function as The extreme values are defined from

where df=0 for extremes and dg1 = ... = dgk = 0 because the constraint functions equal constants. Illustrations for five dimensions and two constraints Let’s consider the following function to maximize or minimize

Page 14: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

9

for the constraints: where the number of constraints must be less than number of dimensions. We find the solutions using a function defined as from which we obtain extremal values from

where df=0 at extreme and dg = 0 for g’s equal to a constant. By using the chain rule of calculus, the above function can be evaluated as

The Lagrange's multipliers are selected such that values in the parentheses are zero. We then obtain the following set of equations:

that coupled with the two constraint equations (g1 = c1 and g2 = c2) provides seven equations to solve the seven unknown terms. Example optimization problem with a constraint 1. Problem statement:- For a closed cylindrical tank of a given volume, find the dimensions such that its has the minimum surface area where the tank has a radius of x1 =R and a height of x2 =H.

We know that the surface area is defined as

and the constraint as Set of equations Lagrange's first equation is

Fig .1-7 Lagrange's second equation is and the constraint of fixed volume, or Solution

Page 15: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

10

We can easily solve for 8 by first using the result of the second equation of x1 = 2/8, which allows x2 = 4/8 to be obtained from the first equation. By using both of these results, the constraint of a constant volume can be evaluated as from which l is obtained as

The radius is then easily obtained from the second equation as

and height from the first equation as

2. Problem statement:- Minimize f (X) = 6x1

2 + 4x1x2 +3x22

subject to h (X) = x1 +x2 -5 = 0 using the ALM method. SOLUTION: The augmented Lagrangian function can be constructed as A(X,λ) = 6x1

2 + 4x1x2 +3x22 + λ ( x1 +x2 -5 ) + rk( x1 +x2 -5 ) 2

For the stationary point of A , the necessary conditions , δA/δxi = 0 ,i = 1,2. yield x1(12+2rk) + x2 (4+2rk) = 10rk - λ x1(4 +2rk) + x2 (6+2rk) = 10rk - λ From the equations we get x1 = (-90rk

2 + 9rk λ - 6 λ +60rk) / ((14-5rk)(12+2rk)) x2 = (20rk - 2λ)/(14 – 5rk) Let the value of rk be fixed at 1 and select a value of λ (1) = 0. This gives x*(1) = -5/21 , x*(2) = 20/9 with h=(-5/21)+( 20/9) -5 = -3.01587 We set these values as the initial values and find out the optimum using following program function sa() la=0; rk=1; h=-3.01587; while(h~=0) x1=(-90*((rk)^2)+9*rk*la-6*la+60*rk)/((14-5*rk)*(12+2*rk)); x2=(20*rk-2*la)/(14-5*rk); la=la+2*rk*h; h=x1+x2-5; end ans=[x1 x2] The output of the program: ans = -0.6000 5.6000 i.e. x1*= -0.6000 x2*= 5.6000 ......................................................................AAANNNSSS f (X)min = 6x1

2 + 4x1x2 +3x22 = 82.8000 ......................................................................AAANNNSSS

Page 16: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

CHAPTER-2

BASIC THEORY

Page 17: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

11

CHAPTER 2 BASIC THEORY

A. GENETIC ALGORITHMS 2. A.1.GENETIC ALGORITHMS The GA is a stochastic global search method that mimics the metaphor of natural biological evolution. GAs operate on a population of potential solutions applying the principle of survival of the fittest to produce (hopefully) better and better approximations to a solution. At each generation, a new set of approximations is created by the process of selecting individuals according to their level of fitness in the problem domain and breeding them together using operators borrowed from natural genetics. This process leads to the evolution of populations of individuals that are better suited to their environment than the individuals that they were created from, just as in natural adaptation.

2. A.2. SOME GENETIC ALGORITHM TERMINOLOGY:

i. Design Variables: - A design problem usually involves many design parameters, of which some are highly sensitive to proper working of the design. These are called design or decision variables

Xi, i=1,2,...,n

So design vector, X={x1, x2,....,xn}

Certain quantities are usually fixed at the outset & are called preassigned parameters.

ii. Constraints:-The constraints represent some functional relationships among the design variables & other design parameters satisfying certain physical phenomenon & certain resource limitations. Constraints that represent limitations on the behavior or performance of the systems are termed behavior or functional constraints. Constraints that represent physical limitations on design variables such as availability, fabricability, & transportability are known as geometric or side constraints.

eg.:- in mechanical & civil Engg. problems , the constraints are formulated to satisfy stress & deflection limitations.

iii. Fitness Functions:-The fitness function is the function you want to optimize. For standard optimization algorithms, this is known as the objective function. GAs are usually suitable for solving maximizations problems. Minimization problems are usually transformed to maximization problems by some suitable transformations.

Certain genetic operations require that function be non negative , although certain operators do not have this requirement. Consider the following transformations

F(X) = f(X) for maximization problem

F(X) = 1/ f(X) for minimization problem, if f(X)

F(X) = 1/ (1+f(X)), if f(X)=0

Page 18: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

12

iv. Individuals:-

An individual is any point to which you can apply the fitness function. The value of the fitness function for an individual is its score. For example, if the fitness function is

the vector (2, 3, 1), whose length is the number of variables in the problem, is an

individual. The score of the individual (2, 3, 1) is f(2, -3, 1) = 51.

An individual is sometimes referred to as a genome and the vector entries of an individual as genes.

v. Populations and Generations:-

A population is an array of individuals. For example, if the size of the population is 100 and the number of variables in the fitness function is 3, you represent the population by a 100-by-3 matrix. The same individual can appear more than once in the population. For example, the individual (2, 3, 1) can appear in more than one row of the array.

At each iteration, the genetic algorithm performs a series of computations on the current population to produce a new population. Each successive population is called a new generation.

vi. Diversity:-

Diversity refers to the average distance between individuals in a population. A population has high diversity if the average distance is large; otherwise, it has low diversity. In the following figure, the population on the left has high diversity, while the population on the right has low diversity.

Diversity is essential to the genetic algorithm because it enables the algorithm to search a larger region of the space.

vii. Fitness Values and Best Fitness Values:- The fitness value of an individual is the value of the fitness function for that individual. Because the toolbox finds the minimum of the fitness function, the best fitness value for a population is the smallest fitness value for any individual in the population.

viii. Parents and Children:- To create the next generation, the genetic algorithm selects certain individuals in the current population, called parents, and uses them to create individuals in the next generation, called children. Typically, the algorithm is more likely to select parents that have better fitness values.

Page 19: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

13

2. A.3.WORKING PRINCIPLES Unlike many methods, GAs use probabilistic transition rules to guide their search. The method is not a simple random search or is not a decision making tool depending on the simple probability act just like a toss of a coin. To demonstrate the working principles of GAs, the following maximization problem is considered

Although a maximization problem is considered here, a minimization problem can also be handled using GAs. The working of GAs is completed by performing the following tasks: a) Coding: To implement GAs in the solution of the above maximization problem, variable xi's are first coded in some string structures. Variable xi's are coded by binary representation having 0's and 1's. The length of the coded string is usually determined according to the desired solution accuracy. For example, if four bits are used to code each variable in a two variable function optimization problem, the strings (0000 , 0000) and (1111, 1111) would represent the points ( x1

(L), x2(L) )T ( x1

(U), x2(U) )T respectively,

because the substring (0000) and (1111) have the minimum and miximum decoded values. Any other eight bit string can be found to represent a point in the search space according to a fixed mapping rule. Usually, the following linear mapping rule is used:

In the above equation, the variable xi is coded in a substring Si of length li. The decoded value of a binary substring Si is calculated as

and the string S is represented as (Sl-1 Sl-2.... S2S1So). For example, a four bit string (0 111) has a decoded value equal to ((1) 2o + (1) 21 + (1) 22 + (0) 23) or 7. It is worthwhile to mention here that with four bits to code each variable, there are only 24 or 16 distinct substrings possible, because each bit position can take a value either 0 or 1. The accuracy that can be obtained with a four bit coding is only approximately 1/16th of the search space. But as the string length is increased by one, the obtainable increases exponentially to 1/32th of the search space. b) Initialization: Referring to the maximization problem a set of binary strings representing the variable xi are generated at random to make the initial population. The string in GA correponds to ' "chromosome" and bits in a string refers "genes" in natural genetics. c) Genetic Operators: With an initial population of individuals of various fitness values, the operators of GAs begin to generate a new and improved population from the old one. A simple genetic algorithm (SGA) consists of three basic operations: reproduction, crossover and mutation. d) Reproduction: Reproduction is usually the first operator applied on a population. Reproduction selects strings according to the fitness values in a population and forms a mating pool. Selecting strings according to their fitness values means that string with a higher value have a higher probability of contributing one or more off springs to the next generation. The i-th string in the population is selected with a probability proportional to Fi. Since the population size is usually kept fixed in a simple GA, the sum of the probability of each string being selected for the mating pool must be one. Therefore, the probability for selecting the i-th string is

Page 20: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

14

where, n is the population size. One way to implement this selection scheme is to imagine a roulette-wheel with its circumference marked for each string proportionate to the string's fitness. The roulette-wheel is spun n times, each time selecting an instance of the string chosen by the roulette-wheel pointer. Since the circumference of the wheel is marked according to a string's fitness, the roulette-wheel

mechanism is expected to make copies of the i-th string in the mating pool. The average fitness of the population is calculated as,

Using the fitness value Fi of all strings, the probability of selecting a string Pi can be calculated. Therefore, the cumulative probability (Pi) of each string being copied can be calculated by adding the individual probabilities from the top of the list. Fig. 2-1 e) Crossover: In reproduction, good strings in a population are probabilistically assigned a larger number of copies and a mating pool is formed. But no new strings are formed in the reproduction phase. In the crossover operator, new strings are created by exchanging information among strings of the mating pool.. The two strings participating in the crossover operation are known as parent strings and the resulting strings are known as children strings. It can be expected that good substrings from parent strings can be combined to form a better child string, if an appropriate site is chosen. Since the knowledge of an appropriate site is usually not known beforehand, a random site is often chosen. With a random site, the children strings produced may or may not have a combination of good substrings from parent strings, depending on the position of crossover point.

Page 21: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

15

Fig. 2-2-A Fig. 2-2-B f) Mutation : A crossover operator is mainly responsible for the search of new strings, even though a mutation operator is also used for this purpose. The mutation operator changes 1 to 0 and vice versa in a bit position with a small mutation probability, pm. Changing bit with probability pm can be simulated by choosing a number between 0 to 1 at random. If the random number is smaller than pm, the randomly selected bit is altered; otherwise the bit is kept unchanged. The need for mutation is to create a point in the neighbourhood of the current point, thereby achieving a local search around the current solution. The mutation is also used to maintain diversity in the population. For example, consider the following population having four eight-bit strings: 0 1 1 0 1 1 0 0 0 0 1 0 0 0 1 1 0 1 0 1 1 1 1 1 0 1 1 1 0 0 0 0 Notice that all four strings have a 0 in the left-most position. If the true optimum solution requires 1 in that position, then neither reproduction nor crossover operator described above will be able to create 1 in that position. The inclusion of mutation introduces some probability of turning 0 into 1.

Page 22: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

16

2. A.4. AN EXAMPLE DESIGN OF SIMPLE CAN BY GA:- A cylindrical can is considered to have only two design parameters- diameter d and height h. Let us consider that the can needs to have a volume of at least 300ml and the objective of the design is to minimize the cost of can material. Nonlinear objective function f(d,h)=c (π d2/2 + π d h) ,

Subject to v (d,h)=( π d2/4) ≥ 300 Variable bounds dmin ≤ d ≤ dmax and hmin ≤ h ≤ hmax Step 1 In order to get optimal parameter values of d and h which satisfy the constraint g4 and minimize f we first need to code the parameter values in binary strings. Assume five bits are representing each of the parameters. So the overall string length is equal to 10. The following string represents a can of diameter 8 cm and height 10 cm.

Step 2 In the above representation, the lower and upper values of both parameters are considered to be zero and 31. So mapping function is not required to use to get the exact value as minimum (00000) and maximum value (11111) represent 0 and 31 respectively which satisfy the lower and upper bounds considered for d and h parameters. But Gas can be assigned to use any integer or non-integer values just by changing the string length, lower and upper bounds.

In the above example L = 5, ximin = 0, ximax = 31 Step 3 Assigning fitness to a solution The fitness is made equal to the objective function value. For example, the fitness of above can F (S) = =23 (assuming C = .0654) Since the objective of the optimization is to maximize the objective function, it is to be noted that a solution with a smaller fitness value is better compared to another solution.

Figure .2-3. A random population of 6 cans This fitness (penalized cost ) of each can is marked on the can

Page 23: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

17

Step 4 Reproduction operator: The primary objective of the reproduction operator is to emphasize good solutions and eliminate bad solutions in a population, while keeping the population size constant. This is achieved by performing the following tasks: (1) Identifying good (usually above-average) solution in a population . (2) Making multiple-copies of good solutions. (3) Eliminating bad solutions from the population so that multiple copies of good solutions can be placed in the population. Some common methods of achieve the above task are tournament selection- proportionate selection, ranking selection and others. In the following, we illustrate the binary tournament selection. As the name suggests, tournaments are played between two solutions and the better solution is chosen and placed in a population slot. Two other solutions are picked again and another population slot is filled up with the better solution. If done systematically, each solution can be made to participate in exactly two tournaments. The best solution in a population will win both times, thereby making two copies of it in the new population. Similarly, the worst solution will lose in both tournaments and will be eliminated from the population. Figure.2-4.Tournaments played between six population members are Step 5 shown. Solutions Within the dashed box form the mating pool.

Like the reproduction operator, there exist a number of methods for crossover operations. Here a single point crossover operation is illustrating for the CAN problem. In fig. reproduction operator selects two strings and the third site along the string length in chosen at random and contents of the right side of this cross site are swapped between the two strings. The process creates two new strings.

Figure2-5. An illustration of the single point crossover operator.

In order to preserve some good strings selected during the reproduction operator, not all strings in the population are used in crossover. If a crossover probability of Pc is used then 100 Pc% strings in the population are used in the crossover operation and (100 (1- Pc) % of the population are simply copied to the new population. Step 6 The mutation operator changes 1 to a 0 and vice versa with a small mutation probability Pm. The need for mutation is to keep diversity in the population. Fig. 5 shows how a string obtained after reproduction and crossover operator has been mutated to another string representing a slightly different CAN.

Figure.2-6. An illustration of the mutation operation.

Page 24: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

18

B. FUZZY –THEORY 2.B.1.FUZZY SETS-INTRODUCTION : Fuzzy sets are generalized sets introduced by Professor Zadeh in 1965 as a mathematical way to represent and deal with vagueness in everyday life [88]. To paraphrase Zadeh [89], we have been developing a wealth of methods to deal with mechanistic systems (e.g., systems governed by differential equations) but there is a lack of methods for humanistic systems. Our natural tendency would be to still use the same good and proven methods we already developed, but they might not work as well for this other class of systems. Indeed, Zadeh informally states what he calls the principle of incompatibility:

“As the complexity of a system increases, our ability to make precise and yet significant statements about its behavior diminishes until a threshold is reached beyond which

precision and significance (or relevance) become almost mutually exclusive Characteristics.”

2.B.2. CLASSICAL SETS AND FUZZY SETS:

CLASSICAL SET : A classical set is a container that wholly includes or wholly excludes any given element. For example, the set of days of the week unquestionably includes Monday, Thursday, and Saturday. It just as unquestionably excludes butter, liberty, and dorsal fins, and so on.

FUZZY SET :

“In fuzzy logic, the truth of any statement becomes a matter of degree.”

True has numerical value of 1 and false the numerical value of 0, we're saying that fuzzy logic also permits in-between values like 0.2 and 0.7453.

Take the example of “Long Distance”.If we say 500 km and more is long distance then according to crisp set theory 499.999 is not long distance although the difference is only 1 mitre.Long distace can be well judged by the given fuzzy set.

Figure- 2-7 .Membership values of range

Page 25: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

19

2.B.3. Membership Functions:- A membership function (MF) is a curve that defines how each point in the input space is mapped to a membership value (or degree of membership) between 0 and 1. The input space is sometimes referred to as the universe of discourse.

One of the most commonly used examples of a fuzzy set is the set of tall people. In this

case the universe of discourse is all potential heights, say from 3 feet to 9 feet, and the word tall would correspond to a curve that defines the degree to which any person is tall. Let X be a space of objects and x be a generic

element of X. A classical set A, A ε X is defined as a collection of elements or objects x ε X, such that each element (x) can either belong or not to the set A. By defining a characteristic (or membership) function for each element x in X, we can represent a classical set A by a set of ordered pairs(x,0)or

(x,1),which indicates xε A or not x ε A, respectively. Unlike a conventional set, a fuzzy set expresses the degree to which an element belongs to a set. Hence the membership function of a fuzzy set is allowed to have values between 0 and 1 that denote the degree of membership of an element in the given set.

An example: In the figure the variable is age and the .In this example we want to describe set of young people. More formally we can denote B= {set of young people}

Since –in general age starts at 0 the lower range of this set ought to be clear. The upper range, on the other hand, is rather hard to define. As a first attempt we set the upper range to, say 20 years. Therefore we get B as a crisp interval, namely B= [10 20]

Now the question arises: why is somebody on his 20th birthday young and right on the next day not young? Obviously this is a structural problem, for if we move the upper bound of the range of 20 to an

arbitrary point we can pose the same question.A more natural way to construct the set B would be to relax the strict separation between young and not young .We will do this by allowing not only the(crisp) decision YES he/she is in the set of young people or NO he/she is not in the set of young people but more flexible phrases like Well, he/she belongs a little bit more to the set of young people or NO, he/she belongs nearly not to the set f young people.

2.B.4. WHY USE FUZZY SET IN DESIGN: Engineering design, the process of creating a new device to perform a desired function, intrinsically involves imprecision. This imprecision arises from the nature of the design problem, where one or more concepts are refined into a final design. At the concept stage, the designs are only vaguely, or imprecisely, described. Once the design process is complete, the design is described sufficiently precisely that it can be manufactured. During the process of the refinement of a concept into a finished design, most information describing the design will be imprecise to some degree, reflecting the degree to which the designer has made final design decisions and refinements. To facilitate solving engineering design problems, and to assist design refinement, advanced design methods must represent and manipulate this intrinsic design imprecision.

Figure .2-8. Membership Values of different Heights.

Figure .2-9.

Page 26: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

20

C. OPTIMIZATION TECHNIQUES 2.C.1. GENETIC ALGORITHM : For the solution of optimization problems we have used “GENETIC ALGORITH AND DIRECT SEARCH TOOLBOX” in which we have

2. GENETIC ALGORITHM TOOL and 3. PATTERNSEARCH TOOL.

For the solution of unconstrained optimization we can use GENETIC ALGORITH TOOL. We can open the tool just giving the command >> gatool and then enter the name of the fitness function (as ‘@name of function’) and different options . We can also find the optimization of a function by defining the objective function in an m-file and then calling ‘ga’ as >>[x, fval] = ga(fitnessfun, nvars, options) where,

x :- gives optimum value of the variables in the objective function. fval: - gives min. or max. value of the function fitnessfcn: - Fitness function nvars: - Number of independent variables for the fitness function options :- Options structure created with gaoptimset

GAOPTIMSET Create a genetic algorithm options structure. 2.C.2. PATTERN SEARCH: A pattern search algorithm computes a sequence of points that get closer and closer to the optimal point. At each step, the algorithm searches a set of points, called a mesh, around the current point -- the point computed at the previous step of the algorithm. The algorithm forms the mesh by adding the current point to a scalar multiple of a fixed set of vectors called a pattern. If the algorithm finds a point in the mesh that improves the objective function at the current point, the new point becomes the current point at the next step of the algorithm. Some Pattern search terminology: Patterns:A pattern is a collection of vectors that the algorithm uses to determine which points to search at each iteration. For example, if there are two independent variables in the optimization problem, the default pattern consists of the following vectors. v1 = [1 0] v2 = [0 1] v3 = [-1 0] v4 = [0 -1] The following figure shows these vectors. Fig. 2-10 Meshes: At each step, the pattern search algorithm searches a set of points, called a mesh, for a point that improves the objective function. The algorithm forms the mesh by Multiplying the pattern vectors by a scalar, called the mesh size Adding the resulting vectors to the current point -- the point with the best objective function value found at the previous step

Page 27: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

21

For example, suppose that The current point is [1.6 3.4]. The pattern consists of the vectors v1 = [1 0] v2 = [0 1] v3 = [-1 0] v4 = [0 -1] The current mesh size is 4. The algorithm multiplies the pattern vectors by 4 and adds them to the current point to obtain the following mesh. [1.6 3.4] + 4*[1 0] = [5.6 3.4] [1.6 3.4] + 4*[0 1] = [1.6 7.4] [1.6 3.4] + 4*[-1 0] = [-2.4 3.4] [1.6 3.4] + 4*[0 -1] = [1.6 -0.6] The pattern vector that produces a mesh point is called its direction Polling:At each step, the algorithm polls the points in the current mesh by computing their objective function values. When option complete poll has the default setting Off, the algorithm stops polling the mesh points as soon as it finds a point whose objective function value is less than that of the current point. If this occurs, the poll is called successful and the point it finds becomes the current point at the next iteration. Note that the algorithm only computes the mesh points and their objective function values up to the point at which it stops the poll. If the algorithm fails to find a point that improves the objective function, the poll is called unsuccessful and the current point stays the same at the next iteration. For the solution of constrained optimization we can use PATTERNSEARCH TOOL . We can open the tool just giving the command >> psearchtool and then enter the name of the fitness function (as ‘@name of function’) and different options . We can also find the optimization of a function by defining the objective function in an m-file and then calling ‘patternsearch’ as >> [x fval] = patternsearch(@objfun, x0, A, b Aeq, beq, lb, ub) where,

x :- gives optimum value of the variables in the objective function. fval: - gives min. or max. value of the function objfun: - Objective function A is a matrix and b is vector that represent inequality constraints of the form Ax < b Aeq is a matrix and beq is a vector that represent equality constraints of the Aeq x = beq lb and ub are vectors representing bound constraints of the form lb < x , x > ub

In this project we have called GENETIC ALGORITHM and PATTERN SEARCH by writing programs.

Page 28: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

CHAPTER-3

PROBLEMS AND RESULTS

Page 29: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

22

CHAPTER -3 PROBLEM AND RESULTS

3.1. UNCONSTRAINT OPTIMIZATION IN MATLAB: Problem. Two uniform bars are connected by pins at A and B supported at A. A horizontal force P acts at C.Knowing the force, length of bars and its weight determine the equilibrium configuration of the system if friction at all joints are neglected. P =2 W1=2 W2=2

l1 = 2 l2 = 2 The total potential for the two bar pendulum is written as Π= -P[(l1sinθ1+l2sinθ2)] –0.5W1l1cosθ1-W2[0.5l2cosθ2+l1cosθ1] Substituting the values for P,W1,W2 , and lengths as 2 we get,

Π( θ1 ,θ2 ) = −4sin θ1−6cos θ1−4 sinθ2 − 2cos θ2

Equilibrium configuration is the one makes Π a minimum

THEORETICAL SOLUTION: δ Π=0, for Π to be maximum or minimum. δ Π= ( δ Π /δθ1)δθ1 + ( δ Π /δθ2)δθ2 δθ1,δθ2 are arbitrary. Therefore we get, ( δ Π /δθ1)= 4cos θ1−6sinθ1=0 ( δ Π /δθ2)= 4cos θ2−6sinθ2=0 From equations tan θ1=(2/3) ,θ1=33.7ο(0.5882 radians) tan θ2=2 , θ2=63.43ο(1.107 radians) Π = −11.68 Now we will solve the problem using GA PROGRAM in Matlab Objective function definition: function s=unc(x) s=-4*sin(x(1))-6*cos(x(1))-4*sin(x(2))-2*cos(x(2)); GA Program: function [X,FVAL,REASON,OUTPUT,POPULATION,SCORES] = unc_solution fitnessFunction = @unc; nvars = 2 ; options = gaoptimset; options = gaoptimset(options,'MutationFcn' ,{ @mutationgaussian 1 1 }); options = gaoptimset(options,'Display' ,'off'); options = gaoptimset(options,'PlotFcns' ,{ @gaplotbestf @gaplotbestindiv }); rand('state',[0.97725 ; 0.10082 ; 0.22781 ; 0.62491 ; 0.86787 ; 0.90765 ; 0.51905 ; 0.15366 ; 0.44839 ; 0.81072 ; 0.40625 ; 0.094482 ; 0.29847 ; 0.15819 ; 0.60467 ; 0.0132 ; 0.86486 ; 0.95853 ; 0.91299 ; 0.34305 ; 0.10979 ; 0.56614 ; 0.36617 ; 0.073297 ; 0.6786 ; 0.31389 ; 0.61353 ; 0.45214 ; 0.70456 ; 0.90829 ; 0.46752 ; 0.21242 ; 0 ; 1.7764e-015 ; 9.3849e-007 ]); randn('state',[851004760 ; 1448593782 ]); [X,FVAL,REASON,OUTPUT,POPULATION,SCORES] = ga(fitnessFunction,nvars,options);

Fig. 3-1

Page 30: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

23

THE OUTPUT OF THE PROGRAM: ans = 0.58879 1.10698 Πmin=-11.6831 θ1=0.58879 , θ2=1.10698

Fig. 3-2 (A & B)

Page 31: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

24

3.2. CONSTRAINT OPTIMIZATION IN MATLAB: Problem: Design a uniform colunm of tubular section to carry a compressive load P=2500 kgf for minimum cost .The column is made up of a material that has a yield stress(σy) of 500kgf/cm2, modulus of elasticity(E)=0.85X106,r=0.0025kg/cm3.The lenth of the collumn(L)=250 cm. Design parameters are: Mean diameter f the collumn(d)=x(1),Thickness(t)=x(2).The cost of the collumn can be taken as 5W+2d. The constraints are: induced stress=σi =(P/πdt)=(2500/πx(1)x(2)) < 500(=σy) induced stress=σi < bukcling stress = (π2ΕΙ/l2)X(1/ π dt)

Calculated I=( π/8) x (1) x(2) { x(1)2+x(2)2} ... g1(x) ={2500/πx(1)x(2)}-500 < 0 ie. x(1)x(2) >1.593 ie. 1.593- x(1)x(2) < 0

... g2(x) ={ 2500/πx(1)x(2)}- [{π2X0.85 X 106(x(1)2+x(2)2)}/8 X2502]< 0

ie. x(1)x(2) X{ x(1)2+x(2)2} > 47.3 ie. 47.3- x(1)x(2) X{ x(1)2+x(2)2} < 0 Again the side constraints are: 2< d< 14 ; 0.2 < t< 0.8;g3(x) = -x(1)+2.0 < 0; g4(x) = x(1) -14.0 < 0; g5(x) = -x(2) +0.2 < 0; g6(x) = x(2) – 0.8 < 0 Let us transform x(1)x(2) = a(1) ; . x(1)x(2) X{ x(1)2+x(2)2}= a(2) Therefore the constraints become: a(1) > 1.593 ; a(2) > 47.3; 0.4< a(1) < 11.2 ; 1.616 < a(2) < 2202.368

Figure. 3-3 .Tubular column under compression

Page 32: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

25

Solution: We will use Pattern search with Search with search process Genetic Algorithm MATLAB function: function a=tube(a) a=9.82*a(1)+2*0.5*(sqrt((a(2)/a(1))+2*a(1))+sqrt((a(2)/a(1))-2*a(1))); end Matlab program function [X,FVAL,EXITFLAG,OUTPUT] = tube_pasearcc objectiveFunction = @tube; X0 = [1 50 ]; Aineq = [-1 0 ; 0 -1 ]; Bineq = [-1.593 ; -47.3 ]; Aeq = []; Beq = []; %Equality Constraints LB = [0.4 ; 1.616 ];UB = [11.2 ; 2202 ]; options = psoptimset; options = psoptimset(options,'MeshAccelerator' ,'on'); options = psoptimset(options,'PollMethod' ,'positivebasisnp1'); options = psoptimset(options,'CompletePoll' ,'on'); options = psoptimset(options,'SearchMethod' ,{ @searchga [] [] }); options = psoptimset(options,'CompleteSearch' ,'on'); options = psoptimset(options,'Display' ,'iter'); options = psoptimset(options,'PlotFcns' ,{ @psplotbestf @psplotmeshsize @psplotfuncount @psplotbestx }); [X,FVAL,EXITFLAG,OUTPUT] = patternsearch(objectiveFunction,X0,Aineq,Bineq,Aeq,Beq,LB,UB,options); The output of the program: Iter f-count f(x) MeshSize Method 0 1 26.84 1 Start iterations Optimization terminated: maximum number of generations exceeded. 1 204 26.73 2 Successful Poll .... .... ........ .... .............. 37 287 26.53 7.629e-006 Successful Poll 38 289 26.53 7.629e-008 Refine Mesh\Rotate Optimization terminated: current mesh size 7.6294e-008 is less than 'TolMesh'. ans = 1.5930 47.3000 d*=x1*=0.5*(sqrt((a(2)/a(1))+2*a(1)) +sqrt((a(2)/a(1))-2*a(1))) = 5.4412 cm. t*= x2*= 1.5930/ x1 = 0.2928 cm. Minimum cost fmin=9.82*a(1)+2*0.5*(sqrt((a(2)/a(1))+2*a(1))+sqrt((a(2)/a(1))-2*a(1))) = 26.5257

Fig. 3-4(A,B,C,D) Genetic Algorithm in Matlab

Page 33: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

26

3.3. FUZZY CONSTRAINT OPTIMIZATION IN MATLAB:- We will solve the same problem with fuzzy constraint and fuzzy bounds for thye two variables. Now if x(1) and x(2) are fuzzy variables then we choose the membership values(μ) of x(1) and x(2) as

1 if 2< d< 14 μ(x(1))= (d-1)/1 if 1< d< 2 (15-d)/1 if 14< d< 15 0 if 1>d and d >15

1 if 0.2< t< 0.8 μ(x(2))= (t-0.1)/0.1 if 0.1< t< 0.2 (0.9-d)/0.1if 0.8< t< 0.9 0 if t < 0.1& t >0.9

Now let us take the yield stress(σy) as a fuzzy variable as 1 if σ y < 500 μ(σ)= 0 if σy > 600

(600-σy)/100 if 500< σy<600

Fig. 3-5. Membership of x(1)

Fig. 3-6. Membership of x(2)

Fig. 3-7. Membership of σ y

Page 34: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

27

Now for the transform x(1)Xx(2) = a(1) ; . x(1) Xx(2) X{ x(1)2+x(2)2}= a(2)

Then we get the membership values of a(1) and a(2) as:- 1 if 0.4< a(1)< 11.2 μ(a(1))= (a(1)-0.1)/(0.4-0.1) if 0.1< a(1)< 0.4 (13.5-a(1))/(13.5-11.2) if 11.2< a(1)< 13.5 0 0 otherwise

1 if 1.161< a(2)< 2202.368 μ(a(2))= (a(2)-0.101)/(1.616-0.101) if 0.101< a(2)< 1.616 (3048.435-a(1))/(3048.435-2202.368) if 2202.368< a(2)< 3048.435

0 if 0.101>a(2) and a(2) >3048.435

Now for calculation of upper

Fig. 3-8. Membership of a(1)

Fig.3-9. Membership of a(2)

Page 35: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

28

bounds ,lower bounds of a(1) & a(2) and yield stress for alfa cut. α=0.00,0.05,0.10,0.15,0.20,0.25,0.30,0.35,0.40,0.45,0.50,0.55,0.60,0.65,0.70, 0.75,0.80,0.85,0.90,0.95,1.00. Program:-

function q=calcu(up,lo,m) for i=1:1:(m+1) q(i)=lo+((up-lo)/m)*(i-1);end

for lowest value of lower bound of a1=0.1,highest value of lower bound=0.4 >>calcu(0.4,0.1,20) Lower bounds of a1= 0.1000, 0.1150, 0.1300, 0.1450, 0.1600, 0.1750, 0.1900, 0.2050, 0.2200, 0.2350, 0.2500, 0.2650, 0.2800, 0.2950, 0.3100, 0.3250, 0.3400, 0.3550, 0.3700, 0.3850, 0.4000

for lowest value of lower bound of a2=0.101 , highest value of lower bound =1.616 >>calcu(1.616,0.101,20) Lower bounds of a2 = 0.1010, 0.1768, 0.2525, 0.3283, 0.4040, 0.4798, 0.5555, 0.6313, 0.7070, 0.7828, 0.8585, 0.9343, 1.0100, 1.0858, 1.1615, 1.2373, 1.3130, 1.3888, 1.4645, 1.5403, 1.6160

function q=calcu1(up,lo,m) for i=1:1:(m+1) q(i)=up-((up-lo)/m)*(i-1);end

for lowest value of upper bound of a1=11.2,highest value of lower bound =13.5 >>calcu1(13.5,11.2,20) upper bound of a1= 13.5000, 13.3850, 13.2700, 13.1550, 13.0400, 12.9250, 12.8100, 12.6950, 12.5800, 12.4650, 12.3500, 12.2350, 12.1200, 12.0050, 11.8900, 11.7750, 11.6600, 11.5450, 11.4300, 11.3150, 11.2000

for lowest value of upper bound of a2=2202,highest value of lower bound =3048.4

>>calcu1(3048.435,2202,20) upper bound of a2= 3048.4, 3006.1, 2963.8, 2921.5, 2879.1, 2836.8, 2794.5, 2752.2, 2709.9, 2667.5, 2625.2, 2582.9, 2540.6, 2498.3, 2455.9, 2413.6, 2371.3, 2329.0, 2286.6, 2244.3 ,2202.0 For the constraint a1> b Calculation of value of the constraint The lowest value of b= 1.3488 ,The highest value of b= 1.59161 >>calcu(1.59155,1.32629,20) Values of b= 1.3263, 1.3396, 1.3528, 1.3661, 1.3793, 1.3926, 1.4059, 1.4191,1.4324, 1.4457, 1.4589, 1.4722, 1.4854, 1.4987, 1.5120, 1.5252, 1.5385, 1.5518, 1.5650,1.5783, 1.5916 RUN PATTERNSEARCH:-

Page 36: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

29

Now we run the patternsearch with genetic algorithm as search process for the 21 set of values >>tube_pasearcc(cons(1),loai(1),loa2(1),up1(1),up2(1)) >> tube_pasearcc(cons(2),loai(2),loa2(2),up1(2),up2(2)) >>_ _ _ _ _ _ _ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ _ _ _ _ _ _ >> tube_pasearcc(cons(21),loai(21),loa2(21),up1(21),up2(21))

We get the optimum values for minimum cost . We got the optimal values of a(1),a(2) from which we have calculated optimal values of x(1) and x(2) using MATLAB as:

Now we present the complete results in the table:

>>for i=1:1:21 x1(i)=0.5*(sqrt((a(i,2)/a(i,1))+ 2*a(i,1))+sqrt((a(i,2)/a(i,1))-2*a(i,1))) end

>>for i=1:1:21 x2(i)=a(i,1)/x1(i) end

Table.3-1.Results of optimization with different values of constraints for α - cut

Serial No.

α= a(1) a(2) x1 x2 Cost Acceptance value of induced stress

1. 0.00 1.3263 47.3000 5.9677 0.2222 24.9569 0.0000 2. 0.05 1.3396 47.3000 5.9379 0.2256 25.0306 0.0596 3. 0.10 1.3528 50.0643 6.0793 0.2225 25.4416 0.1176 4. 0.15 1.3661 50.0612 6.0493 0.2258 25.5121 0.1748 5. 0.20 1.3794 47.3000 5.8510 0.2358 25.2503 0.231 6. 0.25 1.3926 50.0607 5.9911 0.2324 25.6549 0.2857 7. 0.30 1.4059 47.3000 5.7953 0.2426 25.3969 0.3397 8. 0.35 1.4192 47.3000 5.7678 0.2461 25.4747 0.3928 9. 0.40 1.4324 47.3000 5.7410 0.2495 25.5480 0.4445 10. 0.45 1.4457 50.0653 5.8796 0.2459 25.9569 0.4956 11. 0.50 1.4590 47.3000 5.6880 0.2565 25.7031 0.5458 12. 0.55 1.4722 50.0684 5.8263 0.2527 26.1106 0.5947 13. 0.60 1.4855 47.3000 5.6366 0.2635 25.8583 0.6431 14. 0.65 1.4987 50.0724 5.7744 0.2595 26.2636 0.6902 15. 0.70 1.5120 47.3000 5.5866 0.2706 26.0184 0.7369 16. 0.75 1.5253 50.0775 5.7237 0.2665 26.4265 0.7828 17. 0.80 1.5385 50.0806 5.6990 0.2700 26.5083 0.8276 18. 0.85 1.5518 47.3000 5.5138 0.2814 26.2641 0.8719 19. 0.90 1.5651 47.3000 5.4900 0.2851 26.3503 0.9155 20. 0.95 1.5783 47.3000 5.4668 0.2887 26.4322 0.958 21. 1.00 1.5916 47.3000 5.4436 0.2924 26.5178 1.000

Page 37: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

30

Now we have plotted the Minimum cost for different Alfa cut values and acceptance value of the induced stresses.

fig.3-10. Alfa cut versus minimum cost.

As example for the third set of results (α=0.10) the induced stress (σy ) =2500/ (π a(1))

=2500/( π X1.3528)= 588.24

Now the acceptance value of the result =(600-σy )/100 = (600-σy )/100 = (600−588.24)/100 = 00.1176

fig.3-11. Acceptance value of induced-stress versus minimum cost.

So, without fuzziness we got minimum cost =26.5257 with d=5.4412 cm. ,t=0.2928 cm.

whereas in case of fuzzified variables and fuzzy constraints,

minimum cost= 24.9569 with d=5.9677 cm. ,t=0.2222 cm

Alfa cut vs Minimum cost

24.8

25

25.2

25.4

25.6

25.8

26

26.2

26.4

26.6

0 0.2 0.4 0.6 0.8 1 1.2

Alfa cut

Min

imum

cos

t

Acceptance value of Induced- stress vs cost

24.8

25

25.2

25.4

25.6

25.8

26

26.2

26.4

26.6

0 0.2 0.4 0.6 0.8 1 1.2

Acceptance value of induced-stress

cost

Page 38: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

CHAPTER-4

DISCUSSION ,CONCLUSION AND FUTURE SCOPE

Page 39: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

31

CHAPTER -4 Discussion , Conclusion and Future scope

4.1. Discussion: OPTIMIZATION WITHOUT CONSTRAINTS: We start our discussion from the figure.3-2. It shows the best fitness value of the function Π( θ1 ,θ2 ) = −4sin θ1−6cos θ1−4 sinθ2 − 2cosθ2 for different generations during the running of Genetic Algorithm (Fig.3-2(A)).Again Fig.3-2(B)shows the optimal values of the two individuals (θ1 and θ2) for minimum value of Π under unconstraint situation. CONSTRAINTS OPTIMIZATION : Now Fig.3-4(A,B,C,D) shows respectively value of the function at different iterations, Mesh size at different iterations, function evaluation in different iteration and value of the individuals at the optimal position. A pattern search algorithm computes a sequence of points that get closer and closer to the optimal point. At each step, the algorithm searches a set of points, called a mesh, around the current point. The search process is GA. Here “iteration” means the steps of creating a new mesh and searching for a set of points. As we can find the function value is decreasing (fig.3-4(A)) as the process proceeds because it is a minimization problem and the process is aiming at attaining minimum value. The process starts with the value of the function as 26.84 and at the end the value of the function is 26.5257. Now from the second figure (3-4(B)) we can see that the mesh size is fluctuating. This is due to the fact after a successful poll; the algorithm multiplies the current mesh size by 0.5, the default value of Contraction factor in the Mesh options pane.

OPTIMIZATION WITH FUZZY CONSTRAINTS: Now, we will consider the Table.3-1. We have calculated the values of different constraints for different α−cuts. With this constraint values we run the optimization algorithm and got different optimal values of a(1) and a(2).We have represented these values in column 3 and 4. From these values we have calculated x(1)(or d) and x(2)(or t) and represented in column 5 and 6.The corresponding costs are represented in column 7.Column 8 gives the value by which the induced stress can be accepted with corresponding values of d and t. COMPARISON: In the plot shown in Fig.3-10 we have plotted col-2(α−cuts) of Table-3-1. in abscissa and col-7 (Cost) in the ordinate. Again in the plot shown in Fig.3-11 we have plotted col-8(Acceptance value of induced stress) of Table-3-1. in abscissa and col-7 (Cost) in the ordinate. As we have expected that the graph will be a straight line it is not so. Perhaps the reason is the numerical errors. One of the reasons may be that in Matlab the number of bits in the offspring is 8.So, we get a low accuracy. Accuracy can be improved by using 16, 32, 64 or 128 bits. The other reason may be that the difference between different optimum values is very small. As computer has rounded those values there are some errors.

We can see from Fig. 3-10 that for α=0.00 we are getting the optimum cost as 24.9569 with induced stress 600 which has zero acceptability. As the value of the α−cut increases the general trend is that the cost value also increases. The acceptability of induced stress also increasing. The trend shows that for α=1.00 we are getting the same value as in case of nonfuzzy constraints (i.e. cost=26.5178).

4.2. Conclusion: With nonfuzzy constraints minimum cost=26.5178.With fuzzy constraints fuzzy

minimum cost=24.9569 but the criterion for induced stress is not satisfied. We can say with fuzzy constraints we can design parts with lower cost with lower reliability. 4.3. Future scope of study: If we can get chance to work in this subject in future we will try to

1. Consider the membership functions of different parameters based on their true nature. We will carry out some experiments to find out the correct membership function.

2. Set buckling stress as fuzzy constraint. 3. Carry out experiments on Optimization of Fuzzy Logic using Genetic Algorithm.

Page 40: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

32

BIBLIOGRAPHY 1. Singiresu S .Rao, Engineering Optimization Theory and Practice, New Age International (P)

Limited, Publishers 3rd edition, 1998. 2. Klir. G.J., Yuan, Fuzzy set theory, Prentice-Hall Limited, Newjersy, 1997. 3. S.Rajashekharan, G.A.Vijaylakshmi Neural Network, Fuzzy Logic, and Genetic Algorithms

(synthesis and application), Prentice-Hall Limited. 4. Matlab 7.0.1. Service Pack(1)

5. Antonsson, E. K. and K. N. Otto, “Improving Engineering Design with Fuzzy Sets,” 6. Mathtools.com

7. trebi0rmcs.cranfield.ac.uk 8. [email protected]

Page 41: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

APPENDIX

A FUZZY LOGIC PROBLEM AND MATLAB PROGRAMS

Page 42: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

33

APX. 1. A FUZZY LOGIC PROBLEM

GREG VIOT’S FUZZY CRUISE CONTROLLER

This controller is used to maintain a vehicle at a desired speed. The system consists of two fuzzy inputs,namely speed difference and acceleration, and one fuzzy output namely throttle control

RULES

Rule 1 If (speed difference is NL) and (acceleration is ZE) then (throttle control is PL)

Rule 2 If (speed difference is ZE) and (acceleration is NL) then (throttle control is PL)

Rule 3 If (speed difference is NM) and (acceleration is ZE) then (throttle control is PM)

Rule 4 If (speed difference is NS) and (acceleration is PS) then (throttle control is PS)

Rule 5 If (speed difference is PS) and (acceleration is NS) then (throttle control is NS)

Rule 6 If (speed difference is PL) and (acceleration is ZE) then (throttle control is NL)

Rule 7 If (speed difference is ZE) and (acceleration is NS) then (throttle control is PS)

Rule 8 If (speed difference is ZE) and (acceleration is NM) then (throttle control is PM)

Key:-

NL - Negative Large PM - Positive Medium ZE - Zero NS - Negative Small PL - Positive Large PS - Positive Small NM - Negative Medium

1

Degree of

Membership

0

0 31 63 95 127 159 191 223 255

Speed Difference (normalized)

Page 43: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

34

Degree of

membership

0

0 31 63 95 127 159 191 223 255

Acceleration (normalized)

Degree of

membership

0

0 31 63 95 127 159 191 223 255

Throttle control (normalized)

FUZZIFICATION OF INPUTS:

Let the measured normalized speed difference be 100 and the normalized acceleration be70, then the fuzzyfied inputs after computation of the fuzzy membership values are:

Page 44: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

35

For speed difference (x=100), the qualifying fuzzy sets are NS and ZE.Fuzzy membership function of x for NS where: Delta 1= 100-63= 37, Delta 2=127-100 = 27, Slope 1=1/32 = 0.03125, Slope=1/32=0.03125 Degree of membership function μΝS=min [37X0.03125; 27 X0.03125; 1] = 0.8438 Fuzzy membership function of x for ZE where: Delta 1= 100-95= 5, Delta 2=159-100 = 59, Slope 1=1/32 = 0.03125, Slope=1/32=0.03125 Degree of membership function μΖΕ=min [5X0.03125; 59 X0.03125; 1] = 0.840.1563 The membership function of x with the remaining fuzzy sets is zero.Now for acceleration (x=70) ,the qualifying fuzzy sets are NM and NS. The fuzzy membership function of x=70 for NM is μΝM =0.7813 and for NS is μΝS=0.2188. RULE STRENGTH COMPUTATION: For the sample rule base R the rule strengths are Rule 1: min(0,0) = 0 Rule 2: min(0.1563,0) = 0 Rule 3: min(0,0) = 0 Rule 4: min(0.8438,0) = 0 Rule 5: min(0,0.2188) = 0 Rule 6: min(0,0) = 0 Rule 7: min(0.1563,0.2188) = 0.1563 Rule 8: min(01563,0.7813) = 0.1563 FUZZY OUTPUT: Defuzzification: The centre of gravity method is applied to defuzzify the output. PS PM Degree of membership b1 b2 0.1563 h 127 159 191 223 a1 a2 For the fuzzy set PS, X-axis centroid = 159 Rule strength applied to determine output area= 0.1563 Shaded area = 0.5X h X (a1+b1) =9.99 For the fuzzy set PM, X-axis centroid = 191 Rule strength applied to determine output area= 0.1563 Shaded area = 0.5X h X (a1+b1) =9.99 Therefore, Weighted average, (CG) = (1/19.98) X (9.99 X159+9.99 X191) =175 In crisp terms, the throttle control (normalized) is to be set as 175.

Page 45: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

36

SOLUTION USING MATLAB FIS:

Therefore output of the FIS:- Throttle control=175. .....................................................ANS

Page 46: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

37

APX.2. MATLAB PROGRAMS: MATLAB PROGRAM FOR GENETIC ALGORITHM: function [x,fval,exitFlag,output,population,scores]= ga(FUN,genomeLength,options) defaultopt = struct('PopulationType', 'doubleVector', ... 'PopInitRange', [0;1], ... 'PopulationSize', 20, ... 'EliteCount', 2, ... 'CrossoverFraction', 0.8, ... 'MigrationDirection','forward', ... 'MigrationInterval',20, ... 'MigrationFraction',0.2, ... 'Generations', 100, ... 'TimeLimit', inf, ... 'FitnessLimit', -inf, ... 'StallGenLimit', 50, ... 'StallTimeLimit', 20, ... 'InitialPopulation',[], ... 'InitialScores', [], ... 'PlotInterval',1, ... 'FitnessScalingFcn', @fitscalingrank, ... 'SelectionFcn', @selectionstochunif, ... 'CrossoverFcn',@crossoverscattered, ... 'MutationFcn',@mutationgaussian, ... 'PlotFcns', [], ... 'Display', 'final', ... 'OutputFcns', [], ... 'CreationFcn',@gacreationuniform, ... 'HybridFcn',[], ... 'Vectorized','off'); msg = nargchk(1,3,nargin); if ~isempty(msg) %”isempty” is a function checks is the array is empty% error('gads:GA:numberOfInputs',msg); end % If just 'defaults' passed in, return the default options in X if nargin == 1 && nargout <= 1 && isequal(FUN,'defaults') %”isequal” determines the x = defaultopt; array are equal% return end %if 3 arg, options is passed if nargin>=3 if ~isempty(options) && ~isa(options,'struct') %”isa” Detect an object of a given MATLAB class or Java class% error('gads:GA:thirdInputNotStruct','Invalid Inputi for GA.'); else FitnessFcn = FUN; GenomeLength = genomeLength; end if isempty(options) options = gaoptimset; end end %If 2 args, use default options for GA if nargin==2 options = gaoptimset; FitnessFcn = FUN; GenomeLength = genomeLength; end

Page 47: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

38

if nargin == 1 try options = FUN.options; GenomeLength = FUN.nvars; FitnessFcn = FUN.fitnessfcn; if isfield(FUN, 'randstate') && isfield(FUN, 'randnstate') && ... %“isfield” Determine if input is a MATLAB structure array field % isa(FUN.randstate, 'double') && isequal(size(FUN.randstate),[35, 1]) && ... isa(FUN.randnstate, 'double') && isequal(size(FUN.randnstate),[2, 1]) rand('state',FUN.randstate); %”rand” Uniformly distributed random numbers and arrays % randn('state',FUN.randnstate); %”randn” Normally distributed random numbers and arrays % end catch error('gads:GA:invalidStructInput',lasterr); end end x =[];fval =[];exitFlag='';population=[];scores=[];user_options = options; output.randstate = rand('state'); output.randnstate = randn('state'); output.generations = 0; output.funccount = 0; output.message = ''; [GenomeLength,FitnessFcn,options] = validate(GenomeLength,FitnessFcn,options); state = makeState(GenomeLength,FitnessFcn,options); state = gaplot(FitnessFcn,options,state,'init'); [state,options] = gaoutput(FitnessFcn,options,state,'init'); if strcmpi(options.Display,'diagnose') %”strcmpi” Compare strings ignoring case% gadiagnose(FUN,GenomeLength,user_options); end if any(strcmpi(options.Display, {'iter','diagnose'})) fprintf('\n Best Mean Stall\n'); fprintf('Generation f-count f(x) f(x) Generations\n'); end exitFlag = ''; while isempty(exitFlag) state.Generation = state.Generation + 1; offset = 0; totalPop = options.PopulationSize; for pop = 1:length(totalPop) populationSize = totalPop(pop); thisPopulation = 1 + (offset:(offset + populationSize - 1)); population = state.Population(thisPopulation,:); score = state.Score( thisPopulation ); [score,population,state] = stepGA(score,population,options,state,GenomeLength,FitnessFcn); state.Population(thisPopulation,:) = population; state.Score(thisPopulation) = score; offset = offset + populationSize; end scores = state.Score; best = min(state.Score); generation = state.Generation; state.Best(generation) = best; if((generation > 1) && finite(best)) if(state.Best(generation-1) > best) state.LastImprovement = generation; state.LastImprovementTime = cputime; end end

Page 48: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

39

state = migrate(FitnessFcn,GenomeLength,options,state); state = gaplot(FitnessFcn,options,state,'iter'); [state,options] = gaoutput(FitnessFcn,options,state,'iter'); exitFlag = isItTimeToStop(options,state); end [fval,best] = min(state.Score); x = state.Population(best,:); output.generations = state.Generation; output.message = exitFlag; output.funccount = state.Generation*length(state.Score); if(nargout > 4) population = state.Population; if(nargout > 5) scores = state.Score; end end gaplot(FitnessFcn,options,state,'done'); gaoutput(FitnessFcn,options,state,'done'); if(strcmpi(options.PopulationType,'doubleVector') && ~isempty(options.HybridFcn)) if isa(options.HybridFcn,'function_handle') hfunc = func2str(options.HybridFcn); else hfunc = options.HybridFcn; end if any(strcmpi(options.Display, {'iter','diagnose','final'})) fprintf('%s%s%s\n','Switching to the hybrid optimization algorithm (',upper(hfunc),').'); end switch hfunc case 'fminsearch' if isempty(options.HybridFcnArgs) [xx,ff,e,o] = feval(options.HybridFcn,FitnessFcn,x,[],options.FitnessFcnArgs{:}); else [xx,ff,e,o] = feval(options.HybridFcn,FitnessFcn,x,options.HybridFcnArgs{:},options.FitnessFcnArgs{:}); end output.funccount = output.funccount + o.funcCount; output.message = [output.message sprintf('\nFMINSEARCH:\n'), o.message]; case 'patternsearch' [xx,ff,e,o] = feval(options.HybridFcn,{FitnessFcn,options.FitnessFcnArgs{:}},x,[],[],[],[],[],[],options.HybridFcnArgs{:}); output.funccount = output.funccount + o.funccount; output.message = [output.message sprintf('\nPATTERNSEARCH: \n'), o.message]; case 'fminunc' if isempty(options.HybridFcnArgs) [xx,ff,e,o] = feval(options.HybridFcn,FitnessFcn,x,[],options.FitnessFcnArgs{:}); else [xx,ff,e,o] = feval(options.HybridFcn,FitnessFcn,x,options.HybridFcnArgs{:},options.FitnessFcnArgs{:}); end output.funccount = output.funccount + o.funcCount; output.message = [output.message sprintf('\nFMINUNC: \n'), o.message]; otherwise

Page 49: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

40

error('gads:GA:hybridFcnError','Hybrid function must be one of the following:\n@FMINSEARCH, @FMINUNC, @PATTERNSEARCH.') end if e > 0 && ff < fval fval = ff; x = xx; end if any(strcmpi(options.Display, {'iter','diagnose'})) fprintf('%s%s\n',upper(hfunc), ' terminated.'); end end --------------------------------------------------------------------------------------------------------------------------------------------------------------------------

MATLAB PROGRAM FOR PATTERNSEARCH function [X,FVAL,EXITFLAG,OUTPUT] = patternsearch(FUN,initialX,Aineq,Bineq,Aeq,Beq,LB,UB,options) defaultopt = struct('TolMesh', 1e-6, ... 'TolX', 1e-6 , ... 'TolFun',1e-6 , ... 'TolBind',1e-3, ... 'MaxIter', '100*numberofvariables', ... 'MaxFunEvals', '2000*numberofvariables', ... 'MeshContraction', 0.5, ... 'MeshExpansion', 2.0, ... 'MeshAccelerator','off', ... 'MeshRotate','on', ... 'InitialMeshSize', 1.0, ... 'ScaleMesh', 'on', ... 'MaxMeshSize', inf, ... 'PollMethod', 'positivebasis2n', ... 'CompletePoll','off', ... 'PollingOrder', 'consecutive', ... 'SearchMethod', [], ... 'CompleteSearch','off', ... 'Display', 'final', ... 'OutputFcns', [], ... 'PlotFcns', [], ... 'PlotInterval', 1, ... 'Cache','off', ... 'CacheSize',1e4, ... 'CacheTol',eps, ... 'Vectorized','off' ... ); % If just 'defaults' passed in, return the default options in X if nargin == 1 && nargout <= 1 && isequal(FUN,'defaults') X = defaultopt; return end errmsg = nargchk(1,9,nargin); %At least 1 arguments are needed. if nargin <1 error('gads:PATTERNSEARCH:inputArg',[errmsg,' PATTERNSEARCH requires at least 1 input argument.']); elseif ~isempty(errmsg) error('gads:PATTERNSEARCH:inputArg',[errmsg,' PATTERNSEARCH takes at most 9 input arguments.']); end

Page 50: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

41

errmsg = nargoutchk(0,4,nargin); if nargout > 4 && ~isempty(errmsg) error('gads:PATTERNSEARCH:outputArg',[errmsg,' PATTERNSEARCH returns at most 4 output arguments.']); end if nargin < 9, options = []; if nargin < 8, UB = []; if nargin < 7, LB = []; if nargin <6, Beq = []; if nargin <5, Aeq = []; if nargin < 4, Bineq = []; if nargin <3, Aineq= []; end, end, end, end, end, end, end if nargin == 1 if isa(FUN,'struct') try if isfield(FUN, 'randstate') && isfield(FUN, 'randnstate') && ... isa(FUN.randstate, 'double') && isequal(size(FUN.randstate),[35, 1]) && ... isa(FUN.randnstate, 'double') && isequal(size(FUN.randnstate),[2, 1]) rand('state',FUN.randstate); randn('state',FUN.randnstate); end initialX = FUN.X0; Aineq = FUN.Aineq; Bineq = FUN.Bineq; Aeq = FUN.Aeq; Beq = FUN.Beq; LB = FUN.LB; UB = FUN.UB; options = FUN.options; FUN = FUN.objective; catch msg = sprintf('%s%s\n%s', 'Trying to use a structure with invalid/missing fields: ', ... 'See help for PATTERNSEARCH.', ... lasterr); error('gads:PATTERNSEARCH:invalidStructInput',msg); end else % Single input and non-structure. error('gads:PATTERNSEARCH:inputArg','The input should be a structure with valid fields or provide two arguments to patternsearch' ); end end if ~isequal('double', superiorfloat(initialX,Aineq,Bineq,Aeq,Beq,LB,UB)) error('gads:PATTERNSEARCH:dataType','PATTERNSEARCH only accepts inputs of data type double.'); end if ~isempty(Aeq) || ~isempty(Aineq) [X,FVAL,EXITFLAG,OUTPUT] = pfminlcon(FUN,initialX,Aineq,Bineq,Aeq,Beq,LB,UB,options); elseif (isempty(Aeq) && isempty(Aineq) && isempty(Bineq) && isempty(Beq)) && ( ~isempty(LB) || ~isempty(UB) ) [X,FVAL,EXITFLAG,OUTPUT] = pfminbnd(FUN,initialX,LB,UB,options); elseif (isempty(Aeq) && isempty(Aineq) && isempty(Bineq) && isempty(Beq) && isempty(LB) && isempty(UB)) [X,FVAL,EXITFLAG,OUTPUT] = pfminunc(FUN,initialX,options); else try

Page 51: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

42

[X,FVAL,EXITFLAG,OUTPUT] = pfminlcon(FUN,initialX,Aineq,Bineq,Aeq,Beq,LB,UB,options); catch error('gads:PATTERNSEARCH:entryPoint','%s',lasterr); end end --------------------------------------------------------------------------------------------------------------------------------------------------------------------------

FUNCTION GAOPTIMESET

function options = gaoptimset(varargin) if (nargin == 0) && (nargout == 0) fprintf('PopulationType:[''bitstring''|''custom''| {''doubleVector''} ]\n'); fprintf('PopInitRange: [ matrix|{[0;1]}]\n'); fprintf('PopulationSize:[ positive scalar|{20}]\n'); fprintf('EliteCount:[ positive scalar|{2}]\n'); fprintf('CrossoverFraction:[ positive scalar|{0.8}]\n\n'); fprintf('MigrationDirection:[''both''|{''forward''}]\n'); fprintf('MigrationInterval:[ positive scalar|{20} ]\n'); fprintf('MigrationFraction:[ positive scalar|{0.2}]\n\n'); fprintf('Generations:[positive scalar|{100}]\n'); fprintf('TimeLimit:[positive scalar|{Inf}]\n'); fprintf('FitnessLimit:[scalar|{-Inf}]\n\n'); fprintf('StallGenLimit:[ positive scalar|{50}]\n'); fprintf('StallTimeLimit:[ positive scalar|{20}]\n'); fprintf('InitialPopulation:[ matrix|{[]}]\n'); fprintf('InitialScores:[ column vector|{[]} ]\n\n'); fprintf('CreationFcn:[function_handle|{@gacreationuniform}]\n'); fprintf('FitnessScalingFcn:[function_handle|@fitscalingshiftlinear|@fitscalingprop|\n'); fprintf('@fitscalingtop|{@fitscalingrank}]\n'); fprintf('SelectionFcn:[function_handle|@selectionremainder|@selectionrandom|\n'); fprintf('@selectionroulette|@selectiontournament|{@selectionstochunif} ]\n'); fprintf('CrossoverFcn:[function_handle|@crossoverheuristic|crossoverintermediate | \n'); fprintf('@crossoversinglepoint|@crossovertwopoint|{@crossoverscattered}]\n'); fprintf('MutationFcn:[function_handle|@mutationuniform|{@mutationgaussian}]\n'); fprintf('HybridFcn:[@fminsearch|@patternsearch| @fminunc | {[]} ]\n\n'); fprintf('Display: [ off | iter | diagnose | {final} ]\n'); fprintf('OutputFcns: [ function_handle | @gaoutputgen | {[]} ]\n'); fprintf('PlotFcns:[function_handle|@gaplotbestf|@gaplotbestindiv|@gaplotdistance | \n'); fprintf('@gaplotexpectation|@gaplotgeneology|@gaplotselection|@gaplotrange| \n'); fprintf('@gaplotscorediversity | @gaplotscores | @gaplotstopping | {[]} ]\n'); fprintf('PlotInterval: [ positive scalar | {1} ]\n\n'); fprintf('Vectorized: [ ''on'' | {''off''} ]\n'); return; end numberargs = nargin; options=struct('PopulationType', 'doubleVector', ... 'PopInitRange', [0;1], ...

Page 52: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

43

'PopulationSize', 20, ... 'EliteCount', 2, ... 'CrossoverFraction', 0.8, ... 'MigrationDirection','forward', ... 'MigrationInterval',20, ... 'MigrationFraction',0.2, ... 'Generations', 100, ... 'TimeLimit', inf, ... 'FitnessLimit', -inf, ... 'StallGenLimit', 50, ... 'StallTimeLimit', 20, ... 'InitialPopulation',[], ... 'InitialScores', [], ... 'PlotInterval',1, ... 'CreationFcn',@gacreationuniform, ... 'FitnessScalingFcn', @fitscalingrank, ... 'SelectionFcn', @selectionstochunif, ... 'CrossoverFcn',@crossoverscattered, ... 'MutationFcn',@mutationgaussian, ... 'HybridFcn',[], ... 'Display', 'final', ... 'PlotFcns', [], ... 'OutputFcns', [], ... 'Vectorized','off'); if (numberargs==1) && (ischar(varargin{1}) || isa(varargin{1},'function_handle') ) %”ischar” Determine if input is a character array % if ischar(varargin{1}) funcname = lower(varargin{1}); %”lower” convert string to lowercase% if ~exist(funcname) %”exist” Check if variables or functions are defined % msg = sprintf( ... 'No default options available: the function ''%s'' does not exist on the path.',funcname); error('gads:GAOPTIMSET:functionNotFound',msg) end elseif isa(varargin{1},'function_handle') funcname = func2str(varargin{1}); end try optionsfcn = feval(varargin{1},'defaults'); %”feval” function evaluating% catch msg = sprintf( ... 'No default options available for the function ''%s''.',funcname); error('gads:GAOPTIMSET:noDefaultOptions',msg) end varargin{1} = options; varargin{2} = optionsfcn; numberargs = 2; end Names = fieldnames(options); %” fieldnames” Get names of fields % m = size(Names,1); names = lower(Names); i = 1; while i <= numberargs arg = varargin{i}; if ischar(arg) % arg is an option name break; end if ~isempty(arg) % [] is a valid options argument if ~isa(arg,'struct')

Page 53: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

44

error('gads:GAOPTIMSET:invalidArgument',['Expected argument %d to be a string parameter name ' ... 'or an options structure\ncreated with GAOPTIMSET.'], i); end for j = 1:m if any(strcmp(fieldnames(arg),Names{j,:})) val = arg.(Names{j,:}); else val = []; end if ~isempty(val) if ischar(val) val = deblank(val); end [valid, errmsg] = checkfield(Names{j,:},val); if valid options.(Names{j,:}) = val; else error('gads:GAOPTIMSET:invalidOptionField',errmsg); end end end end i = i + 1; end if rem(numberargs-i+1,2) ~= 0 error('gads:GAOPTIMSET:invalidArgPair','Arguments must occur in name-value pairs.'); end expectval = 0; % start expecting a name, not a value while i <= numberargs arg = varargin{i}; if ~expectval if ~ischar(arg) error('gads:GAOPTIMSET:invalidArgFormat','Expected argument %d to be a string parameter name.', i); end lowArg = lower(arg); j = strmatch(lowArg,names); if isempty(j) % if no matches error('gads:GAOPTIMSET:invalidParamName','Unrecognized parameter name ''%s''.', arg); elseif length(j) > 1 % if more than one match k = strmatch(lowArg,names,'exact'); %” strmatch” Find possible matches for a string % if length(k) == 1 j = k; else msg = sprintf('Ambiguous parameter name ''%s'' ', arg); msg = [msg '(' Names{j(1),:}]; for k = j(2:length(j))' msg = [msg ', ' Names{k,:}]; end msg = sprintf('%s).', msg); error('gads:GAOPTIMSET:ambiguousParamName',msg); end end expectval = 1; % we expect a value next else if ischar(arg)

Page 54: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

45

arg = (deblank(arg)); end [valid, errmsg] = checkfield(Names{j,:},arg); if valid options.(Names{j,:}) = arg; else error('gads:GAOPTIMSET:invalidParamVal',errmsg); end expectval = 0; end i = i + 1; end if expectval error('gads:GAOPTIMSET:invalidParamVal','Expected value for parameter ''%s''.', arg); end function [valid, errmsg] = checkfield(field,value) valid = 1; errmsg = ''; if isempty(value) return end switch field case {'PopulationType','MigrationDirection'} if ~isa(value,'char') valid=0; errmsg = sprintf('Invalid value for OPTIONS parameter %s.',field); end case {'FitnessScalingFcn','SelectionFcn','CrossoverFcn','MutationFcn',... 'CreationFcn','HybridFcn','PlotFcns','OutputFcns'} if iscell(value) || isa(value,'function_handle') valid = 1; else valid = 0; errmsg = sprintf('Invalid value for OPTIONS parameter %s.',field); end case {'PopulationSize','EliteCount','CrossoverFraction','MigrationInterval','PlotInterval', ... 'MigrationFraction','Generations','TimeLimit','StallTimeLimit','FitnessLimit','StallGenLimit'} if ~isa(value,'double') valid = 0; if ischar(value) errmsg = sprintf('Invalid value for OPTIONS parameter %s: must be a real positive number (not a string).',field); else errmsg = sprintf('Invalid value for OPTIONS parameter %s: must be a real positive number.',field); end end case {'PopInitRange','InitialPopulation','InitialScores'} valid = 1; case {'Display'} if ~isa(value,'char') || ~any(strcmpi(value,{'off','iter','diagnose','final'})) valid=0;

Page 55: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

46

errmsg = sprintf('Invalid value for OPTIONS parameter %s: must be ''off'',''iter'', ''diagnose'', or ,''final''.',field); end case {'Vectorized'} if ~isa(value,'char') || ~any(strcmp(value,{'on','off'})) valid = 0; errmsg = sprintf('Invalid value for OPTIONS parameter %s: must be ''off'' or ''on''.',field); end otherwise error('gads:GAOPTIMSET:unknownOptionsField','Unknown field name for Options structure.') end --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

FUNCTION VALIDATE function [gl,ff,o] = validate(gLength,fitness,o) msg = nargchk(3,3,nargin); %”nargchk” Check number of input arguments % if ~isempty(msg) error('MATLAB:Validate:numInputs', ... 'VALIDATE requires one structure of the format created by GAOPTIMSET.'); end o.FitnessFcn = fitness; o.GenomeLength = gLength; options = gaoptimset; options.FitnessFcn = []; options.GenomeLength = []; template = fieldnames(options); oFields = fieldnames(o); f = find(0 == ismember(template,oFields)); if(~isempty(f)) msg = sprintf('The field "%s" is missing from the gaoptimset Structure.\n',template{f}); error('gads:VALIDATE:missingField',msg); end f = find(0 == ismember(oFields,template)); if(~isempty(f)) msg = sprintf('There is an unexpected field "%s" in the gaoptimset Structure.\n',oFields{f}); warning('gads:VALIDATE:unexpectedField',msg); end validNumberofVariables(o.GenomeLength); stringSet('PopulationType',o.PopulationType,{'doubleVector','custom','bitString'}); positiveIntegerArray('PopulationSize',o.PopulationSize); realUnitScalar('CrossoverFraction',o.CrossoverFraction); nonNegInteger('EliteCount',o.EliteCount); o = rangeCorrection(o,'PopInitRange'); populationCheck(o); positiveInteger('MigrationInterval',o.MigrationInterval); realUnitScalar('MigrationFraction',o.MigrationFraction); stringSet('MigrationDirection',o.MigrationDirection,{'both','forward'}); stringSet('Display',o.Display,{'off','none','iter','final','diagnose'}); stringSet('Vectorized',o.Vectorized,{'on','off'});

Page 56: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

47

positiveInteger('Generations',o.Generations); positiveScalar('TimeLimit',o.TimeLimit); positiveInteger('StallGenLimit',o.StallGenLimit); positiveScalar('StallTimeLimit',o.StallTimeLimit); realScalar('FitnessLimit',o.FitnessLimit); positiveInteger('PlotInterval',o.PlotInterval); o = functionHandleOrCell(o,'FitnessFcn',o.FitnessFcn); o = functionHandleOrCell(o,'FitnessScalingFcn',o.FitnessScalingFcn); o = functionHandleOrCell(o,'SelectionFcn',o.SelectionFcn); o = functionHandleOrCell(o,'CrossoverFcn',o.CrossoverFcn); o = functionHandleOrCell(o,'MutationFcn',o.MutationFcn); o = functionHandleOrCell(o,'CreationFcn',o.CreationFcn); if ~isempty(o.HybridFcn) o = functionHandleOrCell(o,'HybridFcn',o.HybridFcn); end if ( o.EliteCount >= sum(o.PopulationSize) ) msg = sprintf('Elite count must be less than Population Size.'); error('gads:VALIDATE:EliteCountGTPop',msg); end o = functionHandleOrCellArray(o,'PlotFcns',o.PlotFcns); o = functionHandleOrCellArray(o,'OutputFcns',o.OutputFcns); ff = o.FitnessFcn; gl = o.GenomeLength; o=rmfield(o,{'FitnessFcn','GenomeLength'}); function positiveInteger(property,value) valid = isreal(value) && isscalar(value) && (value > 0) && (value == floor(value)); %”isreal” Determine if all array elements are real numbers % if(~valid) msg = sprintf('The field ''%s'' must contain a positive integer.',property); error('gads:VALIDATE:PostiveInteger:notPosInteger',msg); end function nonNegInteger(property,value) valid = isreal(value) && isscalar(value) && (value >= 0) && (value == floor(value)); if(~valid) msg = sprintf('The field ''%s'' must contain a non negative integer.',property); error('gads:VALIDATE:NonNegInteger:negativeNum',msg); end function positiveScalar(property,value) valid = isreal(value) && isscalar(value) && (value > 0); if(~valid) msg = sprintf('The field ''%s'' must contain a positive Scalar.',property); error('gads:VALIDATE:PositiveScalar:notPosScalar',msg); end function positiveIntegerArray(property,value) allValid = true; for i = 1:length(value) valid = isreal(value(i)) && (value(i) == floor(value(i))); allValid = allValid && valid; end if(~valid) msg = sprintf('The field ''%s'' must contain a positive integer.',property); error('gads:VALIDATE:POSITIVEINTEGERARRAY:notPosIntegerArray',msg); end function realUnitScalar(property,value) valid = isreal(value) && isscalar(value) && (value >= 0) && (value <= 1); if(~valid) msg = sprintf('The field ''%s'' must contain a scalar on the interval (0,1)',property); error('gads:VALIDATE:REALUNITSCALAR:notScalarOnUnitInterval',msg);

Page 57: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

48

end function realScalar(property,value) valid = isreal(value) && isscalar(value); if(~valid) msg = sprintf('The field ''%s'' must contain a scalar',property); error('gads:VALIDATE:REALSCALAR:notScalar',msg); end function validNumberofVariables(GenomeLength) valid = isnumeric(GenomeLength) && isscalar(GenomeLength)&& (GenomeLength > 0) ... && (GenomeLength == floor(GenomeLength)); if(~valid) msg = sprintf('Number of variables (NVARS) must be a positive number.'); error('gads:VALIDATE:validNumberofVariables:notValidNvars',msg); end function [handle,args] = isFcn(x) handle = []; args = {}; if iscell(x) && ~isempty(x) args = x(2:end); handle = x{1}; else args = {}; handle = x; end if ~(isa(handle,'inline') || isa(handle,'function_handle')) handle = []; end function options = functionHandleOrCell(options,property,value) [handle,args] = isFcn(value); if(~isempty(handle)) && (isa(handle,'inline') || isa(handle,'function_handle')) options.(property) = handle; options.([property 'Args']) = args; return end if strcmp(property,'FitnessFcn') msg = sprintf('The fitness function must be a function handle.'); else msg = sprintf('The field ''%s'' must contain a function handle.',property); end error('gads:VALIDATE:FUNCTIONHANDLEORCELL:needHandleOrInline',msg); function options = functionHandleOrCellArray(options,property,value) options.(property) = {}; options.([property 'Args']) = {}; if ~iscell(value) && isscalar(value) value = {value}; end for i = 1:length(value) candidate = value(i); if iscell(candidate) if isempty(candidate{1}) continue; end temp = candidate{1}; while iscell(temp) && isscalar(temp) candidate = temp(1); temp = candidate{1}; end [handle,args] = isFcn(candidate{:}); else [handle,args] = isFcn(candidate);

Page 58: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

49

end if(~isempty(handle)) && isa(handle,'function_handle') options.(property){i} = handle; options.([property 'Args']){i} = args; else msg = sprintf('The field ''%s'' must contain a function handle.',property); error('gads:VALIDATE:FUNCTIONHANDLEORCELLARRAY:needHandleOrInline',msg); end end function stringSet(property,value,set) for i = 1:length(set) if(strcmpi(value,set{i})) return; end end msg = sprintf('The field %s must contain one of these strings: %s %s %s %s %s',property,set{:}); error('gads:VALIDATE:STRINGSET:notCorrectChoice',msg); function options = rangeCorrection(options,property) Range = options.PopInitRange; if ~isa(Range,'double') return; end if size(Range,1) ~=2 msg = sprintf('The field ''%s'' must have two rows.',property); error('gads:VALIDATE:RANGECORRECTION:invalidPopInitRange',msg); end lb = Range(1,:); lb = lb(:); lenlb = length(lb); ub = Range(2,:); ub = ub(:); lenub = length(ub); nvars = options.GenomeLength; if lenlb > nvars warning('gads:VALIDATE:extraRange','Length of lower range is > number of variables; ignoring extra bounds.'); lb = lb(1:nvars); lenlb = nvars; elseif lenlb < nvars lb = [lb; lb(end)*ones(nvars-lenlb,1)]; lenlb = nvars; end if lenub > nvars warning('gads:VALIDATE:extraRange','Length of upper range is > number of variables; ignoring extra bounds.'); ub = ub(1:nvars); lenub = nvars; elseif lenub < nvars ub = [ub; ub(end)*ones(nvars-lenub,1)]; lenub = nvars; end len = min(lenlb,lenub); if any( lb( (1:len)' ) > ub( (1:len)' ) ) count = full(sum(lb>ub)); if count == 1 msg=sprintf(['\nExiting due to infeasibility: %i lower range exceeds the' ... ' corresponding upper range.\n'],count); else msg=sprintf(['\nExiting due to infeasibility: %i lower range exceed the' ... ' corresponding upper range.\n'],count);

Page 59: STUDY OF OPTIMIZATION WITH FUZZY CONSTRAINTS

50

end error('gads:validate:infesibleRange',msg); end if any(eq(ub, -inf)) error('gads:VALIDATE:infRange','-Inf detected in upper bound: upper bounds must be > -Inf.'); elseif any(eq(lb,inf)) error('gads:VALIDATE:infRange','+Inf detected in lower bound: lower bounds must be < Inf.'); end options.PopInitRange = [lb,ub]'; function populationCheck(options) if strcmpi(options.PopulationType,'custom') return; end if ~isnumeric(gaoptimget(options,'InitialPopulation')) error('gads:VALIDATE:invalidPopulation','Invalid value for OPTIONS parameter InitialPopulation.'); end if ~isnumeric(gaoptimget(options,'InitialScores')) error('gads:VALIDATE:invalidScores','Invalid value for OPTIONS parameter InitialScores.'); end --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

FUNCTION MAKESTATE function state = makeState(GenomeLength,FitnessFcn,options) if(isempty(options.InitialPopulation)) state.Population = feval(options.CreationFcn,GenomeLength,FitnessFcn,options,options.CreationFcnArgs{:}); else state.Population = options.InitialPopulation; end if(isempty(options.InitialScores)) if strcmpi(options.Vectorized, 'off') state.Score = feval(@fcnvectorizer,state.Population,FitnessFcn,options.FitnessFcnArgs{:}); else state.Score = feval(FitnessFcn,state.Population,options.FitnessFcnArgs{:}); end else state.Score = options.InitialScores; options.InitialScores = []; end state.Generation = 0; state.StartTime = cputime; state.StopFlag = []; state.LastImprovement = 1; state.LastImprovementTime = state.StartTime; state.Selection = [];