Add beltfinding timeout and debugging.
This commit is contained in:
		
							parent
							
								
									f20a1841c9
								
							
						
					
					
						commit
						79c8b0c710
					
				
					 13 changed files with 278 additions and 53 deletions
				
			
		|  | @ -1,3 +1,6 @@ | |||
| use std::sync::atomic::AtomicU32; | ||||
| use std::time::Instant; | ||||
| 
 | ||||
| use crate::belt_finding::common::PathField; | ||||
| use crate::belt_finding::conflict_avoidance::ConflictAvoidance; | ||||
| use crate::common::visualize::{Color, Symbol, Visualization, Visualize}; | ||||
|  | @ -5,6 +8,8 @@ use crate::prelude::*; | |||
| use rand::{seq::SliceRandom, Rng}; | ||||
| use serde::{Deserialize, Serialize}; | ||||
| 
 | ||||
| static OUTFILEINDEX: AtomicU32 = AtomicU32::new(0); | ||||
| 
 | ||||
| pub struct GeneticAlgorithm<'a> { | ||||
|     problem: &'a Problem, | ||||
|     population: Vec<PathLayout<'a>>, | ||||
|  | @ -107,8 +112,8 @@ pub struct Problem { | |||
|     pub(crate) connections: Vec<Connection>, | ||||
| } | ||||
| 
 | ||||
| #[derive(Debug, Clone, Copy)] | ||||
| pub struct BlockHandle(usize); | ||||
| // #[derive(Debug, Clone, Copy)]
 | ||||
| // pub struct BlockHandle(usize);
 | ||||
| 
 | ||||
| #[derive(Debug, Clone)] | ||||
| pub struct Layout<'a> { | ||||
|  | @ -134,16 +139,25 @@ impl<'a> PathLayout<'a> { | |||
| 
 | ||||
|         // println!("Find Path: {:.2}", start.elapsed().as_secs_f32());
 | ||||
| 
 | ||||
|         let mut c = ConflictAvoidance::new(p); | ||||
|         let mut c = ConflictAvoidance::new(&p); | ||||
| 
 | ||||
|         // let start = std::time::Instant::now();
 | ||||
|         let start = std::time::Instant::now(); | ||||
| 
 | ||||
|         if !c.remove_all_conflicts() { | ||||
|         if !c.remove_all_conflicts(Some(std::time::Duration::from_secs(2))) { | ||||
|             if start.elapsed().as_secs_f32() > 0.5 { | ||||
|                 println!("Conflict avoidance: {:.2}", start.elapsed().as_secs_f32()); | ||||
|                 c.print(); | ||||
|                 let file = std::fs::File::create(format!( | ||||
|                     "out/{}.json", | ||||
|                     OUTFILEINDEX.fetch_add(1, std::sync::atomic::Ordering::Relaxed) | ||||
|                 )) | ||||
|                 .unwrap(); | ||||
|                 serde_json::to_writer(file, &p).unwrap(); | ||||
|                 println!("Saved slow solve."); | ||||
|             } | ||||
|             return None; | ||||
|         } | ||||
| 
 | ||||
|         // println!("Conflict avoidance: {:.2}", start.elapsed().as_secs_f32());
 | ||||
| 
 | ||||
|         let paths = c.get_paths().to_vec(); | ||||
| 
 | ||||
|         let score = paths | ||||
|  | @ -210,15 +224,15 @@ impl Problem { | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     pub fn add_block(&mut self, size: Position) -> BlockHandle { | ||||
|         self.blocks.push(Block { | ||||
|             size, | ||||
|             input: Vec::new(), | ||||
|             output: Vec::new(), | ||||
|         }); | ||||
|     // pub fn add_block(&mut self, size: Position) -> BlockHandle {
 | ||||
|     //     self.blocks.push(Block {
 | ||||
|     //         size,
 | ||||
|     //         input: Vec::new(),
 | ||||
|     //         output: Vec::new(),
 | ||||
|     //     });
 | ||||
| 
 | ||||
|         BlockHandle(self.blocks.len() - 1) | ||||
|     } | ||||
|     //     BlockHandle(self.blocks.len() - 1)
 | ||||
|     // }
 | ||||
| 
 | ||||
|     // pub fn add_connection(
 | ||||
|     //     &mut self,
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue