Skip to content

Commit 06a432e

Browse files
committed
try and improve idiot and sprint
1 parent adc06ad commit 06a432e

File tree

5 files changed

+177
-39
lines changed

5 files changed

+177
-39
lines changed

src/ClpMessage.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static Clp_message clp_us_english[] = {
7272
{ CLP_MATRIX_CHANGE, 31, 2, "Matrix can not be converted into %s" },
7373
{ CLP_TIMING, 32, 1, "%s objective %.10g - %d iterations time %.2f2%?, Presolve %.2f%?, Idiot %.2f%?" },
7474
{ CLP_INTERVAL_TIMING, 33, 2, "%s took %.2f seconds (total %.2f)" },
75-
{ CLP_SPRINT, 34, 1, "Pass %d took %d iterations, objective %g, dual infeasibilities %g( %d)" },
75+
{ CLP_SPRINT, 34, 1, "Pass %d took %d iterations, objective %g, dual infeasibilities %g( %d) - sum artificials %g - %d columns" },
7676
{ CLP_BARRIER_ITERATION, 35, 1, "%d Primal %g Dual %g Complementarity %g - %d fixed, rank %d" },
7777
{ CLP_BARRIER_OBJECTIVE_GAP, 36, 3, "Feasible - objective gap %g" },
7878
{ CLP_BARRIER_GONE_INFEASIBLE, 37, 2, "Infeasible" },

src/ClpSimplexPrimal.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2925,8 +2925,8 @@ void ClpSimplexPrimal::perturb(int type)
29252925
maximumFraction *= 0.1;
29262926
}
29272927
if (savePerturbation == 51) {
2928-
perturbation = std::min(0.1, perturbation);
2929-
maximumFraction *= 0.1;
2928+
perturbation = std::min(0.001, perturbation);
2929+
maximumFraction *= 0.001;
29302930
}
29312931
if (number != numberRows_)
29322932
type = 1;

src/ClpSolve.cpp

