# Find a starting date of the project using an alternative linear expression than min function

**URL:** <https://discuss.ampl.com/t/find-a-starting-date-of-the-project-using-an-alternative-linear-expression-than-min-function/1977>\
**Category:** Support\
**Created:** [November 8, 2024, 5:02am UTC](https://discuss.ampl.com/t/find-a-starting-date-of-the-project-using-an-alternative-linear-expression-than-min-function/1977 "2024-11-08T05:02:22Z")\
**Posts on this page:** 4\
**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 8, 2024, 5:02am UTC](https://discuss.ampl.com/t/find-a-starting-date-of-the-project-using-an-alternative-linear-expression-than-min-function/1977/1 "2024-11-08T05:02:22Z")

</div>

Hi,

I am working on an allocation and scheduling model.  
I would like to identify the optimal starting `D[j]` and finishing `F[j]` dates of each project `j`.  
These dates depend on the resource demand for each project as well as resources availabilities.

Binary variable `Act[j,t]` is used to know if the project is being executed during the period `t` from `T` or not and to be able to express the number of human resource being consumed by each project `j` at period `t`.  
Thus :

```auto
subject to DurationConstraint {j in P}:
   sum{t in T} Act[j,t] = Duration[j];

```

Breaks are allowed means if there is not enough resources to execute all projects together, some projects could be interrupted for a certain time while respecting the deadline `LF[j]`.

I would like to express the starting and finishing dates while using linear constraints, as I have only access to Cplex. I could not use other solver that accept the min and max constraints or other non-convex constraints.

The finishing date is solved as follows :

```auto
subject to Max_Constraint{j in P, t in T}: 
   t * Act[j,t] <= FinMax[j];  
subject to Define_Fin{j in P}: 
   F[j] = FinMax[j];  

```

However, I could not find the right expression to define the starting date `D[j]` such as `D[j]` = the first period `t` in which `Act[j,t]` `=` `1`.

Thank you!

Best regards,

---

<div class="post-metadata">

**Author:** ![4er](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/4er/32/530_2.png) [@4er](https://discuss.ampl.com/u/4er)\
**Post date:** [November 10, 2024, 5:32pm UTC](https://discuss.ampl.com/t/find-a-starting-date-of-the-project-using-an-alternative-linear-expression-than-min-function/1977/2 "2024-11-10T17:32:34Z")

</div>

The current version of CPLEX for AMPL is based on the new [MP interface](https://mp.ampl.com/model-guide.html), which accepts many functions, operators, and expressions — including `min` and `max` — that are nonlinear or logical, and that can be used to write nonconvex objectives and constraints.

- To learn more, see our page on MP [Expressions Supported](https://mp.ampl.com/modeling-expressions.html).
- To get the current CPLEX for AMPL, log in to the [AMPL Download Portal](https://portal.ampl.com).

Your `Max_Constraint` should insure that `FinMax[j]` `>=` the finishing date. If some other objective or constraint of your model forces `FinMax[j]` to be as small as possible (while still satisfying `Max_Constraint`) then this will be enough. Otherwise, you might get some solutions with `FinMax[j]` `>` the finishing date; in that case, to ensure that `FinMax[j]` equals the finishing date, you will need to add a constraint that also forces `FinMax[j]` `<=` the finishing date. (Your constraint `Define_Fin` only forces `F[j]` and `FinMax[j]` to be equal, so it’s not enough by itself to force `FinMax[j]` to equal the finishing date.)

You can force `FinMin[j]` `<=` the starting date with a constraint like this,

```auto
StaMin[j] <= t * Act[j,t] + U * (1-Act[j,t])

```

where `U` is an upper bound on `StaMin[j]` for all `j`. But the complications described above also apply for this.

You might want to search [Operations Research Stack Exchange](https://or.stackexchange.com/), or post your own question there, as there is a lot of discussion of scheduling and of linearizations on that site.

---

<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, 2024, 4:38am UTC](https://discuss.ampl.com/t/find-a-starting-date-of-the-project-using-an-alternative-linear-expression-than-min-function/1977/3 "2024-11-11T04:38:58Z")

</div>

Thank you so much for this detailed answer.  
I tried to add the following constraints :  
LU is the upper bound and Dmin[j] = Stamin [j]  
subject to MinConstraint {j in P, t in T}:  
Dmin [j] \<= t_Act[j, t]+ LU_ (1-Act[j, t]);

subject to DebutConstraint {j in P}:  
Debut[j] \<= Dmin[j];

subject to Debut2Constraint {j in P}:  
Debut[j] \>= Dmin[j];

However, the results, in this case, indicate that the starting date is always t=1 for all project which is not true. In fact, in resource allocation table some projects start at t=2 other t= 4 not really t=1 for all projects …

---

<div class="post-metadata">

**Author:** ![4er](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/4er/32/530_2.png) [@4er](https://discuss.ampl.com/u/4er)\
**Post date:** [November 12, 2024, 5:46pm UTC](https://discuss.ampl.com/t/find-a-starting-date-of-the-project-using-an-alternative-linear-expression-than-min-function/1977/4 "2024-11-12T17:46:32Z")

</div>

As I mentioned, you can force a variable like `DMin[j]` to be _less than or equal to_ the starting date by use of constraints like this,

```auto
DMin[j] <= t * Act[j,t] + LU * (1-Act[j,t])

```

(where `LU` is an upper bound on `DMin[j]` for all `j`). But as you are seeing, this constraint also allows `DMin[j]` to be less than the starting date, unless some other constraints prevent that.

There a general description of how to linearize any relationship like y = \min \{x\_1, x\_2, \ldots, x\_n\} on [FICO’s Minimum Values](https://www.fico.com/fico-xpress-optimization/docs/dms2019-04/mipform/dhtml/chap2s1_sec_ssecminval.html) formulation page. For your example, y is `DMin[j]` and x\_j is `t` `*` `Act[j,t]` `+` `LU` `*` `(1-Act[j,t])`.
