-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidcell.cpp
More file actions
240 lines (190 loc) · 7.32 KB
/
idcell.cpp
File metadata and controls
240 lines (190 loc) · 7.32 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*******************************************************************
*
* DESCRIPTION: class InertialDelayCell
*
* AUTHOR: Amir Barylko & Jorge Beyoglonian
* Version 2: Daniel Rodriguez.
* Version 3: Gabriel Wainer
* Version 4: Alejandro Troccoli
*
* EMAIL: mailto://amir@dc.uba.ar
* mailto://jbeyoglo@dc.uba.ar
* mailto://drodrigu@dc.uba.ar
* mailto://gabrielw@dc.uba.ar
*
* DATE: 27/6/1998
* DATE: 17/9/1999 (v2)
*
*******************************************************************/
// ** include files **//
#include "idcell.h" // header class
#include "message.h" // ExternalMessage
#include "coupcell.h" // CoupledCell
#include "realfunc.h" // calculateWithQuantum
using namespace std;
/***************************************
* INERTIAL DELAY CELL STATE
***************************************/
/***************************************
* Method: operator=
***************************************/
IDCellState &IDCellState::operator=(IDCellState& thisState)
{
(AtomicCellState &)*this = (AtomicCellState &)thisState;
actualValue = thisState.actualValue;
futureValue = thisState.futureValue;
return *this;
}
/***************************************
* Method: copyState
***************************************/
void IDCellState::copyState(IDCellState *thisState)
{
*this = *(IDCellState *) thisState;
}
/***************************************
* Method: getSize()
***************************************/
int IDCellState::getSize() const
{
return sizeof(IDCellState);
}
/***************************************
* INERTIAL DELAY CELL
***************************************/
/*******************************************************************
* Method: initializeCell
********************************************************************/
void InertialDelayCell::initializeCell()
{
AtomicCell::initializeCell();
//This function requires the cell state to be already created.
if ( UseQuantum().Active() )
QuantumValue( Real(UseQuantum().Value()) );
}
/*******************************************************************
* Method: externalFunction
********************************************************************/
Model &InertialDelayCell::externalFunction( const MessageBag &msgs )
{
//This function must be called before processing any messages!
//It is this function who will set the neighborhood value
//correctly
localTransitionConfluent( msgs );
//This is should be removed once the new Cell Devs definition language is
//approved and considers multiple messages from external models
bool executedLocal = false;
VTime delay( static_cast<const CoupledCell*>( parent() )->defaultDelay() ) ;
VTime actualTime( msgs.time() );
list<PortValue> tv;
//////////////////////////////////////////////////////////////////////
//Right now, for this implementation, give priority to portInTransitions
//This should be changed!!
for ( MessageBag::iterator cursor = msgs.begin(); cursor != msgs.end();
cursor++)
{
ExternalMessage msg = *((ExternalMessage *)(*cursor));
if (!isInNCPort(msg.port().name())) {
MASSERTMSG( executedLocal == false, "Current implementation can not handle multiple messages from external models!!");
string functionName = inputPortFunction()[ msg.port().name() ];
if (functionName == DEFAULT_FUNCTION_InPort) {
PortValue pv(msg.port().name(), msg.value());
tv.push_back(pv);
} else { // sino es un PortInTransition valido
VirtualPortList *vpl = new VirtualPortList;
getOutPorts(vpl);
tv = SingleLocalTransAdmin::Instance().evaluate( functionName, neighborhood(), &(inputPortValues()), delay, actualTime, vpl, this, msg.port().name() ) ;
delete vpl;
}//if
executedLocal = true;
}//if
}//for
if ( !executedLocal ) {
VirtualPortList *vpl = new VirtualPortList;
getOutPorts(vpl);
tv = SingleLocalTransAdmin::Instance().evaluate( localFunction(), neighborhood(), NULL, delay, actualTime, vpl, this ) ;
delete vpl;
}
//cout << " Quantum : " << QuantumValue().value() << endl;
//cout << " ActualValue : " << actualValue().value() << " with q " << valueWithQuantum(actualValue(), QuantumValue()) << endl;
//cout << " New value : " << tv << " with q " << valueWithQuantum(tv, QuantumValue()) << endl;
list<PortValue>::iterator pvCursor;
for (pvCursor = tv.begin(); pvCursor != tv.end(); pvCursor++)
{
if( (UseQuantum().Active() || UseDynQuantum().Active()) &&
(valueWithQuantum(pvCursor->second, QuantumValue()) != valueWithQuantum(actualValue(pvCursor->first), QuantumValue()) )
|| ( !UseQuantum().Active() && (actualValue(pvCursor->first) != pvCursor->second ) ) )
{
actualValue ( pvCursor->first, pvCursor->second ); /* El nuevo estado es el recien calculado */
if( state() == AtomicState::passive )
holdIn( AtomicState::active, delay ) ;
else
// the coupled sets sigma to the reminder time until the next internal transition
if( VTime::Zero < nextChange() && futureValue(pvCursor->first) != pvCursor->second)
holdIn( AtomicState::active, delay ) ;
futureValue( pvCursor->first, pvCursor->second);
}
//If using DynamicQuantum, calculate the new Quantum value.
if ( UseDynQuantum().Active() )
{
if ( valueWithQuantum(pvCursor->second,QuantumValue()) == valueWithQuantum(actualValue(pvCursor->first), QuantumValue()))
{
if ( UseDynQuantum().Strat() )
QuantumValue ( QuantumValue() * (1-UseDynQuantum().Ratio()));
else
QuantumValue ( QuantumValue() * (1+UseDynQuantum().Ratio()));
}
//GW
// Esta es una nueva modificacion: si son distintos, lo reduzco.
else
{
if ( !UseDynQuantum().Strat() )
QuantumValue ( QuantumValue() * (1-UseDynQuantum().Ratio()));
else
QuantumValue ( QuantumValue() * (1+UseDynQuantum().Ratio()));
}
//cout << " q act = " << QuantumValue().value() << endl;
}
} // for
return *this ;
}
/*******************************************************************
* Method: initFunction
* Description:
********************************************************************/
Model &InertialDelayCell::initFunction()
{
PortList::iterator cursor;
//To start the simulation, send an output message with the current
//value and passivate. Model will become active on processing the
//outputs from the other cells.
for (cursor = outNCPortList().begin(); cursor != outNCPortList().end(); cursor++) {
string out_port(cursor->second->name());
string in_port(calculateInPort(out_port));
actualValue( out_port, value(in_port) );
futureValue( out_port, value(in_port) );
}
holdIn( AtomicState::active, VTime::Zero);
return *this;
}
/*******************************************************************
* Method: outputFunction
********************************************************************/
Model &InertialDelayCell::outputFunction( const CollectMessage &msg )
{
PortList::iterator cursor;
for (cursor = outNCPortList().begin(); cursor != outNCPortList().end(); cursor++) {
string out_port(cursor->second->name());
string in_port(calculateInPort(out_port));
sendOutput( msg.time(), outputPort(out_port), actualValue(in_port).value() );
}
return *this;
}
/*******************************************************************
* Method: internalFunction
********************************************************************/
Model &InertialDelayCell::internalFunction( const InternalMessage &msg )
{
passivate();
return *this;
}