Skip to content

Commit 3d06835

Browse files
committed
Update to lrslib v7.1a
1 parent dba1279 commit 3d06835

File tree

6 files changed

+139
-5
lines changed

6 files changed

+139
-5
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ Polyhedra = "67491407-f73d-577b-9b50-8179a7c68029"
1111
lrslib_jll = "3873f7d0-7b7c-52c3-bdf4-8ab39b8f337a"
1212

1313
[compat]
14+
BinDeps = "0.7, 0.8, 1"
15+
Homebrew = "0.7"
1416
Polyhedra = "0.6.14"
15-
julia = "1.3"
17+
julia = "1"
1618
lrslib_jll = "= 0.2.0"
1719

1820
[extras]

deps/build.jl

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
using BinDeps
2+
using Libdl
3+
4+
@BinDeps.setup
5+
6+
lrslib_commit = "5b8ab79d3b3a40f128083da3935523cb254d3460"
7+
#lrsname = "lrslib-061"
8+
lrsname = "lrslib-$lrslib_commit"
9+
lrsnashname = "lrsnashlib-$lrslib_commit"
10+
lrslibname = "liblrs"
11+
12+
# julia installs libgmp10 but not libgmp-dev since it
13+
# does not have to compile C program with GMP,
14+
# e.g. it does not need the headers.
15+
# FIXME BinDeps doesn't work with header, it only works for libraries because it checks for the .so
16+
# It sees libgmp.so (installed by libgmp10 as a julia dependency) and thinks that it's ok but
17+
# it does not have the headers
18+
#libgmpdev = library_dependency("libgmp-dev", aliases=["libgmp"])
19+
liblrs = library_dependency("liblrs", aliases=[lrsname, "liblrsgmp"])#, depends=[libgmpdev])
20+
liblrsnash = library_dependency("liblrsnash", aliases=[lrsnashname, "liblrsnashgmp"])
21+
22+
official_repo = "http://cgm.cs.mcgill.ca/~avis/C/lrslib/archive/$lrsname.tar.gz"
23+
forked_repo = "https://github.com/JuliaPolyhedra/lrslib/archive/$lrslib_commit.zip"
24+
25+
#GMP
26+
@static if Sys.islinux()
27+
const has_apt = try success(`apt-get -v`) catch e false end
28+
const has_yum = try success(`yum --version`) catch e false end
29+
const has_pacman = try success(`pacman -Qq`) catch e false end
30+
if has_apt || has_yum
31+
if has_apt
32+
pkgname = "libgmp-dev"
33+
pkgman = "apt-get"
34+
else
35+
pkgname = "libgmp-devel or gmp-devel"
36+
pkgman = "yum"
37+
end
38+
39+
println("Warning: The compilation of LRS requires the header gmp.h provided by the package $pkgname.")
40+
println("If the compilation fails, please install it as follows:")
41+
println("\$ sudo $pkgman install $pkgname")
42+
end
43+
end
44+
45+
#LRS
46+
provides(Sources,
47+
Dict(URI(forked_repo) => liblrs), unpacked_dir="$lrsname")
48+
49+
lrssrcdir = joinpath(BinDeps.srcdir(liblrs), lrsname)
50+
lrsprefixdir = joinpath(BinDeps.usrdir(liblrs))
51+
lrslibdir = joinpath(lrsprefixdir, "lib")
52+
53+
targetdirs = AbstractString["$lrslibname.$(Libdl.dlext)"]
54+
patchdir = BinDeps.depsdir(liblrs)
55+
56+
@static if Sys.isapple()
57+
using Homebrew
58+
Homebrew.add("gmp")
59+
homebrew_includedir = joinpath(Homebrew.brew_prefix, "include")
60+
homebrew_libdir = joinpath(Homebrew.brew_prefix, "lib")
61+
provides(BuildProcess,
62+
(@build_steps begin
63+
GetSources(liblrs)
64+
CreateDirectory(lrsprefixdir)
65+
CreateDirectory(lrslibdir)
66+
@build_steps begin
67+
ChangeDirectory(lrssrcdir)
68+
FileRule(joinpath(lrslibdir,"$lrslibname.$(Libdl.dlext)"),@build_steps begin
69+
pipeline(`cat $patchdir/makefile.osx.patch`, `patch`)
70+
`make $lrslibname.$(Libdl.dlext).0 SONAME=$lrslibdir/$lrslibname.$(Libdl.dlext) SHLIB=$lrslibname.$(Libdl.dlext).0 SHLINK=$lrslibname.$(Libdl.dlext) INCLUDEDIR=$homebrew_includedir LIBDIR=$homebrew_libdir`
71+
`cp $lrslibname.$(Libdl.dlext).0 $lrslibdir/$lrslibname.$(Libdl.dlext)`
72+
end)
73+
end
74+
end),liblrs)
75+
provides(BuildProcess,
76+
(@build_steps begin
77+
ChangeDirectory(lrssrcdir)
78+
FileRule(joinpath(lrslibdir,"liblrsnash.$(Libdl.dlext)"),@build_steps begin
79+
`cp $patchdir/makefile.liblrsnash $lrssrcdir`
80+
`make -f makefile.liblrsnash SHLIB=liblrsnash.$(Libdl.dlext) LIBLRSDIR=$lrslibdir INCLUDEDIR=$homebrew_includedir LIBDIR=$homebrew_libdir`
81+
`cp liblrsnash.$(Libdl.dlext) $lrslibdir/liblrsnash.$(Libdl.dlext)`
82+
end)
83+
end),liblrsnash)
84+
else
85+
provides(BuildProcess,
86+
(@build_steps begin
87+
GetSources(liblrs)
88+
CreateDirectory(lrsprefixdir)
89+
CreateDirectory(lrslibdir)
90+
@build_steps begin
91+
ChangeDirectory(lrssrcdir)
92+
FileRule(joinpath(lrslibdir,"$lrslibname.$(Libdl.dlext)"),@build_steps begin
93+
`make $lrslibname.$(Libdl.dlext).0 SONAME=$lrslibname.$(Libdl.dlext) SHLIB=$lrslibname.$(Libdl.dlext).0`
94+
`cp $lrslibname.$(Libdl.dlext).0 $lrslibdir/$lrslibname.$(Libdl.dlext)`
95+
end)
96+
end
97+
end),liblrs)
98+
provides(BuildProcess,
99+
(@build_steps begin
100+
ChangeDirectory(lrssrcdir)
101+
FileRule(joinpath(lrslibdir,"liblrsnash.$(Libdl.dlext)"),@build_steps begin
102+
`cp $patchdir/makefile.liblrsnash $lrssrcdir`
103+
`make -f makefile.liblrsnash SHLIB=liblrsnash.$(Libdl.dlext) LIBLRSDIR=$lrslibdir`
104+
`cp liblrsnash.$(Libdl.dlext) $lrslibdir/liblrsnash.$(Libdl.dlext)`
105+
end)
106+
end),liblrsnash)
107+
end
108+
109+
BinDeps.@install Dict([(:liblrs, :liblrs),
110+
(:liblrsnash, :liblrsnash)])

deps/makefile.osx.patch

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- makefile.orig 2018-07-03 13:37:36.000000000 +0900
2+
+++ makefile 2019-01-20 12:17:48.000000000 +0900
3+
@@ -193,7 +193,7 @@ SHLIBBIN=lrs-shared lrsnash-shared
4+
# Building (linking) the shared library, and relevant symlinks.
5+
6+
${SHLIB}: ${SHLIBOBJ}
7+
- $(CC) -shared -Wl,-soname=$(SONAME) $(SHLIBFLAGS) -o $@ ${SHLIBOBJ} -lgmp
8+
+ $(CC) -shared -Wl,-install_name,$(SONAME) $(SHLIBFLAGS) -o $@ ${SHLIBOBJ} -L${LIBDIR} -lgmp
9+
10+
${SONAME}: ${SHLIB}
11+
ln -sf ${SHLIB} ${SONAME}

src/LRSLib.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ end
2222
include("lrstypes.jl")
2323

2424
function __init__()
25-
if Clrs_false == (@lrs_ccall init Clong (Ptr{Cchar},) C_NULL)
25+
# lrslib segfault if the name is `C_NULL`.
26+
if Clrs_false == (@lrs_ccall init Clong (Ptr{Cchar},) "LRSLib Julia wrapper")
2627
error("Initialization of LRS failed")
2728
end
2829
end

