pub struct QuantumSpatialOptimizer { /* private fields */ }Expand description
Quantum Approximate Optimization Algorithm (QAOA) for Spatial Problems
QAOA is a variational quantum algorithm designed to solve combinatorial optimization problems. This implementation focuses on spatial optimization problems such as the traveling salesman problem (TSP), facility location, and graph partitioning.
§Features
- QAOA layers with parameterized quantum gates
- Automatic parameter optimization using gradient descent
- TSP solving with quantum state preparation and measurement
- Cost and mixer Hamiltonian implementations
- Adaptive learning rate scheduling
§Example
use scirs2_core::ndarray::Array2;
use scirs2_spatial::quantum_inspired::algorithms::QuantumSpatialOptimizer;
// Create distance matrix for TSP
let distance_matrix = Array2::from_shape_vec((4, 4), vec![
0.0, 1.0, 2.0, 3.0,
1.0, 0.0, 4.0, 2.0,
2.0, 4.0, 0.0, 1.0,
3.0, 2.0, 1.0, 0.0
]).unwrap();
let mut optimizer = QuantumSpatialOptimizer::new(3);
let tour = optimizer.solve_tsp(&distance_matrix).unwrap();
println!("Optimal tour: {:?}", tour);Implementations§
Source§impl QuantumSpatialOptimizer
impl QuantumSpatialOptimizer
Sourcepub fn with_max_iterations(self, max_iter: usize) -> Self
pub fn with_max_iterations(self, max_iter: usize) -> Self
Sourcepub fn with_learning_rate(self, lr: f64) -> Self
pub fn with_learning_rate(self, lr: f64) -> Self
Sourcepub fn with_tolerance(self, tol: f64) -> Self
pub fn with_tolerance(self, tol: f64) -> Self
Sourcepub fn solve_tsp(
&mut self,
distance_matrix: &Array2<f64>,
) -> SpatialResult<Vec<usize>>
pub fn solve_tsp( &mut self, distance_matrix: &Array2<f64>, ) -> SpatialResult<Vec<usize>>
Solve traveling salesman problem using QAOA
Uses the Quantum Approximate Optimization Algorithm to find an approximate solution to the traveling salesman problem. The algorithm encodes the TSP as a QUBO (Quadratic Unconstrained Binary Optimization) problem and uses quantum superposition to explore multiple tour configurations simultaneously.
§Arguments
distance_matrix- Square matrix of distances between cities
§Returns
A tour represented as a vector of city indices
§Errors
Returns error if the distance matrix is not square
Sourcepub fn solve_qap(
&mut self,
flow_matrix: &Array2<f64>,
distance_matrix: &Array2<f64>,
) -> SpatialResult<Vec<usize>>
pub fn solve_qap( &mut self, flow_matrix: &Array2<f64>, distance_matrix: &Array2<f64>, ) -> SpatialResult<Vec<usize>>
Sourcepub fn num_layers(&self) -> usize
pub fn num_layers(&self) -> usize
Get number of QAOA layers
Sourcepub fn beta_params(&self) -> &[f64]
pub fn beta_params(&self) -> &[f64]
Get current beta parameters
Sourcepub fn gamma_params(&self) -> &[f64]
pub fn gamma_params(&self) -> &[f64]
Get current gamma parameters
Sourcepub fn cost_history(&self) -> &[f64]
pub fn cost_history(&self) -> &[f64]
Get cost history
Sourcepub fn learning_rate(&self) -> f64
pub fn learning_rate(&self) -> f64
Get current learning rate
Trait Implementations§
Source§impl Clone for QuantumSpatialOptimizer
impl Clone for QuantumSpatialOptimizer
Source§fn clone(&self) -> QuantumSpatialOptimizer
fn clone(&self) -> QuantumSpatialOptimizer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for QuantumSpatialOptimizer
impl RefUnwindSafe for QuantumSpatialOptimizer
impl Send for QuantumSpatialOptimizer
impl Sync for QuantumSpatialOptimizer
impl Unpin for QuantumSpatialOptimizer
impl UnwindSafe for QuantumSpatialOptimizer
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.