pub struct QuboModel {
pub num_variables: usize,
pub offset: f64,
/* private fields */
}Expand description
Represents a Quadratic Unconstrained Binary Optimization (QUBO) problem
The QUBO form is:
E = Σ Q_ii x_i + Σ Q_ij x_i x_j + offset
where x_i ∈ {0, 1} are binary variables
Fields§
§num_variables: usizeNumber of binary variables in the model
offset: f64Constant offset term
Implementations§
Source§impl QuboModel
impl QuboModel
Sourcepub fn new(num_variables: usize) -> QuboModel
pub fn new(num_variables: usize) -> QuboModel
Create a new empty QUBO model with the specified number of variables
Sourcepub fn set_linear(&mut self, var: usize, value: f64) -> Result<(), IsingError>
pub fn set_linear(&mut self, var: usize, value: f64) -> Result<(), IsingError>
Set the linear coefficient (Q_ii) for a specific variable
Sourcepub fn add_linear(&mut self, var: usize, value: f64) -> Result<(), IsingError>
pub fn add_linear(&mut self, var: usize, value: f64) -> Result<(), IsingError>
Add to the linear coefficient (Q_ii) for a specific variable
Sourcepub fn get_linear(&self, var: usize) -> Result<f64, IsingError>
pub fn get_linear(&self, var: usize) -> Result<f64, IsingError>
Get the linear coefficient (Q_ii) for a specific variable
Sourcepub fn set_quadratic(
&mut self,
var1: usize,
var2: usize,
value: f64,
) -> Result<(), IsingError>
pub fn set_quadratic( &mut self, var1: usize, var2: usize, value: f64, ) -> Result<(), IsingError>
Set the quadratic coefficient (Q_ij) for a pair of variables
Sourcepub fn get_quadratic(&self, var1: usize, var2: usize) -> Result<f64, IsingError>
pub fn get_quadratic(&self, var1: usize, var2: usize) -> Result<f64, IsingError>
Get the quadratic coefficient (Q_ij) for a pair of variables
Sourcepub fn linear_terms(&self) -> Vec<(usize, f64)>
pub fn linear_terms(&self) -> Vec<(usize, f64)>
Get all non-zero linear terms
Sourcepub fn to_dense_matrix(&self) -> ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>
pub fn to_dense_matrix(&self) -> ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>
Convert to dense QUBO matrix for sampler compatibility
Sourcepub fn variable_map(&self) -> HashMap<String, usize>
pub fn variable_map(&self) -> HashMap<String, usize>
Create variable name mapping for sampler compatibility
Sourcepub fn objective(&self, binary_vars: &[bool]) -> Result<f64, IsingError>
pub fn objective(&self, binary_vars: &[bool]) -> Result<f64, IsingError>
Calculate the objective value for a specific binary configuration
The objective value is calculated as:
f(x) = Σ Q_ii x_i + Σ Q_ij x_i x_j + offset
where x_i ∈ {0, 1} are the binary variables
Sourcepub fn to_ising(&self) -> (IsingModel, f64)
pub fn to_ising(&self) -> (IsingModel, f64)
Convert the QUBO model to Ising form
The Ising form is:
H = Σ h_i σ_i^z + Σ J_ij σ_i^z σ_j^z + c
where σ_i^z ∈ {-1, +1} are the spin variables
Sourcepub fn to_qubo_model(&self) -> QuboModel
pub fn to_qubo_model(&self) -> QuboModel
Convert to QUBO model (returns self since this is already a QUBO model)
Trait Implementations§
Source§impl Default for QuboModel
Default implementation for QuboModel creates an empty model with 0 variables
impl Default for QuboModel
Default implementation for QuboModel creates an empty model with 0 variables
Source§impl QuboFormulation for QuboModel
Implementation of QuboFormulation for QuboModel
impl QuboFormulation for QuboModel
Implementation of QuboFormulation for QuboModel
Auto Trait Implementations§
impl Freeze for QuboModel
impl RefUnwindSafe for QuboModel
impl Send for QuboModel
impl Sync for QuboModel
impl Unpin for QuboModel
impl UnwindSafe for QuboModel
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<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.