-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Cbc #374
Refactor Cbc #374
Conversation
Concerning "Eliminate irrelevant/old #ifdefs or change them to parameters instead." I suggest to drop "NEW_DEBUG_AND_FILL" in CbcSolver.cpp as unitialized reads can be found using valgrind, MemorySanitizer, ... without fiddling with overriding new/delete (and missing any malloc'd memory). Does anyone know something about "CLP_MALLOC_STATISTICS" in CbcSolver.cpp? The code does not even compile due to
|
85f0208
to
1b5f4f5
Compare
I suggest we open a new issue listing all of the ifdefs to see if we can collect information on which ones are important to retain or at least which ones actually build. @tosttost would you take this on? |
I'll try to grep the #ifdef and run some parsing on the matches at some point in time, but currently my priority is #ifdef is somewhat related to 2.) as some global variables are inside #ifdef, so there might be some quick wins. |
…all global variables, forward declarations, includes, and symbol definitions together at top
…hanging to use of COINUTILS_HAS_GLPK, no longer check for Glpk in configure
…an be reformatted.
…ster. It may have been introduced by the reformatting, need to check that.
Switch from deprecated windows-2016 to new windows-2022.
Although the task list is incomplete, we plan to merge what has been done so far on this long-standing PR on 1/1/2022 in order to encourage broader review and comment from the community (see #465). Work will continue following the merge, but in a separate PR. More details will be provided in an accompanying announcement, which will be linked here once it's made.
Cbc is is currently undergoing a major refactoring. Importantly, this refactoring is not expected to affect the performance of the code in any way. The goals only regard improving readability, maintainability, and usability.
This pull request is mainly for the purposes of documenting the changes being made so that other maintainers can review and follow along. It is also a task list that anyone who wants to contribute can consult to see what needs to be done.
See also: coin-or/Clp#166 and coin-or/CoinUtils#139
Here are some of the main goals of this refactoring.
ClpMain0()
andClpMain1()
.CbcMain1()
, splitting the while loop into separate functions.Here is the task list, including what has already been done.
CoinUtils
.CoinUtils
for reading input from command-line, file, or environment.CbcParam
derived fromCoinParam
.CbcParameters
class with methods to set up parameters and contain the vector of parameters.CbcParameters
class representing different possible parameters settings (e.g., emphasize optimality versus feasibility).std::cout
and make sure all output (at least inCbcSolver
) is controlled by the log parameter through the proper message handler.libCbcSolver
, which didn't seem to serve a purpose.CbcModel
with main parameter-setting mechanism (seeCbcModelParameters.hpp
).CbcSolver
class.CbcMain1
, moving local variables into theCbcSolver
class.#ifdef
s or change them to parameters instead.master
branch to identify any regressions.Things to consider
readline
to enable automatic command completion and further simplify parameter setting.CoinUtils
to unifyClpParameters
andCbcParameters
Some details about particular aspects of what has already been done.
Parameter mechanism
There are two main classes and some utilities.
CbcParam
class is derived fromCoinParam
and hold information for a single parameter (value, type, upper and lower limits, help strings, etc.).CbcParameters
contains a vector ofCbcParam
objects representing the current settings.CbcParam
Each parameter has a unique code, which is also its index in the parameter vector stored in the
CbcParameters
class (described below). The codes are specified in theCbcParamCode
enum within theCbcParam
class.Parameters also have a type, which can be queried and is one of
Double
: Parameters whose value is a doubleInteger
: Parameters whose value is an integerString
: Parameters whose value is a stringDirectory
: For storing directory names, such as default locations for file typesFile
: For storing the locations/names of filesKeyword
: Parameters that have one of several enumerated values identified by either strings or corresponding integer modes.Action
: Not parameters in the traditional sense, but used to trigger actions, such as solving an instance.There are different constructors for each type, as well as
setup
functions for populating an existing parameter object withFor keyword parameters, there is also a mechanism for creating a mapping between keyword value strings and the so-called "mode" value, which is an integer. The value of a keyword parameter can be set or retrieved either as a keyword string or as an integer mode. The modes may also be specified in enums.
There are separate get/set methods for each parameter type, but for convenience, there is also a single
setVal()
andgetVal()
method that is overloaded and can set the value of any parameter (the input/output is interpreted based on the known parameter type), e.g.,Each parameter object also has optional "push" (and "pull") function that can perform actions or populate related data structures upon the setting of a parameter value. The push/pull functions are defined with the
CbcParamUtils
name space, described below.None of the methods in the class produce output directly. The get/set methods can optionally populate a string object that is passed in as an optional second argument. This is to allow the calling function to control output by piping the string to a message handler as appropriate or simply ignoring it if printing is not desired. This obviates the need to control printing internal to the functions themselves, which would require a separate parameter.
CbcParameters
The
CbcParameters
class serves primarily as a container for a vector of parameters, but can (and will) be used to store other auxiliary information that needs to be accessed by the methods of (soon-to-be)CbcSolver
class. The class has methods for setting parameter values, which are pass-throughs to the methods of theCbcParam
class. It also defines a[]
operator, so that parameter objects contained in the parameter vector, which is a class member, can be directly accessed, e.g.,The constructor of the class calls a method, which sets up all the parameters (as described above). It is envisioned that different constructors will eventually be used to obtain different sets of parameters for different purposes.
CbcParamUtils
There are a number of utilities contained in the
CbcParamUtils
namespace. Mostly, these are the push functions that can extend the functionality of the set methods of the CbcParam class.Input/Output mechanism
The input/output mechanism is used to pass a sequence of parameters to Cbc, including action parameters. This parameter sequence can be set equivalently passed in five different ways.
Regardless of the method, the parameter sequence is stored and accessed as a FIFO queue of strings (
inputQueue
). This can be passed as an input to what is currentlyCbcMain1
or constructed within the mainwhile
loop by parsing either interactive input, the contents of an environment variable, or the contents of a parameter file.The main
while
loop then pops strings off the input queue, looks them up in the parameters list and deals with the result.Changes to Behavior of the Solver
While the goal was to make the changes completely transparent to end users, there were a few changes.
$
to stand for using the default file name.printSolution
was introduced that always writes the solution tostdout
.TODO items to consider
$
for using the default file name).