Skip to content

Commit 3f20260

Browse files
committed
Remove beam
1 parent 62f061e commit 3f20260

2 files changed

Lines changed: 2 additions & 55 deletions

File tree

‎src/main.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use rayon::prelude::*;
77

88
use icfpc::models::*;
99
use icfpc::parse::read_all_inputs;
10-
use icfpc::solve::solve_beam;
10+
use icfpc::solve::solve_small;
1111

1212

1313
fn solve<W: Write>(task: Task, f: &mut W) {
14-
let cmds = solve_beam(task);
14+
let cmds = solve_small(task);
1515
for cmd in cmds {
1616
write!(f, "{}", cmd).unwrap();
1717
}

‎src/solve.rs‎

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,6 @@ impl<'a> State<'a> {
204204

205205
self.remaining > 0
206206
}
207-
208-
pub fn finished(&self) -> bool {
209-
self.remaining == 0
210-
}
211-
212-
// min is better
213-
fn score(&self) -> usize {
214-
self.remaining
215-
}
216207
}
217208

218209
pub fn solve_small(task: Task) -> Vec<Command> {
@@ -223,48 +214,4 @@ pub fn solve_small(task: Task) -> Vec<Command> {
223214
}
224215
}
225216
state.commands
226-
}
227-
228-
#[derive(Clone, Eq, PartialEq)]
229-
struct BeamEntry<'a>(State<'a>);
230-
231-
impl<'a> Ord for BeamEntry<'a> {
232-
fn cmp(&self, other: &BeamEntry) -> Ordering {
233-
let cmd = other.0.commands.len().cmp(&self.0.commands.len());
234-
let score = other.0.score().cmp(&self.0.score());
235-
cmd.then(score)
236-
}
237-
}
238-
239-
impl<'a> PartialOrd for BeamEntry<'a> {
240-
fn partial_cmp(&self, other: &BeamEntry) -> Option<Ordering> {
241-
Some(self.cmp(other))
242-
}
243-
}
244-
245-
pub fn solve_beam(task: Task) -> Vec<Command> {
246-
let mut beam = BinaryHeap::new();
247-
let beam_length = 3;
248-
let branch = 3;
249-
beam.push(BeamEntry(State::initialize(&task)));
250-
loop {
251-
let mut next_beam = BinaryHeap::new();
252-
let mut points_set = HashSet::new();
253-
for entry in beam.into_iter().take(beam_length) {
254-
let state = entry.0;
255-
if state.finished() {
256-
return state.commands;
257-
}
258-
for _ in 0..branch {
259-
let mut state = state.clone();
260-
state.next_state();
261-
if points_set.contains(&state.current_point) {
262-
continue;
263-
}
264-
points_set.insert(state.current_point);
265-
next_beam.push(BeamEntry(state));
266-
}
267-
}
268-
beam = next_beam;
269-
}
270217
}

0 commit comments

Comments
 (0)