Do not redo steps that would not improve the solution
This commit is contained in:
		
							parent
							
								
									71aaabdec4
								
							
						
					
					
						commit
						b3cf776618
					
				
					 1 changed files with 10 additions and 6 deletions
				
			
		
							
								
								
									
										16
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								src/main.rs
									
									
									
									
									
								
							|  | @ -36,18 +36,25 @@ fn main() { | ||||||
|                   MIN_WEIGHT_SCORE, MAX_WEIGHT_SCORE, DB_CHOICE_PROBABILITY); |                   MIN_WEIGHT_SCORE, MAX_WEIGHT_SCORE, DB_CHOICE_PROBABILITY); | ||||||
|         population::populate_using_db(&mut layout, &mut rng, &db, MIN_WEIGHT_SCORE, MAX_WEIGHT_SCORE, DB_CHOICE_PROBABILITY); |         population::populate_using_db(&mut layout, &mut rng, &db, MIN_WEIGHT_SCORE, MAX_WEIGHT_SCORE, DB_CHOICE_PROBABILITY); | ||||||
|         eprintln!("Finished random init, price: {}, houses: {}", layout.price(), layout.houses().len()); |         eprintln!("Finished random init, price: {}, houses: {}", layout.price(), layout.houses().len()); | ||||||
|  |         let mut last_improved_step = -1; | ||||||
|         loop { |         loop { | ||||||
|             let mut improved = false; |             if last_improved_step == 1 { | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|             eprintln!("Starting moving individual houses..."); |             eprintln!("Starting moving individual houses..."); | ||||||
|             if optimization::improve_move_individual_houses(&mut layout, &mut rng) { |             if optimization::improve_move_individual_houses(&mut layout, &mut rng) { | ||||||
|                 dump_layout(&layout, &mut best_price, seed); |                 dump_layout(&layout, &mut best_price, seed); | ||||||
|                 improved = true; |                 last_improved_step = 1; | ||||||
|             } |             } | ||||||
|             eprintln!("Finished moving individual houses..."); |             eprintln!("Finished moving individual houses..."); | ||||||
|  | 
 | ||||||
|  |             if last_improved_step == 2 { | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|             eprintln!("Starting pairwise house merge..."); |             eprintln!("Starting pairwise house merge..."); | ||||||
|             if optimization::improve_merge_pairwise(&mut layout) { |             if optimization::improve_merge_pairwise(&mut layout) { | ||||||
|                 dump_layout(&layout, &mut best_price, seed); |                 dump_layout(&layout, &mut best_price, seed); | ||||||
|                 improved = true; |                 last_improved_step = 2; | ||||||
|             } |             } | ||||||
|             eprintln!("Finished pairwise house merge"); |             eprintln!("Finished pairwise house merge"); | ||||||
|             //eprintln!("Starting pairwise house move...");
 |             //eprintln!("Starting pairwise house move...");
 | ||||||
|  | @ -56,9 +63,6 @@ fn main() { | ||||||
|             //    improved = true;
 |             //    improved = true;
 | ||||||
|             //}
 |             //}
 | ||||||
|             //eprintln!("Finished pairwise house move");
 |             //eprintln!("Finished pairwise house move");
 | ||||||
|             if !improved { |  | ||||||
|                 break; |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|         db.add_layout(&layout.houses(), true).expect("Failed to insert into DB"); |         db.add_layout(&layout.houses(), true).expect("Failed to insert into DB"); | ||||||
|     } |     } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue