Покупатель
        public AddToCart(Customer customer, string desiredProduct, Shelf shelf)
            : base(customer)
        {
            this.desiredProduct = desiredProduct;
            this.shelf = shelf;

            interactionZone = shelf.ClosestInteractionZone(customer.Position);
            Vector3 destination = interactionZone.transform.position;
            moveControl.SetDestination(destination);

            // Think about the desired product
            GameObject product = supermarket.Catalogue[desiredProduct].Model;
            customer.Think(product);
        }
 public void DisplayCustomer(Customer customer)
 {
     this.customer = customer;
     customer.AddListener(this);
     gameObject.SetActive(true);
     currentActionLabel.text = customer.Action;
 }
 public FindShelf(Customer customer, string product)
     : base(customer)
 {
     this.product = product;
     customer.Think(supermarket.Catalogue[product].Model);
     RandomPosition();
 }
 public Idle(Customer customer, float seconds = 5)
     : base(customer)
 {
     // Think about being idle
     customer.Think(supermarket.IdleIcon);
     delay = customer.StartCoroutine(Delay(seconds));
 }
        public Exit(Customer customer)
            : base(customer)
        {
            // Destination is a random exit in the supermarket
            exitZone = supermarket.RandomExit();
            moveControl.SetDestination(exitZone.transform.position);

            // Think about exit
            customer.Think(supermarket.ExitIcon);
        }
        public Queue(Customer customer, Checkout checkout)
            : base(customer)
        {
            this.checkout = checkout;
            interactionZone = checkout.ClosestInteractionZone(customer.transform.position);

            // Move to closest checkout interaction zone
            moveControl.SetDestination(interactionZone.transform.position);

            // Clear thought bubble
            customer.Think(null);
        }
 public CustomerWander(Customer customer)
     : base(customer)
 {
     Vector3 position = supermarket.RandomPosition();
     moveControl.SetDestination(position);
 }
 public MoveToPosition(Customer customer, Vector3 destination)
     : base(customer)
 {
     // Move to destination
     moveControl.SetDestination(destination);
 }
 public void OnCustomerStateChange(Customer customer)
 {
     currentActionLabel.text = customer.Action;
 }
 public CustomerState(Customer customer)
 {
     supermarket = customer.Supermarket;
     moveControl = customer.MoveControl;
     this.customer = customer;
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Запустить процесс моделирования
        /// </summary>
        /// <param name="workingTime">время работы магазина</param>
        /// <param name="cashDeskCount">число касс</param>
        /// <param name="lambda">плотность обслуживания</param>
        public void StartWork(float workingTime, int cashDeskCount, float lambda)
        {
            daysServed = new int[((int) workingTime) / (24 * 60 * 60) + 2];

            sigma = 1.0f;

            for (var i = 0; i < densityCoeff.Length; i++)
                densityCoeff[i] = 0.3f + (float) Math.Pow(5, (1 - 2 * Math.Pow((0.15 * (i - 12)), 2)));
            // проверка входных данных
            if (workingTime <= 0 || cashDeskCount <= 0)
                throw new ApplicationException();
            Money = 0.0f;
            // модельное время
            time = new ModelTime();
            lastVisitorTime = new ModelTime();
            // кассы
            cashDesks = new CashDesk[cashDeskCount];
            for (int i = 0; i < cashDesks.Length; i++)
                cashDesks[i] = new CashDesk(lambda, distributionType);
            // число неудовлетворённых покупателей
            UnsatisfiedCustomersCount = 0;
            // число обслуженных покупателей
            TotalCustomerCount = 0;

            // процесс моделирования
            while (time.Time < workingTime)
            {
                // первый покупатель
                if (lastVisitorTime.Time == 0.0)
                {
                    var addTime = GetNextTime(((int) time.Time) % 24);
                    lastVisitorTime.Add(addTime);
                    var customer = new Customer(lastVisitorTime.Time);

                    // выбрали наилучшую кассу
                    var bestDesk = cashDesks[0];
                    // встаём в очередь
                    bestDesk.Enqueue(customer);
                    time.Add(addTime);

                    // установить время прихода следуюшего покупателя
                    lastVisitorTime.Add(GetNextTime(((int)time.Time) % 24));
                }
                else
                {
                    CashDesk first = null;
                    foreach (CashDesk desk in cashDesks)
                    {
                        if (desk.QueueLength > 0)
                        {
                            if (first == null || desk.ServeTime < first.ServeTime)
                                first = desk;
                        }
                    }
                    if (first != null && first.QueueLength > 0)
                    {
                        // если покупатель придёт раньше, чем кого-либо обслужат
                        if (lastVisitorTime.Time < first.ServeTime)
                        {
                            var customer = new Customer(lastVisitorTime.Time);

                            // выбрали наилучшую кассу
                            var bestDesk = cashDesks[0];
                            foreach (var desk in cashDesks)
                            {
                                if (desk.QueueLength < bestDesk.QueueLength)
                                    bestDesk = desk;
                            }
                            // встаём в очередь
                            bestDesk.Enqueue(customer);
                            time.Time = lastVisitorTime.Time;

                            // установить время прихода следуюшего покупателя
                            lastVisitorTime.Add(GetNextTime(((int)time.Time) % 24));
                        }
                        else
                        {
                            // обслуживание покупателя
                            daysServed[((int)time.Time) / (24 * 60 * 60)]++;
                            time.Time = first.ServeTime;
                            Money += (first.Dequeue()).Money;
                            TotalCustomerCount++;
                        }
                    }
                    else
                    {
                        var customer = new Customer(lastVisitorTime.Time);

                        // выбрали наилучшую кассу
                        var bestDesk = cashDesks[0];
                        // встаём в очередь
                        bestDesk.Enqueue(customer);
                        time.Time = lastVisitorTime.Time;

                        // установить время прихода следуюшего покупателя
                        lastVisitorTime.Add(GetNextTime(((int)time.Time) % 24));
                    }
                }
            } // while

            // необслуженные покупатели
            foreach (CashDesk desk in cashDesks)
            {
                UnsatisfiedCustomersCount += desk.QueueLength;
            }
        }
 /// <summary>
 /// Returns the given object to the object pool and deactives it until it is spawned again.
 /// </summary>
 /// <param name="obj">The object to despawn</param>
 public void DeSpawn(Customer obj)
 {
     pool.Reassign(obj);
 }
 public SelectCheckout(Customer customer)
     : base(customer)
 {
     /* Nothing */
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Встать в очередь
 /// </summary>
 /// <param name="customer">посетитель</param>
 public void Enqueue(Customer customer)
 {
     float add;
     switch (distributionType)
     {
         case DistributionType.Exponential:
             add = RandomGenerator.GetExponentialDistributedValue(lambda);
             break;
         default:
             add = RandomGenerator.GetUniformDistributedValue(0, lambda * 60);
             break;
     }
     if (customers.Count == 0)
     {
         customers.Enqueue(customer);
         customer.ServeTime = customer.ComingTime + add;
         serveTime = customer.ServeTime;
     }
     else
     {
         float time = Math.Max(serveTime, customer.ComingTime) + add;
         customer.ServeTime = time;
         customers.Enqueue(customer);
         serveTime = time;
     }
 }
Ejemplo n.º 15
0
 //
 // TODO: if shopping list is empty steal stuff or impulse buy or seomthing
 //
 public Shop(Customer customer)
     : base(customer)
 {
     /* Nothing */
 }
Ejemplo n.º 16
0
 public void DisplayCustomer(Customer customer)
 {
     customerGUI.DisplayCustomer(customer);
 }