예제 #1
0
void arrive(void){ /* Arrival event function. */
	float delay;
	/* Schedule next arrival. */
	time_next_event[1] = sim_time + expon(mean_interarrival);

	/* Check to see whether server is busy. */
	if(server_status == BUSY){
		/* Server is busy so increment the number of customers in the queue. */
		++num_in_q;

		/* Check to see whether an overflow condition exists. */
		if(num_in_q > Q_LIMIT){
			/* The queue has overflowed, so stop the simulation. */
			fprintf(outfile, "\nOverflow of the array time_arrival at");
			fprintf(outfile, " time %f", sim_time);
			exit(2);
		}

		/* There is still room in the queue, so store the time of arrival of the arriving customer at the (new) end of time_arrival. */
		time_arrival[num_in_q] = sim_time;
	}

	else{
		/* Server is idle, so arriving customer has a delay of zero. */
		delay = 0.0;
		total_of_delays += delay;

		/* Increment the number of customers delayed, and make server busy. */
		++num_custs_delayed;
		server_status = BUSY;

		/* Schedule a departure (service completion). */
		time_next_event[2] = sim_time + expon(mean_service);
	}
}
예제 #2
0
void arrive1(void)  /* Arrival event function. */
{
    float delay;

    /* Schedule next arrival. */

    time_next_event[1] = sim_time + expon(mean_interarrival);

    /* Check to see whether server 1 is busy. */

    if (server1_status == BUSY) {

        /* Server 1 is busy, so increment number of customers in first queue. */

        ++num_in_q1;

        /* Check to see whether an overflow condition exists. */

        if (num_in_q1 > Q_LIMIT) {

            /* The queue has overflowed, so stop the simulation. */
			
            fprintf(outfile, "\nOverflow of the array time_arrival at");
            fprintf(outfile, " time %f", sim_time);
            exit(2);
        }

        /* There is still room in the queue, so store the time of arrival of the
           arriving customer at the (new) end of time_arrival. */

        queue1[num_in_q1] = sim_time;
    }

    else {

        /* Server is idle, so arriving customer has a delay of zero.  (The
           following two statements are for program clarity and do not affect
           the results of the simulation.) */

        delay            = 0.0;
        total_of_delays1 += delay;

        /* Increment the number of customers delayed, and make server busy. */

        ++num_custs_delayed1;
        server1_status = BUSY;

        /* Schedule a a queue change event. */

        time_next_event[2] = sim_time + expon(service_time1);
    }
    
    //printf("ARRIVE1: %d in queue 1 and %d in queue 2, SERVER 1 STATUS: %d and SERVER 2 STATUS: %d, %d in transit\n", num_in_q1, num_in_q2, server1_status, server2_status, num_in_transit);
}
예제 #3
0
void initialize(void)  /* Initialization function. */
{
	int i;

    /* Initialize the simulation clock. */
    sim_time = 0.0;

    /* Initialize the state variables and statistical counters. */
	for (i = 0; i < 2; i++) {
        server_status[i]      = IDLE;		
        num_in_q[i]           = 0;
        area_num_in_q[i]      = 0.0;
        area_server_status[i] = 0.0;
	}

    num_custs_delayed  = 0;
    total_of_delays    = 0.0;
    time_last_event    = 0.0;

    /* Initialize event list.  Since no customers are present, the departure
       (service completion) and tandem switch events are eliminated from consideration. */
    time_next_event[1] = sim_time + expon(mean_interarrival);
    time_next_event[2] = 1.0e+30;
    time_next_event[3] = 1.0e+30;
    time_next_event[4] = 1.0e+30;
    time_next_event[5] = time_end;
}
예제 #4
0
void initialize(void)  /* Initialization function. */
{
    /* Initialize the simulation clock. */

    sim_time = 0.0;

    /* Initialize the state variables. */

    server_status   = IDLE;
    num_in_q        = 0;
    time_last_event = 0.0;

    /* Initialize the statistical counters. */

    num_custs_delayed  = 0;
    total_of_delays    = 0.0;
    area_num_in_q      = 0.0;
    area_server_status = 0.0;

    /* Initialize event list.  Since no customers are present, the departure
       (service completion) event is eliminated from consideration. */

    time_next_event[1] = sim_time + expon(mean_interarrival);
    time_next_event[2] = 1.0e+30;
}
예제 #5
0
/*Departure event function(出発イベント)*/
void depart(void){
    int i;
    float delay;
    
    /*Check to see whether the queue is empty(客が待っているか調べる)*/
    if(num_in_q == 0){
        /*queue is empty so make server idle and eliminate the departure event from consideration
        (待ってる人がいないので店員をヒマにし、出発イベントを無視する)*/
        server_status = IDLE;
        //min_time_next_eventより確実に大きいのでtimingで発生されなくなる
        time_next_event[2]= 1.0e+30;
    }else{
        /*queue is nonempty,(だれかが待っている)
            so decrement the number of customers in queue.(行列から一人減らす)*/
        --num_in_q;
        
        /*Compute the delay of customer who is beginning service and update the total delay accumulator
        (その人が待っていた時間を計算し、総待ち時間を増やす)*/
        delay = sim_clock - time_arrival[1];
        total_of_delays += delay;
        
        /*Increment the number of costomers delayed,(待っていた客の数を増やし)
            and schedule departure.(出発イベントをスケジュールに追加する)*/
        ++num_custs_delayed;
        time_next_event[2] = sim_clock + expon(mean_service);
        
        /*Move each customer in queue (if any) up one place.(待ち行列から客を削除し前につめる)*/
        for(i=1; i <= num_in_q; ++i) time_arrival[i] = time_arrival[i+1];
    }
}
예제 #6
0
void initialize(void)  /* Initialization function. */
{
    /* Initialize the simulation clock. */

    sim_time = 0.0;

    /* Initialize the state variables. */

    inv_level       = initial_inv_level;
    time_last_event = 0.0;

    /* Initialize the statistical counters. */

    total_ordering_cost = 0.0;
    area_holding        = 0.0;
    area_shortage       = 0.0;

    /* Initialize the event list.  Since no order is outstanding, the order-
       arrival event is eliminated from consideration. */

    time_next_event[1] = 1.0e+30;
    time_next_event[2] = sim_time + expon(mean_interdemand);
    time_next_event[3] = num_months;
    time_next_event[4] = 0.0;
}
예제 #7
0
/*Initialization function(初期化)*/
void initialize(void){
    /*Set rondom seed*/
    srand((unsigned int)time(NULL));

    /*Initialize the Simulation sim_clock(シミュレーション内の時計の初期化)*/
    sim_clock = 0.0f;
    
    /*Initialize the state variables(状態の初期化)*/
    server_status   =   IDLE;
    num_in_q        =   0;
    time_last_event =   0.0;
    
    /*Initialize the statical counters(カウンタの初期化)*/
    num_custs_delayed   =   0;
    total_of_delays     =   0.0;
    area_num_in_q       =   0.0;
    area_server_status  =   0.0;
    
    /*Initialize event list.(イベントリストの初期化)
        Since no customers are present,(客が存在しないなら)
        the departure (service completion) event is eliminated from consideration.
        (「departure」イベントは無視する)*/
    time_next_event[1]  =   sim_clock + expon(mean_interarrival);
    /*Guaranteening that first event will be an arrival
    (最初のイベントをArrivalにするために、([timing()]min_time_next_eventより)大きな数を設定しておく)*/
    time_next_event[2]  =   1.0e+30;
    /*if Limit Time Mode, set Time to Simulation end*/
    if(limit_time_mode) time_next_event[3] = time_end;
}
예제 #8
0
	bignum& bignum::power(unsigned short exponent)
	{
		if(sign_)
			sign_ = (exponent & 0x01U) == 0x01U;
		if(value_.any())
		{
			bitset<sizeof(exponent) * 8> expon(exponent);
			
			bits_value result(0x01U);
			bits_value current(value_);
			
			unsigned char prev = 0;
			for(unsigned char i = prev; i < expon.size(); ++i)
			{
				if(expon.test(i))
				{
					auto span = i - prev;
					prev = i;
					for(unsigned char j = 0; j < span; ++j)
						current = multiply(current, current);
					result = multiply(result, current);			
				}
			}
			
			value_ = move(result);
		}
		return *this;
	}