src/lrstypes.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ mutable struct Clrs_dic # dynamic dictionary data
4848
end
4949

5050
mutable struct Clrs_dat # global problem data
51+
redineq::Clong # holds indices of rows for redundancy check
52+
Ain::Clrs_mp_matrix # used only in redund to hold input matrix
5153
Gcd::Clrs_mp_vector # Gcd of each row of numerators
5254
Lcm::Clrs_mp_vector # Lcm for each row of input denominators
5355
output::Clrs_mp_vector # One line of output dimensioned to n
@@ -60,12 +62,14 @@ mutable struct Clrs_dat # global problem data
6062
unbounded::Clong # lp unbounded
6163
fname::Clrs_fname # input file name from line 1 of input
6264

63-
inequality::Ptr{Clong} # indices of inequalities corr. to cobasic ind
6465
# initially holds order used to find starting
6566
# basis, default: m,m-1,...,2,1
6667
facet::Ptr{Clong} # cobasic indices for restart in needed
6768
redundcol::Ptr{Clong} # holds columns which are redundant
69+
inequality::Ptr{Clong} # indices of inequalities corr. to cobasic ind
6870
linearity::Ptr{Clong} # holds cobasic indices of input linearities
71+
remain::Ptr{Clong}
72+
startcob::Ptr{Clong}
6973
minratio::Ptr{Clong} # used for lexicographic ratio test
7074
temparray::Ptr{Clong} # for sorting indices, dimensioned to d
7175
isave::Ptr{Clong}
@@ -110,17 +114,22 @@ mutable struct Clrs_dat # global problem data
110114
cest7::Clong
111115
cest8::Clong
112116
cest9::Clong # ests: 0=rays,1=vert,2=bases,3=vol,4=int vert
117+
nextineq::Clong
113118
#*** flags **********
114119
allbases::Clong # TRUE if all bases should be printed
115120
bound::Clong # TRUE if upper/lower bound on objective given
116121
countonly::Clong # TRUE if only count totals should be output
117122
debug::Clong
118123
dualdeg::Clong # TRUE if start dictionary is dual degenerate
119124
etrace::Clong # turn off debug at basis # strace
125+
extract::Clong
120126
frequency::Clong # frequency to print cobasis indices
121127
geometric::Clong # TRUE if incident vertex prints after each ray
122128
getvolume::Clong # do volume calculation
123129
givenstart::Clong # TRUE if a starting cobasis is given
130+
giveoutput::Clong
131+
verifyredund::Clong
132+
noredundcheck::Clong
124133
homogeneous::Clong # TRUE if all entries in column one are zero
125134
hull::Clong # do convex hull computation if TRUE
126135
incidence::Clong # print all tight inequalities (vertices/rays)
@@ -129,8 +138,10 @@ mutable struct Clrs_dat # global problem data
129138
maximize::Clong # flag for LP maximization
130139
maxoutput::Clong # if positive, maximum number of output lines
131140
maxcobases::Clong # if positive, after maxcobasis unexplored subtrees reported
141+
messages::Clong
132142
minimize::Clong # flag for LP minimization
133143
mindepth::Clonglong # do not backtrack above mindepth
144+
mplrs::Clong
134145
nash::Clong # TRUE for computing nash equilibria
135146
nonnegative::Clong # TRUE if last d constraints are nonnegativity
136147
polytope::Clong # TRUE for facet computation of a polytope

src/nash.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ function solve_nash(hr1::HMatrix, hr2::HMatrix)
4747
NEs = NTuple{2,Vector{Rational{BigInt}}}[]
4848

4949
# Step 1
50-
FirstTime = cglobal((:FirstTime, liblrsnash), Clong)
51-
unsafe_store!(FirstTime, Clrs_true)
50+
ccall((:resetNashSolver, liblrsnash), Cvoid, ())
5251

5352
unsafe_field_store!(hr1.Q, :nash, Clrs_true)
5453
unsafe_field_store!(hr2.Q, :nash, Clrs_true)

0 commit comments

Comments
 (0)