# A JuMP Formulation for the Minimum Up/Down Time Unit Commitment constraint

**URL:** https://discourse.julialang.org/t/a-jump-formulation-for-the-minimum-up-down-time-unit-commitment-constraint/111458
**Category:** Optimization (Mathematical)
**Tags:** jump
**Created:** [March 11, 2024, 12:27pm UTC](https://discourse.julialang.org/t/a-jump-formulation-for-the-minimum-up-down-time-unit-commitment-constraint/111458 "2024-03-11T12:27:06Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Mouhamed](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@Mouhamed](https://discourse.julialang.org/u/Mouhamed)
#### Post date: [March 11, 2024, 12:27pm UTC](https://discourse.julialang.org/t/a-jump-formulation-for-the-minimum-up-down-time-unit-commitment-constraint/111458/1 "2024-03-11T12:27:06Z")

</div>

Hi I’m new to JuMP and i’m currently struggling to generate a working constraint for the Minimum Up/Down Time.

Indeed these are the “mathematical” formulation of what I wanna write:

**Σv(i) \<= u(t)** for **i** in range **[t-UpTime+1 ; t]**  
**Σw(i) \<= 1 - u(t)** for **i** in range **[t-DownTime+1 ; t]**

To implement these constraints, this is how I proceeded :

```julia
    @variable(uc_m, u[g in gen_names, t in time_periods], Bin)
    @variable(uc_m, v[g in gen_names, t in time_periods], Bin)
    @variable(uc_m, w[g in gen_names, t in time_periods], Bin)
    # MinUpTime
    if t <= UpT
        @constraint(uc_m, sum(v[name, i] for i in t-1:-1:1) <= u[t] )
    else
        @constraint(uc_m, sum(v[name, i] for i in (t-1):-1:(t-UpT+1)) <= u[t] )
    end
    # MinDownTime
    if t <= DownT
        @constraint(uc_m, sum(w[name, i] for i in t-1:-1:1) <= 1 - u[t] )
    else
        @constraint(uc_m, sum(w[name, i] for i in (t-1):-1:(t-DownT+1)) <= 1 - u[t] )
    end     

```

The error I get is “Key 2.0 not found”. But my intuition was that the values below instant “t” would have already been computed by the optimization algorithm.

I would really be thankfull if someone could give me hints on how to write such constraints.

Thankss

---

<div class="post-metadata">

### Author: ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)
#### Post date: [March 11, 2024, 3:03pm UTC](https://discourse.julialang.org/t/a-jump-formulation-for-the-minimum-up-down-time-unit-commitment-constraint/111458/2 "2024-03-11T15:03:34Z")

</div>

> [@Mouhamed](#):
>
> Key 2.0 not found

This message suggests that `u` and/or `v` is a `Dict`, `t` is a `Float64`, and the keys of the `Dict`(s) are not `Float64`.

---

<div class="post-metadata">

### Author: ![Mouhamed](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@Mouhamed](https://discourse.julialang.org/u/Mouhamed)
#### Post date: [March 11, 2024, 3:30pm UTC](https://discourse.julialang.org/t/a-jump-formulation-for-the-minimum-up-down-time-unit-commitment-constraint/111458/3 "2024-03-11T15:30:33Z")

</div>

Thank you very much.  
Worked when I casted the indices to Int.
