Skip to content

Commit

Permalink
Merge pull request #8 from ReactionMechanismGenerator/lpsolve
Browse files Browse the repository at this point in the history
add conda recipe for lpsolve
  • Loading branch information
KEHANG authored Feb 27, 2017
2 parents 1c1f56f + 31a440d commit f8e72d0
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 0 deletions.
41 changes: 41 additions & 0 deletions lpsolve/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
platform="unknown"
unamestr=$(uname)
if [[ "$unamestr" == "Linux" ]]; then
platform="linux"
platarch="ux${ARCH}"
libname="liblpsolve55.so"
ccc="ccc"
elif [[ "$unamestr" == "Darwin" ]]; then
platform="macos"
platarch="osx64"
libname="liblpsolve55.dylib"
ccc="ccc.osx"
fi

mkdir -p ${PREFIX}/bin
mkdir -p ${PREFIX}/lib
mkdir -p ${PREFIX}/include/lpsolve

# build library
cd lpsolve55
sed 's/-Wno-long-double//' < ${ccc} > ${ccc}.patched
sh -x ${ccc}.patched
cd bin/${platarch}

if [[ "$platform" == "macos" ]]; then
install_name_tool -id ${PREFIX}/lib/liblpsolve55.dylib liblpsolve55.dylib
fi

cp ${libname} ${PREFIX}/lib/
cd ../../../

# build executable
cd lp_solve
sed 's/-Wno-long-double//' < ${ccc} > ${ccc}.patched
sh ${ccc}.patched
cp bin/${platarch}/lp_solve ${PREFIX}/bin/
cd ..

# install headers
cp *.h ${PREFIX}/include/
cp *.h ${PREFIX}/include/lpsolve/
86 changes: 86 additions & 0 deletions lpsolve/demo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
A very simple example using lp_solve, with the following problem:
Objective function
min: -9 C1 -10 C2;
Constraints
R1: -0 <= +C1 <= 10;
+C1 -C2 = 0;
To compile using GCC:
$ gcc demo2.c -o demo2 -llpsolve55
*/

#include "lp_lib.h"

int demo()
{
lprec *lp;
int j;
int num_cols = 2;
int ret;

int *colno;
REAL *row;

colno = (int *)malloc(sizeof(*colno) * num_cols);
row = (REAL *)malloc(sizeof(*row) * num_cols);

lp = make_lp(0, num_cols);

set_add_rowmode(lp, TRUE); /* makes building the model faster if it is done rows by row */

colno[0] = 1;
colno[1] = 2;
j = 2;

row[0] = 1;
row[1] = 0;
add_constraintex(lp, j, row, colno, LE, 10);

set_rh_range(lp, 1, 10);

row[0] = 1;
row[1] = -1;
add_constraintex(lp, j, row, colno, EQ, 0);

set_add_rowmode(lp, FALSE); /* rowmode should be turned off again when done building the model */

/* set objective function */
row[0] = -9.0;
row[1] = -10.0;

set_obj_fnex(lp, 2, row, colno);

/* object direction is minimise */
set_minim(lp);

/* print problem to stdout */
write_LP(lp, stdout);

set_verbose(lp, IMPORTANT);

printf("\n");

ret = solve(lp);
printf("Status: %i\n", ret);

printf("Objective value: %f\n", get_objective(lp));

get_variables(lp, row);
for(j = 0; j < num_cols; j++)
{
printf("%s: %f\n", get_col_name(lp, j + 1), row[j]);
}


if(lp != NULL)
{
delete_lp(lp);
}

return 0;
}

int main()
{
return demo();
}
23 changes: 23 additions & 0 deletions lpsolve/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This file created by conda-build 2.0.8
# meta.yaml template originally from:
# /Users/mjliu/Dropbox (MIT)/Research/anaconda/lpsolve, last modified Thu Nov 3 17:02:02 2016
# ------------------------------------------------

package:
name: lpsolve
version: 5.5.2.5
source:
fn: lp_solve_5.5.2.5_source.tar.gz
md5: 3be57261fc41dd8e210f54017220d5f7
url: https://sourceforge.net/projects/lpsolve/files/lpsolve/5.5.2.5/lp_solve_5.5.2.5_source.tar.gz
build:
number: '0'
test:
files:
- demo.c
about:
home: http://lpsolve.sourceforge.net/5.5/
license: LGPL
extra:
recipe-maintainers:
- snorfalorpagus
4 changes: 4 additions & 0 deletions lpsolve/run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lp_solve -h

cc -I ${PREFIX}/include -L ${PREFIX}/lib -Wl,-rpath,${PREFIX}/lib -o demo demo.c -llpsolve55
./demo

0 comments on commit f8e72d0

Please sign in to comment.