Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Greedy Algorithms in Class
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SOFT Core
SOFT 260
Greedy Algorithms in Class
Commits
8daf85f6
Commit
8daf85f6
authored
Oct 27, 2022
by
Brady James Garvin
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
greedy-algorithms/notes.md
+16
-13
16 additions, 13 deletions
greedy-algorithms/notes.md
greedy-algorithms/src/features/fueling/solver.js
+11
-2
11 additions, 2 deletions
greedy-algorithms/src/features/fueling/solver.js
with
27 additions
and
15 deletions
greedy-algorithms/notes.md
+
16
−
13
View file @
8daf85f6
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
greedy-algorithms/src/features/fueling/solver.js
+
11
−
2
View file @
8daf85f6
...
@@ -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
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment