# [AMPL 24879] Searching for the starting date of the project using a binary variable Act(j,t)

Hi,

I would like to know what’s the problem with all the statements that I tried to use in order to search about the first date t in T where Act[j,t] equals to 1.

In fact, Act[i,j] is a binary variable which equals to 1 is the project j is executed in the period t and 0 otherwise.

I am trying to express the starting and finishing date of my model using the variable Act[i,j] where :

• Start = the first date t where Act[j,t]=1
• Finish= the last date t where Act[j,t]=1

For Finish date, I used the following statement, and it is working :

subject to FinContrainte{j in P}:

Fin[j] = max {t in T} (t * Act[j, t]);

However, for the start date none of the following statement worked :

subject to DebutContrainte{j in P}:
Debut[j] = ord(t in T: Act[j, t] > 0, t); #Here it said syntax error

subject to DebutContrainte{j in P}:
Debut[j] = ord(t in T, (Act[j, t] = 1)); #Here it said syntax error as well

subject to FinContrainte{j in P}:

Debut[j] = min {t in T} (t * Act[j, t]); #Here it just presents Debut = 0 as there is no condition on Act(j,t)

subject to DebutContrainte{j in P}:
Debut[j] = ord(t, (t in T)\$(Act[j, t] = 1)); #Here it said syntax error as well

For the following statement :

subject to DebutContrainte{j in P}:

Debut[j] = min {t in T: Act[j, t] = 1} t; it shows variable in such-that part of set specification

context: Debut[j] = min {t in T: Act[j, t] = >>> 1} <<< t;

Hi,

Debut[j] = min {t in T} (t * Act[j, t]);

would work if you had constraints on Act preventing them to become 1 before actual start.

Depending on the difficulty of your instances, you might want a more efficient formulation using auxiliary variables S0[j, t] (“start on or before) and S1 (start on) and constraints

S0[j, 1] = Act[j, 1];
S0[j, t] >= Act[j, t];
S0[j, t] >= S0[j, t-1];
S0 jT = 1;

S1 j1 = S0 j1;
S1 jt = S0 jt - S0 j,t-1;
S1 jt <= Act jt;

Depending on your model, you might need only a part of these. For example, when minimising the sum of completion times, “end on or after” variables can be maximised.

EDIT.

You are right, the start time cannot be constrained by

``````Debut[j] = min {t in T} (t * Act[j, t]);
``````

because any time slot with `Act[j, t]=0` sets it to 0. Instead, go as follows:

``````Debut[j] = T - max {t in T} ((T-t) * Act[j, t]);
``````

For the alternative modeling with binary variables S0/S1, the start time can be computed as

``````Debut[j] = sum {t in T} (t * S1[j, t]);
``````

Good afternoon,

The following one works perfectly :
Debut[j] = T - max {t in T} ((T-t) * Act[j, t]);

Many thanks!!!

Good afternoon,

The following one works perfectly : Debut[j] = T - max {t in T} ((T-t) * Act[j, t]);

Thank you so much