Skip to content

Commit

Permalink
handle duplicates in MPS writer, fixes #424
Browse files Browse the repository at this point in the history
  • Loading branch information
mlubin committed Apr 11, 2015
1 parent 0d57c82 commit 528e652
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
23 changes: 11 additions & 12 deletions src/writers.jl
Expand Up @@ -6,7 +6,7 @@
function writeMPS(m::Model, fname::String)
f = open(fname, "w")

write(f,"NAME MathProgModel\n")
write(f,"NAME JuMPModel\n")

numRows = length(m.linconstr)

Expand Down Expand Up @@ -47,31 +47,30 @@ function writeMPS(m::Model, fname::String)


nnz += length(objaff.coeffs)
colval = Array(Int,nnz)
rownzval = Array(Float64,nnz)
I = Array(Int,nnz)
J = Array(Int,nnz)
V = Array(Float64,nnz)
nnz = 0
for c in 1:numRows
rowptr[c] = nnz + 1
# TODO: type assertion shouldn't be necessary
constr::LinearConstraint = m.linconstr[c]
coeffs = constr.terms.coeffs
vars = constr.terms.vars
for ind in 1:length(coeffs)
nnz += 1
colval[nnz] = vars[ind].col
rownzval[nnz] = coeffs[ind]
I[nnz] = c
J[nnz] = vars[ind].col
V[nnz] = coeffs[ind]
end
end
rowptr[numRows+1] = nnz + 1
for ind in 1:length(objaff.coeffs)
nnz += 1
colval[nnz] = objaff.vars[ind].col
rownzval[nnz] = objlincoef[ind]
I[nnz] = numRows+1
J[nnz] = objaff.vars[ind].col
V[nnz] = objlincoef[ind]
end
rowptr[numRows+2] = nnz + 1

rowmat = SparseMatrixCSC(m.numCols,numRows+1, rowptr, colval, rownzval)
colmat = rowmat'
colmat = sparse(I,J,V,numRows+1,m.numCols)
colptr = colmat.colptr
rowval = colmat.rowval
nzval = colmat.nzval
Expand Down
6 changes: 3 additions & 3 deletions test/model.jl
Expand Up @@ -54,7 +54,7 @@ facts("[model] Test printing a model") do
@defConstrRef constraints[1:3]
constraints[1] = @addConstraint(modA, 2 <= x+y <= 4)
constraints[2] = @addConstraint(modA, sum{r[i],i=3:5} <= (2 - x)/2.0)
constraints[3] = @addConstraint(modA, 7.0*y <= z + r[6]/1.9)
constraints[3] = @addConstraint(modA, 6y + y <= z + r[6]/1.9)
#####################################################################
# Test LP writer
writeLP(modA, modPath * "A.lp")
Expand All @@ -65,7 +65,7 @@ facts("[model] Test printing a model") do
"c1: 1 VAR1 + 1 VAR2 >= 2",
"c2: 1 VAR1 + 1 VAR2 <= 4",
"c3: 1 VAR4 + 1 VAR5 + 1 VAR6 + .5 VAR1 <= 1",
"c4: 7 VAR2 - 1 VAR3 - .5263157894736842 VAR7 <= 0",
"c4: 6 VAR2 + 1 VAR2 - 1 VAR3 - .5263157894736842 VAR7 <= 0",
"Bounds",
"0 <= VAR1 <= +inf",
"-inf <= VAR2 <= 5",
Expand All @@ -89,7 +89,7 @@ facts("[model] Test printing a model") do
# Test MPS writer
writeMPS(modA, modPath * "A.mps")
modAMPS = ASCIIString[
"NAME MathProgModel",
"NAME JuMPModel",
"ROWS",
" N CON4",
" E CON1",
Expand Down

0 comments on commit 528e652

Please sign in to comment.