coin-or / Cbc.old

This is a mirror of the subversion repository on COIN-OR
https://projects.coin-or.org/Cbc
Other
89 stars 30 forks source link

[Trac #101] error in processing of input in callCbc1 #103

Open s-c-e opened 5 years ago

s-c-e commented 5 years ago

image

There is an error in the way callCbc1 processing the Cbc input parameters: only the first parameter is processed. This concerns the

int callCbc1(const char * input2, CbcModel & model,
             int callBack(CbcModel * currentSolver, int whereFrom))

function from file CbcSolver.cpp, lines 1020-1066 in release 2.5.0.

I think there should be an i++ statement somewhere after line 1060. Without it, the saveI for the next token points at the '\0' character, so all further tokens are returned as empty strings.. In addition, the input[0] == '0' at line 1025 is almost surely wrong - I think we should have tested for a space there.

Anyway, I think the code is unnecessarily complicated (and hence prone to errors) and would thus suggest to replace lines 1023-1066 with something like

    istringstream cbcArgStr(input2);
    vector<string> cbcArgVect;
    copy(istream_iterator<string>(cbcArgStr),
         istream_iterator<string>(),
         back_inserter<vector<string> >(cbcArgVect));
    int n = cbcArgVect.size();
    char ** argv = new char * [n+2];
    argv[0]=CoinStrdup("cbc");
    for (int i = 0; i < n; ++i) {
        argv[i + 1] = CoinStrdup(cbcArgVect[i].c_str());
    }
    cbcArgVect.clear();
    argv[n+1]=CoinStrdup("-quit");

(adapted from ​http://stackoverflow.com/questions/236129/how-to-split-a-string)

=====

In addition, shouldn't we add also "-solve" at the end of the list, just before "-quit" (so we would have n+3 tokens)? The way it is now, the user has to include "-solve" in the input string, since without it cbc does not do anything.