+32-30
Original file line numberDiff line numberDiff line change
@@ -542,10 +542,12 @@ void instrument_print()
542542
}
543543
}
544544
#endif
545-
#if ABC_PARALLEL == 2
545+
//#if ABC_PARALLEL == 2
546+
#if CLP_HAS_ABC > 2
546547
#ifndef FAKE_CILK
547548
int number_cilk_workers = 0;
548549
#include <cilk/cilk_api.h>
550+
#include <cilk/cilk.h>
549551
#endif
550552
#endif
551553
#ifdef ABC_INHERIT
@@ -659,8 +661,8 @@ ClpSimplex::dealWithAbc(int solveType, int startUp,
659661
#ifndef FAKE_CILK
660662
char temp[3];
661663
sprintf(temp, "%d", numberCpu);
662-
__cilkrts_set_param("nworkers", temp);
663-
printf("setting cilk workers to %d\n", numberCpu);
664+
//__cilkrts_set_param("nworkers", temp);
665+
printf("setting cilk workers to %d XX use env CILK_NWORKERS\n", numberCpu);
664666
number_cilk_workers = numberCpu;
665667

666668
#endif
@@ -2410,7 +2412,8 @@ int ClpSimplex::initialSolve(ClpSolve &options)
24102412
}
24112413
#endif
24122414
#ifndef LACI_TRY
2413-
if (options.getSpecialOption(1) != 2 || options.getExtraInfo(1) < 1000000) {
2415+
if (model2->status()&&
2416+
(options.getSpecialOption(1) != 2 || options.getExtraInfo(1) < 1000000)) {
24142417
if (dynamic_cast< ClpPackedMatrix * >(matrix_)) {
24152418
// See if original wanted vector
24162419
ClpPackedMatrix *clpMatrixO = dynamic_cast< ClpPackedMatrix * >(matrix_);
@@ -2795,7 +2798,7 @@ int ClpSimplex::initialSolve(ClpSolve &options)
27952798
int totalIterations = 0;
27962799
double lastSumArtificials = COIN_DBL_MAX;
27972800
int originalMaxSprintPass = maxSprintPass;
2798-
maxSprintPass = 20; // so we do that many if infeasible
2801+
maxSprintPass = std::max(0,maxSprintPass); // so we do that many if infeasible
27992802
for (iPass = 0; iPass < maxSprintPass; iPass++) {
28002803
//printf("Bug until submodel new version\n");
28012804
//CoinSort_2(sort,sort+numberSort,weight);
@@ -2832,6 +2835,9 @@ int ClpSimplex::initialSolve(ClpSolve &options)
28322835
}
28332836
#endif
28342837
small.setDblParam(ClpObjOffset, originalOffset - offset);
2838+
int smallMore = small.moreSpecialOptions();
2839+
smallMore &= ~1048576; // make sure can't stop early
2840+
small.setMoreSpecialOptions(smallMore);
28352841
model2->clpMatrix()->times(1.0, fullSolution, sumFixed);
28362842

28372843
double *lower = small.rowLower();
@@ -2862,6 +2868,7 @@ int ClpSimplex::initialSolve(ClpSolve &options)
28622868
if (dynamic_cast< ClpPackedMatrix * >(matrix) && clpMatrixO->wantsSpecialColumnCopy()) {
28632869
ClpPackedMatrix *clpMatrix = dynamic_cast< ClpPackedMatrix * >(matrix);
28642870
clpMatrix->makeSpecialColumnCopy();
2871+
small.setMaximumIterations(std::max(small.numberRows(),1000));
28652872
small.primal(1);
28662873
clpMatrix->releaseSpecialColumnCopy();
28672874
} else {
@@ -2954,19 +2961,17 @@ int ClpSimplex::initialSolve(ClpSolve &options)
29542961
}
29552962
int smallIterations = small.numberIterations();
29562963
totalIterations += smallIterations;
2957-
if (2 * smallIterations < std::min(numberRows, 1000) && iPass) {
2964+
if ((2 * smallIterations < std::min(numberRows, 1000)||small.status()==3) && iPass) {
29582965
int oldNumber = smallNumberColumns;
29592966
if (smallIterations < 100)
29602967
smallNumberColumns *= 1.2;
29612968
else
29622969
smallNumberColumns *= 1.1;
29632970
smallNumberColumns = std::min(smallNumberColumns, numberColumns);
2964-
if (smallIterations < 200 && smallNumberColumns > 2 * saveSmallNumber) {
2971+
if (smallIterations < 200) {
29652972
// try kicking it
2966-
emergencyMode = true;
2967-
smallNumberColumns = numberColumns;
2973+
smallNumberColumns *= 1.5;
29682974
}
2969-
// smallNumberColumns = std::min(smallNumberColumns, 3*saveSmallNumber);
29702975
char line[100];
29712976
sprintf(line, "sample size increased from %d to %d",
29722977
oldNumber, smallNumberColumns);
@@ -3020,15 +3025,13 @@ int ClpSimplex::initialSolve(ClpSolve &options)
30203025
}
30213026
handler_->message(CLP_SPRINT, messages_)
30223027
<< iPass + 1 << small.numberIterations() << small.objectiveValue() << sumNegative
3023-
<< numberNegative
3028+
<< numberNegative << sumArtificials << small.numberColumns()
30243029
<< CoinMessageEol;
30253030
if (sumArtificials < 1.0e-8 && originalMaxSprintPass >= 0) {
30263031
maxSprintPass = iPass + originalMaxSprintPass;
30273032
originalMaxSprintPass = -1;
30283033
}
3029-
if (iPass > 20)
3030-
sumArtificials = 0.0;
3031-
if ((small.objectiveValue() * optimizationDirection_ > lastObjective[1] - 1.0e-7 && iPass > 15 && sumArtificials < 1.0e-8 && maxSprintPass < 200) || (!small.numberIterations() && iPass) || iPass == maxSprintPass - 1 || small.status() == 3) {
3034+
if ((small.objectiveValue() * optimizationDirection_ > lastObjective[1] - 1.0e-7 && iPass > 15 && sumArtificials < 1.0e-8 && maxSprintPass < 200) || (!small.numberIterations() && iPass) || iPass == maxSprintPass - 1) {
30323035

30333036
break; // finished
30343037
} else {
@@ -3045,22 +3048,21 @@ int ClpSimplex::initialSolve(ClpSolve &options)
30453048
int saveN = numberSort;
30463049
for (iColumn = 0; iColumn < numberColumns; iColumn++) {
30473050
double dj = djs[iColumn] * optimizationDirection_;
3048-
double value = fullSolution[iColumn];
3049-
if (model2->getColumnStatus(iColumn) != ClpSimplex::basic) {
3050-
if (dj < -dualTolerance_ && value < columnUpper[iColumn])
3051-
/*dj = dj*/;
3052-
else if (dj > dualTolerance_ && value > columnLower[iColumn])
3053-
dj = -dj;
3054-
else if (columnUpper[iColumn] > columnLower[iColumn])
3055-
dj = fabs(dj);
3056-
else
3057-
dj = 1.0e50;
3058-
if (dj < tolerance) {
3059-
weight[numberSort] = dj;
3060-
sort[numberSort++] = iColumn;
3061-
}
3062-
}
3063-
}
3051+
ClpSimplex::Status colStatus = model2->getColumnStatus(iColumn);
3052+
if (colStatus == ClpSimplex::isFree || colStatus == ClpSimplex::superBasic) {
3053+
dj = - fabs(dj);
3054+
} else if (colStatus == ClpSimplex::atLowerBound) {
3055+
dj = dj;
3056+
} else if (colStatus == ClpSimplex::atUpperBound) {
3057+
dj = -dj;
3058+
} else {
3059+
continue;
3060+
}
3061+
if (dj < tolerance) {
3062+
weight[numberSort] = dj;
3063+
sort[numberSort++] = iColumn;
3064+
}
3065+
}
30643066
// sort
30653067
CoinSort_2(weight + saveN, weight + numberSort, sort + saveN);
30663068
//if (numberSort < smallNumberColumns)

src/Idiot.cpp

+132-4
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,18 @@ static int countCostedSlacks(OsiSolverInterface *model)
336336
void Idiot::crash(int numberPass, CoinMessageHandler *handler,
337337
const CoinMessages *messages, bool doCrossover)
338338
{
339+
// use last digit
340+
if (numberPass%10) {
341+
lightWeight_=0;
342+
int option = numberPass%10;
343+
numberPass -= option;
344+
if ((option&1)!=0)
345+
strategy_ |= 1048576; // extra bit at end
346+
if ((option&2)!=0)
347+
strategy_ |= 4194304; // limited presolve
348+
else if ((option&4)!=0)
349+
strategy_ |= 2097152; // no presolve
350+
}
339351
// lightweight options
340352
int numberColumns = model_->getNumCols();
341353
const double *objective = model_->getObjCoefficients();
@@ -974,6 +986,12 @@ void Idiot::solve2(CoinMessageHandler *handler, const CoinMessages *messages)
974986
numberAway = n;
975987
keepinfeas = result.infeas;
976988
lastWeighted = result.weighted;
989+
if (iteration == majorIterations_&&(strategy_&1048576)!=0) {
990+
// do a few more
991+
mu = std::min(mu,1.0e-11);
992+
majorIterations_+=10;
993+
strategy_ &= ~1048576; // switch off
994+
}
977995
//iterationTotal += result.iteration;
978996
if (iteration == 1) {
979997
if ((strategy_ & 1024) != 0 && mu < 1.0e-10)
@@ -1305,6 +1323,8 @@ void Idiot::crossOver(int mode)
13051323
return;
13061324
}
13071325
double fixTolerance = IDIOT_FIX_TOLERANCE;
1326+
bool wantVector = false;
1327+
bool justValuesPass = false;
13081328
#ifdef COIN_DEVELOP
13091329
double startTime = CoinCpuTime();
13101330
#endif
@@ -1356,6 +1376,9 @@ void Idiot::crossOver(int mode)
13561376
double *saveRowUpper = NULL;
13571377
double *saveRowLower = NULL;
13581378
bool allowInfeasible = ((strategy_ & 8192) != 0) || (majorIterations_ > 1000000);
1379+
ClpSimplex * saveModelX = NULL;
1380+
if ((strategy_&(2097152|4194304))!=0)
1381+
saveModelX = new ClpSimplex (*model_);
13591382
if (addAll < 3) {
13601383
saveUpper = new double[ncols];
13611384
saveLower = new double[ncols];
@@ -1447,6 +1470,7 @@ void Idiot::crossOver(int mode)
14471470
// model_->setPerturbation(56);
14481471
#endif
14491472
model_->createStatus();
1473+
if(!saveModelX) {
14501474
/* addAll
14511475
0 - chosen,all used, all
14521476
1 - chosen, all
@@ -1726,7 +1750,7 @@ void Idiot::crossOver(int mode)
17261750
} else {
17271751
maxmin = 1.0;
17281752
}
1729-
bool justValuesPass = majorIterations_ > 1000000;
1753+
justValuesPass = majorIterations_ > 1000000;
17301754
if (slackStart >= 0) {
17311755
for (i = 0; i < nrows; i++) {
17321756
model_->setRowStatus(i, ClpSimplex::superBasic);
@@ -1814,7 +1838,6 @@ void Idiot::crossOver(int mode)
18141838
}
18151839
/*printf("%d in basis\n",ninbas);*/
18161840
}
1817-
bool wantVector = false;
18181841
if (dynamic_cast< ClpPackedMatrix * >(model_->clpMatrix())) {
18191842
// See if original wanted vector
18201843
ClpPackedMatrix *clpMatrixO = dynamic_cast< ClpPackedMatrix * >(model_->clpMatrix());
@@ -1825,6 +1848,85 @@ void Idiot::crossOver(int mode)
18251848
if ((strategy_ & 65536) != 0)
18261849
justValuesPass = true;
18271850
//double * saveBounds=NULL;
1851+
} else {
1852+
addAll = 3;
1853+
memcpy(model_->columnLower(),saveModelX->columnLower(),ncols*sizeof(double));
1854+
memcpy(model_->columnUpper(),saveModelX->columnUpper(),ncols*sizeof(double));
1855+
memcpy(model_->rowLower(),saveModelX->rowLower(),nrows*sizeof(double));
1856+
memcpy(model_->rowUpper(),saveModelX->rowUpper(),nrows*sizeof(double));
1857+
delete saveModelX;
1858+
if (strategy_&4194304) {
1859+
int nAway = 0;
1860+
double *away = new double[ncols+nrows];
1861+
int *choose = new int[ncols+nrows];
1862+
for (int i=0;i<ncols;i++) {
1863+
if (colsol[i] < lower[i] + fixTolerance) {
1864+
colsol[i] = lower[i];
1865+
model_->setColumnStatus(i,ClpSimplex::atLowerBound);
1866+
} else if (colsol[i] > upper[i] - fixTolerance) {
1867+
colsol[i] = upper[i];
1868+
model_->setColumnStatus(i,ClpSimplex::atUpperBound);
1869+
} else if (lower[i]<-1.0e50 && upper[i]>1.0e50) {
1870+
model_->setColumnStatus(i,ClpSimplex::isFree);
1871+
away[i] = -1.0e50;
1872+
choose[nAway++] = i;
1873+
} else {
1874+
away[i] = -std::min(upper[i]-colsol[i],colsol[i]-lower[i]);
1875+
model_->setColumnStatus(i, ClpSimplex::superBasic);
1876+
choose[nAway++] = i;
1877+
}
1878+
}
1879+
for (int i=0;i<nrows;i++) {
1880+
if (rowsol[i] < lower[i] + fixTolerance) {
1881+
rowsol[i] = lower[i];
1882+
model_->setRowStatus(i,ClpSimplex::atLowerBound);
1883+
} else if (rowsol[i] > upper[i] - fixTolerance) {
1884+
rowsol[i] = upper[i];
1885+
model_->setRowStatus(i,ClpSimplex::atUpperBound);
1886+
} else if (lower[i]<-1.0e50 && upper[i]>1.0e50) {
1887+
model_->setRowStatus(i,ClpSimplex::isFree);
1888+
away[i] = -1.0e50;
1889+
choose[nAway++] = i+ncols;
1890+
} else {
1891+
away[i] = -std::min(upper[i]-rowsol[i],rowsol[i]-lower[i]);
1892+
model_->setRowStatus(i, ClpSimplex::superBasic);
1893+
choose[nAway++] = i+ncols;
1894+
}
1895+
}
1896+
CoinSort_2(away, away + nAway, choose);
1897+
//nAway = std::min(nAway,(3*nrows/4));
1898+
nAway = std::min(nAway,nrows);
1899+
for (int i=0;i<nAway;i++)
1900+
model_->setColumnStatus(choose[i],ClpSimplex::basic);
1901+
delete [] away;
1902+
delete [] choose;
1903+
} else {
1904+
for (int i=0;i<ncols;i++) {
1905+
if (colsol[i] < lower[i] + fixTolerance) {
1906+
colsol[i] = lower[i];
1907+
model_->setColumnStatus(i,ClpSimplex::atLowerBound);
1908+
} else if (colsol[i] > upper[i] - fixTolerance) {
1909+
colsol[i] = upper[i];
1910+
model_->setColumnStatus(i,ClpSimplex::atUpperBound);
1911+
} else if (lower[i]<-1.0e50 && upper[i]>1.0e50) {
1912+
model_->setColumnStatus(i,ClpSimplex::isFree);
1913+
} else {
1914+
model_->setColumnStatus(i, ClpSimplex::superBasic);
1915+
}
1916+
}
1917+
for (int i=0;i<nrows;i++) {
1918+
model_->setRowStatus(i,ClpSimplex::basic);
1919+
}
1920+
}
1921+
bool justValuesPass = false;
1922+
bool wantVector =true;
1923+
matrix = model_->clpMatrix();
1924+
ClpPackedMatrix *clpMatrix = dynamic_cast< ClpPackedMatrix * >(matrix);
1925+
assert(clpMatrix);
1926+
clpMatrix->makeSpecialColumnCopy();
1927+
model_->primal(1);
1928+
clpMatrix->releaseSpecialColumnCopy();
1929+
}
18281930
if (addAll < 3) {
18291931
ClpPresolve pinfo;
18301932
if (presolve) {
@@ -1965,6 +2067,16 @@ void Idiot::crossOver(int mode)
19652067
saveModel = model_;
19662068
pinfo.setPresolveActions(pinfo.presolveActions() | 16384);
19672069
model_ = pinfo.presolvedModel(*model_, 1.0e-8, false, 5);
2070+
if ((strategy_&4194304)!=0) {
2071+
if (!model_||model_->numberRows()>0.8*saveModel->numberRows()) {
2072+
// do not presolve
2073+
presolve=0;
2074+
delete model_;
2075+
model_=saveModel;
2076+
delete [] saveBounds;
2077+
saveBounds = NULL;
2078+
}
2079+
}
19682080
if (saveBounds) {
19692081
memcpy(saveModel->columnLower(), saveBounds, ncols * sizeof(double));
19702082
memcpy(saveModel->columnUpper(), saveBounds + ncols, ncols * sizeof(double));
@@ -2049,11 +2161,13 @@ void Idiot::crossOver(int mode)
20492161
delete[] which;
20502162
}
20512163
}
2164+
if ((strategy_&(2097152|4194304))==0) {
20522165
// Maybe presolve did nothing!
20532166
if (pinfo.nullPresolve()) {
20542167
delete model_;
20552168
model_ = NULL;
20562169
}
2170+
}
20572171
if (model_) {
20582172
// See if we want to go all way
20592173
int oldSize = 2 * saveModel->numberRows() + saveModel->numberColumns();
@@ -2160,6 +2274,14 @@ void Idiot::crossOver(int mode)
21602274
if (presolve) {
21612275
saveModel = model_;
21622276
model_ = pinfo.presolvedModel(*model_, 1.0e-8, false, 5);
2277+
if ((strategy_&(2097152|4194304))!=0) {
2278+
if (!model_||(strategy_&2097152)==0||model_->numberRows()>0.8*saveModel->numberRows()) {
2279+
// do not presolve
2280+
presolve=0;
2281+
delete model_;
2282+
model_=saveModel;
2283+
}
2284+
}
21632285
} else {
21642286
presolve = 0;
21652287
}
@@ -2212,6 +2334,14 @@ void Idiot::crossOver(int mode)
22122334
if (presolve) {
22132335
saveModel = model_;
22142336
model_ = pinfo.presolvedModel(*model_, 1.0e-8, false, 5);
2337+
if ((strategy_&(2097152|4194304))!=0) {
2338+
if (!model_||(strategy_&2097152)==0||model_->numberRows()>0.8*saveModel->numberRows()) {
2339+
// do not presolve
2340+
presolve=0;
2341+
delete model_;
2342+
model_=saveModel;
2343+
}
2344+
}
22152345
} else {
22162346
presolve = 0;
22172347
}
@@ -2417,5 +2547,3 @@ Idiot::~Idiot()
24172547
delete[] whenUsed_;
24182548
}
24192549

2420-
/* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
2421-
*/

0 commit comments

Comments
 (0)