#![allow(
clippy::many_single_char_names,
clippy::print_stdout,
clippy::wildcard_imports,
clippy::uninlined_format_args
)]
use quoracle::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("=== Quoracle Simple Example ===\n");
let a = Expr::Node(Node::new("a"));
let b = Expr::Node(Node::new("b"));
let c = Expr::Node(Node::new("c"));
let d = Expr::Node(Node::new("d"));
let e = Expr::Node(Node::new("e"));
let f = Expr::Node(Node::new("f"));
println!("Creating grid quorum system...");
let grid = QuorumSystem::from_reads(
(a.clone() * b.clone() * c.clone())
+ (d.clone() * e.clone() * f.clone()),
);
println!("Read resilience: {}", grid.read_resilience());
println!("Write resilience: {}", grid.write_resilience());
println!("Overall: {}\n", grid.resilience());
println!("Finding optimal strategy for 50% reads...");
let fr = Distribution::fixed(0.5)?;
let limits = StrategyLimits::default();
let strategy =
grid.strategy(Objective::Load, Some(&fr), None, &limits, 0)?;
let load = strategy.load(Some(&fr), None)?;
println!("Optimal load: {:.4}", load);
println!("Capacity: {:.4}\n", 1.0 / load);
println!("Load at different read fractions:");
for frac in [0.0, 0.25, 0.5, 0.75, 1.0] {
let d = Distribution::fixed(frac)?;
let s = grid.strategy(Objective::Load, Some(&d), None, &limits, 0)?;
let l = s.load(Some(&d), None)?;
println!(" fr={:.2}: load={:.4}", frac, l);
}
println!("\n=== Example complete ===");
Ok(())
}