예제 #9
0
void depart(void){ /*Departure event function. */
	int i;
	float delay;

	/* Check to see whether the queue is empty. */
	if(num_in_q == 0){
		/* The queue is empty so make the server idle and eliminate the
		 * departure (service completion) event from consideration. */
		server_status = IDLE;
		time_next_event[2] = 1.0e+30;
	}
	else{
		/* The queue is nonempty, so decrement the number of customers in queue. */
		--num_in_q;

		/* Compute the delay of the customer who is beginning service
		 * and update the total delay of accumulator. */
		delay = sim_time - time_arrival[1];
		total_of_delays += delay;

		/* Increment the number of customers delayed, and schedule departure. */
		++num_custs_delayed;
		time_next_event[2] = sim_time + expon(mean_service);

		/* Move each customer in queue (if any) up one place. */
		for(i = 1; i <= num_in_q; ++i){
			time_arrival[i] = time_arrival[i + 1];
		}
	}
}
예제 #10
0
void initialize(void)  /* Initialization function. */
{
    /* Initialize the simulation clock. */

    sim_time = 0.0;

    /* Initialize the state variables. */

    enc_server_status   = IDLE;
    stor_server_status  = IDLE;
    num_in_enc_q        = 0;
    num_in_stor_q       = 0;
    time_last_event     = 0.0;

    /* Initialize the statistical counters. */

    num_custs_delayed  = 0;
    total_of_delays    = 0.0;
    area_num_in_q      = 0.0;
    area_server_status = 0.0;

    /* Initialize event list.  Since no customers are present, the departure
       (service completion) event is eliminated from consideration.  The end-
       simulation event (type 3) is scheduled for time time_end. */
    time_next_event[0] = time_end+1;
    time_next_event[1] = sim_time + expon(mean_interarrival);
    time_next_event[2] = sim_time + encode_time;
    time_next_event[3] = 
    time_next_event[7] = time_end;
}
예제 #11
0
void arrive2(void) {

	float delay;
	
	
	/* Schedule next arrival from transit. */
	time_next_event[3] = sim_time + uniform(0.0,2.0);

    /* Check to see whether server 2 is busy. */

    if (server2_status == BUSY) {

        /* Server 2 is busy, so increment number of customers in second queue. */

        ++num_in_q2;

        /* Check to see whether an overflow condition exists. */

        if (num_in_q2 > Q_LIMIT) {

            /* The queue has overflowed, so stop the simulation. */

            fprintf(outfile, "\nOverflow of the array time_arrival at");
            fprintf(outfile, " time %f", sim_time);
            exit(2);
        }

        /* There is still room in the queue, so store the time of arrival of the
           arriving customer at the (new) end of time_arrival. */

        queue2[num_in_q2] = sim_time;
    }

    else {

        /* Server is idle, so arriving customer has a delay of zero.  (The
           following two statements are for program clarity and do not affect
           the results of the simulation.) */

        delay            = 0.0;
        total_of_delays2 += delay;

        /* Increment the number of customers delayed, and make server busy. */

        ++num_custs_delayed2;
        server2_status = BUSY;

        /* Schedule a queue departure event. */

        time_next_event[4] = sim_time + expon(service_time2);
    }
    
    num_in_transit -= 1;
     
    
    //printf("ARRIVE2: %d in queue 1 and %d in queue 2, SERVER 1 STATUS: %d and SERVER 2 STATUS: %d, %d in transit\n", num_in_q1, num_in_q2, server1_status, server2_status, num_in_transit);

    
    
}
예제 #12
0
파일: isal.c 프로젝트: gunnarrb/isal
void create_machine_fail_events() {
    int i;
    float a[20],shift_length;
    shift_length = (float)SHIFT_LENGTH;
    int n = failure_nr;
    memset(a,0,20*sizeof(float));
    float span = shift_length / (float)n+1.0;  //max time between machine failures
    float current_span = 0.0;
    int machine;
    float repair_time ;
    float breakdown_time;
	
    for (i = 0;i<n;i++) {

	current_span+=span;
	machine = (int)unirand(1,number_of_machines+1,stream);
	breakdown_time = unirand(0.0,current_span,stream);
	repair_time =(min_machine_repair_time + expon(max_machine_repair_time ,stream))*60.0;
	if (a[machine]<breakdown_time) {  // 
	    a[machine] = breakdown_time+repair_time;
	}
	else { // if breakdown_time clashes with the same machine then let the breakdown happen after the machine goes up again
	    breakdown_time = a[machine] + 1.0;
	    a[machine] = breakdown_time+repair_time;
	}
	transfer[3] = repair_time;
	transfer[4] = (float)machine;
	fail_list[machine-1].downtime+= repair_time;
	fail_list[machine-1].machine_nr++; 
	event_schedule(sim_time + breakdown_time, EVENT_MACHINE_FAILURE );
    }
	
    event_schedule(sim_time + shift_length, EVENT_GENERATE_FAILURES );
}
void demand()
{
	update();
	int dsize;
	dsize=irandi(z);
	//printf("invlev: %d -> %d   dsize: %d\n ",invlev,invlev-dsize,dsize);
	invlev=invlev-dsize;
	tne[2]=time+expon(mdemdt);
	return;
}
예제 #14
0
void demand(void)  /* Demand event function. */
{
    /* Decrement the inventory level by a generated demand size. */

    inv_level -= random_integer(prob_distrib_demand);

    /* Schedule the time of the next demand. */

    time_next_event[2] = sim_time + expon(mean_interdemand);
}
예제 #15
0
/*Arrival event function(到着イベント)*/
void arrival(void){
    float delay;
    
    /*Schedule next arrival(次の到着をスケジュールに追加)*/
    time_next_event[1] = sim_clock + expon(mean_interarrival);
    
    /*Check the whether server is busy(店員が忙しいかどうかチェック)*/
    if(server_status == BUSY){
        /*server is busy, so increment number of customers in queue(店員が忙しいので、待ち行列内の客の数を増やす)*/
        ++num_in_q;
        
        /*Check to see whether an overflow condition status(客があふれていないかチェック)*/
        if(num_in_q > Q_LIMIT){
            /*the queue has overflowed, so stop the simulation(客があふれているのでシミュレーション停止)*/
            fprintf(outfile,"\nOverflow of the array time_arrival at sim_clock %f",sim_clock);
            exit(2);
        }
        
        /*there is still room in the queue,(まだ待ち行列内にいるので)
            so store the sim_clock of arrival of the arriving costomer at the (new) end of time_arrival
            (time_arrivalに客の到着時間を追加する)*/
        time_arrival[num_in_q] = sim_clock;
    
    }else{
        /*server is idle,(店員はヒマ)
            so arriving customer has delay of zero.(なので待ち時間はなし)
            
            the following two statement are for program clarity and do not affect the result of the simulation
            (一応明記しておくが、シミュレーションの結果には影響がない)*/
        delay = 0.0;
        total_of_delays += delay;
        
        /*Increment the number of customers delayed,(待っていた客の数を増やし)
            and make server busy(店員を仕事中にする)*/
        ++num_custs_delayed;
        server_status = BUSY;
        
        /*Schedule a dedeparture(service completion) (出発イベントをスケジュールに追加)*/
        time_next_event[2] = sim_clock + expon(mean_service);
    }
}
예제 #16
0
void queue1_arrival(void)  /* Arrive in the system (queue one) */
{
    float delay;

    /* Schedule next arrival. */
    time_next_event[1] = sim_time + expon(mean_interarrival);

    /* Check to see whether server is busy. */
    if (server_status[0] == BUSY) {
        /* Server is busy, so increment number of customers in the first queue. */
        ++num_in_q[0];

        /* Check to see whether an overflow condition exists. */
        if (num_in_q[0] > Q_LIMIT) {
            /* The queue has overflowed, so stop the simulation. */
            fprintf(outfile, "\nOverflow of the first array time_arrival at");
            fprintf(outfile, " time %f \n\n", sim_time);
            exit(2);
        }

        /* There is still room in the queue, so store the time of arrival of the
           arriving customer at the (new) end of time_arrival. */
        time_arrival[num_in_q[0]] = sim_time;
    }

    else {
        /* Server is idle, so arriving customer has a delay of zero.*/
        delay            = 0.0;
        total_of_delays += delay;

        /* Increment the number of customers delayed, and make server busy. */
        ++num_custs_delayed;
        server_status[0] = BUSY;

        /* Schedule arrival at the second queue */
        time_next_event[2] = sim_time + expon(mean_service[0]);
    }
}
void init()
{
	time=0;         //仿真钟的值 
	invlev=initil;	//动态库存初值(初始库存量) 
	tlevent=0;	    //上一次改变库存水平的时间 
	amount=0;       //订货数量 
	
	tordc=0;        //总订货费用 
	aplus=0;        //I>0时积分值 
	aminus=0;       //I<0时积分值 
	tne[1]=1e+30;   //第一类事件发生时间为无穷大(无订货) 
	tne[2]=expon(mdemdt);//需求到达产生随机数  
	tne[3]=nmnths;       //仿真运行长度(程序事件) 
	tne[4]=0;            //订货时间 
	return;
}
예제 #18
0
void depart1(void)  /* Queue change event function. */
{
    int   i;
    float delay;

    /* Check to see whether the queue is empty. */

    if (num_in_q1 == 0) {

        /* The queue is empty so make the server idle and eliminate the
           departure (service completion) event from consideration. */

        server1_status      = IDLE;
        time_next_event[2] = 1.0e+30;
    }

    else {

        /* The queue is nonempty, so decrement the number of customers in
           queue. */

        --num_in_q1;

        /* Compute the delay of the customer who is beginning service and update
           the total delay accumulator. */

        delay = sim_time - queue1[1];
        total_of_delays1 += delay;

        /* Increment the number of customers delayed, and schedule next change and arrival into second queue. */

        ++num_custs_delayed1;
        time_next_event[2] = sim_time + expon(service_time1);
        time_next_event[3] = sim_time + uniform(0.0,2.0);

        /* Move each customer in queue (if any) up one place. */

        for (i = 1; i <= num_in_q1; ++i)
            queue1[i] = queue1[i + 1];
    }
    
    /* Increment the current number of customers in transit. */
    
    num_in_transit += 1;
    //printf("DEPART1: %d in queue 1 and %d in queue 2, SERVER 1 STATUS: %d and SERVER 2 STATUS: %d, %d in transit\n", num_in_q1, num_in_q2, server1_status, server2_status, num_in_transit);
    
}
예제 #19
0
//===========================================================================
//=  Function to generate Poisson distributed random variables              =
//=    - Input:  Mean value of distribution                                 =
//=    - Output: Returns with Poisson distributed random variable           =
//===========================================================================
int poisson(double x)
{
    int    poi_value;             // Computed Poisson value to be returned
    double t_sum;                 // Time sum value

    // Loop to generate Poisson values using exponential distribution
    poi_value = 0;
    t_sum = 0.0;
    while(1)
    {
        t_sum = t_sum + expon(x);
        if (t_sum >= 1.0) break;
        poi_value++;
    }

    return(poi_value);
}
예제 #20
0
void queue2_arrival(void) /* Arrive at the second queue */
{
	float delay;

	/* Wait for the next arrival afterward*/
	time_next_event[3] = 1.0e+30;

	/* Check to see whether the second server is busy. */
	if (server_status[1] == BUSY) {
		/* Second server is busy, so increment the number of customers in
		 * the second queue. */
		++num_in_q[1];

		if (num_in_q[1] > Q_LIMIT) {
			/* The second queue has overflowed; stop the simulation. */	
            fprintf(outfile, "\nOverflow of the second array time_arrival at");
            fprintf(outfile, " time %f \n\n", sim_time);
            exit(2);
		}

		/* There is still room in the queue, so so store the time of arrival of the
		 * switching customer at the end of the second_time_arrival array.  */
		second_time_arrival[num_in_q[1]] = sim_time;
	}

	else {
		/* Second server is idle; current customer has delay of 0 */
		delay			 = 0.0;
		total_of_delays += delay;

		/* Make second server busy, but do not increment number of customers delayed */
		server_status[1] = BUSY;

		/* Schedule system departure for the current customer*/
		time_next_event[4] = sim_time + expon(mean_service[1]);

		/* FIXME logging to debug file */
		fprintf(debugfile, "SCHEDULING 4 | time:%f\n", time_next_event[4]);
	}
}
예제 #21
0
void initialize(void)  /* Initialization function. */
{
    /* Initialize the simulation clock. */

    sim_time = 0.0;

    /* Initialize the state variables. */

    server1_status  = IDLE;
    server2_status  = IDLE;
    num_in_q1       = 0;
    num_in_q2       = 0;
    
    time_last_event = 0.0;

    /* Initialize the statistical counters. */

    num_custs_delayed1  = 0;
    num_custs_delayed2  = 0;
    total_of_delays1    = 0.0;
    total_of_delays2    = 0.0;
    area_num_in_q1      = 0.0;
    area_num_in_q2      = 0.0;
    area_server_status1 = 0.0;
    area_server_status2 = 0.0;
    num_in_transit = 0;
    max_in_transit = 0;
    total_in_transit = 0;

    /* Initialize event list.  Since no customers are present, the departure
       (service completion) event is eliminated from consideration, as is the
       queue change operation. */

    time_next_event[1] = sim_time + expon(mean_interarrival);
    time_next_event[2] = 1.0e+30;
    time_next_event[3] = 1.0e+30;
    time_next_event[4] = 1.0e+30;
    time_next_event[5] = 1000;
    
}
void arrive(void)  /* Event function for arrival of job at CPU after think
                      time. */
{

    /* Place the arriving job at the end of the CPU queue.
       Note that the following attributes are stored for each job record:
            1. Time of arrival to the computer.
            2. The (remaining) CPU service time required (here equal to the
               total service time since the job is just arriving).*/

    transfer[1] = sim_time;
    transfer[2] = expon(mean_service, STREAM_SERVICE);//TODO nanti ganti sama distribusi yang disebut di spek (belum jelas)
    //jenis job
    int jenis_job;
    if (transfer[2]<=batasatasjob1)
        jenis_job=LIST_QUEUE_1;
    else if (transfer[2]<=batasatasjob2)
        jenis_job=LIST_QUEUE_2;
    else
        jenis_job=LIST_QUEUE_3;
    list_file(LAST, jenis_job); 

    /* If the CPU is idle, start a CPU run. */
    switch(jenis_job){
        case LIST_QUEUE_1:
        if (list_size[LIST_CPU_1] == 0)
            start_CPU_run(jenis_job);
        break;
        case LIST_QUEUE_2:
        if (list_size[LIST_CPU_2] == 0)
            start_CPU_run(jenis_job);
        break;
        case LIST_QUEUE_3:
        if (list_size[LIST_CPU_3] == 0)
            start_CPU_run(jenis_job);
        break;
    }
}
예제 #23
0
void queue1_departure(void) 
{
	int i;
	float delay;

	/* Check to see whether the first queue is empty */
	if (num_in_q[0] == 0) {
		/* The first queue is empty so make the server idle */
		server_status[0]   = IDLE;
		time_next_event[2] = 1.0e+30;
	}
	
	/* Decrement the number of customers in the first queue. */
	else {
		--num_in_q[0];

        /* Compute the delay of the customer who is beginning service and update
           the total delay accumulator. */
        delay            = sim_time - time_arrival[1];
        total_of_delays += delay;

		/* Increment number of customers delayed */
		++num_custs_delayed;
		server_status[0] = BUSY;

		/* Schedule another queue 1 departure and arrival at queue 2 */
		time_next_event[2] = sim_time + expon(mean_service[0]);
		queue2_arrival();

        /* Move each customer in queue (if any) up one place. */
        for (i = 1; i <= num_in_q[0]; ++i)
            time_arrival[i] = time_arrival[i + 1];

		/* FIXME logging to debug file */		
		//fprintf(debugfile, "SCHEDULING 2 | time:%f\n", time_next_event[2]);		
	}

}
예제 #24
0
float encode_time(){
    return capacity_enc/(expon(mean_complex));
}
예제 #25
0
int main(int argc, char* argv[]){
    bind_textdomain_codeset ("calc", "UTF-8");
    setlocale(LC_ALL, "");
    bindtextdomain("calc","idioma");
    textdomain("calc");
    // declaracion de variables locales
    //variable para leer la categoria de funciones
    int categoria;

    //Cambio del manejo de señales, mensaje de error en caso de que no sea posible
	if (signal (SIGINT, myCatch) == SIG_ERR){
		perror ("SIGINT can not change");
	}

    if (signal (SIGSEGV	, myCatch) == SIG_ERR){
		perror ("SIGTERM can not change");
	}

    //Mensaje de bienvenida
    printf(_("\n\nWelcome, you are running a calculator developed by the team Icazas!\n\n"));

    //Ciclo principal
    do{
        //Desplegamos en pantalla el menu de categorias
        mostrarMenu ();

        //Leemos un digito en base 10 de maximo 2 caracteres
        categoria = readInt(10,2);

        //Si el valor leido es un numero evaluamos el menu
        //De lo contrario mostramos mensaje de error
        if (categoria != myNaN ()) {

                //Con la categoria y la operacion elegidas evaluamos la funcion adecuada
                switch (categoria) {
                  case 1: { suma(); break; }
                  case 2: { resta(); break; }
                  case 3: { multiplicacion(); break; }
                  case 4: { division(); break;}
                  case 5: { seno(); break; }
                  case 6: { coseno(); break; }
                  case 7: { tangente(); break; }
                  case 8: { arcoseno(); break; }
                  case 9: { arcoCoseno(); break; }
                  case 10:{ coseno(); break; }
                  case 11:{ senoHiper(); break; }
                  case 12:{ coship(); break; }
                  case 13:{ tangenteHiper(); break; }
                  case 14:{ atanDos(); break; }
                  case 15:{ expon(); break; }
                  case 16:{ logaritmoNatural(); break; }
                  case 17:{ decLog(); break; }
                  case 18:{ raizCuadrada(); break; }
                  case 19:{ potencia(); break; }
                  case 20:{ valorAbsoluto(); break; }
                  case 21:{ fmodd(); break;}
                  case 22:{ funcionTecho(); break;}
                  case 23:{ funcionPiso(); break; }
                  case 24:{ frexpre(); break; }
                  case 25:{ ldexpe(); break;}
                  case 26:{ moduloF(); break;}
                  case 27:{
                      printf(_("\n\nThank you for using our calculator!\n"));
                      printf(_("Come back soon!\n\n"));
                      break;
                  }
                  default:{
                      printf(_("\n\nYou entered an invalid option!\n"));
                      printf(_("Try again!\n\n"));
                      break;
                  }
              }
        }
        else{
            printf(_("\n\nError: It is not a number!\n"));
            printf(_("Try again!\n\n"));
        }
    }while (categoria != 27);
    return 0;
}
예제 #26
0
파일: jobshop.c 프로젝트: gunnarrb/isal
void
arrive (int new_job)		/* Function to serve as both an arrival event of a job
				   to the system, as well as the non-event of a job's
				   arriving to a subsequent station along its
				   route. */
{
    int station;

    /* If this is a new arrival to the system, generate the time of the next
       arrival and determine the job type and task number of the arriving
       job. */


    if (new_job == 1)
    {

        event_schedule (sim_time + expon (mean_interarrival, STREAM_INTERARRIVAL), EVENT_ARRIVAL);
        job_type = intrand (prob_distrib_job_type, STREAM_JOB_TYPE);
        task = 1;
    }

    /* Determine the station from the route matrix. */

    station = route[job_type][task];

    /* Check to see whether all machines in this station are busy. */

    if (num_machines_busy[station] == num_machines[station])
    {

        /* All machines in this station are busy, so place the arriving job at
           the end of the appropriate queue. Note that the following data are
           stored in the record for each job:
           1. Time of arrival to this station.
           2. Job type.
           3. Current task number. */

        transfer[1] = sim_time;
        transfer[2] = job_type;
        transfer[3] = task;
        list_file (LAST, station);
    }

    else
    {

        /* A machine in this station is idle, so start service on the arriving
           job (which has a delay of zero). */

        sampst (0.0, station);	/* For station. */
        sampst (0.0, num_stations + job_type);	/* For job type. */
        ++num_machines_busy[station];
        timest ((double) num_machines_busy[station], station);

        /* Schedule a service completion.  Note defining attributes beyond the
           first two for the event record before invoking event_schedule. */

        transfer[3] = job_type;
        transfer[4] = task;
        event_schedule (sim_time + erlang (2, mean_service[job_type][task], STREAM_SERVICE), EVENT_DEPARTURE);
    }
}
예제 #27
0
파일: jobshop.c 프로젝트: gunnarrb/isal
int
main ()				/* Main function. */
{
    /* Open input and output files. */

    infile = fopen ("jobshop.in", "r");
    outfile = fopen ("jobshop.out", "w");

    /* Read input parameters. */

    fscanf (infile, "%d %d %lg %lg", &num_stations, &num_job_types, &mean_interarrival, &length_simulation);
    for (j = 1; j <= num_stations; ++j)
        fscanf (infile, "%d", &num_machines[j]);
    for (i = 1; i <= num_job_types; ++i)
        fscanf (infile, "%d", &num_tasks[i]);
    for (i = 1; i <= num_job_types; ++i)
    {
        for (j = 1; j <= num_tasks[i]; ++j)
            fscanf (infile, "%d", &route[i][j]);
        for (j = 1; j <= num_tasks[i]; ++j)
            fscanf (infile, "%lg", &mean_service[i][j]);
    }
    for (i = 1; i <= num_job_types; ++i)
        fscanf (infile, "%lg", &prob_distrib_job_type[i]);

    /* Write report heading and input parameters. */

    fprintf (outfile, "Job-shop model\n\n");
    fprintf (outfile, "Number of work stations%21d\n\n", num_stations);
    fprintf (outfile, "Number of machines in each station     ");
    for (j = 1; j <= num_stations; ++j)
        fprintf (outfile, "%5d", num_machines[j]);
    fprintf (outfile, "\n\nNumber of job types%25d\n\n", num_job_types);
    fprintf (outfile, "Number of tasks for each job type      ");
    for (i = 1; i <= num_job_types; ++i)
        fprintf (outfile, "%5d", num_tasks[i]);
    fprintf (outfile, "\n\nDistribution function of job types  ");
    for (i = 1; i <= num_job_types; ++i)
        fprintf (outfile, "%8.3f", prob_distrib_job_type[i]);
    fprintf (outfile, "\n\nMean interarrival time of jobs%14.2f hours\n\n", mean_interarrival);
    fprintf (outfile, "Length of the simulation%20.1f eight-hour days\n\n\n", length_simulation);
    fprintf (outfile, "Job type     Work stations on route");
    for (i = 1; i <= num_job_types; ++i)
    {
        fprintf (outfile, "\n\n%4d        ", i);
        for (j = 1; j <= num_tasks[i]; ++j)
            fprintf (outfile, "%5d", route[i][j]);
    }
    fprintf (outfile, "\n\n\nJob type     ");
    fprintf (outfile, "Mean service time (in hours) for successive tasks");
    for (i = 1; i <= num_job_types; ++i)
    {
        fprintf (outfile, "\n\n%4d    ", i);
        for (j = 1; j <= num_tasks[i]; ++j)
            fprintf (outfile, "%9.2f", mean_service[i][j]);
    }

    /* Initialize rndlib */
    init_twister();

    /* Initialize all machines in all stations to the idle state. */

    for (j = 1; j <= num_stations; ++j)
        num_machines_busy[j] = 0;

    /* Initialize simlib */

    init_simlib ();

    /* Set maxatr = max(maximum number of attributes per record, 4) */

    maxatr = 4;			/* NEVER SET maxatr TO BE SMALLER THAN 4. */

    /* Schedule the arrival of the first job. */

    event_schedule (expon (mean_interarrival, STREAM_INTERARRIVAL), EVENT_ARRIVAL);

    /* Schedule the end of the simulation.  (This is needed for consistency of
       units.) */

    event_schedule (8 * length_simulation, EVENT_END_SIMULATION);

    /* Run the simulation until it terminates after an end-simulation event
       (type EVENT_END_SIMULATION) occurs. */

    do
    {

        /* Determine the next event. */

        timing ();

        /* Invoke the appropriate event function. */

        switch (next_event_type)
        {
        case EVENT_ARRIVAL:
            arrive (1);
            break;
        case EVENT_DEPARTURE:
            depart ();
            break;
        case EVENT_END_SIMULATION:
            report ();
            break;
        }

        /* If the event just executed was not the end-simulation event (type
           EVENT_END_SIMULATION), continue simulating.  Otherwise, end the
           simulation. */

    }
    while (next_event_type != EVENT_END_SIMULATION);

    fclose (infile);
    fclose (outfile);

    return 0;
}
void end_CPU_run(int list_cpu_num)  /* Event function to end a CPU run of a job. */
{
    /* Remove the job from the CPU. */

    list_remove(FIRST, list_cpu_num);

    int jenis_job_queue;
    switch (list_cpu_num){
    case LIST_CPU_1:
        jenis_job_queue=LIST_QUEUE_1;
    break;
    case LIST_CPU_2:
        jenis_job_queue=LIST_QUEUE_2;
    break;
    case LIST_CPU_3:
        jenis_job_queue=LIST_QUEUE_3;
    break;
    }

    /* Check to see whether this job requires more CPU time. */

    if (transfer[2] > 0.0) {

        /* This job requires more CPU time, so place it at the end of the queue
           and start the first job in the queue. */

        list_file(LAST, jenis_job_queue);
        start_CPU_run(jenis_job_queue);
    }

    else {

        /* This job is finished, so collect response-time statistics and send it
           back to its terminal, i.e., schedule another arrival from the same
           terminal. */

        sampst(sim_time - transfer[1], SAMPST_RESPONSE_TIMES);//TODO nanti hapus
        switch(jenis_job_queue){
        case (LIST_QUEUE_1):
            sampst(sim_time - transfer[1], SAMPST_RESPONSE_TIMES_1);
        break;
        case (LIST_QUEUE_2):
            sampst(sim_time - transfer[1], SAMPST_RESPONSE_TIMES_2);
        break;
        case (LIST_QUEUE_3):
            sampst(sim_time - transfer[1], SAMPST_RESPONSE_TIMES_3);
        break;
        }
	

        event_schedule(sim_time + expon(mean_think, STREAM_THINK),
                       EVENT_ARRIVAL); //TODO nanti ganti sama distribusi yang disebut di spek (belum jelas)

        /* Increment the number of completed jobs. */

        ++num_responses;

        /* Check to see whether enough jobs are done. */

        if (num_responses >= num_responses_required)

            /* Enough jobs are done, so schedule the end of the simulation
               immediately (forcing it to the head of the event list). */

            event_schedule(sim_time, EVENT_END_SIMULATION);

        else

            /* Not enough jobs are done; if the queue is not empty, start
               another job. */

            if (list_size[jenis_job_queue] > 0)
                start_CPU_run(jenis_job_queue);
    }
}
int main()  /* Main function. */
{
    printf("Masukkan batas atas job 1 (default: 10): \n");
    scanf("%d", &batasatasjob1);
    printf("\n\nMasukkan batas atas job 2 (default: 40): \n");
    scanf("%d", &batasatasjob2);

    /* Open input and output files. */

    infile  = fopen("tscomp-tugas.in",  "r");
    outfile = fopen("tscomp-tugas.out", "w");

    /* Read input parameters. */

    fscanf(infile, "%d %d %d %d %f %f %f %f",
           &min_terms, &max_terms, &incr_terms, &num_responses_required,
           &mean_think, &mean_service, &quantum, &swap);

    /* Write report heading and input parameters. */

    fprintf(outfile, "Time-shared computer model\n\n");
    fprintf(outfile, "Number of terminals%9d to%4d by %4d\n\n",
            min_terms, max_terms, incr_terms);
    fprintf(outfile, "Mean think time  %11.3f seconds\n\n", mean_think);
    fprintf(outfile, "Mean service time%11.3f seconds\n\n", mean_service);
    fprintf(outfile, "Quantum          %11.3f seconds\n\n", quantum);
    fprintf(outfile, "Swap time        %11.3f seconds\n\n", swap);
    fprintf(outfile, "Number of jobs processed%12d\n\n\n",
            num_responses_required);
    fprintf(outfile, "Number of      Average         Average");
    fprintf(outfile, "       Utilization      CPU-num/\n");
    fprintf(outfile, "terminals   response time  number in queue     of CPU          JOB-type");

    /* Run the simulation varying the number of terminals. */

    for (num_terms = min_terms; num_terms <= max_terms;
         num_terms += incr_terms) {

        /* Initialize simlib */

        init_simlib();

        /* Set maxatr = max(maximum number of attributes per record, 4) */

        maxatr = 4;  /* NEVER SET maxatr TO BE SMALLER THAN 4. */

        /* Initialize the non-simlib statistical counter. */

        num_responses = 0;

        /* Schedule the first arrival to the CPU from each terminal. */

        for (term = 1; term <= num_terms; ++term)
            event_schedule(expon(mean_think, STREAM_THINK), EVENT_ARRIVAL);

        /* Run the simulation until it terminates after an end-simulation event
           (type EVENT_END_SIMULATION) occurs. */

        do {

            /* Determine the next event. */

            timing();

            /* Invoke the appropriate event function. */

            switch (next_event_type) {
                case EVENT_ARRIVAL:
                    arrive();
                    break;
                case EVENT_END_CPU_1_RUN:
                    end_CPU_run(LIST_CPU_1);
                    break;
                case EVENT_END_CPU_2_RUN:
                    end_CPU_run(LIST_CPU_2);
                    break;
                case EVENT_END_CPU_3_RUN:
                    end_CPU_run(LIST_CPU_3);
                    break;
                case EVENT_END_SIMULATION:
                    report();
                    break;
            }

        /* If the event just executed was not the end-simulation event (type
           EVENT_END_SIMULATION), continue simulating.  Otherwise, end the
           simulation. */

        } while (next_event_type != EVENT_END_SIMULATION);
    }

    fclose(infile);
    fclose(outfile);

    printf("\n\nOutput hasil eksekusi program dapat dilihat pada tscomp-tugas.out\n");

    return 0;
}