Opened 9 years ago

Closed 7 weeks ago

#101 closed defect (migrated)

error in processing of input in callCbc1

Reported by: mkaut Owned by:
Priority: major Component: Cbc
Version: 2.5 Keywords:
Cc:

Description

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)

Change History (2)

comment:1 Changed 9 years ago by mkaut

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.

comment:2 Changed 7 weeks ago by stefan

  • Component set to Cbc
  • Resolution set to migrated
  • Status changed from new to closed

This ticket has been migrated to GitHub and will be resolved there: https://github.com/coin-or/Cbc/issues/101

Note: See TracTickets for help on using tickets.