示例#1
0
        /// <summary>
        /// Performs a depth-first propagation backwards along a path for which all successors' computations
        /// are complete, adjusting late start &amp; finish according to a PERT methodology.
        /// </summary>
        /// <param name="tdNode">The TimingData node.</param>
        private void PropagateBackward(TimingData tdNode)
        {
            tdNode.LateStart = tdNode.LateFinish - tdNode.NominalDuration;

            foreach (TimingData predecessor in m_predecessors(tdNode.Subject).Select(n => TimingDataNodeFor(n)))
            {
                if (!predecessor.IsFixed)
                {
                    predecessor.LateFinish = DateTimeOperations.Min(predecessor.LateFinish, tdNode.LateStart);
                }
                predecessor.RegisterSuccessor();
                if (predecessor.AllSuccessorsHaveWeighedIn)
                {
                    PropagateBackward(predecessor);
                }
            }
        }
示例#2
0
            private static void Propagate()
            {
                while (_changedMilestones.Count > 0)
                {
                    Milestone ms = (Milestone)_changedMilestones.Dequeue();
                    if (_debug)
                    {
                        _Debug.WriteLine("\tPerforming propagation of change to " + ms.Name);
                    }

                    #region Create a Hashtable of Lists - key is target Milestone, list contains relationships to that ms.
                    Hashtable htol = new Hashtable();
                    foreach (MilestoneRelationship mr in ms.Relationships)
                    {
                        if (!mr.Enabled)
                        {
                            continue;                                                     // Only enabled relationships can effect change.
                        }
                        if (mr.Dependent.Equals(ms))
                        {
                            continue;                                                     // Only relationships where we are the independent can effect change.
                        }
                        //if ( m_debug ) _Debug.WriteLine("\tConsidering " + mr.ToString());
                        if (!htol.Contains(mr.Dependent))
                        {
                            htol.Add(mr.Dependent, new ArrayList());
                        }
                        ((ArrayList)htol[mr.Dependent]).Add(mr);                          // We now have outbounds, grouped by destination milestone.
                    }
                    #endregion

                    //if ( m_debug ) _Debug.WriteLine("\tPerforming change assessments for relationships that depend on " + ms.Name);

                    // For each 'other' milestone with which this milestone has a relationship, we will
                    // handle all of the relationships that this ms has with that one, as a group.
                    bool fullData = false;
                    foreach (Milestone target in htol.Keys)
                    {
                        if (_debug)
                        {
                            _Debug.WriteLine("\t\tReconciling all relationships between " + ms.Name + " and " + target.Name);
                            // E : RCV Liquid1.Xfer-In.Start and E : RCV Liquid1.Xfer-In.End
                        }
                        IList relationships = (ArrayList)htol[target];                        // Gives us a list of parallel relationships to the same downstream.

//						if ( ms.Name.Equals("B : RCV Liquid1.Xfer-In.Start") && target.Name.Equals("B : RCV Liquid1.Temp-Set.End") ) {
//							fullData = true;
//						}

                        if (fullData)
                        {
                            foreach (MilestoneRelationship mr2 in relationships)
                            {
                                _Debug.WriteLine(mr2.ToString());
                            }
                        }



                        DateTime minDateTime = DateTime.MinValue;
                        DateTime maxDateTime = DateTime.MaxValue;
                        foreach (MilestoneRelationship mr2 in relationships)
                        {
                            /*foreach ( MilestoneRelationship recip in mr2.Reciprocals) {
                             *      recip.PushEnabled(false);
                             *      m_pushedDisablings.Push(recip);
                             * }*/
                            if (fullData)
                            {
                                if (_debug)
                                {
                                    _Debug.WriteLine("\t\tAdjusting window to satisfy " + mr2);
                                }
                            }
                            DateTime thisMinDt, thisMaxDt;
                            mr2.Reaction(ms.DateTime, out thisMinDt, out thisMaxDt);                                 // Get the relationship's acceptable window.
                            minDateTime = DateTimeOperations.Max(minDateTime, thisMinDt);                            // Narrow the range from below.
                            maxDateTime = DateTimeOperations.Min(maxDateTime, thisMaxDt);                            // Narrow the range from above.
                            if (fullData)
                            {
                                if (_debug)
                                {
                                    _Debug.WriteLine("\t\t\tThe window is now from " + minDateTime + " to " + maxDateTime + ".");
                                }
                            }
                        }

                        //if ( m_debug ) _Debug.WriteLine("\t\tThe final window is from " + minDateTime + " to " + maxDateTime + ".");
                        if (minDateTime <= maxDateTime)
                        {
                            DateTime newDateTime = GetClosestDateTime(minDateTime, maxDateTime, target.DateTime);
                            if (!target.DateTime.Equals(newDateTime))
                            {
                                if (_debug)
                                {
                                    _Debug.WriteLine("\t\t\tWe will move " + target.Name + " from " + target.DateTime + " to " + newDateTime);
                                }
                                if (!_changedMilestones.Contains(target))
                                {
                                    _changedMilestones.Enqueue(target);
                                }
                                if (!_oldValues.Contains(target))
                                {
                                    _oldValues.Add(target, target.m_dateTime);
                                }
                                if (fullData)
                                {
                                    if (_debug)
                                    {
                                        _Debug.WriteLine("\t\t\tThere are now " + _changedMilestones.Count + " milestones with changes to process.");
                                    }
                                }
                                target.m_dateTime = newDateTime;
                            }
                            else
                            {
                                if (_debug)
                                {
                                    _Debug.WriteLine("\t\t\t" + target.Name + " stays put.");
                                }
                            }
//						} else {
//							if ( m_debug ) _Debug.WriteLine("\t\t\tThis is an unachievable window.");
//							throw new ApplicationException("Can't find a new datetime value for " + target.ToString());
                        }

                        fullData = false;
                    }
                }
            }
