教室分配问题 very interesting
楼主 · 1 楼
第二部分post-26-1182093970.ibf
2 楼
Vol. 40, Supplement 1: Optimization. (Jan. - Feb., 1992), pp.
S28-S39.
WHEN IS THE CLASSROOM ASSIGNMENT PROBLEM HARD?
MICHAEL W. CARTER
Cnwerslfj of Toronto, Toronto, Ontarlo, Canada
CRAIG A. TOVEY
Georgia Institute of Technology, Atlanta, Georgla
(Received February 1989; revision received March 1990; accepted January 199 1)
The classroom assignment (or hotel room or interval scheduling) problem is to assign classes, which meet at different
time intervals, to rooms. Two classes may not meet simultaneously in the same room, nor may a class meet in two
different rooms. Thousands of colleges and secondary schools face this problem every semester. There has been some
confusion as to how hard this problem is. Many colleges claim that it is easy, while others complain that it is next to
impossible. In the literature, some authors claim or conjecture polynomial time algorithms, while others develop heuristic
approaches. The goal of this paper is to resolve the confusion by identifying cases where the problem will be easy and
others where it will be hard. We focus on the kinds of cases that schedulers are apt to encounter in practice.
Hundreds of colleges and thousands of secondary
schools across North America are faced with
large classroom assignment problems every semester.
The vast majority of institutions "solve" the problem
manually, to a neverending chorus of complaints from
instructors. A few places employ simple computerassisted,
first-come, first-served heuristics.
For example, the University of Waterloo, prior to
1987. used to develop a complete new assignment of
classes to rooms every term. The manual process,
typical of many other universities, utilized a large
"room booking log" with one page for every room on
campus. The Central Scheduling Office estimates that
it took three experienced people two to three weeks to
develop the initial room assignments.
By comparison, at many universities, the room
assignments are essentially unchanged from one year
to the next. When a course is discontinued, the room
becomes free. When a new course is offered, they look
for the best available room at that time. Consequently,
people frequently must accept rooms that do not meet
their requirements, and the problem is compounded
annually.
There is some confusion as to the difficulty of
classroom assignment. Many colleges and secondary
schools claim that the problem is easy, while others
complain that the task is next to impossible. In the
literature, some authors claim or conjecture polynomial
time algorithms, while others develop heuristic
approaches. Our principal goal in this paper is to clear
Subject classifications: Education systems, operation: classroom assignment,
scheduling: applications.
Area of review: OPTIMIZATION.
up some of this confusion. To do this, we give some
new results, and also cite some work of others. It turns
out that the difficulty depends not only on the objective
and size of the problem, but on the underlying
preferences of classes for rooms. By considering the
kinds of situations actually encountered by schools,
we can resolve much of the contradictory evidence
that has been reported.
1. MATHEMATICAL FORMULATION OF THE
PROBLEM
The usual formulation of the problem is expressed in
terms of the variable x,], a 0-1 valued variable which
is equal to 1 when class i is assigned to room j and is
0 otherwise. Time is divided into periods (e.g., every
half hour, though all periods do not have to be the
same length). We sometimes wish to fix the number
of periods and refer to this case as the k-period problem.
The constraints of this problem are
and
2 x,/ 6 1 for j = 1, 2, . . , m; for all k,
lcPk
where Pk represents the set of all classes that meet in
period k. The first constraint ensures that every class
is assigned to some room, while the second constraint
course timetabling. Mathematics: computational complexity. Production/
OperationsResearch 0030-364X/92/4001-OS28 $0 1.25
Vol. 40, Supp. No. I, January-February 1992 O 1992 Operations Research Society of America
When Is the Classroom Assignment Problem Hard? / S29
prevents any room from having more than one class
in the same period. We define three objectives for this
problem:
Feasibility. Is there a feasible solution to the constraints
above?
Satisfice. Given, for each class i, a set of rooms S,
that are satisfactory, is there a feasible solution to the
constraints above that puts each class in a satisfactory
room?
Optimize. Assume the existence of a linear cost model
that adequately describes the problem and reflects
reasonable preferences. This is a standard assumption
and several papers describe such models (e.g., Glassey
and Mizrach 1986, Carter 1989). The cost of assigning
class i to room j is denoted c,,. The objective is to
minimize
Obviously, the three objectives are listed in nondecreasing
order of difficulty, regardless of other problem
characteristics. This is because Feasibility can be
modeled as a special case of Satisfice, which, in turn,
is a special case of Optimize. In particular, if we assign
a cost of 0 to all rooms j in the set S,, and a cost of 1
elsewhere, then Optimize gives the Satisfice solution
if the final total cost equals zero.
Of the three objectives, the one closest to problems
in practice is probably Satisfice. Manual schedulers
tend to think in terms of "acceptable" room assignments,
(e.g., enough seats, not too far away, special
facilities, etc.). They will not associate a specific numerical
rating to every possible combination of assignments.
Therefore, we will emphasize analysis of the
Satisfice objective in what follows.
Implicit in our integer programming formulation is
the constraint that a class is assigned to only one
room. That is, students do not have to change rooms
in the middle of a lecture! There are two versions of
the problem depending on how the word class is
interpreted. We call the first version the I-day or
interval problem. Ordinarily, classes meet once in a
day, from the beginning of one period to the beginning
of some other period. In this case, the class requires
the use of a room during an interval, hence, the
alternative name "interval scheduling." But classes
can meet more than once in a week. Some institutions
require that each class must have all of its meetings
in the same room. We call this version the multiday
or noninterval problem. Normally, we will interpret
the word class to mean a single meeting of a course,
so hereafter in the classroom assignment problem,
unless stated otherwise, we assume that each class
requires the use of a room for some set of consecutive
periods. For the sake of consistency, we will refer to
these problems as interval or noninterval.
Before proceeding to the results, we remark that the
classroom assignment model has several other applications,
including hotel room assignments, shipyard
scheduling, job scheduling on machines with varying
capabilities, and assigning airport gates to flights (see
Kolen, Lenstra and Papadimitriou 1987, Dondeti and
Emmons 1986, Mangoubi and Mathaisal 1985). In
the airport problem, Optimize is the appropriate objective;
in the others Satisfice is applicable.
2. COMPLEXITY RESULTS
Observe that, for the interval problem, if there is no
overlap of any class time periods, then even the
Optimize problem is easily solvable by classical
methods. For example, if all classes are one hour in
length and always begin on the hour, then each hour
of the day can be solved as a separate assignment
problem.
Observation 1. The 1-period classroom assignment
Optimize problem is polynomially solvable.
In many practical problems, classes will take on a
variety of different sizes. Secondary schools often utilize
single and double period courses. At the university
level. classes can be 1, 1.5, 2, 3 or 4 hours in length,
beginning every half hour.
Several heuristics for solving this problem have
appeared in the literature (Mulvey 1982, Ferland and
Roy 1985, Glassey and Mizrach 1986, Gosselin and
Truchon 1986, and Carter 1989). Two of these papers
(Glassey and Mizrach 1986, Gosselin and Truchon
1986) imply that it might be possible to develop a
polynomial algorithm. Papers by Arkin and Silverberg
(1987) and Kolen, Lenstra and Papadimitriou prove
that the general problem is NP-complete, and we are
interested resolving this contradiction.
Gosselin and Truchon solve each day separately and
model the problem as a linear program. To keep the
number of variables and constraints within reasonable
limits, they aggregate the rooms into groups of similar
size and facilities and aggregate classroom requests by
size, facilities and time period. They discovered that
the corresponding linear program always produced
integer solutions, although they were unable to prove
or disprove this statement in general. They tested their
procedure on several test problems and on actual data
from UniversitC Lava1 in Quebec.
In an appendix, Glassey and Mizrach claimed that
the four-period problem, when classes are either one
or two periods long. can be transformed into a network
problem with a polynomial solution. The proof of this
result was not included in the paper because the
problem addressed was more complex.
These results lead us to consider the complexity of
the problem. When is it NP-complete and under what
conditions does a polynomial solution exist? Our first
theorem concerns the most general formulation of the
constraints.
Theorem 1. The nonintealal classroom assign??lent
Feasibility problem is ,VP-complete. H i J phrase the
problen~ in tlze.fortn: Does there esist aft.a.sible assignrnenr
qf classes to roorns? U2 asslcme that cla.sses may
ineer several tirnes per ~t,eckb,z tt ihcj. rnztst be assigned
to chcl same roo~z,firall tncetings. (Note that this
asszlrnption 1r.a.r zrsed bj. Glassej~ and Mizrach at
Berkelt?,.)
Proof. Clearly, classroom assignment belongs to NP.
That is. given any assignment, we can test feasibility
in polynomial time. We will prove that the graph Kcolorability
problem is polynomially reducible to the
classroom assignment problem. Since K-colorability
is NP-complete (Garey and Johnson 1979). therefore,
classroom assignment is NP-complete.
Suppose that we are given a general graph coloring
problem. i.e., can the vertices of a given graph be
colored using at most K colors, such that no two
adjacent vertices have the same color? Let n be the
number of vertices in the graph and p be the number
of edges. We construct an equivalent classroom
assignment problem with K-identical classrooms,
n classes and p time periods. If edge e~ connects vertices
i and J, then classes i and j must both meet in
period k. This classroom assignment problem has a
feasible solution if and only if the corresponding
graph is K-colorable. Therefore, the noninterval
classroom assignment problem is NP-complete, as
required.
So. for the noninterval case of classroom assignment,
even the Feasibility question is NP-complete.
Since graph K-colorability is hard for K = 3, the
noninterval feasibility problem is hard even for only
three (identical) rooms. This problem does not need
to be very complex in order to be hard. Consider the
following simple example based on coloring the nodes
of a cycle of length five with two colors.
Example 1
Course Periods
A 1, 2
B 2 , 3
C 3, 4
D 4, 5
E I. 5
Given two equal rooms, the associated linear program
(LP) admits a feasible solution with every class in half
of each room. But, of course, one can easily recognize
that this problem has no feasible solution, even though
E is the only "noninterval" course. However, if we
were to bury several such odd cycles within a practical
problem, it would become very difficult to verify the
nonexistence of a feasible solution.
The noninterval problem states that, when a class
meets more than once a week, every meeting must
occur in the same room. This restriction is often
desirable, but it is not usually considered absolutely
necessary. In particular. when the problem is solved
one day at a time, as in Carter, and Gosselin and
Truchon, each class meets only once and the coloring
reduction no longer applies, i.e., each meeting is effectively
treated as a separate class and the whole week
becomes an interkal problem. In machine scheduling
applications, frequently an operation may not be
interrupted (so it must be performed on one machine).
but it is not necessary that all the operations for a job
he performed on the same machine. In this case, the
Feasibility question becomes quite easy.
Observation 2. The interval classroom assignment
Feasibility problem is polynomially solvable in O(n)
time.
Proof. From the proof of Theorem 1, clearly it is
sufficient to color the appropriate graph. But this
graph is an interval graph, which is well known to be
easily colorable. (It is perfect, so the minimum number
of rooms needed is equal to the maximum number of
classes in session at any time.) (See Golombic 1980,
chapter 8.j
Let us now consider the Satisfice case. Here we have
a situation actually faced by many schools.
Theorem 2. The interval classroom assignment
Satisfice problem is NP-complete.
This result, based on a reduction from 3-SAT, was
published independently by Arkin and Silverberg in
the context of job scheduling, and we will omit the
proof. However, we can strengthen their result considerably
with the use of an intermediate reduction of
When Is the Classroom Assignment Problem Hard? / S3 1
3-SAT. Theorem 3 represents a minor variation of
Theorem 2.1 in Tovey (1 984) (also hinted at in Garey
and Johnson without proof).
Theorem 3. Any instance of 3-SAT can be red~iccdt o
an instance of SATsuch that:
1. Each clause has two or three literals. Call these
2-clauses and 3-clauses, respectively.
2. No two 3-clauses have any literal in common
(where XI and X, are different literals).
3. No two 2-clauses have any literal in common.
Proof. Given any instance of 3-SAT and consider any
variable X, which has a duplicated literal. Suppose
that the variable X appears in r clauses as X and in s
clauses as 1.Let k = max(r,3 ) .Create k new variables
Yl, . . ., Yk, and replace the ith occurrence of X
with Y, for each i = 1, . . ., r (and 1with yl for each
i = 1, . . . , s). Append the clause (Y, V y,,,) for i =1, . . . ,k - 1 and the clause (YkV y,].
In this new instance, the clause (Y, V F,+,) implies
that, if Y, is false. then Y,,, must also be false. The
cyclic structure of the clauses therefore forces the Y,
variables to be either all true or all false. Moreover,
the transformation requires polynomial time. It is easy
to verify that, in the new instance. every literal occurs
at most once in all of the 2-clauses and at most once
in all of the 3-clauses, as required.
We can now show the stronger result.
Theorem 4. The interval classroom assignment
Satisfice problt?m is NP-complete even when the
problem is restricted to tivo periods.
Proof. Consider any special instance of SAT as
defined in Theorem 3. Suppose that there are n variables
X,. Let each variable represent two rooms called
TRUE, and FALSE, for a total of 2n rooms. For each
2-clause, define a class C,?which occurs in period 1.
Each of them has two preferred rooms corresponding
to the two literals in the clause. For example, if 2-
clause j contains the literal (XI V x2), then class C,?
prefers rooms TRUEI and FALSE2. Similarly, for each
3-clause, define a class Cj occurring only in period 2
and having three preferred rooms. Observe that, since
none of the 2-clauses have a common literal, all of the
classes in period 1 prefer different rooms. Similarly,
none of the period-2 classes have any preferred rooms
in common.
We now define a set of n classes, L, that meet for
both periods and prefer rooms TRUE, and FALSE,.
Observe that, if class L, gets preferred room TRUE,,
then all other classes C,? and Cj can only use room
FALSE,, i.e., the purpose of the L, is simply to force
each variable to be always true (if L, uses room
FALSE,) or always false (if L, uses room TRUE,).
Clearly, all classes can be assigned to their preferred
rooms if and only if the corresponding 3-SAT instance
is satisfiable.
Theorem 4 states that the classroom assignment
problem has the potential to become very nasty. However,
it does not help us to understand whether or not
difficult problems are likely to occur in a practical
setting. The following example illustrates that the
problem does not have to be very complex in order to
be computationally difficult.
Example 2
Satisfactory
Class Periods Rooms
A 1 1,2
B 1, 2 2, 3
C 1 3, 4
D 1, 2 1, 4
E 2 1, 3
F 2 2, 4
It is easy to show that we cannot assign all classes to
satisfactory rooms. For example, in period 1, if classes
A, B, C and D are assigned to rooms 1, 2, 3 and 4,
respectively, then there is no available satisfactory
room for class F in period 2, i.e., classes B and D use
both rooms 2 and 4. Conversely, if classes A, B, C and
D are assigned to rooms 2, 3, 4 and 1, respectively,
the only other solution, then there is no satisfactory
room for class E. In both cases, at least one class must
go in a room that is not satisfactory.
However, it is also easy to show that the optimal
LP relaxation finds a solution with x, = 0.5 for each
class i in each of its two preferred rooms. The LP finds
an answer when, in fact, no feasible solution exists.
After we had discovered the preceding example, we
realized that it could be derived from Theorems 3
and 4 in the following way. Consider the simplest
unsatisfiable SAT problem: (X) A (m.Convert it
to: (X V X) A (X V X), the simplest unsatisfiable
instance whose LP relaxation has a feasible solution.
That is,
Set X = X = 0.5.
Now, apply the transformation of Theorem 3 to get
the SAT instance:
(Y, V Y2) A (Fl V F2) A (Yl V 72) A (Y2 V F]).
Finally, apply the transformation of Theorem 4
treating the first two clauses as 3-clauses (corresponding
to classes E and F in period 2). This yields
Example 2 where:
Room 1 = TRUEl
Room 2 = FALSE2
Room 3 = TRUEz
Room 4 = FALSE,.
This derivation illustrates an interesting use of an
NP-completeness proof. The proof not only tells us
that the problem is hard, but also what kind of instances
ofthe problem are hard. This could be a useful,
general tool for finding difficult instances of NPcomplete
problems.
Arkin and Silverberg have developed a polynomial
algorithm for the interval Satisfice problem when the
number of rooms is fixed at some value m. Their
dynamic programming approach requires O(nm+')
operations, where n is the number of classes. Clearly,
this approach is reasonable only when the number of
rooms is very small. Their construction can also be
modified to solve the Optimize problem.
To summarize, even Feasibility is hard for noninterval
classroom assignment. Feasibility is easy for
interval classroom assignment, but Satisfice is hard,
once there are two or more periods in the day and
more than two types of rooms. If there is only one
period, even Optimize is easily solved as an assignment
problem.
3. MONOTONIC PREFERENCES, OR "I WANT
A BIGGER ROOM!"
The preceding results lead to some interesting questions.
If the problem is NP-complete for two periods,
then how did Glassey and Mizrach get a polynomial
algorithm for four periods, and why do Gosselin and
Truchon get integer solutions to the LP?
A partial explanation can be found by looking at
the assumptions underlying the construction of the 3-
SAT model. There are no restrictions on the patterns
of room preferences. In particular, in Example 2 of
Section 2, every pair of rooms is preferred by one of
the classes. Our model of the problem assumes that
there exists some subset of the available rooms that
can be preferred in almost any combination.
In the problem described by Carter, rooms may be
considered desirable for a variety of different reasons.
Location is one criterion, but nonadjacent buillngs
may be preferred. Some people prefer windowless
rooms for projection purposes, while others prefer lots
of sunlight. Some people request special facilities, such
as cinematography, televisions, computer hook-up capabilities,
and large blackboards. Certain seating types
are more appropriate for some types of classes. In the
model described, instructors can simply specify a list
of preferred rooms. One can visualize a wide variety
of combinations across 2,400 classes.
By contrast, the model described by Gosselin and
Truchon allows for each class to be assigned a list of
possible rooms in the order of preference. However,
in their testing, they used a single preference order for
all the rooms, primarily based on space. Each class
preference was based on the sublist, beginning with
the first room large enough to accommodate the class.
For these problems, the LP always found integer
solutions.
We will define this special case of the Satisfice
problem as having a monotonic preference function.
Specifically, there exists an ordering of the rooms, R1,
R2,.. . , R,, such that if a class i will accept room R,,
then class i will also accept any room Rk, where
k > j .
Kolen, Lenstra and Papadimitriou considered a related
machine scheduling problem. We are given a set
of jobs with fixed start times and durations and a set
of machines with different processor capacities, where
each job has a minimum required processor size. We
must determine whether or not there exists a feasible
assignment of jobs to machines. This is equivalent to
the interval monotonic Satisfice problem, i.e., where
the only assignment constraint is that the room has
enough seats to accommodate the class.
Kolen, Lenstra and Papadimitriou, and Dondeti
and Emmons were able to show the existence of a
polynomial algorithm when there are only two sizes
of processors (two room categories). This result is of
major importance for many secondary schools. Classrooms
are often designed with a fixed capacity and
any class will fit in any room (with possibly one or
two large auditoriums available for combined classes).
These problems are essentially trivial even when classes
are of many different lengths and all rooms are
not always available as long as there are enough rooms
in each time period. The problem remains easy when
special purpose space such as chemistry labs are included,
provided that such space can only be used by
chemistry classes, i.e., the problem can be decomposed
by the type of space required.
Kolen, Lenstra and Papadimitriou also showed that
the interval classroom assignment Satisfice problem
When Is the Classroom Assignment Problem Hard? / S33
with monotonic preferences is NP-hard if there are
three or more room categories. They employ a reduction
from "numerical 3-dimensional matching"
(Garey and Johnson). The construction requires a
fairly large number of periods proportional to the size
of the numbers in the corresponding matching problem.
We have been able to construct an example to
illustrate the type of situation that can occur.
Figure 1 contains a set of 28 classes that must be
assigned to eight rooms over eleven periods. There are
two large rooms, two medium rooms and four small
rooms available. The classes labeled I require a large
room, while those labeled I1 are medium sized classes
that need a medium or large room. The remaining
unlabeled classes can go in any room.
It is easy to verify that this problem has no feasible
solution. However, if we relax the integrality restriction
and solve it as a linear program, we discover that
there is a feasible fractional solution. Specifically, classes
marked (1) have half a medium and half a small
room; classes marked (2)have half a large and half a
small room; and classes marked (3) have half a large
and half a medium room. All other classes are assigned
to a single room of the required size.
Although we are not certain that this represents a
smallest possible example, we believe that it is very
close. It appears unlikely that one could construct a
situation with a gap between the LP solution and the
integer optima with much fewer than eleven periods.
This helps to explain the results of Gosselin and
Truchon. With a monotonic preference function and
fewer than eleven periods, we would expect that the
LP would always find an integer solution. It is also
possible that Glassey and Mizrach used a monotonic
assumption when they apparently proved the existence
of a polynomial solution for the 4-period
problem.
Periods: 1 2 3 4 5 6 7 8 9 10 11
Figure 1. Example 3.
This "I 1-periodm conjecture may have important
practical implications. If each day is solved separately
and the periods are all multiples of an hour, then the
normal day will be at most ten periods long. This is
true for many schools. Gosselin and Truchon describe
the problem at Universitk Lava1 as having this structure,
for example.
At the University of Waterloo, Carter describes a
problem that uses half-hour periods. However, each
half day is solved separately, so again, no subproblem
has more than ten periods. The conjecture does not
help in this case though because that problem is not
monotonic.
Our next result shows that, if the number of periods
is fixed at any level, then there is a polynomial solution
to the problem, even for the noninterval case.
Theorem 5. For anyjixed k, the k-period noninterval
(respectively, interval) monotonic Satisfice problem
can be solved in polynomial time ~ ( n ~(r~esmpec)-
tively, ~ ( n ' / ~ m ) ) .
Proof. We use dynamic programming. Let K =2k- 1. There are K different possible types of schedules
for each class, depending on whether the class meets
or not during period i:i = 1, . . . , k
For the interval problem
K can be taken as (k ;I).)
Arbitrarily index these K types by j = 1, . . . , K. For
example, if k = 2, the types could be 1, 2 and 1-2 for
j = 1, 2 and 3, respectively. We let F (for Feasible)
denote the collection of all 0-1 K-vectors representing
nonoverlapping sets of class types. For example, with
k = 2 and the indexing above,
since type 3 overlaps with types 1 and 2. Each member
f E F represents a feasible combination of classes that
can be assigned to a single room.
For ease of intuitive understanding, we phrase preferences
in terms of room size. The smallest room is
the least preferred. Arrange the m rooms from smallest
to largest. Let C, denote the K-vector of the number
of classes of each type which would fit into room i but
not into room i - 1. Thus, C, = the number of classes
of each type that fit into room 1.
First, we give a verbal description of the algorithm.
Our stages are to consider each room, in turn, assigning
classes to it. When we finish assigning classes to a
room, our state is characterized by how many of each
S34 / CARTERAND TOVEY
type of class have not yet been assigned a room, but
are small enough to fit into the next room under
consideration. A state, therefore, can be characterized
by a K-vector s of integers, where s, equals the number
of classes of type j ( j = 1, . . . , K). The key idea is
this: Any two classes of the same type that are small
enough to fit into the room under consideration are
indistinguishable. Since we consider the rooms in
order of increasing size, all we need to keep track of
is this K-vector. We do not need to keep track of the
exact size requirements of the unassigned classes, because
they are guaranteed to be small enough to fit
into the other rooms. As we start stage i, S, is a
collection of K-vectors that are the possible configurations
of classes that are unassigned, and which could
fit into room i, that is, S, is the set of possible state
vectors s at stage i. The process terminates affirmatively
if and only if Sm+, contains the 0 vector, i.e.,
after using the biggest room, all classes have been
assigned.
A more precise description of the algorithm follows:
Inputs: K; m; C,: i = I , .. . ,m; F.
Step 1. Initialize: Set i c 1;S,c (C,1.
Step 2. Put Classes in Room i: For each s E S,set
R(s) c ((s -f)l for all f E F; (s - f ) 3 0), i.e., R(s)
represents the set of all configurations of remaining
unassigned classes for each feasible assignment,f s s.
Step 3. Consolidate: Set R c UScs,R(s).R is the
set of all possible configurations of unassigned classes
of size i or less.
Step 4. Add Classes: Set S,,, cR + C,,, =((r + C,+~)lrE RJ
Step 5. Next Stage: Set i ti + 1; if i s m go to
Step 2.
Step 6. End: If 0 E Sm+, return YES, otherwise
return NO.
It is obvious that if the algorithm returns YES, there
is a satisfactory solution. Conversely, if T were a
satisficing solution, it would induce a sequence of s',
where sm+l=0, sm=the classes Tassignsto the biggest
rooms, etc. Then it is easy to see inductively that if
s' E S,,then sl+' E Sl+,,and so the algorithm will
return YES. Therefore, the algorithm works correctly.
Now we verify that the algorithm runs in polynomial
time. There are m iterations, one per room.
During any iteration, how many K-vectors can S
have? If there are n classes. an upper bound would be
the number of ways to distribute n or fewer identical
balls into K + 1 nonidentical runs. This is just
(e.g., see Lovasz 1979, p. 14), which is dominated by
nK,a function polynomial (though huge) in n. Since
IFI s 24 Step 2 takes at most
time. Clearly Step 2 dominates, so the total time is
O((2n)"m) = O(nKm),a polynomial as claimed.
This dynamic programming approach can be
streamlined considerably to improve its efficiency. In
Step 3, we construct the set of all possible K-vectors
of unassigned classes. Clearly, only the minimal elements
of this set need to be considered; the others are
dominated. For example, if two options A and B are
identical, except that option A leaves 20 classes meeting
from 8:00to 10:OOunassigned, and option B leaves
19 of this type unassigned, obviously B dominates A.
There is another more subtle kind of dominance.
We develop it by example. Suppose that the smallest
room holds ten students, and there is only one room
this size. Suppose that there are three classes, denoted
I , 2, 3 with i10 students, with meeting times 8:OO-
9:00, 9:OO-10:00, and 8:OO-10:00, respectively. In the
first iteration of the dynamic programming algorithm,
there are five possible options for assigning classes.
The obvious dominance from the previous paragraph
reduces this to two options, namely, (1, 2) and 13).
We can further reduce this to one option, namely (31.
This option dominates ( 1, 2) because any room that
would accommodate (3)would accommodate (1, 21.
(This is where we use the monotonicity that all remaining
rooms are big enough.) But a subsequent
classroom assignment that accommodated 1 and 2
might not accommodate 3, because 1 and 2 might be
in different rooms. Essentially, leaving (1, 2) unassigned
has more flexibility than leaving (3).
These dominance ideas can greatly improve the
📎 post-26-1182093711.rar (256 KB)
WHEN IS THE CLASSROOM ASSIGNMENT PROBLEM HARD?
MICHAEL W. CARTER
Cnwerslfj of Toronto, Toronto, Ontarlo, Canada
CRAIG A. TOVEY
Georgia Institute of Technology, Atlanta, Georgla
(Received February 1989; revision received March 1990; accepted January 199 1)
The classroom assignment (or hotel room or interval scheduling) problem is to assign classes, which meet at different
time intervals, to rooms. Two classes may not meet simultaneously in the same room, nor may a class meet in two
different rooms. Thousands of colleges and secondary schools face this problem every semester. There has been some
confusion as to how hard this problem is. Many colleges claim that it is easy, while others complain that it is next to
impossible. In the literature, some authors claim or conjecture polynomial time algorithms, while others develop heuristic
approaches. The goal of this paper is to resolve the confusion by identifying cases where the problem will be easy and
others where it will be hard. We focus on the kinds of cases that schedulers are apt to encounter in practice.
Hundreds of colleges and thousands of secondary
schools across North America are faced with
large classroom assignment problems every semester.
The vast majority of institutions "solve" the problem
manually, to a neverending chorus of complaints from
instructors. A few places employ simple computerassisted,
first-come, first-served heuristics.
For example, the University of Waterloo, prior to
1987. used to develop a complete new assignment of
classes to rooms every term. The manual process,
typical of many other universities, utilized a large
"room booking log" with one page for every room on
campus. The Central Scheduling Office estimates that
it took three experienced people two to three weeks to
develop the initial room assignments.
By comparison, at many universities, the room
assignments are essentially unchanged from one year
to the next. When a course is discontinued, the room
becomes free. When a new course is offered, they look
for the best available room at that time. Consequently,
people frequently must accept rooms that do not meet
their requirements, and the problem is compounded
annually.
There is some confusion as to the difficulty of
classroom assignment. Many colleges and secondary
schools claim that the problem is easy, while others
complain that the task is next to impossible. In the
literature, some authors claim or conjecture polynomial
time algorithms, while others develop heuristic
approaches. Our principal goal in this paper is to clear
Subject classifications: Education systems, operation: classroom assignment,
scheduling: applications.
Area of review: OPTIMIZATION.
up some of this confusion. To do this, we give some
new results, and also cite some work of others. It turns
out that the difficulty depends not only on the objective
and size of the problem, but on the underlying
preferences of classes for rooms. By considering the
kinds of situations actually encountered by schools,
we can resolve much of the contradictory evidence
that has been reported.
1. MATHEMATICAL FORMULATION OF THE
PROBLEM
The usual formulation of the problem is expressed in
terms of the variable x,], a 0-1 valued variable which
is equal to 1 when class i is assigned to room j and is
0 otherwise. Time is divided into periods (e.g., every
half hour, though all periods do not have to be the
same length). We sometimes wish to fix the number
of periods and refer to this case as the k-period problem.
The constraints of this problem are
and
2 x,/ 6 1 for j = 1, 2, . . , m; for all k,
lcPk
where Pk represents the set of all classes that meet in
period k. The first constraint ensures that every class
is assigned to some room, while the second constraint
course timetabling. Mathematics: computational complexity. Production/
OperationsResearch 0030-364X/92/4001-OS28 $0 1.25
Vol. 40, Supp. No. I, January-February 1992 O 1992 Operations Research Society of America
When Is the Classroom Assignment Problem Hard? / S29
prevents any room from having more than one class
in the same period. We define three objectives for this
problem:
Feasibility. Is there a feasible solution to the constraints
above?
Satisfice. Given, for each class i, a set of rooms S,
that are satisfactory, is there a feasible solution to the
constraints above that puts each class in a satisfactory
room?
Optimize. Assume the existence of a linear cost model
that adequately describes the problem and reflects
reasonable preferences. This is a standard assumption
and several papers describe such models (e.g., Glassey
and Mizrach 1986, Carter 1989). The cost of assigning
class i to room j is denoted c,,. The objective is to
minimize
Obviously, the three objectives are listed in nondecreasing
order of difficulty, regardless of other problem
characteristics. This is because Feasibility can be
modeled as a special case of Satisfice, which, in turn,
is a special case of Optimize. In particular, if we assign
a cost of 0 to all rooms j in the set S,, and a cost of 1
elsewhere, then Optimize gives the Satisfice solution
if the final total cost equals zero.
Of the three objectives, the one closest to problems
in practice is probably Satisfice. Manual schedulers
tend to think in terms of "acceptable" room assignments,
(e.g., enough seats, not too far away, special
facilities, etc.). They will not associate a specific numerical
rating to every possible combination of assignments.
Therefore, we will emphasize analysis of the
Satisfice objective in what follows.
Implicit in our integer programming formulation is
the constraint that a class is assigned to only one
room. That is, students do not have to change rooms
in the middle of a lecture! There are two versions of
the problem depending on how the word class is
interpreted. We call the first version the I-day or
interval problem. Ordinarily, classes meet once in a
day, from the beginning of one period to the beginning
of some other period. In this case, the class requires
the use of a room during an interval, hence, the
alternative name "interval scheduling." But classes
can meet more than once in a week. Some institutions
require that each class must have all of its meetings
in the same room. We call this version the multiday
or noninterval problem. Normally, we will interpret
the word class to mean a single meeting of a course,
so hereafter in the classroom assignment problem,
unless stated otherwise, we assume that each class
requires the use of a room for some set of consecutive
periods. For the sake of consistency, we will refer to
these problems as interval or noninterval.
Before proceeding to the results, we remark that the
classroom assignment model has several other applications,
including hotel room assignments, shipyard
scheduling, job scheduling on machines with varying
capabilities, and assigning airport gates to flights (see
Kolen, Lenstra and Papadimitriou 1987, Dondeti and
Emmons 1986, Mangoubi and Mathaisal 1985). In
the airport problem, Optimize is the appropriate objective;
in the others Satisfice is applicable.
2. COMPLEXITY RESULTS
Observe that, for the interval problem, if there is no
overlap of any class time periods, then even the
Optimize problem is easily solvable by classical
methods. For example, if all classes are one hour in
length and always begin on the hour, then each hour
of the day can be solved as a separate assignment
problem.
Observation 1. The 1-period classroom assignment
Optimize problem is polynomially solvable.
In many practical problems, classes will take on a
variety of different sizes. Secondary schools often utilize
single and double period courses. At the university
level. classes can be 1, 1.5, 2, 3 or 4 hours in length,
beginning every half hour.
Several heuristics for solving this problem have
appeared in the literature (Mulvey 1982, Ferland and
Roy 1985, Glassey and Mizrach 1986, Gosselin and
Truchon 1986, and Carter 1989). Two of these papers
(Glassey and Mizrach 1986, Gosselin and Truchon
1986) imply that it might be possible to develop a
polynomial algorithm. Papers by Arkin and Silverberg
(1987) and Kolen, Lenstra and Papadimitriou prove
that the general problem is NP-complete, and we are
interested resolving this contradiction.
Gosselin and Truchon solve each day separately and
model the problem as a linear program. To keep the
number of variables and constraints within reasonable
limits, they aggregate the rooms into groups of similar
size and facilities and aggregate classroom requests by
size, facilities and time period. They discovered that
the corresponding linear program always produced
integer solutions, although they were unable to prove
or disprove this statement in general. They tested their
procedure on several test problems and on actual data
from UniversitC Lava1 in Quebec.
In an appendix, Glassey and Mizrach claimed that
the four-period problem, when classes are either one
or two periods long. can be transformed into a network
problem with a polynomial solution. The proof of this
result was not included in the paper because the
problem addressed was more complex.
These results lead us to consider the complexity of
the problem. When is it NP-complete and under what
conditions does a polynomial solution exist? Our first
theorem concerns the most general formulation of the
constraints.
Theorem 1. The nonintealal classroom assign??lent
Feasibility problem is ,VP-complete. H i J phrase the
problen~ in tlze.fortn: Does there esist aft.a.sible assignrnenr
qf classes to roorns? U2 asslcme that cla.sses may
ineer several tirnes per ~t,eckb,z tt ihcj. rnztst be assigned
to chcl same roo~z,firall tncetings. (Note that this
asszlrnption 1r.a.r zrsed bj. Glassej~ and Mizrach at
Berkelt?,.)
Proof. Clearly, classroom assignment belongs to NP.
That is. given any assignment, we can test feasibility
in polynomial time. We will prove that the graph Kcolorability
problem is polynomially reducible to the
classroom assignment problem. Since K-colorability
is NP-complete (Garey and Johnson 1979). therefore,
classroom assignment is NP-complete.
Suppose that we are given a general graph coloring
problem. i.e., can the vertices of a given graph be
colored using at most K colors, such that no two
adjacent vertices have the same color? Let n be the
number of vertices in the graph and p be the number
of edges. We construct an equivalent classroom
assignment problem with K-identical classrooms,
n classes and p time periods. If edge e~ connects vertices
i and J, then classes i and j must both meet in
period k. This classroom assignment problem has a
feasible solution if and only if the corresponding
graph is K-colorable. Therefore, the noninterval
classroom assignment problem is NP-complete, as
required.
So. for the noninterval case of classroom assignment,
even the Feasibility question is NP-complete.
Since graph K-colorability is hard for K = 3, the
noninterval feasibility problem is hard even for only
three (identical) rooms. This problem does not need
to be very complex in order to be hard. Consider the
following simple example based on coloring the nodes
of a cycle of length five with two colors.
Example 1
Course Periods
A 1, 2
B 2 , 3
C 3, 4
D 4, 5
E I. 5
Given two equal rooms, the associated linear program
(LP) admits a feasible solution with every class in half
of each room. But, of course, one can easily recognize
that this problem has no feasible solution, even though
E is the only "noninterval" course. However, if we
were to bury several such odd cycles within a practical
problem, it would become very difficult to verify the
nonexistence of a feasible solution.
The noninterval problem states that, when a class
meets more than once a week, every meeting must
occur in the same room. This restriction is often
desirable, but it is not usually considered absolutely
necessary. In particular. when the problem is solved
one day at a time, as in Carter, and Gosselin and
Truchon, each class meets only once and the coloring
reduction no longer applies, i.e., each meeting is effectively
treated as a separate class and the whole week
becomes an interkal problem. In machine scheduling
applications, frequently an operation may not be
interrupted (so it must be performed on one machine).
but it is not necessary that all the operations for a job
he performed on the same machine. In this case, the
Feasibility question becomes quite easy.
Observation 2. The interval classroom assignment
Feasibility problem is polynomially solvable in O(n)
time.
Proof. From the proof of Theorem 1, clearly it is
sufficient to color the appropriate graph. But this
graph is an interval graph, which is well known to be
easily colorable. (It is perfect, so the minimum number
of rooms needed is equal to the maximum number of
classes in session at any time.) (See Golombic 1980,
chapter 8.j
Let us now consider the Satisfice case. Here we have
a situation actually faced by many schools.
Theorem 2. The interval classroom assignment
Satisfice problem is NP-complete.
This result, based on a reduction from 3-SAT, was
published independently by Arkin and Silverberg in
the context of job scheduling, and we will omit the
proof. However, we can strengthen their result considerably
with the use of an intermediate reduction of
When Is the Classroom Assignment Problem Hard? / S3 1
3-SAT. Theorem 3 represents a minor variation of
Theorem 2.1 in Tovey (1 984) (also hinted at in Garey
and Johnson without proof).
Theorem 3. Any instance of 3-SAT can be red~iccdt o
an instance of SATsuch that:
1. Each clause has two or three literals. Call these
2-clauses and 3-clauses, respectively.
2. No two 3-clauses have any literal in common
(where XI and X, are different literals).
3. No two 2-clauses have any literal in common.
Proof. Given any instance of 3-SAT and consider any
variable X, which has a duplicated literal. Suppose
that the variable X appears in r clauses as X and in s
clauses as 1.Let k = max(r,3 ) .Create k new variables
Yl, . . ., Yk, and replace the ith occurrence of X
with Y, for each i = 1, . . ., r (and 1with yl for each
i = 1, . . . , s). Append the clause (Y, V y,,,) for i =1, . . . ,k - 1 and the clause (YkV y,].
In this new instance, the clause (Y, V F,+,) implies
that, if Y, is false. then Y,,, must also be false. The
cyclic structure of the clauses therefore forces the Y,
variables to be either all true or all false. Moreover,
the transformation requires polynomial time. It is easy
to verify that, in the new instance. every literal occurs
at most once in all of the 2-clauses and at most once
in all of the 3-clauses, as required.
We can now show the stronger result.
Theorem 4. The interval classroom assignment
Satisfice problt?m is NP-complete even when the
problem is restricted to tivo periods.
Proof. Consider any special instance of SAT as
defined in Theorem 3. Suppose that there are n variables
X,. Let each variable represent two rooms called
TRUE, and FALSE, for a total of 2n rooms. For each
2-clause, define a class C,?which occurs in period 1.
Each of them has two preferred rooms corresponding
to the two literals in the clause. For example, if 2-
clause j contains the literal (XI V x2), then class C,?
prefers rooms TRUEI and FALSE2. Similarly, for each
3-clause, define a class Cj occurring only in period 2
and having three preferred rooms. Observe that, since
none of the 2-clauses have a common literal, all of the
classes in period 1 prefer different rooms. Similarly,
none of the period-2 classes have any preferred rooms
in common.
We now define a set of n classes, L, that meet for
both periods and prefer rooms TRUE, and FALSE,.
Observe that, if class L, gets preferred room TRUE,,
then all other classes C,? and Cj can only use room
FALSE,, i.e., the purpose of the L, is simply to force
each variable to be always true (if L, uses room
FALSE,) or always false (if L, uses room TRUE,).
Clearly, all classes can be assigned to their preferred
rooms if and only if the corresponding 3-SAT instance
is satisfiable.
Theorem 4 states that the classroom assignment
problem has the potential to become very nasty. However,
it does not help us to understand whether or not
difficult problems are likely to occur in a practical
setting. The following example illustrates that the
problem does not have to be very complex in order to
be computationally difficult.
Example 2
Satisfactory
Class Periods Rooms
A 1 1,2
B 1, 2 2, 3
C 1 3, 4
D 1, 2 1, 4
E 2 1, 3
F 2 2, 4
It is easy to show that we cannot assign all classes to
satisfactory rooms. For example, in period 1, if classes
A, B, C and D are assigned to rooms 1, 2, 3 and 4,
respectively, then there is no available satisfactory
room for class F in period 2, i.e., classes B and D use
both rooms 2 and 4. Conversely, if classes A, B, C and
D are assigned to rooms 2, 3, 4 and 1, respectively,
the only other solution, then there is no satisfactory
room for class E. In both cases, at least one class must
go in a room that is not satisfactory.
However, it is also easy to show that the optimal
LP relaxation finds a solution with x, = 0.5 for each
class i in each of its two preferred rooms. The LP finds
an answer when, in fact, no feasible solution exists.
After we had discovered the preceding example, we
realized that it could be derived from Theorems 3
and 4 in the following way. Consider the simplest
unsatisfiable SAT problem: (X) A (m.Convert it
to: (X V X) A (X V X), the simplest unsatisfiable
instance whose LP relaxation has a feasible solution.
That is,
Set X = X = 0.5.
Now, apply the transformation of Theorem 3 to get
the SAT instance:
(Y, V Y2) A (Fl V F2) A (Yl V 72) A (Y2 V F]).
Finally, apply the transformation of Theorem 4
treating the first two clauses as 3-clauses (corresponding
to classes E and F in period 2). This yields
Example 2 where:
Room 1 = TRUEl
Room 2 = FALSE2
Room 3 = TRUEz
Room 4 = FALSE,.
This derivation illustrates an interesting use of an
NP-completeness proof. The proof not only tells us
that the problem is hard, but also what kind of instances
ofthe problem are hard. This could be a useful,
general tool for finding difficult instances of NPcomplete
problems.
Arkin and Silverberg have developed a polynomial
algorithm for the interval Satisfice problem when the
number of rooms is fixed at some value m. Their
dynamic programming approach requires O(nm+')
operations, where n is the number of classes. Clearly,
this approach is reasonable only when the number of
rooms is very small. Their construction can also be
modified to solve the Optimize problem.
To summarize, even Feasibility is hard for noninterval
classroom assignment. Feasibility is easy for
interval classroom assignment, but Satisfice is hard,
once there are two or more periods in the day and
more than two types of rooms. If there is only one
period, even Optimize is easily solved as an assignment
problem.
3. MONOTONIC PREFERENCES, OR "I WANT
A BIGGER ROOM!"
The preceding results lead to some interesting questions.
If the problem is NP-complete for two periods,
then how did Glassey and Mizrach get a polynomial
algorithm for four periods, and why do Gosselin and
Truchon get integer solutions to the LP?
A partial explanation can be found by looking at
the assumptions underlying the construction of the 3-
SAT model. There are no restrictions on the patterns
of room preferences. In particular, in Example 2 of
Section 2, every pair of rooms is preferred by one of
the classes. Our model of the problem assumes that
there exists some subset of the available rooms that
can be preferred in almost any combination.
In the problem described by Carter, rooms may be
considered desirable for a variety of different reasons.
Location is one criterion, but nonadjacent buillngs
may be preferred. Some people prefer windowless
rooms for projection purposes, while others prefer lots
of sunlight. Some people request special facilities, such
as cinematography, televisions, computer hook-up capabilities,
and large blackboards. Certain seating types
are more appropriate for some types of classes. In the
model described, instructors can simply specify a list
of preferred rooms. One can visualize a wide variety
of combinations across 2,400 classes.
By contrast, the model described by Gosselin and
Truchon allows for each class to be assigned a list of
possible rooms in the order of preference. However,
in their testing, they used a single preference order for
all the rooms, primarily based on space. Each class
preference was based on the sublist, beginning with
the first room large enough to accommodate the class.
For these problems, the LP always found integer
solutions.
We will define this special case of the Satisfice
problem as having a monotonic preference function.
Specifically, there exists an ordering of the rooms, R1,
R2,.. . , R,, such that if a class i will accept room R,,
then class i will also accept any room Rk, where
k > j .
Kolen, Lenstra and Papadimitriou considered a related
machine scheduling problem. We are given a set
of jobs with fixed start times and durations and a set
of machines with different processor capacities, where
each job has a minimum required processor size. We
must determine whether or not there exists a feasible
assignment of jobs to machines. This is equivalent to
the interval monotonic Satisfice problem, i.e., where
the only assignment constraint is that the room has
enough seats to accommodate the class.
Kolen, Lenstra and Papadimitriou, and Dondeti
and Emmons were able to show the existence of a
polynomial algorithm when there are only two sizes
of processors (two room categories). This result is of
major importance for many secondary schools. Classrooms
are often designed with a fixed capacity and
any class will fit in any room (with possibly one or
two large auditoriums available for combined classes).
These problems are essentially trivial even when classes
are of many different lengths and all rooms are
not always available as long as there are enough rooms
in each time period. The problem remains easy when
special purpose space such as chemistry labs are included,
provided that such space can only be used by
chemistry classes, i.e., the problem can be decomposed
by the type of space required.
Kolen, Lenstra and Papadimitriou also showed that
the interval classroom assignment Satisfice problem
When Is the Classroom Assignment Problem Hard? / S33
with monotonic preferences is NP-hard if there are
three or more room categories. They employ a reduction
from "numerical 3-dimensional matching"
(Garey and Johnson). The construction requires a
fairly large number of periods proportional to the size
of the numbers in the corresponding matching problem.
We have been able to construct an example to
illustrate the type of situation that can occur.
Figure 1 contains a set of 28 classes that must be
assigned to eight rooms over eleven periods. There are
two large rooms, two medium rooms and four small
rooms available. The classes labeled I require a large
room, while those labeled I1 are medium sized classes
that need a medium or large room. The remaining
unlabeled classes can go in any room.
It is easy to verify that this problem has no feasible
solution. However, if we relax the integrality restriction
and solve it as a linear program, we discover that
there is a feasible fractional solution. Specifically, classes
marked (1) have half a medium and half a small
room; classes marked (2)have half a large and half a
small room; and classes marked (3) have half a large
and half a medium room. All other classes are assigned
to a single room of the required size.
Although we are not certain that this represents a
smallest possible example, we believe that it is very
close. It appears unlikely that one could construct a
situation with a gap between the LP solution and the
integer optima with much fewer than eleven periods.
This helps to explain the results of Gosselin and
Truchon. With a monotonic preference function and
fewer than eleven periods, we would expect that the
LP would always find an integer solution. It is also
possible that Glassey and Mizrach used a monotonic
assumption when they apparently proved the existence
of a polynomial solution for the 4-period
problem.
Periods: 1 2 3 4 5 6 7 8 9 10 11
Figure 1. Example 3.
This "I 1-periodm conjecture may have important
practical implications. If each day is solved separately
and the periods are all multiples of an hour, then the
normal day will be at most ten periods long. This is
true for many schools. Gosselin and Truchon describe
the problem at Universitk Lava1 as having this structure,
for example.
At the University of Waterloo, Carter describes a
problem that uses half-hour periods. However, each
half day is solved separately, so again, no subproblem
has more than ten periods. The conjecture does not
help in this case though because that problem is not
monotonic.
Our next result shows that, if the number of periods
is fixed at any level, then there is a polynomial solution
to the problem, even for the noninterval case.
Theorem 5. For anyjixed k, the k-period noninterval
(respectively, interval) monotonic Satisfice problem
can be solved in polynomial time ~ ( n ~(r~esmpec)-
tively, ~ ( n ' / ~ m ) ) .
Proof. We use dynamic programming. Let K =2k- 1. There are K different possible types of schedules
for each class, depending on whether the class meets
or not during period i:i = 1, . . . , k
For the interval problem
K can be taken as (k ;I).)
Arbitrarily index these K types by j = 1, . . . , K. For
example, if k = 2, the types could be 1, 2 and 1-2 for
j = 1, 2 and 3, respectively. We let F (for Feasible)
denote the collection of all 0-1 K-vectors representing
nonoverlapping sets of class types. For example, with
k = 2 and the indexing above,
since type 3 overlaps with types 1 and 2. Each member
f E F represents a feasible combination of classes that
can be assigned to a single room.
For ease of intuitive understanding, we phrase preferences
in terms of room size. The smallest room is
the least preferred. Arrange the m rooms from smallest
to largest. Let C, denote the K-vector of the number
of classes of each type which would fit into room i but
not into room i - 1. Thus, C, = the number of classes
of each type that fit into room 1.
First, we give a verbal description of the algorithm.
Our stages are to consider each room, in turn, assigning
classes to it. When we finish assigning classes to a
room, our state is characterized by how many of each
S34 / CARTERAND TOVEY
type of class have not yet been assigned a room, but
are small enough to fit into the next room under
consideration. A state, therefore, can be characterized
by a K-vector s of integers, where s, equals the number
of classes of type j ( j = 1, . . . , K). The key idea is
this: Any two classes of the same type that are small
enough to fit into the room under consideration are
indistinguishable. Since we consider the rooms in
order of increasing size, all we need to keep track of
is this K-vector. We do not need to keep track of the
exact size requirements of the unassigned classes, because
they are guaranteed to be small enough to fit
into the other rooms. As we start stage i, S, is a
collection of K-vectors that are the possible configurations
of classes that are unassigned, and which could
fit into room i, that is, S, is the set of possible state
vectors s at stage i. The process terminates affirmatively
if and only if Sm+, contains the 0 vector, i.e.,
after using the biggest room, all classes have been
assigned.
A more precise description of the algorithm follows:
Inputs: K; m; C,: i = I , .. . ,m; F.
Step 1. Initialize: Set i c 1;S,c (C,1.
Step 2. Put Classes in Room i: For each s E S,set
R(s) c ((s -f)l for all f E F; (s - f ) 3 0), i.e., R(s)
represents the set of all configurations of remaining
unassigned classes for each feasible assignment,f s s.
Step 3. Consolidate: Set R c UScs,R(s).R is the
set of all possible configurations of unassigned classes
of size i or less.
Step 4. Add Classes: Set S,,, cR + C,,, =((r + C,+~)lrE RJ
Step 5. Next Stage: Set i ti + 1; if i s m go to
Step 2.
Step 6. End: If 0 E Sm+, return YES, otherwise
return NO.
It is obvious that if the algorithm returns YES, there
is a satisfactory solution. Conversely, if T were a
satisficing solution, it would induce a sequence of s',
where sm+l=0, sm=the classes Tassignsto the biggest
rooms, etc. Then it is easy to see inductively that if
s' E S,,then sl+' E Sl+,,and so the algorithm will
return YES. Therefore, the algorithm works correctly.
Now we verify that the algorithm runs in polynomial
time. There are m iterations, one per room.
During any iteration, how many K-vectors can S
have? If there are n classes. an upper bound would be
the number of ways to distribute n or fewer identical
balls into K + 1 nonidentical runs. This is just
(e.g., see Lovasz 1979, p. 14), which is dominated by
nK,a function polynomial (though huge) in n. Since
IFI s 24 Step 2 takes at most
time. Clearly Step 2 dominates, so the total time is
O((2n)"m) = O(nKm),a polynomial as claimed.
This dynamic programming approach can be
streamlined considerably to improve its efficiency. In
Step 3, we construct the set of all possible K-vectors
of unassigned classes. Clearly, only the minimal elements
of this set need to be considered; the others are
dominated. For example, if two options A and B are
identical, except that option A leaves 20 classes meeting
from 8:00to 10:OOunassigned, and option B leaves
19 of this type unassigned, obviously B dominates A.
There is another more subtle kind of dominance.
We develop it by example. Suppose that the smallest
room holds ten students, and there is only one room
this size. Suppose that there are three classes, denoted
I , 2, 3 with i10 students, with meeting times 8:OO-
9:00, 9:OO-10:00, and 8:OO-10:00, respectively. In the
first iteration of the dynamic programming algorithm,
there are five possible options for assigning classes.
The obvious dominance from the previous paragraph
reduces this to two options, namely, (1, 2) and 13).
We can further reduce this to one option, namely (31.
This option dominates ( 1, 2) because any room that
would accommodate (3)would accommodate (1, 21.
(This is where we use the monotonicity that all remaining
rooms are big enough.) But a subsequent
classroom assignment that accommodated 1 and 2
might not accommodate 3, because 1 and 2 might be
in different rooms. Essentially, leaving (1, 2) unassigned
has more flexibility than leaving (3).
These dominance ideas can greatly improve the
📎 post-26-1182093711.rar (256 KB)
3 楼
这么长的题目头都晕啊老天。
4 楼
我本科的毕业论文写的就是课程表安排问题的读书笔记,很麻烦,考虑因素一多就乱了
5 楼
够长,看不懂。