nat47 has asked for the wisdom of the Perl Monks concerning the following question:
This is the code I've started to write, it doesn't work and isn't done in Perl fashion...
@solution has the current set of items, @leftovers has the possible items that aren't inside @solution
while($ideal_state > $current_best) { my $coun = 0; for(my $a = 0; $a < scalar @solution; $a++) { for(my $b = 0; $b < scalar @leftovers; $b++) { my $hold_previous = $solution[$a]; $solution[$a] = $leftovers[$b]; if($max_weight > totalweight(@solution)) { if(totalscore(@solution)>=$current_best) { $leftovers[$b] = $hold_previous; } } else { $solution[$a] = $hold_previous; } } #print "Main loop"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Exchange Heuristic and Swapping Code
by SuicideJunkie (Vicar) on Mar 03, 2015 at 16:45 UTC | |
by nat47 (Sexton) on Mar 03, 2015 at 17:03 UTC |