Skip to content

Commit

Permalink
allow more options in C interface by env COIN_CBC_OPTIONS
Browse files Browse the repository at this point in the history
  • Loading branch information
jjhforrest committed Aug 29, 2023
1 parent 51159cf commit efdc0d9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
6 changes: 1 addition & 5 deletions src/CbcModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1937,7 +1937,7 @@ void CbcModel::branchAndBound(int doStatistics)
if (!parentModel_) {
/*
Capture a time stamp before we start (unless set).
*/
*/
if (!dblParam_[CbcStartSeconds]) {
if (!useElapsedTime())
dblParam_[CbcStartSeconds] = CoinCpuTime();
Expand Down Expand Up @@ -14523,13 +14523,9 @@ nPartiallyFixed %d , nPartiallyFixedBut %d , nUntouched %d\n",
name = lastHeuristic_->heuristicName();
else
name = "Reduced search";
// temp to see if threaded passing solutions back
int saveLevel = handler_->logLevel();
handler_->setLogLevel(1);
handler_->message(CBC_ROUNDING, messages_)
<< trueBestObjValue() << name << numberIterations_ << numberNodes_
<< getCurrentSeconds() << CoinMessageEol;
handler_->setLogLevel(saveLevel);
dealWithEventHandler(CbcEventHandler::heuristicSolution, objectiveValue,
solution);
}
Expand Down
53 changes: 52 additions & 1 deletion src/Cbc_C_Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2371,7 +2371,58 @@ Cbc_solve(Cbc_Model *model)
inputQueue.push_back(ss.str());
}
}

// add in from options file
if (getenv("COIN_CBC_OPTIONS")) {
FILE * fp =fopen(getenv("COIN_CBC_OPTIONS"),"r");
if (fp) {
char line[512];
int logLevel = Cbc_getLogLevel(model);
if (logLevel)
printf("Adding options from file %s\n",getenv("COIN_CBC_OPTIONS"));
while (fgets(line, 200, fp)) {
// skip comment
if (line[0]=='*')
continue;
int nchar = strlen(line);
if (nchar<2)
continue;
if (line[0]!='-') {
memmove(line+1,line,nchar+1);
nchar++;
line[0]='-';
}
char *pos=line;
char *put=line;
while (true) {
while (*pos != '\n' && *pos != '\0'
&& *pos != ' ' && *pos != '\t')
pos++;
char save = *pos;
*pos = '\0';
if (strlen(put)) {
inputQueue.push_back(put);
if (logLevel)
std::cout << put << " ";
}
if (save == ' ' || save == '\t') {
pos++;
while (*pos == ' ' || *pos == '\t')
pos++;
put = pos;
} else {
break; // end of line
}
}
}
if (logLevel)
std::cout << std::endl;
fclose(fp);
} else {
fprintf(stderr, "Unable to open COIN_CBC_OPTIONS file %s\n",
getenv("COIN_CBC_OPTIONS"));
fflush(stderr);
}
}
inputQueue.push_back("-solve");
inputQueue.push_back("-quit");

Expand Down

0 comments on commit efdc0d9

Please sign in to comment.