-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoupled.cpp
More file actions
101 lines (82 loc) · 3.09 KB
/
coupled.cpp
File metadata and controls
101 lines (82 loc) · 3.09 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
/*******************************************************************
*
* DESCRIPTION: class Coupled
*
* AUTHOR: Amir Barylko & Jorge Beyoglonian
* VERSION 2: Daniel Rodriguez]
* VERSION 3: Alejandro Troccoli
*
* EMAIL: mailto://amir@dc.uba.ar
* mailto://jbeyoglo@dc.uba.ar
* mailto://drodrigu@dc.uba.ar
* mailto://atrocol@dc.uba.ar
*
* DATE: 27/6/1998
* DATE: 27/2/1999 (v2)
* DATE: 9/1/2000 (v3)
*
*******************************************************************/
/** include files **/
#include <algorithm>
#include "coupled.h" // base header
#include "pmodeladm.h" // SingleParallelModelAdm
using namespace std;
/** public functions **/
/*******************************************************************
* Function Name: addModel
* Description: add a model to the list of children
********************************************************************/
Model &Coupled::addModel( Model &mod )
{
mod.parent( this );
//These two lines might be obsolete and could be removed.
ModelList::iterator cursor = find_if( childs.begin(), childs.end(), bind2nd( greater<ModelId>(), mod.id() ) );
childs.insert( cursor, mod.id() );
//Add a new model. The insertion must be ordered by ModelId.
//When creating cellular models, dependants are not added in the same order
//they are created and the ModelId sorting serves to keep the select
//clause working. If the DEVS select clause becomes obsolete, ordered
//insertion can be removed.
PModelList::iterator cursor2;
for ( cursor2 = pchilds.begin();
cursor2 != pchilds.end() && (*cursor2)->id() < mod.id();
cursor2++ );
pchilds.insert( cursor2, &mod );
return *this;
}
/*******************************************************************
* Function Name: addInfluence
* Description: add a link between two ports
********************************************************************/
Model &Coupled::addInfluence( const string &sourceName, const string &sourcePort, const string &destName, const string &destPort)
{
Port &port1( SingleParallelModelAdm::Instance().model( sourceName ).port( sourcePort ) );
Port &port2( SingleParallelModelAdm::Instance().model( destName ).port( destPort ) );
port1.addInfluence( port2 );
return *this;
}
/*******************************************************************
* Function Name: totalProcCount
********************************************************************/
unsigned long Coupled::totalProcCount() const
{
unsigned long count = 0;
PModelList::const_iterator cursor;
for ( cursor = pchilds.begin(); cursor != pchilds.end() ; cursor++ )
count += (*cursor)->totalProcCount();
count += modelPartition().size();
return count;
}
/*******************************************************************
* Function Name: localProcCount
********************************************************************/
unsigned long Coupled::localProcCount() const
{
unsigned long count = 0;
PModelList::const_iterator cursor;
for ( cursor = pchilds.begin(); cursor != pchilds.end() ; cursor++ )
count += (*cursor)->localProcCount();
if ( localProc() != ParallelProcessor::InvalidId )
count++;
return count;
}