pub struct ModelGraph { /* private fields */ }Expand description
Graph representation of a SAMM model
Nodes represent properties and characteristics, edges represent dependencies
Implementations§
Source§impl ModelGraph
impl ModelGraph
Sourcepub fn to_dot(&self, style: VisualizationStyle) -> Result<String>
pub fn to_dot(&self, style: VisualizationStyle) -> Result<String>
Generate DOT format representation of the graph
Creates a Graphviz DOT file that can be rendered using dot command or
online tools like GraphvizOnline.
§Arguments
style- Visualization style to use
§Returns
DOT format string
§Example
use oxirs_samm::graph_analytics::{ModelGraph, VisualizationStyle};
let dot = graph.to_dot(VisualizationStyle::Detailed)?;
std::fs::write("model.dot", dot)?;Sourcepub fn to_dot_with_colors(
&self,
style: VisualizationStyle,
colors: ColorScheme,
) -> Result<String>
pub fn to_dot_with_colors( &self, style: VisualizationStyle, colors: ColorScheme, ) -> Result<String>
Sourcepub fn render_svg(
&self,
output_path: &str,
style: VisualizationStyle,
) -> Result<()>
pub fn render_svg( &self, output_path: &str, style: VisualizationStyle, ) -> Result<()>
Render graph to SVG file (requires graphviz feature)
This method directly renders the graph to an SVG file using the Graphviz library.
§Arguments
output_path- Path to output SVG filestyle- Visualization style to use
§Example
use oxirs_samm::graph_analytics::{ModelGraph, VisualizationStyle};
graph.render_svg("model.svg", VisualizationStyle::Hierarchical)?;Sourcepub fn render_png(
&self,
output_path: &str,
style: VisualizationStyle,
) -> Result<()>
pub fn render_png( &self, output_path: &str, style: VisualizationStyle, ) -> Result<()>
Render graph to PNG file (requires graphviz feature)
This method directly renders the graph to a PNG file using the Graphviz library.
§Arguments
output_path- Path to output PNG filestyle- Visualization style to use
§Example
use oxirs_samm::graph_analytics::{ModelGraph, VisualizationStyle};
graph.render_png("model.png", VisualizationStyle::Compact)?;Source§impl ModelGraph
impl ModelGraph
Sourcepub fn from_aspect(aspect: &Aspect) -> Result<Self>
pub fn from_aspect(aspect: &Aspect) -> Result<Self>
Build a dependency graph from a SAMM aspect
§Arguments
aspect- The aspect model to analyze
§Returns
A graph representation of the model’s dependency structure
§Example
use oxirs_samm::graph_analytics::ModelGraph;
use oxirs_samm::metamodel::Aspect;
let graph = ModelGraph::from_aspect(aspect)?;
println!("Graph has {} nodes and {} edges",
graph.num_nodes(), graph.num_edges());Sourcepub fn compute_centrality(&self) -> CentralityMetrics
pub fn compute_centrality(&self) -> CentralityMetrics
Compute centrality metrics for all nodes
Uses PageRank, betweenness centrality, and closeness centrality to identify the most important nodes in the dependency graph.
§Example
use oxirs_samm::graph_analytics::ModelGraph;
let centrality = graph.compute_centrality();
println!("Top 5 most central nodes:");
for (name, score) in centrality.top_nodes(5) {
println!(" {}: {:.4}", name, score);
}Sourcepub fn detect_communities(&self) -> Result<Vec<Community>>
pub fn detect_communities(&self) -> Result<Vec<Community>>
Detect communities (clusters) of related elements
Uses the Louvain algorithm to identify modules or groups of tightly coupled properties.
§Example
use oxirs_samm::graph_analytics::ModelGraph;
let communities = graph.detect_communities()?;
println!("Model has {} distinct modules", communities.len());
for (i, community) in communities.iter().enumerate() {
println!("Module {}: {} elements", i, community.members.len());
}Sourcepub fn has_cycles(&self) -> Result<bool>
pub fn has_cycles(&self) -> Result<bool>
Check if the graph has circular dependencies
Circular dependencies indicate potential design issues and should be avoided.
§Example
use oxirs_samm::graph_analytics::ModelGraph;
if graph.has_cycles()? {
eprintln!("Warning: Circular dependencies detected!");
}Sourcepub fn shortest_path(&self, from: &str, to: &str) -> Result<Option<Vec<String>>>
pub fn shortest_path(&self, from: &str, to: &str) -> Result<Option<Vec<String>>>
Compute shortest path between two elements
§Arguments
from- Source element nameto- Target element name
§Returns
The path from source to target, or None if no path exists
§Example
use oxirs_samm::graph_analytics::ModelGraph;
if let Some(path) = graph.shortest_path("Property1", "Property2")? {
println!("Path: {}", path.join(" -> "));
} else {
println!("No dependency path found");
}Sourcepub fn compute_metrics(&self) -> Result<GraphMetrics>
pub fn compute_metrics(&self) -> Result<GraphMetrics>
Compute comprehensive graph metrics
Returns metrics like diameter, density, clustering coefficient, etc.
§Example
use oxirs_samm::graph_analytics::ModelGraph;
let metrics = graph.compute_metrics()?;
println!("Graph Metrics:");
println!(" Nodes: {}", metrics.num_nodes);
println!(" Edges: {}", metrics.num_edges);
println!(" Density: {:.4}", metrics.density);Sourcepub fn strongly_connected_components(&self) -> Result<Vec<Vec<String>>>
pub fn strongly_connected_components(&self) -> Result<Vec<Vec<String>>>
Get strongly connected components
Returns groups of nodes where each node is reachable from every other node in the group.
§Example
use oxirs_samm::graph_analytics::ModelGraph;
let sccs = graph.strongly_connected_components()?;
println!("Found {} strongly connected components", sccs.len());Sourcepub fn analyze_impact(&self, node_name: &str) -> Result<ImpactAnalysis>
pub fn analyze_impact(&self, node_name: &str) -> Result<ImpactAnalysis>
Analyze the impact of changing or removing a node
This performs a dependency impact analysis to identify all nodes that would be affected if the given node is modified or removed. It computes both direct dependents and transitive dependents, along with a risk assessment.
§Arguments
node_name- The name of the node to analyze
§Returns
An ImpactAnalysis struct containing:
- Direct dependents (nodes with edges from the source node)
- All transitive dependents (reachable via dependency chains)
- Impact score (percentage of graph affected)
- Risk level classification
§Example
use oxirs_samm::graph_analytics::ModelGraph;
use oxirs_samm::metamodel::Aspect;
let graph = ModelGraph::from_aspect(aspect)?;
let impact = graph.analyze_impact("PropertyName")?;
println!("Changing {} would affect {} nodes",
impact.source_node, impact.all_dependents.len());
println!("Risk level: {:?}", impact.risk_level);Sourcepub fn suggest_cycle_breaks(&self) -> Result<Vec<CycleBreakSuggestion>>
pub fn suggest_cycle_breaks(&self) -> Result<Vec<CycleBreakSuggestion>>
Suggest ways to break circular dependencies
Analyzes detected cycles and provides suggestions for breaking them, including which edges to remove and why.
§Returns
A vector of suggestions for breaking each cycle found in the graph
§Example
use oxirs_samm::graph_analytics::ModelGraph;
use oxirs_samm::metamodel::Aspect;
let graph = ModelGraph::from_aspect(aspect)?;
if graph.has_cycles()? {
let suggestions = graph.suggest_cycle_breaks()?;
for suggestion in suggestions {
println!("Remove edge: {:?}", suggestion.edge_to_remove);
println!("Reason: {}", suggestion.reason);
}
}Sourcepub fn compare(&self, other: &ModelGraph) -> Result<GraphComparison>
pub fn compare(&self, other: &ModelGraph) -> Result<GraphComparison>
Compare this graph with another graph
Performs structural comparison between two model graphs, identifying added/removed nodes and edges, and computing similarity metrics.
§Arguments
other- The graph to compare with
§Returns
A GraphComparison struct containing:
- Lists of added/removed nodes and edges
- Similarity score (0.0-1.0, where 1.0 means identical)
- Change magnitude classification
§Example
use oxirs_samm::graph_analytics::ModelGraph;
use oxirs_samm::metamodel::Aspect;
let old_graph = ModelGraph::from_aspect(old_aspect)?;
let new_graph = ModelGraph::from_aspect(new_aspect)?;
let comparison = old_graph.compare(&new_graph)?;
println!("Similarity: {:.2}%", comparison.similarity_score * 100.0);
println!("Change magnitude: {:?}", comparison.change_magnitude);
println!("Added {} nodes, removed {} nodes",
comparison.added_nodes.len(),
comparison.removed_nodes.len());Auto Trait Implementations§
impl Freeze for ModelGraph
impl RefUnwindSafe for ModelGraph
impl Send for ModelGraph
impl Sync for ModelGraph
impl Unpin for ModelGraph
impl UnsafeUnpin for ModelGraph
impl UnwindSafe for ModelGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.