package simulator;

import java.util.Collection;

/*
 * ShortestTimeFirst.java
 * Created on Jan 28, 2005
 *
 */

/**
 *  ShortestTimeFirst - This implementation of the customer will
 *  always pick the ride that he can get on in the shortest
 *  amount of time.  (It re-orders the wish list based on the 
 *  time it takes to travel there and the expected wait time at
 *  the ride in question).
 *  
 *  @author Ping
 *
 */
public class ShortestTimeFirst extends Customer
{
    public static String CUSTOMER_TYPE = "Shortest Time First";

    /**
     * @param name
     * @param wishList
     * @param exitStrategy
     * @param timeEntered
     * @param desiredExitTime
     * @param logger
     */
    public ShortestTimeFirst(String name,
            Collection<PrioritizedElement<String, Integer>> wishList, 
            ExitStrategy exitStrategy, Time timeEntered, Time desiredExitTime)
    {
        super(name, wishList, exitStrategy, timeEntered, 
                desiredExitTime);
        // TODO Auto-generated constructor stub
    }
    
    /**
     * This function will re-order the wish list based on both the distance to
     * each ride within the wish list and the expected wait time.
     */
    protected void selectRide()
    {
        super.selectRide();
        MyPriorityQueue<Attraction, Integer> newWishList = 
            new MyPriorityQueue<Attraction, Integer>();
        
        while(!agenda.isEmpty())
        {
            Attraction ride = agenda.dequeue();
            int priority = currLocation.distance(ride.getEntrance()) +
                ride.getEstimatedWaitTime();
            
            // enqueue the ride again based on the new distance
            newWishList.enqueue(ride, priority);
        }
        agenda = newWishList;
    }

}
