Lines
0 %
Functions
Branches
100 %
use std::fmt;
use merc_symbolic::FormatConfigSet;
use crate::PG;
use crate::Player;
use crate::VariabilityParityGame;
/// Display implementation output a parity game in Graphviz DOT format.
pub struct PgDot<'a, G: PG> {
pub game: &'a G,
}
impl<'a, G: PG> PgDot<'a, G> {
/// Creates a new PgDot Display for the given parity game.
pub fn new(game: &'a G) -> Self {
Self { game }
impl<'a, G: PG> fmt::Display for PgDot<'a, G> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write_dot_header(f)?;
write_dot_style(f)?;
let initial = self.game.initial_vertex();
write_vertices(f, self.game)?;
// Display edges
for v in self.game.iter_vertices() {
for to in self.game.outgoing_edges(v) {
writeln!(f, " v{} -> v{};", v, to)?;
write_init_arrow(f, initial)?;
write_footer(f)
/// Display implementation output a variability parity game in Graphviz DOT format.
pub struct VpgDot<'a> {
pub game: &'a VariabilityParityGame,
impl<'a> VpgDot<'a> {
pub fn new(game: &'a VariabilityParityGame) -> Self {
impl<'a> fmt::Display for VpgDot<'a> {
for edge in self.game.outgoing_conf_edges(v) {
writeln!(
f,
" v{} -> v{} [label=\"{}\"];",
v,
edge.to(),
FormatConfigSet(edge.configuration())
)?;
// Shared free functions for DOT rendering
fn write_dot_header(f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "digraph parity_game {{")
fn write_dot_style(f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, " rankdir=LR;")?;
writeln!(f, " graph [fontname=\"DejaVu Sans\", splines=true];")?;
writeln!(f, " node [fontname=\"DejaVu Sans\"];")?;
" edge [fontname=\"DejaVu Sans\", color=\"#444444\", arrowsize=0.9, penwidth=1.2];"
)
fn write_init_arrow(f: &mut fmt::Formatter<'_>, initial: impl fmt::Display) -> fmt::Result {
writeln!(f, " init [shape=point, width=0.05, label=\"\"];")?;
writeln!(f, " init -> v{} [arrowsize=0.6];", initial)
fn write_footer(f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "}}")
fn write_vertices<G: PG>(f: &mut fmt::Formatter<'_>, game: &G) -> fmt::Result {
for v in game.iter_vertices() {
let orientation = match game.owner(v) {
Player::Odd => "0",
Player::Even => "45",
};
" v{} [label=\"{}\", shape=square, orientation={}, xlabel=< <FONT POINT-SIZE=\"9\">v{}</FONT> >];",
game.priority(v),
orientation,
v
Ok(())