////求Petri网的S-不变量和T-不变量的程序,给出的是求T不变量的,求S-不变量只需要将矩阵转置。Petri网 /////经常用于通信和网络协议的验证,但是直接由矩阵求不变量非常麻烦,故本文将代码共享。 #include <iostream.h> #include <math.h> int main() { int row,column; int matrix[50][50]; ////Petri网关联矩阵 int answer[50]; ///求得的不变量 cout << "please input the row num of matrix:" ; cin >> row; cout << "please input the column num of matrix:" ; cin >> column; cout << "please input information of matrix:" << endl; for(int i=0;i<row;i++) { for(int j=0;j<column;j++) { cin >> matrix[i][j]; } } long power=pow(2,column); int total[50]; for(i=1;i<power;i++) { for(int j=0;j<column;j++) { answer[j]=(i>>j)&0x01; } for(int x=0;x<row;x++) { total[x]=0; for(int y=0;y<column;y++) { total[x]+=answer[y]*matrix[x][y]; } if(total[x]!=0) break; } if(x==row) { cout << "get a column sequence:" << endl; for(x=0;x<column;x++) { cout << answer[x] << " "; } cout << endl; } } } 月影孤鸿 华中科技大学计算机学院 [email protected] 
|