Activity selection problem
   HOME

TheInfoList



OR:

The activity selection problem is a
combinatorial optimization Combinatorial optimization is a subfield of mathematical optimization that consists of finding an optimal object from a finite set of objects, where the set of feasible solutions is discrete or can be reduced to a discrete set. Typical combi ...
problem concerning the selection of non-conflicting activities to perform within a given
time frame Time is the continued sequence of existence and events that occurs in an apparently irreversible succession from the past, through the present, into the future. It is a component quantity of various measurements used to sequence events, to c ...
, given a set of activities each marked by a start time (si) and finish time (fi). The problem is to select the maximum number of activities that can be performed by a single person or
machine A machine is a physical system using Power (physics), power to apply Force, forces and control Motion, movement to perform an action. The term is commonly applied to artificial devices, such as those employing engines or motors, but also to na ...
, assuming that a person can only work on a single activity at a time. The activity selection problem is also known as the Interval scheduling maximization problem (ISMP), which is a special type of the more general
Interval Scheduling Interval scheduling is a class of problems in computer science, particularly in the area of algorithm design. The problems consider a set of tasks. Each task is represented by an ''interval'' describing the time in which it needs to be processed b ...
problem. A classic application of this problem is in scheduling a room for multiple
competing Competition is a rivalry where two or more parties strive for a common goal which cannot be shared: where one's gain is the other's loss (an example of which is a zero-sum game). Competition can arise between entities such as organisms, indivi ...
events, each having its own time requirements (start and end time), and many more arise within the framework of
operations research Operations research ( en-GB, operational research) (U.S. Air Force Specialty Code: Operations Analysis), often shortened to the initialism OR, is a discipline that deals with the development and application of analytical methods to improve deci ...
.


Formal definition

Assume there exist ''n'' activities with each of them being represented by a start time ''si'' and finish time ''fi''. Two activities ''i'' and ''j'' are said to be non-conflicting if ''si'' ≥ ''fj'' or ''sj'' ≥ ''fi''. The activity selection problem consists in finding the maximal solution set (S) of non-conflicting activities, or more precisely there must exist no
solution set In mathematics, a solution set is the set of values that satisfy a given set of equations or inequalities. For example, for a set of polynomials over a ring , the solution set is the subset of on which the polynomials all vanish (evaluate to ...
S' such that , S', > , S, in the case that multiple maximal solutions have equal sizes.


Optimal solution

The activity selection problem is notable in that using a
greedy algorithm A greedy algorithm is any algorithm that follows the problem-solving heuristic of making the locally optimal choice at each stage. In many problems, a greedy strategy does not produce an optimal solution, but a greedy heuristic can yield locally ...
to find a solution will always result in an
optimal solution In mathematics, computer science and economics, an optimization problem is the problem of finding the ''best'' solution from all feasible solutions. Optimization problems can be divided into two categories, depending on whether the variables ...
. A
pseudocode In computer science, pseudocode is a plain language description of the steps in an algorithm or another system. Pseudocode often uses structural conventions of a normal programming language, but is intended for human reading rather than machine re ...
sketch of the iterative version of the algorithm and a proof of the optimality of its result are included below.


Algorithm

Greedy-Iterative-Activity-Selector(A, s, f): Sort A by finish times stored in f S = k = 1 n = A.length for i = 2 to n: if s ≥ f S = S U k = i return S


Explanation

Line 1: This algorithm is called ''Greedy-Iterative-Activity-Selector'', because it is first of all a greedy algorithm, and then it is iterative. There's also a recursive version of this greedy algorithm. *A is an array containing the ''activities''. * s is an array containing the ''start times'' of the activities in A. * f is an array containing the ''finish times'' of the activities in A. Note that these arrays are indexed starting from 1 up to the length of the corresponding array. Line 3: Sorts in ''increasing order of finish times'' the array of activities A by using the finish times stored in the array f. This operation can be done in O(n \cdot \log n) time, using for example merge sort, heap sort, or quick sort algorithms. Line 4: Creates a set S to store the ''selected activities'', and initialises it with the activity A /math> that has the earliest finish time. Line 5: Creates a variable k that keeps track of the index of the last selected activity. Line 9: Starts iterating from the second element of that array A up to its last element. Lines 10,11: If the ''start time'' s /math> of the ith activity (A /math>) is greater or equal to the ''finish time'' f /math> of the ''last selected activity'' (A /math>), then A /math> is compatible to the selected activities in the set S, and thus it can be added to S. Line 12: The index of the last selected activity is updated to the just added activity A /math>.


Proof of optimality

Let S = \ be the set of activities ordered by finish time. Assume that A\subseteq S is an optimal solution, also ordered by finish time; and that the index of the first activity in ''A'' is k\neq 1, i.e., this optimal solution ''does not'' start with the greedy choice. We will show that B = (A \setminus \) \cup \, which begins with the greedy choice (activity 1), is another optimal solution. Since f_1 \leq f_k, and the activities in A are disjoint by definition, the activities in B are also disjoint. Since ''B'' has the same number of activities as ''A'', that is, , A, = , B, , ''B'' is also optimal. Once the greedy choice is made, the problem reduces to finding an optimal solution for the subproblem. If ''A'' is an optimal solution to the original problem ''S'' containing the greedy choice, then A^\prime = A \setminus \ is an optimal solution to the activity-selection problem S' = \. Why? If this were not the case, pick a solution ''B''′ to ''S''′ with more activities than ''A''′ containing the greedy choice for ''S''′. Then, adding 1 to ''B''′ would yield a feasible solution ''B'' to ''S'' with more activities than ''A'', contradicting the optimality.


Weighted activity selection problem

The generalized version of the activity selection problem involves selecting an optimal set of non-overlapping activities such that the total weight is maximized. Unlike the unweighted version, there is no greedy solution to the weighted activity selection problem. However, a
dynamic programming Dynamic programming is both a mathematical optimization method and a computer programming method. The method was developed by Richard Bellman in the 1950s and has found applications in numerous fields, from aerospace engineering to economics. I ...
solution can readily be formed using the following approach:Dynamic Programming with introduction to Weighted Activity Selection
/ref> Consider an optimal solution containing activity . We now have non-overlapping activities on the left and right of . We can recursively find solutions for these two sets because of optimal sub-structure. As we don't know , we can try each of the activities. This approach leads to an O(n^3) solution. This can be optimized further considering that for each set of activities in (i, j), we can find the optimal solution if we had known the solution for (i, t), where is the last non-overlapping interval with in (i, j). This yields an O(n^2) solution. This can be further optimized considering the fact that we do not need to consider all ranges (i, j) but instead just (1, j). The following algorithm thus yields an O(n \log n) solution: Weighted-Activity-Selection(S): // S = list of activities sort S by finish time opt = 0 // opt represents optimal solution (sum of weights of selected activities) for S ,2..,j for i = 1 to n: t = binary search to find activity with finish time <= start time for i // if there are more than one such activities, choose the one with last finish time opt = MAX(opt -1 opt + w(i)) return opt


References

{{Reflist


External links


Activity Selection Problem
Optimal scheduling Articles containing proofs