0% found this document useful (0 votes)
1 views9 pages

Term Project Pit Mining

The document presents a term project on pit mining, focusing on maximizing net profit through the maximum sum subarray problem. It outlines various algorithmic approaches, including brute force, divide and conquer, and dynamic programming, to solve the problem of finding the optimal contiguous subsequence in a one-dimensional array of net profits. The conclusion emphasizes the importance of these algorithms in achieving the goal of profit maximization in mining operations.

Uploaded by

babyfisho19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views9 pages

Term Project Pit Mining

The document presents a term project on pit mining, focusing on maximizing net profit through the maximum sum subarray problem. It outlines various algorithmic approaches, including brute force, divide and conquer, and dynamic programming, to solve the problem of finding the optimal contiguous subsequence in a one-dimensional array of net profits. The conclusion emphasizes the importance of these algorithms in achieving the goal of profit maximization in mining operations.

Uploaded by

babyfisho19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

AASTU, Addis Ababa

Advanced algorithm and problem solving


Term Project
Pit Mining

Instructor: Dr.Beakal Gizachew


2020,2nd MSc
Name :Fisiha Alebachew Tilahun
ID No: GSE/064/11

1
Contents

Contents 2

0.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

0.2 Problem definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

0.3 Data structure used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

0.4 Algorithm design approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

5. Comparison Table Summary for time and space Asymptotic analysis . . . . . . . . . . . . . 8

6.Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

6.1. Important lectures from the class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

6.2 Hardest Part . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

0.1 Introduction
Open-pit mining is a surface mining technique of extracting rock or minerals from the earth. Open pit
production scheduling problems seek to determine when, if ever, a block is extracted from an open pit
mine. A typical objective is to maximize the net present value of the extracted ore. The mining region is
divided into blocks, and for simplicity we assume a one-dimensional layout. From a preliminary geological
survey, I estimate that removing block i will produce a net profit (value of ore minus processing cost) of
ai million dollars. Because of environmental restrictions, I want to mine for ore in only one contiguous

2
set of blocks. In other words, given a sequence of N integers (possibly negative), determine the maximum
possible sum of any consecutive sequence.

0.2 Problem definition


We are given an array A(Net Profit) having n(Blocks) integers. What we want to find is a contiguous subsequence
(A[i], A[i+1], . . . , A[j]) such that the sum of the elements in that subsequence is maximized. (Note that, in general,
there may be more than one such optimal subsequence.) Note that if all elements in A are non-negative, we could
directly return the entire array as the required optimal subsequence
The problem is easy if all the numbers are positive: choose the entire sequence. The difficulty is when
there are negative integers: should you take a negative integer in the hope that nearby positive integers
will compensate for it
Input

Blocks 1 up to n
Net Profit A[i] i=1 to n

So that Net profit maximization in a given blocks is the same with the maximum sum subarray problem is
the task of finding a contiguous subarray with the largest sum, within a given one-dimensional array A[1...n]
of numbers. Formally, the task is to find indices { \ displaystyle i} i and { \ displaystyle j} j with 1< =
i<= j <= n such that the

j
P
A[x]{ \ displaystyle \ sum _{ x=i} ˆ { j} A[x]}

x=i
is as large as possible. (Some formulations of the problem also allow the empty subarray to be considered;
by convention, the sum of all values of the empty subarray is zero.) Each number in the input array A
could be positive, negative, or zero

0.3 Data structure used


I prefer array for this pit mining Profit maximization because

• In pit mining there are collection of similar types of data. Since all the data is integers of blocks and
Profits

• if we want to store the blocks of all profits it will easy to store in array otherwise, we have to store
profits in different location, which is not easy.

• we have to only remember the first index of array and used to sequence of maximum profits from
starting to ending indices.

3
0.4 Algorithm design approach
Approach 1: brute force.

A simple brute-force method could be to compute the sums of all possible sub sequences in A. How many
subsequences are there? There are n+(n-1)+(n-2)+. . . +1 = O(n2) possible subsequences. Computing the sum of a subsequence take

