[rge, obviously]. I am trying to learn and use proc optmodel (replacing an older program someone else wrote with proc nlp, which didn't really work as desired anyway.) Am I doing this at all correctly? Here is my code: proc optmodel;
/*decision variables*/
var n {1..&n};
var denom;
var sum_n;
number pop {1..&n};
number p_rate {1..&n};
read data ced_rates into [_n_] pop p_rate;
denom = sum{k in 1..&n} n[k] * p_rate[k];
minimize sum_sqrs = sum {j in 1..&n.} ((n[j] * p_rate[j] / denom) - (pop[j] / &usa_population.))**2;
sum_n = sum{k in 1..&n} n[k];
/*problem constraints*/
con sum_n = &n_usa.,
p_rate[1] * n[1] >= &n_min_urban.,
p_rate[2] * n[2] >= &n_min_urban.,
p_rate[3] * n[3] >= &n_min_urban.,
p_rate[4] * n[4] >= &n_min_urban.,
p_rate[5] * n[5] >= &n_min_urban.,
p_rate[6] * n[6] >= &n_min_urban.,
p_rate[7] * n[7] >= &n_min_urban.,
p_rate[8] * n[8] >= &n_min_urban.,
p_rate[9] * n[9] >= &n_min_urban.,
p_rate[10]*n[10] >= &n_min_rural.,
p_rate[11]*n[11] >= &n_min_rural.,
p_rate[12]*n[12] >= &n_min_rural.,
p_rate[13]*n[13] >= &n_min_rural.,
p_rate[14]*n[14] >= &n_min_rural.,
p_rate[15]*n[15] >= &n_min_rural.,
p_rate[16]*n[16] >= &n_min_rural.,
p_rate[17]*n[17] >= &n_min_rural.,
p_rate[18]*n[18] >= &n_min_rural.,
p_rate[19]*n[19] >= &n_min_urban.,
p_rate[20]*n[20] >= &n_min_urban.,
p_rate[21]*n[21] >= &n_min_urban.,
p_rate[22]*n[22] >= &n_min_urban.,
p_rate[23]*n[23] >= &n_min_urban.,
p_rate[24]*n[24] >= &n_min_urban.,
p_rate[25]*n[25] >= &n_min_urban.,
p_rate[26]*n[26] >= &n_min_urban.,
p_rate[27]*n[27] >= &n_min_urban.,
p_rate[28]*n[28] >= &n_min_urban.,
p_rate[29]*n[29] >= &n_min_urban.,
p_rate[30]*n[30] >= &n_min_urban.,
p_rate[31]*n[31] >= &n_min_urban.,
p_rate[32]*n[32] >= &n_min_urban.,
p_rate[33]*n[33] >= &n_min_urban.,
p_rate[34]*n[34] >= &n_min_urban.,
p_rate[35]*n[35] >= &n_min_urban.,
p_rate[36]*n[36] >= &n_min_urban.,
p_rate[37]*n[37] >= &n_min_urban.,
p_rate[38]*n[38] >= &n_min_urban.,
p_rate[39]*n[39] >= &n_min_urban.,
p_rate[40]*n[40] >= &n_min_urban.,
p_rate[41]*n[41] >= &n_min_urban.;
solve;
print n;
print sum_sqrs;
quit; (I wanted the number of constraints to be dynamic (&n. = 41), but I couldn't figure out a way to do that.) I guess the major problem is that the log shows WARNING: Objective function cannot be evaluated at starting point. NOTE: Did not converge. and then a bunch of "NOTE: Division by zero at line"... lines. Another problem is that, when the program does print out the 41 n values, they do NOT add up to the desired total, &n_usa. (They are all given values greater than their constraint minimums, so at least that's something.) The sum_sqrs variable is output as "." What am I doing wrong? (Am I doing anything right, even?) Thanks in advance for any help or constructive input.
... View more