Commit e006f43d authored by SPARSA ROYCHOWDHURY's avatar SPARSA ROYCHOWDHURY

19/7/2017:

1. Replaced all "NULL" by "nullptr" as par C++11 standard 
2. Tried to fix some memory leaks
3. Now the program is compilation error free and apparently the TPDA is implemente
4. Testing Remaining Though
5. Still more memory leaks re there.
parent 17277298
......@@ -58,7 +58,7 @@ public :
char *del; // transitions
short **w; // weight matrix
runZone* addNext(char dn, char wn); // new run after adding transition 'dn' of tsm value 'wn'
runZone* addNext(char dn, char wn); // new run after adding transition 'dn' of tsm value 'wn'
runZone* shuffle(runZone *s2); // concatenation of two partial runs
......
......@@ -35,7 +35,7 @@
<rebuildPropChanged>false</rebuildPropChanged>
</toolsSet>
<flagsDictionary>
<element flagsID="0" commonFlags="-std=c++11"/>
<element flagsID="0" commonFlags="-mtune=generic -march=x86-64 -std=c++11"/>
</flagsDictionary>
<codeAssistance>
</codeAssistance>
......@@ -45,11 +45,6 @@
<buildCommand>${MAKE} -f makefile</buildCommand>
<cleanCommand>${MAKE} -f makefile clean</cleanCommand>
<executablePath></executablePath>
<ccTool>
<incDir>
<pElem>include</pElem>
</incDir>
</ccTool>
</makeTool>
<preBuild>
<preBuildCommandWorkingDir>.</preBuildCommandWorkingDir>
......@@ -59,12 +54,18 @@
<folder path="0/src">
<ccTool>
<incDir>
<pElem>src</pElem>
<pElem>include</pElem>
<pElem>.</pElem>
</incDir>
</ccTool>
</folder>
<item path="main.cpp" ex="false" tool="1" flavor2="8">
<ccTool flags="0">
<incDir>
<pElem>include</pElem>
<pElem>.</pElem>
</incDir>
</ccTool>
</item>
<item path="src/continuoustpda.cpp" ex="false" tool="1" flavor2="8">
......
# Automatic path mapper. CRC = 1
# Automatic path mapper. CRC = 468718686
/home/sparsa/NetBeansProjects=/home/sparsa/Programming
/home/sparsa/Programming/mtp/src/tpdaCGPP.cpp=/home/sparsa/Programming/mtp#-g -I ./include -c ./src/tpdaCGPP.cpp -o ./obj/tpdaCGPP.o -lm -std=c++11
/home/sparsa/Programming/mtp/src/timePushDown.cpp=/home/sparsa/Programming/mtp#-g -I ./include -c ./src/timePushDown.cpp -o ./obj/timePushDown.o -lm -std=c++11
/home/sparsa/Programming/mtp/src/tpda2.cpp=/home/sparsa/Programming/mtp#-g -I ./include -c ./src/tpda2.cpp -o ./obj/tpda2.o -lm -std=c++11
/home/sparsa/Programming/mtp/src/drawsystem.cpp=/home/sparsa/Programming/mtp#-g -I ./include -c ./src/drawsystem.cpp -o ./obj/drawsystem.o -lm -std=c++11
/home/sparsa/Programming/mtp/src/continuoustpda.cpp=/home/sparsa/Programming/mtp#-g -I ./include -c ./src/continuoustpda.cpp -o ./obj/continuoustpda.o -lm -std=c++11
/home/sparsa/Programming/mtp/src/tpdaZone.cpp=/home/sparsa/Programming/mtp#-g -I ./include -c ./src/tpdaZone.cpp -o ./obj/tpdaZone.o -lm -std=c++11
/home/sparsa/Programming/mtp/src/treeBitOperations.cpp=/home/sparsa/Programming/mtp#-g -I ./include -c ./src/treeBitOperations.cpp -o ./obj/treeBitOperations.o -lm -std=c++11
/home/sparsa/Programming/mtp/src/pds.cpp=/home/sparsa/Programming/mtp#-g -I ./include -c ./src/pds.cpp -o ./obj/pds.o -lm -std=c++11
/home/sparsa/Programming/mtp/main.cpp=/home/sparsa/Programming/mtp#-g -I ./include -c main.cpp -o main.o -lm -std=c++11
......@@ -49,7 +49,7 @@
#include <functional> // Function objects, designed for use with the standard algorithms
#include <utility> // Various utility components
#include <ctime> // C-style time/date utilites
#include <cstddef> // typedefs for types such as size_t, NULL and others
#include <cstddef> // typedefs for types such as size_t, nullptr and others
#include <new> // Low-level memory management utilities
#include <memory> // Higher level memory management utilities
#include <climits> // limits of integral types
......
......@@ -111,19 +111,19 @@ tpdastate* tpdastate::shuffle(tpdastate *s2) {
// trans at L of s2 should be same as trans at R of this state
if( d4 != (s2->d2) || w4 != (s2->w2) )
return NULL;
return nullptr;
// there should be a push at L and pop at R of state s2
if( !isPush(s2->d2) || !isPop(s2->d4) )
return NULL;
return nullptr;
// push and pop symbol must be same
if( (transitions[s2->d2].as) != (transitions[s2->d4].as) )
return NULL;
return nullptr;
// push-pop edge between L and R of s2 should be added
if( ( (s2->gc) & 1 ) == 0 || ( (s2->gc) & 128 ) == 0 ) // push-pop edge not added yet
return NULL;
return nullptr;
char gcn; // flag for the new state
char d0, w0; // d1 and w1 for the new state
......@@ -144,14 +144,14 @@ tpdastate* tpdastate::shuffle(tpdastate *s2) {
// if d3 of this state has a reset of clock x1
if( d3 != (-1) ) {
if( d3 != (s2->d1) || w3 != (s2->w1) ) // hanging trans and tsm should be same as d3 and w3 resp.
return NULL;
return nullptr;
// accuracy between d3->d4 and s2->d1 -> s2->d2 should be same
if( (gc & 8) == 0 && ( (s2->gc) & 2) != 0 )
return NULL;
return nullptr;
if( (gc & 8) != 0 && ( (s2->gc) & 2) == 0 )
return NULL;
return nullptr;
d0 = d1; // new hanging points comes from first state
w0 = w1;
......@@ -166,13 +166,13 @@ tpdastate* tpdastate::shuffle(tpdastate *s2) {
else if(isReset(1, d2) ) {
if( d2 != (s2->d1) || w2 != (s2->w1) )
return NULL;
return nullptr;
if( ac24 && ( (s2->gc) & 2) == 0 )
return NULL;
return nullptr;
if( !ac24 && ( (s2->gc) & 2) != 0 )
return NULL;
return nullptr;
d0 = d1;
w0 = w1;
......@@ -187,15 +187,15 @@ tpdastate* tpdastate::shuffle(tpdastate *s2) {
else if(d1 != (-1) ) {
if( d1 != (s2->d1) || w1 != (s2->w1) )
return NULL;
return nullptr;
ac14 = !big(1, 4); // accuracy between points d1 and d4 of first state
if( ac14 && ( (s2->gc) & 2) == 0 )
return NULL;
return nullptr;
if( !ac14 && ( (s2->gc) & 2) != 0 )
return NULL;
return nullptr;
d0 = d1;
w0 = w1;
......@@ -216,11 +216,11 @@ tpdastate* tpdastate::shuffle(tpdastate *s2) {
if( (s2->gc) & 2) { // hanging distance of 2nd state is small
if(!ac24) // if distance between d2 and d4 is big for first state
return NULL;
return nullptr;
dis = mod(w1-w0, M) + d24;
if(dis >= M) // if distance between d2 and d4 is big for first state,
return NULL;
return nullptr;
gcn |= 16; // accuracy between d0 to d1 can be small
}
......@@ -1086,7 +1086,7 @@ bool isEmptyTPDA() {
xrs.right = i;
// shuffle, considering rs as left state
vs = rs->shuffle( states[i] );
if(vs != NULL) { // if new state is valid
if(vs != nullptr) { // if new state is valid
if( (vs->gc) & 16) { // if hanging distance is accurate
rs1 = vs->copyState();
......@@ -1129,7 +1129,7 @@ bool isEmptyTPDA() {
// shuffle, considering rs as right state
vs = states[i]->shuffle(rs);
if(vs != NULL) { // if new state is valid
if(vs != nullptr) { // if new state is valid
if( (vs->gc) & 16) { // if hanging distance is accurate
rs1 = vs->copyState();
......
......@@ -38,26 +38,26 @@ pds_state* pds_state::add_stack() {
// if push edge already added to left point(bit 1) or pop edge already added to right point(bit 2)
if(gc & 6) // looking at 1st and 2nd bit from right side(bit position starts from 0)
return NULL;
return nullptr;
if( !isPush(del1) || !isPop(del2) ) // there must be a push at first point and pop at 2nd point
return NULL;
return nullptr;
if(transitions[del1].as != transitions[del2].as) // push and pop stack symbol must be same
return NULL;
return nullptr;
int lb = transitions[del2].lbs[0]; // lower bound for symbol age
int ub = transitions[del2].ubs[0];// upper bound
// if distance between two points is big, but upper bound is not infinity
if( (gc & 1) == 0 && ub != INF)
return NULL;
return nullptr;
//if distance between two points is accurate
if(gc & 1) {
int dis = mod(w2-w1, M);
if(dis < lb || dis > ub) // distance must be compatible with the bounds
return NULL;
return nullptr;
}
......@@ -82,13 +82,13 @@ pds_state* pds_state::add_stack() {
pds_state* pds_state::shuffle(pds_state *s2){ // shuffle with state s2{
if( del2 != (s2->del1) || w2 != (s2->w1) )
return NULL;
return nullptr;
if( isPush(s2->del1) && ( (s2->gc) & 2 ) == 0 ) // if there is a push of first point of 2nd state, but not yet done
return NULL;
return nullptr;
if( isPop(del2) && (gc & 4) == 0 ) // if there is a pop of second point of 1st state, but not yet done
return NULL;
return nullptr;
pds_state *vs = new pds_state(); // allocate memory for new state
......@@ -290,7 +290,7 @@ bool pdsempty() {
for(w2=0; w2 < M; w2++) {
vs = atomic(d1, d2, w1, w2, 1); // atomic state with distance accurate
if(vs != NULL && identity(vs) ) {
if(vs != nullptr && identity(vs) ) {
states.push_back(vs);
vrs.push_back(xrs);
......@@ -307,7 +307,7 @@ bool pdsempty() {
}
vs = atomic(d1, d2, w1, w2, 0); // atomic state with distance big
if(vs != NULL && identity(vs) ) {
if(vs != nullptr && identity(vs) ) {
states.push_back(vs);
......@@ -342,7 +342,7 @@ bool pdsempty() {
//states[count]->print();
vs = states[count]->add_stack();
if(vs != NULL && identity(vs) ) {
if(vs != nullptr && identity(vs) ) {
xrs.type = 1; // add_stack type
xrs.left = count;
......@@ -364,7 +364,7 @@ bool pdsempty() {
xrs.type = 2; // shuffle type
vs = states[count]->shuffle(states[i]);
if(vs != NULL && identity(vs) ) {
if(vs != nullptr && identity(vs) ) {
xrs.left = count;
xrs.right = i;
......@@ -384,7 +384,7 @@ bool pdsempty() {
// shuffle i-th state with 'count'-th state
vs = states[i]->shuffle(states[count]);
if(vs != NULL && identity(vs) ) {
if(vs != nullptr && identity(vs) ) {
xrs.left = i;
xrs.right = count;
......
......@@ -29,26 +29,26 @@ stpdastate* stpdastate::shuffle(stpdastate *s2) {
// transion at L of s2 should be same as transion at R of this state, tsm values as well better be equal
if( d2 != (s2->d1) || w2 != (s2->w1) )
return NULL;
return nullptr;
// there should be a push at L and pop at R of state s2
if( !isPush(s2->d1) || !isPop(s2->d2) )
return NULL;
return nullptr;
/* ******** THIS IS A HUGE MISTAKE , IN OTHER FILES ALSO *****************, REMOVE THIS
// push and pop symbol must be same
if( (transitions[s2->d1].ps) != (transitions[s2->d2].pp) )
return NULL;
return nullptr;
*/
//cout << "ilias" << endl;
// push-pop edge between L and R of s2 should be added
if( ( (s2->gc) & 1 ) == 0 ) // push-pop edge not added yet
return NULL;
return nullptr;
char gcn; // flag for the new state
......@@ -578,7 +578,7 @@ bool isEmptySTPDA() {
xrs.right = i;
// shuffle, considering rs as left state
vs = rs->shuffle( states[i] );
if(vs != NULL) { // if new state is valid
if(vs != nullptr) { // if new state is valid
if( identity(vs) ) {
states.push_back(vs);
vrs.push_back(xrs);
......@@ -599,7 +599,7 @@ bool isEmptySTPDA() {
// shuffle, considering rs as right state
vs = states[i]->shuffle(rs);
if(vs != NULL) { // if new state is valid
if(vs != nullptr) { // if new state is valid
if( identity(vs) ) {
states.push_back(vs);
vrs.push_back(xrs);
......
......@@ -227,7 +227,7 @@ bool stateGCPP::shuffleCheck(stateGCPP *s2) {
stateGCPP* stateGCPP::shuffle(stateGCPP *s2){ // shuffle with state s2
if(! shuffleCheck(s2) )
return NULL;
return nullptr;
return reduceShuffle(s2);
}
......@@ -935,7 +935,7 @@ bool isEmptyGCPP() {
for(i=0; i < count; i++) {
// shuffle, considering rs as left state
vs = rs->shuffle( allStates[i].first );
if(vs != NULL) { // if new state is valid
if(vs != nullptr) { // if new state is valid
if( identity(vs) ) {
xrs = getTrack(2, count, i); // key for the new state
allStates.push_back( make_pair(vs, xrs) );
......@@ -968,7 +968,7 @@ bool isEmptyGCPP() {
// shuffle, considering rs as right state
vs = (allStates[i].first)->shuffle(rs);
if(vs != NULL) { // if new state is valid
if(vs != nullptr) { // if new state is valid
if( identity(vs) ) {
xrs = getTrack(2, i, count); // key for the new state
allStates.push_back( make_pair(vs, xrs) );
......
......@@ -113,12 +113,12 @@ bool identity(stateZone *vs) {
}
}
/*bool findVector(vector <int> vector1, int val)
{
int n = find(vector1.begin(),vector1.end(),val);
if( n == vector1.end())
return false;
return true;
}*/
{
int n = find(vector1.begin(),vector1.end(),val);
if( n == vector1.end())
return false;
return true;
}*/
stateZone* stateZone::reduceShuffle(stateZone* s2) {
......@@ -132,13 +132,13 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) {
char count=0; // used for storing #points in new state
char indexNew; // looping invariant
int lb,ub,openl,openu;
count = P + P2 - (L2+1); //total number of points before reducing the state, the point P1 and L2 are same so reduced by 1.
stateZone *vs = new stateZone(); // new Shuffled state but not reduced.
vs->del = new char[count]; // allocate memory for the transitions in the state
vs->w = new short[count*(count-1)]; //this will hold the matrix without the diagonal element the index will be given by the macro
vs->f = f; //f contains the push complete command flag bit along with the value of L
......@@ -153,7 +153,7 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) {
else
WT1[i][j] = 0;
}
/*copying the transitions for both the states to this new state*/
indexNew = count - 1; // index of the last transition of the new state.
......@@ -168,7 +168,7 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) {
open1[i][i] = false;
}
else if(i < m) {
WT1[i][m] = min(int(WT1[i][m]),int(w[index((i-P), (m-P), P2)] & (~a32[15]))); // 15-TH bit is used for open or not
WT1[i][m] = min(int(WT1[i][m]),int(w[index((i-P), (m-P), P2)] & (~a32[15]))); // 15-TH bit is used for open or not
if( w[index((i-P), (m-P), P2)] & a32[15] ) // as 15th bit is used for open and close interval
open1[i][m] = true;
......@@ -177,7 +177,7 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) {
}
else{ ///when i > j i.e the edges coming from j to i it must be negetive.
WT1[i][m] = - ( min(int(w[index((i-P), (m-P), P2)] & (~a32[15])),-int(WT1[i][m]) )); // 15-TH bit is used for open or not
WT1[i][m] = - ( min(int(w[index((i-P), (m-P), P2)] & (~a32[15])),-int(WT1[i][m]) )); // 15-TH bit is used for open or not
if( w[index((i-P), (m-P), P2)] & a32[15] )
open1[i][m] = true;
......@@ -186,7 +186,7 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) {
}
}
}
char indexNew1 = indexNew;
// Here we are copying points of state 2.
for(int j=P2-1; j >=0; j--,indexNew--) {
......@@ -198,7 +198,7 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) {
open1[indexNew][indexNew1] = false;
}
else if(j < i) {
WT1[indexNew][indexNew1] = min(int(w2[index(j, i, P)] & (~a32[15])),int(WT1[indexNew][indexNew1])); // 15-TH bit is used for open or not
WT1[indexNew][indexNew1] = min(int(w2[index(j, i, P)] & (~a32[15])),int(WT1[indexNew][indexNew1])); // 15-TH bit is used for open or not
if( w2[index(j, i, P)] & a32[15] ) // as 15th bit is used for open and close interval
open1[indexNew][indexNew1] = true;
......@@ -207,7 +207,7 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) {
}
else{ ///when i > j i.e the edges coming from j to i it must be negetive.
WT1[indexNew][indexNew1] = - (min(int( w2[index(j, i, P)] & (~a32[15])),int(WT1[indexNew][indexNew1])) ); // 15-TH bit is used for open or not
WT1[indexNew][indexNew1] = - (min(int( w2[index(j, i, P)] & (~a32[15])),int(WT1[indexNew][indexNew1])) ); // 15-TH bit is used for open or not
if( w2[index(j, i, P)] & a32[15] )
open1[indexNew][indexNew1] = true;
......@@ -221,8 +221,8 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) {
//nf |= ( f & a32[j+1] ); // here f means some thing different
}
//Now before reducing the state we want to check if the state is at all feasible..
// so we run the APSP algo.
//Now before reducing the state we want to check if the state is at all feasible..
// so we run the APSP algo.
allPairSP(count); //this is the Floyd–Warshall algorithm implementation
......@@ -253,7 +253,7 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) {
for(int i=0; i <= count; i++){
if(WT[i][i] < 0 || open[i][i])
return NULL;
return nullptr;
}
short countNew = 1; // var for storing #points in new state after applying forget operation
......@@ -262,7 +262,7 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) {
curReset = 0, reset = 0;
int prevPoints = 0;
for(int i=L2; i < P2; i++)
curReset |= ( transitions[ del2[i] ].reset );
curReset |= ( transitions[ del2[i] ].reset );
for(int i=P-1; i >= L; i--,prevPoints++) {
reset = ( transitions[ del[i] ].reset );
......@@ -295,6 +295,8 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) {
vs1->del = new char[newcount]; // allocate memory
vs1->w = new short[newcount*newcount - newcount];
vs1->f = f; // **** must edit this for tpda
//clearly the left point is the same as the left point of the state vs1.
// if the last point
vs1->P = newcount;
......@@ -328,56 +330,56 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) {
//for(i=P-1; i >= L; i--) { //iterating on the points of the first state
// current point reset set
/* j = (count - 1) - (P2 - L2);//this is the start of hanging points of state 2
for(int k = 0; k < P2 ; k++) //iterating through the points of second state to find any clock constraint check
{
for(int x=1; x <= X; x++) { // iterate for every clocks
if( isChecked(x, del2[k]) ) { // if there is a constraint for clock x in the transition k of second state
lb = transitions[del2[k]].lbs[x];//storing the value of the upper bound of the constraint
ub = transitions[del2[k]].ubs[x]; // storing the lower bound of the constraint
openl = (transitions[del2[k]].openl) & a32[x]; // lower bound for clock x is open or not
openu = (transitions[del2[k]].openu) & a32[x]; // upper bound of the clock x is open or not
for(i=P-1; i >= L; i--) { // find reset point for clock x in the first state
reset = ( transitions[ del[i] ].reset ); //storing the reset information for this transition
if( (reset & (~curReset) & (~1)) && (isReset(x, del[i])) ) { // if current point has more reset then seen earlier
//and if this point have the a reset point of the clock x
vs->del[j] = del[i]; //copy the transition number
//if( ) { // if clock x is reset at point i+1
// tighten the lower and upper bounds
if( (-lb) < WT1[P][i] ) {
WT1[P][i] = -lb;
open1[P][i] = (openl & a32[x]);
}
else if( (-lb) == WT1[i][P] )
open1[P][i] |= (openl & a32[x]);
if(ub != INF) {
if(ub < WT1[i][P]) {
WT1[i][P] = ub;
open1[i][P] = (openu & a32[x]);
}
else if( ub == WT1[i][P] )
open1[i][P] |= (openu & a32[x]);
}
i = -1;
}
//curReset |= reset;
j--;
//lastindex = i;
}
}
}
}
*/
/* j = (count - 1) - (P2 - L2);//this is the start of hanging points of state 2
for(int k = 0; k < P2 ; k++) //iterating through the points of second state to find any clock constraint check
{
for(int x=1; x <= X; x++) { // iterate for every clocks
if( isChecked(x, del2[k]) ) { // if there is a constraint for clock x in the transition k of second state
lb = transitions[del2[k]].lbs[x];//storing the value of the upper bound of the constraint
ub = transitions[del2[k]].ubs[x]; // storing the lower bound of the constraint
openl = (transitions[del2[k]].openl) & a32[x]; // lower bound for clock x is open or not
openu = (transitions[del2[k]].openu) & a32[x]; // upper bound of the clock x is open or not
for(i=P-1; i >= L; i--) { // find reset point for clock x in the first state
reset = ( transitions[ del[i] ].reset ); //storing the reset information for this transition
if( (reset & (~curReset) & (~1)) && (isReset(x, del[i])) ) { // if current point has more reset then seen earlier
//and if this point have the a reset point of the clock x
vs->del[j] = del[i]; //copy the transition number
//if( ) { // if clock x is reset at point i+1
// tighten the lower and upper bounds
if( (-lb) < WT1[P][i] ) {
WT1[P][i] = -lb;
open1[P][i] = (openl & a32[x]);
}
else if( (-lb) == WT1[i][P] )
open1[P][i] |= (openl & a32[x]);
if(ub != INF) {
if(ub < WT1[i][P]) {
WT1[i][P] = ub;
open1[i][P] = (openu & a32[x]);
}
else if( ub == WT1[i][P] )
open1[i][P] |= (openu & a32[x]);
}
i = -1;
}
//curReset |= reset;
j--;
//lastindex = i;
}
}
}
}
*/
//vs->P = count; // #points in new state
free(vs);
return vs1;
......@@ -772,7 +774,7 @@ bool stateZone::shuffleCheck(stateZone *s2) {
stateZone* stateZone::shuffle(stateZone *s2){ // shuffle with state s2
if(! shuffleCheck(s2) )
return NULL;
return nullptr;
return reduceShuffle(s2);
}
......@@ -1017,7 +1019,7 @@ stateZone* stateZone::addNextTPDA(char dn) {
for(i=0; i <= P; i++){
if(WT[i][i] < 0 || open[i][i])
return NULL;
return nullptr;
}
......@@ -1098,61 +1100,61 @@ stateZone* stateZone::addNextTPDA(char dn) {
// not applied by ilias
/*// Return template successor state whose descendent states will be right states for shuffle operation with this state
stateGCPP* stateZone::sucState(){
short curReset, reset; // temp vars for keeping reset bit vector
char count; // will contain #points in the new state
char i,j; // counters
// iterate through all points right to left except the last point
curReset = transitions[ del[P-1] ].reset;
count = 1; //we have to take the last point, so initialize 'count' to 1
for(i=P-2; i >= 0; i--) {
reset = transitions[ del[i] ].reset; // reset bit vector for point i+1
if( reset & (~curReset) & (~1) ) { // if (i+1)-th point has additional reset for some clock
count++;
curReset |= reset;
}
}
stateZone* vs = new stateZone(); // new template state
vs->P = count; //#points
//vs->L = count; // no non-trivial block is there there is no L in the zone class
vs->del = new char[count]; //allocate space for transition
vs->w = new char[count]; // allocate space for the upper and lower limits
vs->del[count-1] = del[P-1]; // the last point is the last transition
//vs->w[count-1] = w[P-1]; // have to apply the upper and lower bounds
// copy the necessary points into the template state
char lastindex = P-1;
short nf = 0; // flag variable for new state
curReset = transitions[ del[P-1] ].reset;
for(i=P-2, j = count-2; i >= 0; i--) {
reset = transitions[ del[i] ].reset; // reset bit vector for point i+1
if(reset & (~curReset) & (~1) ) { // found a new necessary point, copy this point to new state
vs->del[j] = del[i];
vs->w[j] = w[i];
if( !big(i+1, lastindex+1) ) //from current needy point to the last found needy point distance small
nf |= a32[j+1]; // distance (j+1->(j+2)) is small
curReset |= reset;
j--;
lastindex = i; // this point is the last point selected till now
}
}
vs->f = nf; // copy flag information, no stack info is there till now for the template state
return vs;
}
* */
// Return template successor state whose descendent states will be right states for shuffle operation with this state
stateZone* stateZone::sucState(){
short curReset, reset; // temp vars for keeping reset bit vector
char count; // will contain #points in the new state
char i,j; // counters
// iterate through all points right to left except the last point
curReset = transitions[ del[P-1] ].reset;
count = 1; //we have to take the last point, so initialize 'count' to 1
for(i=P-2; i >= 0; i--) {
reset = transitions[ del[i] ].reset; // reset bit vector for point i+1
if( reset & (~curReset) & (~1) ) { // if (i+1)-th point has additional reset for some clock
count++;
curReset |= reset;
}
}
stateZone* vs = new stateZone(); // new template state
vs->P = count; //#points
//vs->L = count; // no non-trivial block is there there is no L in the zone class
vs->del = new char[count]; //allocate space for transition
vs->w = new short[count*(count-1)]; // allocate space for the upper and lower limits
vs->del[count-1] = del[P-1]; // the last point is the last transition
//vs->w[count-1] = w[P-1]; // have to apply the upper and lower bounds
// copy the necessary points into the template state
char lastindex = P-1;
//short nf = 0; // flag variable for new state
curReset = transitions[ del[P-1] ].reset;
for(i=P-2, j = count-2; i >= 0; i--) {
reset = transitions[ del[i] ].reset; // reset bit vector for point i+1
if(reset & (~curReset) & (~1) ) { // found a new necessary point, copy this point to new state
vs->del[j] = del[i];
// vs->w[j] = w[i];
// if( !big(i+1, lastindex+1) ) //from current needy point to the last found needy point distance small
// nf |= a32[j+1]; // distance (j+1->(j+2)) is small
curReset |= reset;
j--;
lastindex = i; // this point is the last point selected till now
}
}
// vs->f = nf; // copy flag information, no stack info is there till now for the template state
return vs;
}
......@@ -1227,56 +1229,68 @@ bool stateZone::isFinal(){
}
/*
// return the partial run corresponding the tree automata state 'vs', ignore the hanging points
// copy only transitions between L(left) and R(right)
runCGPP* getRun(stateGCPP* vs) {
runCGPP *pr = new runCGPP(); // new partial run stored in variable pr
pr->P = vs->P - vs->L + 1 ; // transitions in new partial run will be from left(L) point to right(R) point
// allocate memory for transitions and tsm vlaues for new run
pr->del = new char[pr->P];
pr->w = new char[pr->P];
// loopers : i used to index transition of the tree automata state and j is used to index trans in the run
char i = vs->L - 1, j=0;
// copy transitions and tsm values from earlier partial run to new partial run
for(; i < (vs->P); i++, j++) {
pr->del[j] = vs->del[i];
pr->w[j] = vs->w[i];
}
return pr; // return the new run
}
runZone* getRunZone(stateZone* vs) {
runZone *pr = new runZone(); // new partial run stored in variable pr
char L = vs->f&127;
pr->P = vs->P - L + 1 ; // transitions in new partial run will be from left(L) point to right(R) point
// allocate memory for transitions and tsm vlaues for new run
pr->del = new char[pr->P];
pr->w = new short*[(pr->P)];
//allocate memory for weight matrix
for(int i = 0; i < pr->P; i++)
{
pr->w[i]=new short[pr->P];
}
// loopers : i used to index transition of the tree automata state and j is used to index trans in the run
// copy transitions and tsm values from earlier partial run to new partial run
for(char i = L - 1, j=0; i < (vs->P); i++, j++) {
pr->del[j] = vs->del[i];
for(char m= L-1,n = 0; m <(vs->P); m++, n++)
{
if(j == n)
{
pr->w[j][n]=0;
}
else
pr->w[j][n] = vs->w[index(i,m,vs->P)];
}
}
return pr; // return the new run
}
// GIVEN the current partial run, append the transition 'dn' with tsm value 'wn'
runCGPP* runCGPP::addNext(char dn, char wn) {
runCGPP *pr = new runCGPP(); // new partial run stored in variable pr
pr->P = P + 1; // #transitions in new partial run will be one more than the earlier
// allocate memory for transitions and tsm vlaues for new run
pr->del = new char[pr->P];
pr->w = new char[pr->P];
// copy transitions and tsm values from earlier partial run to new partial run
for(char i=0; i < P; i++) {
pr->del[i] = del[i];
pr->w[i] = w[i];
}
pr->del[P] = dn; // add the new transition and tsm value to the last position of new partial run
pr->w[P] = wn;
return pr; // return the new run
}
// runZone* runZone::addNext(char dn, short wn) {
//
// runZone *pr = new runZone(); // new partial run stored in variable pr
//
// pr->P = P + 1; // #transitions in new partial run will be one more than the earlier
//
// // allocate memory for transitions and tsm vlaues for new run
// pr->del = new char[pr->P];
// pr->w = new short[pr->P];
//
// // copy transitions and tsm values from earlier partial run to new partial run
// for(char i=0; i < P; i++) {
// pr->del[i] = del[i];
// pr->w[i] = w[i];
// }
//
// pr->del[P] = dn; // add the new transition and tsm value to the last position of new partial run
// pr->w[P] = wn;
//
// return pr; // return the new run
// }
/*
// shuffle two partial runs and return the new partial run
runCGPP* runCGPP::shuffle(runCGPP *s2) {
......@@ -1318,7 +1332,7 @@ stateZone* getZeroStateZone() {
vs->f = 1; // no push pop info yet and L = 1 cause the last bit of the flag denotes the push complete information
vs->del = new char[1]; // memory allocation for the transitions
vs->w = NULL; //the 2-dimentional array projected in to one dimentional arry initially empty
vs->w = nullptr; //the 2-dimentional array projected in to one dimentional arry initially empty
vs->del[0] = 0; // 0th transition has tsm value 0
......@@ -1393,28 +1407,28 @@ string stateZone::getKeyRight() {
return s;
}
/*
// print a run as witness of the given TPDA if the language is non-empty
void runCGPP::print() {
short int lt = 0, ct=0; // lt : last timestamps, ct : current time stamps
cout << endl << "A run of the automation as a witness for the language to be non-empty.\nThe run given as a sequence of pairs (Transition, Time stamp) : " << endl;
for(char i=0; i < P; i++) {
if( w[i] < lt ) // if current time stamps less than last time stamps
ct = M + ct + (w[i] - lt);
else
ct = ct + (w[i] - lt);
lt = w[i];
cout << "(" << int(del[i]) << ", " << int(ct) << ".0" << "), ";
}
cout << endl << endl;
}
*/
// print a run as witness of the given TPDA if the language is non-empty
void runZone::print() {
short int lt = 0, ct=0; // lt : last timestamps, ct : current time stamps
cout << endl << "A run of the automation as a witness for the language to be non-empty.\nThe run given as a sequence of pairs (Transition, Time stamp) : " << endl;
for(char i=0; i < P; i++) {
//
// if( w[i] < lt ) // if current time stamps less than last time stamps
// ct = M + ct + (w[i] - lt);
// else
// ct = ct + (w[i] - lt);
//
// lt = w[i];
cout << "(" << int(del[i]) << ", " << int(ct) << ".0" << "), ";
}
cout << endl << endl;
}
// return a backtracking state with the info given in the parameters
trackZone* getTrackZone(char t, int l, int r) {
......@@ -1427,50 +1441,50 @@ trackZone* getTrackZone(char t, int l, int r) {
return xrs;
}
/*
// get the run of the timed system
// if sm == "", this means. we are backtracking from the state reside in i-th index of main vector 'allStates'
// if sm != "", then sm string is the key for shuffle operation of the state reside in i-th index of allStates
runCGPP* printRun(int i) {
stateGCPP* vs; // tree automata state variable
trackCGPP *bp; // back tracking state
vs = allStates[i].first;
bp = allStates[i].second;
runCGPP *rs, *rs1, *rs2;
// if the i-th state is an atomic state
if( (bp->type) == 0 ) {
cout << endl << i << ":";
vs->print();
return getRun(vs); // return the run generated from atomic state
}
// if the considerted state is generated by an addNext operation from a state in the main vector
else if( (bp->type) == 1 ) {
rs1 = printRun( bp->left );
rs = rs1->addNext(vs->del[vs->P - 1], vs->w[vs->P - 1]);
cout << endl << i << " : " << (bp->left);
vs->print();
return rs;
}
else{
rs1 = printRun( bp->left);
rs2 = printRun(bp->right);
rs = rs1->shuffle(rs2);
cout << endl << i << " : " << (bp->left) << ", " << (bp->right);
vs->print();
return rs;
}
}
*/
// get the run of the timed system
// if sm == "", this means. we are backtracking from the state reside in i-th index of main vector 'allStates'
// if sm != "", then sm string is the key for shuffle operation of the state reside in i-th index of allStates
runZone* printRunZone(int i) {
stateZone* vs; // tree automata state variable
trackZone *bp; // back tracking state
vs = allStatesZone[i].first;
bp = allStatesZone[i].second;
runZone *rs, *rs1, *rs2;
// if the i-th state is an atomic state
if( (bp->type) == 0 ) {
cout << endl << i << ":";
vs->print();
return getRunZone(vs); // return the run generated from atomic state
}
// if the considerted state is generated by an addNext operation from a state in the main vector
else if( (bp->type) == 1 ) {
rs1 = printRunZone( bp->left );
//rs = rs1->addNext(vs->del[vs->P - 1], vs->w[vs->P - 1]);
cout << endl << i << " : " << (bp->left);
vs->print();
return rs;
}
else{
rs1 = printRunZone( bp->left);
rs2 = printRunZone(bp->right);
//rs = rs1->shuffle(rs2);
cout << endl << i << " : " << (bp->left) << ", " << (bp->right);
vs->print();
return rs;
}
}
// return true iff language recognized by the TPDA is empty
......@@ -1482,7 +1496,7 @@ bool isEmptyZone() {
return false;
}
int i,j; // counters
//int i,j; // counters
bool pushl, pushr, popl, popr, ppDone;
// allocate memory for two weight matrix and their corresponding open vars used shortest path operations
// K : maximum #points in a state
......@@ -1492,7 +1506,7 @@ bool isEmptyZone() {
open1 = new bool*[K+2]; // size is K(tree-width), so that we can use for any #points in a state
open2 = new bool*[K+2];
for(i=0; i < (K+2); i++) { // allocate memory for inner 1d arrays
for(int i=0; i < (K+2); i++) { // allocate memory for inner 1d arrays
WT1[i] = new short[K+2];
WT2[i] = new short[K+2];
......@@ -1551,10 +1565,10 @@ bool isEmptyZone() {
//cout << "Parents: " << (xrs->left) << ", " << (xrs->right) << endl << "--------------" << endl;
del = rs->del;
P = rs->P;
f = rs->f;
L = f & 127;
del = rs->del;// getting the transitions of the point
P = rs->P; // getting the number of points of the point
f = rs->f; // getting the L and the push flag
L = f & 127;// extracting the value of L.
pushl = isPush( del[L - 1] ); // pushl = 1 iff there is a push at L
pushr = isPush( del[P - 1] ); // pushr = 1 iff there is a push at R
popl = isPop( del[L - 1] ); // popl = 1 iff there is a pop at L
......@@ -1562,13 +1576,59 @@ bool isEmptyZone() {
ppDone = (f & 1) ; // if push at L and pop at R is done in rs
// iterate through all the generated states and process them to generate new state
if(L < P && pushr)
if(L < P && pushr)// if there exists a non trivial block and the point L have a push
{
for(int i =0; i < count ; i++)
{
vs = rs->shuffle(allStatesZone[i].first);
if(vs != nullptr)
{
if(identity(vs)) //if already not present in the all states
{
xrs = getTrackZone(2,count,i); // 2 is the shuffle operation, with count and i
allStatesZone.push_back(make_pair(vs,xrs)); // push it in the vector
N++; //increase the number of states
if( vs->isFinal())
{
vs->print();
prs = printRunZone(N-1);
prs->print();
return false;
}
}
}
}
vs = rs->sucState();
if(identity(vs))
{
xrs = getTrackZone(0,-1,count);
allStatesZone.push_back(make_pair(vs,xrs));
N++;
}
}
else if (L < P && pushl && ppDone)
else if (L < P && pushl &&popr && ppDone)
{
for(int i = 0; i < count ; i++)
{
vs = (allStatesZone[i].first)->shuffle(rs);
if(vs != nullptr)
{
if(identity(vs))
{
xrs = getTrackZone(2,i,count);
allStatesZone.push_back(make_pair(vs,xrs));
N++;
if(vs->isFinal())
{
vs->print();
prs = printRunZone(N-1);
prs->print();
return false;
}
}
}
}
}
else
{
......@@ -1578,12 +1638,12 @@ bool isEmptyZone() {
// iterate through all the upcoming transitions
//this is only add operations we have to find way to suffle and
for(i=0; i < nexttrans[q].size(); i++) {
for(int i=0; i < nexttrans[q].size(); i++) {
dn = nexttrans[q][i]; // i-th upcoming transition
vs = rs->addNextTPDA(dn); // get set of states after doing the add operation
if(vs != NULL) { // if new state is valid
if(vs != nullptr) { // if new state is valid
//vs->print();
if( identity(vs) ) {
xrs = getTrackZone(1, count, -1); // key for the new state
......@@ -1634,6 +1694,24 @@ bool isEmptyZone() {
rs->print();
*/
//freeing up the space allocated dynamically.
for(int i = 0; i < (K+2) ; i++)
{
delete[] WT1[i];
delete[] WT2[i];
delete[] open1[i];
delete[] open2[i];
}
delete[] WT1;
delete[] WT2;
delete[] open1;
delete[] open2;
return true;
}
......
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment