BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
KarolinaA
Fluorite | Level 6

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; 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

I really suggest you to use Nonlinear Optimization Function, since GA can not guarantee you to get the optimal solution.

And better post it at IML forum.

If you want stick with PROC GA ,then post it at OR forum, since PROC GA is under SAS/OR.

 

proc iml;
start F_UC2D(x);
f = 0.1*x[1]*x[2];;
return(f);
finish F_UC2D;

start C_UC2D(x);
c = (5+2.2*cos(10*atan(x[1]/x[2])))**2 - x[1]**2 - x[2]**2 ;
return(c);
finish C_UC2D;

x = j(1,2,0.5);
optn= j(1,10,.);optn[1]=0; optn[2]= 1; optn[10]= 1;
CALL NLPNMS(rc,xres,"F_UC2D",x,optn) nlc="C_UC2D";

print rc[l='rc>0 means find a soultion'],xres[l='solution for x'];
quit;

 

 

ABSXCONV convergence criterion satisfied.
rc>0 means find a soultion
4
solution for x
-4.283178 5.7739759

View solution in original post

2 REPLIES 2
Ksharp
Super User

I really suggest you to use Nonlinear Optimization Function, since GA can not guarantee you to get the optimal solution.

And better post it at IML forum.

If you want stick with PROC GA ,then post it at OR forum, since PROC GA is under SAS/OR.

 

proc iml;
start F_UC2D(x);
f = 0.1*x[1]*x[2];;
return(f);
finish F_UC2D;

start C_UC2D(x);
c = (5+2.2*cos(10*atan(x[1]/x[2])))**2 - x[1]**2 - x[2]**2 ;
return(c);
finish C_UC2D;

x = j(1,2,0.5);
optn= j(1,10,.);optn[1]=0; optn[2]= 1; optn[10]= 1;
CALL NLPNMS(rc,xres,"F_UC2D",x,optn) nlc="C_UC2D";

print rc[l='rc>0 means find a soultion'],xres[l='solution for x'];
quit;

 

 

ABSXCONV convergence criterion satisfied.
rc>0 means find a soultion
4
solution for x
-4.283178 5.7739759
Ksharp
Super User

I minimize object function,

If you want maximize it , use

optn[1]=1;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 816 views
  • 3 likes
  • 2 in conversation