← Back to Home

How I Used Dynamic Programming to Optimize Classroom Ventilation

Published at 11th Grade · Updated at 11th Grade · National First Prize (Top 56 among 118k participants)

Classroom Ventilation

In winter, opening windows in a classroom is sometimes difficult. If we open the windows, fresh air can come in and the carbon dioxide concentration can become lower. However, the classroom can also become cold. If we do not open the windows, the temperature may be more comfortable, but the CO₂ concentration can become too high.

This was the problem I studied in my mathematical modeling competition paper. The title of my paper was Dynamic Changes of Carbon Dioxide Concentration in Classrooms and Optimization of Ventilation Strategies.

CO2 concentration curves under different ventilation conditions

How I Started

I joined the competition during my winter vacation. The first round was an ability test. We needed to answer some questions that tested our mathematical modeling skills. The questions were about using mathematics to solve problems in daily life.

For example, one question was about why different fallen leaves can have different falling speeds in similar conditions. Another type of question was about arranging orders in an operation process. These problems were different, but they all required us to find important variables, make reasonable assumptions, and use mathematics to analyze the problem.

I received a First Prize in the preliminary round. Then I entered the next round, where I needed to write a complete modeling paper.

My Research Question

For the semifinal, I decided to study the air quality in classrooms.

Students spend many hours in classrooms every day. When many students are in the same classroom, they produce carbon dioxide continuously. If the classroom is not ventilated enough, the CO₂ concentration can become high. I thought this may affect students' comfort and attention during class.

However, it was winter when I was doing this project. Opening windows could reduce CO₂ concentration, but it could also make the classroom colder. So I needed to consider two things at the same time:

The CO₂ concentration should not be too high.
The classroom temperature should not be too low.

My goal was to find a better ventilation strategy during a school day.

Building the Model

First, I built a model to describe how the CO₂ concentration and indoor temperature changed over time.

When students were in the classroom, the CO₂ concentration would increase. When the windows were opened, fresh air could enter, so the CO₂ concentration could decrease. But opening windows also caused heat loss, especially in winter.

I set different conditions for class time, short breaks, and longer breaks. These periods were important because opening windows during a break may be more suitable than opening them during class.

To measure the comfort of the classroom, I designed two penalty functions:

A CO₂ penalty, which became higher when the CO₂ concentration was too high.
A temperature penalty, which became higher when the classroom temperature was too low.

Then I combined the two penalties into one total penalty function. The best ventilation strategy should make the total penalty as small as possible.

Penalty function visualization

Using a Questionnaire

One difficult part was deciding the weights of CO₂ concentration and temperature.

Some people may care more about fresh air, while other people may care more about staying warm in winter. I did not want to choose the weights only based on my own opinion.

So I designed a questionnaire. I used the results to decide how important temperature and air quality were in the model. This made the model closer to people's real feelings in a classroom.

Questionnaire results

Why I Used Dynamic Programming

I learned about dynamic programming when I was studying Python. I thought it could be useful for this problem.

Ventilation is not only one decision. We need to make many decisions during the day. For example, we need to decide whether to open the windows during a class, a short break, or a long break.

One decision can also influence the next decision. If the classroom becomes very cold after opening windows for a long time, we may not want to open them again soon. If we keep the windows closed for too long, the CO₂ concentration may become too high later.

Because of this, I used dynamic programming to find the best sequence of decisions.

I started from the end of the school day. I set the penalty after school as zero, and then used backward calculation to find the best decision for each earlier period. In this way, the model could consider not only the current condition, but also the influence on later classes.

Dynamic programming recursion structure

MATLAB Simulation

After building the model, I used MATLAB to do the calculation.

I simulated a full school day from 8:00 AM to 5:00 PM. The model divided the day into 5-minute intervals. For each interval, it chose the best window state: fully closed, slightly open, half open, or fully open.

Strategy comparison results

The results showed that the optimized strategy was better than just keeping windows closed or always keeping them open. The CO₂ concentration stayed lower, and the temperature did not drop too much.

What I Learned

This project taught me that the best solution is not always the most extreme one. Sometimes the answer is in the middle — opening windows during breaks, keeping them mostly closed during class.

It also taught me that a simple model can be useful. I did not need complex fluid dynamics simulations. A basic mass balance equation plus dynamic programming was enough to give practical advice.

Most importantly, I learned that the best problems to solve are the ones you can see from where you stand. My classroom was stuffy every afternoon. That was my problem.

Optimized strategy vs traditional approach ← Back to Home