Skip to content

Commit

Permalink
Replace DefaultFor trait with corresponding methods
Browse files Browse the repository at this point in the history
  • Loading branch information
justinlovinger committed Sep 27, 2023
1 parent a0bafc5 commit 28783d4
Show file tree
Hide file tree
Showing 11 changed files with 8 additions and 51 deletions.
1 change: 0 additions & 1 deletion .hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/sh

cargo readme -o README.md
cargo readme -r default-for -o README.md
cargo readme -r derive-bounded -o README.md
cargo readme -r optimal-core -o README.md
cargo readme -r optimal-pbil -o README.md
Expand Down
6 changes: 0 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[workspace]
members = [
"default-for",
"derive-bounded",
"optimal-binary",
"optimal-core",
Expand Down
15 changes: 0 additions & 15 deletions default-for/Cargo.toml

This file was deleted.

3 changes: 0 additions & 3 deletions default-for/README.md

This file was deleted.

15 changes: 0 additions & 15 deletions default-for/src/lib.rs

This file was deleted.

3 changes: 3 additions & 0 deletions derive-num-bounded/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# derive-bounded

License: MIT
1 change: 0 additions & 1 deletion optimal-pbil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ license = "MIT"
serde = ["dep:serde", "rand/serde1", "rand_xoshiro/serde1"]

[dependencies]
default-for = { path = "../default-for" }
derive-bounded = { path = "../derive-bounded" }
derive-getters = "0.3.0"
derive_more = "0.99.17"
Expand Down
8 changes: 3 additions & 5 deletions optimal-pbil/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ mod state_machine;
mod types;
mod until_probabilities_converged;

use default_for::DefaultFor;
use derive_getters::{Dissolve, Getters};
use derive_more::IsVariant;
pub use optimal_core::prelude::*;
Expand Down Expand Up @@ -191,18 +190,17 @@ impl Config {
}
}

impl DefaultFor<usize> for Config {
fn default_for(num_bits: usize) -> Self {
impl Config {
/// Return default 'Config'.
pub fn default_for(num_bits: usize) -> Self {
Self {
num_samples: NumSamples::default(),
adjust_rate: AdjustRate::default(),
mutation_chance: MutationChance::default_for(num_bits),
mutation_adjust_rate: MutationAdjustRate::default(),
}
}
}

impl Config {
/// Return this optimizer default
/// running on the given problem.
///
Expand Down
5 changes: 2 additions & 3 deletions optimal-pbil/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use core::convert::TryFrom;
use std::f64::EPSILON;

use default_for::DefaultFor;
use derive_bounded::{
derive_from_str_from_try_into, derive_into_inner, derive_new_from_bounded_float,
derive_new_from_lower_bounded, derive_try_from_from_new,
Expand Down Expand Up @@ -87,10 +86,10 @@ impl Ord for AdjustRate {
#[cfg_attr(feature = "serde", serde(try_from = "f64"))]
pub struct MutationChance(f64);

impl DefaultFor<usize> for MutationChance {
impl MutationChance {
/// Return recommended default mutation chance,
/// average of one mutation per step.
fn default_for(num_bits: usize) -> Self {
pub fn default_for(num_bits: usize) -> Self {
if num_bits == 0 {
Self(1.)
} else {
Expand Down
1 change: 0 additions & 1 deletion optimal-steepest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ license = "MIT"
serde = ["dep:serde"]

[dependencies]
default-for = { path = "../default-for" }
derive-bounded = { path = "../derive-bounded" }
derive-getters = "0.3.0"
derive_more = "0.99.17"
Expand Down

0 comments on commit 28783d4

Please sign in to comment.