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

**URL:** <https://discuss.ampl.com/t/ampl-24879-searching-for-the-starting-date-of-the-project-using-a-binary-variable-act-j-t/799>\
**Category:** Google Group Mirror\
**Created:** [November 11, 2023, 5:26pm UTC](https://discuss.ampl.com/t/ampl-24879-searching-for-the-starting-date-of-the-project-using-a-binary-variable-act-j-t/799 "2023-11-11T17:26:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Basma\_Ben\_Mahmoud](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/basma_ben_mahmoud/32/612_2.png) [@Basma\_Ben\_Mahmoud](https://discuss.ampl.com/u/Basma_Ben_Mahmoud)\
**Post date:** [November 11, 2023, 5:26pm UTC](https://discuss.ampl.com/t/ampl-24879-searching-for-the-starting-date-of-the-project-using-a-binary-variable-act-j-t/799/1 "2023-11-11T17:26:07Z")

</div>

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;

Thanks in advance!!!

---

<div class="post-metadata">

**Author:** ![AMPL\_Google\_Group](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@AMPL\_Google\_Group](https://discuss.ampl.com/u/AMPL_Google_Group)\
**Post date:** [November 12, 2023, 11:48pm UTC](https://discuss.ampl.com/t/ampl-24879-searching-for-the-starting-date-of-the-project-using-a-binary-variable-act-j-t/799/2 "2023-11-12T23:48:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![AMPL\_Google\_Group](https://avatars.discourse-cdn.com/v4/letter/a/9dc877/32.png) [@AMPL\_Google\_Group](https://discuss.ampl.com/u/AMPL_Google_Group)\
**Post date:** [November 13, 2023, 1:15am UTC](https://discuss.ampl.com/t/ampl-24879-searching-for-the-starting-date-of-the-project-using-a-binary-variable-act-j-t/799/3 "2023-11-13T01:15:56Z")

</div>

EDIT.

You are right, the start time cannot be constrained by

```ampl
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:

```ampl
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

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

```

---

<div class="post-metadata">

**Author:** ![Basma\_Ben\_Mahmoud](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/basma_ben_mahmoud/32/612_2.png) [@Basma\_Ben\_Mahmoud](https://discuss.ampl.com/u/Basma_Ben_Mahmoud)\
**Post date:** [November 13, 2023, 3:30am UTC](https://discuss.ampl.com/t/ampl-24879-searching-for-the-starting-date-of-the-project-using-a-binary-variable-act-j-t/799/4 "2023-11-13T03:30:37Z")

</div>

Good afternoon,

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

Many thanks!!!

---

<div class="post-metadata">

**Author:** ![Basma\_Ben\_Mahmoud](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/basma_ben_mahmoud/32/612_2.png) [@Basma\_Ben\_Mahmoud](https://discuss.ampl.com/u/Basma_Ben_Mahmoud)\
**Post date:** [November 13, 2023, 3:27am UTC](https://discuss.ampl.com/t/ampl-24879-searching-for-the-starting-date-of-the-project-using-a-binary-variable-act-j-t/799/5 "2023-11-13T03:27:47Z")

</div>

Good afternoon,

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

Thank you so much
