Initial merge of the refactor branch #465
tkralphs
announced in
Announcements
Replies: 2 comments 1 reply
-
I'm trying to update some Cbc interface code that was processing the Cbc parameters.
Are these options going to be completely removed, or will they come back? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Stefan,
On 18/01/2022 05:33, Stefan Vigerske wrote:
I'm trying to update some Cbc interface code that was processing the
Cbc parameters.
There are two options that I had before and seem to have vanished:
1. |costStrategy|: I see it mentioned in the |CbcParamCode| enum in
|CbcParam.hpp|, but it does not seem to appear in the vector of
parameters I get from |CbcParameters::paramVec()|.
This seems to have been renamed as branchStrategy.
1. |pivotAndComplement|: I see it mentioned in the |CbcParamCode|
enum in |CbcParam.hpp|, but it does not seem to appear in the
vector of parameters I get from |CbcParameters::paramVec()|. There
is code about it in |CbcParamUtils.cpp| that is commented out with
an |#if 0|.
This does not seem to be in stable either - I can't find the code
anywhere in last few years. Also looking at pivotAndFix, that exists
and can be called but does not seem to do anything with default defines
- and if you modify defines there is coding such as -
std::cout << "Lucky you! You're in the Pivot-and-Fix Heuristic" <<
std::endl;
which would imply that this is not finished code - I will look further.
Are these options going to be completely removed, or will they come back?
John
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
TL;DR: The refactor branch will be merged on 1/1/2022. There are some changes to various interfaces. For a limited time, compatibility files that allow switching back to the "old style" are provided in the
src/Attic
subdirectory. Details below.Cbc is has been undergoing a major refactoring for some time. This has been moving slowly due to a lack of developer bandwidth. This refactoring is not expected to affect the performance of the code in general, but it is highly likely that there will be some random side effects. We would be happy to hear about any serious regressions, but please keep in mind that while performance is expected to be similar on the whole, performance on individual instances could vary (as one would expect with any change). The goals of the refactoring are only to address readability, maintainability, and usability.
Overall goals
As a reminder (see also #374), here are some of the main goals of this refactoring.
ClpMain0()
andClpMain1()
.CbcMain1()
, splitting the while loop into separate functions.Here is what has been done so far and that will be merged from the current
refactor
branch.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).CbcSolver
) is controlled by the log parameter through the proper message handler.libCbcSolver
, which didn't seem to serve a purpose.Changes to the interface
In this first step of the refactoring, we have endeavored not to change the interfaces too dramatically, but there are some differences, summarized here. Note that we may have missed some things, so feel free to let us know in the comments about differences you run into that trip you up in the conversion. Also, if there are any differences that you feel make the interface worse, let us know that. The changes were intended to be improvements, but we may have missed the mark.
Command line interface
Most of the changes to the command-line interface that users will notice come from changes made to allow for better parsing and validation of parameter values. There are two additional parameter types,
Directory
andFile
, so that values assigned to parameters that are expected to be file or directory names can be properly validated to ensure they specify valid paths. This avoids later errors when trying to open files and bugs that have been reported by users over time. The parameter types are as follows.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.The main changes to how parameters are specified both on the command line and in the interactive console are as follows.
(Almost) all parameters that end in
File
(e.g.,exportF(ile)
,mipStartF(ile)
) are used to set the default file location/name for certain input/output files. Similarly, parameters that begin withdir
specify a directory that is the default location for some file type.File name parameters are all associated with actions that involve reading or writing from the files whose names they specify. For actions involving writing/reading to a file, a
$
was previously used to indicate that the action should be performed using "the same file as the last time the action was performed," but this is no longer supported. Instead, the previous (or initial default) file name will be used automatically if no argument is provided to the action parameter.As described above, there is a separate command for setting the default file name. Alternatively, if a file name is given as an argument, then this also automatically sets the file name. To exemplify what all this means, here are some basic commands as they would be given in the interactive console, with explanations
read
is something that reads a file and a parameters beginning withwrite
is something that writes a file.print
should usually write to the standard output. This is to replace the old mechanism, which was to use the special file name-
.log(Level)
andlplog(Level)
, which is hopefully more memorable.Changes to the API
Cbc is still invoked by calling
CbcMain0()
andCbcMain1()
, as before, but the signatures of these functions have changed to reflect changes to the underlying implementation (the old signatures continue to work through wrapper functions). The signature ofCbcMain0
is nowwhere
model
is aCbcModel
object, as before, andparameters
is an object containing parameter settings. To obtain aCbcParameters
object pre-populated with default parameter settings, simply use its default constructor.Parameters can then be customized individually using the new mechanism for setting parameter values described in more detail below. The signature of
CbcMain1
has also changed. It is nowThe
inputQueue
is a standard deque containing the strings making up the command line, which is in turn just a list of commands for setting parameters. parameters names are preceded by a-
. A convenience method for building an input queue from strings is provided, so that a simple sequence of commands for solving a MIP would then be.Note that the
callBack
andampl_info
arguments toCbcMain1()
have default values, so these are not ordinarily needed in callingCbcMain1
.More Details on 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 typesFilenames
: 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.More Details on 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.Restoring the old interface
To restore the old interface, simply copy files from
src/Attic
tosrc
in both Clp and Cbc. To do so, invoke the following commands from the root of acoinbrew
checkout.To restore the new version just do
git reset --hard HEAD
in both theCbc
andClp
subdirectories.Obtaining Cbc
master
branch prior to refactoringBeta Was this translation helpful? Give feedback.
All reactions