예제 #1
0
 public Simulation()
 {
     this.store = new Store();
     cont = false;
     this.client_args = new List<ClientStoreArg>();
     this.SP_args = new List<SPStoreArg>();
     this.queue_args = new List<QueueStoreArg>();
 }
 public SpecializedServicePoint(int i, Store store, string type, int maxQueueSize, int maxItems, int itemProcessingTime)
     : base(i, store)
 {
     this.maxQueueSize = maxQueueSize;
     this.maxItems = maxItems;
     this.type = type;
     this.itemProcessingTime = itemProcessingTime;
     this.queue.setMaxClients(maxQueueSize);
 }
예제 #3
0
        public Supervisor(Store s)
        {
            store = s;
            timeLastClientEntered = new Dictionary<ServicePoint, long>();
            timeLastClientEntered.Remove(new ServicePoint(10, s));

            strategies = new List<SupervisorStrategy>();
            strategies.Add(new ArrivalRateStrategy(store));
            strategies.Add(new QueueSizeStrategy(store));
            //Store.ServicePointOpened += new Store.ServicePointOpenedEventHandler(OpenedCash);
            this.currentStrategy = 0;
            this.store = s;
        }
예제 #4
0
        public ServicePoint(int i, Store store)
        {
            //clients = new List<Client>();

            queue = new StoreQueueListImpl(this.ToString(), Configs.MAX_CLIENTS_PER_CASH);
            queue.AddServicePoint(this);

            id = i;
            this.store = store;
            arrivalRate = 0.0f;
            timeOpened = Timer.getTick();
            this.type = "default";
            this.maxItems = Configs.MAX_ITEMS_PER_CLIENT;
        }
예제 #5
0
        public Client(int numServiceItems, Store s)
        {
            this.id = CUSTOMERID;
            CUSTOMERID++;
            this.inQueue = false;
            this.timeEnteredStore = Timer.getTick();
            this.timeEnteredQueue = -1;
            this.state = STATES.WAIT_TO_QUEUE;
            this.serviceItems = new List<ServiceItem>();
            this.GenerateServiceItems(numServiceItems);

            this.strategies = new List<ClientStrategy>();
            this.strategies.Add(new SmallestQueueStrategy(s, this));
            this.strategies.Add(new FewestItemsStrategy(s, this));
            this.currentStrategy = 0;

            patience = Configs.CLIENT_CHANGE_QUEUE_INTERVAL + (new Random()).Next(180);
            this.store = s;
        }
 public FewestItemsStrategy(Store s, Client c)
 {
     store = s;
     client = c;
     type = 1;
 }
예제 #7
0
        private int determineBetterServicePoint(Store store)
        {
            List<ServicePoint> sps = store.getServicePoints();
            int index = -1;
            ServicePoint curSP = store.getWhichServicePointAt(this);
            int curConstraint = curSP.getClients().IndexOf(this);
            int size = 10000000;

            if (strategies.ElementAt(this.currentStrategy).getStrategyType() == 1)
            {
                int t = 0;
                List<Client> clients = curSP.getClients();
                for (int i = 0; i < curConstraint; i++)
                {
                    t += clients.ElementAt(i).getNumItems();
                }
                curConstraint = t;
            }

            foreach (ServicePoint s in sps)
            {
                switch (strategies.ElementAt(this.currentStrategy).getStrategyType())
                {
                    case 0:
                        if (s.getClients().Count < size && s.CanService(this))
                        {
                            index = s.getId();
                            size = s.getClients().Count;
                        }
                        break;
                    case 1:
                        if (s.getTotalItems() < size && s.CanService(this))
                        {
                            index = s.getId();
                            size = s.getTotalItems();
                        }
                        break;
                }
            }

            if (curSP.getId() == index)
            {
                return -1;
            }
            return index;
        }
예제 #8
0
        public void Update(Store store)
        {
            bool finished = false;

            do
            {
                switch (state)
                {
                    // If it's waited the amount of time needed to enter  the queue, then enter the queue.
                    case STATES.WAIT_TO_QUEUE:
                        if (this.isReadyForQueue())
                        {
                            this.timeEnteredQueue = Timer.getTick();
                            store.AddClientToWaitQueue(this, this.chooseStoreWaitingQueue());
                            this.state = STATES.IN_WQ;
                            this.startWQTime = Timer.getTick();
                        }
                        else
                        {
                            finished = true;
                        }
                        break;

                    case STATES.IN_WQ:
                        if (store.getQueuePosition(this) == 0)
                        {
                            this.state = STATES.FRONT_WQ;
                        }
                        else
                        {
                            finished = true;
                        }
                        break;

                    case STATES.FRONT_WQ:
                        if (this.goToOptimalServicePoint(store))
                        {
                            this.startSQTime = Timer.getTick();
                            this.state = STATES.IN_CASH;
                        }
                        else
                        {
                            finished = true;
                        }
                        break;

                    case STATES.IN_CASH:
                        if (this.startSQTime + this.patience < Timer.getTick())
                        {
                            int index = determineBetterServicePoint(store);
                            if (index != -1)
                            {

                            }
                        }
                        finished = true;
                        break;

                    case STATES.FRONT_CASH:
                        finished = true;
                        break;

                }
            }
            while (!finished);
        }
예제 #9
0
        // When the customer strategy is implemented, put it in this part
        public bool goToOptimalServicePoint(Store store)
        {
            List<ServicePoint> spList = store.CheckForAvailableCashes(this);

            if (spList.Count > 0)
            {
                ServicePoint s = strategies.ElementAt(this.currentStrategy).selectServicePoint(spList);
                store.MoveClientToCash(this, s);
                return true;
            }
            else
            {
                return false;
            }
        }
 public ArrivalRateStrategy(Store s)
     : base(s, "ArrivalRateStrategy")
 {
 }
예제 #11
0
 public void setStore(Store s)
 {
     this.store = s;
 }
예제 #12
0
 public ClientStrategy(Store s, Client c)
 {
     store = s;
     client = c;
     type = -1;
 }
 public QueueSizeStrategy(Store s)
     : base(s, "QueueSizeStrategy")
 {
 }
 public SupervisorStrategy(Store s, string name)
 {
     store = s;
     this.name = name;
 }
 public SmallestQueueStrategy(Store s, Client c)
 {
     store = s;
     client = c;
     type = 0;
 }