var TAMS_TAF1 {d in ND, t in F1[d], s in NS, c in NC} = if TA_MRS_SAT[d,t,s,c] <= TA_F1[d,t,s] then 1 else 0;
var TAMS_TAF1 {d in ND, t in F1[d], s in NS, c in NC} binary; subject to TAMS_TAF1_define {d in ND, t in F1[d], s in NS, c in NC}: TAMS_TAF1[d,t,s,c] = 1 ==> TA_MRS_SAT[d,t,s,c] <= TA_F1[d,t,s] else TA_MRS_SAT[d,t,s,c] >= TA_F1[d,t,s];
Hi Mr Robert,
The statements I wrote in the variables description are the followings:
var TA_F1 {d in ND, t in F1[d], i in (ND union NS) } >= 0 ;
var TA_MRS_SAT {d in ND, t in F1[d], s in NS, c in NC} >= 0 ;
var TD_MRS_SAT {s in NS, c in NC} >= 0 ;
var TAMS_TAF1 {d in ND, t in F1[d], s in NS, c in NC} = if TA_MRS_SAT[d,t,s,c] <= TA_F1[d,t,s] then 1 else 0;
var TAF1_TDMS {d in ND, t in F1[d], s in NS, c in NC} = if TA_F1[d,t,s] <= TD_MRS_SAT[s,c] then 1 else 0;
var TAMSTAF1_TAF1TDMS {d in ND, t in F1[d], s in NS, c in NC} = if TAMS_TAF1[d,t,s,c]=TAF1_TDMS[d,t,s,c]=1 then 1 else 0;
They contain the "if-then-else" expression as you have mentioned before, perhaps it because of this I have the notice of " nonquadratic nonlinear constraints" from Gurobi.
I would like to aks you how I can write those variables so that they can be accepted by Gurobi.
Thanks a lot for your support.
Best Regards.
On Tue, Apr 21, 2020 at 4:28 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
You might have some logical expression in your constraints, which Gurobi would reject as "nonlinear" since it is not a linear expression. For example, an "if-then" or "if-then-else" construct will be considered nonlinear if there are variables in the expression after "if". However, for a simple logical condition like the one that defines your variable e_ih^m, there is often a reformulation that Gurobi does accept.
To get more help, try attaching the file that has your model in it, and also your data file if that is practical.
--
Robert Fourer
am...@googlegroups.com
subject to Contrainte_3 {d in ND, i in NS, j in NS: i <> j, c in NC, m in NC: m<>c}:
sum {t in F1[d]}( X_F1[d,t,i,j]+TRUCK_CUST[d,t,i,c]+TRUCK_CUST[d,t,j,m]) <= 2 ;
Hi Robert,
I write to you again because I have an another preoccupation.
I wrote this equation and I got syntax error statement:
subject to Contrainte_3 {d in ND, i in NS, j in NS: i <> j, c in NC, m in NC: m<>c}:
sum {t in F1[d]}( X_F1[d,t,i,j]+TRUCK_CUST[d,t,i,c]+TRUCK_CUST[d,t,j,m]) <= 2 ;
I would like to ask you how to write variables wtih are different twice time in the bracket in front of contrainte _3{ }.
Best regards.
On Thu, Apr 23, 2020 at 4:00 AM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Hi Robert,
Thanks a lot. Your help is very precious for me.
Best Regards.
On Thu, Apr 23, 2020 at 3:55 AM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:Hi Robert,
Many thanks for your help. It is very precious for me.
On Wed, Apr 22, 2020 at 7:13 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
To satisfy Gurobi, write these variable definitions as "indicator constraints" instead. For example, you havevar TAMS_TAF1 {d in ND, t in F1[d], s in NS, c in NC} = if TA_MRS_SAT[d,t,s,c] <= TA_F1[d,t,s] then 1 else 0;
For Gurobi, define a binary variable and a separate constraint:var TAMS_TAF1 {d in ND, t in F1[d], s in NS, c in NC} binary; subject to TAMS_TAF1_define {d in ND, t in F1[d], s in NS, c in NC}: TAMS_TAF1[d,t,s,c] = 1 ==> TA_MRS_SAT[d,t,s,c] <= TA_F1[d,t,s] else TA_MRS_SAT[d,t,s,c] >= TA_F1[d,t,s];
The ==> operator means "implies". For a constraint using ==> to be an indicator constraint, the expression to the left must be "binary-variable = 0" or "binary-variable=1". The above formulation allows TAMS_TAF1[d,t,s,c] to be either 1 or 0 when TA_MRS_SAT[d,t,s,c] = TA_F1[d,t,s]; if you don't want to permit that, you could try something like TA_MRS_SAT[d,t,s,c] >= TA_F1[d,t,s] + 0.0001 in the "else" part. (It's not possible to enforce > on continuous variables in optimization problems.)
TAF1_TDMS would be handled similarly. In TAMSTAF1_TAF1TDMS, AMPL doesn't recognize the double-constraint TAMS_TAF1[d,t,s,c]=TAF1_TDMS[d,t,s,c]=1, but since TAMS_TAF1[d,t,s,c] and TAF1_TDMS[d,t,s,c] and both zero-one (binary) variables, you can write that equivalently as TAMS_TAF1[d,t,s,c]+TAF1_TDMS[d,t,s,c]=2, and then apply the same approach as for the previous constraints.
--
Robert Fourer
am...@googlegroups.com
Hi Mr Robert,
I rewrote the variable that I wrote incorrectly (var TAMSTAF1_TAF1TDMS {d in ND, t in F1[d], s in NS, c in NC} = if TAMS_TAF1[d,t,s,c]=TAF1_TDMS[d,t,s,c]=1 then 1 else 0 ) this way:
subject to TAMSTAF1_TAF1TDMS_define {d in ND, t in F1[d], s in NS, c in NC}:
TAMSTAF1_TAF1TDMS[d,t,s,c] = 1 ==>
TAMS_TAF1[d,t,s,c]+TAF1_TDMS[d,t,s,c]=2 else
TAMS_TAF1[d,t,s,c]+TAF1_TDMS[d,t,s,c]=2-0.0001;
I would like to ask you if this formulation is correct.
Best regards.
On Sat, Apr 25, 2020 at 2:52 AM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:Thank you very much!
On Fri, Apr 24, 2020 at 5:07 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
Place all of the conditions at the end of the indexing expression, like this:
subject to Contrainte_3
{d in ND, i in NS, j in NS, c in NC, m in NC: i<>j and m<>c}: . . .
On Fri, Apr 24, 2020 at 9:54 AM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Hi Robert,
I write to you again because I have an another preoccupation.
I wrote this equation and I got syntax error statement:
subject to Contrainte_3 {d in ND, i in NS, j in NS: i <> j, c in NC, m in NC: m<>c}:
sum {t in F1[d]}( X_F1[d,t,i,j]+TRUCK_CUST[d,t,i,c]+TRUCK_CUST[d,t,j,m]) <= 2 ;
I would like to ask you how to write variables wtih are different twice time in the bracket in front of contrainte _3{ }.
Best regards.
On Thu, Apr 23, 2020 at 4:00 AM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Hi Robert,
Thanks a lot. Your help is very precious for me.
Best Regards.
On Thu, Apr 23, 2020 at 3:55 AM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Hi Robert,
Many thanks for your help. It is very precious for me.
On Wed, Apr 22, 2020 at 7:13 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
To satisfy Gurobi, write these variable definitions as "indicator constraints" instead. For example, you havevar TAMS_TAF1 {d in ND, t in F1[d], s in NS, c in NC} = if TA_MRS_SAT[d,t,s,c] <= TA_F1[d,t,s] then 1 else 0;
For Gurobi, define a binary variable and a separate constraint:var TAMS_TAF1 {d in ND, t in F1[d], s in NS, c in NC} binary; subject to TAMS_TAF1_define {d in ND, t in F1[d], s in NS, c in NC}: TAMS_TAF1[d,t,s,c] = 1 ==> TA_MRS_SAT[d,t,s,c] <= TA_F1[d,t,s] else TA_MRS_SAT[d,t,s,c] >= TA_F1[d,t,s];
The ==> operator means "implies". For a constraint using ==> to be an indicator constraint, the expression to the left must be "binary-variable = 0" or "binary-variable=1". The above formulation allows TAMS_TAF1[d,t,s,c] to be either 1 or 0 when TA_MRS_SAT[d,t,s,c] = TA_F1[d,t,s]; if you don't want to permit that, you could try something like TA_MRS_SAT[d,t,s,c] >= TA_F1[d,t,s] + 0.0001 in the "else" part. (It's not possible to enforce > on continuous variables in optimization problems.)
TAF1_TDMS would be handled similarly. In TAMSTAF1_TAF1TDMS, AMPL doesn't recognize the double-constraint TAMS_TAF1[d,t,s,c]=TAF1_TDMS[d,t,s,c]=1, but since TAMS_TAF1[d,t,s,c] and TAF1_TDMS[d,t,s,c] and both zero-one (binary) variables, you can write that equivalently as TAMS_TAF1[d,t,s,c]+TAF1_TDMS[d,t,s,c]=2, and then apply the same approach as for the previous constraints.
--
Robert Fourer
am...@googlegroups.com
Hi Sir,
Thanks very much for reply.
But how can I write TAMS_TAF1[d,t,s,c] + TAF1_TDMS[d,t,s,c] to tell that it must equal 0 or 1?
Like this?
subject to TAMSTAF1_TAF1TDMS_define {d in ND, t in F1[d], s in NS, c in NC}:
TAMSTAF1_TAF1TDMS[d,t,s,c] = 1 ==>
TAMS_TAF1[d,t,s,c]+TAF1_TDMS[d,t,s,c]=2 else
TAMS_TAF1[d,t,s,c]+TAF1_TDMS[d,t,s,c]=0 or 1;
On Mon, Apr 27, 2020 at 5:39 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
In the "else" part of your constraint, you have
TAMS_TAF1[d,t,s,c] + TAF1_TDMS[d,t,s,c] = 2 - 0.0001
But as I understand your problem, TAMS_TAF1[d,t,s,c] and TAF1_TDMS[d,t,s,c] are supposed to be variables that only take the value 0 or 1. Thus TAMS_TAF1[d,t,s,c] + TAF1_TDMS[d,t,s,c] can only be 0, 1, or 2 -- and it cannot be 2 - 0.0001.
So the "else" part will need to be fixed. You want to specify an inequality that lets TAMS_TAF1[d,t,s,c] + TAF1_TDMS[d,t,s,c] equal 0 or 1, but not 2.
--
Robert Fourer
am...@googlegroups.com