You are on page 1of 5

Genetic algorithm

(Convert maximization to minimization by multiply -1 and all constraint <= otherwise multiply by -1 and
bounds are lower(>=) or upper(<=) )

Example 1:

Maximize Z=3x1+4x2 or Minimize Z=-3x1-4x2

Subject to

X1+x2<=450

2X1+x2<=600

Where x1, x2, x3>=0

A=[1 1;2 1]

B=[450;600]

Lower=[0 0 0]

Solution:

Step1: in Command prompt enter

>>optimtool

Step2: open live editor

Include Parameters or Data


x0 = [2;1];
a = 100;
n=2;
A=[1 1; 2 1];
B=[450;600];
lower=[0 0 0];

After that run

Step 3:

Optimize Live Editor Task


Specify problem type

Select objective-linear

Constraints: lower bounds, Linear inequality and nonlinear

Solver: genetic algorithm

Select Program data

Objective function: local function (min1)

No of variables : n

Constraints: lower bounds (All bounds are same) (0-numeric value)

Linear inequality: A<=B

Nonlinear: local function (constaintfun) –inequality equation and equality if any

Output save with (example2.mlx)

Example 2:

Solution:-
Example 3: from book exact result show

Minimize Z=5x1+6x2

Subject to

2X1+5x2>=1500 or -2X1-5x2<=-1500

3X1+x2>=1200 or -3X1-x2<=-1200

Where x1, x2, x3>=0

Result in book:

X1=4500/13 X2=2100/13 Z=Rs. 2700

Example 4: from book exact result show

Maximize Z=10x1+5x2 Minimize Z=-10x1-5x2

Subject to

4X1+5x2<=100

5X1+2x2<=80

Where x1, x2, x3>=0

Result in book:

X1=200/17 X2=180/17 Z=2900/17

You might also like