コード例 #1
0
ファイル: SingleTimeLine.cs プロジェクト: jcol27/HCDESLib
        /// <summary>
        /// Earliest slot 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 Slot GetEarliestSlotTime(SlotRequest request, SingleTimeLineConstraints constraints)
        {
            if (Full)
            {
                return(null);
            }

            return(GetFirstSlotAtMinAtom(FirstAvailableAtom, request, constraints));
        } // end if
コード例 #2
0
ファイル: SingleTimeLine.cs プロジェクト: jcol27/HCDESLib
        } // 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
コード例 #3
0
ファイル: SingleTimeLine.cs プロジェクト: jcol27/HCDESLib
        } // 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