Skip to content
Snippets Groups Projects
Commit 8daf85f6 authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Designed and coded solution to the fueling problem; introduced design for Huffman encoding.

parent e1bc9908
No related branches found
No related tags found
No related merge requests found
...@@ -126,8 +126,8 @@ Problem: [same as above] ...@@ -126,8 +126,8 @@ Problem: [same as above]
## Choosing a Forward Edge ## Choosing a Forward Edge
* Exhaustive search: * Exhaustive search:
* Generate * Generate all edges that travel up to distance `range` along the route
* Check that * Check that the chosen edge travels farthest (always favors the current candidate)
## Example ## Example
...@@ -143,12 +143,15 @@ Problem: [same as above] ...@@ -143,12 +143,15 @@ Problem: [same as above]
Location Next Location Location Next Location
-------- ------------- -------- -------------
a … a c
c d
d e
e h
h i
Path Path
---- ----
a → a → c → d → e → h → i
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
...@@ -214,22 +217,22 @@ Problem: Given frequencies for a set of symbols, create a lossless binary encodi ...@@ -214,22 +217,22 @@ Problem: Given frequencies for a set of symbols, create a lossless binary encodi
## DAG ## DAG
* Edges (actions): * Edges (actions):
* * Combining two sets of symbols
* Vertices (situations): * Vertices (situations):
* * Symbol partitionnings
* Edge weights: * Edge weights:
* * Total frequency of the combined sets
* Topological order: * Topological order:
* * By decreasing number of sets (parts in the paritioning)
* Goal: * Goal:
* * Find the shortest path
## Choosing a Forward Edge ## Choosing a Forward Edge
* Direct solution: * Direct solution:
* * Choose the lowest-frequency set
* * Choose the second-lowest-frequency set
* * Choose the edge that combines those sets
## Example ## Example
......
...@@ -7,7 +7,16 @@ export function planFuelings(gaps, range) { ...@@ -7,7 +7,16 @@ export function planFuelings(gaps, range) {
gaps.every((gap) => gap <= range), gaps.every((gap) => gap <= range),
`Tried to find a fueling plan crossing a gap longer than the range ${range}.`, `Tried to find a fueling plan crossing a gap longer than the range ${range}.`,
); );
const results = []; const destination = gaps.length;
// TODO: stub const results = [0];
while (results[results.length - 1] !== destination) {
let best = undefined;
for (let distance = 0, candidate = results[results.length - 1];
distance <= range && candidate <= destination;
distance += gaps[candidate], ++candidate) {
best = candidate;
}
results.push(best);
}
return results; return results;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment