//Jacky: this file along with idcell.org_2006_01_22.cpp is the version based on Lopez's Original version. //But the DRW file generated from the Fire model (30*30 and 15*15) is different from the Lopez's version, //which indicates logic error in this version!!! /******************************************************************* * * DESCRIPTION: class InertialDelayCell * * AUTHOR: Amir Barylko & Jorge Beyoglonian * Version 2: Daniel Rodriguez. * Version 3: Qi (Jacky) Liu * * EMAIL: mailto://amir@dc.uba.ar * mailto://jbeyoglo@dc.uba.ar * mailto://drodrigu@dc.uba.ar * mailto://liuqi@sce.carleton.ca * * DATE: 27/6/1998 * DATE: 17/9/1999 (v2) * DATE: 09/10/2005 (v3) * *******************************************************************/ #ifndef __INERTIAL_DELAY_ATOMIC_CELL_H #define __INERTIAL_DELAY_ATOMIC_CELL_H /** include files **/ #include "atomcell.h" // base class header #include "JackyDebugStream.h" //jacky-debug-mode & jacky-sync /** foward declarations **/ #define INERTIAL_DELAY_CELL_NAME "InertialDelayCell" /** declarations **/ class IDCellState : public AtomicCellState { public: #ifndef JACKY_SYNC map futureValue; map actualValue; #else #ifndef JACKY_PORTIN_FIRST // Nov. 29, 2005 ^^^^^^^^^ Previous Version ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ typedef map StateValues; #else // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Jacky's New Version ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ typedef pair ValueWithFlag; typedef map StateValues; #endif // end JACKY_PORTIN_FIRST ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ StateValues futureValue; StateValues actualValue; #endif #ifdef JACKY_SYNC //============================ VTime recordTime; StateValues recordActual; AtomicState::State recordState; #ifdef JACKY_STATE_VAR // [2006-01-10] /////////////////////////////////////////////////////////////// //add a StateVars here to record the values of the state variables at the beginning of Round 0 //[see macro JACKY_STATE_VAR in JackyDebugStream.h for more information] StateVars vars_round0; #endif //end JACKY_STATE_VAR ///////////////////////////////////////////////////////////////////////// #ifdef JACKY_IDCELL //[2006-01-16] ````````````````````````````````````````````````` //this is to record the delay of the cell when it first enters R0 at a given time //[see "change back" in idcell.cpp for further information.] VTime recordDelay; #endif //end JACKY_IDCELL ````````````````````````````````````````````````````````` #endif //end JACKY_SYNC ======================== IDCellState(){}; virtual ~IDCellState(){}; IDCellState& operator=(IDCellState& thisState); //Assignment #ifndef JACKY_REVISION //original version ========================== void copyState(IDCellState *); #else //This is Jacky's revision 10-17-2005 ======================== void copyState(BasicState *); #endif //=========================================================== int getSize() const; bool isAtomic(); bool isAtomic() const; #ifdef JACKY_DEBUG //Jacky: this function will be defined in all state classes for ParallelProcesses & Models // to show (print) the content of the state for debugging purpose virtual void showStateContent( ostream& ) const; void showActualValues( ostream& ) const; void showFutureValues( ostream& ) const; void showRecordActualValues( ostream& ) const; #endif }; #ifdef JACKY_DEBUG //======================================================================== inline void IDCellState::showActualValues( ostream& out ) const{ out << "\t\t ActualValues -> " << flush; IDCellState::StateValues::const_iterator it = actualValue.begin(); for( ; it != actualValue.end(); it++){ #ifndef JACKY_PORTIN_FIRST // Nov. 29, 2005 ^^^^^^^^^ Previous Version ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out << "<" << it->first << " = " << (it->second).value() << "> " << flush; #else // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Jacky's New Version ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out << "<" << it->first << " = " << (it->second).first.value() << flush; if( (it->second).second == true ){ out << " / flag = TRUE>" << flush; } else { out << " / flag = FALSE>" << flush; } #endif // end JACKY_PORTIN_FIRST ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ } out << endl << flush; } inline void IDCellState::showFutureValues( ostream& out ) const{ out << "\t\t FutureValues -> " << flush; IDCellState::StateValues::const_iterator it = futureValue.begin(); for( ; it != futureValue.end(); it++){ #ifndef JACKY_PORTIN_FIRST // Nov. 29, 2005 ^^^^^^^^^ Previous Version ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out << "<" << it->first << " = " << (it->second).value() << "> " << flush; #else // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Jacky's New Version ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out << "<" << it->first << " = " << (it->second).first.value() << flush; if( (it->second).second == true ){ out << " / flag = TRUE>" << flush; } else { out << " / flag = FALSE>" << flush; } #endif // end JACKY_PORTIN_FIRST ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ } out << endl << flush; } inline void IDCellState::showRecordActualValues( ostream& out ) const{ out << "\t\t RA -> " << flush; IDCellState::StateValues::const_iterator it = recordActual.begin(); for( ; it != recordActual.end(); it++){ #ifndef JACKY_PORTIN_FIRST // Nov. 29, 2005 ^^^^^^^^^ Previous Version ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out << "<" << it->first << " = " << (it->second).value() << "> " << flush; #else // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Jacky's New Version ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out << "<" << it->first << " = " << (it->second).first.value() << flush; if( (it->second).second == true ){ out << " / flag = TRUE>" << flush; } else { out << " / flag = FALSE>" << flush; } #endif // end JACKY_PORTIN_FIRST ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ } out << endl << flush; } inline void IDCellState::showStateContent( ostream& out) const{ //1> first call the counterpart function in the base class AtomicCellState::showStateContent(out); //2> show content defined in this class out << "\t\tIDCellState : " << endl << flush; showActualValues( out ); showFutureValues( out ); out << "\t\t RT = " << recordTime.asString() << " / RS = " << flush; if( recordState == AtomicState::active ){ out << "active" << endl << flush; } else if( recordState == AtomicState::passive ){ out << "passive" << endl << flush; } #ifdef JACKY_IDCELL //[2006-01-16]`````````````````````````````````````````````` out << "\t\t RD = " << recordDelay.asString() << endl << flush; #endif //end JACKY_IDCELL `````````````````````````````````````````````````````` showRecordActualValues( out ); #ifdef JACKY_STATE_VAR // [2006-01-10] ///////////////////////////////////////// //show the state variables in the AtomicCellState out << "\t[2006-01-10] State Variables in AtomicCellState = " << variables.asString() << endl << flush; //show the recorded values of these state variables out << "\t[2006-01-10] Recorded State Variables in IDCellState = " << vars_round0.asString() << endl << flush; #endif // end JACKY_STATE_VAR ////////////////////////////////////////////////// } #endif //end JACKY_DEBUG =================================================================== class InertialDelayCell: public AtomicCell { public: InertialDelayCell( const CellPosition& cellPos, const string &name = INERTIAL_DELAY_CELL_NAME , const LocalTransAdmin::Function &fn = LocalTransAdmin::InvalidFn ) : AtomicCell( cellPos, name, fn ) {} string className() const {return INERTIAL_DELAY_CELL_NAME;} protected: Model &initFunction(); Model &internalFunction( const InternalMessage & ); Model &externalFunction( const MessageBag & ) ; Model &outputFunction( const CollectMessage & ); ModelState* allocateState() { return new IDCellState;} void initializeCell(); private: Real futureValue( const string& ) const; #ifndef JACKY_PORTIN_FIRST // Nov. 29, 2005 ^^^^^^^^^ Previous Version ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ void futureValue( const string&, const Real& ); #else // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Jacky's New Version ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bool futureValueFlag( const string& ) const; void futureValue( const string&, const Real&, const bool &flag = false ); #endif // end JACKY_PORTIN_FIRST ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Real actualValue( const string& ) const; #ifndef JACKY_PORTIN_FIRST // Nov. 29, 2005 ^^^^^^^^^ Previous Version ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ void actualValue( const string&, const Real& ); #else // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Jacky's New Version ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bool actualValueFlag( const string& ) const; void actualValue( const string&, const Real&, const bool &flag = false ); void resetValueFlags( IDCellState::StateValues & ); #endif // end JACKY_PORTIN_FIRST ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #ifdef JACKY_DEBUG void printValues(const IDCellState::StateValues &, ostream &) const; #endif //end JACKY_DEBUG #ifdef JACKY_SYNC //==================================================== //function to get/set the RT (recordTime) in the state const VTime &getRecordTime() const; void setRecordTime( const VTime& ); //function to get/set the RS (recordState) in the state const AtomicState::State &getRecordState() const; void setRecordState( const AtomicState::State& ); //function to get/set the value in the RA (recordActual) in the state Real getRecordActual( const string& ) const; #ifndef JACKY_PORTIN_FIRST // Nov. 29, 2005 ^^^^^^^^^ Previous Version ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ void setRecordActual( const string&, const Real& ); #else // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Jacky's New Version ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ void setRecordActual( const string&, const Real&, const bool &flag = false ); #endif // end JACKY_PORTIN_FIRST ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //function to get the recordActual in the state IDCellState::StateValues &recordActualVal() const; //function to get the actualValue in the state IDCellState::StateValues &actualMap() const; //function to get the futureValue in the state IDCellState::StateValues &futureMap() const; #ifdef JACKY_STATE_VAR // [2006-01-10] ////////////////////////////////////////////////////////////////////// //get the StateVars in the AtomicCellState class StateVars &cellStateVariables(); //get the StateVars in the IDCellState class, which is a record of the StateVars in AtomicCellState // at the beginning of Round 0 StateVars &recordStateVariables(); #endif //end JACKY_STATE_VAR ///////////////////////////////////////////////////////////////////////////////// #ifdef JACKY_IDCELL //[2006-01-16] ````````````````````````````````````````````````` //this is to record the delay of the cell when it first enters R0 at a given time //[see "change back" in idcell.cpp for further information.] VTime &getRecordDelay() const; void setRecordDelay(const VTime&); #endif //end JACKY_IDCELL ````````````````````````````````````````````````````````` #endif //end JACKY_SYNC ================================================= #ifdef JACKY_DEBUG //this is the number to record the number of the Round in the multiple-round message passing int roundNum; #endif //end JACKY_DEBUG } ; // InertialDelayCell /** inline **/ #ifdef JACKY_SYNC //===================================================== inline const VTime &InertialDelayCell::getRecordTime() const{ return ((IDCellState*)getCurrentState())->recordTime; } inline void InertialDelayCell::setRecordTime( const VTime& newTime){ ((IDCellState*)getCurrentState())->recordTime = newTime; } inline const AtomicState::State &InertialDelayCell::getRecordState() const{ return ((IDCellState*)getCurrentState())->recordState; } inline void InertialDelayCell::setRecordState( const AtomicState::State& newState){ ((IDCellState*)getCurrentState())->recordState = newState; } #ifndef JACKY_PORTIN_FIRST // Nov. 29, 2005 ^^^^^^^^^ Previous Version ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ inline Real InertialDelayCell::getRecordActual( const string &port ) const{ return ((IDCellState*)getCurrentState())->recordActual[port]; } inline void InertialDelayCell::setRecordActual( const string &port, const Real &r ){ ((IDCellState*)getCurrentState())->recordActual[port] = r; } #else // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Jacky's New Version ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ inline Real InertialDelayCell::getRecordActual( const string &port ) const{ return (((IDCellState*)getCurrentState())->recordActual[port]).first; } inline void InertialDelayCell::setRecordActual( const string &port, const Real &r, const bool &flag ){ (((IDCellState*)getCurrentState())->recordActual[port]).first = r; (((IDCellState*)getCurrentState())->recordActual[port]).second = flag; } #endif // end JACKY_PORTIN_FIRST ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ inline IDCellState::StateValues &InertialDelayCell::recordActualVal() const { return ((IDCellState*)getCurrentState())->recordActual; } inline IDCellState::StateValues &InertialDelayCell::actualMap() const { return ((IDCellState*)getCurrentState())->actualValue; } inline IDCellState::StateValues &InertialDelayCell::futureMap() const { return ((IDCellState*)getCurrentState())->futureValue; } #ifdef JACKY_STATE_VAR // [2006-01-10] ////////////////////////////////////////////////////////////////////// //get the StateVars in the AtomicCellState class inline StateVars &InertialDelayCell::cellStateVariables(){ return ((IDCellState*)getCurrentState())->variables; } //get the StateVars in the TDCellState class, which is a record of the StateVars in AtomicCellState //at the beginning of Round 0 inline StateVars &InertialDelayCell::recordStateVariables(){ return ((IDCellState*)getCurrentState())->vars_round0; } #endif //end JACKY_STATE_VAR ///////////////////////////////////////////////////////////////////////////////// #ifdef JACKY_IDCELL //[2006-01-16] ``````````````````````````````````````````````````````````````````````````` //get the delay recorded whenever ther is a time change and the cell's phase is Active inline VTime &InertialDelayCell::getRecordDelay() const { return ((IDCellState*)getCurrentState())->recordDelay; } //record the value of the delay whenever there is a time change and the cell's phase is Active inline void InertialDelayCell::setRecordDelay( const VTime &delay ){ ((IDCellState*)getCurrentState())->recordDelay = delay; } #endif //end JACKY_IDCELL ``````````````````````````````````````````````````````````````````````````````````` #endif //end JACKY_SYNC ================================================== #ifndef JACKY_PORTIN_FIRST // Nov. 29, 2005 ^^^^^^^^^ Previous Version ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ inline Real InertialDelayCell::futureValue(const string &port) const { return ((IDCellState*)getCurrentState())->futureValue[port]; } inline void InertialDelayCell::futureValue (const string &port, const Real &r) { ((IDCellState*)getCurrentState())->futureValue[port] = r; } inline Real InertialDelayCell::actualValue(const string &port) const { return ((IDCellState*)getCurrentState())->actualValue[port]; } inline void InertialDelayCell::actualValue (const string &port, const Real& r) { ((IDCellState*)getCurrentState())->actualValue[port] = r; } #else // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Jacky's New Version ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ inline Real InertialDelayCell::futureValue(const string &port) const { return (((IDCellState*)getCurrentState())->futureValue[port]).first; } //Nov. 29, 2005 //function to get the flag value for the value of the given port inline bool InertialDelayCell::futureValueFlag( const string &port ) const{ return (((IDCellState*)getCurrentState())->futureValue[port]).second; } inline void InertialDelayCell::futureValue (const string &port, const Real &r, const bool &flag) { (((IDCellState*)getCurrentState())->futureValue[port]).first = r; (((IDCellState*)getCurrentState())->futureValue[port]).second = flag; } inline Real InertialDelayCell::actualValue(const string &port) const { return (((IDCellState*)getCurrentState())->actualValue[port]).first; } //Nov. 29, 2005 //function to get the flag value for the value of the given port inline bool InertialDelayCell::actualValueFlag( const string &port ) const{ return (((IDCellState*)getCurrentState())->actualValue[port]).second; } inline void InertialDelayCell::actualValue (const string &port, const Real &r, const bool &flag) { (((IDCellState*)getCurrentState())->actualValue[port]).first = r; (((IDCellState*)getCurrentState())->actualValue[port]).second = flag; } #endif // end JACKY_PORTIN_FIRST ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #endif // __INERTIAL_DELAY_ATOMIC_CELL_H