Skip to content

Commit d997dae

Browse files
author
GBathie
committed
Instance verifier
1 parent 5433a6f commit d997dae

File tree

5 files changed

+52
-8
lines changed

5 files changed

+52
-8
lines changed

src/bin/experiments.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn get_name_time_sol<P: BoolAlgoParams + Clone>(
7878
#[derive(Parser)]
7979
// #[command(version, about, long_about = None)]
8080
struct CliArgs {
81-
/// Name of the .trace file to read.
81+
/// Name of the .json file to read.
8282
input_filename: PathBuf,
8383
/// Run LTL enumeration until `max_size_ltl`
8484
/// before switching to boolean algorithm.

src/bin/verifier.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use std::path::PathBuf;
2+
3+
use clap::Parser;
4+
5+
use bolt::ltl::trace::traces_from_file;
6+
use log::info;
7+
8+
fn main() {
9+
env_logger::init();
10+
11+
let args = CliArgs::parse();
12+
info!("Reading file '{}'", args.input_filename.display());
13+
14+
let instance = traces_from_file(&args.input_filename);
15+
16+
let f = instance
17+
.formula
18+
.expect("This instance does not contain a smallest_known_formula");
19+
20+
assert_eq!(f.eval(&instance.traces).accepted_vec(), instance.target);
21+
info!("All checks succesful!");
22+
println!("All checks were succesful");
23+
}
24+
25+
#[derive(Parser)]
26+
struct CliArgs {
27+
/// Name of the .json file to read.
28+
input_filename: PathBuf,
29+
}

src/formula/tree.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ lazy_static::lazy_static! {
8585

8686
// Precedence is defined lowest to highest
8787
PrattParser::new()
88-
// Addition and subtract have equal precedence
88+
// Implies and Equivalent have equal precedence
8989
.op(Op::infix(implies, Right) | Op::infix(equiv, Right))
9090
.op(Op::infix(or, Left))
9191
.op(Op::infix(and, Left))
@@ -96,7 +96,10 @@ lazy_static::lazy_static! {
9696
};
9797
}
9898

99-
pub fn parse_expr(expr: &str, atomic_props: &[String]) -> Result<FormulaTree, LtlParsingError> {
99+
pub fn parse_ltl_formula(
100+
expr: &str,
101+
atomic_props: &[String],
102+
) -> Result<FormulaTree, LtlParsingError> {
100103
let mut pairs = LtlParser::parse(Rule::ltl_expr, expr)?;
101104
let res = parse_pairs(
102105
pairs
@@ -125,7 +128,7 @@ fn parse_pairs(
125128
}
126129
Rule::expr => parse_pairs(primary.into_inner(), atomic_props),
127130
rule => unreachable!(
128-
"FormulaTree::parse expected atom, found {:?} {}",
131+
"FormulaTree::parse expected prop or expr, found {:?} {}",
129132
rule,
130133
primary.as_str()
131134
),

src/ltl/trace.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use std::{collections::HashMap, fs::File, io::Read, path::Path};
22

33
use serde::Deserialize;
44

5-
use crate::ops::{binary::LtlBinaryOp, unary::LtlUnaryOp};
5+
use crate::{
6+
formula::tree::{FormulaTree, parse_ltl_formula},
7+
ops::{binary::LtlBinaryOp, unary::LtlUnaryOp},
8+
};
69

710
use super::cs::CharSeq;
811

@@ -12,6 +15,7 @@ pub struct Instance {
1215
pub atomic_propositions: Vec<String>,
1316
pub target: Vec<bool>,
1417
pub operators: Operators,
18+
pub formula: Option<FormulaTree>,
1519
}
1620

1721
/// Stores the [`CharSeq`] of each atomic_proposition on a given trace.
@@ -84,11 +88,18 @@ pub fn parse_traces(buf: &str) -> Instance {
8488
// Operators filtering is not implemented in current input format.
8589
let operators = Operators::all();
8690

91+
let formula = parsed_input
92+
.smallest_known_formula
93+
.into_iter()
94+
.flat_map(|expr| parse_ltl_formula(&expr, &parsed_input.atomic_propositions))
95+
.next();
96+
8797
Instance {
8898
traces,
8999
atomic_propositions: parsed_input.atomic_propositions,
90100
target,
91101
operators,
102+
formula,
92103
}
93104
}
94105

@@ -126,6 +137,7 @@ pub struct ParsedInput {
126137
positive_traces: Vec<ParsedTrace>,
127138
negative_traces: Vec<ParsedTrace>,
128139
atomic_propositions: Vec<String>,
140+
smallest_known_formula: Option<String>,
129141
number_positive_traces: usize,
130142
number_negative_traces: usize,
131143
max_length_traces: usize,

src/tests/formula_parser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
formula::tree::parse_expr,
2+
formula::tree::parse_ltl_formula,
33
tests::{G, Not},
44
};
55

@@ -18,7 +18,7 @@ fn test_parsing_fixed() {
1818
("G(a0)", G(a0())),
1919
("G(!(a0))", G(Not(a0()))),
2020
] {
21-
let f = parse_expr(expr, &atomic_props).unwrap();
21+
let f = parse_ltl_formula(expr, &atomic_props).unwrap();
2222
assert_eq!(f, expected)
2323
}
2424
}
@@ -33,7 +33,7 @@ fn test_parsing_gfand() {
3333
let p2 = || build_atom("p2", 1);
3434
let p3 = || build_atom("p3", 2);
3535
for (expr, expected) in [("G p1 && F p2 && F p3", AND(AND(G(p1()), F(p2())), F(p3())))] {
36-
let f = parse_expr(expr, &atomic_props).unwrap();
36+
let f = parse_ltl_formula(expr, &atomic_props).unwrap();
3737
assert_eq!(f, expected)
3838
}
3939
}

0 commit comments

Comments
 (0)