@@ -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
218209pub 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