Solved
New Contributor
Posts: 4

# PROC GA under non-linear constraint

Hello,

I have a function I neet to optimize using PROC GA and it is simple --  0.1*x*y. But then I have constraint which is not that simple  x**2 + y**2 <= (5+2.2*cos(10*atan(x/y)))**2. How  can I solve this in SAS? Sorry, I am very new with SAS. My code so far looks like:

```proc ga seed = 12 maxiter = 30;

function funkc(selected[*]);
array x[2] /nosym;
call ReadMember(selected,1,x);
x1 = x[1];
x2 = x[2];
F= 0.1*x1*x2;
return(F);
endsub;

call SetEncoding('R2');
array LowerBound[2] /nosym (-10 -6);
array UpperBound[2] /nosym (10 6);
call SetBounds(LowerBound, UpperBound);
call SetObjFunc('funkc',0);
call SetCrossProb(0.65);
call SetCross('Heuristic');
call SetMutProb(0.15);
array del[2] /nosym (0.2 0.2);
call SetMut('Delta','nchange', 1, 'delta',del);
call SetSel('tournament','size', 2);
call SetElite(2);
call Initialize('DEFAULT',150);
run;
quit; ```

Accepted Solutions
Solution
‎04-10-2017 11:35 AM
Super User
Posts: 10,610

## Re: PROC GA under non-linear constraint

[ Edited ]
Posted in reply to KarolinaA

Some thought.

``````function funkc(selected[*]);

call ReadMember(selected,1,x);
F= 0.1*x[1]*x[2];  if (5+2.2*cos(10*atan(x[1]/x[2])))**2 - x[1]**2 - x[2]**2 < 0 then F=9999999;
return(F);
endsub; ``````

and make population size bigger.

`call Initialize('DEFAULT',15000);`

All Replies
Solution
‎04-10-2017 11:35 AM
Super User
Posts: 10,610

## Re: PROC GA under non-linear constraint

[ Edited ]
Posted in reply to KarolinaA

Some thought.

``````function funkc(selected[*]);

call ReadMember(selected,1,x);
F= 0.1*x[1]*x[2];  if (5+2.2*cos(10*atan(x[1]/x[2])))**2 - x[1]**2 - x[2]**2 < 0 then F=9999999;
return(F);
endsub; ``````

and make population size bigger.

`call Initialize('DEFAULT',15000);`

New Contributor
Posts: 4

## Re: PROC GA under non-linear constraint

Nice idea. Got an error: ERROR: The array 'x' cannot be an argument of the '**' operation.
New Contributor
Posts: 4

## Re: PROC GA under non-linear constraint

Okay. It was very simple. Could you please edit your post and change x to x[1] and y to x[2] and then it would be a solution
SAS Employee
Posts: 538

## Re: PROC GA under non-linear constraint

Posted in reply to KarolinaA

Here's how you can solve it with the NLP solver in PROC OPTMODEL:

``````proc optmodel;
var x >= -10 <= 10 init 1;
var y >= -6  <= 6  init 1;
min F = 0.1*x*y;
con Mycon:
x**2 + y**2 <= (5+2.2*cos(10*atan(x/y)))**2;
solve with nlp / ms;
print x y;
quit;``````
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
• 4 replies
• 157 views
• 0 likes
• 3 in conversation