Skip to content

Commit

Permalink
Merge pull request #125 from JuliaOpt/warnoption
Browse files Browse the repository at this point in the history
Fix #122
  • Loading branch information
IainNZ committed Mar 10, 2014
2 parents 491fbe3 + 4ad9eb0 commit 6287e2a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
1 change: 1 addition & 0 deletions doc/refmodel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Methods
* ``getNumVars(m::Model)`` - returns the number of variables associated with the ``Model m``.
* ``getNumConstraints(m::Model)`` - returns the number of constraints associated with the ``Model m``.
* ``getSolverModel(m::Model)`` - returns the internal low-level ``AbstractMathProgModel`` object which can be used to access any functionality that is not exposed by JuMP. See the MathProgBase `documentation <http://mathprogbasejl.readthedocs.org/en/latest/mathprogbase.html#low-level-interface>`_.
* ``solve(m::Model; load_model_only=false, suppress_warnings=false)`` - solves the model using the selected solver (or a default for the problem class), and takes two optional arguments that are disabled by default. For the details of ``load_model_only`` see :ref:`probmod`. Setting ``suppress_warnings`` to ``true`` will suppress all JuMP-specific output (e.g. warnings about infeasibility and lack of dual information) but will not suppress solver output (which should be done by passing options to the solver).

**Objective**

Expand Down
30 changes: 15 additions & 15 deletions src/solvers.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function solve(m::Model; load_model_only=false)
function solve(m::Model; load_model_only=false, suppress_warnings=false)
# Analyze model to see if any integers
anyInts = false
for j = 1:m.numCols
Expand All @@ -15,22 +15,22 @@ function solve(m::Model; load_model_only=false)
if anyInts
if isa(m.solver,MathProgBase.MissingSolver)
m.solver = MathProgBase.defaultMIPsolver
s = solveMIP(m; load_model_only=load_model_only)
s = solveMIP(m; load_model_only=load_model_only, suppress_warnings=suppress_warnings)
# Clear solver in case we change problem types
m.solver = MathProgBase.MissingSolver("",Symbol[])
m.internalModelLoaded = false
return s
else
solveMIP(m; load_model_only=load_model_only)
solveMIP(m; load_model_only=load_model_only, suppress_warnings=suppress_warnings)
end
else
if isa(m.solver,MathProgBase.MissingSolver)
m.solver = MathProgBase.defaultLPsolver
s = solveLP(m, load_model_only=load_model_only)
s = solveLP(m, load_model_only=load_model_only, suppress_warnings=suppress_warnings)
m.solver = MathProgBase.MissingSolver("",Symbol[])
return s
else
solveLP(m; load_model_only=load_model_only)
solveLP(m; load_model_only=load_model_only, suppress_warnings=suppress_warnings)
end
end
end
Expand Down Expand Up @@ -157,7 +157,7 @@ function prepConstrMatrix(m::Model)
A = rowmat'
end

function solveLP(m::Model; load_model_only=false)
function solveLP(m::Model; load_model_only=false, suppress_warnings=false)
f, rowlb, rowub = prepProblemBounds(m)

# Ready to solve
Expand All @@ -170,7 +170,7 @@ function solveLP(m::Model; load_model_only=false)
setconstrUB!(m.internalModel, rowub)
setobj!(m.internalModel, f)
catch
warn("LP solver does not appear to support hot-starts. Problem will be solved from scratch.")
!suppress_warnings && warn("LP solver does not appear to support hot-starts. Problem will be solved from scratch.")
m.internalModelLoaded = false
end
all_cont = true
Expand Down Expand Up @@ -199,18 +199,18 @@ function solveLP(m::Model; load_model_only=false)
if stat == :NotSolved
# do nothing
elseif stat != :Optimal
warn("LP not solved to optimality, status: $stat")
!suppress_warnings && warn("LP not solved to optimality, status: $stat")
if stat == :Infeasible
try
m.linconstrDuals = getinfeasibilityray(m.internalModel)
catch
println("Infeasibility ray (Farkas proof) not available")
!suppress_warnings && println("Infeasibility ray (Farkas proof) not available")
end
elseif stat == :Unbounded
try
m.colVal = getunboundedray(m.internalModel)
catch
println("Unbounded ray not available")
!suppress_warnings && println("Unbounded ray not available")
end
end
else
Expand All @@ -222,14 +222,14 @@ function solveLP(m::Model; load_model_only=false)
m.redCosts = getreducedcosts(m.internalModel)
m.linconstrDuals = getconstrduals(m.internalModel)
catch
Base.warn_once("Dual solutions not available")
!suppress_warnings && Base.warn_once("Dual solutions not available")
end
end

return stat
end

function solveMIP(m::Model; load_model_only=false)
function solveMIP(m::Model; load_model_only=false, suppress_warnings=false)
f, rowlb, rowub = prepProblemBounds(m)
A = prepConstrMatrix(m)

Expand All @@ -254,7 +254,7 @@ function solveMIP(m::Model; load_model_only=false)
setobj!(m.internalModel, f)
setvartype!(m.internalModel, vartype)
catch
warn("LP solver does not appear to support hot-starts. Problem will be solved from scratch.")
!suppress_warnings && warn("LP solver does not appear to support hot-starts. Problem will be solved from scratch.")
m.internalModelLoaded = false
end
end
Expand All @@ -276,7 +276,7 @@ function solveMIP(m::Model; load_model_only=false)
try
setwarmstart!(m.internalModel, m.colVal)
catch
Base.warn_once("MIP solver does not appear to support warm start solution.")
!suppress_warnings && Base.warn_once("MIP solver does not appear to support warm start solution.")
end
end

Expand All @@ -300,7 +300,7 @@ function solveMIP(m::Model; load_model_only=false)
end
end
if stat != :Optimal
println("Warning: MIP not solved to optimality, status: ", stat)
!suppress_warnings && println("Warning: MIP not solved to optimality, status: ", stat)
end

return stat
Expand Down

0 comments on commit 6287e2a

Please sign in to comment.