|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
[AMPL 2627] obtaining minimum between two variablesHi, I need to obtain the minimum between two variables. The idea is the following: -------------- set NODES; var X {NODES}; var Y {NODES}; var Z {NODES}; minimize: sum {n in NODES} Z[n]; s.t. s.t. .... subject to minimum {n in NODES}: Z[n] = min { X[n], Y[n] }; --------------------------------------------- I'm working with cplex and all the constraints must be linear and the variables X and Y contains a cost, with different elements I have calculated too with the other constraints... Can I make it with CPLEX? Thanks, --~--~---------~--~----~------------~-------~--~----~ 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 2630] Re: obtaining minimum between two variablesOn Jul 6, 2:24 pm, plozmar <lozano_pal...@...> wrote: > Hi, > > I need to obtain the minimum between two variables. The idea is the > following: > > -------------- > set NODES; > > var X {NODES}; > var Y {NODES}; > var Z {NODES}; > > minimize: > > sum {n in NODES} Z[n]; > > s.t. > s.t. > .... > > subject to minimum {n in NODES}: > > Z[n] = min { X[n], Y[n] }; > > --------------------------------------------- > I'm working with cplex and all the constraints must be linear and the > variables X and Y contains a cost, with different elements I have > calculated too with the other constraints... > > Can I make it with CPLEX? > I assume X and Y (and hence Z) are nonnegative. If you know upper bounds for X and Y, and can cope with binary variables (making the model a MILP), then yes. var B {NODES} binary; param MX {NODES}; # MX[n] is a valid a priori upper bound on X[n] param MY {NODES}; # MY[n] is a valid a priori upper bound on Y[n] ... s.t. Zdef1 {n in NODES}: Z[n] >= X[n] - MX[n]*B[n]; s.t. Zdef2 {n in NODES}: Z[n] >= Y[n] - MY[n]*(1 - B[n]); If Z[n] is not used anywhere in the model other than the objective, this is sufficient; the solver will set B[n] based on whichever value produces the smaller value of Z[n]. If Z[n] is used in other constraints, so that there is a danger the solver might "want" to pick a value of Z[n] greater than the min of X[n] and Y[n], then you also need the following: s.t. Xsmaller {n in NODES}: X[n] <= Y[n] + MX[n]*B[n]; # X <= Y if B = 0 s.t. Ysmaller {n in NODES}: Y[n] <= X[n] + MY[n]*(1 - B[n]); # Y <= X if B = 1 s.t. Zmax1 {n in NODES}: Z[n] <= X[n] + MX[n]*B[n]; s.t. Zmax2 {n in NODES}: Z[n] <= Y[n] + MY[n]*(1 - B[n]); /Paul --~--~---------~--~----~------------~-------~--~----~ 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 |