In C++, we could write the following function to do what was explained above:
// start and end are the starting and ending indices of an optimal subsequence.
void f ( int∗ A, int n, int & start, int& end)
{
int sum, max = A[0];
for (int i = 0; i < n ; i++)
for (int j = i; j < n; j++)
{
sum = 0;
for (int k = i; k <=j; k++)
sum+= A[k];
if (sum >= max)
{
start = i;
end = j;
max = sum;
}
}
}
Approach 2
Better Algorithm than brute
We can improve the running time to O(n2) by being a bit more clever in computing the sums of different subsequences. We observe that the s

In C++, we could write as follows:


void f (int ∗ A, int n, int & start, int & end)
{
int sum, max = A[0];
for (int i = 0; i < n; i++)
{
sum = 0;
for (int j = i; j < n; j++)
{
sum + = A[j];
if (sum >= max)
{
start = i;
end = j;
max = sum;
}
}
}
}
Approach 3
Using Divide and Conquer approach

4
This approach can find the maximum subarray sum in O(nLogn) time. Following is the Divide and Conquer
algorithm.
1) Divide the given array in two halves
2) Return the maximum of following three
a) Maximum subarray sum in left half (Make a recursive call)
b) Maximum subarray sum in right half (Make a recursive call)
c) Maximum subarray sum such that the subarray crosses the midpoint

How to find maximum subarray sum such that the subarray crosses the midpoint? We can easily find the
crossing sum in linear time. The idea is simple, find the maximum sum starting from mid point and ending
at some point on left of mid, then find the maximum sum starting from mid + 1 and ending with sum
point on right of mid + 1. Finally, combine the two and return.
/ /The original values would be low = 0 and high = n-1
int maxSubarraySum (int A[], int low, int high)
{
if (low == high)
return A[low]
else
{
int mid = low + (high - low)/2
int left_sum = maxSubarraySum (A, low, mid)
int right_sum = maxSubarraySum (A, mid+1, high)
int crossing_Sum = maxCrossingSum(A, low, mid, high)
return max (left_sum, right_sum, crossing_Sum)
}
}

int maxCrossingSum(int A[], int l, int mid, int r)


{
int sum = 0
int lsum = INT_MIN
for(i = mid to l)
{
sum = sum + A[i]
If (sum > lsum)
lsum = sum
}
sum = 0
int rsum = INT_MIN
for(i = mid+1 to r)
{
sum = sum + A[i]
If (sum > rsum)
rsum = sum
}
return (lsum + rsum)
}

5
Left Mid(n/2) Right

Max of the left


max of the right
Time Complexity: maxSubArraySum() is a recursive method and time complexity can be expressed as
following recurrence relation.
T(n) = 2T(n/2) + Θ (n)
The above recurrence is similar to Merge Sort and can be solved either using Recurrence Tree method or
Master method. It falls in case II of Master Method and solution of the recurrence is Θ (nLogn).

Approach 4
Using dynamic programming, the problem is solved in linear time.
We consider a linear number of subproblems, each of which can be solved using previously solved subprob-
lems in constant time, this giving a running time of O(n).
Let S[K] denote the sum of a maximum sum contiguous subsequence ending exactly at index K.
Thus, we have that:
S[K+1]=max{ S[K]+A[K+1,A[K+1]]}
For all (1<=k<=n-1)
Also, S[0] = A[0].

Using the above recurrence relation, we can compute the sum of the optimal subsequence for array A,
which would just be the maximum over S[i] for .0<=i<=n-1
Since we are required to output the starting and ending indices of an optimal subsequence, we would use
another array T where T[i] would store the starting index for a maximum sum contiguous subsequence
ending at index i.
In pseudocode form, the algorithm would look this

Create arrays S and T each of size n.


S[0] = A[0];
T[0] = 0;
max = S[0];
max_start = 0, max_end = 0;
For i going from 1 to n-1:
// We know that S[i] = max { S[i-1] + A[i], A[i] .
If ( S[i-1] > 0)
S[i] = S[i-1] + A[i];
T[i] = T[i-1];
Else
S[i] = A[i];
T[i] = i;
If ( S[i] > max)
max_start = T[i];
max_end = i;
max = S[i];
EndFor.
Output max_start and max_end.

The above algorithm takes O(n) time and O(n) space.

