Skip to content

Instantly share code, notes, and snippets.

@luismbo
Last active December 19, 2015 03:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luismbo/5891803 to your computer and use it in GitHub Desktop.
Save luismbo/5891803 to your computer and use it in GitHub Desktop.
Project template for Coursera's "Discrete Optimization" course using SBCL.
submit:
python submit.pyc
clean:
find . \( -name "*~" -name "*.dfsl" -o -name "*.fasl" -o -name "*.fas" -o -name "*.lib" -o -name "*.x86f" -o -name "*.amd64f" -o -name "*.sparcf" -o -name "*.sparc64f" -o -name "*.hpf" -o -name "*.hp64f" -o -name "*.ppcf" -o -name "*.nfasl" -o -name "*.ufsl" -o -name "*.fsl" -o -name "*.lx64fsl" \) -exec rm {} \;
(defsystem solver
:serial t
:depends-on ()
:components ((:file "solver")))
(defpackage :solver
(:use :cl)
(:export #:solve))
(in-package :solver)
(defun solve (problem-path solution-path)
)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os, sys
from subprocess import Popen, PIPE
def readFileContent(path):
f = open(path, 'r')
lines = ''.join(f.readlines())
f.close()
return lines
def solveIt(inputData):
tmpProblemFile = "problem.data"
tmpSolutionFile = "solution.data"
# Writes the inputData to a temporay file
tmpFile = open(tmpProblemFile, 'w')
tmpFile.write(inputData)
tmpFile.close()
process = Popen(['/usr/local/bin/sbcl',
'--noinform',
'--non-interactive',
'--eval', '(require :asdf)',
'--eval', '(let ((asdf:*central-registry* \
(cons *default-pathname-defaults* \
asdf:*central-registry*))) \
(asdf:load-system :solver))',
'--eval', '(solver:solve "' + tmpProblemFile + '" \
"' + tmpSolutionFile + '")'],
stdout=PIPE)
(stdout, stderr) = process.communicate()
solution = readFileContent(tmpSolutionFile)
# removes the temporay file
os.remove(tmpProblemFile)
os.remove(tmpSolutionFile)
return solution.strip()
if __name__ == '__main__':
if len(sys.argv) > 1:
fileLocation = sys.argv[1].strip()
print solveIt(readFileContent(fileLocation))
else:
print 'Usage: python solver.py <input-file>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment