Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,65 +0,0 @@
|
|||
with Ada.Text_IO;
|
||||
|
||||
procedure Knapsack_Unbounded is
|
||||
|
||||
type Bounty is record
|
||||
Value : Natural;
|
||||
Weight : Float;
|
||||
Volume : Float;
|
||||
end record;
|
||||
|
||||
function Min (A, B : Float) return Float is
|
||||
begin
|
||||
if A < B then
|
||||
return A;
|
||||
else
|
||||
return B;
|
||||
end if;
|
||||
end Min;
|
||||
|
||||
Panacea : Bounty := (3000, 0.3, 0.025);
|
||||
Ichor : Bounty := (1800, 0.2, 0.015);
|
||||
Gold : Bounty := (2500, 2.0, 0.002);
|
||||
Limits : Bounty := ( 0, 25.0, 0.250);
|
||||
Best : Bounty := ( 0, 0.0, 0.000);
|
||||
Current : Bounty := ( 0, 0.0, 0.000);
|
||||
|
||||
Best_Amounts : array (1 .. 3) of Natural := (0, 0, 0);
|
||||
|
||||
Max_Panacea : Natural := Natural (Float'Floor (Min
|
||||
(Limits.Weight / Panacea.Weight,
|
||||
Limits.Volume / Panacea.Volume)));
|
||||
Max_Ichor : Natural := Natural (Float'Floor (Min
|
||||
(Limits.Weight / Ichor.Weight,
|
||||
Limits.Volume / Ichor.Volume)));
|
||||
Max_Gold : Natural := Natural (Float'Floor (Min
|
||||
(Limits.Weight / Gold.Weight,
|
||||
Limits.Volume / Gold.Volume)));
|
||||
|
||||
begin
|
||||
for Panacea_Count in 0 .. Max_Panacea loop
|
||||
for Ichor_Count in 0 .. Max_Ichor loop
|
||||
for Gold_Count in 0 .. Max_Gold loop
|
||||
Current.Value := Panacea_Count * Panacea.Value +
|
||||
Ichor_Count * Ichor.Value +
|
||||
Gold_Count * Gold.Value;
|
||||
Current.Weight := Float (Panacea_Count) * Panacea.Weight +
|
||||
Float (Ichor_Count) * Ichor.Weight +
|
||||
Float (Gold_Count) * Gold.Weight;
|
||||
Current.Volume := Float (Panacea_Count) * Panacea.Volume +
|
||||
Float (Ichor_Count) * Ichor.Volume +
|
||||
Float (Gold_Count) * Gold.Volume;
|
||||
if Current.Value > Best.Value and
|
||||
Current.Weight <= Limits.Weight and
|
||||
Current.Volume <= Limits.Volume then
|
||||
Best := Current;
|
||||
Best_Amounts := (Panacea_Count, Ichor_Count, Gold_Count);
|
||||
end if;
|
||||
end loop;
|
||||
end loop;
|
||||
end loop;
|
||||
Ada.Text_IO.Put_Line ("Maximum value:" & Natural'Image (Best.Value));
|
||||
Ada.Text_IO.Put_Line ("Panacea:" & Natural'Image (Best_Amounts (1)));
|
||||
Ada.Text_IO.Put_Line ("Ichor: " & Natural'Image (Best_Amounts (2)));
|
||||
Ada.Text_IO.Put_Line ("Gold: " & Natural'Image (Best_Amounts (3)));
|
||||
end Knapsack_Unbounded;
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
# Define the items to pack
|
||||
$Item = @(
|
||||
[pscustomobject]@{ Name = 'panacea'; Unit = 'vials' ; value = 3000; Weight = 0.3; Volume = 0.025 }
|
||||
[pscustomobject]@{ Name = 'ichor' ; Unit = 'ampules'; value = 1800; Weight = 0.2; Volume = 0.015 }
|
||||
[pscustomobject]@{ Name = 'gold' ; Unit = 'bars' ; value = 2500; Weight = 2.0; Volume = 0.002 }
|
||||
)
|
||||
|
||||
# Define our maximums
|
||||
$MaxWeight = 25
|
||||
$MaxVolume = 0.25
|
||||
|
||||
# Set our default value to beat
|
||||
$OptimalValue = 0
|
||||
|
||||
# Iterate through the possible quantities of item 0, without going over the weight or volume limit
|
||||
ForEach ( $Qty0 in 0..( [math]::Min( [math]::Truncate( $MaxWeight / $Item[0].Weight ), [math]::Truncate( $MaxVolume / $Item[0].Volume ) ) ) )
|
||||
{
|
||||
# Calculate the remaining space
|
||||
$RemainingWeight = $MaxWeight - $Qty0 * $Item[0].Weight
|
||||
$RemainingVolume = $MaxVolume - $Qty0 * $Item[0].Volume
|
||||
|
||||
# Iterate through the possible quantities of item 1, without going over the weight or volume limit
|
||||
ForEach ( $Qty1 in 0..( [math]::Min( [math]::Truncate( $RemainingWeight / $Item[1].Weight ), [math]::Truncate( $RemainingVolume / $Item[1].Volume ) ) ) )
|
||||
{
|
||||
# Calculate the remaining space
|
||||
$RemainingWeight2 = $RemainingWeight - $Qty1 * $Item[1].Weight
|
||||
$RemainingVolume2 = $RemainingVolume - $Qty1 * $Item[1].Volume
|
||||
|
||||
# Calculate the maximum quantity of item 2 for the remaining space, without going over the weight or volume limit
|
||||
$Qty2 = [math]::Min( [math]::Truncate( $RemainingWeight2 / $Item[2].Weight ), [math]::Truncate( $RemainingVolume2 / $Item[2].Volume ) )
|
||||
|
||||
# Calculate the total value of the items packed
|
||||
$TrialValue = $Qty0 * $Item[0].Value +
|
||||
$Qty1 * $Item[1].Value +
|
||||
$Qty2 * $Item[2].Value
|
||||
|
||||
# Describe the trial solution
|
||||
$Solution = "$Qty0 $($Item[0].Unit) of $($Item[0].Name), "
|
||||
$Solution += "$Qty1 $($Item[1].Unit) of $($Item[1].Name), and "
|
||||
$Solution += "$Qty2 $($Item[2].Unit) of $($Item[2].Name) worth a total of $TrialValue."
|
||||
|
||||
# If the trial value is higher than previous most valuable trial...
|
||||
If ( $TrialValue -gt $OptimalValue )
|
||||
{
|
||||
# Set the new number to beat
|
||||
$OptimalValue = $TrialValue
|
||||
|
||||
# Overwrite the previous optimal solution(s) with the trial solution
|
||||
$Solutions = @( $Solution )
|
||||
}
|
||||
|
||||
# Else if the trial value matches the previous most valuable trial...
|
||||
ElseIf ( $TrialValue -eq $OptimalValue )
|
||||
{
|
||||
# Add the trial solution to the list of optimal solutions
|
||||
$Solutions += @( $Solution )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Show the results
|
||||
$Solutions
|
||||
Loading…
Add table
Add a link
Reference in a new issue