Skip to content

Commit

Permalink
A src/list/raxos/evolution/src/config.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Sep 8, 2024
1 parent 1a02514 commit 57f548a
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 140 deletions.
12 changes: 12 additions & 0 deletions src/list/raxos/evolution/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pub struct Config {
pub n_points_per_scene: usize,

/// The number of round to evolve.
pub n_round: usize,

/// Number of variants to spawn for each contour
pub n_spawn: usize,

/// The probability of moving a point, adding a point, or removing a point
pub variant_weight: (f64, f64, f64),
}
64 changes: 32 additions & 32 deletions src/list/raxos/evolution/src/contour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ impl Contour {
let y = rand::random::<f64>() * (y_high - y_low) + y_low;
let p = Point::new(x, y);
// println!("Move point {}/{l} {} to {}", i, p0, p);
if i == l - 1 {
println!("Move point {}/{l} {} to {}", i, p0, p);
}
// if i == l - 1 {
// println!("Move point {}/{l} {} to {}", i, p0, p);
// }
points[i] = p;
Self { points }
} else if rand < prob_move + prob_add {
Expand All @@ -107,39 +107,39 @@ impl Contour {

let x = rand::random::<f64>() * (x_right - x_left) + x_left;

let (frm, to) = if i == 0 {
let frm = self.points[1];
let to = self.points[0];
(frm, to)
} else if i == l {
let fmt = self.points[l - 2];
let to = self.points[l - 1];
(fmt, to)
} else {
let frm = self.points[i - 1];
let to = self.points[i];
(frm, to)
};

let y = (to.y - frm.y) / (to.x - frm.x) * (x - frm.x) + frm.y;

// let (y_low, y_high) = if i == 0 {
// let right_sibling = self.points[i].y;
// (right_sibling, (right_sibling * 1.5f64))
// let (frm, to) = if i == 0 {
// let frm = self.points[1];
// let to = self.points[0];
// (frm, to)
// } else if i == l {
// let last = self.points[i - 1].y;
// (0.0, last)
// let fmt = self.points[l - 2];
// let to = self.points[l - 1];
// (fmt, to)
// } else {
// (self.points[i].y, self.points[i - 1].y)
// let frm = self.points[i - 1];
// let to = self.points[i];
// (frm, to)
// };
// let y = rand::random::<f64>() * (y_high - y_low) + y_low;
//
// let y = (to.y - frm.y) / (to.x - frm.x) * (x - frm.x) + frm.y;

let (y_low, y_high) = if i == 0 {
let right_sibling = self.points[i].y;
(right_sibling, (right_sibling * 1.5f64))
} else if i == l {
let last = self.points[i - 1].y;
(0.0, last)
} else {
(self.points[i].y, self.points[i - 1].y)
};
let y = rand::random::<f64>() * (y_high - y_low) + y_low;

let mut points = self.points.clone();
let p = Point::new(x, y);
// println!("Add point {}/{l} at {}", i, p);
if i == l {
println!("Add point {}/{l} at {}", i, p);
}
// if i == l {
// println!("Add point {}/{l} at {}", i, p);
// }
points.insert(i, p);
Self { points }
} else {
Expand All @@ -153,9 +153,9 @@ impl Contour {
let mut points = self.points.clone();
// println!("Remove point at {}/{l} {}", i, points[i]);

if i == l - 1 {
println!("Remove point at {}/{l} {}", i, points[i]);
}
// if i == l - 1 {
// println!("Remove point at {}/{l} {}", i, points[i]);
// }

points.remove(i);
Self { points }
Expand Down
Loading

0 comments on commit 57f548a

Please sign in to comment.