Opened 10 years ago
Closed 9 years ago
#10785 closed enhancement (fixed)
Setting solver-specific options
Reported by: | ncohen | Owned by: | ncohen |
---|---|---|---|
Priority: | major | Milestone: | sage-5.0 |
Component: | linear programming | Keywords: | |
Cc: | Merged in: | sage-5.0.beta0 | |
Authors: | Nathann Cohen | Reviewers: | Johannes Klaus Fichte |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
With this patch, it is now possible to set solver-specific options, like a time limit or a ratio of approximation (if you do not want to compute the optimal value, but something 10% away from it)
Nathann
Attachments (1)
Change History (18)
comment:1 Changed 10 years ago by
- Status changed from new to needs_review
- Type changed from PLEASE CHANGE to enhancement
comment:2 Changed 9 years ago by
- Status changed from needs_review to needs_info
Seems good so far. But in my sage version (4.7.1) the constructor of MixedIntegerLinearProgram? does not use it when given as a backend, since get_solver in the Generic Backend requires a String or None. So we should change to something like
__init__ ....
if isinstance(solver,GenericBackend):
...
else:
...
or even better change GenericBackend?.get_solver
if solver is None:
...
elif isinstance(solver,GenericBackend):
...
elif solver=="Coin":
...
But I may have overlooked something.
comment:3 Changed 9 years ago by
- Status changed from needs_info to needs_review
I am sorry but I do not understand what you mean O_o
. Could you give me an example ?
This being said, when reviewing a ticket, the sage version you should use is the latest developper's version, that is sage-4.8.alpha3 at this instant (see the sage-release google group)
Nathann
comment:4 Changed 9 years ago by
Sry. My mistake. I'll check it with the latest snapshot first ;-)
comment:5 Changed 9 years ago by
The lastest developper's version does not work for me. I have an build issue on ubuntu, so we have to postpone that one.
A short (hopefully better) description of the problem above:
The code online linked in trac is the latest developper's code, is't it?
When we create a new instance of a MixedIntegerLinearProgram? (see http://trac.sagemath.org/sage_trac/browser/sage/numerical/mip.pyx#L200) like
p = MixedIntegerLinearProgram(maximization=True)
, we call
get_solver(solver=solver, constraint_generation=constraint_generation)
Then get_solver(...) checks for a solver (e.g. CPLEX see http://trac.sagemath.org/sage_trac/browser/sage/numerical/backends/generic_backend.pyx#L90), but the solver is required to be a string, not an instance of a solver.
Since MixedIntegerLinearProgram? uses get_solver to obtain a solver, get_solver requires a string in the input, and the backend is hidden in the MixedIntegerLinearProgram, we will never be able to use the solver with special parameters in an instance of MixedIntegerLinearProgramm?, e.g:
my_solver = get_solver(solver = "CPLEX") my_solver.solver_parameter("timelimit", 60) p = MixedIntegerLinearProgram(solver=my_solver)
will fail. I do not see this addressed in the patch.
But I may be mistaken?
comment:6 Changed 9 years ago by
Well, you can use the solver_parameter method of MixedIntegerLinearProgram?, which is made for this very purpose. It is the part of the patch that modifies mip.pyx.
This being said, your remark also comes from the fact that the example given in this function directly calls get_solver instead of MixedIntegerLinearProgram?. I just updated the patch so that it is clearer.
Nathann
comment:7 Changed 9 years ago by
I have overlooked that method. I am almost fine.
Some minor points in the documentation:
In mip.pyx:1357 you write
"The solver parameters are by essence solver-specific, which means their meaning heavily depends on the solver used (it is GLPK by default)."
The priority is CPLEX, Coin, GLPK. I guess sage is released with GLPK. Thus it is still right, but we should clarify it or remove the statement about the default solver.
The import of example mip.pyx:1396 uses
from sage.numerical.backends.generic_backend import get_solver p = MixedIntegerLinearProgram() p.solver_parameter("timelimit", 60)
I think it has to be
from sage.numerical.mip import MixedIntegerLinearProgram p = MixedIntegerLinearProgram()
comment:8 Changed 9 years ago by
Patch updated ! I modified the sentence about the default solver, but the meaning is the same : "in case of doubt, you are using GLPK" :-)
And the MixedIntegerLinearProgram? does not need to be imported first, it is always present when working in a Sage terminal.
Nathann
comment:9 Changed 9 years ago by
- Status changed from needs_review to positive_review
:-)
Cool. I updated the status.
comment:10 Changed 9 years ago by
- Status changed from positive_review to needs_info
fichtejo: add your real name as Reviewer and also add yourself to http://trac.sagemath.org/sage_trac/#AccountNamesMappedtoRealNames please.
comment:11 Changed 9 years ago by
- Reviewers set to Johannes Klaus Fichte
- Status changed from needs_info to needs_review
Done.
comment:12 Changed 9 years ago by
- Status changed from needs_review to positive_review
comment:13 Changed 9 years ago by
- Status changed from positive_review to needs_work
I get a doctest failure:
sage -t -force_lib devel/sage/sage/numerical/mip.pyx Writing problem data to `/scratch/jdemeyer/merger/sage-4.8.alpha5/home/.sage//temp/sage.math.washington.edu/18491//lp_problem.mps'... 17 records were written Writing problem data to `/scratch/jdemeyer/merger/sage-4.8.alpha5/home/.sage//temp/sage.math.washington.edu/18491//lp_problem.lp'... 9 lines were written ********************************************************************** File "/mnt/usb1/scratch/jdemeyer/merger/sage-4.8.alpha5/devel/sage-main/sage/numerical/mip.pyx", line 1393: sage: p.solver_parameter("CPX_PARAM_TILIM", 60) Exception raised: Traceback (most recent call last): File "/mnt/usb1/scratch/jdemeyer/merger/sage-4.8.alpha5/local/bin/ncadoctest.py", line 1231, in run_one_test self.run_one_example(test, example, filename, compileflags) File "/mnt/usb1/scratch/jdemeyer/merger/sage-4.8.alpha5/local/bin/sagedoctest.py", line 38, in run_one_example OrigDocTestRunner.run_one_example(self, test, example, filename, compileflags) File "/mnt/usb1/scratch/jdemeyer/merger/sage-4.8.alpha5/local/bin/ncadoctest.py", line 1172, in run_one_example compileflags, 1) in test.globs File "<doctest __main__.example_27[4]>", line 1, in <module> p.solver_parameter("CPX_PARAM_TILIM", Integer(60))###line 1393: sage: p.solver_parameter("CPX_PARAM_TILIM", 60) File "mip.pyx", line 1414, in sage.numerical.mip.MixedIntegerLinearProgram.solver_parameter (sage/numerical/mip.c:7302) self._backend.solver_parameter(name, value) File "glpk_backend.pyx", line 1101, in sage.numerical.backends.glpk_backend.GLPKBackend.solver_parameter (sage/numerical/backends/glpk_backend.cpp:7916) ValueError: This parameter is not available. ********************************************************************** 1 items had failures: 1 of 9 in __main__.example_27 ***Test Failed*** 1 failures. For whitespace errors, see the file /scratch/jdemeyer/merger/sage-4.8.alpha5/home/.sage/tmp/sage.math.washington.edu-11856/mip_18486.py [3.2 s]
comment:14 Changed 9 years ago by
Oopppps............ Yep, clearly a "#optional - CPLEX" would be in order there.
Nathann
Changed 9 years ago by
comment:15 Changed 9 years ago by
- Status changed from needs_work to positive_review
comment:16 Changed 9 years ago by
- Milestone changed from sage-4.8 to sage-5.0
comment:17 Changed 9 years ago by
- Merged in set to sage-5.0.beta0
- Resolution set to fixed
- Status changed from positive_review to closed
I had forgotten to click on "needs_review"
T_T
Nathann