6
Approach 5 Dynamic Programing reducing space requirement
We can however improve upon the space requirements, reducing it to O(1). The key idea to look for all
positive contiguous segments of the array (max_ending_here is used for this). And keep track of maximum
sum contiguous segment among all positive segments (max_so_far is used for this). Each time we get a
positive sum compare it with max_so_far and update max_so_far if it is greater than max_so_far We could
proceed as follows:

Algorithm
Initialize
max_so_far=0
max_Ending_here=0
Loop for each element of the array

1) max_ending_here=max_ending_here + A[i]

2. if(max_ending_here<0)
max_ending_here=0
3.if(max_so_far < max_ending_here)
max_so_far = max_ending_here

Return max_so_far

Lets take the example to implement the above algorithm


A = { -2, -3, 4, -1, -2, 1, 5}
max_so_far = max_ending_here =0
for i=0, A[0]= -2
max_ending_here = max_ending_here +(-2)
set max_ending_here =0 because max_ending_here < 0

for i=1,A[1] = -3
max_ending_here = max_ending_here +(-3)
set max_ending_here =0 because max_ending_here < 0

for i=2,A[2] = 4
max_ending_here = max_ending_here +(4)
max_ending_here = 4
max_so_far is updated to 4 because max_ending_here > max_so_far which was 0 till now
set max_ending_here =0 because max_ending_here < 0

for i=3,A[3] = -1
max_ending_here = max_ending_here +(-1)
max_ending_here = 3

for i=4,A[4] = -2
max_ending_here = max_ending_here +(-2)
max_ending_here = 1

for i=5,A[5] = 1
max_ending_here = max_ending_here +(1)

7
max_ending_here = 2

for i=6,A[6] = 5
max_ending_here = max_ending_here +(5)
max_ending_here = 7
max_so_far is updated to 7 because max_ending_here > max_so_far which was 4 till now

The above algorithm takes O(n) time and O(1) space.

5. Comparison Table Summary for time and space Asymptotic


analysis

No Algorithms Time Complexity Space Complexity


1 Brute force O(n3 ) O(1)
2 Brute force Better algo- O(n2 ) O(1)
rithm
3 Divide and conquer O(nlogn) O(logn) stack space by
recursive calls
4 Dynamic programing O(n) O(n) for storing the
Recurrence relation auxiliary array
5 Dynamic program- O(n) O(1)
ing reducing space
requirement

6.Conclusion

In pit mining the ultimate objective is to maximize Net profit in a given blocks which is the same with the
maximum sum subarray problem is the task of finding a contiguous subarray with the largest sum, within
a given one-dimensional array A[1...n] of numbers.

6.1. Important lectures from the class


1.Divide and Conquer

8
Divide and Conquer is an algorithmic paradigm. A typical Divide and Conquer algorithm solves a problem
using following three steps.
a. Divide: Break the given problem into subproblems of same type.
b. Conquer: Recursively solve these subproblems
c. Combine: Appropriately combine the answers

2. Big O notations
3.recurence relations

6.2 Hardest Part


all elements in A are non-negative, we could directly return the entire array as the required optimal subsequence
if all the numbers are positive: choose the entire sequence. If There
is negative integers. The difficulty is when there are negative integers: should you take a negative integer
in the hope that nearby positive integers will compensate for it and to find the optimal sequence. The
other hardest part is write using latex’s, code writing algorithm analysis and big O notations.

https://en.wikipedia.org/wiki/Maximum_subarray_problem
http://en.wikipedia.org/wiki/Kadane% 27s_Algorithm
DataMine Software (2011) Accessed February 2011, http://www.datamine.co.uk.
Dynamic% 20Programming% 20% 20Maximum% 20sum% 20contiguous% 20subsequence% 20_% 20Thoughts.h
COS 126 Assignment 8_Pit Mining.html
Maximum% 20Subarray% 20Problem% 20(Kadane’s% 20algorithm)% 20-% 20Techie% 20Delight.html
Merge% 20K% 20sorted% 20arrays% 20_% 20Set% 203% 20(% 20Using% 20Divide% 20and% 20Conquer%
20Approach% 20)% 20-% 20GeeksforGeeks.html

You might also like