pub struct LongestCommonSubsequence { /* private fields */ }Expand description
The Longest Common Subsequence problem.
Given an alphabet of size k and a set of strings over {0, ..., k-1},
find a longest string w that is a subsequence of every input string.
§Representation
The configuration is a vector of length max_length, where each entry is
either a symbol in {0, ..., alphabet_size - 1} or None as padding.
Padding must be contiguous at the end of the vector. The effective
subsequence consists of the symbols before padding starts. The objective is
to maximize the effective length.
Implementations§
Source§impl LongestCommonSubsequence
impl LongestCommonSubsequence
Sourcepub fn new(alphabet_size: usize, strings: Vec<Vec<usize>>) -> Self
pub fn new(alphabet_size: usize, strings: Vec<Vec<usize>>) -> Self
Create a new LongestCommonSubsequence instance.
The max_length is computed automatically as the minimum of all string
lengths (the maximum possible common subsequence length).
§Panics
Panics if alphabet_size == 0 and any input string is non-empty, or if
an input symbol is outside the declared alphabet, or if all strings are
empty (max_length would be 0, requiring at least one non-empty string).
Sourcepub fn alphabet_size(&self) -> usize
pub fn alphabet_size(&self) -> usize
Returns the alphabet size.
Sourcepub fn max_length(&self) -> usize
pub fn max_length(&self) -> usize
Returns the max_length field.
Sourcepub fn num_strings(&self) -> usize
pub fn num_strings(&self) -> usize
Returns the number of input strings.
Sourcepub fn total_length(&self) -> usize
pub fn total_length(&self) -> usize
Returns the total input length across all strings.
Sourcepub fn sum_squared_lengths(&self) -> usize
pub fn sum_squared_lengths(&self) -> usize
Returns the sum of squared string lengths.
Sourcepub fn sum_triangular_lengths(&self) -> usize
pub fn sum_triangular_lengths(&self) -> usize
Returns the sum of triangular numbers len * (len + 1) / 2 across strings.
Sourcepub fn num_transitions(&self) -> usize
pub fn num_transitions(&self) -> usize
Returns the number of adjacent position transitions.
Sourcepub fn cross_frequency_product(&self) -> usize
pub fn cross_frequency_product(&self) -> usize
Returns the cross-frequency product: the sum over each alphabet symbol of the product of that symbol’s frequency across all input strings.
Formally: Σ_{c ∈ 0..alphabet_size} Π_{i=1..k} count(c, strings[i]) where count(c, s) is the number of occurrences of symbol c in string s.
This equals the exact number of match-node vertices in the LCS → MaxIS reduction graph.
Trait Implementations§
Source§impl BruteForceProblem for LongestCommonSubsequence
impl BruteForceProblem for LongestCommonSubsequence
Source§fn dimensions(&self) -> Vec<usize>
fn dimensions(&self) -> Vec<usize>
Source§fn num_variables(&self) -> usize
fn num_variables(&self) -> usize
Source§impl Clone for LongestCommonSubsequence
impl Clone for LongestCommonSubsequence
Source§fn clone(&self) -> LongestCommonSubsequence
fn clone(&self) -> LongestCommonSubsequence
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LongestCommonSubsequence
impl Debug for LongestCommonSubsequence
impl DeclaredVariant for LongestCommonSubsequence
Source§impl<'de> Deserialize<'de> for LongestCommonSubsequence
impl<'de> Deserialize<'de> for LongestCommonSubsequence
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 LongestCommonSubsequence
impl Problem for LongestCommonSubsequence
Source§const NAME: &'static str = "LongestCommonSubsequence"
const NAME: &'static str = "LongestCommonSubsequence"
Source§fn parameter_names() -> &'static [&'static str]
fn parameter_names() -> &'static [&'static str]
Source§fn parameters(&self) -> ProblemParameters
fn parameters(&self) -> ProblemParameters
Source§fn variant() -> Vec<(&'static str, &'static str)>
fn variant() -> Vec<(&'static str, &'static str)>
Source§fn evaluate(&self, config: &Self::Solution) -> Result<Max<i64>, EvaluationError>
fn evaluate(&self, config: &Self::Solution) -> Result<Max<i64>, EvaluationError>
Source§fn problem_type() -> ProblemType
fn problem_type() -> ProblemType
Source§impl ReduceTo<ILP> for LongestCommonSubsequence
impl ReduceTo<ILP> for LongestCommonSubsequence
Source§fn reduce_to(&self) -> Result<Self::Result, ReductionError>
fn reduce_to(&self) -> Result<Self::Result, ReductionError>
Source§fn target_construction(error: ConstructionError) -> ReductionErrorwhere
Self: Sized,
fn target_construction(error: ConstructionError) -> ReductionErrorwhere
Self: Sized,
Source§impl ReduceTo<LongestCommonSubsequence> for MinimumVertexCover<SimpleGraph, One>
impl ReduceTo<LongestCommonSubsequence> for MinimumVertexCover<SimpleGraph, One>
Source§fn reduce_to(&self) -> Result<Self::Result, ReductionError>
fn reduce_to(&self) -> Result<Self::Result, ReductionError>
Source§fn target_construction(error: ConstructionError) -> ReductionErrorwhere
Self: Sized,
fn target_construction(error: ConstructionError) -> ReductionErrorwhere
Self: Sized,
Source§impl ReduceTo<MaximumIndependentSet<SimpleGraph, One>> for LongestCommonSubsequence
impl ReduceTo<MaximumIndependentSet<SimpleGraph, One>> for LongestCommonSubsequence
Source§fn reduce_to(&self) -> Result<Self::Result, ReductionError>
fn reduce_to(&self) -> Result<Self::Result, ReductionError>
Source§fn target_construction(error: ConstructionError) -> ReductionErrorwhere
Self: Sized,
fn target_construction(error: ConstructionError) -> ReductionErrorwhere
Self: Sized,
Auto Trait Implementations§
impl Freeze for LongestCommonSubsequence
impl RefUnwindSafe for LongestCommonSubsequence
impl Send for LongestCommonSubsequence
impl Sync for LongestCommonSubsequence
impl Unpin for LongestCommonSubsequence
impl UnsafeUnpin for LongestCommonSubsequence
impl UnwindSafe for LongestCommonSubsequence
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
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> DynProblem for Twhere
T: Problem + Serialize + 'static,
<T as Problem>::Solution: DeserializeOwned,
<T as Problem>::Value: SolutionAggregate + Display + Serialize,
impl<T> DynProblem for Twhere
T: Problem + Serialize + 'static,
<T as Problem>::Solution: DeserializeOwned,
<T as Problem>::Value: SolutionAggregate + Display + Serialize,
Source§fn evaluate_dyn(&self, solution: &Value) -> Result<String, EvaluationError>
fn evaluate_dyn(&self, solution: &Value) -> Result<String, EvaluationError>
Source§fn evaluate_json(&self, solution: &Value) -> Result<Value, EvaluationError>
fn evaluate_json(&self, solution: &Value) -> Result<Value, EvaluationError>
Source§fn evaluate_witness_dyn(
&self,
solution: &Value,
) -> Result<Option<String>, EvaluationError>
fn evaluate_witness_dyn( &self, solution: &Value, ) -> Result<Option<String>, EvaluationError>
None when it is infeasible.
This validates feasibility, not global optimality.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 parameter_names_dyn(&self) -> &'static [&'static str]
fn parameter_names_dyn(&self) -> &'static [&'static str]
Source§fn parameters_dyn(&self) -> ProblemParameters
fn parameters_dyn(&self) -> ProblemParameters
§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.