Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cmath>
- using namespace std;
- class state
- {
- public:
- string id;
- double *q2;
- };
- class CTMC
- {
- public:
- state * Q;
- int states;
- CTMC(int nos) {
- Q = new state[nos];
- states = nos;
- for (int i = 0; i < nos; i++)
- {
- Q[i].id = i;
- Q[i].q2 = new double[nos];
- double sum = -1;
- for (int j = 0; j < nos; j++)
- {
- cout << "enter value for Q " << i + 1 << j + 1 << " : " ;
- cin >> Q[i].q2[j];
- if (i == j)
- Q[i].q2[j] = 0;
- sum += Q[i].q2[j];
- }
- cout << endl;
- cout << "-------------------------" << endl;
- if (sum == -1)
- {
- cout << "invalid inputs, try again!"<<endl;
- i -= 1;
- }
- }
- }
- double V(int n) {
- double v = 0;
- for (int i = 0; i < states; i++)
- {
- v += Q[n-1].q2[i];
- }
- return v;
- }
- double Exp(int n) {
- double ex;
- ex = 1 / V(n);
- return ex;
- }
- double P(int i, int j)
- {
- double p;
- p = Q[i-1].q2[j-1] / V(i);
- return p;
- }
- double less(int i, int min)
- {
- double less;
- less = 1 - (exp(-V(i)*min));
- return less;
- }
- double more(int i, int min)
- {
- double more;
- more = 1 - less(i, min);
- return more;
- }
- double lessToj (int i, int min , int j )
- {
- double less;
- less = (1 - (exp(-V(i)*min)) ) * P(i,j);
- return less;
- }
- double more(int i, int min, int j)
- {
- double more;
- more = (1 - (1 - (exp(-V(i)*min)))) * P(i,j);
- return more;
- }
- double T(int i, int vis)
- {
- return (Exp(i)* vis);
- }
- };
- int main()
- {
- int nos; //Number of states
- int i, j , min , visits; //inset indices for matrix and minutes
- cout << "Enter the number of states : ";
- cin >> nos;
- cout << endl;
- CTMC k(nos);
- cout << "enter i and j : ";
- cin >> i >> j;
- cout << "V" << i << " : " << k.V(i) <<endl;
- cout << "Exp[" << i << "] : " << k.Exp(i)<<endl;
- cout << "P " << i<<j << " : " << k.P(i, j)<<endl;
- cout << "Enter # of mins : ";
- cin >> min;
- cout << "P(T<="<<min << ") : " << k.less(i, min) << endl;
- cout << "P(T>=" << min << ") : " << k.more(i, min) << endl;
- cout << "Enter # of visits : ";
- cin >> visits;
- cout << "T" << 2 << " : " << k.T(i, visits) << endl;
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement