コード例 #1
0
ファイル: LaneScheduler.cs プロジェクト: nover/dtu-02165
 public static List<LaneSchedulerAction> Expand(LaneSchedulerState state, LaneSchedulerReservation reservation)
 {
     List<LaneSchedulerAction> actions = new List<LaneSchedulerAction>();
     if (state.IsPossible(reservation))
     {
         for (int lane = 0; lane < state.numberOfLanes; lane++)
         {
             AppWeightPair appWeightPair = state.IsApplicable(lane, reservation.NumberOfLanes, reservation.NumberOfTimeSlots, reservation.StartTimeSlot);
             if (appWeightPair.applicable)
             {
                 actions.Add(new LaneSchedulerAction(lane, reservation, appWeightPair.weight));
             }
         }
     }
     return actions;
 }
コード例 #2
0
ファイル: LaneScheduler.cs プロジェクト: nover/dtu-02165
        public static LaneSchedulerStateReservationsPair Search(LaneSchedulerState state, List<LaneSchedulerReservation> reservations, LaneSchedulerReservation newReservation)
        {
            LaneScheduler.closedStateList = new Dictionary<string, int>();
            Debug.WriteLine("Adding new Reservation");
            if (!state.IsPossible(newReservation))
            {
                Debug.WriteLine("    It failed the first check");
                // get other reservations
                return new LaneSchedulerStateReservationsPair(null, LaneScheduler.GetAlternativeReservations(state, newReservation));
            }
            // if it can be applied easily
            List<LaneSchedulerAction> actions = Expand(state, newReservation);
            actions = (from y in actions
                       select y).OrderBy(y => y.weight).ToList<LaneSchedulerAction>();
            if (actions.Count > 0)
            {
                state.Apply(actions[0]);
                Debug.WriteLine("    The reservation was straight forward");
                return new LaneSchedulerStateReservationsPair(state, new List<LaneSchedulerReservation>());
            }

            // else, search

            // cut the relevant piece out of the state, so we end up with three pieces.
            // Solve the middle piece, and add it to the top and bottom piece.
            //List<State> statePieces = state.cutInPieces(newReservation);

            List<LaneSchedulerReservation> newReservations = new List<LaneSchedulerReservation>(reservations);
            newReservations.Add(newReservation);

            long time1 = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
            LaneSchedulerState emptyState = new LaneSchedulerState(state.numberOfLanes, state.numberOfTimeSlots, newReservations);
            LaneSchedulerState newState = LaneScheduler.RecursiveSearch(emptyState, newReservations, 0, 100000, 0);

            long time2 = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
            long runTime = time2 - time1;
            Debug.WriteLine("    Search took: " + runTime + " ms");
            if (newState != null)
            {
                Debug.WriteLine("    Returning state");
                return new LaneSchedulerStateReservationsPair(newState, new List<LaneSchedulerReservation>());
            }
            else
            {
                // get other reservations
                Debug.WriteLine("    Returning other reservations");
                return new LaneSchedulerStateReservationsPair(null, LaneScheduler.GetAlternativeReservations(state, newReservation));
            }
        }