as2: finish task 1
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,8 @@
|
||||
#import "@preview/simple-ntnu-report:0.1.2": ntnu-report, un
|
||||
#import "@preview/zero:0.5.0": num
|
||||
#import "@preview/physica:0.9.8": *
|
||||
#import "@preview/algorithmic:1.0.7"
|
||||
#import algorithmic: style-algorithm, algorithm-figure
|
||||
|
||||
#let text-size = 12pt
|
||||
#let white = rgb("#F8F8F2")
|
||||
@@ -13,6 +15,14 @@
|
||||
#let purple = rgb("#BD93F9")
|
||||
#let pink = rgb("#FF79C6")
|
||||
|
||||
#show: style-algorithm.with(
|
||||
hlines: (
|
||||
grid.hline(stroke: 0.5pt + white),
|
||||
grid.hline(stroke: 0.5pt + white),
|
||||
grid.hline(stroke: 0.5pt + white)
|
||||
)
|
||||
)
|
||||
|
||||
#set page(fill: black)
|
||||
|
||||
#set text(size: text-size, fill: white)
|
||||
@@ -102,3 +112,48 @@ $
|
||||
<=> sum_(v in e) y_e <= c_v \
|
||||
quad forall v in V, quad y >= 0
|
||||
$
|
||||
|
||||
=== c)
|
||||
to construct a primal-dual algorithm to approximate this problem, we use the formulations given previously.
|
||||
|
||||
|
||||
#algorithm-figure(
|
||||
"Primal-Dual Weighted Vertex Cover Approximation",
|
||||
vstroke: .5pt + white, {
|
||||
import algorithmic: *
|
||||
Procedure(
|
||||
"Vertex-Cover",
|
||||
("G", "c"), {
|
||||
Comment[initialize primal ($x$) and dual ($y$) variables]
|
||||
For($v in V, e in E$,
|
||||
Assign[$y_e$][$0$],
|
||||
Assign[$x_v$][$0$]
|
||||
)
|
||||
LineBreak
|
||||
While([there exists an uncovered edge $e = (u, v)$], {
|
||||
Comment[calculate minimum slack]
|
||||
Assign[$"slack"_u$][$c_u - sum_(e' in delta(u)) y_(e')$]
|
||||
Assign[$"slack"_v$][$c_v - sum_(e' in delta(v)) y_(e')$]
|
||||
Assign[$alpha$][$min("slack"_u, "slack"_v)$]
|
||||
LineBreak
|
||||
Comment[increase dual variable for edge $e$]
|
||||
Assign[$y_e$][$y_e + alpha$]
|
||||
LineBreak
|
||||
Comment[Update primal if constraint becomes tight]
|
||||
If([$sum_(e' in delta(u)) y_(e') = c_u$],
|
||||
Assign[$x_u$][$1$])
|
||||
If([$sum_(e' in delta(v)) y_(e') = c_v$],
|
||||
Assign[$x_v$][$1$])
|
||||
})
|
||||
Return[$C = {v in V | x_v = 1}$]
|
||||
},
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
where $delta(u)$ means the set of all edges going out of vertex $u$.
|
||||
|
||||
== other
|
||||
|
||||
the rest of the tasks are attached or can be found at
|
||||
https://git.pvv.ntnu.no/frero-uni/TDT4125/src/branch/main/assignment-2
|
||||
|
||||
Reference in New Issue
Block a user