Пример #1
0
        //--------------------------------------------------------------------------------------------------
        // Constructor
        //--------------------------------------------------------------------------------------------------

        #region Constructor

        /// <summary>
        /// Basic constructor
        /// </summary>
        /// <param name="parentTimeLine">Time line that the slot is hosted by</param>
        /// <param name="startTimeAtom">Start atom of the slot</param>
        /// <param name="coveredAtoms">All time atoms covered by the slot</param>
        /// <param name="endTime">End time of the slot</param>
        /// <param name="capacity">Capacity consumed by the slot</param>
        /// <param name="type">Type of slot</param>
        public Slot(SinglePerDayTimeLine parentTimeLine,
                    TimeAtom startTimeAtom,
                    TimeAtom[] coveredAtoms,
                    DateTime endTime,
                    double capacity,
                    string type)
        {
            _parentTimeLine = parentTimeLine;
            _startTimeAtom  = startTimeAtom;
            _startTime      = startTimeAtom.StartTime;
            _coveredAtoms   = coveredAtoms;
            _endTime        = endTime;
            _capacity       = capacity;
            _type           = type;
            _immediate      = false;
        } // end of Slot
Пример #2
0
        }         // end of InitializeChain

        #endregion

        #region InitializeNextAtom

        /// <summary>
        /// Method to intialize the pervious atom for the creation of the atom chain
        /// </summary>
        /// <param name="nextAtom"></param>
        public void InitializeNextAtom(TimeAtom nextAtom)
        {
            _nextAtom = nextAtom;

            if (nextAtom != null)
            {
                if (nextAtom.Blocked)
                {
                    _nextBlockedAtom   = nextAtom;
                    _nextAvailableAtom = nextAtom._nextAvailableAtom;
                }
                else
                {
                    _nextAvailableAtom = nextAtom;
                    _nextBlockedAtom   = nextAtom._nextBlockedAtom;
                } // end if
            }     // end if
        }         // end of InitializeChain
Пример #3
0
        } // end of TimeAtom

        #endregion

        #region InitializePreviousAtom

        /// <summary>
        /// Method to intialize the pervious atom for the creation of the atom chain
        /// </summary>
        /// <param name="previousAtom"></param>
        public void InitializePreviousAtom(TimeAtom previousAtom)
        {
            _previousAtom = previousAtom;

            if (previousAtom != null)
            {
                if (previousAtom.Blocked)
                {
                    _previousBlockedAtom   = previousAtom;
                    _previousAvailableAtom = previousAtom._previousAvailableAtom;
                }
                else
                {
                    _previousAvailableAtom = previousAtom;
                    _previousBlockedAtom   = previousAtom._previousBlockedAtom;
                } // end if
            }     // end if
        }         // end of InitializeChain
Пример #4
0
        } // end if

        #endregion

        #region GetAllSlotTimes

        /// <summary>
        /// Gets all slots on the time line for a request
        /// </summary>
        /// <param name="request">The request for the slot</param>
        /// <param name="constraints">Constraints associated with the request</param>
        /// <returns></returns>
        public List <Slot> GetAllSlotTime(SlotRequest request, SingleTimeLineConstraints constraints)
        {
            List <Slot> allSlots = new List <Slot>();

            if (Full)
            {
                return(allSlots);
            }

            TimeAtom currentAtom = FirstAvailableAtom;

            // loops through all possible start atoms
            while (currentAtom != null)
            {
                allSlots.Add(GetFirstSlotAtMinAtom(currentAtom, request, constraints));
                currentAtom = currentAtom.NextAvailableAtom;
            } // end while

            return(allSlots);
        } // end of GetAllSlotTime
Пример #5
0
        } // end of TimeLineConstraints

        #endregion

        #region ConstraintsWithinTimeLine

        /// <summary>
        /// Method that defines constraints within a single time line, e.g. booking of different types to be
        /// balanced
        /// </summary>
        /// <param name="request">Request to be booked</param>
        /// <param name="timeLine">Time line for the booking</param>
        /// <param name="atom">Atom to be used as a start atom for a slot</param>
        /// <returns></returns>
        virtual public bool ConstraintsWithinTimeLine(SlotRequest request, SinglePerDayTimeLine timeLine, TimeAtom atom)
        {
            return(true);
        } // end of ConstraintsWithinTimeLine
Пример #6
0
        } // end of GetAllSlotTime

        #endregion

        #region GetFirstSlotAtMinAtom

        /// <summary>
        /// Gets the first slot after a minimum atom that can be booked
        /// </summary>
        /// <param name="firstAtom">First atom to consider</param>
        /// <param name="request">Request for slot</param>
        /// <param name="constraints">Constraints associated with the slot</param>
        /// <returns>The first slot with a starting atom later than the first atom that can be booked</returns>
        private Slot GetFirstSlotAtMinAtom(TimeAtom firstAtom, SlotRequest request, SingleTimeLineConstraints constraints)
        {
            TimeAtom currentAtom = firstAtom;
            DateTime availableTo;

            // setting start atom for search
            while (currentAtom != null && (currentAtom.Blocked || currentAtom.NonBookable))
            {
                currentAtom = currentAtom.NextAvailableAtom;
            } // while

            // looping through possible start atoms
            while (currentAtom != null)
            {
                TimeAtom loopingAtom;

                // calc the availability period for the current atom
                if (currentAtom.NextBlockedAtom == null)
                {
                    availableTo = EndTime;
                }
                else
                {
                    availableTo = currentAtom.NextBlockedAtom.StartTime;
                } // end if

                // checking if the availability length is sufficient
                if (availableTo - currentAtom.StartTime >= request.Length)
                {
                    // checking constraints for booking
                    // this is currently only done for the start atom of a possible slot
                    // could be easily extended to the whole stretch
                    if (constraints(request, this, currentAtom))
                    {
                        DateTime endTime = currentAtom.StartTime + request.Length;

                        loopingAtom = currentAtom;

                        bool noViolationDetected = true;

                        List <TimeAtom> coveredAtoms = new List <TimeAtom>();

                        // checking the capacitity of all covered atoms
                        while (loopingAtom != null && loopingAtom.StartTime < endTime && noViolationDetected)
                        {
                            coveredAtoms.Add(loopingAtom);

                            if (loopingAtom.Capacity > loopingAtom.MaxCapacity - request.Capacity)
                            {
                                noViolationDetected = false;
                            }

                            loopingAtom = loopingAtom.NextAtom;
                        } // end while

                        // in case a booking would be possible the atom is returned
                        if (noViolationDetected)
                        {
                            return(new Slot(
                                       this,
                                       currentAtom,
                                       coveredAtoms.ToArray(),
                                       endTime,
                                       request.Capacity,
                                       request.Type.AdmissionType.Identifier));
                        }
                    } // end if
                }     // end if

                currentAtom = currentAtom.NextAvailableAtom;
            } // end while

            return(null);
        } // end of GetFirstSlotAfterTime