示例#3
0
        private void RunTest(TimePeriod tpA, TimePeriod tpB, TimePeriod.Relationship relationship,
                             TimePeriodPart moveWhichPart, string ofWhich, TimeSpan byHowMuch)
        {
            bool CONSOLE_OUTPUT = false;

            tpA.AddRelationship(relationship, tpB);

            DateTime earliest = DateTimeOperations.Min(tpA.StartTime, tpB.StartTime);
            DateTime left     = earliest - new TimeSpan(0, 0, (earliest.Minute % 10), 0, 0);

            int    spaces, width;
            string A, B;

            if (CONSOLE_OUTPUT)
            {
                Debug.WriteLine("           ....*....|....*....|....*....|....*....|....*....|");
                A      = "Initial A : ";
                spaces = (int)((TimeSpan)(tpA.StartTime - left)).TotalMinutes;
                width  = (int)tpA.Duration.TotalMinutes;
                for (int i = 0; i < spaces; i++)
                {
                    A += " ";
                }
                for (int i = 0; i < width; i++)
                {
                    A += "a";
                }
                for (int i = (spaces + width); i < 50; i++)
                {
                    A += " ";
                }
                Debug.WriteLine(A + tpA.ToString());


                B      = "Initial B : ";
                spaces = (int)((TimeSpan)(tpB.StartTime - left)).TotalMinutes;
                width  = (int)tpB.Duration.TotalMinutes;
                for (int i = 0; i < spaces; i++)
                {
                    B += " ";
                }
                for (int i = 0; i < width; i++)
                {
                    B += "b";
                }
                for (int i = (spaces + width); i < 50; i++)
                {
                    B += " ";
                }
                Debug.WriteLine(B + tpB.ToString());

                Debug.WriteLine("We'll move " + ofWhich + "." + moveWhichPart.ToString() + " by " + byHowMuch.ToString() + "...");
            }

            int selector = 0;

            if (ofWhich.Equals("A"))
            {
                selector += 0;
            }
            if (ofWhich.Equals("B"))
            {
                selector += 1;
            }
            selector <<= 1;
            if (moveWhichPart.Equals(TimePeriodPart.StartTime))
            {
                selector += 0;
            }
            if (moveWhichPart.Equals(TimePeriodPart.EndTime))
            {
                selector += 1;
            }


            tpA.AdjustmentMode = TimeAdjustmentMode.FixedDuration;
            tpB.AdjustmentMode = TimeAdjustmentMode.FixedDuration;
            if (CONSOLE_OUTPUT)
            {
                Console.WriteLine("3.");
                foreach (IMilestone ms in new IMilestone[] { tpB.StartMilestone, tpB.EndMilestone })
                {
                    Console.WriteLine(ms.Name);
                    foreach (MilestoneRelationship mr in ms.Relationships)
                    {
                        Console.WriteLine(mr.ToString());
                    }
                }
                Console.WriteLine("4.");
                foreach (IMilestone ms in new IMilestone[] { tpB.StartMilestone, tpB.EndMilestone })
                {
                    Console.WriteLine(ms.Name);
                    foreach (MilestoneRelationship mr in ms.Relationships)
                    {
                        Console.WriteLine(mr.ToString());
                    }
                }
            }

            switch (selector)
            {
            case 0: tpA.AdjustmentMode = TimeAdjustmentMode.InferEndTime;   tpA.StartTime += byHowMuch; break;

            case 1: tpA.AdjustmentMode = TimeAdjustmentMode.InferStartTime; tpA.EndTime += byHowMuch; break;

            case 2: tpB.AdjustmentMode = TimeAdjustmentMode.InferEndTime;   tpB.StartTime += byHowMuch; break;

            case 3: tpB.AdjustmentMode = TimeAdjustmentMode.InferStartTime; tpB.EndTime += byHowMuch; break;
            }

            if (CONSOLE_OUTPUT)
            {
                A      = "Final A   : ";
                spaces = (int)((TimeSpan)(tpA.StartTime - left)).TotalMinutes;
                width  = (int)tpA.Duration.TotalMinutes;
                for (int i = 0; i < spaces; i++)
                {
                    A += " ";
                }
                for (int i = 0; i < width; i++)
                {
                    A += "A";
                }
                for (int i = (spaces + width); i < 50; i++)
                {
                    A += " ";
                }
                Debug.WriteLine(A + tpA.ToString());

                B      = "Final B   : ";
                spaces = (int)((TimeSpan)(tpB.StartTime - left)).TotalMinutes;
                width  = (int)tpB.Duration.TotalMinutes;
                for (int i = 0; i < spaces; i++)
                {
                    B += " ";
                }
                for (int i = 0; i < width; i++)
                {
                    B += "B";
                }
                for (int i = (spaces + width); i < 50; i++)
                {
                    B += " ";
                }
                Debug.WriteLine(B + tpB.ToString());
            }

            foreach (TimePeriod tp in new TimePeriod[] { tpA, tpB })
            {
                foreach (IMilestone ms in new IMilestone[] { tp.StartMilestone, tp.EndMilestone })
                {
                    foreach (MilestoneRelationship mr in ms.Relationships)
                    {
                        bool b = mr.IsSatisfied();
                        Console.WriteLine(mr + (b?" is ":" is not ") + "satisfied.");
                        //Assert.IsTrue(b, mr + " is not satisfied!");
                    }
                }
            }
        }