use crate::sampler::SampleResult;
use scirs2_core::ndarray::Array2;
use std::collections::{HashMap, HashSet};
#[derive(Debug, Clone)]
pub struct Graph {
pub num_nodes: usize,
pub edges: Vec<Edge>,
pub node_weights: Vec<f64>,
}
#[derive(Debug, Clone)]
pub struct Edge {
pub from: usize,
pub to: usize,
pub weight: f64,
}
#[derive(Debug, Clone)]
pub enum PartitioningAlgorithm {
KernighanLin,
FiducciaMattheyses,
Spectral,
Multilevel,
CommunityDetection,
MinCutMaxFlow,
}
#[derive(Debug, Clone)]
pub struct Partitioning {
pub partition_assignment: Vec<usize>,
pub subproblems: Vec<Subproblem>,
pub coupling_terms: Vec<CouplingTerm>,
pub metrics: PartitionMetrics,
}
#[derive(Debug, Clone)]
pub struct Subproblem {
pub id: usize,
pub variables: Vec<String>,
pub qubo: Array2<f64>,
pub var_map: HashMap<String, usize>,
}
#[derive(Debug, Clone)]
pub struct CouplingTerm {
pub var1: String,
pub var2: String,
pub subproblem1: usize,
pub subproblem2: usize,
pub weight: f64,
}
#[derive(Debug, Clone)]
pub struct PartitionMetrics {
pub edge_cut: f64,
pub balance: f64,
pub modularity: f64,
pub conductance: f64,
}
#[derive(Debug, Clone)]
pub enum HierarchicalStrategy {
CoarsenSolve,
MultiGrid,
VCycle,
}
#[derive(Debug, Clone)]
pub enum CoarseningStrategy {
VariableClustering,
EdgeCollapsing,
AlgebraicMultigrid,
}
#[derive(Debug, Clone)]
pub struct Hierarchy {
pub levels: Vec<HierarchyLevel>,
pub projections: Vec<Projection>,
}
#[derive(Debug, Clone)]
pub struct HierarchyLevel {
pub level: usize,
pub qubo: Array2<f64>,
pub var_map: HashMap<String, usize>,
pub size: usize,
}
#[derive(Debug, Clone)]
pub struct Projection {
pub fine_to_coarse: Vec<usize>,
pub coarse_to_fine: Vec<Vec<usize>>,
}
#[derive(Debug, Clone)]
pub enum DecompositionStrategy {
Schwarz,
BlockJacobi,
AdditiveSchwarz,
MultiplicativeSchwarz,
}
#[derive(Debug, Clone)]
pub enum CoordinationStrategy {
ADMM { rho: f64 },
Consensus,
LagrangianRelaxation,
PriceCoordination,
}
#[derive(Debug, Clone)]
pub struct Domain {
pub id: usize,
pub variables: Vec<String>,
pub qubo: Array2<f64>,
pub var_map: HashMap<String, usize>,
pub boundary_vars: Vec<usize>,
pub internal_vars: Vec<usize>,
}
#[derive(Debug, Clone)]
pub struct CoordinationState {
pub iteration: usize,
pub lagrange_multipliers: Option<HashMap<(usize, usize), f64>>,
pub consensus_variables: Option<HashMap<usize, bool>>,
pub convergence_tolerance: f64,
pub max_iterations: usize,
}
#[derive(Debug, Clone)]
pub struct SubdomainSolution {
pub domain_id: usize,
pub results: SampleResult,
}
#[derive(Debug, Clone)]
pub enum CSPDecompositionStrategy {
TreeDecomposition,
ConstraintClustering,
CycleCutset,
BucketElimination,
}
#[derive(Debug, Clone)]
pub enum VariableOrderingHeuristic {
MinWidth,
MaxCardinality,
MinFillIn,
WeightedMinFill,
}
#[derive(Debug, Clone)]
pub enum PropagationLevel {
None,
ArcConsistency,
PathConsistency,
FullConsistency,
}
#[derive(Debug, Clone)]
pub struct CSPProblem {
pub variables: HashMap<String, DomainCsp>,
pub constraints: Vec<CSPConstraint>,
pub constraint_graph: ConstraintGraph,
}
#[derive(Debug, Clone)]
pub struct DomainCsp {
pub values: Vec<i32>,
}
#[derive(Debug, Clone)]
pub struct CSPConstraint {
pub id: usize,
pub scope: Vec<String>,
pub constraint_type: ConstraintType,
pub tuples: Option<Vec<Vec<i32>>>,
}
#[derive(Debug, Clone)]
pub enum ConstraintType {
AllDifferent,
Linear { coefficients: Vec<f64>, rhs: f64 },
Table,
Global { name: String },
}
#[derive(Debug, Clone)]
pub struct ConstraintGraph {
pub adjacency: HashMap<String, HashSet<String>>,
pub hyperedges: Vec<HashSet<String>>,
}
#[derive(Debug, Clone)]
pub struct CSPDecomposition {
pub clusters: Vec<CSPCluster>,
pub cluster_tree: ClusterTree,
pub separator_sets: Vec<HashSet<String>>,
pub width: usize,
}
#[derive(Debug, Clone)]
pub struct CSPCluster {
pub id: usize,
pub variables: HashSet<String>,
pub constraints: Vec<usize>,
pub subproblem: Option<CSPSubproblem>,
}
#[derive(Debug, Clone)]
pub struct CSPSubproblem {
pub variables: HashMap<String, DomainCsp>,
pub constraints: Vec<CSPConstraint>,
}
#[derive(Debug, Clone)]
pub struct ClusterTree {
pub nodes: Vec<TreeNode>,
pub edges: Vec<(usize, usize)>,
pub root: usize,
}
#[derive(Debug, Clone)]
pub struct TreeNode {
pub id: usize,
pub cluster_id: usize,
pub separator: HashSet<String>,
pub children: Vec<usize>,
pub parent: Option<usize>,
}
#[derive(Debug, Clone)]
pub struct TreeDecomposition {
pub bags: Vec<HashSet<String>>,
pub tree_edges: Vec<(usize, usize)>,
pub width: usize,
}
#[derive(Debug, Clone)]
pub struct DecompositionMetrics {
pub width: usize,
pub num_clusters: usize,
pub balance_factor: f64,
pub separator_size: f64,
pub decomposition_time: std::time::Duration,
}
#[derive(Debug, Clone)]
pub enum IntegrationStrategy {
WeightedVoting,
Consensus,
BestSelection,
MajorityVoting,
}
#[derive(Debug, Clone)]
pub struct IntegratedSolution {
pub assignment: HashMap<String, bool>,
pub energy: f64,
pub confidence: f64,
pub component_solutions: Vec<ComponentSolution>,
}
#[derive(Debug, Clone)]
pub struct ComponentSolution {
pub subproblem_id: usize,
pub assignment: HashMap<String, bool>,
pub energy: f64,
pub weight: f64,
}
#[derive(Debug, Clone)]
pub struct DecompositionConfig {
pub max_subproblem_size: usize,
pub min_subproblem_size: usize,
pub overlap_factor: f64,
pub balance_tolerance: f64,
pub quality_threshold: f64,
}
#[derive(Debug, Clone)]
pub struct ParallelConfig {
pub num_threads: usize,
pub thread_pool_size: usize,
pub load_balancing: bool,
pub dynamic_scheduling: bool,
}