summaryrefslogtreecommitdiffstats
path: root/ps5/gap.py
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2014-10-28 00:40:01 -0400
committerThibaut Horel <thibaut.horel@gmail.com>2014-10-28 00:40:01 -0400
commit83ebe72479fdf541ed05e82460eecac3af31d25d (patch)
tree067287df9800daaaf3b5849fce8d8041a0ded429 /ps5/gap.py
parent7c253d520c8f20a719ac782386310348b9783660 (diff)
downloadcs224-83ebe72479fdf541ed05e82460eecac3af31d25d.tar.gz
[ps5] Add code to compute integrality gap
Diffstat (limited to 'ps5/gap.py')
-rw-r--r--ps5/gap.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/ps5/gap.py b/ps5/gap.py
new file mode 100644
index 0000000..45925ba
--- /dev/null
+++ b/ps5/gap.py
@@ -0,0 +1,11 @@
+from math import cos, pi
+
+
+def gap(n):
+ qp = n - 1
+ sdp = n * (1 - cos(2 * pi / n * (n / 2))) / 2.
+ return qp / sdp
+
+
+for i in xrange(3, 1000, 2):
+ print "{0:3}: {1}".format(i, gap(i))