C
C#13mo ago
maroonlol

✅ Solve please delete this post

I have made my console application to calculate the project duration, the earliest start time and the latest start time Project Duration✅ Earliest Start Time✅ Latest Start Time❌ - Partially works Link to code - https://github.com/AbdulRaheemNazir/CPM/blob/main/Program.cs ================================================================================================================================================= V9 is equal to 18 as total project duration then to calculate the activity leading form and too latest finish time for V1..V4 we would have to go backwards through this path: V9->V8->V6->V4->V1 = 4+4+2+5 =15 If we do the calculation 18-15 it should give 3 as the latest finish time for V1..V4 but my output gives me 1 ------------------------------------------------------------------------------------ V1..V3 we would have to go backwards through either these paths: V9->V8->V5->V3->V1 = 4+7+1+4 =16 V9->V7->V5->V3->V1 = 2+9+1+4 =16 Since we have 2 paths we see which one is the longest duration but since we have the same we can just use 16. If we do the calculation 18-16 it should give 2 as the latest finish time for V1..V3 but my output gives me 1 ------------------------------------------------------------------------------------ V1..V2 we would have to go backwards through either these paths: V9->V8->V5->V2->V1 = 4+7+1+6 =18 V9->V7->V5->V2->V1 = 2+9+1+6 = 18 Since we have 2 paths we see which one is the longest duration but since we have the same we can just use 18. If we do the calculation 18-18 it should give 0 as the latest finish time for V1..V2 but my output gives me 1 ================================================================================================================================================= Only V1..V2, V1..V3 AND V1..V4 have this issue the latest Start time is calculates=d correctly for the rest
GitHub
CPM/Program.cs at main · AbdulRaheemNazir/CPM
Contribute to AbdulRaheemNazir/CPM development by creating an account on GitHub.
11 Replies
maroonlol
maroonlolOP13mo ago
Anyone here to take a look? If your avalaible ofcourse
JakenVeina
JakenVeina13mo ago
what? what is the actual question here?
maroonlol
maroonlolOP12mo ago
For latest start time for the first nodes it is setting it automatically to 1 but all the other nodes calculate start time fine So my earliest start time is correct the latest start time is correct but only for V2..V5 and onwards anything before that is swt to 1 but it shouldn't be, it should be like this in the table I created =============_ I think it is because if this line of code: earliestStartTime[startnode] = 1 That was the issue because for example if I changed it to 300 that first nodes with no dependences will also be 300 for ealiest start time and same for the latest start times I want to know how I can make it so that the latest start time is calculated for the first nodes correctly @V.EINA Jaken
JakenVeina
JakenVeina12mo ago
what are nodes? what are start times?
maroonlol
maroonlolOP12mo ago
The nodes are like V1, V2,V3 and so on I'm not sure what you mean by this earliest start time or latest start time and is your question asking what the expected output should be or asking me to explain the concept
JakenVeina
JakenVeina12mo ago
my question is "What in the world is the context here?" you have some nodes, apparently, and something to do with starting and stopping something on a per-bode basis and perhaps these nodes connect? how? you want to know how to calculate the earliest start time for the "first" nodes?
var earliestStartTimeForFirstNodes = firstNodes.Min(x => x.StartTime);
var earliestStartTimeForFirstNodes = firstNodes.Min(x => x.StartTime);
without more context, that's as good as it gets
maroonlol
maroonlolOP12mo ago
Context - Code seems to be implementing the Critical Path Method (CPM), which is normally used for project management. Nodes and Activities: - Nodes represent different tasks or activities in a project. - Activities connect nodes, indicating the flow or dependency between them. Start and End: - The project starts with certain nodes and ends with others. - I determine the earliest start time for activities, considering dependencies. Calculating Earliest Start Times: - The CalculateEarliestStartTimes method determines the earliest start times for each node/activity. - It starts with nodes that have no incoming edges and propagates forward, updating start times based on activity durations. Displaying Results: - The main method then displays the calculated earliest start times for each activity. Latest Start Times: - Later, the program calculates the latest start times using the CalculateLatestStartTimes method, considering the project's end time and backward propagation. Output: - The program prints a table with details for each activity, including the activity's leading nodes, duration, earliest start time, and latest start time. Hopefully this should be some help I tried my best understanding the questions you said, if you have any questions let me know @V.EINA Jaken
JakenVeina
JakenVeina12mo ago
so, the "latest start time" for each activity is the maximum start time, from among all the different paths that can lead to that activity, I.E. the maximum duration of those paths yes?
static Dictionary<string, int> CalculateLatestStartTimes(List<Activity> activities, Dictionary<string, int> earliestStartTimes)
{
Dictionary<string, int> latestStartTimes = new Dictionary<string, int>();

foreach (var activity in activities)
{
var latestStartTime = earliestStartTimes[activity.To] - activity.Duration;
if (!latestStartTimes.ContainsKey(activity.From) || latestStartTimes[activity.From] > latestStartTime)
{
latestStartTimes[activity.From] = latestStartTime;
}
}

return latestStartTimes;
}
static Dictionary<string, int> CalculateLatestStartTimes(List<Activity> activities, Dictionary<string, int> earliestStartTimes)
{
Dictionary<string, int> latestStartTimes = new Dictionary<string, int>();

foreach (var activity in activities)
{
var latestStartTime = earliestStartTimes[activity.To] - activity.Duration;
if (!latestStartTimes.ContainsKey(activity.From) || latestStartTimes[activity.From] > latestStartTime)
{
latestStartTimes[activity.From] = latestStartTime;
}
}

return latestStartTimes;
}
This method doesn't iterate all the possible prior paths for each activity, in order to find the one with the maximum duration it retrieves the minimum start time for the node it's going to and subtracts is own duration I.E. it effectively just re-calculates the "earliest start time" for this activity seems like nonsense to me you say the "latest start time" for V1->V3 should be 3 the possible paths for this are....well, there's only one V1 leads directly to V3 with a duration of 4 V1 => V3 only has one start time because it's a root node the start time is "1" that is both the earliest and the latest I haven't the slightest clue how you can go from a duration of "4" for that activity, and somehow end up with it starting at "3"
maroonlol
maroonlolOP12mo ago
For the Latest Start Time I'm attempting in going backwards with setting last node as the project duration. This is how I calculated latest start time for the following example V9 is equal to 18 as total project duration then to calculate the activity leading form and too latest finish time for V1..V4 we would have to go backwards through this path: V9->V8->V6->V4->V1 = 4+4+2+5 =15 If we do the calculation 18-15 it should give 3 as the latest finish time for V1..V4 but my output gives me 1 I'm trying to make the root nodes 1 only for the earliest start time but not for the latest start times If that makes more sense
JakenVeina
JakenVeina12mo ago
okay, so "latest start time" being "the latest that this can be started and still complete on time" with "on time" being defined by the shortest total path within the project so your algorithm is working exactly as you told it to it's retrieving the earliest start time of the next node subtracting the duration of the current activity and using that as the latest start time, for that activity
foreach (var activity in activities)
{
var latestStartTime = earliestStartTimes[activity.To] - activity.Duration;
if (!latestStartTimes.ContainsKey(activity.From) || latestStartTimes[activity.From] > latestStartTime)
{
latestStartTimes[activity.From] = latestStartTime;
}
}
foreach (var activity in activities)
{
var latestStartTime = earliestStartTimes[activity.To] - activity.Duration;
if (!latestStartTimes.ContainsKey(activity.From) || latestStartTimes[activity.From] > latestStartTime)
{
latestStartTimes[activity.From] = latestStartTime;
}
}
for the V1 => V3 activity, the earliest start time for V3, according to your table, is 5 the duration of V1 => V3 is 4 so, you get a latest start time of 1 if that's not what you want, well what is it that you DO what? you described how to get your intended "latest start time" for V1 => V4 why is your algorithm not doing that? why is it doing something completely different? you say you have to take the duration of the backwards path and subtract it from the "total project duration" why doesn't the algorithm calculate either of those values?
maroonlol
maroonlolOP12mo ago
I see the issue now and I have solved it @V.EINA Jaken Thank you for all your help your detailed questions made me examine my code and then I saw I had parts missing and I also had an issue of retrieving data which I discorved thanks to you
Want results from more Discord servers?
Add your server