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 : ...@@ -58,7 +58,7 @@ public :
char *del; // transitions char *del; // transitions
short **w; // weight matrix 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 runZone* shuffle(runZone *s2); // concatenation of two partial runs
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
<rebuildPropChanged>false</rebuildPropChanged> <rebuildPropChanged>false</rebuildPropChanged>
</toolsSet> </toolsSet>
<flagsDictionary> <flagsDictionary>
<element flagsID="0" commonFlags="-std=c++11"/> <element flagsID="0" commonFlags="-mtune=generic -march=x86-64 -std=c++11"/>
</flagsDictionary> </flagsDictionary>
<codeAssistance> <codeAssistance>
</codeAssistance> </codeAssistance>
...@@ -45,11 +45,6 @@ ...@@ -45,11 +45,6 @@
<buildCommand>${MAKE} -f makefile</buildCommand> <buildCommand>${MAKE} -f makefile</buildCommand>
<cleanCommand>${MAKE} -f makefile clean</cleanCommand> <cleanCommand>${MAKE} -f makefile clean</cleanCommand>
<executablePath></executablePath> <executablePath></executablePath>
<ccTool>
<incDir>
<pElem>include</pElem>
</incDir>
</ccTool>
</makeTool> </makeTool>
<preBuild> <preBuild>
<preBuildCommandWorkingDir>.</preBuildCommandWorkingDir> <preBuildCommandWorkingDir>.</preBuildCommandWorkingDir>
...@@ -59,12 +54,18 @@ ...@@ -59,12 +54,18 @@
<folder path="0/src"> <folder path="0/src">
<ccTool> <ccTool>
<incDir> <incDir>
<pElem>src</pElem>
<pElem>include</pElem>
<pElem>.</pElem> <pElem>.</pElem>
</incDir> </incDir>
</ccTool> </ccTool>
</folder> </folder>
<item path="main.cpp" ex="false" tool="1" flavor2="8"> <item path="main.cpp" ex="false" tool="1" flavor2="8">
<ccTool flags="0"> <ccTool flags="0">
<incDir>
<pElem>include</pElem>
<pElem>.</pElem>
</incDir>
</ccTool> </ccTool>
</item> </item>
<item path="src/continuoustpda.cpp" ex="false" tool="1" flavor2="8"> <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 @@ ...@@ -49,7 +49,7 @@
#include <functional> // Function objects, designed for use with the standard algorithms #include <functional> // Function objects, designed for use with the standard algorithms
#include <utility> // Various utility components #include <utility> // Various utility components
#include <ctime> // C-style time/date utilites #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 <new> // Low-level memory management utilities
#include <memory> // Higher level memory management utilities #include <memory> // Higher level memory management utilities
#include <climits> // limits of integral types #include <climits> // limits of integral types
......
...@@ -111,19 +111,19 @@ tpdastate* tpdastate::shuffle(tpdastate *s2) { ...@@ -111,19 +111,19 @@ tpdastate* tpdastate::shuffle(tpdastate *s2) {
// trans at L of s2 should be same as trans at R of this state // trans at L of s2 should be same as trans at R of this state
if( d4 != (s2->d2) || w4 != (s2->w2) ) 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 // there should be a push at L and pop at R of state s2
if( !isPush(s2->d2) || !isPop(s2->d4) ) if( !isPush(s2->d2) || !isPop(s2->d4) )
return NULL; return nullptr;
// push and pop symbol must be same // push and pop symbol must be same
if( (transitions[s2->d2].as) != (transitions[s2->d4].as) ) 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 // 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 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 gcn; // flag for the new state
char d0, w0; // d1 and w1 for the new state char d0, w0; // d1 and w1 for the new state
...@@ -144,14 +144,14 @@ tpdastate* tpdastate::shuffle(tpdastate *s2) { ...@@ -144,14 +144,14 @@ tpdastate* tpdastate::shuffle(tpdastate *s2) {
// if d3 of this state has a reset of clock x1 // if d3 of this state has a reset of clock x1
if( d3 != (-1) ) { if( d3 != (-1) ) {
if( d3 != (s2->d1) || w3 != (s2->w1) ) // hanging trans and tsm should be same as d3 and w3 resp. 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 // accuracy between d3->d4 and s2->d1 -> s2->d2 should be same
if( (gc & 8) == 0 && ( (s2->gc) & 2) != 0 ) if( (gc & 8) == 0 && ( (s2->gc) & 2) != 0 )
return NULL; return nullptr;
if( (gc & 8) != 0 && ( (s2->gc) & 2) == 0 ) if( (gc & 8) != 0 && ( (s2->gc) & 2) == 0 )
return NULL; return nullptr;
d0 = d1; // new hanging points comes from first state d0 = d1; // new hanging points comes from first state
w0 = w1; w0 = w1;
...@@ -166,13 +166,13 @@ tpdastate* tpdastate::shuffle(tpdastate *s2) { ...@@ -166,13 +166,13 @@ tpdastate* tpdastate::shuffle(tpdastate *s2) {
else if(isReset(1, d2) ) { else if(isReset(1, d2) ) {
if( d2 != (s2->d1) || w2 != (s2->w1) ) if( d2 != (s2->d1) || w2 != (s2->w1) )
return NULL; return nullptr;
if( ac24 && ( (s2->gc) & 2) == 0 ) if( ac24 && ( (s2->gc) & 2) == 0 )
return NULL; return nullptr;
if( !ac24 && ( (s2->gc) & 2) != 0 ) if( !ac24 && ( (s2->gc) & 2) != 0 )
return NULL; return nullptr;
d0 = d1; d0 = d1;
w0 = w1; w0 = w1;
...@@ -187,15 +187,15 @@ tpdastate* tpdastate::shuffle(tpdastate *s2) { ...@@ -187,15 +187,15 @@ tpdastate* tpdastate::shuffle(tpdastate *s2) {
else if(d1 != (-1) ) { else if(d1 != (-1) ) {
if( d1 != (s2->d1) || w1 != (s2->w1) ) if( d1 != (s2->d1) || w1 != (s2->w1) )
return NULL; return nullptr;
ac14 = !big(1, 4); // accuracy between points d1 and d4 of first state ac14 = !big(1, 4); // accuracy between points d1 and d4 of first state
if( ac14 && ( (s2->gc) & 2) == 0 ) if( ac14 && ( (s2->gc) & 2) == 0 )
return NULL; return nullptr;
if( !ac14 && ( (s2->gc) & 2) != 0 ) if( !ac14 && ( (s2->gc) & 2) != 0 )
return NULL; return nullptr;
d0 = d1; d0 = d1;
w0 = w1; w0 = w1;
...@@ -216,11 +216,11 @@ tpdastate* tpdastate::shuffle(tpdastate *s2) { ...@@ -216,11 +216,11 @@ tpdastate* tpdastate::shuffle(tpdastate *s2) {
if( (s2->gc) & 2) { // hanging distance of 2nd state is small if( (s2->gc) & 2) { // hanging distance of 2nd state is small
if(!ac24) // if distance between d2 and d4 is big for first state if(!ac24) // if distance between d2 and d4 is big for first state
return NULL; return nullptr;
dis = mod(w1-w0, M) + d24; dis = mod(w1-w0, M) + d24;
if(dis >= M) // if distance between d2 and d4 is big for first state, 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 gcn |= 16; // accuracy between d0 to d1 can be small
} }
...@@ -1086,7 +1086,7 @@ bool isEmptyTPDA() { ...@@ -1086,7 +1086,7 @@ bool isEmptyTPDA() {
xrs.right = i; xrs.right = i;
// shuffle, considering rs as left state // shuffle, considering rs as left state
vs = rs->shuffle( states[i] ); 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 if( (vs->gc) & 16) { // if hanging distance is accurate
rs1 = vs->copyState(); rs1 = vs->copyState();
...@@ -1129,7 +1129,7 @@ bool isEmptyTPDA() { ...@@ -1129,7 +1129,7 @@ bool isEmptyTPDA() {
// shuffle, considering rs as right state // shuffle, considering rs as right state
vs = states[i]->shuffle(rs); 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 if( (vs->gc) & 16) { // if hanging distance is accurate
rs1 = vs->copyState(); rs1 = vs->copyState();
......
...@@ -38,26 +38,26 @@ pds_state* pds_state::add_stack() { ...@@ -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 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) 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 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 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 lb = transitions[del2].lbs[0]; // lower bound for symbol age
int ub = transitions[del2].ubs[0];// upper bound int ub = transitions[del2].ubs[0];// upper bound
// if distance between two points is big, but upper bound is not infinity // if distance between two points is big, but upper bound is not infinity
if( (gc & 1) == 0 && ub != INF) if( (gc & 1) == 0 && ub != INF)
return NULL; return nullptr;
//if distance between two points is accurate //if distance between two points is accurate
if(gc & 1) { if(gc & 1) {
int dis = mod(w2-w1, M); int dis = mod(w2-w1, M);
if(dis < lb || dis > ub) // distance must be compatible with the bounds 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() { ...@@ -82,13 +82,13 @@ pds_state* pds_state::add_stack() {
pds_state* pds_state::shuffle(pds_state *s2){ // shuffle with state s2{ pds_state* pds_state::shuffle(pds_state *s2){ // shuffle with state s2{
if( del2 != (s2->del1) || w2 != (s2->w1) ) 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 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 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 pds_state *vs = new pds_state(); // allocate memory for new state
...@@ -290,7 +290,7 @@ bool pdsempty() { ...@@ -290,7 +290,7 @@ bool pdsempty() {
for(w2=0; w2 < M; w2++) { for(w2=0; w2 < M; w2++) {
vs = atomic(d1, d2, w1, w2, 1); // atomic state with distance accurate 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); states.push_back(vs);
vrs.push_back(xrs); vrs.push_back(xrs);
...@@ -307,7 +307,7 @@ bool pdsempty() { ...@@ -307,7 +307,7 @@ bool pdsempty() {
} }
vs = atomic(d1, d2, w1, w2, 0); // atomic state with distance big 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); states.push_back(vs);
...@@ -342,7 +342,7 @@ bool pdsempty() { ...@@ -342,7 +342,7 @@ bool pdsempty() {
//states[count]->print(); //states[count]->print();
vs = states[count]->add_stack(); vs = states[count]->add_stack();
if(vs != NULL && identity(vs) ) { if(vs != nullptr && identity(vs) ) {
xrs.type = 1; // add_stack type xrs.type = 1; // add_stack type
xrs.left = count; xrs.left = count;
...@@ -364,7 +364,7 @@ bool pdsempty() { ...@@ -364,7 +364,7 @@ bool pdsempty() {
xrs.type = 2; // shuffle type xrs.type = 2; // shuffle type
vs = states[count]->shuffle(states[i]); vs = states[count]->shuffle(states[i]);
if(vs != NULL && identity(vs) ) { if(vs != nullptr && identity(vs) ) {
xrs.left = count; xrs.left = count;
xrs.right = i; xrs.right = i;
...@@ -384,7 +384,7 @@ bool pdsempty() { ...@@ -384,7 +384,7 @@ bool pdsempty() {
// shuffle i-th state with 'count'-th state // shuffle i-th state with 'count'-th state
vs = states[i]->shuffle(states[count]); vs = states[i]->shuffle(states[count]);
if(vs != NULL && identity(vs) ) { if(vs != nullptr && identity(vs) ) {
xrs.left = i; xrs.left = i;
xrs.right = count; xrs.right = count;
......
...@@ -29,26 +29,26 @@ stpdastate* stpdastate::shuffle(stpdastate *s2) { ...@@ -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 // 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) ) 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 // there should be a push at L and pop at R of state s2
if( !isPush(s2->d1) || !isPop(s2->d2) ) if( !isPush(s2->d1) || !isPop(s2->d2) )
return NULL; return nullptr;
/* ******** THIS IS A HUGE MISTAKE , IN OTHER FILES ALSO *****************, REMOVE THIS /* ******** THIS IS A HUGE MISTAKE , IN OTHER FILES ALSO *****************, REMOVE THIS
// push and pop symbol must be same // push and pop symbol must be same
if( (transitions[s2->d1].ps) != (transitions[s2->d2].pp) ) if( (transitions[s2->d1].ps) != (transitions[s2->d2].pp) )
return NULL; return nullptr;
*/ */
//cout << "ilias" << endl; //cout << "ilias" << endl;
// push-pop edge between L and R of s2 should be added // push-pop edge between L and R of s2 should be added
if( ( (s2->gc) & 1 ) == 0 ) // push-pop edge not added yet if( ( (s2->gc) & 1 ) == 0 ) // push-pop edge not added yet
return NULL; return nullptr;
char gcn; // flag for the new state char gcn; // flag for the new state
...@@ -578,7 +578,7 @@ bool isEmptySTPDA() { ...@@ -578,7 +578,7 @@ bool isEmptySTPDA() {
xrs.right = i; xrs.right = i;
// shuffle, considering rs as left state // shuffle, considering rs as left state
vs = rs->shuffle( states[i] ); vs = rs->shuffle( states[i] );
if(vs != NULL) { // if new state is valid if(vs != nullptr) { // if new state is valid
if( identity(vs) ) { if( identity(vs) ) {
states.push_back(vs); states.push_back(vs);
vrs.push_back(xrs); vrs.push_back(xrs);
...@@ -599,7 +599,7 @@ bool isEmptySTPDA() { ...@@ -599,7 +599,7 @@ bool isEmptySTPDA() {
// shuffle, considering rs as right state // shuffle, considering rs as right state
vs = states[i]->shuffle(rs); vs = states[i]->shuffle(rs);
if(vs != NULL) { // if new state is valid if(vs != nullptr) { // if new state is valid
if( identity(vs) ) { if( identity(vs) ) {
states.push_back(vs); states.push_back(vs);
vrs.push_back(xrs); vrs.push_back(xrs);
......
...@@ -227,7 +227,7 @@ bool stateGCPP::shuffleCheck(stateGCPP *s2) { ...@@ -227,7 +227,7 @@ bool stateGCPP::shuffleCheck(stateGCPP *s2) {
stateGCPP* stateGCPP::shuffle(stateGCPP *s2){ // shuffle with state s2 stateGCPP* stateGCPP::shuffle(stateGCPP *s2){ // shuffle with state s2
if(! shuffleCheck(s2) ) if(! shuffleCheck(s2) )
return NULL; return nullptr;
return reduceShuffle(s2); return reduceShuffle(s2);
} }
...@@ -935,7 +935,7 @@ bool isEmptyGCPP() { ...@@ -935,7 +935,7 @@ bool isEmptyGCPP() {
for(i=0; i < count; i++) { for(i=0; i < count; i++) {
// shuffle, considering rs as left state // shuffle, considering rs as left state
vs = rs->shuffle( allStates[i].first ); 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) ) { if( identity(vs) ) {
xrs = getTrack(2, count, i); // key for the new state xrs = getTrack(2, count, i); // key for the new state
allStates.push_back( make_pair(vs, xrs) ); allStates.push_back( make_pair(vs, xrs) );
...@@ -968,7 +968,7 @@ bool isEmptyGCPP() { ...@@ -968,7 +968,7 @@ bool isEmptyGCPP() {
// shuffle, considering rs as right state // shuffle, considering rs as right state
vs = (allStates[i].first)->shuffle(rs); 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) ) { if( identity(vs) ) {
xrs = getTrack(2, i, count); // key for the new state xrs = getTrack(2, i, count); // key for the new state
allStates.push_back( make_pair(vs, xrs) ); allStates.push_back( make_pair(vs, xrs) );
......
...@@ -113,12 +113,12 @@ bool identity(stateZone *vs) { ...@@ -113,12 +113,12 @@ bool identity(stateZone *vs) {
} }
} }
/*bool findVector(vector <int> vector1, int val) /*bool findVector(vector <int> vector1, int val)
{ {
int n = find(vector1.begin(),vector1.end(),val); int n = find(vector1.begin(),vector1.end(),val);
if( n == vector1.end()) if( n == vector1.end())
return false; return false;
return true; return true;
}*/ }*/
stateZone* stateZone::reduceShuffle(stateZone* s2) { stateZone* stateZone::reduceShuffle(stateZone* s2) {
...@@ -132,13 +132,13 @@ 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 count=0; // used for storing #points in new state
char indexNew; // looping invariant char indexNew; // looping invariant
int lb,ub,openl,openu; 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. 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. stateZone *vs = new stateZone(); // new Shuffled state but not reduced.
vs->del = new char[count]; // allocate memory for the transitions in the state 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->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 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) { ...@@ -153,7 +153,7 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) {
else else
WT1[i][j] = 0; WT1[i][j] = 0;
} }
/*copying the transitions for both the states to this new state*/ /*copying the transitions for both the states to this new state*/
indexNew = count - 1; // index of the last transition of the new state. indexNew = count - 1; // index of the last transition of the new state.
...@@ -168,7 +168,7 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) { ...@@ -168,7 +168,7 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) {
open1[i][i] = false; open1[i][i] = false;
} }
else if(i < m) { 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 if( w[index((i-P), (m-P), P2)] & a32[15] ) // as 15th bit is used for open and close interval
open1[i][m] = true; open1[i][m] = true;
...@@ -177,7 +177,7 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) { ...@@ -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. 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] ) if( w[index((i-P), (m-P), P2)] & a32[15] )
open1[i][m] = true; open1[i][m] = true;
...@@ -186,7 +186,7 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) { ...@@ -186,7 +186,7 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) {
} }
} }
} }
char indexNew1 = indexNew; char indexNew1 = indexNew;
// Here we are copying points of state 2. // Here we are copying points of state 2.
for(int j=P2-1; j >=0; j--,indexNew--) { for(int j=P2-1; j >=0; j--,indexNew--) {
...@@ -198,7 +198,7 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) { ...@@ -198,7 +198,7 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) {
open1[indexNew][indexNew1] = false; open1[indexNew][indexNew1] = false;
} }
else if(j < i) { 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 if( w2[index(j, i, P)] & a32[15] ) // as 15th bit is used for open and close interval
open1[indexNew][indexNew1] = true; open1[indexNew][indexNew1] = true;
...@@ -207,7 +207,7 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) { ...@@ -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. 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] ) if( w2[index(j, i, P)] & a32[15] )
open1[indexNew][indexNew1] = true; open1[indexNew][indexNew1] = true;
...@@ -221,8 +221,8 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) { ...@@ -221,8 +221,8 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) {
//nf |= ( f & a32[j+1] ); // here f means some thing different //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.. //Now before reducing the state we want to check if the state is at all feasible..
// so we run the APSP algo. // so we run the APSP algo.
allPairSP(count); //this is the Floyd–Warshall algorithm implementation allPairSP(count); //this is the Floyd–Warshall algorithm implementation
...@@ -253,7 +253,7 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) { ...@@ -253,7 +253,7 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) {
for(int i=0; i <= count; i++){ for(int i=0; i <= count; i++){
if(WT[i][i] < 0 || open[i][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 short countNew = 1; // var for storing #points in new state after applying forget operation
...@@ -262,7 +262,7 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) { ...@@ -262,7 +262,7 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) {
curReset = 0, reset = 0; curReset = 0, reset = 0;
int prevPoints = 0; int prevPoints = 0;
for(int i=L2; i < P2; i++) 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++) { for(int i=P-1; i >= L; i--,prevPoints++) {
reset = ( transitions[ del[i] ].reset ); reset = ( transitions[ del[i] ].reset );
...@@ -295,6 +295,8 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) { ...@@ -295,6 +295,8 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) {
vs1->del = new char[newcount]; // allocate memory vs1->del = new char[newcount]; // allocate memory
vs1->w = new short[newcount*newcount - newcount]; vs1->w = new short[newcount*newcount - newcount];
vs1->f = f; // **** must edit this for tpda 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; vs1->P = newcount;
...@@ -328,56 +330,56 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) { ...@@ -328,56 +330,56 @@ stateZone* stateZone::reduceShuffle(stateZone* s2) {
//for(i=P-1; i >= L; i--) { //iterating on the points of the first state //for(i=P-1; i >= L; i--) { //iterating on the points of the first state
// current point reset set // current point reset set
/* j = (count - 1) - (P2 - L2);//this is the start of hanging points of state 2 /* 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 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 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 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 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 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 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 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 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 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 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 //and if this point have the a reset point of the clock x
vs->del[j] = del[i]; //copy the transition number vs->del[j] = del[i]; //copy the transition number
//if( ) { // if clock x is reset at point i+1 //if( ) { // if clock x is reset at point i+1
// tighten the lower and upper bounds // tighten the lower and upper bounds
if( (-lb) < WT1[P][i] ) { if( (-lb) < WT1[P][i] ) {
WT1[P][i] = -lb; WT1[P][i] = -lb;
open1[P][i] = (openl & a32[x]); open1[P][i] = (openl & a32[x]);
} }
else if( (-lb) == WT1[i][P] ) else if( (-lb) == WT1[i][P] )
open1[P][i] |= (openl & a32[x]); open1[P][i] |= (openl & a32[x]);
if(ub != INF) { if(ub != INF) {
if(ub < WT1[i][P]) { if(ub < WT1[i][P]) {
WT1[i][P] = ub; WT1[i][P] = ub;
open1[i][P] = (openu & a32[x]); open1[i][P] = (openu & a32[x]);
} }
else if( ub == WT1[i][P] ) else if( ub == WT1[i][P] )
open1[i][P] |= (openu & a32[x]); open1[i][P] |= (openu & a32[x]);
} }
i = -1; i = -1;
} }
//curReset |= reset; //curReset |= reset;
j--; j--;
//lastindex = i; //lastindex = i;
} }
} }
} }
} }
*/ */
//vs->P = count; // #points in new state //vs->P = count; // #points in new state
free(vs); free(vs);
return vs1; return vs1;
...@@ -772,7 +774,7 @@ bool stateZone::shuffleCheck(stateZone *s2) { ...@@ -772,7 +774,7 @@ bool stateZone::shuffleCheck(stateZone *s2) {
stateZone* stateZone::shuffle(stateZone *s2){ // shuffle with state s2 stateZone* stateZone::shuffle(stateZone *s2){ // shuffle with state s2
if(! shuffleCheck(s2) ) if(! shuffleCheck(s2) )
return NULL; return nullptr;
return reduceShuffle(s2); return reduceShuffle(s2);
} }
...@@ -1017,7 +1019,7 @@ stateZone* stateZone::addNextTPDA(char dn) { ...@@ -1017,7 +1019,7 @@ stateZone* stateZone::addNextTPDA(char dn) {
for(i=0; i <= P; i++){ for(i=0; i <= P; i++){
if(WT[i][i] < 0 || open[i][i]) if(WT[i][i] < 0 || open[i][i])
return NULL; return nullptr;
} }
...@@ -1098,61 +1100,61 @@ stateZone* stateZone::addNextTPDA(char dn) { ...@@ -1098,61 +1100,61 @@ stateZone* stateZone::addNextTPDA(char dn) {
// not applied by ilias // not applied by ilias
/*// Return template successor state whose descendent states will be right states for shuffle operation with this state // Return template successor state whose descendent states will be right states for shuffle operation with this state
stateGCPP* stateZone::sucState(){ stateZone* stateZone::sucState(){
short curReset, reset; // temp vars for keeping reset bit vector short curReset, reset; // temp vars for keeping reset bit vector
char count; // will contain #points in the new state char count; // will contain #points in the new state
char i,j; // counters char i,j; // counters
// iterate through all points right to left except the last point // iterate through all points right to left except the last point
curReset = transitions[ del[P-1] ].reset; curReset = transitions[ del[P-1] ].reset;
count = 1; //we have to take the last point, so initialize 'count' to 1 count = 1; //we have to take the last point, so initialize 'count' to 1
for(i=P-2; i >= 0; i--) { for(i=P-2; i >= 0; i--) {
reset = transitions[ del[i] ].reset; // reset bit vector for point i+1 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 if( reset & (~curReset) & (~1) ) { // if (i+1)-th point has additional reset for some clock
count++; count++;
curReset |= reset; curReset |= reset;
} }
} }
stateZone* vs = new stateZone(); // new template state stateZone* vs = new stateZone(); // new template state
vs->P = count; //#points vs->P = count; //#points
//vs->L = count; // no non-trivial block is there there is no L in the zone class //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->del = new char[count]; //allocate space for transition
vs->w = new char[count]; // allocate space for the upper and lower limits 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->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 //vs->w[count-1] = w[P-1]; // have to apply the upper and lower bounds
// copy the necessary points into the template state // copy the necessary points into the template state
char lastindex = P-1; char lastindex = P-1;
short nf = 0; // flag variable for new state //short nf = 0; // flag variable for new state
curReset = transitions[ del[P-1] ].reset; curReset = transitions[ del[P-1] ].reset;
for(i=P-2, j = count-2; i >= 0; i--) { for(i=P-2, j = count-2; i >= 0; i--) {
reset = transitions[ del[i] ].reset; // reset bit vector for point i+1 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 if(reset & (~curReset) & (~1) ) { // found a new necessary point, copy this point to new state
vs->del[j] = del[i]; vs->del[j] = del[i];
vs->w[j] = w[i]; // vs->w[j] = w[i];
if( !big(i+1, lastindex+1) ) //from current needy point to the last found needy point distance small // 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 // nf |= a32[j+1]; // distance (j+1->(j+2)) is small
curReset |= reset; curReset |= reset;
j--; j--;
lastindex = i; // this point is the last point selected till now 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 // vs->f = nf; // copy flag information, no stack info is there till now for the template state
return vs; return vs;
} }
* */
...@@ -1227,56 +1229,68 @@ bool stateZone::isFinal(){ ...@@ -1227,56 +1229,68 @@ bool stateZone::isFinal(){
} }
/*
// return the partial run corresponding the tree automata state 'vs', ignore the hanging points // return the partial run corresponding the tree automata state 'vs', ignore the hanging points
// copy only transitions between L(left) and R(right) // copy only transitions between L(left) and R(right)
runCGPP* getRun(stateGCPP* vs) { runZone* getRunZone(stateZone* vs) {
runCGPP *pr = new runCGPP(); // new partial run stored in variable pr runZone *pr = new runZone(); // 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 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]; // allocate memory for transitions and tsm vlaues for new run
pr->w = new char[pr->P]; pr->del = new char[pr->P];
pr->w = 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 //allocate memory for weight matrix
char i = vs->L - 1, j=0; for(int i = 0; i < pr->P; i++)
{
// copy transitions and tsm values from earlier partial run to new partial run pr->w[i]=new short[pr->P];
for(; i < (vs->P); i++, j++) { }
pr->del[j] = vs->del[i]; // loopers : i used to index transition of the tree automata state and j is used to index trans in the run
pr->w[j] = vs->w[i];
} // 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++) {
return pr; // return the new run 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' // GIVEN the current partial run, append the transition 'dn' with tsm value 'wn'
runCGPP* runCGPP::addNext(char dn, char wn) { // runZone* runZone::addNext(char dn, short wn) {
//
runCGPP *pr = new runCGPP(); // new partial run stored in variable pr // 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 // 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 // // allocate memory for transitions and tsm vlaues for new run
pr->del = new char[pr->P]; // pr->del = new char[pr->P];
pr->w = new char[pr->P]; // pr->w = new short[pr->P];
//
// copy transitions and tsm values from earlier partial run to new partial run // // copy transitions and tsm values from earlier partial run to new partial run
for(char i=0; i < P; i++) { // for(char i=0; i < P; i++) {
pr->del[i] = del[i]; // pr->del[i] = del[i];
pr->w[i] = w[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->del[P] = dn; // add the new transition and tsm value to the last position of new partial run
pr->w[P] = wn; // pr->w[P] = wn;
//
return pr; // return the new run // return pr; // return the new run
} // }
/*
// shuffle two partial runs and return the new partial run // shuffle two partial runs and return the new partial run
runCGPP* runCGPP::shuffle(runCGPP *s2) { runCGPP* runCGPP::shuffle(runCGPP *s2) {
...@@ -1318,7 +1332,7 @@ stateZone* getZeroStateZone() { ...@@ -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->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->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 vs->del[0] = 0; // 0th transition has tsm value 0
...@@ -1393,28 +1407,28 @@ string stateZone::getKeyRight() { ...@@ -1393,28 +1407,28 @@ string stateZone::getKeyRight() {
return s; return s;
} }
/*
// print a run as witness of the given TPDA if the language is non-empty // print a run as witness of the given TPDA if the language is non-empty
void runCGPP::print() { void runZone::print() {
short int lt = 0, ct=0; // lt : last timestamps, ct : current time stamps 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; 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++) { for(char i=0; i < P; i++) {
//
if( w[i] < lt ) // if current time stamps less than last time stamps // if( w[i] < lt ) // if current time stamps less than last time stamps
ct = M + ct + (w[i] - lt); // ct = M + ct + (w[i] - lt);
else // else
ct = ct + (w[i] - lt); // ct = ct + (w[i] - lt);
//
lt = w[i]; // lt = w[i];
cout << "(" << int(del[i]) << ", " << int(ct) << ".0" << "), "; cout << "(" << int(del[i]) << ", " << int(ct) << ".0" << "), ";
} }
cout << endl << endl; cout << endl << endl;
} }
*/
// return a backtracking state with the info given in the parameters // return a backtracking state with the info given in the parameters
trackZone* getTrackZone(char t, int l, int r) { trackZone* getTrackZone(char t, int l, int r) {
...@@ -1427,50 +1441,50 @@ trackZone* getTrackZone(char t, int l, int r) { ...@@ -1427,50 +1441,50 @@ trackZone* getTrackZone(char t, int l, int r) {
return xrs; return xrs;
} }
/*
// get the run of the timed system // 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 == "", 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 // 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) { runZone* printRunZone(int i) {
stateGCPP* vs; // tree automata state variable stateZone* vs; // tree automata state variable
trackCGPP *bp; // back tracking state trackZone *bp; // back tracking state
vs = allStates[i].first; vs = allStatesZone[i].first;
bp = allStates[i].second; bp = allStatesZone[i].second;
runCGPP *rs, *rs1, *rs2; runZone *rs, *rs1, *rs2;
// if the i-th state is an atomic state // if the i-th state is an atomic state
if( (bp->type) == 0 ) { if( (bp->type) == 0 ) {
cout << endl << i << ":"; cout << endl << i << ":";
vs->print(); vs->print();
return getRun(vs); // return the run generated from atomic state 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 // if the considerted state is generated by an addNext operation from a state in the main vector
else if( (bp->type) == 1 ) { else if( (bp->type) == 1 ) {
rs1 = printRun( bp->left ); rs1 = printRunZone( bp->left );
rs = rs1->addNext(vs->del[vs->P - 1], vs->w[vs->P - 1]); //rs = rs1->addNext(vs->del[vs->P - 1], vs->w[vs->P - 1]);
cout << endl << i << " : " << (bp->left); cout << endl << i << " : " << (bp->left);
vs->print(); vs->print();
return rs; return rs;
} }
else{ else{
rs1 = printRun( bp->left); rs1 = printRunZone( bp->left);
rs2 = printRun(bp->right); rs2 = printRunZone(bp->right);
rs = rs1->shuffle(rs2); //rs = rs1->shuffle(rs2);
cout << endl << i << " : " << (bp->left) << ", " << (bp->right); cout << endl << i << " : " << (bp->left) << ", " << (bp->right);
vs->print(); vs->print();
return rs; return rs;
} }
} }
*/
// return true iff language recognized by the TPDA is empty // return true iff language recognized by the TPDA is empty
...@@ -1482,7 +1496,7 @@ bool isEmptyZone() { ...@@ -1482,7 +1496,7 @@ bool isEmptyZone() {
return false; return false;
} }
int i,j; // counters //int i,j; // counters
bool pushl, pushr, popl, popr, ppDone; bool pushl, pushr, popl, popr, ppDone;
// allocate memory for two weight matrix and their corresponding open vars used shortest path operations // allocate memory for two weight matrix and their corresponding open vars used shortest path operations
// K : maximum #points in a state // K : maximum #points in a state
...@@ -1492,7 +1506,7 @@ bool isEmptyZone() { ...@@ -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 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]; 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]; WT1[i] = new short[K+2];
WT2[i] = new short[K+2]; WT2[i] = new short[K+2];
...@@ -1551,10 +1565,10 @@ bool isEmptyZone() { ...@@ -1551,10 +1565,10 @@ bool isEmptyZone() {
//cout << "Parents: " << (xrs->left) << ", " << (xrs->right) << endl << "--------------" << endl; //cout << "Parents: " << (xrs->left) << ", " << (xrs->right) << endl << "--------------" << endl;
del = rs->del; del = rs->del;// getting the transitions of the point
P = rs->P; P = rs->P; // getting the number of points of the point
f = rs->f; f = rs->f; // getting the L and the push flag
L = f & 127; L = f & 127;// extracting the value of L.
pushl = isPush( del[L - 1] ); // pushl = 1 iff there is a push at 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 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 popl = isPop( del[L - 1] ); // popl = 1 iff there is a pop at L
...@@ -1562,13 +1576,59 @@ bool isEmptyZone() { ...@@ -1562,13 +1576,59 @@ bool isEmptyZone() {
ppDone = (f & 1) ; // if push at L and pop at R is done in rs 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 // 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 else
{ {
...@@ -1578,12 +1638,12 @@ bool isEmptyZone() { ...@@ -1578,12 +1638,12 @@ bool isEmptyZone() {
// iterate through all the upcoming transitions // iterate through all the upcoming transitions
//this is only add operations we have to find way to suffle and //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 dn = nexttrans[q][i]; // i-th upcoming transition
vs = rs->addNextTPDA(dn); // get set of states after doing the add operation 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(); //vs->print();
if( identity(vs) ) { if( identity(vs) ) {
xrs = getTrackZone(1, count, -1); // key for the new state xrs = getTrackZone(1, count, -1); // key for the new state
...@@ -1634,6 +1694,24 @@ bool isEmptyZone() { ...@@ -1634,6 +1694,24 @@ bool isEmptyZone() {
rs->print(); 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; 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