Skip to content

Commit

Permalink
Generify TS, modify transitions and general clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
paultristanwagner committed Oct 12, 2023
1 parent 25a41d9 commit d3891f5
Show file tree
Hide file tree
Showing 68 changed files with 1,004 additions and 944 deletions.
36 changes: 17 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,23 @@ Example: See examples/ts0.json

```
{
"states": ["s0","s1","s2","s3","s4"],
"transitions": [
["s0","s1"],
["s1","s2"],
["s2","s3"],
["s3","s3"],
["s3","s0"],
["s0","s4"],
["s4","s4"]
],
"initialStates": ["s0","s3"],
"atomicPropositions": ["a","b"],
"labelingFunction": {
"s0": [],
"s1": ["a"],
"s2": ["a","b"],
"s3": ["b"],
"s4": ["b"]
}
"states": ["s0", "s1", "s2", "s3", "s4"],
"initialStates": ["s0", "s3"],
"successors": {
"s0": ["s1", "s4"],
"s1": ["s2"],
"s2": ["s3"],
"s3": ["s0", "s3"],
"s4": ["s4"]
},
"atomicPropositions": ["a", "b"],
"labelingFunction": {
"s0": [],
"s1": ["a"],
"s2": ["a", "b"],
"s3": ["b"],
"s4": ["b"]
}
}
```

Expand Down
61 changes: 12 additions & 49 deletions examples/etest8_5.json
Original file line number Diff line number Diff line change
@@ -1,54 +1,17 @@
{
"states": [
"s1",
"s2",
"s3",
"s4"
],
"transitions": [
[
"s1",
"s2"
],
[
"s1",
"s3"
],
[
"s2",
"s4"
],
[
"s3",
"s1"
],
[
"s3",
"s4"
],
[
"s4",
"s1"
]
],
"initialStates": [
"s1"
],
"atomicPropositions": [
"a",
"b"
],
"states": ["s1", "s2", "s3", "s4"],
"initialStates": ["s1"],
"successors": {
"s1": ["s2", "s3"],
"s2": ["s4"],
"s3": ["s1", "s4"],
"s4": ["s1"]
},
"atomicPropositions": ["a", "b"],
"labelingFunction": {
"s3": [
"b"
],
"s4": [
"a",
"b"
],
"s1": [],
"s2": [
"a"
]
"s2": ["a"],
"s3": ["b"],
"s4": ["a", "b"]
}
}
72 changes: 14 additions & 58 deletions examples/ts0.json
Original file line number Diff line number Diff line change
@@ -1,63 +1,19 @@
{
"states": [
"s0",
"s1",
"s2",
"s3",
"s4"
],
"transitions": [
[
"s0",
"s1"
],
[
"s1",
"s2"
],
[
"s2",
"s3"
],
[
"s3",
"s3"
],
[
"s3",
"s0"
],
[
"s0",
"s4"
],
[
"s4",
"s4"
]
],
"initialStates": [
"s0",
"s3"
],
"atomicPropositions": [
"a",
"b"
],
"states": ["s0", "s1", "s2", "s3", "s4"],
"initialStates": ["s0", "s3"],
"successors": {
"s0": ["s1", "s4"],
"s1": ["s2"],
"s2": ["s3"],
"s3": ["s0", "s3"],
"s4": ["s4"]
},
"atomicPropositions": ["a", "b"],
"labelingFunction": {
"s0": [],
"s1": [
"a"
],
"s2": [
"a",
"b"
],
"s3": [
"b"
],
"s4": [
"b"
]
"s1": ["a"],
"s2": ["a", "b"],
"s3": ["b"],
"s4": ["b"]
}
}
41 changes: 9 additions & 32 deletions examples/ts1.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,15 @@
{
"states": [
"s0",
"s1",
"s2"
],
"transitions": [
[
"s0",
"s1"
],
[
"s0",
"s2"
],
[
"s1",
"s1"
],
[
"s2",
"s2"
]
],
"initialStates": [
"s0"
],
"atomicPropositions": [
"a"
],
"states": ["s0", "s1", "s2"],
"initialStates": ["s0"],
"successors": {
"s0": ["s1", "s2"],
"s1": ["s1"],
"s2": ["s2"]
},
"atomicPropositions": ["a"],
"labelingFunction": {
"s0": [],
"s1": [
"a"
],
"s1": ["a"],
"s2": []
}
}
22 changes: 11 additions & 11 deletions src/main/java/me/paultristanwagner/modelchecking/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import static java.nio.charset.StandardCharsets.UTF_8;
import static me.paultristanwagner.modelchecking.util.AnsiColor.*;
import static me.paultristanwagner.modelchecking.util.Symbol.MODELS_SYMBOL;
import static me.paultristanwagner.modelchecking.util.Symbol.NOT_MODELS_SYMBOL;
import static me.paultristanwagner.modelchecking.util.Symbol.MODELS;
import static me.paultristanwagner.modelchecking.util.Symbol.NOT_MODELS;

