Add initial station generator
This commit is contained in:
		
							parent
							
								
									24b989b9f2
								
							
						
					
					
						commit
						c4a17d1792
					
				
					 9 changed files with 398 additions and 37 deletions
				
			
		|  | @ -112,6 +112,7 @@ pub fn genetic_algorithm2<'a, R: Rng + ?Sized>( | |||
|     problem: &'a Problem, | ||||
|     new_layouts: usize, | ||||
|     mutation_timeout: usize, | ||||
|     max_mutations: usize, | ||||
|     rng: &'_ mut R, | ||||
| ) -> PathLayout<'a> { | ||||
|     let mut m = (0..new_layouts) | ||||
|  | @ -119,19 +120,19 @@ pub fn genetic_algorithm2<'a, R: Rng + ?Sized>( | |||
|         .min_by_key(|p| p.score()) | ||||
|         .unwrap(); | ||||
| 
 | ||||
|     m.print_visualization(); | ||||
|     // m.print_visualization();
 | ||||
| 
 | ||||
|     let mut last_improvement = 0; | ||||
|     let mut count = 0; | ||||
| 
 | ||||
|     while last_improvement < mutation_timeout { | ||||
|     while last_improvement < mutation_timeout && count < max_mutations { | ||||
|         last_improvement += 1; | ||||
|         count += 1; | ||||
|         if let Some(p) = PathLayout::new(m.layout.mutate(rng)) { | ||||
|             if p.score() < m.score() { | ||||
|                 m = p; | ||||
|                 println!("Step: {count}"); | ||||
|                 m.print_visualization(); | ||||
|                 // println!("Step: {count}");
 | ||||
|                 // m.print_visualization();
 | ||||
|                 last_improvement = 0; | ||||
|             } | ||||
|         } | ||||
|  | @ -207,15 +208,15 @@ impl<'a> PathLayout<'a> { | |||
| 
 | ||||
|         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_visualization(); | ||||
|                 // println!("Conflict avoidance: {:.2}", start.elapsed().as_secs_f32());
 | ||||
|                 // c.print_visualization();
 | ||||
|                 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."); | ||||
|                 // println!("Saved slow solve.");
 | ||||
|             } | ||||
|             return None; | ||||
|         } | ||||
|  | @ -419,7 +420,7 @@ impl Layout<'_> { | |||
|         loop { | ||||
|             let p = r.choose_weighted(rng, |i| i.1).unwrap(); | ||||
| 
 | ||||
|             if p.0(&mut s, rng) && rng.gen_bool(0.2) { | ||||
|             if p.0(&mut s, rng) && rng.gen_bool(0.5) { | ||||
|                 break; | ||||
|             } | ||||
|         } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue