1use crate::sampler::SampleResult;
4use scirs2_core::ndarray::Array2;
5use std::collections::{HashMap, HashSet};
6
7#[derive(Debug, Clone)]
9pub struct Graph {
10 pub num_nodes: usize,
11 pub edges: Vec<Edge>,
12 pub node_weights: Vec<f64>,
13}
14
15#[derive(Debug, Clone)]
17pub struct Edge {
18 pub from: usize,
19 pub to: usize,
20 pub weight: f64,
21}
22
23#[derive(Debug, Clone)]
25pub enum PartitioningAlgorithm {
26 KernighanLin,
28 FiducciaMattheyses,
30 Spectral,
32 Multilevel,
34 CommunityDetection,
36 MinCutMaxFlow,
38}
39
40#[derive(Debug, Clone)]
42pub struct Partitioning {
43 pub partition_assignment: Vec<usize>,
44 pub subproblems: Vec<Subproblem>,
45 pub coupling_terms: Vec<CouplingTerm>,
46 pub metrics: PartitionMetrics,
47}
48
49#[derive(Debug, Clone)]
51pub struct Subproblem {
52 pub id: usize,
53 pub variables: Vec<String>,
54 pub qubo: Array2<f64>,
55 pub var_map: HashMap<String, usize>,
56}
57
58#[derive(Debug, Clone)]
60pub struct CouplingTerm {
61 pub var1: String,
62 pub var2: String,
63 pub subproblem1: usize,
64 pub subproblem2: usize,
65 pub weight: f64,
66}
67
68#[derive(Debug, Clone)]
70pub struct PartitionMetrics {
71 pub edge_cut: f64,
72 pub balance: f64,
73 pub modularity: f64,
74 pub conductance: f64,
75}
76
77#[derive(Debug, Clone)]
79pub enum HierarchicalStrategy {
80 CoarsenSolve,
82 MultiGrid,
84 VCycle,
86}
87
88#[derive(Debug, Clone)]
90pub enum CoarseningStrategy {
91 VariableClustering,
93 EdgeCollapsing,
95 AlgebraicMultigrid,
97}
98
99#[derive(Debug, Clone)]
101pub struct Hierarchy {
102 pub levels: Vec<HierarchyLevel>,
103 pub projections: Vec<Projection>,
104}
105
106#[derive(Debug, Clone)]
108pub struct HierarchyLevel {
109 pub level: usize,
110 pub qubo: Array2<f64>,
111 pub var_map: HashMap<String, usize>,
112 pub size: usize,
113}
114
115#[derive(Debug, Clone)]
117pub struct Projection {
118 pub fine_to_coarse: Vec<usize>,
119 pub coarse_to_fine: Vec<Vec<usize>>,
120}
121
122#[derive(Debug, Clone)]
124pub enum DecompositionStrategy {
125 Schwarz,
127 BlockJacobi,
129 AdditiveSchwarz,
131 MultiplicativeSchwarz,
133}
134
135#[derive(Debug, Clone)]
137pub enum CoordinationStrategy {
138 ADMM { rho: f64 },
140 Consensus,
142 LagrangianRelaxation,
144 PriceCoordination,
146}
147
148#[derive(Debug, Clone)]
150pub struct Domain {
151 pub id: usize,
152 pub variables: Vec<String>,
153 pub qubo: Array2<f64>,
154 pub var_map: HashMap<String, usize>,
155 pub boundary_vars: Vec<usize>,
156 pub internal_vars: Vec<usize>,
157}
158
159#[derive(Debug, Clone)]
161pub struct CoordinationState {
162 pub iteration: usize,
163 pub lagrange_multipliers: Option<HashMap<(usize, usize), f64>>,
164 pub consensus_variables: Option<HashMap<usize, bool>>,
165 pub convergence_tolerance: f64,
166 pub max_iterations: usize,
167}
168
169#[derive(Debug, Clone)]
171pub struct SubdomainSolution {
172 pub domain_id: usize,
173 pub results: SampleResult,
174}
175
176#[derive(Debug, Clone)]
178pub enum CSPDecompositionStrategy {
179 TreeDecomposition,
181 ConstraintClustering,
183 CycleCutset,
185 BucketElimination,
187}
188
189#[derive(Debug, Clone)]
191pub enum VariableOrderingHeuristic {
192 MinWidth,
194 MaxCardinality,
196 MinFillIn,
198 WeightedMinFill,
200}
201
202#[derive(Debug, Clone)]
204pub enum PropagationLevel {
205 None,
207 ArcConsistency,
209 PathConsistency,
211 FullConsistency,
213}
214
215#[derive(Debug, Clone)]
217pub struct CSPProblem {
218 pub variables: HashMap<String, DomainCsp>,
219 pub constraints: Vec<CSPConstraint>,
220 pub constraint_graph: ConstraintGraph,
221}
222
223#[derive(Debug, Clone)]
225pub struct DomainCsp {
226 pub values: Vec<i32>,
227}
228
229#[derive(Debug, Clone)]
231pub struct CSPConstraint {
232 pub id: usize,
233 pub scope: Vec<String>,
234 pub constraint_type: ConstraintType,
235 pub tuples: Option<Vec<Vec<i32>>>,
236}
237
238#[derive(Debug, Clone)]
240pub enum ConstraintType {
241 AllDifferent,
243 Linear { coefficients: Vec<f64>, rhs: f64 },
245 Table,
247 Global { name: String },
249}
250
251#[derive(Debug, Clone)]
253pub struct ConstraintGraph {
254 pub adjacency: HashMap<String, HashSet<String>>,
256 pub hyperedges: Vec<HashSet<String>>,
258}
259
260#[derive(Debug, Clone)]
262pub struct CSPDecomposition {
263 pub clusters: Vec<CSPCluster>,
264 pub cluster_tree: ClusterTree,
265 pub separator_sets: Vec<HashSet<String>>,
266 pub width: usize,
267}
268
269#[derive(Debug, Clone)]
271pub struct CSPCluster {
272 pub id: usize,
273 pub variables: HashSet<String>,
274 pub constraints: Vec<usize>,
275 pub subproblem: Option<CSPSubproblem>,
276}
277
278#[derive(Debug, Clone)]
280pub struct CSPSubproblem {
281 pub variables: HashMap<String, DomainCsp>,
282 pub constraints: Vec<CSPConstraint>,
283}
284
285#[derive(Debug, Clone)]
287pub struct ClusterTree {
288 pub nodes: Vec<TreeNode>,
289 pub edges: Vec<(usize, usize)>,
290 pub root: usize,
291}
292
293#[derive(Debug, Clone)]
295pub struct TreeNode {
296 pub id: usize,
297 pub cluster_id: usize,
298 pub separator: HashSet<String>,
299 pub children: Vec<usize>,
300 pub parent: Option<usize>,
301}
302
303#[derive(Debug, Clone)]
305pub struct TreeDecomposition {
306 pub bags: Vec<HashSet<String>>,
307 pub tree_edges: Vec<(usize, usize)>,
308 pub width: usize,
309}
310
311#[derive(Debug, Clone)]
313pub struct DecompositionMetrics {
314 pub width: usize,
315 pub num_clusters: usize,
316 pub balance_factor: f64,
317 pub separator_size: f64,
318 pub decomposition_time: std::time::Duration,
319}
320
321#[derive(Debug, Clone)]
323pub enum IntegrationStrategy {
324 WeightedVoting,
326 Consensus,
328 BestSelection,
330 MajorityVoting,
332}
333
334#[derive(Debug, Clone)]
336pub struct IntegratedSolution {
337 pub assignment: HashMap<String, bool>,
338 pub energy: f64,
339 pub confidence: f64,
340 pub component_solutions: Vec<ComponentSolution>,
341}
342
343#[derive(Debug, Clone)]
345pub struct ComponentSolution {
346 pub subproblem_id: usize,
347 pub assignment: HashMap<String, bool>,
348 pub energy: f64,
349 pub weight: f64,
350}
351
352#[derive(Debug, Clone)]
354pub struct DecompositionConfig {
355 pub max_subproblem_size: usize,
356 pub min_subproblem_size: usize,
357 pub overlap_factor: f64,
358 pub balance_tolerance: f64,
359 pub quality_threshold: f64,
360}
361
362#[derive(Debug, Clone)]
364pub struct ParallelConfig {
365 pub num_threads: usize,
366 pub thread_pool_size: usize,
367 pub load_balancing: bool,
368 pub dynamic_scheduling: bool,
369}