File: Generator.cpp

package info (click to toggle)
vite 1.2%2Bsvn1430-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 20,164 kB
  • ctags: 3,915
  • sloc: cpp: 26,903; makefile: 455; sh: 111; ansic: 67
file content (254 lines) | stat: -rw-r--r-- 6,556 bytes parent folder | download | duplicates (4)
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#include "Generator.hpp"
#include <iostream>
#include <math.h>

Generator::Generator (QString name,
                      int depth, int procNbr, int nbrOfState, int nbrOfLine, 
                      int countNbr, int eventNbr, int linkNbr,
                      int eventTypeNbr, int linkTypeNbr,
                      bool paje, bool otf, bool tau){

    _name          = name        ;
    _depth         = depth       ;
    _procNbr       = procNbr     ;
    _numberOfState = nbrOfState  ;
    _numberOfLine  = nbrOfLine   ;
    _counterNbr    = countNbr    ;
    _eventNbr      = eventNbr    ;
    _linkNbr       = linkNbr     ; 
    _eventTypeNbr  = eventTypeNbr;
    _linkTypeNbr   = linkTypeNbr ;
    _paje          = paje        ;
    _otf           = otf         ;
    _tau           = tau         ;


    _arrayOfValues = new int[TYPEACTION];
    int pos = 0;
    _arrayOfValues[pos] = CHANGESTATE;
    pos ++;
    if (linkNbr){
        _arrayOfValues[pos] = STARTLINK;
        pos ++;
        _arrayOfValues[pos] = ENDLINK;
        pos ++;
    }
    if (countNbr){
        _arrayOfValues[pos] = INCCPT;
        pos ++;
        _arrayOfValues[pos] = DECCPT;
        pos ++;
    }
    if (eventNbr){
        _arrayOfValues[pos] = EVENT;
        pos ++;
    }
    _numberAction = pos;
    fprintf (stderr, "Valeur de nb action = %d \n", _numberAction);


    if (paje)
        _pajeGen = new PajeGenerator ();
    if (otf)
        _otfGen  = new OTFGenerator  ();
    if (tau)
        _tauGen  = new TauGenerator  ();

}

Generator::~Generator (){
    if (_pajeGen)
        delete _pajeGen;
    _pajeGen = NULL;
    if (_tauGen)
        delete _tauGen;
    _tauGen = NULL;
    if (_otfGen)
        delete _otfGen;
    _otfGen = NULL;
}

void Generator::initTrace (QString name, int depth, int procNbr, int stateTypeNbr, int eventTypeNbr, int linkTypeNbr, int varNbr){
    if (_paje)
        _pajeGen->initTrace (name, depth, procNbr, stateTypeNbr, eventTypeNbr, linkTypeNbr, varNbr);
    if (_tau)
        _tauGen->initTrace  (name, depth, procNbr, stateTypeNbr, eventTypeNbr, linkTypeNbr, varNbr);
    if (_otf)
        _otfGen->initTrace  (name, depth, procNbr, stateTypeNbr, eventTypeNbr, linkTypeNbr, varNbr);

    time_t t;
    t = time(NULL);
    srand ((int)t);
}

void Generator::endTrace (){
    int i;
    my_link lnk;
    fpritnf (stderr, "Ending the trace, nettoyage des liens morts\n");
    for (i=0; i<_size ; i++){
        lnk = getLink (1);
        // Ending the link
        endLink (lnk.proc, lnk.type, lnk.time);
    }
    fprintf (stderr, "Nettoyee \n");
    if (_paje)
        _pajeGen->endTrace ();
    if (_tau)
        _tauGen->endTrace  ();
    if (_otf)
        _otfGen->endTrace  ();
}


void Generator::addState (int proc, int state, double time){
    if (_paje)
        _pajeGen->addState (proc, state, time);
    if (_tau)
        _tauGen->addState  (proc, state, time);
    if (_otf)
        _otfGen->addState  (proc, state, time);
}



void Generator::startLink (int proc, int type, double time){
    if (_paje)
        _pajeGen->startLink (proc, type, time);
    if (_tau)
        _tauGen->startLink  (proc, type, time);
    if (_otf)
        _otfGen->startLink  (proc, type, time);
}



void Generator::endLink (int proc, int type, double time){
    if (_paje)
        _pajeGen->endLink (proc, type, time);
    if (_tau)
        _tauGen->endLink  (proc, type, time);
    if (_otf)
        _otfGen->endLink  (proc, type, time);
}



void Generator::addEvent (int proc, int type, double time){
    if (_paje)
        _pajeGen->addEvent (proc, type, time);
    if (_tau)
        _tauGen->addEvent  (proc, type, time);
    if (_otf)
        _otfGen->addEvent  (proc, type, time);
}


void Generator::incCpt (int proc, int var, double time){
    if (_paje)
        _pajeGen->incCpt (proc, var, time);
    if (_tau)
        _tauGen->incCpt  (proc, var, time);
    if (_otf)
        _otfGen->incCpt  (proc, var, time);
}


void Generator::decCpt (int proc, int var, double time){
    if (_paje)
        _pajeGen->decCpt (proc, var, time);
    if (_tau)
        _tauGen->decCpt  (proc,var, time);
    if (_otf)
        _otfGen->decCpt  (proc, var, time);
}

void Generator::generate (){
    int i;
    int val = 0;
    
    initTrace (_name, _depth, _procNbr, _numberOfState, _eventTypeNbr,  _linkTypeNbr, _counterNbr);
    for (i=0; i<_numberOfLine ; i++){
        do{
            val = getRand (_numberAction);
            if (_arrayOfValues[val]==STARTLINK)
                _size ++;
        }
        while (_arrayOfValues[val]==ENDLINK && _size<1);
        launchAction (_arrayOfValues[val], i);
    }
    endTrace ();
}

void Generator::launchAction (int val, int time){
    int  newVal ;
    int  newVal2;
    my_link lnk    ;
    
    switch (val){
    case CHANGESTATE :
        // Getting the corresponding proc
        newVal = getRand (_procNbr);
        // Getting the corresponding state
        newVal2 = getRand (_numberOfState);
        addState (newVal, newVal2, time);
        break;
    case STARTLINK :
        // Getting the corresponding proc 
        newVal = getRand (_linkNbr);
        // Getting the corresponding link type
        newVal2 = getRand (_linkTypeNbr);

        lnk.time  = time;
        lnk.proc  = newVal;
        lnk.type  = newVal2;

        // Ajouter un lien a la liste
        _startedLink.append (lnk);
        startLink (newVal, newVal2, time);
        break;
    case ENDLINK :
        // Choosing the link to end
        newVal = getRand (_size);
        _size--;
        lnk = getLink (newVal);
        // Ending the link
        endLink (lnk.proc, lnk.type, time);
        break;
    case EVENT :
        // Getting the proc to add the event
        newVal = getRand (_eventNbr);
        // Getting the type of the event
        newVal2 = getRand (_eventTypeNbr);
        addEvent (newVal, newVal2, time);
        break;
    case INCCPT :
        newVal = getRand (_counterNbr);
        // Always generate 1 counter per proc
        incCpt (newVal, 1, time);
        break;
    case DECCPT :
        newVal = getRand (_counterNbr);
        // Always generate 1 counter per proc
        decCpt (newVal, 1, time);
        break;
    default :
        break;
    }
    
}
 
my_link Generator::getLink (int pos){
    my_link ret;
    QList<my_link>::iterator it = _startedLink.begin ();
    it += pos;
    ret = *it;
    _startedLink.erase (it);
    return ret;
}


int Generator::getRand (int max){
    int ret = 10.0 * rand () / (RAND_MAX + 1.0); 
    return ret%max;
}