Hej!
Chcę wykonać zadanie o treści: Znajdź taką wartość średniej liczby klientów na godzinę, dla której średni czas oczekiwania w kolejce wyniesie minutę (w próbach co najmniej 100-godzinnych). Myślę nad nim już dużo czasu i nie mam pojęcia jak wyliczyć tą średnią wartość liczby klientów na godzinę, proszę o sugestie!
Z góry dziękuję :)
Klasy:
#pragma once
#ifndef QUEUE_H_
#define QUEUE_H_
#include <cstdlib>
class Customer
{
long arrive;
long processtime;
public:
Customer() { arrive = processtime = 0; }
void set(long when) { arrive=when; processtime=std::rand()%3+1;}
long when() { return arrive; }
int ptime() { return processtime; }
};
typedef Customer Item;
class Queue
{
struct Node { Item item; Node *next; };
enum { Q_SIZE = 10 };
Node *front;
Node *rear;
int items;
const int qsize;
Queue(const Queue &q) :qsize(0) {}
Queue & operator=(const Queue &q) { return *this; }
public:
Queue(int qs = Q_SIZE);
bool isempty();
bool isfull();
int queuecount() const; // zwraca ilosc elementow w kolejce
bool enqueue(const Item &item); //dodanie elementu do kolejki
bool dequeue(Item &item); //usuniecie elementu z kolejki
~Queue();
};
#endif
Mój program main (choć na pewno błędny):
#include <iostream>
#include "Queue.h"
#include <cstdlib>
#include <ctime>
const int MIN_PER_HR = 60;
int main()
{
using std::cin;
using std::cout;
using std::endl;
using std::ios_base;
std::srand(time(0));
cout << "Studium przypadku: bankomat Stu Kas\n";
cout << "Podaj maksymalna dlugosc kolejki:";
int qs;
cin >> qs;
Queue line(qs);
cout << "Podaj symulowany czas (w godzinach): ";
int hours;
cin >> hours;
long cyclelimit = MIN_PER_HR*hours;
Item temp;
long turnaways = 0;
long customers = 0;
long served=0;
long sum_line = 0;
int wait_time = 0;
long line_wait = 0;
for (int cycle = 0; cycle < cyclelimit; cycle++)
{
if (line.isfull())
turnaways++;
else
{
temp.set(cycle);
line.enqueue(temp);
customers++;
}
if (wait_time <= 0 && !line.isempty())
{
line.dequeue(temp);
wait_time = temp.ptime();
line_wait += cycle - temp.when();
served++;
}
if (wait_time > 0)
wait_time--;
sum_line += line.queuecount();
}
if (customers > 0)
{
cout << "Liczba przyjetych klientow: " << customers << endl;
cout << "Liczba klientow odeslanych: " << turnaways << endl;
cout << "Srednia dlugosc kolejki: ";
cout.precision(2);
cout.setf(ios_base::fixed, ios_base::floatfield);
cout.setf(ios_base::showpoint);
cout << (double)sum_line / cyclelimit;
//served = line_wait;
cout << "\nLiczba obsluzonych klientow: " << served << endl;
cout << "Laczny czas oczekiwania: " << line_wait << endl;
long cust_per_hour = line_wait / hours;
cout << "Ilosc klientow na godzine: " << cust_per_hour << endl;
cout << line_wait / customers << endl;
}
}