You are talking about CPM - Critical Path Method.
Eval each Condition Type (Finish to Start , ....) is a simple Select - Case .
You need eval early Dates then later dates. This determines the Critical Path.
If your algoritm includes ASAP - ALAP for some tasks, you can eval Scheduled Dates aditional pass.
I use Recursive algorhitm for each Pass (Early Dates, Latest Dates ...). This discover Condition Loop and Show them (Task1 -> Task2 -> Task1).
The most compless task for CPM is the calendar management.
Nothe that the function
Date1 = Calendar.Eval_DateFinish(Start, Duration)
Becomes a Function based on Resources calendar Intervals.
Here my Function for Ealy Dates.
Private Sub cpm_fmte(ByVal n As Int32)
Dim a = Actividades(n), fi, f As FechaCpm, ncit As Integer = 0
fi.value = Integer.MinValue
Dim cal As Calend = a.Cal, dur As Integer = a.dur
sw(n) = 255 : RaBucle.Add(a) 'Marco la actividad para detectar bucle condicionantes
For Each c In a.Predecesoras '/* calcular predecesoras */
If c._Act >= nHitos Then
If c._Act < nTResumen Then Continue For
Select Case sw(c._Act)
Case 0 : cpm_fmte(c._Act)
Case 255 : ShowBucle(c._Act) : Throw New Exception("Cpm_ftme: Error - Bucle Condicionantes")
'case Else - 1 - Ya calculada anteriormente
End Select
End If
Dim Pred = Actividades(c._Act)
Select Case c.Tipo
Case "D"c : f.value = Pred.ffmte.value + c.Demora
Case "I"c : f.value = Pred.fimte.value + c.Demora : ncit += 1
Case "T"c : f = cal.Calc_Fi(Pred.ffmte + c.Demora, dur) : ncit += 1
Case Else : Throw New Exception(String.Format("Error condic.: {0} {1} {2} {3} {4}", _
a.Id, c.Tipo, Pred.Id, c.Demora))
End Select
If f > fi Then fi = f
Next
RaBucle.Count -= 1
If fi.value = Integer.MinValue Then fi = Proyecto.Actprj.FechaPrj
If dur > 0 Then fi = cal.Fecha_Jla_Av(fi)
a.fimte.value = fi.value : a.ffmte = cal.Calc_Ff(fi, dur)
a.Fip = a.fimte : a.Ffp = a.ffmte
If a.ffmte.value > Fmax.value Then mfmax.value = a.ffmte.value
If a.fimte.value < Fmin.value Then mFmin.value = a.fimte.value
sw(n) = 1 'Actividad calculada
End Sub
Notes. I'am Spanish then :
- Fmte -> Early Dates (Fechas más Tempranas), Fmta -> Latest Dates, Fp - Schedulded.
- Fi -> Start Date (Fecha Inicio), FF - > Finish Date (Fecha Fín)
- Actividades - Tasks
- "D"c -> (Finish - start), "Después",
- "I"c -> (Start - Start) "Inician..."
- "T"c -> (Finish - Finish) "Terminan ..."
- Never used Start - Finish condition.
I use FechaCpm type (structure) that evals as Int32 type (FechaCpm.Value) and interprets as minute time interval unit.
You can get more code for CPM on SourceForge, but I never find any code on Net.
You can see "Open WorkBench" - Java or "Planner" - C++.
My code is CPM based, most Planification programs are resources based supporting CPM.
I use only one resource (Human resource) then Calendar is a Task property.