invcust

Capsim Block Documentation

Short Description

This star generates inventory customers.

Top
Parameters
Num Description Type Name Default Value
0 total number of customers int num_of_samples 128
1 Type:0=exp,1=gamma int type 0
2 Inter Arrival Time float meanArrival 1.0
3 Expression for random number generator file expression any expresssion
4 File with demand probabilities file demandProbDist demand_dist.dat
5 pace rate to determine how many samples to output float pace_rate 1.0
6 number of samples on the first call if paced int samples_first_time 128
Top
States
Num Type Name Initial Value Description
0 int samples_out_total 0
1 double pace_in_total 0.0
2 int output_target NUMBER_SAMPLES_PER_VISIT
3 int no_inbuf
4 int obufs
5 int pass 0
6 long seed1
7 long seed2
8 float* demandProb_P
9 int numberDemandProb
Top

Declarations


 

     int i,j,ok,n;
     int numin;
     int count = 0;
     float	x;
     FILE*	demand_F;
     complex	outSamp;
     int	demand;
     float	u;



Top

Initialization Code



 

	demand_F= fopen(demandProbDist,"r");
	if(demand_F == NULL) {
                fprintf(stderr,"invcust: could not open demand prob. file\n");
                return(1); 
	}
	fscanf(demand_F,"%d",&numberDemandProb);
	demandProb_P = (float*)calloc(numberDemandProb,sizeof(float));	
	if(demandProb_P == NULL) {
                fprintf(stderr,"invcust: could not allocate space\n");
                return(2); 
	}
	for(i=0; i< numberDemandProb; i++) {
		fscanf(demand_F,"%f",&demandProb_P[i]);
	}
	fclose(demand_F);
	if((obufs = NO_OUTPUT_BUFFERS() ) <= 0) {
                fprintf(stderr,"invcust: no output buffers\n");
                return(3); /* no output buffers */
        }
	for(i=0; i num_of_samples)
           output_target = num_of_samples;
   	if(pace_rate < 0) pace_rate = -pace_rate;
	/*
	 * Get seeds from expression
	 */
	phrtsd(expression,&seed1,&seed2);
	fprintf(stderr,"genrad: seed1=%d seed2=%d\n",seed1,seed2);
	setall(seed1,seed2);




Top

