Skip to content

WIP: Enhance Gantt chart plotting by incorporating resource capacities#310

Draft
merqurio wants to merge 2 commits intoPyJobShop:mainfrom
merqurio:main
Draft

WIP: Enhance Gantt chart plotting by incorporating resource capacities#310
merqurio wants to merge 2 commits intoPyJobShop:mainfrom
merqurio:main

Conversation

@merqurio
Copy link

@merqurio merqurio commented Jul 9, 2025

This PR enhances the plot_machine_gantt function by showing the tasks in a resource with a capacity > 1. These changes make the Gantt chart more informative and visually robust, especially for problems involving multi-capacity resources. This helps users better interpret the schedule and resource utilization. Specifically:

  • Y-Axis Labels: For resources with capacity greater than 1, the label now includes the capacity (e.g., Machine A (cap=3)), making it clearer when a resource can process multiple tasks simultaneously.
  • Y-Axis Limits: The y-axis limits are set to ensure that all bars, including those at the top and bottom, are fully visible, preventing clipping.
  • Ticks and Labels: The y-ticks and labels are aligned with the base of each resource, improving readability.

machine_gantt

This is still WIP, i wanted to open the door to early feedback. At the moment there is still some overlay happening in the resource lanes.

Testing:

  • Verified that Gantt charts render correctly for both single- and multi-capacity resources.
  • Checked that all bars and labels are visible and correctly aligned.

@leonlan
Copy link
Member

leonlan commented Jul 9, 2025

Hi @merqurio, thanks for opening this PR and taking this initiative! I will have a look later tonight :)

@merqurio merqurio marked this pull request as draft July 9, 2025 11:04
@leonlan
Copy link
Member

leonlan commented Jul 9, 2025

@merqurio I've tried making a Gantt chart before for capacity-based resources (see #221 (comment)), but I found it difficult to judge what's a "good" visualization because I only have experience solving scheduling problems with machines. That's why I opted for just providing the plot_resource_usage function as demonstrated here.

Could you share some experiences of your use cases, and what you would like to see as the result? These questions will help me better understand your needs to shape this PR. I'm curious to know more about the following details:

  • Does your instance also have tasks that have more than one demand? I currently only see tasks that take up exactly one lane. How should these tasks be visualized?
  • Do you also have non-renewable resources in your instance? If so, how would you like to visualize those resources as opposed to renewable resources?
  • What do you think about the attempt that I made before? What do you like and dislike about it?

@merqurio
Copy link
Author

merqurio commented Jul 10, 2025

I've tried making a Gantt chart before for capacity-based resources (see [#221 (comment)](#221 (comment))).

Sorry, I completely missed that!

Does your instance also have tasks that have more than one demand? I currently only see tasks that take up exactly one lane. How should these tasks be visualized?

Not currently, but I'm still modeling the problem. I see that you adapted the height of the task; was that based on the amount of resource used, right?

Do you also have non-renewable resources in your instance? If so, how would you like to visualize those resources as opposed to renewable resources?

We don't at the moment. I checked Pyomo for inspiration, but I don't see anything in their plots. Getting creative here ⚠️, we could perhaps plot an hbar that's more or less filled with color based on the amount of non-renewable resources used? (I'm thinking of milliCPUs, in the case of a budgeted resource). I'd suggest tackling this in a second iteration if that's okay with you.

What do you think about the attempt that I made before? What do you like and dislike about it?

I like it, and I'm happy to work from there if you feel more comfortable. This is exactly why I opened an early PR, so you could also give some clues on what's important for you. Let me know, and thanks for your fast answer!

@leonlan
Copy link
Member

leonlan commented Jul 10, 2025

Sorry, I completely missed that!

No worries at all! My initial attempt was buried inside a PR, so I didn't expect anyone to find it.

Not currently, but I'm still modeling the problem. I see that you adapted the height of the task; was that based on the amount of resource used, right?

Correct. I saw something like that in your code as well, so we're on the same page here.

We don't at the moment. I checked Pyomo for inspiration, but I don't see anything in their plots. Getting creative here ⚠️, we could perhaps plot an hbar that's more or less filled with color based on the amount of non-renewable resources used? (I'm thinking of milliCPUs, in the case of a budgeted resource). I'd suggest tackling this in a second iteration if that's okay with you.

I like it, and I'm happy to work from there if you feel more comfortable. This is exactly why I opened an early PR, so you could also give some clues on what's important for you. Let me know, and thanks for your fast answer!

That's fine! I already think that the current approach you're taking is something we can continue working with. Let's first focus on purely renewable resources. There are some scenarios and resulting design decisions that we need to experiment with:

  1. What if a task has a demand larger than 1?
  2. What if resource capacities vary greatly (e.g., 10 vs. 1000)?

Point 1 is actually which I found most challenging. Drawing such plots is actually an optimization problem in itself: How do draw the tasks in the nicest possible way? Should we schedule tasks in order of their starting times (like you already do), but maybe also prioritize tasks with the highest demand first? Or perhaps area (width * height)? (I don't have an answer to this question.)

I think that the visualization that I made earlier could be much improved. For instance, there are too many vertical gaps between the tasks. That gives a skewed view of how much of a resource's capacity is used.

Image image

I'm going to try to find more examples. Please feel free to share ideas and your personal needs, as they can be very helpful in shaping this PR.

@leonlan
Copy link
Member

leonlan commented Jul 11, 2025

I think there will always be some kind of RCPSP instances that don't admit a nice visualization, like this one:

Details image

Scheduling the tasks of resource 1 will always result in some kind of vertical gaps. The result is that it's not clear how much resource capacity is actually consumed at each time point.

We could plot the resource usage as an overlay on top of the Gantt chart plots. This picture is not entirely correct, but the resource usage would be represented by the black dotted lines.

image

While writing this, I think the "optimization problem" that we try to solve is the following: Given the resource usage pattern, can we plot the tasks so that we minimize the area that falls outside of the resource usage profile?

@merqurio
Copy link
Author

newplot

Screen Recording 2025-07-17 at 22 29 58

This new commit introduces plot_gantt_plotly.py, a new visualization utility that generates an interactive chart.

I had to use Plotly for its zooming capabilities. The scheduling model, with its long time horizons and high number of iterative tasks, produces detailed schedules that are difficult to inspect as static images. This interactive chart help for exploring the full timeline and drilling down into specific task allocations, which helps overcome the practical limitations of visualizing such a complex problem.

@merqurio
Copy link
Author

My primary focus is to get the first iteration into production as soon as possible. Once that's live, I'll reconnect with you to discuss and ask for your help to merge the charting capabilities. I'm currently creating more charts, similar to the one I just pushed, for debugging purposes. I'll likely push most of them and coordinate with you them, but it might take some time 😄

@leonlan
Copy link
Member

leonlan commented Jul 18, 2025

Sure thing, good luck! Let me know if you need any help with the scheduling part -- feel free to open an issue or send me an email.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants