-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerat.cpp
More file actions
103 lines (89 loc) · 2.66 KB
/
generat.cpp
File metadata and controls
103 lines (89 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*******************************************************************
*
* DESCRIPTION: class Generator
*
* AUTHOR: Khaldoon Al-zoubi
*
* DATE: 29/11/2003
*
*******************************************************************/
/** include files **/
#include "generat.h" // base header
#include "message.h" // class InternalMessage
#include "mainsimu.h" // class Simulator
#include "distri.h" // class Distribution
#include "strutil.h" // str2Value( ... )
/*******************************************************************
* Function Name: Generator
* Description: constructor
********************************************************************/
Generator::Generator( const string &name )
: Atomic( name )
, out( addOutputPort( "out" ) )
{
try
{
dist = Distribution::create( MainSimulator::Instance().getParameter( description(), "distribution" ) );
MASSERT( dist ) ;
for ( register int i = 0; i < dist->varCount(); i++ )
{
string parameter( MainSimulator::Instance().getParameter( description(), dist->getVar( i ) ) ) ;
dist->setVar( i, str2Value( parameter ) ) ;
}
} catch( InvalidDistribution &e )
{
e.addText( "The model " + description() + " has distribution problems!" ) ;
e.print(cerr);
MTHROW( e ) ;
} catch( MException &e )
{
MTHROW( e ) ;
}
}
/*******************************************************************
* Function Name: initFunction
********************************************************************/
Model &Generator::initFunction()
{
customer_id = 0;
customers = 0;
holdIn( active, Time::Zero);
return *this;
}
/*******************************************************************
* Function Name: internalFunction
********************************************************************/
Model &Generator::internalFunction( const InternalMessage & )
{
static double all_customers;
if (customers == 0)
{
customers = fabs( distribution().get() ); // get customers for next time unit
all_customers = customers;
}
if (customers > 0)
holdIn( active, Time(0,0,0,1000/all_customers) );
else // nobody has come
holdIn( active, Time(0,0,1,0) ); // sleep until next time unit.
return *this ;
}
/*******************************************************************
* Function Name: outputFunction
********************************************************************/
Model &Generator::outputFunction( const InternalMessage &msg )
{
if (customers > 0)
{
customer_id++;
sendOutput( msg.time(), out, customer_id);
customers--;
} // if
return *this ;
}
/*******************************************************************
* Function Name:
********************************************************************/
Generator::~Generator()
{
delete dist;
}