This project is a group work designed and solve by Shaokang Jiang & Katherine Fu for course CS524 project.
Optimization is a powerful way to solve real problem in a short amount of time. It needs us to use more math when we design solutions instead of using computing resources when the problem runs. GAMS is a powerful optimization software. GAMS could do calculation and generate equations in seconds. By using CPLEX, we are able to reach solutions in seconds. In this project, we utilize GAMS feature (dynamic sets, mip, etc) and nearly solved a real problem.
Problem
College library optimization problem
We consider a simplified example of arranging the number of students who use the college library for studying. In different period of time during school year, the number of students staying in the library is different. During the midterm and final weeks, the number is rapidly increasing. Thus, it is essential to maximize the efficiency of the number of hours of students who can use the library given their studying duration of using individual seats, the inflow and outflow of students, the equipment checking-out situations, and so on.
To simplify our model, we assume that the library has two sections: a quiet area, a public area. The total number of seats in the college library is 1000.
≤5 hrs | >5 hrs | For project | For chatting | ||
---|---|---|---|---|---|
≤2 hrs | >2 hrs | ≤4 hrs | >4 hrs | ||
1 | 0.6 | 1.1 | 0.5 | 0.12 | 0.05 |
To understand the Efficiency, we gave an example at here. Assume a person could finish a page of work in an hour, this is defined as one unit of efficiency, also known as the efficiency per hour for a person work in quiet area for less than 5 hours. But if this person work more than 5 hours, then he/she can only finish 0.6 pages of work for each hour he/she spend. By using formula, it looks like this: (t stand for time of working, f(t) stand for total efficiency) Equation 1 stand for student total efficiency staying in quiet area. Equation 2 stand for student total efficiency staying in public area for project purpose. Equation 3 stand for student total efficiency staying in public area for chatting purpose.
\begin{equation} f(t)=\left\{ \begin{aligned} & 1*t & \forall t\le 5 \\ & 5+0.6*t & \forall t> 5 \end{aligned} \right. \end{equation} \begin{equation} f(t)=\left\{ \begin{aligned} & 1.1*t & \forall t\le 2 \\ & 2.2+0.5*t & \forall t> 2 \end{aligned} \right. \end{equation} \begin{equation} f(t)=\left\{ \begin{aligned} & 0.12*t & \forall t\le 4 \\ & 0.48+0.05*t & \forall t> 4 \end{aligned} \right. \end{equation}It is permitted to switch a person from quiet place to public place. A person who requested the quiet apace and switched to public space due to limited seats will have an coefficient of efficiency of 0.8; A person who requested the public apace and switched to quiet space due to limited seats will have an coefficient of efficiency of 0.3;
Equation below stand for student total efficiency. (x represent for the original efficiency this student have, which is also the caalculation result from the previous step, f(x) stand for result of new efficiency)
\begin{equation} f(x)=\left\{ \begin{aligned} & 0.8*x & \forall x| quiet\rightarrow public \\ & 0.3*x & \forall x| public \rightarrow quiet \end{aligned} \right. \end{equation}The college library also provides equipment including laptops,
calculators, and computer chargers for students to use. If a student
checks out one of these equipment, the efficiency of that student could be multiply by those coefficient. The coefficient for regular efficiency is shown below.
Laptops | calculators | computer chargers |
---|---|---|
1.1 | 1.2 | 1.3 |
Equation below stand for student total efficiency. (x represent for the original efficiency this student have, which is also the calculation result from the previous step, f(x) stand for result of new efficiency)
\begin{equation} f(x)=\left\{ \begin{aligned} & 1.2*x & \forall x| calculator=1 &\\ & 1.1*x & \forall x| laptops=1 &\\ & 1.3*x & \forall x| charger=1 & \end{aligned} \right. \end{equation}The number of laptops is 10, the total number of calculators is 30, and
the number of chargers is also 10. Every person could use those equipment for the time duration that they are study in the library. Each person could borrow at most one equipment during time duration that he is in library.
data.gdx contain the data of students’ thinking of purpose of using those equipment and seats in the library. We want to consider a situation in a day of experimenting period during opening hours of 8:00 am to 9:00 pm. This file recorded the time when a student enter the library; the time they want to study; the place they want to study; Max possible hours for quiet hours is 10. Max possible hours for public hours is 6; type of 0 stands for project, 1 stands for chatting;
By using data above, you are going to give permission for certain group of students to enter this library and arrange seats in the library in order to maximize total efficiency. And also, to demonstrate that this library is open to all people, you get to allow at least 10 chatting people to enter this library.
Objective1:
How to arrange seats in the library to try the best to meet the requirement of student’s thought in data.gdx and maximize the total efficiency of students using the library? Also, which student will be permitted of entering this library?
Dataset could be downloaded from data.gdx.
Objective2:
More gdx file is provided. Those gdx files describe different time of requests from students. How to arrange seats in the library to try the best to meet the requirement of student’s thought in those gdx files and maximize the total efficiency of students using the library? Each gdx file is considered as a different scene, store the output in parameter and plot different seat arrangement during this year in a line diagram and draw out if there is any suggestion to provide to the library.
Dataset could be downloaded from data-free.gdx, data-middle.gdx, data-busy.gdx.
Objective3:
Solve the model multiple times with different total seats provided, do you have any recommendation for the school that they need to buy more seats or not? Do not consider rules of fire protection design and construction of buildings. Plot the result in graph and explain the reason.
Analyze:
The approach used.
We organized the requests from all the students based on their (enter_hour, public_hour) with the help of variables, respectively, n_pe_public and n_pe_quiet. These are represented as the maxmize number of people each regetangle block could contain in the graph below.
Regarding the opening time of the library, there are two variables called quiet_arrange and public_arrange in a form of tuples (enter_hour, public_hour) as an entry. Based on the graph above, every quiet(open_hour, quiet_hour) variable contains # of people staying on seat at certain time interval and the duration of his or her studying hours is illustrated as the length of each block. Same case for public area. After we synthesized all the cases of students from his or her entering times to leaving times, we could form a complete diagram and the left graph above is a snippet.
In general, we utilized a dynamic set determined by students’ entering time and the duration of studying in either quiet or public area during each time interval from 8 am to 9 pm to measure the seat arrangement. This dynamic dataset is called “visible_quiet”, a 3-dimensional set, with sets (o, enter_hour, quiet_hour). It means, for every time interval o(as 10:00 in above) starting from 8 am, the (open_hour, quiet_hour) should be counted once, which is shown as shaded blocks on the top right side. In each time interval, a decent amount of students will enter the library and the total number during that time will be calculated. For example, based on the graph above, quiet(“8”, “3”) records the number of students who enter the library at 8 am and stay for 3 hours. If another student comes at 10 am and has also studied for 3 hours, we should count both of them in the time interval from 10 am to 11 am (the shaded area). The sum of number of students that shaded blocks contains should be less or equal to a corresponding variable(called quiet_chairs in code). Similiar case would be applied to public case.
We also took the seat-switching situations as considerations. The number of students in quiet area in certain interval should be the sum of the number of current students, those who just arrive, and those who switch from the public area to the quiet area(named as switch_p2q in code). Same thing applies to the arrangement of the public area(in a variable called switch_q2p).
Our objective is to maximize the total efficiency. We realized the utilization of calculators, chargers and laptops will also exert significant effects on students’ efficiency. Considering that it was hard to calculate them with our original model, we splited the entire block into two stages demonstrated in two blocks in obj1. The first stage begin from the head of introduction and end at here. Because we had them in the problem description part, we solved the second stage and use this model to discover data in obj2. In the first stage, the model is calculated by multiplying the base total efficiency coefficients with the number of hours students spend in each area. The base total efficiency coefficients depend on area and hours, so they are pre-calculated and stored in eff_quiet and eff_public in the code. We also considered the situation whether students switch areas or utilize equipments. For different scenarios, we multiplied hours with different coefficients. More details will be discussed in the section below.
For the second stage of the problem, we employed some variables similar to ca_need_public, ca_need_quiet to represent the machines borrowed at pair (enter_hour, quiet_hour). We organized the needs for devices at first and set up them as an upper bound. The other procedures are similar to methods using in stage one. One difference is that we utilized some variableS for spliting, similar to ca_need_public_1, ca_need_public_2. They are used later for the objective function. Because the objective function has two variables with different conditions(quiet_arrange and switch_p2q) in each type(pblic or quiet) taking different final coefficient, we need to split the variable to represent those conditions. Because we try to maximizing the problem, the program will always fill the quiet_arrange first as it has a higher coefficient in general.
In terms of the number of equipments, we assumed that the requests for equipments should be greater than the number the library has. Given a simple example. If four students all require to use calculator but currently, the library only has 3 calculators available, we try to find a way to give the calculators to students in order to maximize the total efficiency.
Optimization model
We first counted the total number of people in either public or private areas based on the avalibility. Then, we calculated the efficiency of both regular studying hour, switching situations, and, equipment check-out situations and attempt to maxmize the total efficiency. We finally displayed students who have been chosen to study in certain seats in certain time interval.
We simplified the representation so we only represented the quiet study room and calculator case.
In the model, we had those variables:
- let o to be a set of open hour from 8 to 21.
- let q to be a set of people can stay in the quiet room, from 1 to 10.
- let ty be the type of public object, it could be chat or project.
- let qi be the set of original people record identity number, and cj be the category, like enter, hours, calculator
- Let for represent the dataset.
- let for be the dynamic set represents at hour i, people who come in at j and plan to stay k hours, which is visible. For example, = {(8,2),(8,3),(8,4)…(8,10),(9,1),(9,2),(9,3)…(9,10)}
- let for be the dynamic set represents at hour i, people who come in at j and plan to stay k hours, which is visible. For example, = {(8,2),(8,3),(8,4)…(8,6),(9,1),(9,2),(9,3)…(9,6)}
- let for to be the Base total efficiency base vector on time k.
- let for to be people switch from public area to quiet area enter at hour j and stay for hours k. Same mechanism for
- let variable be the chairs should be in quiet room.
- let variable for be the number of people accepted to the library to maximize total efficiency
- let variable for be the number of calculator split for quiet area accepted to the library to maximize total efficiency
- let variable for be the number of calculator accepted to the library to maximize total efficiency
- let be the increment factor of efficiency of using calculator, let be the factor of efficiency of switch from public to quiet
- Let for be the number of people requested to stay in the library.
- Let for be the number of calculator requested to stay in the library.
- Let for be a binary variable record which people is selected
- Let for be a binary variable record which people has calculator
\begin{align} \begin{split} s.t.\quad & CQ1_{jk} + CQ2_{jk} \le NCQ_{jk} && \forall j\in o,k\in q \\ & Q_{jk} \le NPQ_{jk}&&\forall j\in o,k\in q\\ & 1000\ge QC&\\ & \sum_{j,k}Q_{jk}+\sum_{l,j,k}P2Q_{ljk}\le QC &&\forall i\in o, \forall Q_{jk}\in sq_{ijk}, \forall P2Q_{ljk}\in sp_{ijk} \\ & \sum_{m\in qi} SQ_{m} = Q_{jk}&& \forall j\in o, k\in q,\forall m\in \{m | Quiet_{m"enter"}=j\\ &&& \&Quiet_{m"hours"}=k\}\\ & \sum_{m\in qi} SQC_{m} \ge CQ1_{jk} + CQ2_{jk} && \forall j\in o, k\in q,\forall m\in \{m | Quiet_{m"enter"}=j\\ &&& \&Quiet_{m"hours"}=k\& Quiet_{m"Calculator"}=1\}\\ & \sum_{j,k}(CQ1_{jk} + CQ2_{jk})\le 20 &&\forall i\in o, \forall CQ1_{jk}, CQ2_{jk}\in sq_{ijk} \\ & CQ1_{jk} \le Q_{jk}+Q2P_{jk}&&\forall i\in o, k\in q \end{split} \end{align}
Most of other formulas for the entire project is similiar to the methods using above, so we choose to not write them.
For the solutions, see here for solution of obj1, here for solution of obj2, here for solution of obj3
Processing of the solution
processing for the first objective
processing for the second objective
processing for the third objective
Some brief conclusion
As shown in area below
Conclusion for the first objective
Based on our problem, (the total_limit is 1000), there are no significant difference between borrowing equipments and not borrowing equipments. But if we look into a smaller scalar problem, there are difference betweeen those two cases. The reason for it is that borrowing equipment has a low chance to happen.
For the conclusion, library need to arrange 321 seats for public area and 679 seats for quiet area in order to maxmize students’ total efficiency in the busy hours. We also demostrate a permission list but we think it is not unique and it is not as important as seats arrangement. So, we represented it but not discuss a lot about it.
Conclusion for the second objective
As we mentioned in the problem, we provided the permission in each case. But it is not useful.
By using the graph, we could clearly see that more quiet seats need to be arranged when students get bussier. This might be a guidance for library to provide different arrangement of seats in different time period.
Conclusion for the third objective
As we could see on the graph that the slope goes down at point around 1200. So for the bussiest season, school do need to buy more chairs for students to study.
Conclusion for the entire objective
As we could see on the graph that the slope goes down at point around 1200. So for the bussiest season, school do need to buy more chairs for students to study.
Further thoughts:
Furthermore, there are lots of improvements that could be done.
Since our model separates the public and quiet areas in our parameter, it is hard for us to simplify our model. In the future model, we could try to combine these two into one parameter to make it simplier.
The constraints, dealing ways might need to be improved. And there might be some small errors as there are too many equations. We checked them for multiple times, but it is hard to guarantee that every place is perfectly correct.
And the model could only make sense if they have the real data input. Right now, we only have fake data.
Solution is not unique(for selection of people). Maybe we don’t have to find which person should be given the permission. We could find the number of people we should accept in each case.
we always want to keep minimum change to what we setup in the previous submission, A lot of places could be improved actually. Like obj2, execute_load command would be better.
like what we discussed in obj3, some more discoveries could be done, including if the library needs to buy more calculators or not.
And, not all people are on time in real case. In this problem, we assume data are collected from survey or somethimg. So, there is no person would have a time duration of 2:15. But in real case, this would happen. So, it would be helpful to invite error vectors to describe this and form the problem.
Solution:
Important startup of jupyter notebook interface:
1 | from IPython.core.display import display, HTML |
Objective1:
How to arrange seats in the library to try the best to meet the requirement of student’s thought in data.gdx and maximize the total efficiency of students using the library? Also, which student will be permitted of entering this library?
1 | %%gams |
1 | %%gams |
Solver Status | Model Status | Objective | #equ | #var | Model Type | Solver | Solver Time | |
---|---|---|---|---|---|---|---|---|
0 | Normal (1) | Optimal Global (1) | 9699.148 | 601 | 4403 | MIP | CPLEX | 0.038 |
1 | %%gams |
Solver Status | Model Status | Objective | #equ | #var | Model Type | Solver | Solver Time | |
---|---|---|---|---|---|---|---|---|
0 | Normal (1) | Optimal Global (1) | 9830.486 | 2642 | 6977 | MIP | CPLEX | 0.067 |
Plot result at area below:
1 | %gams_pull -d chairs selection_public_ selection_quiet_ |
run | room | value | |
---|---|---|---|
0 | 1 | public | 321.0 |
1 | 1 | quiet | 679.0 |
2 | 2 | public | 321.0 |
3 | 2 | quiet | 679.0 |
run | public_i | value | |
---|---|---|---|
0 | 1 | 1 | 1.0 |
1 | 1 | 2 | 1.0 |
2 | 1 | 3 | 1.0 |
3 | 1 | 4 | 1.0 |
4 | 1 | 5 | 1.0 |
... | ... | ... | ... |
2787 | 2 | 1922 | 1.0 |
2788 | 2 | 1923 | 1.0 |
2789 | 2 | 1924 | 1.0 |
2790 | 2 | 1925 | 1.0 |
2791 | 2 | 1926 | 1.0 |
2792 rows × 3 columns
run | quiet_i | value | |
---|---|---|---|
0 | 1 | 1 | 1.0 |
1 | 1 | 2 | 1.0 |
2 | 1 | 3 | 1.0 |
3 | 1 | 4 | 1.0 |
4 | 1 | 5 | 1.0 |
... | ... | ... | ... |
3597 | 2 | 1898 | 1.0 |
3598 | 2 | 1899 | 1.0 |
3599 | 2 | 1900 | 1.0 |
3600 | 2 | 1901 | 1.0 |
3601 | 2 | 1902 | 1.0 |
3602 rows × 3 columns
1 | %%gams |
Solver Status | Model Status | Objective | #equ | #var | Model Type | Solver | Solver Time | |
---|---|---|---|---|---|---|---|---|
0 | Normal (1) | Optimal Global (1) | 704.900 | 601 | 4403 | MIP | CPLEX | 0.019 |
1 | Normal (1) | Optimal Global (1) | 791.634 | 2642 | 6977 | MIP | CPLEX | 0.086 |
1 | %gams_pull -d chairs |
run | room | value | |
---|---|---|---|
0 | 1 | public | 50.0 |
1 | 2 | public | 25.0 |
2 | 2 | quiet | 25.0 |
Conclusion for this part:
Based on our problem, (the total_limit is 1000), there are no significant difference between borrowing equipments and not borrowing equipments. But if we look into a smaller scalar problem, there are difference betweeen those two cases. The reason for it is that borrowing equipment has a low chance to happen.
For the conclusion, library need to arrange 321 seats for public area and 679 seats for quiet area in order to maxmize students’ total efficiency in the busy hours. We also demostrate a permission list but we think it is not unique and it is not as important as seats arrangement. So, we represented it but not discuss a lot about it.
Objective2:
More gdx file is provided. Those gdx files describe different time of requests from students. How to arrange seats in the library to try the best to meet the requirement of student’s thought in those gdx files and maximize the total efficiency of students using the library? Each gdx file is considered as a different scene, store the output in parameter and plot different seat arrangement during this year in a line diagram and draw out if there is any suggestion to provide to the library.
1 | %%gams |
Solver Status | Model Status | Objective | #equ | #var | Model Type | Solver | Solver Time | |
---|---|---|---|---|---|---|---|---|
0 | Normal (1) | Optimal Global (1) | 6809.384 | 2642 | 5873 | MIP | CPLEX | 0.05 |
1 | %%gams |
Solver Status | Model Status | Objective | #equ | #var | Model Type | Solver | Solver Time | |
---|---|---|---|---|---|---|---|---|
0 | Normal (1) | Optimal Global (1) | 8038.18 | 2642 | 6342 | MIP | CPLEX | 0.056 |
1 | %%gams |
Solver Status | Model Status | Objective | #equ | #var | Model Type | Solver | Solver Time | |
---|---|---|---|---|---|---|---|---|
0 | Normal (1) | Optimal Global (1) | 9830.486 | 2642 | 6977 | MIP | CPLEX | 0.066 |
Plot result at area below:
1 | %gams_pull -d problem2 selection_problem2_quiet selection_problem2_public |
obj2 | quiet_i | value | |
---|---|---|---|
0 | 1 | 1 | 1.0 |
1 | 1 | 2 | 1.0 |
2 | 1 | 3 | 1.0 |
3 | 1 | 4 | 1.0 |
4 | 1 | 5 | 1.0 |
... | ... | ... | ... |
4620 | 3 | 1898 | 1.0 |
4621 | 3 | 1899 | 1.0 |
4622 | 3 | 1900 | 1.0 |
4623 | 3 | 1901 | 1.0 |
4624 | 3 | 1902 | 1.0 |
4625 rows × 3 columns
obj2 | public_i | value | |
---|---|---|---|
0 | 1 | 1 | 1.0 |
1 | 1 | 2 | 1.0 |
2 | 1 | 3 | 1.0 |
3 | 1 | 4 | 1.0 |
4 | 1 | 5 | 1.0 |
... | ... | ... | ... |
4603 | 3 | 1922 | 1.0 |
4604 | 3 | 1923 | 1.0 |
4605 | 3 | 1924 | 1.0 |
4606 | 3 | 1925 | 1.0 |
4607 | 3 | 1926 | 1.0 |
4608 rows × 3 columns
obj2 | room | value | |
---|---|---|---|
0 | 1 | public | 556.0 |
1 | 1 | quiet | 444.0 |
2 | 2 | public | 453.0 |
3 | 2 | quiet | 547.0 |
4 | 3 | public | 321.0 |
5 | 3 | quiet | 679.0 |
Conclusion for this part:
As we mentioned in the problem, we provided the permission in each case. But it is not useful.
By using the graph, we could clearly see that more quiet seats need to be arranged when students get bussier. This might be a guidance for library to provide different arrangement of seats in different time period.
Objective3:
Solve the model multiple times with different total seats provided, do you have any recommendation for the school that they need to buy more seats or not? Do not consider rules of fire protection design and construction of buildings. Plot the result in graph and explain the reason.
1 | %%gams |
Solver Status | Model Status | Objective | #equ | #var | Model Type | Solver | Solver Time | |
---|---|---|---|---|---|---|---|---|
0 | Normal (1) | Optimal Global (1) | 165.596 | 2642 | 6977 | MIP | CPLEX | 0.11 |
1 | Normal (1) | Optimal Global (1) | 331.180 | 2642 | 6977 | MIP | CPLEX | 0.089 |
2 | Normal (1) | Optimal Global (1) | 488.794 | 2642 | 6977 | MIP | CPLEX | 0.084 |
3 | Normal (1) | Optimal Global (1) | 642.634 | 2642 | 6977 | MIP | CPLEX | 0.085 |
4 | Normal (1) | Optimal Global (1) | 791.634 | 2642 | 6977 | MIP | CPLEX | 0.085 |
... | ... | ... | ... | ... | ... | ... | ... | ... |
195 | Normal (1) | Optimal Global (1) | 10790.158 | 2642 | 6977 | MIP | CPLEX | 0.055 |
196 | Normal (1) | Optimal Global (1) | 10790.158 | 2642 | 6977 | MIP | CPLEX | 0.054 |
197 | Normal (1) | Optimal Global (1) | 10790.158 | 2642 | 6977 | MIP | CPLEX | 0.055 |
198 | Normal (1) | Optimal Global (1) | 10790.158 | 2642 | 6977 | MIP | CPLEX | 0.054 |
199 | Normal (1) | Optimal Global (1) | 10790.158 | 2642 | 6977 | MIP | CPLEX | 0.051 |
200 rows × 8 columns
Plot result area:
1 | %gams_pull -d n_result |
Conclusion for this part
As we could see on the graph that the slope goes down at point around 1200. So for the bussiest season, school do need to buy more chairs for students to study.
Conclusion for this project:
In this project, we learned how to use gams and solve a near real case problem. We observe an optimized seat arrangement for library to use. We also see the difference between different time in one semester and the result could be used to guide seat arrangements. At last, we see that 1000 seats might be too small for this library and they need to buy more.
We spent a lot of time on this project and we learned a lot from it. We also observe that gams system is pretty simple and efficient compared to other language. In the future, we would like to use it for more times on optimization problem.