Skip to content

Commit

Permalink
Functions for getting string array attributes (#88)
Browse files Browse the repository at this point in the history
* Functions for getting string array attributes

adds get_strattrarray and get_strattrarray!

* Update grb_attrs.jl

* Add files via upload

* Update test_get_strarray.jl

* Update runtests.jl
  • Loading branch information
iaravena authored and mlubin committed Mar 15, 2017
1 parent b1cd971 commit 6d9f039
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/grb_attrs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,22 @@ function get_charattrarray(model::Model, name::String, start::Integer, len::Inte
get_charattrarray!(Array{Cchar}(len), model, name, start)
end

function get_strattrarray(model::Model, name::String, start::Integer, len::Integer)
@assert isascii(name)
get_strattrarray!(Array(Ptr{UInt8}, len), model, name, start)
end

function get_strattrarray!(r::Array{Ptr{UInt8}}, model::Model, name::String, start::Integer)
@assert isascii(name)
ret = @grb_ccall(getstrattrarray, Cint,
(Ptr{Void}, Ptr{UInt8}, Cint, Cint, Ptr{Ptr{UInt8}}),
model, name, start - 1, length(r), r)
if ret != 0
throw(GurobiError(model.env, ret))
end
map(unsafe_string, r)
end

# setters

function set_intattr!(model::Model, name::String, v::Integer)
Expand Down
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ tests = [
"mathprog",
"test_grb_attrs",
"env",
"range_constraints"
"range_constraints",
"test_get_strarray"
]

for t in tests
Expand Down
13 changes: 13 additions & 0 deletions test/test_get_strarray.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Gurobi
using Base.Test

# enviroment and problem
env = Gurobi.Env()
m = Gurobi.Model(env, "test")

# read mps problem in Gurobi
read_model(m, "test_get_strarray.mps")

# test functions
@test Gurobi.get_strattrarray(m, "VarName", 1, Gurobi.num_vars(m)) == ["XONE","YTWO","ZTHREE"]
@test Gurobi.get_strattrarray(m, "ConstrName", 1, Gurobi.num_constrs(m)) == ["LIM1","LIM2","MYEQN"]
22 changes: 22 additions & 0 deletions test/test_get_strarray.mps
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
*Source: http://lpsolve.sourceforge.net/5.5/mps-format.htm
NAME TESTPROB
ROWS
N COST
L LIM1
G LIM2
E MYEQN
COLUMNS
XONE COST 1 LIM1 1
XONE LIM2 1
YTWO COST 4 LIM1 1
YTWO MYEQN -1
ZTHREE COST 9 LIM2 1
ZTHREE MYEQN 1
RHS
RHS1 LIM1 5 LIM2 10
RHS1 MYEQN 7
BOUNDS
UP BND1 XONE 4
LO BND1 YTWO -1
UP BND1 YTWO 1
ENDATA

0 comments on commit 6d9f039

Please sign in to comment.