Use i64 instead of f64 for WheightedGraph

This commit is contained in:
hal8174 2025-03-26 17:22:37 +01:00
parent 068297e2c2
commit 6f74f1345e
6 changed files with 52 additions and 52 deletions

View file

@ -66,7 +66,7 @@ impl SinglePathfinder for ConflictAvoidance {
#[derive(Debug, Default, Serialize, Deserialize, Clone, Copy)]
pub struct Field {
pub blocked: bool,
weight: f64,
weight: i64,
}
#[derive(Debug, Serialize, Deserialize)]
@ -108,10 +108,10 @@ impl Problem {
fn calculate_wheights(&mut self, without: usize) {
for x in 0..self.map.width {
for y in 0..self.map.height {
let mut weight = 0.0;
let mut weight = 0;
if self.map.get(x, y).blocked {
weight += 10000.0;
weight += 10000;
}
self.map.get_mut(x, y).weight = weight;
@ -121,7 +121,7 @@ impl Problem {
for (i, path) in self.path.iter().enumerate() {
if i != without && !path.is_empty() {
for p in &path[1..] {
let weight = 1000.0;
let weight = 1000;
let x = p.0.x as usize;
let y = p.0.y as usize;
@ -226,7 +226,7 @@ impl WheightedGraph for MapInternal<'_> {
&self,
node: &(Position, Direction),
num: usize,
) -> Option<((Position, Direction), f64)> {
) -> Option<((Position, Direction), i64)> {
let next = node.0.in_direction(&node.1, 1);
next.in_range(
&Position::new(0, 0),
@ -241,9 +241,9 @@ impl WheightedGraph for MapInternal<'_> {
let penalty = self.map.get(next.x as usize, next.y as usize).weight;
match num {
0 => Some(((next, node.1), 1.5 + penalty)),
1 => Some(((next, node.1.counter_clockwise()), 2.0 + penalty)),
2 => Some(((next, node.1.clockwise()), 2.0 + penalty)),
0 => Some(((next, node.1), 3 + penalty)),
1 => Some(((next, node.1.counter_clockwise()), 4 + penalty)),
2 => Some(((next, node.1.clockwise()), 4 + penalty)),
_ => {
let mut count = 2;
for l in 2..=6 {
@ -259,7 +259,7 @@ impl WheightedGraph for MapInternal<'_> {
count += 1;
if count == num {
let penalty = penalty + self.map.get(n.x as usize, n.y as usize).weight;
return Some(((n, node.1), 35.0 + penalty));
return Some(((n, node.1), 35 + penalty));
}
}
}
@ -285,9 +285,9 @@ impl Problem {
self.start[i],
|&n| n == self.end[i],
|&(p, _)| {
1.5 * (PositionType::abs_diff(p.x, self.end[i].0.x)
3 * (PositionType::abs_diff(p.x, self.end[i].0.x)
+ PositionType::abs_diff(p.y, self.end[i].0.y))
as f64
as i64
},
)
};