Main Code



 


        if(no_inbuf == 1) {
           while(IT_IN(0))
                pace_in_total += 1.0;
           if(pass == 1) {
                output_target = samples_first_time + (int) (pace_rate *
                                pace_in_total + 0.5);
                if(output_target > num_of_samples && num_of_samples > 0)
                       output_target = num_of_samples;
	   }
        }
        pass = 1;
 	i = 0;

       /*
	*  generate NUMBER_SAMPLES samples, then return 
	*/
        while(samples_out_total < output_target) {

                /* 
		 * return if all samples have been output 
		 */
                if((i += 1) > NUMBER_SAMPLES_PER_VISIT) return(0);
  		/*
		 * generate random inter arrival time 
		 */ 
	        switch(type) {
		   case DIST_GAMMA:
			x=gengam(meanArrival,0);
			break;
		   case DIST_EXPONENTIAL:
			x=genexp(meanArrival);
			break;
		}

		/*
		 * generate demand
		 */

		demand=0;
		u=genunf(0.0,1.0);
		for(i=0; i= demandProb_P[i])
				demand=i+1;

		


		samples_out_total += 1;
		
		outSamp.re=x;
		outSamp.im = demand+1;

		/*
		 * output sample auto fan-out
		 */
		for(j=0; j
    
Top

Wrapup Code



 

	fprintf(stderr,"\n\nInventory Customer Mean Arrival Time = %f \n",
					meanArrival);
	fprintf(stderr,"Number of demand sizes = %d \n",
					numberDemandProb);
	fprintf(stderr,"Distribution function of demand sizes\n");
	for(i=0; i< numberDemandProb; i++)
		fprintf(stderr,"%f \n",demandProb_P[i]);




Top

License



/*  Capsim (r) Text Mode Kernel (TMK) Star Library (Blocks)
    Copyright (C) 1989-2017  Silicon DSP Corporation

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    http://www.silicondsp.com
    Silicon DSP  Corporation
    Las Vegas, Nevada
*/


Top

Description



 

/*invcust.s */
/***************************************************************************
                          invcust()
*****************************************************************************
This star generates  inventory customers. 
The customers each have an inter arrival time and a product demand.
The inter arrival time is packaged with the product demand into a complex
data structure and output.
The real part of the complex data structure is the inter arrival time.
The imaginary part is the product demand.
The first parameter, which defaults to NUMBER_SAMPLES, 
tells how many total samples to send out.
CONTROL PARAMETERS:
	num_of_samples     = total number of samples to output.
	pace_rate          = multiplies the number of samples received 
			     on pace input (if connected) to determine 
			     how many samples to output.
	samples_first_time = the number of samples to put out on the
			     first call if pace input connected. It can
			     be zero. negative values = 0.
CONTROL DESCRIPTION:
If the pace input is not connected:
      The num_of_samples parameter sets the maximum number of samples
	that the star will output. If num_of_samples < 0, an indefinite
	number of samples can be output.
      The star will output a maximum of NUMBER_SAMPLES on each call.
If the pace input is connected:
      The num_of_samples parameter sets the maximum number of samples
        that the star will output. If num_samples_out < 0, an infinite
	number of samples can be output.
      The pace input paces the number of output samples on each call.
      At each call of the star all samples are read from the pace input
	and a running total of how many there have been is kept.
      An output_target  is computed at each pass = pace_input_total *
	pace_rate. If pace_rate < 0, the absolute value is used.
      On the first call:
	output = lesser of (samples_first_time, num_of_samples)
      On subsequent calls:
	output = lesser of (NUMBER_SAMPLES, output_target)
	   output_target = samples_first_time +
		 pace_rate * pace_input_total - to that point
      The total number of samples that will be output:
	samples_out_total = lesser of (num_of_samples,
		     samples_first_time + pace_rate * pace_input_total)

invcust


This star generates  inventory customers. 
The customers each have an inter arrival time and a product demand.
The inter arrival time is packaged with the product demand into a complex
data structure and output.
The real part of the complex data structure is the inter arrival time.
The imaginary part is the product demand.
The first parameter, which defaults to NUMBER_SAMPLES, 
tells how many total samples to send out.
CONTROL PARAMETERS:
	num_of_samples     = total number of samples to output.
	pace_rate          = multiplies the number of samples received 
			     on pace input (if connected) to determine 
			     how many samples to output.
	samples_first_time = the number of samples to put out on the
			     first call if pace input connected. It can
			     be zero. negative values = 0.
CONTROL DESCRIPTION:
If the pace input is not connected:
      The num_of_samples parameter sets the maximum number of samples
	that the star will output. If num_of_samples < 0, an indefinite
	number of samples can be output.
      The star will output a maximum of NUMBER_SAMPLES on each call.
If the pace input is connected:
      The num_of_samples parameter sets the maximum number of samples
        that the star will output. If num_samples_out < 0, an infinite
	number of samples can be output.
      The pace input paces the number of output samples on each call.
      At each call of the star all samples are read from the pace input
	and a running total of how many there have been is kept.
      An output_target  is computed at each pass = pace_input_total *
	pace_rate. If pace_rate < 0, the absolute value is used.
      On the first call:
	output = lesser of (samples_first_time, num_of_samples)
      On subsequent calls:
	output = lesser of (NUMBER_SAMPLES, output_target)
	   output_target = samples_first_time +
		 pace_rate * pace_input_total - to that point
      The total number of samples that will be output:
	samples_out_total = lesser of (num_of_samples,
		     samples_first_time + pace_rate * pace_input_total)


Sasan Ardalan

*/