Skip to content

Commit

Permalink
generate graph in dot format
Browse files Browse the repository at this point in the history
  • Loading branch information
ekiwi committed Aug 24, 2024
1 parent 3dbafee commit c52bf4e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
patronus = "0.18.0"
patronus = "0.18.2"
clap = { version = "4.5.14", features = ["derive"] }
smallvec = { version = "1.13.2", features = ["union"] }
petgraph = { version = "0.6.5" , features = []}
22 changes: 16 additions & 6 deletions src/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ pub fn random_testing(
println!("{}", sys.serialize_to_str(ctx));

// analyze constraint dependencies
let constraints = analyze_constraints(ctx, &sys, true);
let constraints = merge_clusters(&constraints);
println!("{constraints:?}");
//let constraints = analyze_constraints(ctx, &sys, true);
//let constraints = merge_clusters(&constraints);
//println!("{constraints:?}");

let constraints = extract_constraint_graph(ctx, &sys, false);

println!("{:?}", petgraph::dot::Dot::new(&constraints));

// TODO

Expand Down Expand Up @@ -68,7 +72,11 @@ struct ConstraintCluster {
leaves: ExprRefVec,
}

fn extract_constraint_graph(ctx: &mut Context, sys: &TransitionSystem, init: bool) {
fn extract_constraint_graph(
ctx: &mut Context,
sys: &TransitionSystem,
init: bool,
) -> petgraph::Graph<ExprRef, ExprRef, petgraph::Undirected> {
let state_map = sys.state_map();
let mut out = petgraph::Graph::new_undirected();
let mut var_to_node = HashMap::new();
Expand Down Expand Up @@ -99,11 +107,12 @@ fn extract_constraint_graph(ctx: &mut Context, sys: &TransitionSystem, init: boo
// make sure all leaves are represented as nodes
for leaf in leaves.iter() {
if !var_to_node.contains_key(leaf) {
let node = out.add_node(leaf);
var_to_node.insert(leaf, node);
let node = out.add_node(*leaf);
var_to_node.insert(*leaf, node);
}
}

// generate constraint edges
while let Some(leaf) = leaves.pop() {
for other in leaves.iter() {
debug_assert_ne!(leaf, *other);
Expand All @@ -113,6 +122,7 @@ fn extract_constraint_graph(ctx: &mut Context, sys: &TransitionSystem, init: boo
}
}
}
out
}

/// Check to see which constraints we can fulfill
Expand Down

0 comments on commit c52bf4e

Please sign in to comment.