-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: rework Partitioner trait family
This simplifies the family of traits from before into one "Partition" trait.
- Loading branch information
Showing
16 changed files
with
1,091 additions
and
1,398 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,62 @@ | ||
pub mod ckk; | ||
pub mod fiduccia_mattheyses; | ||
pub mod graph_growth; | ||
pub mod greedy; | ||
pub mod hilbert_curve; | ||
pub mod k_means; | ||
pub mod kernighan_lin; | ||
pub mod kk; | ||
pub mod multi_jagged; | ||
pub mod recursive_bisection; | ||
pub mod vn; | ||
pub mod z_curve; | ||
mod ckk; | ||
mod fiduccia_mattheyses; | ||
mod graph_growth; | ||
mod greedy; | ||
mod hilbert_curve; | ||
mod k_means; | ||
mod kernighan_lin; | ||
mod kk; | ||
mod multi_jagged; | ||
mod recursive_bisection; | ||
mod vn; | ||
mod z_curve; | ||
|
||
pub use ckk::CompleteKarmarkarKarp; | ||
pub use fiduccia_mattheyses::FiducciaMattheyses; | ||
pub use graph_growth::GraphGrowth; | ||
pub use greedy::Greedy; | ||
pub use hilbert_curve::HilbertCurve; | ||
pub use k_means::KMeans; | ||
pub use kernighan_lin::KernighanLin; | ||
pub use kk::KarmarkarKarp; | ||
pub use multi_jagged::MultiJagged; | ||
pub use recursive_bisection::Rcb; | ||
pub use recursive_bisection::Rib; | ||
pub use vn::VnBest; | ||
pub use z_curve::ZCurve; | ||
|
||
/// Map mesh elements to parts randomly. | ||
/// | ||
/// # Example | ||
/// | ||
/// ```rust | ||
/// use coupe::Partitioner; | ||
/// use coupe::Point2D; | ||
/// use coupe::Random; | ||
/// use rand; | ||
/// | ||
/// let num_parts = 3; | ||
/// let points: &[Point2D] = &[Point2D::new(1., 0.), Point2D::new(0., 1.)]; | ||
/// | ||
/// let r = Random::new(rand::thread_rng(), num_parts); | ||
/// r.partition(points, &[1., 1.]); | ||
/// ``` | ||
pub struct Random<R> { | ||
pub rng: R, | ||
pub part_count: usize, | ||
} | ||
|
||
impl<R> crate::Partition<()> for Random<R> | ||
where | ||
R: rand::Rng, | ||
{ | ||
type Metadata = (); | ||
type Error = std::convert::Infallible; | ||
|
||
fn partition(&mut self, part_ids: &mut [usize], _: ()) -> Result<Self::Metadata, Self::Error> { | ||
for part_id in part_ids { | ||
*part_id = self.rng.gen_range(0..self.part_count); | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.