Ejemplo n.º 1
0
void CBank::StartATM()
{
  double time1, sim_time = executive->SimulationTime();
  CDistribution dist;
  CEntity * client;

  if(atm_free){
      if(!atm_queue->EhVazia()){

          // Get call from queue
          client = (CEntity *) atm_queue->ObterInfo();
          atm_queue->Remover();
          client->SetActivity(STARTATM);

          // Collect stats on call waiting
          client_wait.Add(time - client->start);
          atm_wait.Add(time - client->start);
          client->start = time;

          if(_DEBUG_) printf("ATM Starts %f \n", time);

          // Calculate call ending time
          time1 = sim_time + dist.NormalLimited(atm_service_mean, atm_service_stddev, min_service, max_service);

          // Schedule end of conversation time
          executive->AddActivity(time1, ENDATM, client);

          // atm isn't free
          atm_free = false;
      }
  }
}
Ejemplo n.º 2
0
void CBank::StartManager()  // service Start handling
{
    double time1, sim_time = executive->SimulationTime();
    CDistribution dist;
    CEntity       *client;

    if(manager_free) { // Manager is free
        if (call_queue->EhVazia() && !manager_queue->EhVazia()) { // There is client in the queue
            // Get client from client queue
            client = (CEntity*) manager_queue->ObterInfo();
            manager_queue->Remover();
            client->SetActivity(ENDMANAGER);

            // Collect statistics on client waiting
            client_wait.Add(time - client->start);
            manager_wait.Add(time - client->start);
            client->start = time;

            if(_DEBUG_) printf("Service Starts %f \n", time);

            // Calculate service ending time
            time1 = sim_time + dist.NormalLimited(manager_service_mean, manager_service_stddev, min_service, max_service);
            executive->AddActivity(time1, ENDMANAGER, client);
            manager_free = false;
        }
    }

}
Ejemplo n.º 3
0
void CBank::ArriveClient()  // Arrival activity handling
{
    double time1, sim_time = executive->SimulationTime();

    if (activity == ARRIVE && time == sim_time) {
        CEntity *client = new CEntity();
        CDistribution dist;

        // Current client arrival
        entity->arrive = time;
        entity->start  = time;
        if(_DEBUG_) printf("Client Arrives %f \n", time);

        // Next client arrival time calculation
        time1 = sim_time + dist.Exponential(arrival_mean);
        client->SetActivity(ARRIVE);

        // Schedule next client arrival
        executive->AddActivity(time1, ARRIVE, client);

        // decide where the client goes
        double r = dist.Random();
        if(r < arrival_teller_prob){
            teller_queue->InserirFim(entity);
        }else if(r < arrival_teller_prob + arrival_manager_prob){
            manager_queue->InserirFim(entity);
        }else{
            atm_queue->InserirFim(entity);
        }

    }
}
Ejemplo n.º 4
0
void CBank::StartCall()  // Call start handling
{
    double time1, wait_time, sim_time = executive->SimulationTime();
    CDistribution dist;
    CEntity * call;

    if(manager_free){
        if(!call_queue->EhVazia()){

            // Get call from queue
            call = (CEntity *) call_queue->ObterInfo();
            call_queue->Remover();
            call->SetActivity(STARTCALL);
            call->start=time;

            // Collect stats on call waiting if doesnt waiting for a long time
            wait_time = call->start - call->arrive;
            call_wait.Add(wait_time);
            if(wait_time < call_max_wait){
              call_attended.Add(1.0);
            }else{
              call_attended.Add(0.0);
              return ;
            }

            if(_DEBUG_) printf("Call Starts %f \n", time);

            // Calculate call ending time
            time1 = sim_time + dist.Uniform(min_call, max_call);

            // Schedule end of conversation time
            executive->AddActivity(time1, ENDCALL, call);

            // manager isn't free
            manager_free = false;
        }
    }
}
Ejemplo n.º 5
0
int main(int argc, _TCHAR* argv[])
{
    char c;
    CEntity *client = new CEntity();
    CEntity *call   = new CEntity();
    executive       = new CBankExecutive();
    client_queue    = new CLista<CEntity *>;
    call_queue      = new CLista<CEntity *>;
    manager_queue   = new CLista<CEntity *>;
    atm_queue       = new CLista<CEntity *>;
    teller_queue    = new CLista<CEntity *>;
    CDistribution dist;

    // Simulation Paramters
    // um ano = 60min * 8h * 21d * 12m
    double total_time = 10*60*8*21*12;
    executive->SetSimulationEnd(total_time);
    // call_arrival=5.0; // call arrival mean - Negative exponential distribution
    // arrival_mean=3.0; // client arrival mean - Negative exponential distribution
    // min_service=0.5; // minimum of uniform distribution
    // max_service=2.0; // maximum of uniform distribution
    // min_call=0.5; // minimum of uniform distribution
    // max_call=1.5; // maximum of uniform distribution


    call_arrival           = 10.0;    // call arrival mean - Negative exponential distribution
    arrival_mean           = 5.0;     // client arrival mean - Negative exponential distribution
    arrival_manager_prob   = 0.1;
    arrival_teller_prob    = 0.2;
    atm_service_mean       = 4.0;
    atm_service_stddev     = 2.0;
    teller_service_mean    = 7.0;
    teller_service_stddev  = 3.0;
    manager_service_mean   = 10.0;
    manager_service_stddev = 4.0;
    atm_to_teller_prob     = 0.15;
    atm_to_manager_prob    = 0.15;
    min_service            = 0.2;     // minimum of uniform distribution
    max_service            = 10000.0; // maximum of uniform distribution
    min_call               = 1.0;     // minimum of uniform distribution
    max_call               = 10.0;    // maximum of uniform distribution
    call_max_wait          = 10.0;

    // Initial activitys: client arrival and call arrival

    // Schedule next client arrival
    client->SetActivity(ARRIVE);
    executive->AddActivity(dist.Exponential(arrival_mean), ARRIVE, client);

    // Schedule next call arrival
    call->SetActivity(ARRIVECALL);
    executive->AddActivity(dist.Exponential(call_arrival), ARRIVECALL, call);

    // Simulation loop
    while(executive->SimulationTime() < executive->SimulationEnd()) {
        sim_time = executive->TimeScan(); // Time Scan = get next activity time
        executive->ExecuteActivities();   // Execute all activitys at sim_time
    }

    // Report statistics on mean, std dev, min and max
    StatisticsReport();
    printf("\nPress any key to end\n");
    scanf("%c",&c);
    return 0;

}