C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[6668] 이거.왜 결과가 이상하죠??
이정훈 [] 2133 읽음    2001-04-07 15:44
C++로 프로그램을 짰는데......프로그램 결과가 원하는게 안나오네요
값이 잘 못 들어간거 같은데.어딘지 모르겠어요
한번 바주시고요..조언부탁드립니다..

===========================================================================================
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>

#define  CBR  5
#define  rt_VBR  4
#define  nrt_VBR  3

#define num_CBR 5
#define num_rt_VBR 28
#define num_nrt_VBR 2
#define MAX_MT 35

#define A 16807.0
#define B 2147483647.0
#define frameDuration 0.002


typedef long int Lint;

typedef struct Call
{

        int mtNUM;                                 
        int service;
        Lint length;
        Lint arvTime;
        Lint srtTime;
}Call;

Call QUEUE[MAX_MT];

int DATASLOT = 30;
double  LambdaC=0.0005, LambdaV=0.1;
long int CLK=0, duration=100000;

static double possionC_seed=1., PossionV_seed=1., PossionDealy_seed=1.;
static double expoC_seed=1., expoV_seed=1.;
static long seed1=0,seed2=1,seed3=2,seed4=3,seed5=4,seed6=5,seed7=6,seed8=7;

long int tot_gen_num, c_gen_num,v_gen_num,vr_gen_num;
double TOT_LOAD, CBR_LOAD=0.5, RT_VBR_LOAD=0.35, NRT_VBR_LOAD=0.15;


void traffic_generation();
double rnd(double *);
int possion(double,double *);
void traffic_test();
void initialize();
void performance_result();


void traffic_generation()
  {
        int i, count=0;
        double load,gen_num;

        for(i=0;i<num_CBR;i++)  {
                QUEUE[i].mtNUM=i;
                QUEUE[i].service=CBR;

                load=(double)(TOT_LOAD*CBR_LOAD*DATASLOT)/num_CBR;
                //cprintf("%ld",CBR_LOAD);
                //cprintf("%lu\n",load);
                gen_num=possion(load,&possionC_seed);

                QUEUE[i].length = QUEUE[i].length + gen_num;

                c_gen_num=c_gen_num+gen_num;
                tot_gen_num=tot_gen_num+gen_num;
     }
                count=i;

   for(i=count;i<count+num_rt_VBR;i++) {
                QUEUE[i].mtNUM=i;
                QUEUE[i].service=rt_VBR;

                load=(float)(TOT_LOAD*RT_VBR_LOAD*DATASLOT)/num_rt_VBR;

                gen_num=possion(load,&expoV_seed);

                QUEUE[i].length = QUEUE[i].length + gen_num;

                v_gen_num=v_gen_num+gen_num;
                tot_gen_num=tot_gen_num+gen_num;
     }
                count=i;

    for(i=count;i<count+num_nrt_VBR;i++){
                QUEUE[i].mtNUM=i;
                QUEUE[i].service=nrt_VBR;

                load=(float)(TOT_LOAD*CBR_LOAD*DATASLOT)/num_nrt_VBR;

                gen_num=possion(load,&expoV_seed);

                QUEUE[i].length = QUEUE[i].length + gen_num;

                vr_gen_num=vr_gen_num+gen_num;
                tot_gen_num=tot_gen_num+gen_num;
     }
              

   }



   double rnd(double *r_seed)
   {
        *r_seed=fmod(A*(*r_seed),B);
        return((*r_seed)*4.656612875e-10);

   }

   int possion(double a, double *r_seed)
   {
       
        int i;
        float u,p,f;
        i=0;
        f=p=exp(-a);
        u=rnd(r_seed);
        cprintf("\%ld",f);

        while(f<=u)
        {
                p*=(a/(i+1.0));
                f+=p;
                i++;
        }

        return(i);

   }


   void initialize()

   {
       
       // int i;
       // clrscr();

        cprintf("\nTOTAL LOAD ??");
        scanf("%ld",&TOT_LOAD);
   
   }


  void traffic_test()
  {
        long int i;

        for(i=0;i<10000;i++){
        traffic_generation();
        CLK++;

        if(i==10000){
            cprintf("\n\n\n%f",(double)tot_gen_num/(double)(CLK*DATASLOT));
            cprintf("\n%f",(double)c_gen_num/(double)(CLK*DATASLOT));
            cprintf("\n%f",(double)v_gen_num/(double)(CLK*DATASLOT));
            cprintf("\n%f",(double)vr_gen_num/(double)(CLK*DATASLOT));
                     }
        }
  }



void performance_result()
{

   //  FILE *OUT;
     int i,count=0;

     //cprintf("\n clk ==> %ld",CLK);
     //cprintf("\nTOT_slot ==>%ld",CLK*DATASLOT);
     //cprintf("\nTOT_gen_num ==>%ld",tot_gen_num);

  //   if((OUT=fopen("result.txt","r"))==NULL){
   //  OUT=fopen("result.txt","w");
    // fclose(OUT);
    // }

     //OUT=fopen("result.txt","a");



      cprintf("\nCBR\n");
      cprintf("NUM \t SERVICE \t LOAD \t LENGTH");
   
      for(i=0;i<num_CBR;i++){
          
            cprintf("\n%d\t %ld\t  %ld\t",QUEUE[i].mtNUM,QUEUE[i].service,QUEUE[i].length);
       }
     
      count=i;
      cprintf("\n\nrt_VBR\n");
      cprintf("NUM \t SERVICE \t LOAD \t LENGTH");
    
     
      for(i=count;i<count+num_rt_VBR;i++){
         
            cprintf("\n%d\t %ld\t  %ld\t l",QUEUE[i].mtNUM,QUEUE[i].service,QUEUE[i].length);
       }
     
      count=i;
      cprintf("\n\nnrt_VBR\n");
      cprintf("NUM \t SERVICE \t LOAD \t LENGTH");
     
      for(i=count;i<count+num_nrt_VBR;i++){
           
            cprintf("\n%d\t %ld\t  %ld\t l",QUEUE[i].mtNUM,QUEUE[i].service,QUEUE[i].length);
       }

}
       

void main()
{

        initialize();
        traffic_generation();
        performance_result();
        getch();
}
==========================================================================================

+ -

관련 글 리스트
6668 이거.왜 결과가 이상하죠?? 이정훈 2133 2001/04/07
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.