Last active
December 19, 2015 03:39
-
-
Save luismbo/5891803 to your computer and use it in GitHub Desktop.
Project template for Coursera's "Discrete Optimization" course using SBCL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} \; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defsystem solver | |
:serial t | |
:depends-on () | |
:components ((:file "solver"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defpackage :solver | |
(:use :cl) | |
(:export #:solve)) | |
(in-package :solver) | |
(defun solve (problem-path solution-path) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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