Operations Research topics: SAS/OR,
SAS Optimization, and SAS Simulation Studio

how can i read parameters value automatically?

Accepted Solution Solved
Reply
Contributor
Posts: 38
Accepted Solution

how can i read parameters value automatically?

[ Edited ]

 

I have this problem and its works ok, but it´s possible read paramerts in data statement?

 

proc optmodel;
   var x {1..3};
   max z1 = (2*x[1]-3*x[2]+5*x[3])**3/(x[1]+5*x[2]+x[3]**2);
   con c1: -1<=x[1]<= 3;
   con c2: 1.5<=x[2]<= 2;
   con c3: 1.2<=x[3]<= 2.2;
   solve with nlp/multistart ;
   print x;
quit;



 Edit: I want to put in data statement:

 

 

-1<=x[1]<= 3;...

Accepted Solutions
Solution
3 weeks ago
SAS Employee
Posts: 492

Re: how can i read parameters value automatically?

data bounds;
   input lb ub;
   datalines;
-1   3
 1.5 2
 1.2 2.2
;

proc optmodel;
   var x {1..3};
   max z1 = (2*x[1]-3*x[2]+5*x[3])**3/(x[1]+5*x[2]+x[3]**2);
   read data bounds into [_N_] x.lb=lb x.ub=ub;
   solve with nlp/multistart ;
   print x;
quit;

View solution in original post


All Replies
Solution
3 weeks ago
SAS Employee
Posts: 492

Re: how can i read parameters value automatically?

data bounds;
   input lb ub;
   datalines;
-1   3
 1.5 2
 1.2 2.2
;

proc optmodel;
   var x {1..3};
   max z1 = (2*x[1]-3*x[2]+5*x[3])**3/(x[1]+5*x[2]+x[3]**2);
   read data bounds into [_N_] x.lb=lb x.ub=ub;
   solve with nlp/multistart ;
   print x;
quit;
Contributor
Posts: 38

Re: how can i read parameters value automatically?

[ Edited ]

if it will be possible to read coeficientes that multiplies x too? 

 

 

 

SAS Employee
Posts: 492

Re: how can i read parameters value automatically?

data bounds;
   input lb ub a b;
   datalines;
-1   3    2 1
 1.5 2   -3 5
 1.2 2.2  5 1
;

proc optmodel;
   var x {1..3};
   num a {1..3};
   num b {1..3};
   max z1 = (sum {j in 1..3} a[j]*x[j])**3/(b[1]*x[1]+b[2]*x[2]+b[3]*x[3]**2);
   read data bounds into [_N_] x.lb=lb x.ub=ub a b;
   solve with nlp/multistart ;
   print x;
quit;
Contributor
Posts: 38

Re: how can i read parameters value automatically?

[ Edited ]

edit: it works too

 

thanks rob!

 

 



data bounds;
   input lb ub a b;
   datalines;
-1   3    2 1
 1.5 2   -3 5
 1.2 2.2  5 1
;

proc optmodel;
   var x {1..3};
   num a {1..3};
   num b {1..3};
   max z1 = (sum {j in 1..3} a[j]*x[j])**3/ (sum {j in 1..3} b[j]*x[j]);
   read data bounds into [_N_] x.lb=lb x.ub=ub a b;
   solve with nlp/multistart ;
   print x;
quit;
SAS Employee
Posts: 492

Re: how can i read parameters value automatically?

[ Edited ]

Note that your original objective function had x[3]**2 in the denominator.  With your latest change, it is now just x[3].  If that is what you want, here's a way to make the code more data-driven (without hard-coding 1..3):

proc optmodel;
   set OBS;
   var x {OBS};
   num a {OBS};
   num b {OBS};
   max z1 = (sum {j in OBS} a[j]*x[j])**3/ (sum {j in OBS} b[j]*x[j]);
   read data bounds into OBS=[_N_] x.lb=lb x.ub=ub a b;
   solve with nlp/multistart ;
   print x;
quit;

This way, you can run again with different data without changing the PROC OPTMODEL code.  Such separation of model and data is a best practice enabled by the use of an algebraic modeling language.

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 300 views
  • 0 likes
  • 2 in conversation