import com.google.gson.JsonSyntaxException;
import java.io.*;
Expand All @@ -26,8 +26,8 @@
import me.paultristanwagner.modelchecking.ltl.formula.LTLFormula;
import me.paultristanwagner.modelchecking.ltl.parse.LTLParser;
import me.paultristanwagner.modelchecking.parse.SyntaxError;
import me.paultristanwagner.modelchecking.ts.BasicTransitionSystem;
import me.paultristanwagner.modelchecking.ts.CyclePath;
import me.paultristanwagner.modelchecking.ts.TransitionSystem;
import me.paultristanwagner.modelchecking.ts.TransitionSystemLoader;
import me.paultristanwagner.modelchecking.util.Symbol;

Expand All @@ -38,7 +38,7 @@ public class Main {
public static final Scanner SCANNER = new Scanner(System.in);

public static void main(String[] args) {
TransitionSystem ts = enterTransitionSystem();
BasicTransitionSystem ts = enterTransitionSystem();
ts.verifyNoNullLabels();

while (true) {
Expand All @@ -65,7 +65,7 @@ public static void main(String[] args) {
ModelCheckingResult result;
Optional<CyclePath> counterExample = Optional.empty();
if (formula instanceof LTLFormula ltlFormula) {
phiSymbol = Symbol.LOWERCASE_PHI_SYMBOL;
phiSymbol = Symbol.LOWERCASE_PHI;
OUT.println(phiSymbol + " := " + formula + GRAY + " (LTL)" + RESET);

LTLModelChecker modelChecker = new BasicLTLModelChecker();
Expand All @@ -76,14 +76,14 @@ public static void main(String[] args) {
counterExample = Optional.of(ltlModelCheckingResult.getCounterExample());
}
} else if (formula instanceof CTLFormula ctlFormula) {
phiSymbol = Symbol.UPPERCASE_PHI_SYMBOL;
phiSymbol = Symbol.UPPERCASE_PHI;

OUT.println(phiSymbol + " := " + formula + GRAY + " (CTL)" + RESET);

CTLModelChecker modelChecker = new BasicCTLModelChecker();
result = modelChecker.check(ts, ctlFormula);
} else if (formula instanceof CTLStarFormula ctlStarFormula) {
phiSymbol = Symbol.UPPERCASE_PHI_SYMBOL;
phiSymbol = Symbol.UPPERCASE_PHI;

OUT.println(phiSymbol + " := " + formula + GRAY + " (CTL*)" + RESET);

Expand All @@ -95,9 +95,9 @@ public static void main(String[] args) {
}

if (result.isModel()) {
OUT.println(GREEN + "TS " + MODELS_SYMBOL + " " + phiSymbol + RESET);
OUT.println(GREEN + "TS " + MODELS + " " + phiSymbol + RESET);
} else {
OUT.println(RED + "TS " + NOT_MODELS_SYMBOL + " " + phiSymbol);
OUT.println(RED + "TS " + NOT_MODELS + " " + phiSymbol);
counterExample.ifPresent(infinitePath -> OUT.println("Counterexample: " + infinitePath));
OUT.print(RESET);
}
Expand Down Expand Up @@ -211,8 +211,8 @@ private static CTLStarFormula parseCTLStarFormula(String string) {
return ctlStarParser.parse(string);
}

private static TransitionSystem enterTransitionSystem() {
TransitionSystem ts = null;
private static BasicTransitionSystem enterTransitionSystem() {
BasicTransitionSystem ts = null;
while (ts == null) {
File file = null;
String fileName = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package me.paultristanwagner.modelchecking;

import java.util.Set;
import me.paultristanwagner.modelchecking.ts.TransitionSystem;
import me.paultristanwagner.modelchecking.automaton.State;
import me.paultristanwagner.modelchecking.ts.BasicTransitionSystem;

public interface ModelChecker<T extends Formula, R extends ModelCheckingResult> {

R check(TransitionSystem ts, T formula);
R check(BasicTransitionSystem ts, T formula);

Set<String> sat(TransitionSystem ts, T formula);
Set<State> sat(BasicTransitionSystem ts, T formula);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package me.paultristanwagner.modelchecking.automaton;

import com.google.gson.*;
import java.lang.reflect.Type;
import java.util.Objects;

public class BasicState extends State {

protected final String name;

public BasicState(String name) {
this.name = name;
}

@Override
public String toString() {
return name;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BasicState that = (BasicState) o;
return Objects.equals(name, that.name);
}

@Override
public int hashCode() {
return Objects.hash(name);
}

public static class BasicStateJsonAdapter
implements JsonSerializer<BasicState>, JsonDeserializer<BasicState> {

@Override
public BasicState deserialize(
JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
return new BasicState(json.getAsString());
}

@Override
public JsonElement serialize(BasicState src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(src.name);
}
}
}
Loading

0 comments on commit d3891f5

Please sign in to comment.