paper - People Server at UNCW

Class Scheduling Algorithms
Victor Mancha
Kunta Lowe
Students of Computer Science at the University of North Carolina Wilmington
CSC 380
Abstract
Students face many problems in their
college career, professors, exams, attendance,
but the number one factor these problems have
in common is they belong to a class. Students
must choose their classes within a certain order
so that they may graduate and get a good
paying job, but how do they choose this order
and how can we make it more effective? Our
team has looked into this problem and done
research on different algorithms so that we may
optimize class scheduling for future students.
The algorithms we used were: Dijkstra’s
algorithm, Bellman-Ford’s algorithm and A*
search algorithm. We conducted many trials
and experiments, testing and learning about
each algorithm searching for the most optimal
way to schedule classes.
Key Words: Dijkstra’s algorithm, Bellman-Ford’s
algorithm, A* search algorithm, weight,
Shortest-Path Finding Algorithms, Acyclic Graph
1. Introduction
Deciding which classes to take is a difficult
and time consuming process for all students. If
someone wants to graduate with a degree in
Computer Science and a concentration in
Systems, what classes are needed and in what
order should that person take them? The goal
of our research is to find the most optimal
algorithm for scheduling classes for students.
The algorithms we conducted our research
upon are Dijkstra’s algorithm, Bellman-Ford’s
algorithm and A* search algorithm. Each of
which was tested based on a graph of x amount
of given classes and how fast and efficient the
algorithm could produce a set of results. The
Computer Science department was the main set
of classes used in trials due to the familiarity
our team had with these classes. We based our
results with past students schedules to test if
the algorithms produced appropriate schedules
for students. The graphs consisted of classes
(ex. CSC 131, 231, etc.), each of which was given
a “weight”, the cost of traversing from one
vertex to the next. In order to decide how much
a certain class “weighed”, we used the
University of North Carolina Wilmington’s
Computer Science Course Offering Catalogues
to see how many credit hours each course cost.
The credit hours were the numbers we used for
the “weight” of an edge to a vertex. We then
had each algorithm traverse the graph one class
at a time, searching for the most optimal path
of classes that needed to be taken to reach a
state called “Graduated”, which signified that
the student met all requirements for that
degree and would graduate with that degree.
2. Formal Statement
The goal for our project was to find the most
optimal path for a student to traverse from
class A to class B within a directed weighted
graph. G = (V, E) where G represents a graph
made up of a set of Vertices (V) and a set of
Edges (E). p = (v1,...,vn) such that vi ~ vi+1, where
p is a path that is a sequence of vertices that
traverses from v1 to vn. The total distance for p
is represented by d(p) = ∑𝑛𝑖 w(ei), where ei =
(vi,vi+1), which means that the total distance is
the sum of the weights of the edges from v1 to
vn.
3. Algorithms
There were many algorithms that we
considered in the beginning that we believed
would help us reach our goal, but as time
progressed, we realized that we had a very
specific goal in mind and that only certain
algorithms would help us reach that goal. We
then limited our use of algorithms to only
Shortest-Path Finding Algorithms. This meant
that given a weighted graph (see Figure 3.1 at
the bottom), a graph with a weight attached to
each edge, the algorithm would calculate the
shortest/least costing path from vertex A to
vertex B, starting class to destination class.
3.1 Dijkstra’s Algorithm
The first algorithm that we researched was
Dijkstra’s Algorithm. Edsger Dijkstra founded
Dijkstra’s Algorithm in 1959 in order to solve
the shortest path problem. The goal was to find
the shortest path between nodes in a graph.
Dijkstra’s algorithm would be incorrect in
finding the shortest path in a graph with
negative weights. Using the same logic as
Dijkstra, we implemented his algorithm to find
the shortest path for a student to graduate with
a degree of their choice. The algorithm runs in
O (|V|2), where |V| is the number of nodes. In
terms of our research, the user selects a class,
this class represents the starting node. From
this class, the algorithm searches through the
graph to find the shortest path to a destination
node. In terms of our trials, the destination
node was not always “Graduate”, but a variety
of classes, some even being the next class after
the previous one. Dijkstra’s algorithm is a
greedy algorithm. This means that at each node
in the graph, the algorithm will use the best
path found so far. This ensures that the path
consists of the shortest/least-costing vertices
from the starting class to the destination class.
Dijkstra’s algorithm looks at the big picture. This
means that if two immediate edges cost the
same weight, the algorithm will look further
down the road and chose the least costing path
to ensure optimization.
3.2 Bellman-Ford’s Algorithm
The second algorithm we researched was
the Bellman-Ford’s Algorithm. This algorithm
computes the shortest path from a single
sourced vertex to every other vertex in a
weighted di-graph (a graph with negative
weights). Bellman-Fords algorithm is similar to
Dijkstra’s but much slower in finding the
shortest path. It stores information about the
distance from the current Node to its closest
short distance neighbor. Since our course graph
was a directed graph, we employed different
algorithms to test the possibility of failing a
class, which Bellman-Ford would take into
account to figure out the shortest path to
graduate using the course credit hours as the
weights for the Nodes. We modified the
Bellman-Ford algorithm into 3 different types of
algorithms, the negative, unweighted and
acyclic algorithms. Negative algorithm was to
find the shortest path from a starting class to
graduation taking into consideration the
possibility of failing a class. Unweighted was to
test the shortest path from a start class with all
the classes having the same or no weights. The
last algorithm, acyclic, which is the type of
graph we used (see Figure 3.1), is to find the
shortest path from start to end with no class
leading back to itself. The runtime for Bellman-
Ford is O (|V| * |E|) with V as the number of
Vertices and E as the number of Edges.
3.3 A* Search Algorithm
A* algorithm is a path-finding algorithm
that follows the least cost path from a starting
node to a destination node, keeping track of the
alternate paths segments in a Priority Queue.
The runtime for A* is O (|V|) or O (|E|). A* was
considered as an algorithm that can be used for
finding the shortest path in our course graph
search but due to the lack of time, we couldn’t
apply the algorithms to the graph (see 6. Future
Works).
4. Results
After conducting research on each of the
algorithms, our team predicted that Dijkstra’s
algorithm was going to produce the fastest
results. We started by creating two arrays that
held 1000 nodes, a starting node array and a
destination node array. We then implemented
each algorithm with these arrays and calculated
the average runtimes (see Figure 4.1 at the
bottom). Dijkstra’s algorithm had an average
runtime of 9000 nanoseconds. The singlesource unweighted shortest-path algorithm had
an average runtime of 6,700 nanoseconds. The
single-source negative-weighted shortest-path
algorithm had an average runtime of 7,300
nanoseconds. The single-source negativeweighted acyclic graph shortest-path algorithm
had an average runtime of 11,300 nanoseconds.
Theoretically, Dijkstra’s algorithm should have
been superior in runtime due to its nature of
searching through entire graphs and finding the
most optimal paths. However, it is believed that
due to the small size of our graphs, the BellmanFord algorithms were faster because of their
ability to pick short term gains instead of long
term gains at a better rate. In terms of
efficiency, both Dijkstra’s algorithm and the
Bellman-Ford algorithms chose the
shortest/least costing paths; however, the
directions that these algorithms took were
different (see Figure 4.2 and 4.3). The figures
show that Dijkstra’s algorithm prints a path
from MAT111 to CSC421 by taking MAT111 to
get to CSC133 to get to CSC231 to get to CSC340
to get to CSC421, the final destination. When
the credit hours are added up, the total is 13
credit hours (3 + 3 + 4 + 3). The Bellman-Ford
algorithms calculated a different path, MAT111
to CSC421 by taking MAT111 to get to CSC 131
to get to CSC220 to get to CSC320 to get to
CSC421, the final destination. When the credit
hours are added up, the total is 13 hours as well
(3 + 4 + 3 + 3). Therefore, we can conclude that
while the different algorithms produced
different paths, the results show that they were
all optimal and cost effective, with runtime
being the deciding factor in which is the most
optimal (the unweighted Bellman-Ford
algorithm).
5. Why 380?
By taking 380, our team was able to discuss
general techniques that apply to many different
problems across many different platforms. We
were able to analyze different shortest path
algorithms and optimize a path from class A to
class B. We were able to learn how to design
efficient and low maintenance algorithms with
reasonable computation times and we were
able to take a difficult problem, deciding the
future schedules of students, and programming
a computer to calculate the most optimal paths.
We believe that this has been a very helpful and
productive class in terms of the design and
analysis of algorithms.
6. Future Works
8. References
In the event that our team had more time,
we would have liked to conduct more research
on A* search and its capabilities to find the
shortest/least costing path. We believe that A*
search could have proven to be more optimal
than both Dijkstra’s algorithm and BellmanFord’s algorithm. We also would have liked to
expand on courses that require co-requisites so
that we would have been able to include the
other courses into the path from start to end.
The last thing we would have liked to do is
expand our problem, as well as, the algorithms
that we could use with it. We want to do more
than just pick the most optimal paths for
classes. We want to expand the problem to life
events and choices as well.
[1]http://www.ifors.ms.unimelb.edu.au/tutorial
/dijkstra_new/
7. Conclusion
The journey our team had tackling the
shortest path problem was an interesting one.
We started off trying to implement a graphical
user interface that ran each of these algorithms,
but then we realized that we were no longer
focused on the design and analysis of our
algorithms, but on the functionality and userfriendliness of our project. We learned about
Dijkstra’s algorithm, Bellman-Ford’s algorithm,
and briefly touched upon A* search. Although
Bellman-Ford’s unweighted modified form of
the algorithm proved to be the most optimal,
we still believe that Dijkstra’s algorithm had the
potential to surpass all the rest if given a large
enough graph to work with. In the end, this has
been a fun project to work on and we will use
what we have learned in the course in our
future endeavors.
[2]http://en.wikipedia.org/wiki/Shortest_path_
problem#Algorithms
[3]http://en.wikipedia.org/wiki/Dijkstra%27s_al
gorithm
[4]http://en.wikipedia.org/wiki/Bellman%E2%8
0%93Ford_algorithm
[5]http://en.wikipedia.org/wiki/Directed_acycli
c_graph
[6]http://courses.csail.mit.edu/6.006/spring11/l
ectures/lec15.pdf
[7]https://www.cs.auckland.ac.nz/software/Alg
Anim/dijkstra.html
Figures
Figure 3.1
Runtime of Algorithms
400000
350000
300000
Nanoseconds
250000
200000
150000
100000
50000
0
Dijkstra
Unweighted
Negative
Acyclic
1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 Trials
49 52 55 58 61 64 67 70 73 76 79 82 85 88 91 94 97
Figure 4.1
Figure 4.2
Figure 4.3