|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
[AMPL 2150] variable number of variablesHi all, I'd like to do something like this: var n integer >= 1, <= 1000; Then, I want to have variables x_1, x_2, ... , x_k where k=log(n), with each x_i being a positive integer and each having a different upper limit (derived from n in a systematic way). Is there a way to code this in AMPL? Eagerly awaiting suggestions, x --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group. To post to this group, send email to ampl@... To unsubscribe from this group, send email to ampl+unsubscribe@... For more options, visit this group at http://groups.google.com/group/ampl?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
[AMPL 2152] Re: variable number of variablesThe general rule for optimization models with a variable number of variables (this is not AMPL-specific) is to allocate the maximum number of variables you might conceivably need and then use constraints to "turn off" the excess variables. I'll use common logs below to illustrate (just to make my life easier). Since you did not specify how to handle "k=log(n)" when log(n) is not an integer, I'll assume you meant to round up. param M >= 0; # a priori upper bound for all var n integer >= 1, <= 1000; var x {1..3} integer >= 0 <= M; # because log_10(1000) = 3 var y {2..3} binary; # controls use of x; x[1] always exists s.t. nSize: n >= 1 + 10*y[2] + 90*y[3]; # need n >= 11 to have x2, n >= 101 to have x3 s.t. yorder: y[2] >= y[3]; # can't have x3 until you have x2 s.t. useX {i in 2..3}: x[i] <= M*y[i]; # turn x2, x3 on or off To derive upper bounds for the x[i] that depend on n, you'll need additional constraints. Assuming those bounds are linear functions of n, you don't want to use them in place of the a priori constant bound M in the useX constraints, since multiplying them by y[i] creates a nonlinear constraint. (If the bounds are not linear, or at least piecewise linear, in n, you're already staring at a nonlinear model.) /Paul x wrote: > Hi all, > > I'd like to do something like this: > > var n integer >= 1, <= 1000; > > Then, I want to have variables x_1, x_2, ... , x_k where k=log(n), > with each x_i being a positive integer and > each having a different upper limit (derived from n in a systematic > way). > > Is there a way to code this in AMPL? > > Eagerly awaiting suggestions, > x You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group. To post to this group, send email to ampl@... To unsubscribe from this group, send email to ampl+unsubscribe@... For more options, visit this group at http://groups.google.com/group/ampl?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
[AMPL 2364] Re: variable number of variablesA follow-up question below. I've: param N_MAX = 1000; var N >= 1, <= N_MAX; var x {0 .. N_MAX} >= 0; The number of x depends on N and I control this as Paul had suggested. But now, I want to do *something like*: subject to {i in {(N/2)-1, (N/2)+1} }: #calculation of indices simplified for sake of discussion x[i] = 1000; #RHS simplified for sake of discussion But of course I can't use variables for indexing. Neither can I do it explicitly as there are too many possible values that N can take. As always, in true appreciation of suggestions, x On Sat, Jan 10, 2009 at 9:49 AM, Paul <rubin@...> wrote: > > The general rule for optimization models with a variable number of > variables (this is not AMPL-specific) is to allocate the maximum > number of variables you might conceivably need and then use > constraints to "turn off" the excess variables. I'll use common logs > below to illustrate (just to make my life easier). Since you did not > specify how to handle "k=log(n)" when log(n) is not an integer, I'll > assume you meant to round up. > > param M >= 0; # a priori upper bound for all > var n integer >= 1, <= 1000; > var x {1..3} integer >= 0 <= M; # because log_10(1000) = 3 > var y {2..3} binary; # controls use of x; x[1] always exists > > s.t. nSize: n >= 1 + 10*y[2] + 90*y[3]; # need n >= 11 to have x2, n >>= 101 to have x3 > s.t. yorder: y[2] >= y[3]; # can't have x3 until you have x2 > s.t. useX {i in 2..3}: x[i] <= M*y[i]; # turn x2, x3 on or off > > To derive upper bounds for the x[i] that depend on n, you'll need > additional constraints. Assuming those bounds are linear functions of > n, you don't want to use them in place of the a priori constant bound > M in the useX constraints, since multiplying them by y[i] creates a > nonlinear constraint. (If the bounds are not linear, or at least > piecewise linear, in n, you're already staring at a nonlinear model.) > > /Paul > > x wrote: >> Hi all, >> >> I'd like to do something like this: >> >> var n integer >= 1, <= 1000; >> >> Then, I want to have variables x_1, x_2, ... , x_k where k=log(n), >> with each x_i being a positive integer and >> each having a different upper limit (derived from n in a systematic >> way). >> >> Is there a way to code this in AMPL? >> >> Eagerly awaiting suggestions, >> x > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group. To post to this group, send email to ampl@... To unsubscribe from this group, send email to ampl+unsubscribe@... For more options, visit this group at http://groups.google.com/group/ampl?hl=en -~----------~----~----~----~------~----~------~--~--- |
| Free embeddable forum powered by Nabble | Forum Help |