File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
pygorithm/greedy_algorithm Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change 3
3
Created On: 26th August 2017
4
4
"""
5
5
import inspect
6
- # TODO: Explain what this is / how it works
7
6
8
7
9
8
def activity_selection (start_times , finish_times ):
10
9
"""
10
+ The activity selection problem is a combinatorial optimization problem concerning the selection of
11
+ non-conflicting activities to perform within a given time frame, given a set of activities each marked
12
+ by a start time (si) and finish time (fi). The problem is to select the maximum number of activities
13
+ that can be performed by a single person or machine, assuming that a person can only work on a single
14
+ activity at a time.
15
+
11
16
:param start_times: An array that contains start time of all activities
12
17
:param finish_times: An array that conatins finish time of all activities
13
18
"""
Original file line number Diff line number Diff line change 3
3
Created On: 22nd August 2017
4
4
"""
5
5
import inspect
6
- # TODO: Explain how this works / Explain what a knapsack is
7
6
8
7
9
8
def knapsack (w , item_values , item_weights ):
10
9
"""
10
+ The knapsack problem or rucksack problem is a problem in combinatorial optimization: Given a set of
11
+ items, each with a weight and a value, determine the number of each item to include in a collection so
12
+ that the total weight is less than or equal to a given limit and the total value is as large as
13
+ possible. It derives its name from the problem faced by someone who is constrained by a fixed-size
14
+ knapsack and must fill it with the most valuable items.
15
+
11
16
:param w: maximum weight capacity
12
17
:param item_values: a list of values of items in the knapsack
13
18
:param item_weights: a list of weights of items in the knapsack
You can’t perform that action at this time.
0 commit comments