Пример #1
0
        private String testList(int lengthA, int lenghtB, int rangeA, int rangeB, int size)
        {
            int insertArrayLength          = lengthA;
            int removeAndInsertArrayLength = lenghtB;
            int insertRange          = rangeA;
            int removeAndInsertRange = rangeB;

            Element[] elementM = new Element[insertArrayLength];
            Element[] elementN = new Element[removeAndInsertArrayLength];
            Random    rnd      = new Random();
            int       tmp      = 0;

            while (tmp < insertArrayLength)
            {
                elementM[tmp] = new Element(rnd.Next(1, insertRange + 1));
                tmp++;
            }

            tmp = 0;
            while (tmp < removeAndInsertArrayLength)
            {
                elementN[tmp] = new Element(rnd.Next(1, removeAndInsertRange + 1));
                tmp++;
            }

            Stopwatch watch = new Stopwatch();

            watch.Start(); //czy tutaj włączyć czy przy inicjalizacji randomów?
            UnorderedList list = new UnorderedList(size);

            for (tmp = 0; tmp < insertArrayLength; tmp++)
            {
                list.insert(elementM[tmp]);
            }
            tmp = 0;
            while (tmp < removeAndInsertArrayLength)
            {
                list.deleteMin();
                list.insert(elementN[tmp]);
                tmp++;
            }
            watch.Stop();

            return(watch.Elapsed.ToString()); //watch.ElapsedMilliseconds.ToString();
        }
Пример #2
0
        private String testList(int lengthA, int lenghtB, int rangeA, int rangeB, int size)
        {
            int insertArrayLength = lengthA;
            int removeAndInsertArrayLength = lenghtB;
            int insertRange = rangeA;
            int removeAndInsertRange = rangeB;

            Element[] elementM = new Element[insertArrayLength];
            Element[] elementN = new Element[removeAndInsertArrayLength];
            Random rnd = new Random();
            int tmp = 0;
            while (tmp < insertArrayLength)
            {
                elementM[tmp] = new Element(rnd.Next(1, insertRange + 1));
                tmp++;
            }

            tmp = 0;
            while (tmp < removeAndInsertArrayLength)
            {
                elementN[tmp] = new Element(rnd.Next(1, removeAndInsertRange + 1));
                tmp++;
            }

            Stopwatch watch = new Stopwatch();
            watch.Start(); //czy tutaj włączyć czy przy inicjalizacji randomów?
            UnorderedList list = new UnorderedList(size);

            for (tmp = 0; tmp < insertArrayLength; tmp++)
            {
                list.insert(elementM[tmp]);
            }
            tmp = 0;
            while (tmp < removeAndInsertArrayLength)
            {

                list.deleteMin();
                list.insert(elementN[tmp]);
                tmp++;
            }
            watch.Stop();

            return watch.Elapsed.ToString(); //watch.ElapsedMilliseconds.ToString();
        }
