Commit 04d3e929 authored by SPARSA ROYCHOWDHURY's avatar SPARSA ROYCHOWDHURY

25/10/17:

1. Time Automata Working
2. A lot change is done in the function reduceshuffle and a lot of work still need to be done else you will be welcome with a segmentation fault.

Sparsa Roychowdhury
parent 5b4e7740
......@@ -26,6 +26,7 @@ class stateGCPP{
relation **r_matrix; // the matrix of relation which denotes the relation between the points fractional part. clearly the size of the matrix is P*P as p is the total number of active colors.
void allocate_r_matrix();
void allocate_r_matrix(relation r);
relation **allocate_r_matrix(char P);
void delete_r_matrix();
void delete_r_matrix(relation **matrix,char P);
......
......@@ -13,5 +13,5 @@
0
2 3 0 1 0
1 1 0 2 0
1 1 0 2 1
0
......@@ -18,4 +18,4 @@
0
3 4 0 0 0
2 1 1 0 2 0
2 1 1 0 2 1
......@@ -7,5 +7,5 @@ digraph finite_state_machine {
1 -> 1 [ label = "{tn:1,x1:=0}" ];
1 -> 2 [ label = "{tn:2,ps_1}" ];
2 -> 3 [ label = "{tn:3,2<=x1<=2}" ];
3 -> 4 [ label = "{tn:4,pp_1,1<=x2<=2}" ];
3 -> 4 [ label = "{tn:4,pp_1,1<=ag(1)<=2}" ];
}
\ No newline at end of file
input1/test2.png

22.3 KB | W: | H:

input1/test2.png

23.2 KB | W: | H:

input1/test2.png
input1/test2.png
input1/test2.png
input1/test2.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -87,8 +87,9 @@
<runcommandpicklistitem>"${OUTPUT_PATH}" /home/sparsa/Programming/mtp/input/pd1</runcommandpicklistitem>
<runcommandpicklistitem>"${OUTPUT_PATH}" /home/sparsa/Programming/mtp/input/tp2_</runcommandpicklistitem>
<runcommandpicklistitem>"${OUTPUT_PATH}" /home/sparsa/Programming/mtp/input/tp2_0</runcommandpicklistitem>
<runcommandpicklistitem>"${OUTPUT_PATH}" /home/sparsa/Programming/mtp/input1/test2</runcommandpicklistitem>
</runcommandpicklist>
<runcommand>"${OUTPUT_PATH}" /home/sparsa/Programming/mtp/input/tp2_0</runcommand>
<runcommand>"${OUTPUT_PATH}" /home/sparsa/Programming/mtp/input1/test2</runcommand>
<rundir>.</rundir>
<buildfirst>false</buildfirst>
<terminal-type>0</terminal-type>
......
......@@ -21,9 +21,10 @@ vector<pair<stateGCPP*, trackCGPP*> > allStates;
void print_r_matrix(relation** r_matrix,char p)
{
string sarr[4] = {"0","<","<=","?"};
for(char i = 0; i < p; i++){
for(char j =0; j < p; j++)
cout << r_matrix[i][j] << '\t' ;
cout << sarr[r_matrix[i][j]] << '\t' ;
cout << endl;
}
cout << endl;
......@@ -86,7 +87,7 @@ stateGCPP* stateGCPP::reduceShuffle(stateGCPP* s2) {
char *del2 = s2->del, *w2 = s2->w;
char P2 = s2->P, L2 = s2->L;
short f2 = s2->f;
char map1[L2-1];//mapping points from state 2 to state 1 including the L2 point.
short curReset, reset, tempReset,reset2,curReset2; // temp variables to keep reset for a range of points
char count=0; // used for storing #points in new state
char i, j; // loopers
......@@ -96,12 +97,12 @@ stateGCPP* stateGCPP::reduceShuffle(stateGCPP* s2) {
// take union of resets for points between s2->L+1(including) and s2->P(including)
curReset = 0;
for(i=L2; i < P2; i++)
for(char i=L2; i < P2; i++)
curReset |= ( transitions[ del2[i] ].reset ); //getting reset points im the non trivial block of state2
tempReset = curReset; // store this value for later use
for( i=P-1; i >= L; i--) {
for( char i=P-1; i >= L; i--) {
reset = ( transitions[ del[i] ].reset );
/* there is a bit '1' of 'reset' but '0' of 'curReset' at same position => there is a clock
......@@ -111,10 +112,44 @@ stateGCPP* stateGCPP::reduceShuffle(stateGCPP* s2) {
curReset |= reset; // union reset set at this point with earlier set
}
}
// addition of 'L' below comes from the fact that all point from 1 to L of first state is there in new state
// addition of 'L' below comes from the fact that all point from 1 to L of first state is there in new state
// (s2->P - s2-> L) comes from : all points s2->L+1 to s2->P are there in new state
count += L + (P2 - L2); // #points in new state
///////////////new addition//////////
curReset = transitions[s2->del[L2-1]].reset; //reset points onthe left point of state 2
char index = L2-2; //L2-1 elements
for(char i = P-2; i >=0; i--) // I am not including the L2 == P here
{
reset =(transitions[del[i]].reset);
if(reset & (~curReset) & (~1))
{
map1[index] = i; //copy the index of the current state.
index --;
curReset |= reset;
}
}
//////////map1 contains the mapping to first state from second state.
char map_p1[P]; //contains the mapping from the state1 to matrix
char map_p2[P2]; // contains the mapping from the state2 to matrix
for(char i = 0; i < P; i++)
map_p1[i] = i;
index = P;
for(char i= 0; i <P2; i++)
{
if(i<L2-1)
{
map_p2[i] = map_p1[map1[i]];
}
else
{
map_p2[i] = index;
index++;
}
}
stateGCPP *vs = new stateGCPP(); // new TA state
......@@ -123,35 +158,54 @@ stateGCPP* stateGCPP::reduceShuffle(stateGCPP* s2) {
vs->del = new char[count]; // allocate memory
vs->w = new char[count];
vs->L = L;
vs->allocate_r_matrix(que);
vs->r_matrix = allocate_r_matrix(count);
char points_before_reduce = P+P2-L2;
relation **storage_matrix = allocate_r_matrix(points_before_reduce);
for(char i = 0; i < P; i++)
for(char j =0 ; j < P; j++)
{
storage_matrix[i][j] = r_matrix[i][j];
}
for(char i = 0;i <P2 ;i++)
for(char j = 0; j <P2;j++)
{
if(storage_matrix[map_p2[i]][map_p2[j]] > s2->r_matrix[i][j])
storage_matrix[map_p2[i]][map_p2[j]] = s2->r_matrix[i][j];
}
pairWiseTightestRelation(storage_matrix,(points_before_reduce));
char map[count];
short nf = 0; // initially flag is zero
short dis; // distance variable
// j = count-1; // index of the rightmost point of new state
j = count-1; // index of the rightmost point of new state
// Here we are copying points from s2->L+1 to s2->P of 2nd state to new state
for(int i=P2 - 1,j = count - 1; i >= L2; i--, j--) {
for(char i=P2 - 1; i >= L2; i--, j--) {
vs->del[j] = del2[i]; // copy (i+1)-th transition to (j+1) transition of new state
vs->w[j] = w2[i]; // copy (i+1)-th tsm to (j+1) tsm of new state
for(int a=P2-1, b = count-1; i>=L2; i--,j--)
{
if(vs->r_matrix[j][b] > s2->r_matrix[i][a])
vs->r_matrix[j][b] = s2->r_matrix[i][a];
}
map[j] = map_p2[i];
// for(char a=P2-1, b = count-1; a>=L2; a--,b--)
// {
// if(vs->r_matrix[j][b] > s2->r_matrix[i][a])
// vs->r_matrix[j][b] = s2->r_matrix[i][a];
// }
// if distance (i+1)->(i+2) of 2nd state is accurate, then distance (j+1)->(j+2) of new state is accurate
if( f2 & a32[i+1] )
nf |= a32[j+1];
}
// Here we are copying points from 1 to L-1 of 1st state to new state
for(int j=0; j < (L-1); j++) {
for( j=0; j < (L-1); j++) {
vs->del[j] = del[j];
vs->w[j] = w[j];
for(int a = 0 ; a < (L-1) ; a ++)
{
if(vs->r_matrix[j][a] > r_matrix[j][a])
vs->r_matrix[j][a] = r_matrix[j][a];
}
map[j] = map_p1[j];
// for(int a = 0 ; a < (L-1) ; a ++)
// {
// if(vs->r_matrix[j][a] > r_matrix[j][a])
// vs->r_matrix[j][a] = r_matrix[j][a];
// }
// if distance (j+1)->(j+2) of 1st state is accurate, then distance (j+1)->(j+2) of new state is accurate
nf |= ( f & a32[j+1] );
}
......@@ -159,33 +213,35 @@ stateGCPP* stateGCPP::reduceShuffle(stateGCPP* s2) {
//copy the point L, doing it separately because of the flag variable which is not applicable for L-th point
vs->del[L-1] = del[L-1];
vs->w[L-1] = w[L-1];
for(int i = 0 ; i < L ;i++)
{
vs->r_matrix[vs->P-1][i] = r_matrix[P-1][i];
vs->r_matrix[i][vs->P-1] = r_matrix[i][P-1];
}
// for(int i = 0 ; i < L ;i++)
// {
// vs->r_matrix[vs->P-1][i] = r_matrix[P-1][i];
// vs->r_matrix[i][vs->P-1] = r_matrix[i][P-1];
// }
// Now we watch out for points from L+1 to P of 1st state
char lastindex = P;// last index of the point we have taken so far, although P might not be included
curReset2 = curReset = tempReset; //get the union of resets for points between s2->L+1 and s2->P
// current indices j of new state we have to take care
//j = (count - 1) - (P2 - L2);
for(int i=P-1,j = (count - 1) - (P2 - L2); i >= L; i--) {
j = (count - 1) - (P2 - L2);
for( i=P-1,j = (count - 1) - (P2 - L2); i >= L; i--) {
reset = ( transitions[ del[i] ].reset ); // current point reset set
if( reset & (~curReset) & (~1) ) { // if current point has more reset then seen earlier
vs->del[j] = del[i];
vs->w[j] = w[i];
for(int a = P-1, b = (count -1) - (P2 - L2); a >= L; a--)
{
reset2 = (transitions[del[a]].reset);
if(reset2 &(!curReset2) & ~(1))
{
vs->r_matrix[j][b] = r_matrix[i][a];
curReset2 |= reset2;
b--;
}
}
map[j] = map_p1[j];
// char b = (count -1) - (P2 - L2);
// for(char a = P-1; a >= L; a--)
// {
// reset2 = (transitions[del[a]].reset);
// if(reset2 &(!curReset2) & ~(1))
// {
// vs->r_matrix[j][b] = r_matrix[i][a];
// curReset2 |= reset2;
// b--;
// }
// }
if( lastindex == P ) { // if (i+1) is the first point we are considering after starting the loop
// In if : first check is for accuracy check from L to P of left state
// In if : second check is for cheking accuracy from L2 to L2+1 of right state, L2 is not choosen
......@@ -231,7 +287,17 @@ stateGCPP* stateGCPP::reduceShuffle(stateGCPP* s2) {
vs->f = nf; // add the flag variable also
//vs->P = count; // #points in new state
cout << int(count) << "the cound " << endl;
// for(char i = 0 ; i < count ; i++)
// cout << int(map[i]) << endl;
for(char i = 0; i < count ; i ++)
for(char j = 0 ; j < count ; j++)
{
vs->r_matrix[i][j] = storage_matrix[map[i]][map[j]];
}
pairWiseTightestRelation(vs->r_matrix,vs->P);
delete_r_matrix(storage_matrix,points_before_reduce);
return vs;
}
......@@ -245,9 +311,10 @@ bool stateGCPP::shuffleCheck(stateGCPP *s2) {
return false;
// there should be a push at L of s2 and pop at R of s2, note : del[P-1] = del2[P2-1]
//cout << int(s2->del[s2->L-1]) <<" " << int(s2->del[s2->P-1]) << endl;
if( !isPush( s2->del[s2->L-1] ) || !isPop( s2->del[s2->P-1] ) )
return false;
//cout << "test" << endl;
if( !( (s2->f) & 1 ) || !( (s2->f) & a3215 ) ) // push-pop edge should be connected in right state
return false;
......@@ -588,7 +655,7 @@ bool stateGCPP::consSatisfied(stateGCPP* vs,char dn, char wn, short *clockDis, b
CircuitFinder cf(vs->r_matrix,vs->P);
bool b = cf.run();
if(b){
//print_r_matrix(store_matrix,vs->P);
//print_r_matrix(vs->r_matrix,vs->P);
//cout << b <<endl;
//delete_r_matrix(store_matrix,vs->P);
......@@ -636,8 +703,9 @@ bool stateGCPP::consSatisfied(stateGCPP* vs,char dn, char wn, short *clockDis, b
// situation : we are trying to add trans 'dn' with tsm 'wn' to the right of current state
// check for stack constraint where dlr and aclr are distance and accuracy from L to R resp.
bool stateGCPP::stackCheck(stateGCPP* vs,char dn, char wn, short dlr, bool aclr) {
//cout << int(dn) << endl;
int ub = transitions[dn].ubs[0];// the stacks upper bound
int lb = transitions[dn].lbs[0];
//int lb = transitions[dn].lbs[0];
// int openl,openu; //added extra
// openl = transitions[dn].openl;
// openu = transitions[dn].openu;
......@@ -651,9 +719,11 @@ bool stateGCPP::stackCheck(stateGCPP* vs,char dn, char wn, short dlr, bool aclr)
// }
// }
if(aclr) { // if distance from L to R is small
// if(dn == 4)
// cout << "true aclr" << endl;
short dis = dlr + mod( wn - w[P-1], M ); // mark
char t = vs->L-1; //the source of push must be L.
if( ( dis < lb ) || dis > ub )
if( ( dis < transitions[dn].lbs[0] ) || dis > ub )
{// check if d(source,destination) \in I
//delete_r_matrix(store_matrix,vs->P);
return false;
......@@ -692,16 +762,23 @@ bool stateGCPP::stackCheck(stateGCPP* vs,char dn, char wn, short dlr, bool aclr)
// // Hence (j,i) \in R_<
// }
//pairWiseTightestRelation(store_matrix,vs->P);
else if( dis == lb || dis == ub)
else if( dis == transitions[dn].lbs[0] || dis == ub)
{
CircuitFinder cf(vs->r_matrix,vs->P);
bool b = cf.run();
if(b)
if(b){
//print_r_matrix(vs->r_matrix,vs->P);
return false;
}
else if(dn ==4)
{
//print_r_matrix(vs->r_matrix,vs->P);
}
}
else
return true;
//#pragma openmp parallel for
// for(int i = 0 ;i < vs->P; i++)
// {
......@@ -714,10 +791,10 @@ bool stateGCPP::stackCheck(stateGCPP* vs,char dn, char wn, short dlr, bool aclr)
}
else if(ub == INF) // if distance from L to R is big
return true;
else if(ub != INF) // if distance from L to R is big
return false;
//delete_r_matrix(store_matrix,vs->P);
return false; // distance is big, but upper bound is not infinity
return true; // distance is big, but upper bound is not infinity
}
......@@ -754,7 +831,7 @@ vector<stateGCPP*> stateGCPP::addNextTPDA() {
for(char i=0; i < nexttrans[q].size(); i++) {
dn = nexttrans[q][i]; // i-th upcoming transition
//cout << int(dn) << endl;
popflag = isPop(dn); // popflag = 1 iff there is a pop at transition 'dn'
// if there is a pop at 'dn', but no push at L in this state, don't do anything
......@@ -771,7 +848,7 @@ vector<stateGCPP*> stateGCPP::addNextTPDA() {
// add next transition to this state if possible and return all generated states by doing this operation
//cout << int(dn)<<endl;
// stateGCPP* vs1 = nextDummy(dn); // get partial new state after adding transition 'dn'(TSM for 'dn' not known yet)
//cout << int(dn) << endl;
short *clockDis = new short[X + 1]; // distance from last reset of clock x to point P, stored in clockDis[x]
bool *clockAcc = new bool[X + 1]; // accuracy from last reset of clock x to point P, stored in clockAcc[x]
......@@ -816,6 +893,7 @@ vector<stateGCPP*> stateGCPP::addNextTPDA() {
else { // if clock and stack both constraints are satisfied
// stateGCPP* vs = vs1->reduce(dn);
// delete vs1;
//cout << int(dn) << endl;
stateGCPP* rs = new stateGCPP();
rs->L = L; // left point remain same
......@@ -920,6 +998,7 @@ stateGCPP* stateGCPP::sucState(){
int map[count]; // mapping array to map points from current state to new state
map[count-1]= P-1;
stateGCPP* vs = new stateGCPP(); // new template state
vs->P = count; //#points
......@@ -1346,11 +1425,18 @@ bool isEmptyGCPP() {
// store current state info in variables for shortcut use
del = rs->del;
P = rs->P;
//cout << int(P) << endl;
L = rs->L;
//cout << int(L) << endl;
//cout << endl;
f = rs->f;
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
//cout << pushr << endl;
//cout << endl;
popl = isPop( del[L - 1] ); // popl = 1 iff there is a pop at L
popr = isPop( del[P - 1] ); // popr = 1 iff there is a pop at R
ppDone = (f & 1) && (f & a3215) ; // if push at L and pop at R is done in rs
......@@ -1711,10 +1797,19 @@ stateGCPP* stateGCPP::reduce2(char dn,char wn,short* clockDis,bool* clockAcc,sho
// Hence (j,i) \in R_<
}
}
// if(dn==4){
// cout << "_______________________" << endl;
// print_r_matrix(store_matrix,P+1);
// }
pairWiseTightestRelation(store_matrix,P+1);
//print_r_matrix(store_matrix,P+1);
// print_r_matrix(store_matrix,P+1);
// if(dn==4){
//
// print_r_matrix(store_matrix,P+1);
// cout << "_______________________" << endl;
// }
short curReset = transitions[dn].reset; // set of clocks reset at transition 'dn'
for( char i=P-1; i >= L; i-- ) {
......
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