# Beginner | Basic Cyclic Scheduling | New To Julia and Scheduling

**URL:** <https://discourse.julialang.org/t/beginner-basic-cyclic-scheduling-new-to-julia-and-scheduling/129344>\
**Category:** New to Julia\
**Created:** [May 26, 2025, 12:10pm UTC](https://discourse.julialang.org/t/beginner-basic-cyclic-scheduling-new-to-julia-and-scheduling/129344 "2025-05-26T12:10:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ely](https://avatars.discourse-cdn.com/v4/letter/e/87869e/32.png) [@Ely](https://discourse.julialang.org/u/Ely)\
**Post date:** [May 26, 2025, 12:10pm UTC](https://discourse.julialang.org/t/beginner-basic-cyclic-scheduling-new-to-julia-and-scheduling/129344/1 "2025-05-26T12:10:41Z")

</div>

Hi, i am trying to work on some cyclic scheduling problems with CPLEX and Julia and i need to admit i am quite new to both.  
Any idea please how a similar program can be solved:

 ![Capture d'écran 2025-05-26 132822](https://global.discourse-cdn.com/julialang/original/3X/c/f/cf197e64c0831d7d4d6d6dedc46fd19e74da1d27.png)  
With the following data:  
Tasks from 1 to 7 with the following processing times: 5 4 5 5 4 3 5  
Knowing that the optimal cycle time in the article is equal to 9.5

Thanks in advance ! ( I have tried some code but never was able to reach the optimal/correct result)

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [May 26, 2025, 12:48pm UTC](https://discourse.julialang.org/t/beginner-basic-cyclic-scheduling-new-to-julia-and-scheduling/129344/2 "2025-05-26T12:48:42Z")

</div>

Hi, welcome to the community!  
Perhaps you want to take a look at JuMP.jl?

---

<div class="post-metadata">

**Author:** ![Ely](https://avatars.discourse-cdn.com/v4/letter/e/87869e/32.png) [@Ely](https://discourse.julialang.org/u/Ely)\
**Post date:** [May 26, 2025, 1:34pm UTC](https://discourse.julialang.org/t/beginner-basic-cyclic-scheduling-new-to-julia-and-scheduling/129344/3 "2025-05-26T13:34:45Z")

</div>

Thanks ! That’s what i am trying to do tbh.

I am tryin to share my code here but it’s not possible. Can i create another topic for that ?

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [May 26, 2025, 1:35pm UTC](https://discourse.julialang.org/t/beginner-basic-cyclic-scheduling-new-to-julia-and-scheduling/129344/4 "2025-05-26T13:35:34Z")

</div>

I think as a new member your link sharing permissions are still restricted for a while. Can you just copy-paste the code into a block with backticks?

---

<div class="post-metadata">

**Author:** ![Ely](https://avatars.discourse-cdn.com/v4/letter/e/87869e/32.png) [@Ely](https://discourse.julialang.org/u/Ely)\
**Post date:** [May 26, 2025, 1:45pm UTC](https://discourse.julialang.org/t/beginner-basic-cyclic-scheduling-new-to-julia-and-scheduling/129344/5 "2025-05-26T13:45:26Z")

</div>

Done !  
I tried to give this code a try but still not giving the right result.

```julia
using JuMP
using CPLEX

T = 1:7
p = [5, 4, 5, 5, 4, 3, 5]  

model = Model(CPLEX.Optimizer)

# start times of each task 
@variable(model, x[i in T] >= 0)

# Cycle time
@variable(model, C >= 0)

# Constraints: Cycle time >= p[i]
for i in T
        @constraint(model, C >= p[i])
end

# precedence constraints
for i in T, j in T 
    if i != j
        @constraint(model, x[j] + C >= x[i] + p[i])
    end
end

@objective(model, Min, C)

optimize!(model)

println("Optimal cycle time is equal to ", value(C)) 

# If anyone has already worked on the cyclic scheduling problem, I'd be grateful for any tips !
```

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [May 26, 2025, 2:50pm UTC](https://discourse.julialang.org/t/beginner-basic-cyclic-scheduling-new-to-julia-and-scheduling/129344/6 "2025-05-26T14:50:13Z")

</div>

I assume H\_{i,j} is some kind of precedence variable? I don’t see it in your model

---

<div class="post-metadata">

**Author:** ![Ely](https://avatars.discourse-cdn.com/v4/letter/e/87869e/32.png) [@Ely](https://discourse.julialang.org/u/Ely)\
**Post date:** [May 26, 2025, 2:59pm UTC](https://discourse.julialang.org/t/beginner-basic-cyclic-scheduling-new-to-julia-and-scheduling/129344/7 "2025-05-26T14:59:14Z")

</div>

Exactly, Hij is the height of the precedence constraint.

 ![Hij](https://global.discourse-cdn.com/julialang/original/3X/0/c/0cec02bc452b08a0d34cbf9707047577aea6e9ae.png)  
This is the example i’m trying to test:  
 ![example1](https://global.discourse-cdn.com/julialang/original/3X/d/6/d675a342cfb05d4012fd5e5a5f16ffce99a2ee94.png)  
 ![example2](https://global.discourse-cdn.com/julialang/original/3X/9/f/9fd3b217ef4fea6becbf090987a02e1c946926cb.png)

I’ve actually tried to add it somehow at the beginning but still didn’t work.

I guess i need to check more articles and see how it goes.

Thanks !

---

<div class="post-metadata">

**Author:** ![slwu89](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/slwu89/32/217323_2.png) [@slwu89](https://discourse.julialang.org/u/slwu89)\
**Post date:** [May 26, 2025, 4:13pm UTC](https://discourse.julialang.org/t/beginner-basic-cyclic-scheduling-new-to-julia-and-scheduling/129344/8 "2025-05-26T16:13:33Z")

</div>

Hi, welcome to Julia. I found the paper you are referencing (note, it might be nice in the future if you can directly provide us a link) here: [https://laas.hal.science/hal-02318936v1/document](https://laas.hal.science/hal-02318936v1/document) and I implemented the model you cite in section 2 below, which retrieves the answer given in the paper of a cycle time of 9.5.

Because the paper conceptually uses a graph to structure the sets and constraints it considers, I use 2 `DataFrames` to store information related to the vertices (`T`) and edges (`E`). You will note that we store `p`, the times associated to each task with the tasks, as well as attach the vector of decision variables `t` directly to the dataframe so they can be easily retrieved when we write constraint 1b. We store the `H` variables directly with the dataframe that stores the edges as an edge list format.

One further note, you may find more focused help on optimization topics specifically by posting in the optimization specific forum here [Optimization (Mathematical) - Julia Programming Language](https://discourse.julialang.org/c/domain/opt/13)

```julia
using JuMP, HiGHS
using DataFrames

T = DataFrame(
    i = [:s,1,2,3,4,5,6,7,:f], 
    p = [0,5,4,5,5,4,3,5,0]
)
E = DataFrame(
    src = [:s, 1, 2, 3, 4, :f, :s, 5, 6, 7],
    tgt = [1, 2, 3, 4, :f, :s, 5, 6, 7, :f],
    H = [0, 0, 0, 0, 0, 2, 0, 0, 0, 0]
)

model = JuMP.Model(HiGHS.Optimizer)

# cycle time
@variable(model, α)

# dec var: starting time and 1c
T.t = @variable(model, t[1:nrow(T)] ≥ 0)

# 1a
for i in eachrow(T)
    @constraint(
        model,
        α ≥ i.p        
    )
end

# 1b
for e in eachrow(E)
    i = e.src
    j = e.tgt
    ti = T[findfirst(T.i .== i), :t]
    pi = T[findfirst(T.i .== i), :p]
    tj = T[findfirst(T.i .== j), :t]
    Hij = e.H
    @constraint(
        model,
        tj + α*Hij ≥ ti + pi
    )
end

# obj
@objective(
    model,
    Min,
    α
)

optimize!(model)

# look at optimal vals of dec vars
value(α)
value.(T.t)

```

---

<div class="post-metadata">

**Author:** ![Ely](https://avatars.discourse-cdn.com/v4/letter/e/87869e/32.png) [@Ely](https://discourse.julialang.org/u/Ely)\
**Post date:** [May 26, 2025, 5:32pm UTC](https://discourse.julialang.org/t/beginner-basic-cyclic-scheduling-new-to-julia-and-scheduling/129344/9 "2025-05-26T17:32:13Z")

</div>

Hi, Thanks a lot for the implementation as well as the explanation !  
I’ll try to tackle the rest of the paper with a similar approach.

Also well noted regarding the reference, I’ll make sure to have it included in further posts (if needed).

Thanks again !