Пример #3
0
        private double[] doSimulation(int whichQueue) //same eventy
        {
            Stream stream1 = new Stream(Convert.ToInt32(simVariables[4]), simVariables[2], simVariables[3]);
            Stream stream2 = new Stream(Convert.ToInt32(simVariables[7]), simVariables[5], simVariables[6]);

            Stream[] streams = new Stream[numberOfStreams];
            streams[0] = stream1;
            streams[1] = stream2;

            PriorityQueue priorityQueue;
            EventQueue    evQueue = new EventQueue();

            if (1 == whichQueue)
            {
                priorityQueue = new Heap(queueSize);
            }
            else
            {
                priorityQueue = new UnorderedList(queueSize);
            }

            double currentTime  = 0;
            double totalTime    = 10000;
            int    busyChannels = 0;
            int    inService    = 0;
            int    inQueue      = 0;
            int    lostElements = 0;
            int    doubleToInt  = 10000;

            //Zajętość systemu:
            double averageChannelOccupancySum = 0;
            double averageQueueOccupancySum   = 0;
            double inSystemTime = 0;

            for (int tmp = 0; tmp < 2; tmp++)
            {
                evQueue.addEvent(EventType.Arrival, currentTime + streams[tmp].getRandDistance(), streams[tmp].getStreamSize(), tmp, currentTime);
            }
            while (currentTime < totalTime)
            {
                Event ev = new Event();
                ev = evQueue.getEvent();
                //Console.WriteLine("zdarzenie: {0} o czasie {1}, Stream {2}",ev.eventType, currentTime , ev.numberOfStream);
                inSystemTime = ev.eventTime - currentTime;//czas od ostatniego zdarzenia

                currentTime = ev.eventTime;

                averageChannelOccupancySum += inSystemTime * busyChannels / channelSize;
                averageQueueOccupancySum   += inSystemTime * inQueue / queueSize;

                Element el = new Element(Convert.ToInt32((currentTime * doubleToInt) - 0.5), ev.streamSize);

                switch (ev.eventType)
                {
                case EventType.Arrival:
                    if (busyChannels + el.getStreamSize() < channelSize)
                    {
                        //zajmij kanały
                        inService++;
                        busyChannels += el.getStreamSize();
                        evQueue.addEvent(EventType.Departure, currentTime + streams[ev.numberOfStream].getRandLength(), el.getStreamSize(), ev.numberOfStream, currentTime);
                    }
                    else if (priorityQueue.getNumberOfElements() < queueSize - 1)
                    {
                        //dodaj do kolejki
                        inQueue++;
                        priorityQueue.insert(el);
                    }
                    else
                    {
                        lostElements++;
                        streams[ev.numberOfStream].lost++;
                    }

                    evQueue.addEvent(EventType.Arrival, currentTime + streams[ev.numberOfStream].getRandDistance(), ev.streamSize, ev.numberOfStream, currentTime);
                    break;

                case EventType.Departure:
                    inService--;
                    busyChannels -= ev.streamSize;

                    //srednie
                    streams[ev.numberOfStream].served++;
                    streams[ev.numberOfStream].inSystemTime += currentTime - ev.arrivalTime;

                    if (inQueue > 0)
                    {
                        Element element = priorityQueue.getLowest();
                        if (busyChannels + element.getStreamSize() < channelSize)
                        {
                            //zajmij kanały
                            inQueue--;
                            priorityQueue.deleteMin();
                            inService++;
                            busyChannels += element.getStreamSize();
                            evQueue.addEvent(EventType.Departure, currentTime + streams[ev.numberOfStream].getRandLength(), el.getStreamSize(), ev.numberOfStream, currentTime);
                        }
                    }
                    break;
                }
            }

            //przygotuj dane wyjściowe
            double[] outs = new double[numberOfOuts];
            outs[0] = lostElements;
            outs[1] = averageChannelOccupancySum / totalTime;                                                                            //srednia zajętość kanału
            outs[2] = averageQueueOccupancySum / totalTime;                                                                              //srednia zajetosc kolejki
            if (0 != streams[0].served)                                                                                                  //nie dziel przez zero
            {
                outs[3] = Convert.ToDouble(streams[0].lost) / (Convert.ToDouble(streams[0].served + Convert.ToDouble(streams[0].lost))); //prawdopodobieństwo utraty pakietu
            }
            else
            {
                outs[5] = -10;
            }
            outs[4] = streams[0].inSystemTime / totalTime; // sredni czas przebywania w systemie
            if (0 != streams[1].served)
            {
                outs[5] = Convert.ToDouble(streams[1].lost) / (Convert.ToDouble(streams[1].served + Convert.ToDouble(streams[1].lost)));//prawdopodobieństwo utraty pakietu
            }
            else
            {
                outs[5] = -10;
            }
            outs[6]  = streams[1].inSystemTime / totalTime; // sredni czas przebywania w systemie
            outs[7]  = streams[0].lost;
            outs[8]  = streams[0].served;
            outs[9]  = streams[1].lost;
            outs[10] = streams[1].served;


            return(outs);
        }