Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Exhaustive Search 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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SOFT Core
SOFT 260
Exhaustive Search In Class
Commits
e4376f3a
Commit
e4376f3a
authored
1 year ago
by
Brady James Garvin
Browse files
Options
Downloads
Patches
Plain Diff
Designed and implemented exhaustive searches.
parent
67188590
Branches
solution
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
exhaustive-search.md
+45
-27
45 additions, 27 deletions
exhaustive-search.md
with
45 additions
and
27 deletions
exhaustive-search.md
+
45
−
27
View file @
e4376f3a
...
...
@@ -9,8 +9,8 @@ with a given tag.
Signature: filterPosts(X: list
<Post>
, t: string) → R: list
<Post>
Precondition: [none]
Postcondition:
Postcondition:
Postcondition:
R ⊆ X
Postcondition:
∀x∈X. x ∈ R ↔ t ∈ tags(x)
### JavaScript
...
...
@@ -18,7 +18,13 @@ Postcondition:
```
js
function
filter
(
posts
,
tag
)
{
// …
const
results
=
[];
for
(
const
post
of
posts
)
{
// "generate" step
if
(
post
.
tags
.
has
(
tag
))
{
// "check" step
results
.
push
(
post
);
}
}
return
results
;
}
```
...
...
@@ -37,12 +43,12 @@ and blue.)
Signature: color(G = (V, E): graph) → C: map
<vertex
,
color
>
Happy path:
Precondition:
Postcondition:
Postcondition:
Precondition:
∃X∈P^V. isValidColoring(G, X)
Postcondition:
C ∈ P^V
Postcondition:
isValidColoring(G, C)
Sad path:
Precondition:
Postcondition:
Precondition:
¬∃X∈P^V. isValidColoring(G, X)
Postcondition:
C = ⊥
### JavaScript
...
...
@@ -53,13 +59,12 @@ green, and blue.)
```
js
function
color
(
graph
)
{
// …
for
(
const
coloring
of
mappings
(
graph
.
vertices
,
PALETTE
))
{
if
(
isValidColoring
(
graph
,
coloring
))
{
// …
for
(
const
coloring
of
mappings
(
graph
.
vertices
,
PALETTE
))
{
// combinatorial enumeration
if
(
isValidColoring
(
graph
,
coloring
))
{
// helper function
return
coloring
;
}
}
// …
return
undefined
;
}
```
...
...
@@ -74,8 +79,8 @@ color).
#### Contract
Signature: isValidColoring(G = (V, E): graph, C: map
<vertex
,
color
>
) → r: boolean
Precondition:
Postcondition:
Precondition:
C ∈ P^V
Postcondition:
r ↔ ¬∃(u, v)∈E. C[u] = C[v]
#### JavaScript
...
...
@@ -87,7 +92,12 @@ vertices to colors.)
```
js
function
isValidColoring
(
graph
,
coloring
)
{
// …
for
(
const
[
source
,
destination
]
of
graph
.
edges
)
{
if
(
coloring
.
get
(
source
)
===
coloring
.
get
(
destination
))
{
return
false
;
}
}
return
true
;
}
```
...
...
@@ -103,22 +113,24 @@ set of items not exceeding the weight limit.
Signature: knapsack(I: set
<item>
, w: set
<item>
→ number, W: number, v: set
<item>
→ number) → K: set
<item>
Happy path:
Precondition:
Postcondition:
Postcondition:
Precondition:
|options(I, w, W)| > 0
Postcondition:
K ∈ options(I, w, W)
Postcondition:
∀X∈options(I, w, W). v(K) ≥ v(X)
Sad path:
Precondition:
Postcondition:
Precondition:
|options(I, w, W)| = 0
Postcondition:
K = ⊥
### JavaScript
```
js
function
knapsack
(
items
,
getWeight
,
weightLimit
,
getValue
)
{
// …
const
result
=
undefined
;
for
(
const
option
of
options
(
items
,
getWeight
,
weightLimit
))
{
// …
if
(
result
===
undefined
||
getValue
(
option
)
>
getValue
(
result
))
{
result
=
option
;
}
}
// …
return
result
;
}
```
...
...
@@ -134,13 +146,19 @@ of items not exceeding the weight limit.
Signature: options(I: set
<item>
, w: set
<item>
→ number, W: number) → O: set
<set
<
item
>
>
Precondition: [none]
Postcondition:
Postcondition:
Postcondition:
O ⊆ 𝒫(I)
Postcondition:
∀X∈𝒫(I). X ∈ O ↔ w(X) ≤ W
#### JavaScript
```
js
function
options
(
items
,
getWeight
,
weightLimit
)
{
// …
const
results
=
new
Set
();
for
(
const
candidate
of
powerset
(
items
))
{
if
(
getWeight
(
candidate
)
<=
weightLimit
)
{
results
.
add
(
candidate
);
}
}
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