Created
February 5, 2014 21:16
-
-
Save anonymous/8833263 to your computer and use it in GitHub Desktop.
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
require 'formula' | |
class Psopt302Patch < Formula | |
homepage 'https://code.google.com/p/psopt/' | |
url 'http://psopt.googlecode.com/files/patch_3.02.zip' | |
sha1 'fd04038126dcfe4e1e9d95a26c7795423ac73276' | |
def patches | |
# include assert and resolve ambiguous reference to rank in psopt.cxx | |
DATA | |
end | |
end | |
class Psopt < Formula | |
homepage 'https://code.google.com/p/psopt/' | |
url 'http://psopt.googlecode.com/files/Psopt3.tgz' | |
sha1 '3cdcb7eb82bb3862376488026bd47413ec31161c' | |
version '3.02' | |
depends_on 'openblas' => :optional | |
depends_on 'ipopt' => (build.with? 'openblas') ? ['with-openblas'] : :build | |
depends_on 'adol-c' => :build | |
depends_on 'gnuplot' => :optional | |
depends_on 'suite-sparse' => (build.with? 'openblas') ? ['with-openblas'] : :build | |
depends_on 'lp_solve' => :build | |
def install | |
# Download and apply Psopt 3.02 patch | |
Psopt302Patch.new.brew do | |
(buildpath/'PSOPT/src').install 'psopt.cxx' | |
end | |
# Don't need to build CXSparse or LUSOL here | |
inreplace 'Makefile', | |
'all: $(CXSPARSE_LIBS) $(DMATRIX_LIBS) $(LUSOL_LIBS)', | |
'all: $(DMATRIX_LIBS)' | |
# Correct paths to dependencies | |
ipopt_prefix = Formula.factory('ipopt').prefix | |
adolc_prefix = Formula.factory('adol-c').prefix | |
suite_sparse_prefix = Formula.factory('suite-sparse').prefix | |
lp_solve_prefix = Formula.factory('lp_solve').prefix | |
inreplace ['PSOPT/lib/Makefile', 'PSOPT/examples/Makefile_linux.inc'] do |s| | |
s.change_make_var! "prefix", ipopt_prefix | |
end | |
inreplace ['dmatrix/examples/Makefile'] + Dir['PSOPT/examples/*/Makefile'] do |s| | |
s.gsub! "-L$(LIBDIR)", "" | |
end | |
inreplace ['dmatrix/examples/Makefile', 'PSOPT/examples/Makefile_linux.inc'] do |s| | |
s.change_make_var! "CXSPARSE", suite_sparse_prefix | |
s.change_make_var! "LUSOL", lp_solve_prefix | |
s.change_make_var! "SPARSE_LIBS", "$(LUSOL)/lib/liblpsolve55.a $(CXSPARSE)/lib/libcxsparse.a" | |
if build.with? 'openblas' | |
s.change_make_var! "FLIBS", "-L#{Formula.factory('openblas').lib} -lopenblas" | |
else | |
s.change_make_var! "FLIBS", "-llapack -lblas" | |
end | |
s.gsub! "-lgcc_s", "" | |
s.change_make_var! "LDFLAGS", "" | |
end | |
inreplace 'PSOPT/examples/Makefile_linux.inc' do |s| | |
s.change_make_var! "IPOPT_LIBS", "`cat #{ipopt_prefix}/share/coin/doc/Ipopt/ipopt_addlibs_cpp.txt`" | |
s.change_make_var! "ADOLC_LIBS", "-L#{adolc_prefix}/lib -ladolc" | |
end | |
inreplace 'dmatrix/src/dmatrixv.cxx' do |s| | |
# remove first extern "C" around standard includes | |
# (this refused to work as a separate patch from a gist ?? | |
# only worked when together with the psopt.cxx patch in DATA) | |
s.sub! 'extern "C" {', "" | |
s.sub! "}", "" | |
end | |
system "make all" | |
lib.install 'dmatrix/lib/libdmatrix.a' | |
include.install 'dmatrix/include/dmatrixv.h' | |
lib.install 'PSOPT/lib/libpsopt.a' | |
include.install Dir['PSOPT/src/*.h'] | |
bin.install 'PSOPT/examples/obstacle/obstacle' | |
bin.install 'PSOPT/examples/bioreactor/bioreactor' | |
end | |
end | |
__END__ | |
diff --git a/psopt.cxx b/psopt.cxx | |
index 2e063cf..681a2d6 100644 | |
--- a/psopt.cxx | |
+++ b/psopt.cxx | |
@@ -92,6 +92,7 @@ _CRTIMP int * __cdecl errno(void) { static int i=0; return &i; }; | |
#include <math.h> | |
#include <string.h> | |
#include <time.h> | |
+#include <assert.h> | |
@@ -9896,7 +9897,7 @@ void print_solution_summary(Prob& problem, Alg& algorithm, Sol& solution) | |
} | |
} | |
- fprintf(outfile,"\n\n>>>>> Rank of parameter covariance matrix: %i ", rank(Cp)); | |
+ fprintf(outfile,"\n\n>>>>> Rank of parameter covariance matrix: %i ", ::rank(Cp)); | |
fprintf(outfile,"\n\n>>> 95 percent statistical confidence limits on estimated parameters "); | |
fprintf(outfile,"\nPhase\tParameter\t(Low Confidence Limit) \t(Value) \t\t(High Confidence Limit)"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment