pub struct SubgraphIsomorphism { /* private fields */ }Expand description
The Subgraph Isomorphism problem.
Given a host graph G = (V_1, E_1) and a pattern graph H = (V_2, E_2), determine whether there exists an injective function f: V_2 -> V_1 such that for every edge {u,v} in E_2, {f(u), f(v)} is an edge in E_1.
This is a satisfaction (decision) problem: the metric is bool.
§Configuration
A configuration is a vector of length |V_2| where each entry is a value in {0, …, |V_1|-1} representing the host vertex that each pattern vertex maps to. The configuration is valid (true) if:
- All mapped host vertices are distinct (injective mapping)
- Every edge in the pattern graph maps to an edge in the host graph
§Example
use problemreductions::models::graph::SubgraphIsomorphism;
use problemreductions::topology::SimpleGraph;
use problemreductions::{Problem, Solver, BruteForce};
// Host: K4 (complete graph on 4 vertices)
let host = SimpleGraph::new(4, vec![(0,1),(0,2),(0,3),(1,2),(1,3),(2,3)]);
// Pattern: triangle (K3)
let pattern = SimpleGraph::new(3, vec![(0,1),(0,2),(1,2)]);
let problem = SubgraphIsomorphism::new(host, pattern);
// Mapping [0, 1, 2] means pattern vertex 0->host 0, 1->1, 2->2
assert!(problem.evaluate(&[0, 1, 2]));
let solver = BruteForce::new();
let solution = solver.find_witness(&problem);
assert!(solution.is_some());Implementations§
Source§impl SubgraphIsomorphism
impl SubgraphIsomorphism
Sourcepub fn new(host_graph: SimpleGraph, pattern_graph: SimpleGraph) -> Self
pub fn new(host_graph: SimpleGraph, pattern_graph: SimpleGraph) -> Self
Create a new SubgraphIsomorphism problem.
§Arguments
host_graph- The host graph to search inpattern_graph- The pattern graph to find as a subgraph
Sourcepub fn host_graph(&self) -> &SimpleGraph
pub fn host_graph(&self) -> &SimpleGraph
Get a reference to the host graph.
Sourcepub fn pattern_graph(&self) -> &SimpleGraph
pub fn pattern_graph(&self) -> &SimpleGraph
Get a reference to the pattern graph.
Sourcepub fn num_host_vertices(&self) -> usize
pub fn num_host_vertices(&self) -> usize
Get the number of vertices in the host graph.
Sourcepub fn num_host_edges(&self) -> usize
pub fn num_host_edges(&self) -> usize
Get the number of edges in the host graph.
Sourcepub fn num_pattern_vertices(&self) -> usize
pub fn num_pattern_vertices(&self) -> usize
Get the number of vertices in the pattern graph.
Sourcepub fn num_pattern_edges(&self) -> usize
pub fn num_pattern_edges(&self) -> usize
Get the number of edges in the pattern graph.
Sourcepub fn is_valid_solution(&self, config: &[usize]) -> bool
pub fn is_valid_solution(&self, config: &[usize]) -> bool
Check if a configuration represents a valid subgraph isomorphism.
Trait Implementations§
Source§impl Clone for SubgraphIsomorphism
impl Clone for SubgraphIsomorphism
Source§fn clone(&self) -> SubgraphIsomorphism
fn clone(&self) -> SubgraphIsomorphism
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SubgraphIsomorphism
impl Debug for SubgraphIsomorphism
Source§impl<'de> Deserialize<'de> for SubgraphIsomorphism
impl<'de> Deserialize<'de> for SubgraphIsomorphism
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Problem for SubgraphIsomorphism
impl Problem for SubgraphIsomorphism
Source§const NAME: &'static str = "SubgraphIsomorphism"
const NAME: &'static str = "SubgraphIsomorphism"
Source§fn dims(&self) -> Vec<usize>
fn dims(&self) -> Vec<usize>
Source§fn variant() -> Vec<(&'static str, &'static str)>
fn variant() -> Vec<(&'static str, &'static str)>
Source§fn num_variables(&self) -> usize
fn num_variables(&self) -> usize
Source§fn problem_type() -> ProblemType
fn problem_type() -> ProblemType
Source§impl ReduceTo<ILP> for SubgraphIsomorphism
impl ReduceTo<ILP> for SubgraphIsomorphism
Source§impl ReduceTo<SubgraphIsomorphism> for KClique<SimpleGraph>
impl ReduceTo<SubgraphIsomorphism> for KClique<SimpleGraph>
Source§impl Serialize for SubgraphIsomorphism
impl Serialize for SubgraphIsomorphism
impl DeclaredVariant for SubgraphIsomorphism
Auto Trait Implementations§
impl Freeze for SubgraphIsomorphism
impl RefUnwindSafe for SubgraphIsomorphism
impl Send for SubgraphIsomorphism
impl Sync for SubgraphIsomorphism
impl Unpin for SubgraphIsomorphism
impl UnsafeUnpin for SubgraphIsomorphism
impl UnwindSafe for SubgraphIsomorphism
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Conv for T
impl<T> Conv for T
Source§impl<T> DynProblem for T
impl<T> DynProblem for T
Source§fn evaluate_dyn(&self, config: &[usize]) -> String
fn evaluate_dyn(&self, config: &[usize]) -> String
Source§fn evaluate_json(&self, config: &[usize]) -> Value
fn evaluate_json(&self, config: &[usize]) -> Value
Source§fn serialize_json(&self) -> Value
fn serialize_json(&self) -> Value
Source§fn problem_name(&self) -> &'static str
fn problem_name(&self) -> &'static str
Problem::NAME).Source§fn num_variables_dyn(&self) -> usize
fn num_variables_dyn(&self) -> usize
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.