Skip to content

Commit 1102e04

Browse files
committed
WIP: Rework trait system
1 parent 01bd7c2 commit 1102e04

File tree

5 files changed

+562
-709
lines changed

5 files changed

+562
-709
lines changed

src/algorithms/fiduccia_mattheyses.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
use itertools::Itertools;
2-
use nalgebra::{allocator::Allocator, DefaultAllocator, DimName};
32
use sprs::CsMatView;
43

5-
use crate::partition::Partition;
6-
use crate::PointND;
74
use crate::ProcessUniqueId;
85
use std::collections::HashMap;
96

10-
pub fn fiduccia_mattheyses<'a, D>(
11-
initial_partition: &mut Partition<'a, PointND<D>, f64>,
7+
pub fn fiduccia_mattheyses(
8+
ids: &mut [ProcessUniqueId],
129
adjacency: CsMatView<f64>,
10+
weights: &[f64],
1311
max_passes: impl Into<Option<usize>>,
1412
max_flips_per_pass: impl Into<Option<usize>>,
1513
max_imbalance_per_flip: impl Into<Option<f64>>,
1614
max_bad_move_in_a_row: usize,
17-
) where
18-
D: DimName,
19-
DefaultAllocator: Allocator<f64, D>,
20-
<DefaultAllocator as Allocator<f64, D>>::Buffer: Send + Sync,
15+
)
2116
{
2217
let max_passes = max_passes.into();
2318
let max_flips_per_pass = max_flips_per_pass.into();
2419
let max_imbalance_per_flip = max_imbalance_per_flip.into();
25-
let (_points, weights, ids) = initial_partition.as_raw_mut();
2620

2721
fiduccia_mattheyses_impl(
2822
weights,

src/algorithms/kernighan_lin.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,20 @@
33
//! At each iteration, two nodes of different partition will be swapped, decreasing the overall cutsize
44
//! of the partition. The swap is performed in such a way that the added partition imbalanced is controlled.
55
6-
use crate::geometry::PointND;
7-
use crate::partition::Partition;
86
use crate::ProcessUniqueId;
97

108
use itertools::Itertools;
11-
use nalgebra::allocator::Allocator;
12-
use nalgebra::DefaultAllocator;
13-
use nalgebra::DimName;
149
use sprs::CsMatView;
1510

16-
pub(crate) fn kernighan_lin<'a, D>(
17-
initial_partition: &mut Partition<'a, PointND<D>, f64>,
11+
pub(crate) fn kernighan_lin(
12+
ids: &mut [ProcessUniqueId],
1813
adjacency: CsMatView<f64>,
14+
weights: &[f64],
1915
max_passes: impl Into<Option<usize>>,
2016
max_flips_per_pass: impl Into<Option<usize>>,
2117
max_imbalance_per_flip: impl Into<Option<f64>>,
2218
max_bad_move_in_a_row: usize,
23-
) where
24-
D: DimName,
25-
DefaultAllocator: Allocator<f64, D>,
26-
<DefaultAllocator as Allocator<f64, D>>::Buffer: Send + Sync,
19+
)
2720
{
2821
// To adapt Kernighan-Lin to a partition of more than 2 parts,
2922
// we apply the algorithm to each pair of adjacent parts (two parts
@@ -33,7 +26,6 @@ pub(crate) fn kernighan_lin<'a, D>(
3326
let max_passes = max_passes.into();
3427
let max_flips_per_pass = max_flips_per_pass.into();
3528
let max_imbalance_per_flip = max_imbalance_per_flip.into();
36-
let (_points, weights, ids) = initial_partition.as_raw_mut();
3729

3830
kernighan_lin_2_impl(
3931
weights,
@@ -46,18 +38,15 @@ pub(crate) fn kernighan_lin<'a, D>(
4638
);
4739
}
4840

49-
fn kernighan_lin_2_impl<D>(
41+
fn kernighan_lin_2_impl(
5042
weights: &[f64],
5143
adjacency: CsMatView<f64>,
5244
initial_partition: &mut [ProcessUniqueId],
5345
max_passes: Option<usize>,
5446
max_flips_per_pass: Option<usize>,
5547
_max_imbalance_per_flip: Option<f64>,
5648
max_bad_move_in_a_row: usize,
57-
) where
58-
D: DimName,
59-
DefaultAllocator: Allocator<f64, D>,
60-
<DefaultAllocator as Allocator<f64, D>>::Buffer: Send + Sync,
49+
)
6150
{
6251
let unique_ids = initial_partition
6352
.iter()

src/algorithms/kk.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::collections::BinaryHeap;
22
use std::ops::Sub;
3-
use std::ops::SubAssign;
43

54
use num::Zero;
65

@@ -53,7 +52,7 @@ where
5352
/// Implementation of the Karmarkar-Karp algorithm
5453
pub fn kk<T, I>(partition: &mut [usize], weights: I, num_parts: usize)
5554
where
56-
T: Zero + Ord + Sub<Output = T> + SubAssign + Copy,
55+
T: Zero + Ord + Sub<Output = T> + Copy,
5756
I: IntoIterator<Item = T>,
5857
<I as IntoIterator>::IntoIter: ExactSizeIterator,
5958
{
@@ -110,7 +109,7 @@ where
110109

111110
let emin = e[e.len() - 1].0;
112111
for ei in &mut e {
113-
ei.0 -= emin;
112+
ei.0 = ei.0 - emin;
114113
}
115114
opposites.push(tuples);
116115
m.push(e);

0 commit comments

Comments
 (0)