Skip to content

Commit a6ae6e8

Browse files
committed
Done
0 parents  commit a6ae6e8

12 files changed

+506
-0
lines changed

.vscode/launch.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"configurations": [
3+
{
4+
"type": "java",
5+
"name": "CodeLens (Launch) - CA1",
6+
"request": "launch",
7+
"cwd": "${workspaceFolder}",
8+
"console": "internalConsole",
9+
"stopOnEntry": false,
10+
"mainClass": "CA1",
11+
"args": ""
12+
}
13+
]
14+
}

CA1.class

2.66 KB
Binary file not shown.

CA1.java

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/**
2+
* @author Alireza Kavian - kay.alireza@gmail.com
3+
* Petrinet Incident Matrix
4+
* 11/14/2018
5+
*/
6+
7+
/*
8+
[D] = [(D+)] - [(D-)]
9+
[Next Marking Matrix] = ([Transition Matrix][D]) + [Marking Matrix]
10+
*/
11+
12+
import java.io.*;
13+
import java.util.ArrayList;
14+
import java.util.Scanner;
15+
16+
public class CA1 {
17+
public static void main(String[] args) throws IOException {
18+
Petrinet pn = new Petrinet("");
19+
run(pn);
20+
// __UNIT_TEST__(pn);
21+
}
22+
23+
public static void run(Petrinet pn) {
24+
Scanner in = new Scanner(System.in);
25+
System.out.print("How many marking matrix derivations do you wanna be calculated??? ");
26+
int num_calc = in.nextInt();
27+
System.out.print("How many marking matrix derivations do you wanna be dumped??? ");
28+
int num_see = in.nextInt();
29+
System.out.println("************");
30+
31+
Integer[][] marklist = pn.MarkingMatrixToState(num_calc);
32+
System.out.println("| First " + num_see + " marking matrices derived from M0 |\n--------------");
33+
pn.__showMatrixInteger_mxn(marklist, num_see);
34+
System.out.println("--------------");
35+
36+
// check safeness
37+
/*
38+
** It is safe if all the places in all `Markings` don't exceed having upto 1 token
39+
*/
40+
boolean safe_flag = true;
41+
for (int i = 0; i < marklist.length; i++) {
42+
for (int j = 0; j < marklist[i].length; j++) {
43+
if (marklist[i][j] > 1) {
44+
safe_flag = false;
45+
}
46+
}
47+
}
48+
System.out.println("Is It Safe ? " + (safe_flag ? "YES" : "NO"));
49+
50+
// check liveness
51+
/*
52+
** It is live if all elements of`Transition `Matrices` in all the particular markings, have upto 1 firings
53+
*/
54+
boolean live_flag = true;
55+
ArrayList<Integer[]> tmatrices = pn.getTmatrices();
56+
for (int i = 0; i < tmatrices.size(); i++) {
57+
for (int j = 0; j < tmatrices.get(i).length; j++) {
58+
if (marklist[i][j] == 0) {
59+
live_flag = false;
60+
break;
61+
}
62+
}
63+
if(!live_flag){
64+
break;
65+
}
66+
}
67+
System.out.println("Is It Live ? " + (live_flag ? "YES" : "NO"));
68+
69+
in.close();
70+
}
71+
72+
//---------------------------------------------------//
73+
// TEST
74+
public static void __UNIT_TEST__(Petrinet pn) {
75+
pn.__show("M");
76+
System.out.println("");
77+
pn.__showMatrixInteger_mxn(pn.getD_Minus());
78+
System.out.println("");
79+
pn.__showMatrixInteger_mxn(pn.getD_Plus());
80+
System.out.println("");
81+
pn.__showMatrixInteger_mxn(pn.getD());
82+
System.out.println("");
83+
pn.__showMatrixInteger_1xn(pn.getTransitionMatrix());
84+
System.out.println("");
85+
pn.__showMatrixInteger_1xn(pn.getNextMarkingMatrix());
86+
pn.__showMatrixInteger_mxn(pn.MarkingMatrixToState(150));
87+
}
88+
}

CA1.pdf

26.4 KB
Binary file not shown.

IncidentMatrix.class

697 Bytes
Binary file not shown.

IncidentMatrix.java

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import java.util.*;
2+
import javafx.util.Pair;
3+
4+
public interface IncidentMatrix {
5+
6+
public Integer[][] D_Minus(ArrayList<String> P, ArrayList<String> T, ArrayList<Pair> F);
7+
8+
public Integer[][] D_Plus(ArrayList<String> P, ArrayList<String> T, ArrayList<Pair> F);
9+
10+
public Integer[][] D(Integer[][] d_minus, Integer[][] d_plus);
11+
12+
public Integer[] TransitionMatrix(Integer[][] d_minus, Integer[] markingMatrix);
13+
14+
public Integer[] NextMarkingMatrix(Integer[][] d, Integer[] transitionMatrix, Integer[] markingMatrix);
15+
16+
}

Matrix.class

1.48 KB
Binary file not shown.

Matrix.java

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
/**
3+
* Matrix
4+
*/
5+
import java.util.*;
6+
7+
public class Matrix {
8+
public static Integer[][] multiplicar(Integer[][] A, Integer[][] B) {
9+
int aRows = A.length;
10+
int aColumns = A[0].length;
11+
int bRows = B.length;
12+
int bColumns = B[0].length;
13+
14+
if (aColumns != bRows) {
15+
throw new IllegalArgumentException("A:Rows: " + aColumns + " did not match B:Columns " + bRows + ".");
16+
}
17+
Integer[][] product = new Integer[aRows][bColumns];
18+
for (int i = 0; i < aRows; i++) {
19+
for (int j = 0; j < bColumns; j++) {
20+
product[i][j] = 0;
21+
}
22+
}
23+
for (int i = 0; i < aRows; i++) { // aRow
24+
for (int j = 0; j < bColumns; j++) { // bColumn
25+
for (int k = 0; k < aColumns; k++) { // aColumn
26+
product[i][j] += A[i][k] * B[k][j];
27+
}
28+
}
29+
}
30+
return product;
31+
}
32+
33+
public static Integer[][] subMatricesInteger(Integer[][] A, Integer[][] B) {
34+
Integer[][] sub = new Integer[A.length][];
35+
for (int i = 0; i < A.length; i++) {
36+
sub[i] = new Integer[A[i].length];
37+
for (int j = 0; j < A[i].length; j++) {
38+
sub[i][j] = A[i][j] - B[i][j];
39+
}
40+
}
41+
return sub;
42+
}
43+
44+
public static Integer[][] addMatricesInteger(Integer[][] A, Integer[][] B) {
45+
Integer[][] sum = new Integer[A.length][];
46+
for (int i = 0; i < A.length; i++) {
47+
sum[i] = new Integer[A[i].length];
48+
for (int j = 0; j < A[i].length; j++) {
49+
sum[i][j] = A[i][j] + B[i][j];
50+
}
51+
}
52+
return sum;
53+
}
54+
}

Petrinet.class

7.87 KB
Binary file not shown.

0 commit comments

Comments
 (0)