Question #61018

TCS is working on a new project called "TestVita". There are N modules in the project. Each module (i) has completion time denoted in number of hours (Hi) and may depend on other modules. If Module x depends on Module y then one needs to complete y before x.

As Project manager, you are asked to deliver the project as early as possible.
Provide an estimation of amount of time required to complete the project.

Expert's answer

Answer on Question #61018, Programming & Computer Science / C++

TCS is working on a new project called "TestVita". There are N modules in the project. Each module (i) has completion time denoted in number of hours (Hi) and may depend on other modules. If Module x depends on Module y then one needs to complete y before x.

As Project manager, you are asked to deliver the project as early as possible. Provide an estimation of amount of time required to complete the project.

Solution:

Let x1,x2,,xNx_1, x_2, \ldots, x_N – all modules, H1,H2,,HNH_1, H_2, \ldots, H_N – corresponding completion times, F(xi,xj)=1F(x_i, x_j) = 1 if xix_i depends on module xjx_j, F(xi,xj)=0F(x_i, x_j) = 0 if xjx_j doesn’t depend (directly) on module xix_i.

Let xkx_k – the main module of the project. Our task is to find all modules on which this xkx_k depends (directly or indirectly through sequence of some other modules) and then find the sum of corresponding HiH_i.

Let's mark all modules by pip_i, where pi=1p_i = 1 if that module is necessary for project, pi=0p_i = 0 if not.

Solution algorithm:

1. Let pk=1p_k = 1, all other pi=0p_i = 0.

2. Loop through all pairs xi,xjx_i, x_j. If module xix_i depends on module xjx_j (F(xi,xj)=1F(x_i, x_j) = 1) AND module xix_i marked as 1 (pi=1p_i = 1) then change pjp_j mark to 1.

3. If in step 2 at least one mark pip_i is changed, then go to step 2 and repeat it. If no pip_i is changed then proceed to step 4.

4. Now all modules necessary for project is marked by 1 (pi=1p_i = 1 for them). Loop through all xix_i and sum such HiH_i for which pj=1p_j = 1.

In C++ this algorithm can be coded for example in such way:


P[k] = 1;
Changed = 1;
while (Changed)
{
    Changed = 0;
    for (i=0; i<N; i++)
        for (j=0;j<N;j++)
            if ((F[i][j] == 1) && (P[i] == 1))
            {
                Changed=1;
                P[j] = 1;
            }
}
for (i=0, sum=0; i<N; i++)
    if (P[i] == 1) sum += H[i];
cout << "Time to complete: " << sum;


http://www.AssignmentExpert.com

LATEST TUTORIALS
APPROVED BY CLIENTS