I want to minimize an unconstrained NLP problem, having 4 variables. But, upon running the SAS file the solution status was failed and I got a warning that the "Objective function cannot be evaluated at the starting point." Can somebody PLEASE help me with this? I attached here the code. I am new to SAS by the way, it would be a great help for me.
proc optmodel;
var x{1..4} >=0 <=50;
min g=(-1) * ((-1) * (((10/x[1])^x[1]) * ((12/x[2])^x[2]) *
((0.5/(2*(0.4*x[3]-0.2*x[1]-1)))^(0.4*x[3]-0.2*x[1]-1)) *
((0.4/(2*(0.55*x[4]-0.6*x[2]-1)))^(0.55*x[4]-0.6*x[2]-1)) *
((50/(0.6*x[3]-0.8*x[1]))^(0.6*x[3]-0.8*x[1])) *
((60/(0.5*x[4]-0.4*x[2]))^(0.5*x[4]-0.4*x[2])) * ((100/x[3])^(-x[3])) *
((120/x[4])^(-x[4])) * ((((-0.34*x[3]-0.08*x[1]-0.475*x[4]+0.66*x[2]+3)*4)/(195*(-0.34*x[3]-0.08*x[1]+1.6)))^(-0.34*x[3]-0.08*x[1]+1.6))
* ((((-0.34*x[3]-0.08*x[1]-0.475*x[4]+0.66*x[2]+3)*2)/(195*(-0.475*x[4]-0.66*x[2]+1.4)))^(-0.475*x[4]+0.66*x[2]+1.4)))^(-1));
/* starting point */
x[1]=0.5;
x[2]=0.5;
x[3]=0.5;
x[4]=0.5;
solve with nlp / algorithm=activeset;
print x;
quit;
Because your objective function has product form, it is natural to minimize the log instead:
min log_g = -(
x[1]*log(10/x[1])
+ x[2]*log(12/x[2])
+ y[1]*log(0.5/(2*y[1]))
+ y[2]*log(0.4/(2*y[2]))
+ y[3]*log(50/y[3])
+ y[4]*log(60/y[4])
- x[3]*log(100/x[3])
- x[4]*log(120/x[4])
+ y[6]*log(y[5]*4/(195*y[6]))
+ y[7]*log(y[5]*2/(195*y[7]))
);
The resulting solution status is then Optimal rather than Best Feasible.
I have a suggestion that should help, but first I want to make sure that your objective function is defined correctly. In the final line of the MIN statement, did you really mean to have both -0.66*x[2] and +0.66*x[2], or should those coefficients be the same?
Hi Rob,
I am sorry for typo error, I mean to have only +0.66 in the objective function. By the way the objective function should be define by:
proc optmodel;
var x{1..4} >=0 <=50;
min g=(-1) * ((-1) * (((10/x[1])^x[1]) * ((12/x[2])^x[2]) *
((0.5/(2*(0.4*x[3]-0.2*x[1]-1)))^(0.4*x[3]-0.2*x[1]-1)) *
((0.4/(2*(0.55*x[4]-0.6*x[2]-1)))^(0.55*x[4]-0.6*x[2]-1)) *
((50/(0.6*x[3]-0.8*x[1]))^(0.6*x[3]-0.8*x[1])) *
((60/(0.5*x[4]-0.4*x[2]))^(0.5*x[4]-0.4*x[2])) * ((100/x[3])^(-x[3])) *
((120/x[4])^(-x[4])) * ((((-0.34*x[3]-0.08*x[1]-0.475*x[4]+0.66*x[2]+3)*4)/(195*(-0.34*x[3]-0.08*x[1]+1.6)))^(-0.34*x[3]-0.08*x[1]+1.6)) * ((((-0.34*x[3]-0.08*x[1]-0.475*x[4]+0.66*x[2]+3)*2)/(195*(-0.475*x[4]+0.66*x[2]+1.4)))^(-0.475*x[4]+0.66*x[2]+1.4)))^(-1));
/* starting point */
x[1]=0.5;
x[2]=0.5;
x[3]=0.5;
x[4]=0.5;
solve with nlp / algorithm=activeset;
print x;
quit;
One way to avoid typos is to use implicit variables to represent expressions that appear in multiple places:
impvar y {i in 1..7} =
if i = 1 then 0.4*x[3]-0.2*x[1]-1
else if i = 2 then 0.55*x[4]-0.6*x[2]-1
else if i = 3 then 0.6*x[3]-0.8*x[1]
else if i = 4 then 0.5*x[4]-0.4*x[2]
else if i = 5 then -0.34*x[3]-0.08*x[1]-0.475*x[4]+0.66*x[2]+3
else if i = 6 then -0.34*x[3]-0.08*x[1]+1.6
else if i = 7 then -0.475*x[4]+0.66*x[2]+1.4;
min g=(-1) * ((-1) * (((10/x[1])^x[1]) * ((12/x[2])^x[2]) *
((0.5/(2*y[1]))^y[1]) *
((0.4/(2*y[2]))^y[2]) *
((50/y[3])^y[3]) *
((60/y[4])^y[4]) * ((100/x[3])^(-x[3])) *
((120/x[4])^(-x[4])) * (((y[5]*4)/(195*y[6]))^y[6])
* (((y[5]*2)/(195*y[7]))^y[7]))^(-1));
With or without these changes, try using the multistart option:
solve with nlp / ms;
Hi there, I tried running the code that you sent me however I got this error saying "Statement is not valid or it is used out of proper order.
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 impvar y {i in 1..7} =
______
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
74 if i = 1 then 0.4*x[3]-0.2*x[1]-1
75 else if i = 2 then 0.55*x[4]-0.6*x[2]-1
76 else if i = 3 then 0.6*x[3]-0.8*x[1]
77 else if i = 4 then 0.5*x[4]-0.4*x[2]
78 else if i = 5 then -0.34*x[3]-0.08*x[1]-0.475*x[4]+0.66*x[2]+3
79 else if i = 6 then -0.34*x[3]-0.08*x[1]+1.6
80 else if i = 7 then -0.475*x[4]+0.66*x[2]+1.4;
81 min g=(-1) * ((-1) * (((10/x[1])^x[1]) * ((12/x[2])^x[2]) *
___
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
82 ((0.5/(2*y[1]))^y[1]) *
83 ((0.4/(2*y[2]))^y[2]) *
84 ((50/y[3])^y[3]) *
85 ((60/y[4])^y[4]) * ((100/x[3])^(-x[3])) *
86 ((120/x[4])^(-x[4])) * (((y[5]*4)/(195*y[6]))^y[6])
87 * (((y[5]*2)/(195*y[7]))^y[7]))^(-1));
88
89 solve with nlp / ms;
_____
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
90
91 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
104
Hi Rob, I just want to ask what if I run this code and I don't want to set an upper bound for my Variables X[1].. X[4], therefore I would like them only to be greater than or equal to zero. However, I've tried running this code multiple times and I've got different results for X and it only says that it has only the "best feasible solution" everytime I run it. I was just concerned about how can I deal with this type of problem? or Can we have options other than multistart, or shall we incorporate a search method for this? I'm clueless. Thanks for the help! 🙂
proc optmodel;
var x{1..4} >=0;
min g=(-1) * ((-1) * (((10/x[1])^x[1]) * ((12/x[2])^x[2]) *
((0.5/(2*(0.4*x[3]-0.2*x[1]-1)))^(0.4*x[3]-0.2*x[1]-1)) *
((0.4/(2*(0.55*x[4]-0.6*x[2]-1)))^(0.55*x[4]-0.6*x[2]-1)) *
((50/(0.6*x[3]-0.8*x[1]))^(0.6*x[3]-0.8*x[1])) *
((60/(0.5*x[4]-0.4*x[2]))^(0.5*x[4]-0.4*x[2])) * ((100/x[3])^(-x[3])) *
((120/x[4])^(-x[4])) * ((((-0.34*x[3]-0.08*x[1]-0.475*x[4]+0.66*x[2]+3)*4)/(195*(-0.34*x[3]-0.08*x[1]+1.6)))^(-0.34*x[3]-0.08*x[1]+1.6))
* ((((-0.34*x[3]-0.08*x[1]-0.475*x[4]+0.66*x[2]+3)*2)/(195*(-0.475*x[4]+0.66*x[2]+1.4)))^(-0.475*x[4]+0.66*x[2]+1.4)))^(-1));
impvar y {i in 1..7} =
if i = 1 then 0.4*x[3]-0.2*x[1]-1
else if i = 2 then 0.55*x[4]-0.6*x[2]-1
else if i = 3 then 0.6*x[3]-0.8*x[1]
else if i = 4 then 0.5*x[4]-0.4*x[2]
else if i = 5 then -0.34*x[3]-0.08*x[1]-0.475*x[4]+0.66*x[2]+3
else if i = 6 then -0.34*x[3]-0.08*x[1]+1.6
else if i = 7 then -0.475*x[4]+0.66*x[2]+1.4;
min f=(-1) * ((-1) * (((10/x[1])^x[1]) * ((12/x[2])^x[2]) *
((0.5/(2*y[1]))^y[1]) *
((0.4/(2*y[2]))^y[2]) *
((50/y[3])^y[3]) *
((60/y[4])^y[4]) * ((100/x[3])^(-x[3])) *
((120/x[4])^(-x[4])) * (((y[5]*4)/(195*y[6]))^y[6])
* (((y[5]*2)/(195*y[7]))^y[7]))^(-1));
solve with nlp / ms;
print x;
Because your objective function has product form, it is natural to minimize the log instead:
min log_g = -(
x[1]*log(10/x[1])
+ x[2]*log(12/x[2])
+ y[1]*log(0.5/(2*y[1]))
+ y[2]*log(0.4/(2*y[2]))
+ y[3]*log(50/y[3])
+ y[4]*log(60/y[4])
- x[3]*log(100/x[3])
- x[4]*log(120/x[4])
+ y[6]*log(y[5]*4/(195*y[6]))
+ y[7]*log(y[5]*2/(195*y[7]))
);
The resulting solution status is then Optimal rather than Best Feasible.
Indeed the solution that you recommended was brilliant and I thank you for that. I never had that idea before 🙂 In line with this, I tried this approach in evaluating the optimal values for another unconstrained minimization, however, it says that the solution status is failed. I guess I've had some problem with formulation? or in dealing with this type should require other type of solver?
proc optmodel;
var x{1..4} >=0;
impvar y {i in 1..8} =
if i = 1 then -((-0.6*4.5)/(1.6*5.5))*x[1]-(4.5/5.5)*x[3]
else if i = 2 then -((-0.7*5.2)/(1.7*6.2))*x[2]-(5.2/6.2)*x[4]
else if i = 3 then (-1/0.72)+((1/0.72)+((-0.6*15.5)/(0.72*1.6*5.5)))*x[1]+((15.5/(0.72*5.5))-((1/0.72)+1))*x[3]
else if i = 4 then (-1/0.78)+((1/0.78)+((-0.7*17.6)/(0.78*1.7*6.2)))*x[2]+((17.6/(0.78*6.2))-((1/0.78)+1))*x[4]
else if i = 5 then (0.6/(1.6*5.5))*x[1]-(1/5.5)*x[3]
else if i = 6 then (0.7/(1.7*6.2))*x[2]-(1/6.2)*x[4]
else if i = 7 then (-1/0.72)+((1/0.72)+(((4.5*5.5)/0.72)+(2/0.72)+1)*(-0.6/1.6))*x[1]-(((5.5*4.5)+1)/0.72)*x[3]
else if i = 8 then (-1/0.78)+((1/0.78)+(((5.2*6.2)/0.78)+(2/0.78)+1)*(-0.7/1.7))*x[2]-(((5.2*6.2)+1)/0.78)*x[4];
min log_h = -(
- x[1]*log(3500/(300*x[1]))
- x[2]*log(4000/(300*x[2]))
+ x[3]*log(175/x[3])
+ x[4]*log(64000/(300*x[4]))
+ y[1]*log(3500/(300*y[1]))
+ y[2]*log(4000/(300*y[2]))
+ y[3]*log(0.15/(600*y[3]))
+ y[4]*log(0.2/(600*y[4]))
+ y[5]*log(5250/y[5])
+ y[6]*log(2000000/(300*y[6]))
- y[7]*log(3.9/(45*y[7]))
- y[8]*log(4.3/(45*y[8]))
);
solve with nlp / ms;
print x;
quit;
The log function requires a positive argument, and that implies that each x[i] and y[i] should be positive. But x[2], y[4], and y[8] cannot all be nonnegative, as detected by using the IIS functionality:
con c {i in 1..8}: y[i] >= 0;
solve noobj with lp / iis=on;
expand / iis;
SAS Output
Var x[2] >= 0 Constraint c[4]: y[4] >= 0 Constraint c[8]: y[8] >= 0 |
Now expand y[4] and y[8]:
expand y[4];
expand y[8];
SAS Output
Impvar y[4] = 1.3573200993*x[4] - 0.2165134044*x[2] - 1.2820512821 |
Impvar y[8] = - 42.615384615*x[4] - 17.205128205*x[2] - 1.2820512821 |
Indeed, x[2] >= 0 and y[4] >= 0 together imply x[4] >= 0, which forces y[8] < 0. I would recommend checking your formula for y[8], which should not have all coefficients negative.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.