示例#1
0
        /// <summary>
        /// Performs the forward path calculations to define for each
        /// activity its earliest start time and earliest end time.
        /// </summary>
        /// <param name="list">Array storing the activities already entered.</param>
        /// <returns>void</returns>
        ///
        private static void forwardCalculation(List <IActivity> list, DateTime startDate)
        {
            List <IActivity> currentSuccessors = new List <IActivity>();;

            foreach (IActivity act in list)
            {
                if (act.Successors != null)
                {
                    //currentSuccessors = new List<IActivity>();
                    for (int i = 0; i < act.Successors.Count; i++)
                    {
                        IActivity succ = (IActivity)act.Successors[i].Succ;
                        currentSuccessors.Add(succ);
                        switch (act.Successors[i].RelationshipType)
                        {
                        case relType.FS:
                            if (succ.Est < act.Eet + 1 + act.Successors[i].Lag)
                            {
                                succ.Est = act.Eet + 1 + act.Successors[i].Lag;
                            }
                            succ.Eet = succ.Est + succ.Duration - 1;
                            succ.ES  = HelperFunctions.AddWorkdays(startDate, succ.Est + 1);
                            succ.EF  = HelperFunctions.AddWorkdays(succ.ES, succ.Duration);
                            break;

                        case relType.FF:
                            if (succ.Eet < act.Eet + act.Successors[i].Lag)
                            {
                                succ.Eet = act.Eet + act.Successors[i].Lag;
                            }
                            succ.Est = succ.Eet - succ.Duration + 1;
                            succ.ES  = HelperFunctions.AddWorkdays(startDate, succ.Est + 1);
                            succ.EF  = HelperFunctions.AddWorkdays(succ.ES, succ.Duration);
                            break;

                        case relType.SS:
                            if (succ.Est < act.Est + act.Successors[i].Lag)
                            {
                                succ.Est = act.Est + act.Successors[i].Lag;
                            }
                            succ.Eet = succ.Est + succ.Duration - 1;
                            succ.ES  = HelperFunctions.AddWorkdays(startDate, succ.Est + 1);
                            succ.EF  = HelperFunctions.AddWorkdays(succ.ES, succ.Duration);
                            break;

                        case relType.SF:
                            if (succ.Eet < act.Est + act.Successors[i].Lag)
                            {
                                succ.Est = act.Eet + act.Successors[i].Lag;
                            }
                            succ.Eet = succ.Est + succ.Duration - 1;
                            succ.ES  = HelperFunctions.AddWorkdays(startDate, succ.Est + 1);
                            succ.EF  = HelperFunctions.AddWorkdays(succ.ES, succ.Duration);
                            break;
                        }
                    }
                    forwardCalculation(currentSuccessors, startDate);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Checks for activities with no successors and assigns late start and finish
        /// the function returns a list of all end nodes
        /// </summary>
        /// <param name="list">List of all activities already entered.</param>
        /// <returns>List</IActivity></returns>
        ///
        public static List <IActivity> getEndNodes(List <IActivity> list, DateTime startDate)
        {
            List <IActivity> endNodes = new List <IActivity>();
            int dur = longestDuration(list);

            foreach (IActivity activity in list)
            {
                activity.Let = dur;
                activity.Lst = activity.Let - activity.Duration + 1;
                if (activity.Successors == null)
                {
                    activity.Let = dur;
                    activity.Lst = activity.Let - activity.Duration + 1;
                    activity.Tf  = activity.Let - activity.Eet;
                    activity.LS  = HelperFunctions.AddWorkdays(startDate, activity.Lst + 1);
                    activity.LF  = HelperFunctions.AddWorkdays(activity.LS, activity.Duration);
                    endNodes.Add(activity);
                }
            }
            return(endNodes);
        }
示例#3
0
        /// <summary>
        /// Performs the backward path for calculating each
        /// activity its latest start time and latest end time.
        /// </summary>
        /// <param name="list">Array storing the activities already entered.</param>
        /// <returns>void</returns>
        private static void backwardCalculation(List <IActivity> list, DateTime startDate)
        {
            List <IActivity> currentPred = new List <IActivity>();

            foreach (IActivity act in list)
            {
                if (act.Predecessors != null)
                {
                    //currentSuccessors = new List<IActivity>();
                    for (int i = 0; i < act.Predecessors.Count; i++)
                    {
                        IActivity pred = (IActivity)act.Predecessors[i].Pred;
                        currentPred.Add(pred);
                        switch (act.Predecessors[i].RelationshipType)
                        {
                        case (relType.FS):
                            if (pred.Let == 0)
                            {
                                pred.Let = act.Lst - act.Predecessors[i].Lag - 1;
                            }
                            else if (pred.Let > act.Lst - act.Predecessors[i].Lag - 1)
                            {
                                pred.Let = act.Lst - act.Predecessors[i].Lag - 1;
                            }
                            pred.Lst = pred.Let - pred.Duration + 1;
                            pred.Tf  = pred.Let - pred.Eet;
                            pred.LS  = HelperFunctions.AddWorkdays(startDate, pred.Lst + 1);
                            pred.LF  = HelperFunctions.AddWorkdays(pred.LS, pred.Duration);
                            break;

                        case relType.FF:
                            if (pred.Let == 0)
                            {
                                pred.Let = act.Let - act.Predecessors[i].Lag;
                            }
                            else if (pred.Let > act.Let - act.Predecessors[i].Lag)
                            {
                                pred.Let = act.Let - act.Predecessors[i].Lag;
                            }
                            pred.Lst = pred.Let - pred.Duration + 1;
                            pred.Tf  = pred.Let - pred.Eet;
                            pred.LS  = HelperFunctions.AddWorkdays(startDate, pred.Lst + 1);
                            pred.LF  = HelperFunctions.AddWorkdays(pred.LS, pred.Duration);
                            break;

                        case relType.SS:
                            if (pred.Lst == 0)
                            {
                                pred.Lst = act.Lst - act.Predecessors[i].Lag;
                            }
                            else if (pred.Lst > act.Lst - act.Predecessors[i].Lag)
                            {
                                pred.Lst = act.Lst - act.Predecessors[i].Lag;
                            }
                            pred.Let = pred.Lst + pred.Duration - 1;
                            pred.Tf  = pred.Let - pred.Eet;
                            pred.LS  = HelperFunctions.AddWorkdays(startDate, pred.Lst + 1);
                            pred.LF  = HelperFunctions.AddWorkdays(pred.LS, pred.Duration);

                            break;

                        case relType.SF:

                            break;
                        }
                    }
                    backwardCalculation(currentPred, startDate);
                }
            }
        }
示例#4
0
        private static void Main(string[] args)
        {
            Project  project = new Project("HS2", "Central Enabling Works");
            Activity a       = new Activity();

            a.Id           = "a";
            a.Description  = "Activity A";
            a.Duration     = 5;
            a.Predecessors = null;
            project.addActivity(a);
            Activity b = new Activity();

            b.Id          = "b";
            b.Description = "Activity B";
            b.Duration    = 10;
            project.addActivity(b);
            Activity c = new Activity();

            c.Id          = "c";
            c.Description = "Activity C";
            c.Duration    = 8;
            project.addActivity(c);
            Activity d = new Activity();

            d.Id          = "d";
            d.Description = "Activity D";
            d.Duration    = 6;
            project.addActivity(d);
            Activity E = new Activity();

            E.Id          = "e";
            E.Description = "Activity E";
            E.Duration    = 8;
            project.addActivity(E);
            Relationship rel3 = new Relationship(a, d, relType.FS, 0);
            Relationship rel4 = new Relationship(d, E, relType.FF, 0);
            Relationship rel  = new Relationship(a, b, relType.FS, 0);
            Relationship rel2 = new Relationship(b, c, relType.SS, 0);

            List <IRelationship> rels = new List <IRelationship>();

            rels.Add(rel);
            rels.Add(rel2);
            rels.Add(rel3);
            rels.Add(rel4);
            project.Relations = rels;

            project.calculate();
            DateTime        startDate = new DateTime(2016, 11, 7);
            List <DateTime> daysOff   = new List <DateTime>();

            daysOff.Add(new DateTime(2016, 11, 10));
            Console.WriteLine(HelperFunctions.AddWorkdays(startDate, 10, daysOff));
            Resource                   steelFixer = new Resource("SF", "Steelfixer", resourceType.Labour, 0, 80);
            ResourceAssignment         assign     = new ResourceAssignments.ResourceAssignment(a, steelFixer, 100, 80);
            List <IResourceAssignment> x          = new List <IResourceAssignment>();

            x.Add(assign);
            a.Resources = x;
            Console.WriteLine(a.Resources[0].Resource.ResName);
            WBS        wbsProject  = new WBS("10", "Hassan Emam Project", null);
            WBS        wbsNode1    = new WBS("20", "Node 1", wbsProject);
            WBS        wbsNode2    = new WBS("30", "Node 2", wbsNode1);
            List <WBS> wbsElements = new List <WBS>();

            wbsElements.Add(wbsProject);
            wbsElements.Add(wbsNode1);
            wbsElements.Add(wbsNode2);
            foreach (WBS node in wbsElements)
            {
                if (node != null && node.Parent != null)
                {
                    Console.WriteLine(node.WbsName + "\t" + node.Parent.WbsName);
                }
                if (node != null && node.Parent == null)
                {
                    Console.WriteLine(node.WbsName + "\t Root");
                }
            }
        }