pub struct QUBOProblem {
pub num_variables: usize,
pub variable_names: Vec<String>,
pub quadratic: Array2<f64>,
pub linear: Array1<f64>,
pub offset: f64,
}Expand description
A Quadratic Unconstrained Binary Optimization (QUBO) problem.
QUBO represents the optimization problem: minimize x^T Q x + c^T x
where x ∈ {0, 1}^n is a binary vector.
Fields§
§num_variables: usizeNumber of binary variables
variable_names: Vec<String>Variable names for reference
quadratic: Array2<f64>Quadratic coefficients matrix Q (upper triangular)
linear: Array1<f64>Linear coefficients c
offset: f64Constant offset
Implementations§
Source§impl QUBOProblem
impl QUBOProblem
Sourcepub fn new(num_variables: usize) -> Self
pub fn new(num_variables: usize) -> Self
Create a new QUBO problem with given number of variables.
Sourcepub fn with_names(variable_names: Vec<String>) -> Self
pub fn with_names(variable_names: Vec<String>) -> Self
Create a QUBO problem with named variables.
Sourcepub fn set_linear(&mut self, i: usize, value: f64)
pub fn set_linear(&mut self, i: usize, value: f64)
Set a linear coefficient.
Sourcepub fn set_quadratic(&mut self, i: usize, j: usize, value: f64)
pub fn set_quadratic(&mut self, i: usize, j: usize, value: f64)
Set a quadratic coefficient (ensures upper triangular).
Sourcepub fn add_linear(&mut self, i: usize, value: f64)
pub fn add_linear(&mut self, i: usize, value: f64)
Add to a linear coefficient.
Sourcepub fn add_quadratic(&mut self, i: usize, j: usize, value: f64)
pub fn add_quadratic(&mut self, i: usize, j: usize, value: f64)
Add to a quadratic coefficient.
Sourcepub fn evaluate(&self, assignment: &[usize]) -> f64
pub fn evaluate(&self, assignment: &[usize]) -> f64
Evaluate the QUBO objective for a binary assignment.
Sourcepub fn to_ising(&self) -> IsingModel
pub fn to_ising(&self) -> IsingModel
Convert QUBO to Ising model (h, J).
The Ising model is: H = Σᵢ hᵢ σᵢ + Σᵢⱼ Jᵢⱼ σᵢσⱼ where σ ∈ {-1, +1}.
The transformation is: x = (1 + σ) / 2
Sourcepub fn variable_index(&self, name: &str) -> Option<usize>
pub fn variable_index(&self, name: &str) -> Option<usize>
Get the index of a variable by name.
Trait Implementations§
Source§impl Clone for QUBOProblem
impl Clone for QUBOProblem
Source§fn clone(&self) -> QUBOProblem
fn clone(&self) -> QUBOProblem
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for QUBOProblem
impl Debug for QUBOProblem
Source§impl<'de> Deserialize<'de> for QUBOProblem
impl<'de> Deserialize<'de> for QUBOProblem
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>,
Auto Trait Implementations§
impl Freeze for QUBOProblem
impl RefUnwindSafe for QUBOProblem
impl Send for QUBOProblem
impl Sync for QUBOProblem
impl Unpin for QUBOProblem
impl UnwindSafe for QUBOProblem
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,
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> Serialize for T
impl<T> Serialize for T
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>
fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>
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.