• º» °Ô½ÃÆÇÀº ¼ö¾÷½Ã°£¿¡ Çлýµé ½Ç½ÀÀ» À§ÇÑ °Ô½ÃÆÇÀÔ´Ï´Ù.
  • º» °Ô½ÃÆÇ¿¡ ¿Ã¶ó¿Í ÀÖ´Â ÇÁ·Î±×·¥Àº ´ëºÎºÐ ¿Ã¹Ù¸£Áö ¾ÊÀº ÇÁ·Î±×·¥ÀÔ´Ï´Ù.
        ¹Ú±ÝÁ¤
        11½Ç½À) ½Ã¹Ä·¹À̼Ç




    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>

    #define MAX_QUEUE_SIZE 10
    #define TRUE 1
    #define FALSE 0

    typedef struct {
      int id;
      int arrival_time;
      int service_time;
    } element;

    typedef struct {
      element  queue[MAX_QUEUE_SIZE];
      int  front, rear;
    } QueueType;
    QueueType queue;

    // 0¿¡¼­ 1»çÀÌÀÇ ½Ç¼ö ³­¼ö »ý¼º ÇÔ¼ö
    double random() {
      return rand()/(double)RAND_MAX;
    }

    // ½Ã¹Ä·¹À̼ǿ¡ ÇÊ¿äÇÑ ¿©·¯°¡Áö »óÅ º¯¼ö
    int duration=10; // ½Ã¹°·¹ÀÌ¼Ç ½Ã°£
    double arrival_prob=0.7; // ÇϳªÀÇ ½Ã°£ ´ÜÀ§¿¡ µµÂøÇÏ´Â Æò±Õ °í°´ÀÇ ¼ö
    int max_serv_time=5; // ÇϳªÀÇ °í°´¿¡ ´ëÇÑ ÃÖ´ë ¼­ºñ½º ½Ã°£
    int clock;

    // ½Ã¹Ä·¹À̼ÇÀÇ °á°ú
    int cashier;
    int customers;      // Àüü°í°´¼ö
    int served_customers;  // ¼­ºñ½º¹ÞÀº °í°´¼ö
    int waited_time;  // °í°´µéÀÌ ±â´Ù¸° ½Ã°£
    // ·£´ý ¼ýÀÚ¸¦ »ý¼ºÇÏ¿© °í°´ÀÌ µµÂøÇß´ÂÁö µµÂøÇÏÁö ¾Ê¾Ò´ÂÁö¸¦ ÆÇ´Ü
    int is_customer_arrived() {

      if( random() < arrival_prob )
        return TRUE;
      else return FALSE;
    }

    // °ø¹é »óÅ °ËÃâ ÇÔ¼ö
    int is_empty(QueueType *q)
    {
     return (q->front == q->rear);
    }
    // Æ÷È­ »óÅ °ËÃâ ÇÔ¼ö
    int is_full(QueueType *q)
    {
     return ((q->rear+1)%MAX_QUEUE_SIZE == q->front);
    }
    // »ðÀÔ ÇÔ¼ö
    void enqueue(QueueType *q, element item)
    {
       if( is_full(q) )
      fprintf(stderr,"Å¥°¡ Æ÷È­»óÅÂÀÔ´Ï´Ù\n");
     q->rear = (q->rear+1) % MAX_QUEUE_SIZE;
     q->queue[q->rear] = item;
    }
    // »èÁ¦ ÇÔ¼ö
    element dequeue(QueueType *q)
    {
        if( is_empty(q) )
      fprintf(stderr,"Å¥°¡ °ø¹é»óÅÂÀÔ´Ï´Ù\n");
     q->front = (q->front+1) % MAX_QUEUE_SIZE;
     return q->queue[q->front];
    }

    // »õ·Î µµÂøÇÑ °í°´À» Å¥¿¡ »ðÀÔ
    void insert_customer(int arrival_time) {
      element customer;

      customer.id = customers++;
      customer.arrival_time = arrival_time;
      customer.service_time=(int)(max_serv_time*random()) + 1;
      enqueue(&queue, customer);
      printf("[°í°´ %d] %dºÐ¿¡ µµÂø   ¼­ºñ½º½Ã°£Àº %dºÐ\n",
           customer.id, customer.arrival_time, customer.service_time);
    }
    int remove_customer(int cashier) {
      element customer;
      int service_time=0;
      //int servise_timw2=0;

      if (is_empty(&queue)) return 0;
     
      customer = dequeue(&queue);
      service_time = customer.service_time-1;
      served_customers++;
      waited_time += clock - customer.arrival_time;

      printf("\t[°í°´ %d] (ÀºÇà¿ø%d) %dºÐ¿¡ ¼­ºñ½º ½ÃÀÛ   ´ë±â½Ã°£Àº %dºÐ\n"
          ,customer.id, cashier, clock, clock - customer.arrival_time);
     
      return service_time;
    }
    // Åë°èÄ¡¸¦ Ãâ·ÂÇÑ´Ù.
    void print_stat() {
      printf("----------------------------------------\n");
      printf("¼­ºñ½º¹ÞÀº °í°´¼ö = %d\n",
               served_customers);
      printf("Àüü ´ë±â ½Ã°£ = %dºÐ\n", waited_time);
      printf("1Àδç Æò±º ´ë±â ½Ã°£ = %fºÐ\n",
        (double)waited_time/served_customers);
      printf("¾ÆÁ÷ ´ë±âÁßÀÎ °í°´¼ö = %d\n",
       customers-served_customers);
      printf("----------------------------------------\n");
    }
    // ½Ã¹Ä·¹ÀÌ¼Ç ÇÁ·Î±×·¥
    void main()
    {
      int service_time1=0;
      int service_time2=0;
      int i;
      printf("----------------------------------------\n");
      printf("//1ºÐ´ç °í°´ µµÂøÀ² : %f\n",arrival_prob);
      printf("//1ÀÎ ÃÖ´ë ¼­ºñ½º½Ã°£ : %d\n",max_serv_time);
      printf("----------------------------------------\n");
      clock=0;
      while(clock < duration){
        clock++;
        printf("(t=%d)   ",clock);

      if (is_customer_arrived()) {
        insert_customer(clock);
      }
      if (service_time1 > 0)
        service_time1--;
      else {
        service_time1 = remove_customer(1);
      }
      if (service_time2 >0)
       service_time2--;
      else
       service_time2 = remove_customer(2);
     }
     
      print_stat();
    }

     

      µî·ÏÀÏ : 2017-06-01 [22:01] Á¶È¸ : 916 ´Ù¿î : 0   
     
    ¡â ÀÌÀü±Û½Ç½À
    ¡ä ´ÙÀ½±Û½Ç½À6 Ãß°¡ ¼öÁ¤
    Çлý½Ç½À °Ô½ÃÆÇ
    ¹øÈ£ ¨Ï Á¦ ¸ñ À̸§ Á¶È¸ µî·ÏÀÏ
    35 ÃÊ º¯È¯ ¼ÒÇÁÆ®¿þ¾îÀÇÀÌÇØ ¹ÚÁÖÇü 709 09-19
    34 ½ÃºÐÃÊ ºñ°ø°³ ¼ÒÇÁÆ®¿þ¾îÀÇÀÌÇØ Àå¼÷¿µ 25 09-19
    33 ½Ç½À ºñ°ø°³ ¼ÒÇÁÆ®¿þ¾îÀÇÀÌÇØ È«¼®ÁØ 22 09-19
    32 11½Ç½À) ½Ã¹Ä·¹ÀÌ¼Ç ÀڷᱸÁ¶ ¹Ú±ÝÁ¤ 916 06-01
    31 ½Ç½À6 Ãß°¡ ¼öÁ¤ ÀڷᱸÁ¶ ±èÀ±¼º 966 04-13
    30 ½Ç½À 6 Ãß°¡ ÀڷᱸÁ¶ ±èÀ±¼º 874 04-13
    29 ½Ç½À4-Ãß°¡ ÀڷᱸÁ¶ Á¶¼º¹ü 895 03-30
    28 ½Ç½À3-Ãß°¡ ÀڷᱸÁ¶ Á¶¼º¹ü 839 03-23
    27 ½Ç½À3-°í±Þ ÀڷᱸÁ¶ Á¶¼º¹ü 900 03-23
    26 ½Ç½À3-2 ÀڷᱸÁ¶ ±èÀ±¼º 832 03-23
    25 ½Ç½À2 °í±Þ ÀڷᱸÁ¶ Á¶¼º¹ü 941 03-16
    24 ½Ç½À2 Ãß°¡ ÀڷᱸÁ¶ ÇÑ½Â½Ä 890 03-16
    23 ½Ç½À1 ÀڷᱸÁ¶ Á¶¼º¹ü 880 03-09
    22 ³²´Ù¼Ö °´Ã¼ÁöÇâ¾ð¾î ³²´Ù¼Ö 1178 09-13
    21 1693028 À̼ºÁÖ 2Àå½Ç½À¹®Á¦ 4¹ø °´Ã¼ÁöÇâ¾ð¾î À̼ºÁÖ 1085 09-08

    [1][2][3][4][5][6][7]