<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Matheus Garvão</title>
    <description>The latest articles on DEV Community by Matheus Garvão (@matheusgarvao).</description>
    <link>https://dev.to/matheusgarvao</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3105367%2F2215bd18-7f27-4c54-a5e9-e71eb92ea3e9.jpg</url>
      <title>DEV Community: Matheus Garvão</title>
      <link>https://dev.to/matheusgarvao</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/matheusgarvao"/>
    <language>en</language>
    <item>
      <title>How I build a university timetable generator</title>
      <dc:creator>Matheus Garvão</dc:creator>
      <pubDate>Tue, 29 Apr 2025 14:17:03 +0000</pubDate>
      <link>https://dev.to/matheusgarvao/how-i-build-a-university-timetable-generator-5fn6</link>
      <guid>https://dev.to/matheusgarvao/how-i-build-a-university-timetable-generator-5fn6</guid>
      <description>&lt;h2&gt;
  
  
  Internship Project: Automatic Timetable Generation System for UniFil
&lt;/h2&gt;

&lt;p&gt;At the beginning of 2023, my advisor challenged me to develop, as an internship project, an automatic timetable generation system for UniFil (&lt;a href="https://unifil.br" rel="noopener noreferrer"&gt;https://unifil.br&lt;/a&gt;).&lt;/p&gt;

&lt;h3&gt;
  
  
  Context and Challenges
&lt;/h3&gt;

&lt;p&gt;Unlike many universities, our institution must deal with several peculiarities:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Professors do not have a fixed workload during the day.&lt;/li&gt;
&lt;li&gt;There is a list of around &lt;strong&gt;200 courses&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The schedules are renewed every &lt;strong&gt;two months&lt;/strong&gt; with new subjects.&lt;/li&gt;
&lt;li&gt;We have a &lt;strong&gt;varied number of rooms&lt;/strong&gt;—from computer labs and robotics rooms to common classrooms—each with its own restrictions and capacities.&lt;/li&gt;
&lt;li&gt;Additional internal constraints significantly increase the complexity of the problem.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Initial Research
&lt;/h3&gt;

&lt;p&gt;I started researching existing solutions and found the &lt;strong&gt;FET Timetable&lt;/strong&gt;. However, its documentation and usability were not compatible with our scenario.&lt;/p&gt;

&lt;p&gt;Then I discovered &lt;strong&gt;OptaPlanner&lt;/strong&gt;—now known as &lt;a href="https://solver.timefold.ai" rel="noopener noreferrer"&gt;Timefold Solver&lt;/a&gt;—which, with its detailed documentation, allowed me to build my own problem model and develop a customized interface.&lt;/p&gt;

&lt;h3&gt;
  
  
  First Implementation
&lt;/h3&gt;

&lt;p&gt;Initially, I focused on modeling the problem without including the flexible courses and performed the first tests with default settings. Quickly, I identified that several constraints were implemented inadequately.&lt;/p&gt;

&lt;p&gt;To better understand the errors:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I used the &lt;strong&gt;ScoreExplanation&lt;/strong&gt; feature.&lt;/li&gt;
&lt;li&gt;Saved debugging info in a JSON file.&lt;/li&gt;
&lt;li&gt;Adjusted flaws and re-ran the system — but the timetable was still not fully functional.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Optimization Insight
&lt;/h3&gt;

&lt;p&gt;By revisiting the documentation and studying the chapter on &lt;strong&gt;combinatorial optimization&lt;/strong&gt; in Peter Norvig’s book &lt;em&gt;“Artificial Intelligence”&lt;/em&gt;, I realized the need to improve the constraints.&lt;/p&gt;

&lt;p&gt;Changes made:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Switched from &lt;strong&gt;lists to sets&lt;/strong&gt; to optimize access time.&lt;/li&gt;
&lt;li&gt;Inverted the association: instead of linking professors to courses, each course now holds the &lt;strong&gt;set of qualified professors&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Benchmarking and Migration
&lt;/h3&gt;

&lt;p&gt;During benchmarking, I found OptaPlanner was outdated and migrated to &lt;strong&gt;Timefold Solver&lt;/strong&gt;, which improved execution time.&lt;/p&gt;

&lt;p&gt;I published my first articles on the topic:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://periodicos.unifil.br/index.php/Revistateste/article/view/3216/2995" rel="noopener noreferrer"&gt;Article 1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://periodicos.unifil.br/index.php/livros_unifil/article/view/3192/3011" rel="noopener noreferrer"&gt;Article 2&lt;/a&gt; – page 63&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These detail the algorithm and benchmarking process.&lt;/p&gt;

&lt;h3&gt;
  
  
  Interface &amp;amp; Search Space Challenges
&lt;/h3&gt;

&lt;p&gt;Even with improvements, challenges remained:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lack of a &lt;strong&gt;user-friendly interface&lt;/strong&gt; — data was entered via JSON.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;search space&lt;/strong&gt; was extremely large: ~10^820 possibilities.&lt;/li&gt;
&lt;li&gt;The generator overly focused on specific preferences.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Strategies to Overcome Challenges
&lt;/h3&gt;

&lt;p&gt;I adopted two strategies:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Reduced the search space&lt;/strong&gt; by excluding optional courses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ran two executions&lt;/strong&gt; of Timefold:

&lt;ul&gt;
&lt;li&gt;One ignoring “soft” constraints (e.g., Friday off, Monday preference).&lt;/li&gt;
&lt;li&gt;Then adjusted results to match those preferences.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Results
&lt;/h3&gt;

&lt;p&gt;With these changes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In ~6 hours, I generated a viable timetable.&lt;/li&gt;
&lt;li&gt;After 5 more hours of tuning, it became production-ready.&lt;/li&gt;
&lt;li&gt;A process that normally takes &lt;strong&gt;a month&lt;/strong&gt; was reduced to &lt;strong&gt;&amp;lt;12 hours&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Lessons and Future Work
&lt;/h3&gt;

&lt;p&gt;Biggest challenges:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Working with new technologies.&lt;/li&gt;
&lt;li&gt;Finding creative solutions independently.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks to the excellent documentation on Timefold, this became manageable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next steps:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Improve the system further.&lt;/li&gt;
&lt;li&gt;Re-evaluate constraints.&lt;/li&gt;
&lt;li&gt;Implement a &lt;strong&gt;hyper-heuristic&lt;/strong&gt; layer on Timefold.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We are currently testing a choice function (developed by another student), which improved execution time by ~20%.&lt;/p&gt;

</description>
      <category>timefold</category>
      <category>ai</category>
      <category>jssp</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
