Created
October 13, 2017 13:47
-
-
Save Zulcom/9b0ce2cf9fca151a1a76d449396262d9 to your computer and use it in GitHub Desktop.
Make Petri (PT) net language from incidence matrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdio.h> | |
#include <string.h> | |
#include <clocale> | |
#include <string> | |
#include <set> | |
#include <fstream> | |
using namespace std; | |
const int countP = 6; | |
const int countT = 6; | |
int Fp[countP][countT] = | |
{ | |
1, 0, 0, 1, 0, 0, | |
1, 1, 1, 1, 0, 0, | |
0, 1, 1, 0, 0, 0, | |
0, 0, 0, 0, 1, 0, | |
0, 0, 0, 0, 1, 1, | |
0, 0, 0, 0, 1, 0, | |
}; | |
int Ft[countT][countP] = | |
{ | |
1, 0, 0, 0, 0, 0, | |
0, 0, 1, 0, 0, 0, | |
1, 0, 0, 2, 0, 0, | |
0, 0, 1, 0, 2, 0, | |
0, 0, 0, 0, 0, 1, | |
0, 0, 1, 0, 0, 1, | |
}; | |
int M0[countP] = {2,2,2,1,1,1}; | |
//Переход j сработает в том случае, если для каждого элемента множества Pj | |
//выполняется условие M0[i] - Fp[i][j] >= 0 | |
bool isPossibleToTransit(int M[countP], int j) | |
{ | |
bool isPossible = true; | |
for(int i = 0; i < countP; i++) | |
if(Fp[i][j] > 0) | |
if(M[i] - Fp[i][j] < 0) | |
isPossible = false; | |
return isPossible; | |
} | |
void printInfoAboutTransition(int j) | |
{ | |
ofstream out("out.txt",ios::app); | |
out <<endl<<endl<< "======================" << endl<<endl; | |
out << "Для планки: t" << j + 1 << endl << endl << "Входные кругляши: " << endl; | |
for(int i = 0; i < countP; i++) | |
if(Fp[i][j] > 0) | |
out << "Кругляш: p" << i + 1 << "-" << Fp[i][j] << endl; | |
out << endl << "Выходные кругляши: " << endl; | |
for(int i = 0; i < countP; i++) | |
if(Ft[j][i] > 0) | |
out << "Кругляш: p" << i + 1 << "-" << Fp[j][i] << endl; | |
//system("pause"); | |
out.close(); | |
} | |
//срабатывает переход j при маркировке M | |
void transit(int(&M)[countP], int j) | |
{ | |
if(isPossibleToTransit(M, j)) | |
{ | |
for(int i = 0; i < countP; i++) | |
if(Fp[i][j] > 0) | |
M[i] = M[i] - Fp[i][j] + Ft[j][i]; | |
for(int i = 0; i < countP; i++) | |
if(Ft[j][i] > 0) | |
M[i] = M[i] + Ft[j][i]; | |
printInfoAboutTransition(j); | |
} | |
} | |
std::set<std::string> makeDictonary(int M[countP], int time, std::string word = "") | |
{ | |
std::set<std::string> words; | |
if(time > 0 && time < 5) | |
{ | |
for(int i = 0; i < countT; i++) | |
if(isPossibleToTransit(M, i)) | |
{ | |
std::string newWord = word + std::to_string(i + 1); | |
words.insert(newWord); | |
int M1[countP]; | |
for(int k = 0; k < countP; k++) | |
M1[k] = M[k]; | |
transit(M1, i); | |
std::set<std::string> anotherWords = makeDictonary(M1, time + 1, newWord); | |
words.insert(anotherWords.begin(), anotherWords.end()); | |
int sum = M1[0] + M1[1] + M1[2] + M1[3] + M1[4] + M1[5]; | |
//if (sum > 10) cout << "Сумма: " << sum << endl; | |
printInfoAboutTransition(i); | |
} | |
} | |
return words; | |
} | |
int main() | |
{ | |
setlocale(LC_ALL, "Russian"); | |
std::set<std::string> words = makeDictonary(M0, 1);; | |
ofstream out("out.txt", ios::app); | |
for(std::set<std::string>::const_iterator it = words.begin(); it != words.end(); it++) | |
out << (*it).c_str() << endl; | |
out.close(); | |
system("pause"); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment