-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerat.cpp
More file actions
144 lines (126 loc) · 4.25 KB
/
generat.cpp
File metadata and controls
144 lines (126 loc) · 4.25 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*******************************************************************
*
* DESCRIPTION: class Generator
*
* AUTHOR: Amir Barylko & Jorge Beyoglonian
* v2: Alejandro Troccoli
*
* EMAIL: mailto://amir@dc.uba.ar
* mailto://jbeyoglo@dc.uba.ar
* mailto://atroccol@dc.uba.ar
*
* DATE: 27/6/1998
* 01/02/2001
*
*******************************************************************/
/** include files **/
#include "generat.h" // base header
#include "message.h" // class InternalMessage
#include "parsimu.h" // class Simulator
#include "distri.h" // class Distribution
#include "strutil.h" // str2Value( ... )
using namespace std;
/*******************************************************************
* CLASS GeneratorState
*********************************************************************/
/*******************************************************************
* Function Name: operator =
*********************************************************************/
GeneratorState& GeneratorState::operator=(GeneratorState& thisState) {
(AtomicState &)*this = (AtomicState &) thisState;
this->pid = thisState.pid;
return *this;
}
/*******************************************************************
* Function Name: copyState
*********************************************************************/
void GeneratorState::copyState(GeneratorState *rhs) {
*this = *((GeneratorState *) rhs);
}
/*******************************************************************
* Function Name: getSize
*********************************************************************/
int GeneratorState::getSize() const {
return sizeof( GeneratorState );
}
/*******************************************************************
* CLASS Generator
*********************************************************************/
/*******************************************************************
* Function Name: Generator
* Description: constructor
********************************************************************/
Generator::Generator( const string &name )
: Atomic( name )
, out( addOutputPort( "out" ) )
{
try
{
dist = Distribution::create( ParallelMainSimulator::Instance().getParameter( description(), "distribution" ) );
MASSERT( dist ) ;
for ( register int i = 0; i < dist->varCount(); i++ )
{
string parameter( ParallelMainSimulator::Instance().getParameter( description(), dist->getVar( i ) ) ) ;
dist->setVar( i, str2Value( parameter ) ) ;
}
if( ParallelMainSimulator::Instance().existsParameter( description(), "initial" ) )
initial = str2Int( ParallelMainSimulator::Instance().getParameter( description(), "initial" ) );
else
initial = 0;
if( ParallelMainSimulator::Instance().existsParameter( description(), "increment" ) )
increment = str2Int( ParallelMainSimulator::Instance().getParameter( description(), "increment" ) );
else
increment = 1;
} 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()
{
pid ( initial );
holdIn( AtomicState::active, VTime::Zero ) ;
return *this ;
}
/*******************************************************************
* Function Name: internalFunction
********************************************************************/
Model &Generator::internalFunction( const InternalMessage & )
{
#ifdef DEVS_DELAY_INTERNAL
string a;
for (int i = 1; i < 100000; i++ ) {
if ( a.length() > 100 )
a = "";
else
a += i;
}
#endif
#ifndef DEVS_NOTRANDOM
holdIn( AtomicState::active, VTime( static_cast< float >( fabs(distribution().get() ) ) ) ) ;
#else
holdIn( AtomicState::active, VTime( 0,0,10,0 ) ) ;
#endif
return *this ;
}
/*******************************************************************
* Function Name: outputFunction
********************************************************************/
Model &Generator::outputFunction( const CollectMessage &msg )
{
sendOutput( msg.time(), out, pid() ) ;
pid( pid() + increment);
return *this ;
}
Generator::~Generator()
{
delete dist;
}