Skip to content

Commit

Permalink
Create model_checker.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 8, 2024
1 parent b4985e4 commit 5d8080a
Showing 1 changed file with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// model_checker.js

const { Z3 } = require('z3-js');

class ModelChecker {
constructor(config) {
this.config = config;
this.z3 = new Z3();
}

async checkModel(model, properties) {
const ctx = this.z3.context;
const solver = ctx.mkSolver();
solver.add(model);
for (const property of properties) {
solver.add(ctx.mkNot(property));
}
const result = solver.check();
if (result === 'sat') {
return { result: 'invalid', counterexample: solver.getModel() };
} else if (result === 'unsat') {
return { result: 'valid' };
} else {
return { result: 'unknown' };
}
}

async generateModel(properties) {
const ctx = this.z3.context;
const solver = ctx.mkSolver();
for (const property of properties) {
solver.add(property);
}
const result = solver.check();
if (result === 'sat') {
return solver.getModel();
} else {
return null;
}
}
}

module.exports = ModelChecker;

0 comments on commit 5d8080a

Please sign in to comment.