Skip to content

Instantly share code, notes, and snippets.

@mlalevic
mlalevic / wsgiHandlerFunction.py
Created October 13, 2013 18:15
Function required to expose wsgi handler
def wsgiHandler():
return web.application(urls, globals(), autoreload=False).wsgifunc()
@mlalevic
mlalevic / code.py
Created October 13, 2013 18:12
Simple hello world example for web.py
import web
urls = (
'/', 'index'
)
class index:
def GET(self):
return "Hello, world!"
@mlalevic
mlalevic / dynamic_tsp.py
Last active October 17, 2023 16:07
Simple Python implementation of dynamic programming algorithm for the Traveling salesman problem
def solve_tsp_dynamic(points):
#calc all lengths
all_distances = [[length(x,y) for y in points] for x in points]
#initial value - just distance from 0 to every other point + keep the track of edges
A = {(frozenset([0, idx+1]), idx+1): (dist, [0,idx+1]) for idx,dist in enumerate(all_distances[0][1:])}
cnt = len(points)
for m in range(2, cnt):
B = {}
for S in [frozenset(C) | {0} for C in itertools.combinations(range(1, cnt), m)]:
for j in S - {0}: