1 | // Copyright (C) 2007, International Business Machines |
---|
2 | // Corporation and others. All Rights Reserved. |
---|
3 | Â Â |
---|
4 | #include "CbcConfig.h" |
---|
5 | #include "CoinPragma.hpp" |
---|
6 | |
---|
7 | #include <cassert> |
---|
8 | #include <cstdio> |
---|
9 | #include <cmath> |
---|
10 | #include <cfloat> |
---|
11 | #include <cstring> |
---|
12 | #include <iostream> |
---|
13 | |
---|
14 | #include "CoinPragma.hpp" |
---|
15 | #include "CoinHelperFunctions.hpp" |
---|
16 | // Version |
---|
17 | #define CBCVERSION "2.00.00" |
---|
18 | |
---|
19 | #include "CoinMpsIO.hpp" |
---|
20 | #include "CoinModel.hpp" |
---|
21 | |
---|
22 | #include "ClpFactorization.hpp" |
---|
23 | #include "ClpQuadraticObjective.hpp" |
---|
24 | #include "CoinTime.hpp" |
---|
25 | #include "ClpSimplex.hpp" |
---|
26 | #include "ClpSimplexOther.hpp" |
---|
27 | #include "ClpSolve.hpp" |
---|
28 | #include "ClpMessage.hpp" |
---|
29 | #include "ClpPackedMatrix.hpp" |
---|
30 | #include "ClpPlusMinusOneMatrix.hpp" |
---|
31 | #include "ClpNetworkMatrix.hpp" |
---|
32 | #include "ClpDualRowSteepest.hpp" |
---|
33 | #include "ClpDualRowDantzig.hpp" |
---|
34 | #include "ClpLinearObjective.hpp" |
---|
35 | #include "ClpPrimalColumnSteepest.hpp" |
---|
36 | #include "ClpPrimalColumnDantzig.hpp" |
---|
37 | #include "ClpPresolve.hpp" |
---|
38 | #include "CbcOrClpParam.hpp" |
---|
39 | #include "OsiRowCutDebugger.hpp" |
---|
40 | #include "OsiChooseVariable.hpp" |
---|
41 | #include "OsiAuxInfo.hpp" |
---|
42 | //#define USER_HAS_FAKE_CLP |
---|
43 | //#define USER_HAS_FAKE_CBC |
---|
44 | //#define CLP_MALLOC_STATISTICS |
---|
45 | #ifdef CLP_MALLOC_STATISTICS |
---|
46 | #include <malloc.h> |
---|
47 | #include <exception> |
---|
48 | #include <new> |
---|
49 | static double malloc_times=0.0; |
---|
50 | static double malloc_total=0.0; |
---|
51 | static int malloc_amount[]={0,32,128,256,1024,4096,16384,65536,262144,INT_MAX}; |
---|
52 | static int malloc_n=10; |
---|
53 | double malloc_counts[10]={0,0,0,0,0,0,0,0,0,0}; |
---|
54 | void * operator new (size_t size) throw (std::bad_alloc) |
---|
55 | { |
---|
56 | Â malloc_times ++; |
---|
57 | Â malloc_total +=Â size; |
---|
58 |  int i; |
---|
59 |  for (i=0;i<malloc_n;i++) { |
---|
60 |   if ((int) size<=malloc_amount[i]) { |
---|
61 | Â Â Â malloc_counts[i]++; |
---|
62 | Â Â Â break; |
---|
63 | Â Â } |
---|
64 | Â } |
---|
65 |  void * p =malloc(size); |
---|
66 | Â //char * xx = (char *) p; |
---|
67 | Â //memset(xx,0,size); |
---|
68 | Â // Initialize random seed |
---|
69 | Â //CoinSeedRandom(987654321); |
---|
70 |  return p; |
---|
71 | } |
---|
72 | void operator delete (void *p) throw() |
---|
73 | { |
---|
74 | Â free(p); |
---|
75 | } |
---|
76 | static void malloc_stats2() |
---|
77 | { |
---|
78 |  double average = malloc_total/malloc_times; |
---|
79 | Â printf("count %g bytes %g - average %g\n",malloc_times,malloc_total,average); |
---|
80 |  for (int i=0;i<malloc_n;i++) |
---|
81 | Â Â printf("%g ",malloc_counts[i]); |
---|
82 | Â printf("\n"); |
---|
83 | Â malloc_times=0.0; |
---|
84 | Â malloc_total=0.0; |
---|
85 | Â memset(malloc_counts,0,sizeof(malloc_counts)); |
---|
86 | } |
---|
87 | #endif |
---|
88 | //#define DMALLOC |
---|
89 | #ifdef DMALLOC |
---|
90 | #include "dmalloc.h" |
---|
91 | #endif |
---|
92 | #ifdef WSSMP_BARRIER |
---|
93 | #define FOREIGN_BARRIER |
---|
94 | #endif |
---|
95 | #ifdef UFL_BARRIER |
---|
96 | #define FOREIGN_BARRIER |
---|
97 | #endif |
---|
98 | #ifdef TAUCS_BARRIER |
---|
99 | #define FOREIGN_BARRIER |
---|
100 | #endif |
---|
101 | #include "CoinWarmStartBasis.hpp" |
---|
102 | |
---|
103 | #include "OsiSolverInterface.hpp" |
---|
104 | #include "OsiCuts.hpp" |
---|
105 | #include "OsiRowCut.hpp" |
---|
106 | #include "OsiColCut.hpp" |
---|
107 | #ifndef COIN_HAS_LINK |
---|
108 | #define COIN_HAS_LINK |
---|
109 | #endif |
---|
110 | #ifdef COIN_HAS_LINK |
---|
111 | #include "CbcLinked.hpp" |
---|
112 | #endif |
---|
113 | #include "CglPreProcess.hpp" |
---|
114 | #include "CglCutGenerator.hpp" |
---|
115 | #include "CglGomory.hpp" |
---|
116 | #include "CglProbing.hpp" |
---|
117 | #include "CglKnapsackCover.hpp" |
---|
118 | #include "CglRedSplit.hpp" |
---|
119 | #include "CglClique.hpp" |
---|
120 | #include "CglFlowCover.hpp" |
---|
121 | #include "CglMixedIntegerRounding2.hpp" |
---|
122 | #include "CglTwomir.hpp" |
---|
123 | #include "CglDuplicateRow.hpp" |
---|
124 | #include "CglStored.hpp" |
---|
125 | #include "CglLandP.hpp" |
---|
126 | #include "CglResidualCapacity.hpp" |
---|
127 | |
---|
128 | #include "CbcModel.hpp" |
---|
129 | #include "CbcHeuristic.hpp" |
---|
130 | #include "CbcHeuristicLocal.hpp" |
---|
131 | #include "CbcHeuristicGreedy.hpp" |
---|
132 | #include "CbcHeuristicFPump.hpp" |
---|
133 | #include "CbcHeuristicRINS.hpp" |
---|
134 | #include "CbcTreeLocal.hpp" |
---|
135 | #include "CbcCompareActual.hpp" |
---|
136 | #include "CbcBranchActual.hpp" |
---|
137 | #include "CbcBranchLotsize.hpp" |
---|
138 | #include "CbcOrClpParam.hpp" |
---|
139 | #include "CbcCutGenerator.hpp" |
---|
140 | #include "CbcStrategy.hpp" |
---|
141 | #include "CbcBranchLotsize.hpp" |
---|
142 | |
---|
143 | #include "OsiClpSolverInterface.hpp" |
---|
144 | #include "CbcSolver.hpp" |
---|
145 | CbcSolver::CbcSolver() |
---|
146 | Â :Â babModel_(NULL), |
---|
147 | Â Â userFunction_(NULL), |
---|
148 | Â Â statusUserFunction_(NULL), |
---|
149 | Â Â originalSolver_(NULL), |
---|
150 | Â Â originalCoinModel_(NULL), |
---|
151 | Â Â cutGenerator_(NULL), |
---|
152 | Â Â numberUserFunctions_(0), |
---|
153 | Â Â numberCutGenerators_(0), |
---|
154 | Â Â startTime_(CoinCpuTime()), |
---|
155 | Â Â parameters_(NULL), |
---|
156 | Â Â numberParameters_(0), |
---|
157 | Â Â doMiplib_(false), |
---|
158 | Â Â noPrinting_(false), |
---|
159 | Â Â readMode_(1) |
---|
160 | { |
---|
161 |  callBack_ = new CbcStopNow(); |
---|
162 | Â fillParameters(); |
---|
163 | } |
---|
164 | CbcSolver::CbcSolver(const OsiClpSolverInterface & solver) |
---|
165 | Â :Â babModel_(NULL), |
---|
166 | Â Â userFunction_(NULL), |
---|
167 | Â Â statusUserFunction_(NULL), |
---|
168 | Â Â originalSolver_(NULL), |
---|
169 | Â Â originalCoinModel_(NULL), |
---|
170 | Â Â cutGenerator_(NULL), |
---|
171 | Â Â numberUserFunctions_(0), |
---|
172 | Â Â numberCutGenerators_(0), |
---|
173 | Â Â startTime_(CoinCpuTime()), |
---|
174 | Â Â parameters_(NULL), |
---|
175 | Â Â numberParameters_(0), |
---|
176 | Â Â doMiplib_(false), |
---|
177 | Â Â noPrinting_(false), |
---|
178 | Â Â readMode_(1) |
---|
179 | { |
---|
180 |  callBack_ = new CbcStopNow(); |
---|
181 | Â model_ =Â CbcModel(solver); |
---|
182 | Â fillParameters(); |
---|
183 | } |
---|
184 | CbcSolver::CbcSolver(const CbcModel & solver) |
---|
185 | Â :Â babModel_(NULL), |
---|
186 | Â Â userFunction_(NULL), |
---|
187 | Â Â statusUserFunction_(NULL), |
---|
188 | Â Â originalSolver_(NULL), |
---|
189 | Â Â originalCoinModel_(NULL), |
---|
190 | Â Â cutGenerator_(NULL), |
---|
191 | Â Â numberUserFunctions_(0), |
---|
192 | Â Â numberCutGenerators_(0), |
---|
193 | Â Â startTime_(CoinCpuTime()), |
---|
194 | Â Â parameters_(NULL), |
---|
195 | Â Â numberParameters_(0), |
---|
196 | Â Â doMiplib_(false), |
---|
197 | Â Â noPrinting_(false), |
---|
198 | Â Â readMode_(1) |
---|
199 | { |
---|
200 |  callBack_ = new CbcStopNow(); |
---|
201 | Â model_ =Â solver; |
---|
202 | Â fillParameters(); |
---|
203 | } |
---|
204 | CbcSolver::~CbcSolver() |
---|
205 | { |
---|
206 |  int i; |
---|
207 |  for (i=0;i<numberUserFunctions_;i++) |
---|
208 |   delete userFunction_[i]; |
---|
209 |  delete [] userFunction_; |
---|
210 |  for (i=0;i<numberCutGenerators_;i++) |
---|
211 |   delete cutGenerator_[i]; |
---|
212 |  delete [] cutGenerator_; |
---|
213 |  delete [] statusUserFunction_; |
---|
214 |  delete originalSolver_; |
---|
215 |  delete originalCoinModel_; |
---|
216 |  delete babModel_; |
---|
217 |  delete [] parameters_; |
---|
218 |  delete callBack_; |
---|
219 | } |
---|
220 | // Copy constructor |
---|
221 | CbcSolver::CbcSolver ( const CbcSolver & rhs) |
---|
222 | Â :Â model_(rhs.model_), |
---|
223 | Â Â babModel_(NULL), |
---|
224 | Â Â userFunction_(NULL), |
---|
225 | Â Â statusUserFunction_(NULL), |
---|
226 | Â Â numberUserFunctions_(rhs.numberUserFunctions_), |
---|
227 | Â Â startTime_(CoinCpuTime()), |
---|
228 | Â Â parameters_(NULL), |
---|
229 | Â Â numberParameters_(rhs.numberParameters_), |
---|
230 | Â Â doMiplib_(rhs.doMiplib_), |
---|
231 | Â Â noPrinting_(rhs.noPrinting_), |
---|
232 | Â Â readMode_(rhs.readMode_) |
---|
233 | { |
---|
234 | Â fillParameters(); |
---|
235 |  if (rhs.babModel_) |
---|
236 |   babModel_ = new CbcModel(*rhs.babModel_); |
---|
237 |  userFunction_ = new CbcUser * [numberUserFunctions_]; |
---|
238 |  int i; |
---|
239 |  for (i=0;i<numberUserFunctions_;i++) |
---|
240 | Â Â userFunction_[i]Â =Â rhs.userFunction_[i]->clone(); |
---|
241 |  for (i=0;i<numberParameters_;i++) |
---|
242 | Â Â parameters_[i]=rhs.parameters_[i]; |
---|
243 |  for (i=0;i<numberCutGenerators_;i++) |
---|
244 | Â Â cutGenerator_[i]Â =Â rhs.cutGenerator_[i]->clone(); |
---|
245 | Â callBack_ =Â rhs.callBack_->clone(); |
---|
246 | Â originalSolver_ =Â NULL; |
---|
247 |  if (rhs.originalSolver_) { |
---|
248 | Â Â OsiSolverInterface *Â temp =Â rhs.originalSolver_->clone(); |
---|
249 | Â Â originalSolver_ =Â dynamic_cast<OsiClpSolverInterface *>Â (temp); |
---|
250 | Â Â assert (originalSolver_); |
---|
251 | Â } |
---|
252 | Â originalCoinModel_ =Â NULL; |
---|
253 |  if (rhs.originalCoinModel_) |
---|
254 |   originalCoinModel_ = new CoinModel(*rhs.originalCoinModel_); |
---|
255 | } |
---|
256 | // Assignment operator |
---|
257 | CbcSolver & |
---|
258 | CbcSolver::operator=(const CbcSolver & rhs) |
---|
259 | { |
---|
260 |  if (this != &rhs) { |
---|
261 |   int i; |
---|
262 |   for (i=0;i<numberUserFunctions_;i++) |
---|
263 |    delete userFunction_[i]; |
---|
264 |   delete [] userFunction_; |
---|
265 |   for (i=0;i<numberCutGenerators_;i++) |
---|
266 |    delete cutGenerator_[i]; |
---|
267 |   delete [] cutGenerator_; |
---|
268 |   delete [] statusUserFunction_; |
---|
269 |   delete originalSolver_; |
---|
270 |   delete originalCoinModel_; |
---|
271 | Â Â statusUserFunction_ =Â NULL; |
---|
272 |   delete babModel_; |
---|
273 |   delete [] parameters_; |
---|
274 |   delete callBack_; |
---|
275 | Â Â numberUserFunctions_ =Â rhs.numberUserFunctions_; |
---|
276 | Â Â startTime_ =Â rhs.startTime_; |
---|
277 | Â Â numberParameters_=Â rhs.numberParameters_; |
---|
278 |   for (i=0;i<numberParameters_;i++) |
---|
279 | Â Â Â parameters_[i]=rhs.parameters_[i]; |
---|
280 |   for (i=0;i<numberCutGenerators_;i++) |
---|
281 | Â Â Â cutGenerator_[i]Â =Â rhs.cutGenerator_[i]->clone(); |
---|
282 | Â Â noPrinting_ =Â rhs.noPrinting_; |
---|
283 | Â Â readMode_ =Â rhs.readMode_; |
---|
284 | Â Â doMiplib_ =Â rhs.doMiplib_; |
---|
285 | Â Â model_ =Â rhs.model_; |
---|
286 |   if (rhs.babModel_) |
---|
287 |    babModel_ = new CbcModel(*rhs.babModel_); |
---|
288 | Â Â else |
---|
289 | Â Â Â babModel_ =Â NULL; |
---|
290 |   userFunction_ = new CbcUser * [numberUserFunctions_]; |
---|
291 |   for (i=0;i<numberUserFunctions_;i++) |
---|
292 | Â Â Â userFunction_[i]Â =Â rhs.userFunction_[i]->clone(); |
---|
293 | Â Â callBack_ =Â rhs.callBack_->clone(); |
---|
294 | Â Â originalSolver_ =Â NULL; |
---|
295 |   if (rhs.originalSolver_) { |
---|
296 | Â Â Â OsiSolverInterface *Â temp =Â rhs.originalSolver_->clone(); |
---|
297 | Â Â Â originalSolver_ =Â dynamic_cast<OsiClpSolverInterface *>Â (temp); |
---|
298 | Â Â assert (originalSolver_); |
---|
299 | Â Â } |
---|
300 | Â Â originalCoinModel_ =Â NULL; |
---|
301 |   if (rhs.originalCoinModel_) |
---|
302 |    originalCoinModel_ = new CoinModel(*rhs.originalCoinModel_); |
---|
303 | } |
---|
304 |  return *this; |
---|
305 | } |
---|
306 | // Get int value |
---|
307 | int CbcSolver::intValue(CbcOrClpParameterType type) const |
---|
308 | { |
---|
309 |  return parameters_[whichParam(type,numberParameters_,parameters_)].intValue(); |
---|
310 | } |
---|
311 | // Set int value |
---|
312 | void CbcSolver::setIntValue(CbcOrClpParameterType type,int value) |
---|
313 | { |
---|
314 | Â parameters_[whichParam(type,numberParameters_,parameters_)].setIntValue(value); |
---|
315 | } |
---|
316 | // Get double value |
---|
317 | double CbcSolver::doubleValue(CbcOrClpParameterType type) const |
---|
318 | { |
---|
319 |  return parameters_[whichParam(type,numberParameters_,parameters_)].doubleValue(); |
---|
320 | } |
---|
321 | // Set double value |
---|
322 | void CbcSolver::setDoubleValue(CbcOrClpParameterType type,double value) |
---|
323 | { |
---|
324 | Â parameters_[whichParam(type,numberParameters_,parameters_)].setDoubleValue(value); |
---|
325 | } |
---|
326 | // User function (NULL if no match) |
---|
327 | CbcUser * CbcSolver::userFunction(const char * name) const |
---|
328 | { |
---|
329 |  int i; |
---|
330 |  for (i=0;i<numberUserFunctions_;i++) { |
---|
331 |   if (!strcmp(name,userFunction_[i]->name().c_str())) |
---|
332 | Â Â Â break; |
---|
333 | Â } |
---|
334 |  if (i<numberUserFunctions_) |
---|
335 |   return userFunction_[i]; |
---|
336 | Â else |
---|
337 |   return NULL; |
---|
338 | } |
---|
339 | void CbcSolver::fillParameters() |
---|
340 | { |
---|
341 |  int maxParam = 200; |
---|
342 |  CbcOrClpParam * parameters = new CbcOrClpParam [maxParam]; |
---|
343 | Â numberParameters_=0Â ; |
---|
344 | Â establishParams(numberParameters_,parameters)Â ; |
---|
345 | Â assert (numberParameters_<=maxParam); |
---|
346 |  parameters_ = new CbcOrClpParam [numberParameters_]; |
---|
347 |  int i; |
---|
348 |  for (i=0;i<numberParameters_;i++) |
---|
349 | Â Â parameters_[i]=parameters[i]; |
---|
350 |  delete [] parameters; |
---|
351 |  const char dirsep = CoinFindDirSeparator(); |
---|
352 | Â std::string directory; |
---|
353 | Â std::string dirSample; |
---|
354 | Â std::string dirNetlib; |
---|
355 | Â std::string dirMiplib; |
---|
356 |  if (dirsep == '/') { |
---|
357 | Â Â directory =Â "./"; |
---|
358 | Â Â dirSample =Â "../../Data/Sample/"; |
---|
359 | Â Â dirNetlib =Â "../../Data/Netlib/"; |
---|
360 | Â Â dirMiplib =Â "../../Data/miplib3/"; |
---|
361 |  } else { |
---|
362 | Â Â directory =Â ".\\"; |
---|
363 | Â Â dirSample =Â "..\\..\\Data\\Sample\\"; |
---|
364 | Â Â dirNetlib =Â "..\\..\\Data\\Netlib\\"; |
---|
365 | Â Â dirMiplib =Â "..\\..\\Data\\miplib3\\"; |
---|
366 | Â } |
---|
367 | Â std::string defaultDirectory =Â directory; |
---|
368 | Â std::string importFile =""; |
---|
369 | Â std::string exportFile ="default.mps"; |
---|
370 | Â std::string importBasisFile =""; |
---|
371 | Â std::string importPriorityFile =""; |
---|
372 | Â std::string debugFile=""; |
---|
373 | Â std::string printMask=""; |
---|
374 | Â std::string exportBasisFile ="default.bas"; |
---|
375 | Â std::string saveFile ="default.prob"; |
---|
376 | Â std::string restoreFile ="default.prob"; |
---|
377 | Â std::string solutionFile ="stdout"; |
---|
378 | Â std::string solutionSaveFile ="solution.file"; |
---|
379 |  int doIdiot=-1; |
---|
380 |  int outputFormat=2; |
---|
381 |  int substitution=3; |
---|
382 |  int dualize=3; |
---|
383 |  int preSolve=5; |
---|
384 |  int doSprint=-1; |
---|
385 |  int testOsiParameters=-1; |
---|
386 |  int createSolver=0; |
---|
387 | Â ClpSimplex *Â lpSolver; |
---|
388 | Â OsiClpSolverInterface *Â clpSolver; |
---|
389 |  if (model_.solver()) { |
---|
390 | Â Â clpSolver =Â dynamic_cast<OsiClpSolverInterface *>Â (model_.solver()); |
---|
391 | Â Â assert (clpSolver); |
---|
392 | Â Â lpSolver =Â clpSolver->getModelPtr(); |
---|
393 | Â Â assert (lpSolver); |
---|
394 |  } else { |
---|
395 |   lpSolver = new ClpSimplex(); |
---|
396 |   clpSolver = new OsiClpSolverInterface(lpSolver,true); |
---|
397 | Â Â createSolver =1Â ; |
---|
398 | Â } |
---|
399 | Â parameters_[whichParam(BASISIN,numberParameters_,parameters_)].setStringValue(importBasisFile); |
---|
400 | Â parameters_[whichParam(PRIORITYIN,numberParameters_,parameters_)].setStringValue(importPriorityFile); |
---|
401 | Â parameters_[whichParam(BASISOUT,numberParameters_,parameters_)].setStringValue(exportBasisFile); |
---|
402 | Â parameters_[whichParam(DEBUG,numberParameters_,parameters_)].setStringValue(debugFile); |
---|
403 | Â parameters_[whichParam(PRINTMASK,numberParameters_,parameters_)].setStringValue(printMask); |
---|
404 | Â parameters_[whichParam(DIRECTORY,numberParameters_,parameters_)].setStringValue(directory); |
---|
405 | Â parameters_[whichParam(DIRSAMPLE,numberParameters_,parameters_)].setStringValue(dirSample); |
---|
406 | Â parameters_[whichParam(DIRNETLIB,numberParameters_,parameters_)].setStringValue(dirNetlib); |
---|
407 | Â parameters_[whichParam(DIRMIPLIB,numberParameters_,parameters_)].setStringValue(dirMiplib); |
---|
408 | Â parameters_[whichParam(DUALBOUND,numberParameters_,parameters_)].setDoubleValue(lpSolver->dualBound()); |
---|
409 | Â parameters_[whichParam(DUALTOLERANCE,numberParameters_,parameters_)].setDoubleValue(lpSolver->dualTolerance()); |
---|
410 | Â parameters_[whichParam(EXPORT,numberParameters_,parameters_)].setStringValue(exportFile); |
---|
411 | Â parameters_[whichParam(IDIOT,numberParameters_,parameters_)].setIntValue(doIdiot); |
---|
412 | Â parameters_[whichParam(IMPORT,numberParameters_,parameters_)].setStringValue(importFile); |
---|
413 | Â parameters_[whichParam(PRESOLVETOLERANCE,numberParameters_,parameters_)].setDoubleValue(1.0e-8); |
---|
414 |  int iParam = whichParam(SOLVERLOGLEVEL,numberParameters_,parameters_); |
---|
415 |  int value=1; |
---|
416 | Â clpSolver->messageHandler()->setLogLevel(1)Â ; |
---|
417 | Â lpSolver->setLogLevel(1); |
---|
418 | Â parameters_[iParam].setIntValue(value); |
---|
419 | Â iParam =Â whichParam(LOGLEVEL,numberParameters_,parameters_); |
---|
420 | Â model_.messageHandler()->setLogLevel(value); |
---|
421 | Â parameters_[iParam].setIntValue(value); |
---|
422 | Â parameters_[whichParam(MAXFACTOR,numberParameters_,parameters_)].setIntValue(lpSolver->factorizationFrequency()); |
---|
423 | Â parameters_[whichParam(MAXITERATION,numberParameters_,parameters_)].setIntValue(lpSolver->maximumIterations()); |
---|
424 | Â parameters_[whichParam(OUTPUTFORMAT,numberParameters_,parameters_)].setIntValue(outputFormat); |
---|
425 | Â parameters_[whichParam(PRESOLVEPASS,numberParameters_,parameters_)].setIntValue(preSolve); |
---|
426 | Â parameters_[whichParam(PERTVALUE,numberParameters_,parameters_)].setIntValue(lpSolver->perturbation()); |
---|
427 | Â parameters_[whichParam(PRIMALTOLERANCE,numberParameters_,parameters_)].setDoubleValue(lpSolver->primalTolerance()); |
---|
428 | Â parameters_[whichParam(PRIMALWEIGHT,numberParameters_,parameters_)].setDoubleValue(lpSolver->infeasibilityCost()); |
---|
429 | Â parameters_[whichParam(RESTORE,numberParameters_,parameters_)].setStringValue(restoreFile); |
---|
430 | Â parameters_[whichParam(SAVE,numberParameters_,parameters_)].setStringValue(saveFile); |
---|
431 | Â //parameters_[whichParam(TIMELIMIT,numberParameters_,parameters_)].setDoubleValue(1.0e8); |
---|
432 | Â parameters_[whichParam(TIMELIMIT_BAB,numberParameters_,parameters_)].setDoubleValue(1.0e8); |
---|
433 | Â parameters_[whichParam(SOLUTION,numberParameters_,parameters_)].setStringValue(solutionFile); |
---|
434 | Â parameters_[whichParam(SAVESOL,numberParameters_,parameters_)].setStringValue(solutionSaveFile); |
---|
435 | Â parameters_[whichParam(SPRINT,numberParameters_,parameters_)].setIntValue(doSprint); |
---|
436 | Â parameters_[whichParam(SUBSTITUTION,numberParameters_,parameters_)].setIntValue(substitution); |
---|
437 | Â parameters_[whichParam(DUALIZE,numberParameters_,parameters_)].setIntValue(dualize); |
---|
438 | Â parameters_[whichParam(NUMBERBEFORE,numberParameters_,parameters_)].setIntValue(model_.numberBeforeTrust()); |
---|
439 | Â parameters_[whichParam(MAXNODES,numberParameters_,parameters_)].setIntValue(model_.getMaximumNodes()); |
---|
440 | Â parameters_[whichParam(STRONGBRANCHING,numberParameters_,parameters_)].setIntValue(model_.numberStrong()); |
---|
441 | Â parameters_[whichParam(INFEASIBILITYWEIGHT,numberParameters_,parameters_)].setDoubleValue(model_.getDblParam(CbcModel::CbcInfeasibilityWeight)); |
---|
442 | Â parameters_[whichParam(INTEGERTOLERANCE,numberParameters_,parameters_)].setDoubleValue(model_.getDblParam(CbcModel::CbcIntegerTolerance)); |
---|
443 | Â parameters_[whichParam(INCREMENT,numberParameters_,parameters_)].setDoubleValue(model_.getDblParam(CbcModel::CbcCutoffIncrement)); |
---|
444 | Â parameters_[whichParam(TESTOSI,numberParameters_,parameters_)].setIntValue(testOsiParameters); |
---|
445 | Â parameters_[whichParam(FPUMPTUNE,numberParameters_,parameters_)].setIntValue(1003); |
---|
446 | #ifdef CBC_THREAD |
---|
447 | Â parameters_[whichParam(THREADS,numberParameters_,parameters_)].setIntValue(0); |
---|
448 | #endif |
---|
449 | Â // Set up likely cut generators and defaults |
---|
450 | Â parameters_[whichParam(PREPROCESS,numberParameters_,parameters_)].setCurrentOption("sos"); |
---|
451 | Â parameters_[whichParam(MIPOPTIONS,numberParameters_,parameters_)].setIntValue(128|64|1); |
---|
452 | Â parameters_[whichParam(MIPOPTIONS,numberParameters_,parameters_)].setIntValue(1); |
---|
453 | Â parameters_[whichParam(CUTPASSINTREE,numberParameters_,parameters_)].setIntValue(1); |
---|
454 | Â parameters_[whichParam(MOREMIPOPTIONS,numberParameters_,parameters_)].setIntValue(-1); |
---|
455 | Â parameters_[whichParam(MAXHOTITS,numberParameters_,parameters_)].setIntValue(100); |
---|
456 | Â parameters_[whichParam(CUTSSTRATEGY,numberParameters_,parameters_)].setCurrentOption("on"); |
---|
457 | Â parameters_[whichParam(HEURISTICSTRATEGY,numberParameters_,parameters_)].setCurrentOption("on"); |
---|
458 | Â parameters_[whichParam(NODESTRATEGY,numberParameters_,parameters_)].setCurrentOption("fewest"); |
---|
459 | Â parameters_[whichParam(GOMORYCUTS,numberParameters_,parameters_)].setCurrentOption("ifmove"); |
---|
460 | Â parameters_[whichParam(PROBINGCUTS,numberParameters_,parameters_)].setCurrentOption("ifmove"); |
---|
461 | Â parameters_[whichParam(KNAPSACKCUTS,numberParameters_,parameters_)].setCurrentOption("ifmove"); |
---|
462 | Â parameters_[whichParam(REDSPLITCUTS,numberParameters_,parameters_)].setCurrentOption("off"); |
---|
463 | Â parameters_[whichParam(CLIQUECUTS,numberParameters_,parameters_)].setCurrentOption("ifmove"); |
---|
464 | Â parameters_[whichParam(MIXEDCUTS,numberParameters_,parameters_)].setCurrentOption("ifmove"); |
---|
465 | Â parameters_[whichParam(FLOWCUTS,numberParameters_,parameters_)].setCurrentOption("ifmove"); |
---|
466 | Â parameters_[whichParam(TWOMIRCUTS,numberParameters_,parameters_)].setCurrentOption("root"); |
---|
467 | Â parameters_[whichParam(LANDPCUTS,numberParameters_,parameters_)].setCurrentOption("off"); |
---|
468 | Â parameters_[whichParam(RESIDCUTS,numberParameters_,parameters_)].setCurrentOption("off"); |
---|
469 | Â parameters_[whichParam(ROUNDING,numberParameters_,parameters_)].setCurrentOption("on"); |
---|
470 | Â parameters_[whichParam(FPUMP,numberParameters_,parameters_)].setCurrentOption("on"); |
---|
471 | Â parameters_[whichParam(GREEDY,numberParameters_,parameters_)].setCurrentOption("on"); |
---|
472 | Â parameters_[whichParam(COMBINE,numberParameters_,parameters_)].setCurrentOption("on"); |
---|
473 | Â parameters_[whichParam(RINS,numberParameters_,parameters_)].setCurrentOption("off"); |
---|
474 | Â parameters_[whichParam(LOCALTREE,numberParameters_,parameters_)].setCurrentOption("off"); |
---|
475 | Â parameters_[whichParam(COSTSTRATEGY,numberParameters_,parameters_)].setCurrentOption("off"); |
---|
476 |  if (createSolver) |
---|
477 |   delete clpSolver; |
---|
478 | } |
---|
479 | void CbcSolver::fillValuesInSolver() |
---|
480 | { |
---|
481 | Â OsiSolverInterface *Â solver =Â model_.solver(); |
---|
482 | Â OsiClpSolverInterface *Â clpSolver =Â dynamic_cast<Â OsiClpSolverInterface*>Â (solver); |
---|
483 | Â assert (clpSolver); |
---|
484 | Â noPrinting_ =Â (clpSolver->getModelPtr()->logLevel()==0); |
---|
485 | Â CoinMessageHandler *Â generalMessageHandler =Â clpSolver->messageHandler(); |
---|
486 | Â generalMessageHandler->setPrefix(true); |
---|
487 | Â ClpSimplex *Â lpSolver =Â clpSolver->getModelPtr(); |
---|
488 | Â lpSolver->setPerturbation(50); |
---|
489 | Â lpSolver->messageHandler()->setPrefix(false); |
---|
490 | Â parameters_[whichParam(DUALBOUND,numberParameters_,parameters_)].setDoubleValue(lpSolver->dualBound()); |
---|
491 | Â parameters_[whichParam(DUALTOLERANCE,numberParameters_,parameters_)].setDoubleValue(lpSolver->dualTolerance()); |
---|
492 |  int iParam = whichParam(SOLVERLOGLEVEL,numberParameters_,parameters_); |
---|
493 |  int value=parameters_[iParam].intValue(); |
---|
494 | Â clpSolver->messageHandler()->setLogLevel(value)Â ; |
---|
495 | Â lpSolver->setLogLevel(value); |
---|
496 | Â iParam =Â whichParam(LOGLEVEL,numberParameters_,parameters_); |
---|
497 | Â value=parameters_[iParam].intValue(); |
---|
498 | Â model_.messageHandler()->setLogLevel(value); |
---|
499 | Â parameters_[whichParam(LOGLEVEL,numberParameters_,parameters_)].setIntValue(model_.logLevel()); |
---|
500 | Â parameters_[whichParam(SOLVERLOGLEVEL,numberParameters_,parameters_)].setIntValue(lpSolver->logLevel()); |
---|
501 | Â parameters_[whichParam(MAXFACTOR,numberParameters_,parameters_)].setIntValue(lpSolver->factorizationFrequency()); |
---|
502 | Â parameters_[whichParam(MAXITERATION,numberParameters_,parameters_)].setIntValue(lpSolver->maximumIterations()); |
---|
503 | Â parameters_[whichParam(PERTVALUE,numberParameters_,parameters_)].setIntValue(lpSolver->perturbation()); |
---|
504 | Â parameters_[whichParam(PRIMALTOLERANCE,numberParameters_,parameters_)].setDoubleValue(lpSolver->primalTolerance()); |
---|
505 | Â parameters_[whichParam(PRIMALWEIGHT,numberParameters_,parameters_)].setDoubleValue(lpSolver->infeasibilityCost()); |
---|
506 | Â parameters_[whichParam(NUMBERBEFORE,numberParameters_,parameters_)].setIntValue(model_.numberBeforeTrust()); |
---|
507 | Â parameters_[whichParam(MAXNODES,numberParameters_,parameters_)].setIntValue(model_.getMaximumNodes()); |
---|
508 | Â parameters_[whichParam(STRONGBRANCHING,numberParameters_,parameters_)].setIntValue(model_.numberStrong()); |
---|
509 | Â parameters_[whichParam(INFEASIBILITYWEIGHT,numberParameters_,parameters_)].setDoubleValue(model_.getDblParam(CbcModel::CbcInfeasibilityWeight)); |
---|
510 | Â parameters_[whichParam(INTEGERTOLERANCE,numberParameters_,parameters_)].setDoubleValue(model_.getDblParam(CbcModel::CbcIntegerTolerance)); |
---|
511 | Â parameters_[whichParam(INCREMENT,numberParameters_,parameters_)].setDoubleValue(model_.getDblParam(CbcModel::CbcCutoffIncrement)); |
---|
512 | } |
---|
513 | // Add user function |
---|
514 | void |
---|
515 | CbcSolver::addUserFunction(CbcUser *Â function) |
---|
516 | { |
---|
517 |  CbcUser ** temp = new CbcUser * [numberUserFunctions_+1]; |
---|
518 |  int i; |
---|
519 |  for (i=0;i<numberUserFunctions_;i++) |
---|
520 | Â Â temp[i]=userFunction_[i]; |
---|
521 |  delete [] userFunction_; |
---|
522 | Â userFunction_ =Â temp; |
---|
523 | Â userFunction_[numberUserFunctions_++]Â =Â function->clone(); |
---|
524 |  delete [] statusUserFunction_; |
---|
525 | Â statusUserFunction_ =Â NULL; |
---|
526 | } |
---|
527 | // Set user call back |
---|
528 | void |
---|
529 | CbcSolver::setUserCallBack(CbcStopNow *Â function) |
---|
530 | { |
---|
531 |  delete callBack_; |
---|
532 | Â callBack_ =Â function->clone(); |
---|
533 | } |
---|
534 | // Copy of model on initial load (will contain output solutions) |
---|
535 | void |
---|
536 | CbcSolver::setOriginalSolver(OsiClpSolverInterface *Â originalSolver) |
---|
537 | { |
---|
538 |  delete originalSolver_; |
---|
539 | Â OsiSolverInterface *Â temp =Â originalSolver->clone(); |
---|
540 | Â originalSolver_ =Â dynamic_cast<OsiClpSolverInterface *>Â (temp); |
---|
541 | Â assert (originalSolver_); |
---|
542 | Â |
---|
543 | } |
---|
544 | // Copy of model on initial load |
---|
545 | void |
---|
546 | CbcSolver::setOriginalCoinModel(CoinModel *Â originalCoinModel) |
---|
547 | { |
---|
548 |  delete originalCoinModel_; |
---|
549 |  originalCoinModel_ = new CoinModel(*originalCoinModel); |
---|
550 | } |
---|
551 | // Add cut generator |
---|
552 | void |
---|
553 | CbcSolver::addCutGenerator(CglCutGenerator *Â generator) |
---|
554 | { |
---|
555 |  CglCutGenerator ** temp = new CglCutGenerator * [numberCutGenerators_+1]; |
---|
556 |  int i; |
---|
557 |  for (i=0;i<numberCutGenerators_;i++) |
---|
558 | Â Â temp[i]=cutGenerator_[i]; |
---|
559 |  delete [] cutGenerator_; |
---|
560 | Â cutGenerator_ =Â temp; |
---|
561 | Â cutGenerator_[numberCutGenerators_++]Â =Â generator->clone(); |
---|
562 | } |
---|
563 | // User stuff (base class) |
---|
564 | CbcUser::CbcUser() |
---|
565 | Â :Â coinModel_(NULL), |
---|
566 | Â Â userName_("null") |
---|
567 | { |
---|
568 | } |
---|
569 | CbcUser::~CbcUser() |
---|
570 | { |
---|
571 |  delete coinModel_; |
---|
572 | } |
---|
573 | // Copy constructor |
---|
574 | CbcUser::CbcUser ( const CbcUser & rhs) |
---|
575 | { |
---|
576 |  if (rhs.coinModel_) |
---|
577 |   coinModel_ = new CoinModel(*rhs.coinModel_); |
---|
578 | Â else |
---|
579 | Â Â coinModel_ =Â NULL; |
---|
580 | Â userName_ =Â rhs.userName_; |
---|
581 | } |
---|
582 | // Assignment operator |
---|
583 | CbcUser & |
---|
584 | CbcUser::operator=(const CbcUser & rhs) |
---|
585 | { |
---|
586 |  if (this != &rhs) { |
---|
587 |   if (rhs.coinModel_) |
---|
588 |    coinModel_ = new CoinModel(*rhs.coinModel_); |
---|
589 | Â Â else |
---|
590 | Â Â Â coinModel_ =Â NULL; |
---|
591 | Â Â userName_ =Â rhs.userName_; |
---|
592 | Â } |
---|
593 |  return *this; |
---|
594 | } |
---|
595 | /* Updates model_ from babModel_ according to returnMode |
---|
596 | Â Â returnMode - |
---|
597 | Â Â 0 model and solver untouched - babModel updated |
---|
598 | Â Â 1 model updated - just with solution basis etc |
---|
599 | Â Â 2 model updated i.e. as babModel (babModel NULL) (only use without preprocessing!) |
---|
600 | */ |
---|
601 | void |
---|
602 | CbcSolver::updateModel(ClpSimplex * model2, int returnMode) |
---|
603 | { |
---|
604 |  if (!returnMode) |
---|
605 | Â Â return; |
---|
606 |  if (returnMode==2&&babModel_) |
---|
607 | Â Â model_ =Â *babModel_; |
---|
608 |  if (model2) { |
---|
609 | Â Â // Only continuous valid |
---|
610 | Â Â // update with basis etc |
---|
611 | Â Â // map states |
---|
612 | Â Â /* clp status |
---|
613 | Â Â Â Â -1 - unknown e.g. before solve or if postSolve says not optimal |
---|
614 | Â Â Â Â 0 - optimal |
---|
615 | Â Â Â Â 1 - primal infeasible |
---|
616 | Â Â Â Â 2 - dual infeasible |
---|
617 | Â Â Â Â 3 - stopped on iterations or time |
---|
618 | Â Â Â Â 4 - stopped due to errors |
---|
619 | Â Â Â Â 5 - stopped by event handler (virtual int ClpEventHandler::event()) */ |
---|
620 | Â Â /* cbc status |
---|
621 | Â Â Â Â -1 before branchAndBound |
---|
622 | Â Â Â Â 0 finished - check isProvenOptimal or isProvenInfeasible to see if solution found |
---|
623 | Â Â Â Â (or check value of best solution) |
---|
624 | Â Â Â Â 1 stopped - on maxnodes, maxsols, maxtime |
---|
625 | Â Â Â Â 2 difficulties so run was abandoned |
---|
626 | Â Â Â Â (5 event user programmed event occurred) */ |
---|
627 | Â Â /* clp secondary status of problem - may get extended |
---|
628 | Â Â Â Â 0 - none |
---|
629 | Â Â Â Â 1 - primal infeasible because dual limit reached OR probably primal |
---|
630 | Â Â Â Â infeasible but can't prove it (main status 4) |
---|
631 | Â Â Â Â 2 - scaled problem optimal - unscaled problem has primal infeasibilities |
---|
632 | Â Â Â Â 3 - scaled problem optimal - unscaled problem has dual infeasibilities |
---|
633 | Â Â Â Â 4 - scaled problem optimal - unscaled problem has primal and dual infeasibilities |
---|
634 | Â Â Â Â 5 - giving up in primal with flagged variables |
---|
635 | Â Â Â Â 6 - failed due to empty problem check |
---|
636 | Â Â Â Â 7 - postSolve says not optimal |
---|
637 | Â Â Â Â 8 - failed due to bad element check |
---|
638 | Â Â Â Â 9 - status was 3 and stopped on time |
---|
639 | Â Â Â Â 100 up - translation of enum from ClpEventHandler |
---|
640 | Â Â */ |
---|
641 | Â Â /* cbc secondary status of problem |
---|
642 | Â Â Â Â -1 unset (status_ will also be -1) |
---|
643 | Â Â Â Â 0 search completed with solution |
---|
644 | Â Â Â Â 1 linear relaxation not feasible (or worse than cutoff) |
---|
645 | Â Â Â Â 2 stopped on gap |
---|
646 | Â Â Â Â 3 stopped on nodes |
---|
647 | Â Â Â Â 4 stopped on time |
---|
648 | Â Â Â Â 5 stopped on user event |
---|
649 | Â Â Â Â 6 stopped on solutions |
---|
650 | Â Â Â Â 7 linear relaxation unbounded |
---|
651 | Â Â */ |
---|
652 |   int iStatus = model2->status(); |
---|
653 |   int iStatus2 = model2->secondaryStatus(); |
---|
654 |   if (iStatus==0) { |
---|
655 | Â Â Â iStatus2=0; |
---|
656 |   } else if (iStatus==1) { |
---|
657 | Â Â Â iStatus=0; |
---|
658 | Â Â Â iStatus2=1;Â // say infeasible |
---|
659 |   } else if (iStatus==2) { |
---|
660 | Â Â Â iStatus=0; |
---|
661 | Â Â Â iStatus2=7;Â // say unbounded |
---|
662 |   } else if (iStatus==3) { |
---|
663 | Â Â Â iStatus=1; |
---|
664 |    if (iStatus2==9) |
---|
665 | Â Â Â Â iStatus2=4; |
---|
666 | Â Â Â else |
---|
667 | Â Â Â Â iStatus2=3;Â // Use nodes - as closer than solutions |
---|
668 |   } else if (iStatus==4) { |
---|
669 | Â Â Â iStatus=2;Â // difficulties |
---|
670 | Â Â Â iStatus2=0;Â |
---|
671 | Â Â } |
---|
672 | Â Â model_.setProblemStatus(iStatus); |
---|
673 | Â Â model_.setSecondaryStatus(iStatus2); |
---|
674 | Â Â OsiClpSolverInterface *Â clpSolver =Â dynamic_cast<Â OsiClpSolverInterface*>Â (model_.solver()); |
---|
675 | Â Â ClpSimplex *Â lpSolver =Â clpSolver->getModelPtr(); |
---|
676 |   if (model2!=lpSolver) { |
---|
677 | Â Â Â lpSolver->moveInfo(*model2); |
---|
678 | Â Â } |
---|
679 | Â Â clpSolver->setWarmStart(NULL);Â // synchronize bases |
---|
680 |   if (originalSolver_) { |
---|
681 | Â Â Â ClpSimplex *Â lpSolver2 =Â originalSolver_->getModelPtr(); |
---|
682 | Â Â Â assert (model2!=lpSolver2); |
---|
683 | Â Â Â lpSolver2->moveInfo(*model2); |
---|
684 | Â Â Â originalSolver_->setWarmStart(NULL);Â // synchronize bases |
---|
685 | Â Â } |
---|
686 |  } else if (returnMode==1) { |
---|
687 | Â Â OsiClpSolverInterface *Â clpSolver =Â dynamic_cast<Â OsiClpSolverInterface*>Â (model_.solver()); |
---|
688 | Â Â ClpSimplex *Â lpSolver =Â clpSolver->getModelPtr(); |
---|
689 |   if (babModel_) { |
---|
690 | Â Â Â model_.moveInfo(*babModel_); |
---|
691 |    int numberColumns = babModel_->getNumCols(); |
---|
692 |    if (babModel_->bestSolution()) |
---|
693 | Â Â Â Â model_.setBestSolution(babModel_->bestSolution(),numberColumns,babModel_->getObjValue()); |
---|
694 | Â Â Â OsiClpSolverInterface *Â clpSolver1 =Â dynamic_cast<Â OsiClpSolverInterface*>Â (babModel_->solver()); |
---|
695 | Â Â Â ClpSimplex *Â lpSolver1 =Â clpSolver1->getModelPtr(); |
---|
696 |    if (lpSolver1!=lpSolver&&model_.bestSolution()) { |
---|
697 | Â Â Â Â lpSolver->moveInfo(*lpSolver1); |
---|
698 | Â Â Â } |
---|
699 | Â Â } |
---|
700 | Â Â clpSolver->setWarmStart(NULL);Â // synchronize bases |
---|
701 | Â } |
---|
702 |  if (returnMode==2) { |
---|
703 |   delete babModel_; |
---|
704 | Â Â babModel_=NULL; |
---|
705 | Â } |
---|
706 | } |
---|
707 | // Stop now stuff (base class) |
---|
708 | CbcStopNow::CbcStopNow() |
---|
709 | { |
---|
710 | } |
---|
711 | CbcStopNow::~CbcStopNow() |
---|
712 | { |
---|
713 | } |
---|
714 | // Copy constructor |
---|
715 | CbcStopNow::CbcStopNow ( const CbcStopNow & rhs) |
---|
716 | { |
---|
717 | } |
---|
718 | // Assignment operator |
---|
719 | CbcStopNow & |
---|
720 | CbcStopNow::operator=(const CbcStopNow & rhs) |
---|
721 | { |
---|
722 |  if (this != &rhs) { |
---|
723 | Â } |
---|
724 |  return *this; |
---|
725 | } |
---|
726 | // Clone |
---|
727 | CbcStopNow * |
---|
728 | CbcStopNow::clone()Â const |
---|
729 | { |
---|
730 |  return new CbcStopNow(*this); |
---|
731 | } |
---|
732 | //#undef NEW_STYLE_SOLVER |
---|
733 | //#define NEW_STYLE_SOLVER |
---|
734 | //#undef COIN_HAS_ASL |
---|
735 | #ifdef COIN_HAS_ASL |
---|
736 | #include "Cbc_ampl.h" |
---|
737 | #endif |
---|
738 | static double totalTime=0.0; |
---|
739 | static void statistics(ClpSimplex * originalModel, ClpSimplex * model); |
---|
740 | static bool maskMatches(const int * starts, char ** masks, |
---|
741 | Â Â Â Â Â Â Â Â Â Â Â Â std::string &Â check); |
---|
742 | static void generateCode(CbcModel * model, const char * fileName,int type,int preProcess); |
---|
743 | //#ifdef NDEBUG |
---|
744 | //#undef NDEBUG |
---|
745 | //#endif |
---|
746 | // define (probably dummy fake main programs for UserClp and UserCbc |
---|
747 | void fakeMain (ClpSimplex & model,OsiSolverInterface & osiSolver, CbcModel & babSolver); |
---|
748 | void fakeMain2 (ClpSimplex & model,OsiClpSolverInterface & osiSolver,int options); |
---|
749 | |
---|
750 | // Allow for interrupts |
---|
751 | // But is this threadsafe ? (so switched off by option) |
---|
752 | |
---|
753 | #include "CoinSignal.hpp" |
---|
754 | static CbcModel * currentBranchModel = NULL; |
---|
755 | |
---|
756 | extern "C" { |
---|
757 |   static void signal_handler(int whichSignal) |
---|
758 | Â Â { |
---|
759 |    if (currentBranchModel!=NULL) { |
---|
760 | Â Â Â Â currentBranchModel->setMaximumNodes(0);Â // stop at next node |
---|
761 | Â Â Â Â currentBranchModel->setMaximumSeconds(0.0);Â // stop |
---|
762 | Â Â Â } |
---|
763 | Â Â Â return; |
---|
764 | Â Â } |
---|
765 | } |
---|
766 | //#define CBC_SIG_TRAP |
---|
767 | #ifdef CBC_SIG_TRAP |
---|
768 | #include <setjmp.h> |
---|
769 | static sigjmp_buf cbc_seg_buffer; |
---|
770 | extern "C" { |
---|
771 |   static void signal_handler_error(int whichSignal) |
---|
772 | Â Â { |
---|
773 | Â Â Â siglongjmp(cbc_seg_buffer,1); |
---|
774 | Â Â } |
---|
775 | } |
---|
776 | #endif |
---|
777 | #if 0 |
---|
778 | /* Updates model_ from babModel_ according to returnMode |
---|
779 | Â Â returnMode - |
---|
780 | Â Â 0 model and solver untouched |
---|
781 | Â Â 1 model updated - just with solution basis etc |
---|
782 | */ |
---|
783 | static void updateModel(CbcModel & model_,int returnMode) |
---|
784 | { |
---|
785 | Â if (!returnMode) |
---|
786 | Â Â return; |
---|
787 | Â assert (returnMode==1); |
---|
788 | } |
---|
789 | #endif |
---|
790 | int CbcOrClpRead_mode=1; |
---|
791 | FILE *Â CbcOrClpReadCommand=stdin; |
---|
792 | static bool noPrinting=false; |
---|
793 | #ifdef NEW_STYLE_SOLVER |
---|
794 | int * CbcSolver::analyze(OsiClpSolverInterface * solverMod, int & numberChanged, double & increment, |
---|
795 |            bool changeInt, CoinMessageHandler * generalMessageHandler) |
---|
796 | #else |
---|
797 | static int * analyze(OsiClpSolverInterface * solverMod, int & numberChanged, double & increment, |
---|
798 |            bool changeInt, CoinMessageHandler * generalMessageHandler) |
---|
799 | #endif |
---|
800 | { |
---|
801 | #ifndef NEW_STYLE_SOLVER |
---|
802 |  bool noPrinting_ = noPrinting; |
---|
803 | #endif |
---|
804 | Â OsiSolverInterface *Â solver =Â solverMod->clone(); |
---|
805 |  char generalPrint[200]; |
---|
806 |  if (0) { |
---|
807 | Â Â // just get increment |
---|
808 | Â Â CbcModel model(*solver); |
---|
809 | Â Â model.analyzeObjective(); |
---|
810 |   double increment2=model.getCutoffIncrement(); |
---|
811 | Â Â printf("initial cutoff increment %g\n",increment2); |
---|
812 | Â } |
---|
813 |  const double *objective = solver->getObjCoefficients() ; |
---|
814 |  const double *lower = solver->getColLower() ; |
---|
815 |  const double *upper = solver->getColUpper() ; |
---|
816 |  int numberColumns = solver->getNumCols() ; |
---|
817 |  int numberRows = solver->getNumRows(); |
---|
818 |  double direction = solver->getObjSense(); |
---|
819 |  int iRow,iColumn; |
---|
820 | |
---|
821 | Â // Row copy |
---|
822 | Â CoinPackedMatrix matrixByRow(*solver->getMatrixByRow()); |
---|
823 |  const double * elementByRow = matrixByRow.getElements(); |
---|
824 |  const int * column = matrixByRow.getIndices(); |
---|
825 |  const CoinBigIndex * rowStart = matrixByRow.getVectorStarts(); |
---|
826 |  const int * rowLength = matrixByRow.getVectorLengths(); |
---|
827 | |
---|
828 | Â // Column copy |
---|
829 |  CoinPackedMatrix matrixByCol(*solver->getMatrixByCol()); |
---|
830 |  const double * element = matrixByCol.getElements(); |
---|
831 |  const int * row = matrixByCol.getIndices(); |
---|
832 |  const CoinBigIndex * columnStart = matrixByCol.getVectorStarts(); |
---|
833 |  const int * columnLength = matrixByCol.getVectorLengths(); |
---|
834 | |
---|
835 |  const double * rowLower = solver->getRowLower(); |
---|
836 |  const double * rowUpper = solver->getRowUpper(); |
---|
837 | |
---|
838 |  char * ignore = new char [numberRows]; |
---|
839 |  int * changed = new int[numberColumns]; |
---|
840 |  int * which = new int[numberRows]; |
---|
841 |  double * changeRhs = new double[numberRows]; |
---|
842 | Â memset(changeRhs,0,numberRows*sizeof(double)); |
---|
843 | Â memset(ignore,0,numberRows); |
---|
844 | Â numberChanged=0; |
---|
845 |  int numberInteger=0; |
---|
846 |  for (iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
847 |   if (upper[iColumn] > lower[iColumn]+1.0e-8&&solver->isInteger(iColumn)) |
---|
848 | Â Â Â numberInteger++; |
---|
849 | Â } |
---|
850 |  bool finished=false; |
---|
851 |  while (!finished) { |
---|
852 |   int saveNumberChanged = numberChanged; |
---|
853 |   for (iRow=0;iRow<numberRows;iRow++) { |
---|
854 |    int numberContinuous=0; |
---|
855 |    double value1=0.0,value2=0.0; |
---|
856 |    bool allIntegerCoeff=true; |
---|
857 |    double sumFixed=0.0; |
---|
858 |    int jColumn1=-1,jColumn2=-1; |
---|
859 |    for (CoinBigIndex j=rowStart[iRow];j<rowStart[iRow]+rowLength[iRow];j++) { |
---|
860 |     int jColumn = column[j]; |
---|
861 |     double value = elementByRow[j]; |
---|
862 |     if (upper[jColumn] > lower[jColumn]+1.0e-8) { |
---|
863 |      if (!solver->isInteger(jColumn)) { |
---|
864 |       if (numberContinuous==0) { |
---|
865 | Â Â Â Â Â Â Â jColumn1=jColumn; |
---|
866 | Â Â Â Â Â Â Â value1=value; |
---|
867 |       } else { |
---|
868 | Â Â Â Â Â Â Â jColumn2=jColumn; |
---|
869 | Â Â Â Â Â Â Â value2=value; |
---|
870 | Â Â Â Â Â Â } |
---|
871 | Â Â Â Â Â Â numberContinuous++; |
---|
872 |      } else { |
---|
873 |       if (fabs(value-floor(value+0.5))>1.0e-12) |
---|
874 | Â Â Â Â Â Â Â allIntegerCoeff=false; |
---|
875 | Â Â Â Â Â } |
---|
876 |     } else { |
---|
877 | Â Â Â Â Â sumFixed +=Â lower[jColumn]*value; |
---|
878 | Â Â Â Â } |
---|
879 | Â Â Â } |
---|
880 |    double low = rowLower[iRow]; |
---|
881 |    if (low>-1.0e20) { |
---|
882 | Â Â Â Â low -=Â sumFixed; |
---|
883 |     if (fabs(low-floor(low+0.5))>1.0e-12) |
---|
884 | Â Â Â Â Â allIntegerCoeff=false; |
---|
885 | Â Â Â } |
---|
886 |    double up = rowUpper[iRow]; |
---|
887 |    if (up<1.0e20) { |
---|
888 | Â Â Â Â up -=Â sumFixed; |
---|
889 |     if (fabs(up-floor(up+0.5))>1.0e-12) |
---|
890 | Â Â Â Â Â allIntegerCoeff=false; |
---|
891 | Â Â Â } |
---|
892 |    if (!allIntegerCoeff) |
---|
893 | Â Â Â Â continue;Â // can't do |
---|
894 |    if (numberContinuous==1) { |
---|
895 | Â Â Â Â // see if really integer |
---|
896 | Â Â Â Â // This does not allow for complicated cases |
---|
897 |     if (low==up) { |
---|
898 |      if (fabs(value1)>1.0e-3) { |
---|
899 | Â Â Â Â Â Â value1 =Â 1.0/value1; |
---|
900 |       if (fabs(value1-floor(value1+0.5))<1.0e-12) { |
---|
901 | Â Â Â Â Â Â Â // integer |
---|
902 | Â Â Â Â Â Â Â changed[numberChanged++]=jColumn1; |
---|
903 | Â Â Â Â Â Â Â solver->setInteger(jColumn1); |
---|
904 |        if (upper[jColumn1]>1.0e20) |
---|
905 | Â Â Â Â Â Â Â Â solver->setColUpper(jColumn1,1.0e20); |
---|
906 |        if (lower[jColumn1]<-1.0e20) |
---|
907 | Â Â Â Â Â Â Â Â solver->setColLower(jColumn1,-1.0e20); |
---|
908 | Â Â Â Â Â Â } |
---|
909 | Â Â Â Â Â } |
---|
910 |     } else { |
---|
911 |      if (fabs(value1)>1.0e-3) { |
---|
912 | Â Â Â Â Â Â value1 =Â 1.0/value1; |
---|
913 |       if (fabs(value1-floor(value1+0.5))<1.0e-12) { |
---|
914 | Â Â Â Â Â Â Â // This constraint will not stop it being integer |
---|
915 | Â Â Â Â Â Â Â ignore[iRow]=1; |
---|
916 | Â Â Â Â Â Â } |
---|
917 | Â Â Â Â Â } |
---|
918 | Â Â Â Â } |
---|
919 |    } else if (numberContinuous==2) { |
---|
920 |     if (low==up) { |
---|
921 | Â Â Â Â Â /* need general theory - for now just look at 2 cases - |
---|
922 | Â Â Â Â Â Â Â 1 - +- 1 one in column and just costs i.e. matching objective |
---|
923 | Â Â Â Â Â Â Â 2 - +- 1 two in column but feeds into G/L row which will try and minimize |
---|
924 | Â Â Â Â Â */ |
---|
925 |      if (fabs(value1)==1.0&&value1*value2==-1.0&&!lower[jColumn1] |
---|
926 | Â Â Â Â Â Â Â &&!lower[jColumn2])Â { |
---|
927 |       int n=0; |
---|
928 |       int i; |
---|
929 |       double objChange=direction*(objective[jColumn1]+objective[jColumn2]); |
---|
930 |       double bound = CoinMin(upper[jColumn1],upper[jColumn2]); |
---|
931 | Â Â Â Â Â Â bound =Â CoinMin(bound,1.0e20); |
---|
932 |       for ( i=columnStart[jColumn1];i<columnStart[jColumn1]+columnLength[jColumn1];i++) { |
---|
933 |        int jRow = row[i]; |
---|
934 |        double value = element[i]; |
---|
935 |        if (jRow!=iRow) { |
---|
936 | Â Â Â Â Â Â Â Â which[n++]=jRow; |
---|
937 | Â Â Â Â Â Â Â Â changeRhs[jRow]=value; |
---|
938 | Â Â Â Â Â Â Â } |
---|
939 | Â Â Â Â Â Â } |
---|
940 |       for ( i=columnStart[jColumn1];i<columnStart[jColumn1]+columnLength[jColumn1];i++) { |
---|
941 |        int jRow = row[i]; |
---|
942 |        double value = element[i]; |
---|
943 |        if (jRow!=iRow) { |
---|
944 |         if (!changeRhs[jRow]) { |
---|
945 | Â Â Â Â Â Â Â Â Â which[n++]=jRow; |
---|
946 | Â Â Â Â Â Â Â Â Â changeRhs[jRow]=value; |
---|
947 |         } else { |
---|
948 | Â Â Â Â Â Â Â Â Â changeRhs[jRow]+=value; |
---|
949 | Â Â Â Â Â Â Â Â } |
---|
950 | Â Â Â Â Â Â Â } |
---|
951 | Â Â Â Â Â Â } |
---|
952 |       if (objChange>=0.0) { |
---|
953 | Â Â Â Â Â Â Â // see if all rows OK |
---|
954 |        bool good=true; |
---|
955 |        for (i=0;i<n;i++) { |
---|
956 |         int jRow = which[i]; |
---|
957 |         double value = changeRhs[jRow]; |
---|
958 |         if (value) { |
---|
959 | Â Â Â Â Â Â Â Â Â value *=Â bound; |
---|
960 |          if (rowLength[jRow]==1) { |
---|
961 |           if (value>0.0) { |
---|
962 |            double rhs = rowLower[jRow]; |
---|
963 |            if (rhs>0.0) { |
---|
964 |             double ratio =rhs/value; |
---|
965 |             if (fabs(ratio-floor(ratio+0.5))>1.0e-12) |
---|
966 | Â Â Â Â Â Â Â Â Â Â Â Â Â good=false; |
---|
967 | Â Â Â Â Â Â Â Â Â Â Â } |
---|
968 |           } else { |
---|
969 |            double rhs = rowUpper[jRow]; |
---|
970 |            if (rhs<0.0) { |
---|
971 |             double ratio =rhs/value; |
---|
972 |             if (fabs(ratio-floor(ratio+0.5))>1.0e-12) |
---|
973 | Â Â Â Â Â Â Â Â Â Â Â Â Â good=false; |
---|
974 | Â Â Â Â Â Â Â Â Â Â Â } |
---|
975 | Â Â Â Â Â Â Â Â Â Â } |
---|
976 |          } else if (rowLength[jRow]==2) { |
---|
977 |           if (value>0.0) { |
---|
978 |            if (rowLower[jRow]>-1.0e20) |
---|
979 | Â Â Â Â Â Â Â Â Â Â Â Â good=false; |
---|
980 |           } else { |
---|
981 |            if (rowUpper[jRow]<1.0e20) |
---|
982 | Â Â Â Â Â Â Â Â Â Â Â Â good=false; |
---|
983 | Â Â Â Â Â Â Â Â Â Â } |
---|
984 |          } else { |
---|
985 | Â Â Â Â Â Â Â Â Â Â good=false; |
---|
986 | Â Â Â Â Â Â Â Â Â } |
---|
987 | Â Â Â Â Â Â Â Â } |
---|
988 | Â Â Â Â Â Â Â } |
---|
989 |        if (good) { |
---|
990 | Â Â Â Â Â Â Â Â // both can be integer |
---|
991 | Â Â Â Â Â Â Â Â changed[numberChanged++]=jColumn1; |
---|
992 | Â Â Â Â Â Â Â Â solver->setInteger(jColumn1); |
---|
993 |         if (upper[jColumn1]>1.0e20) |
---|
994 | Â Â Â Â Â Â Â Â Â solver->setColUpper(jColumn1,1.0e20); |
---|
995 |         if (lower[jColumn1]<-1.0e20) |
---|
996 | Â Â Â Â Â Â Â Â Â solver->setColLower(jColumn1,-1.0e20); |
---|
997 | Â Â Â Â Â Â Â Â changed[numberChanged++]=jColumn2; |
---|
998 | Â Â Â Â Â Â Â Â solver->setInteger(jColumn2); |
---|
999 |         if (upper[jColumn2]>1.0e20) |
---|
1000 | Â Â Â Â Â Â Â Â Â solver->setColUpper(jColumn2,1.0e20); |
---|
1001 |         if (lower[jColumn2]<-1.0e20) |
---|
1002 | Â Â Â Â Â Â Â Â Â solver->setColLower(jColumn2,-1.0e20); |
---|
1003 | Â Â Â Â Â Â Â } |
---|
1004 | Â Â Â Â Â Â } |
---|
1005 | Â Â Â Â Â Â // clear |
---|
1006 |       for (i=0;i<n;i++) { |
---|
1007 | Â Â Â Â Â Â Â changeRhs[which[i]]=0.0; |
---|
1008 | Â Â Â Â Â Â } |
---|
1009 | Â Â Â Â Â } |
---|
1010 | Â Â Â Â } |
---|
1011 | Â Â Â } |
---|
1012 | Â Â } |
---|
1013 |   for (iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
1014 |    if (upper[iColumn] > lower[iColumn]+1.0e-8&&!solver->isInteger(iColumn)) { |
---|
1015 |     double value; |
---|
1016 | Â Â Â Â value =Â upper[iColumn]; |
---|
1017 |     if (value<1.0e20&&fabs(value-floor(value+0.5))>1.0e-12) |
---|
1018 | Â Â Â Â Â continue; |
---|
1019 | Â Â Â Â value =Â lower[iColumn]; |
---|
1020 |     if (value>-1.0e20&&fabs(value-floor(value+0.5))>1.0e-12) |
---|
1021 | Â Â Â Â Â continue; |
---|
1022 |     bool integer=true; |
---|
1023 |     for (CoinBigIndex j=columnStart[iColumn];j<columnStart[iColumn]+columnLength[iColumn];j++) { |
---|
1024 |      int iRow = row[j]; |
---|
1025 |      if (!ignore[iRow]) { |
---|
1026 | Â Â Â Â Â Â integer=false; |
---|
1027 | Â Â Â Â Â Â break; |
---|
1028 | Â Â Â Â Â } |
---|
1029 | Â Â Â Â } |
---|
1030 |     if (integer) { |
---|
1031 | Â Â Â Â Â // integer |
---|
1032 | Â Â Â Â Â changed[numberChanged++]=iColumn; |
---|
1033 | Â Â Â Â Â solver->setInteger(iColumn); |
---|
1034 |      if (upper[iColumn]>1.0e20) |
---|
1035 | Â Â Â Â Â Â solver->setColUpper(iColumn,1.0e20); |
---|
1036 |      if (lower[iColumn]<-1.0e20) |
---|
1037 | Â Â Â Â Â Â solver->setColLower(iColumn,-1.0e20); |
---|
1038 | Â Â Â Â } |
---|
1039 | Â Â Â } |
---|
1040 | Â Â } |
---|
1041 | Â Â finished =Â numberChanged==saveNumberChanged; |
---|
1042 | Â } |
---|
1043 |  delete [] which; |
---|
1044 |  delete [] changeRhs; |
---|
1045 |  delete [] ignore; |
---|
1046 | Â //if (numberInteger&&!noPrinting_) |
---|
1047 | Â //printf("%d integer variables",numberInteger); |
---|
1048 |  if (changeInt) { |
---|
1049 | Â Â //if (!noPrinting_) { |
---|
1050 | Â Â //if (numberChanged) |
---|
1051 | Â Â //Â printf(" and %d variables made integer\n",numberChanged); |
---|
1052 | Â Â //else |
---|
1053 | Â Â //Â printf("\n"); |
---|
1054 | Â Â //} |
---|
1055 |   delete [] ignore; |
---|
1056 | Â Â //increment=0.0; |
---|
1057 |   if (!numberChanged) { |
---|
1058 |    delete [] changed; |
---|
1059 |    delete solver; |
---|
1060 |    return NULL; |
---|
1061 |   } else { |
---|
1062 |    for (iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
1063 |     if (solver->isInteger(iColumn)) |
---|
1064 | Â Â Â Â Â solverMod->setInteger(iColumn); |
---|
1065 | Â Â Â } |
---|
1066 |    delete solver; |
---|
1067 |    return changed; |
---|
1068 | Â Â } |
---|
1069 |  } else { |
---|
1070 | Â Â //if (!noPrinting_) { |
---|
1071 | Â Â //if (numberChanged) |
---|
1072 | Â Â //Â printf(" and %d variables could be made integer\n",numberChanged); |
---|
1073 | Â Â //else |
---|
1074 | Â Â //Â printf("\n"); |
---|
1075 | Â Â //} |
---|
1076 | Â Â // just get increment |
---|
1077 |   int logLevel=generalMessageHandler->logLevel(); |
---|
1078 | Â Â CbcModel model(*solver); |
---|
1079 | Â Â model.passInMessageHandler(generalMessageHandler); |
---|
1080 |   if (noPrinting_) |
---|
1081 | Â Â Â model.setLogLevel(0); |
---|
1082 | Â Â model.analyzeObjective(); |
---|
1083 | Â Â generalMessageHandler->setLogLevel(logLevel); |
---|
1084 |   double increment2=model.getCutoffIncrement(); |
---|
1085 |   if (increment2>increment&&increment2>0.0) { |
---|
1086 |    if (!noPrinting_) { |
---|
1087 | Â Â Â Â sprintf(generalPrint,"Cutoff increment increased from %g to %g",increment,increment2); |
---|
1088 | Â Â Â Â CoinMessages generalMessages =Â solverMod->getModelPtr()->messages(); |
---|
1089 | Â Â Â Â generalMessageHandler->message(CLP_GENERAL,generalMessages) |
---|
1090 | Â Â Â Â Â <<Â generalPrint |
---|
1091 | Â Â Â Â Â <<CoinMessageEol; |
---|
1092 | Â Â Â } |
---|
1093 | Â Â Â increment=increment2; |
---|
1094 | Â Â } |
---|
1095 |   delete solver; |
---|
1096 | Â Â numberChanged=0; |
---|
1097 |   delete [] changed; |
---|
1098 |   return NULL; |
---|
1099 | Â } |
---|
1100 | } |
---|
1101 | #if 1 |
---|
1102 | #include "ClpSimplexOther.hpp" |
---|
1103 | |
---|
1104 | // Crunch down model |
---|
1105 | static void |
---|
1106 | crunchIt(ClpSimplex *Â model) |
---|
1107 | { |
---|
1108 | #if 0 |
---|
1109 | Â model->dual(); |
---|
1110 | #else |
---|
1111 | Â int numberColumns = model->numberColumns(); |
---|
1112 | Â int numberRows = model->numberRows(); |
---|
1113 | Â // Use dual region |
---|
1114 | Â double * rhs = model->dualRowSolution(); |
---|
1115 | Â int * whichRow = new int[3*numberRows]; |
---|
1116 | Â int * whichColumn = new int[2*numberColumns]; |
---|
1117 | Â int nBound; |
---|
1118 | Â ClpSimplex * small = ((ClpSimplexOther *) model)->crunch(rhs,whichRow,whichColumn, |
---|
1119 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â nBound,false,false); |
---|
1120 | Â if (small) { |
---|
1121 | Â Â small->dual(); |
---|
1122 | Â Â if (small->problemStatus()==0) { |
---|
1123 | Â Â Â model->setProblemStatus(0); |
---|
1124 | Â Â Â ((ClpSimplexOther *) model)->afterCrunch(*small,whichRow,whichColumn,nBound); |
---|
1125 | Â Â } else if (small->problemStatus()!=3) { |
---|
1126 | Â Â Â model->setProblemStatus(1); |
---|
1127 | Â Â } else { |
---|
1128 | Â Â Â if (small->problemStatus()==3) { |
---|
1129 | Â Â Â Â // may be problems |
---|
1130 | Â Â Â Â small->computeObjectiveValue(); |
---|
1131 | Â Â Â Â model->setObjectiveValue(small->objectiveValue()); |
---|
1132 | Â Â Â Â model->setProblemStatus(3); |
---|
1133 | Â Â Â } else { |
---|
1134 | Â Â Â Â model->setProblemStatus(3); |
---|
1135 | Â Â Â } |
---|
1136 | Â Â } |
---|
1137 | Â Â delete small; |
---|
1138 | Â } else { |
---|
1139 | Â Â model->setProblemStatus(1); |
---|
1140 | Â } |
---|
1141 | Â delete [] whichRow; |
---|
1142 | Â delete [] whichColumn; |
---|
1143 | #endif |
---|
1144 | } |
---|
1145 | /* |
---|
1146 | Â On input |
---|
1147 | Â doAction - 0 just fix in original and return NULL |
---|
1148 | Â Â Â Â Â Â Â 1 return fixed non-presolved solver |
---|
1149 | Â Â Â Â Â Â Â 2 as one but use presolve Inside this |
---|
1150 | Â Â Â Â Â Â Â 3 do heuristics and set best solution |
---|
1151 | Â Â Â Â Â Â Â 4 do BAB and just set best solution |
---|
1152 | Â Â Â Â Â Â Â 10+ then use lastSolution and relax a few |
---|
1153 | Â Â Â Â Â Â Â -2 cleanup afterwards if using 2 |
---|
1154 | Â On output - number fixed |
---|
1155 | */ |
---|
1156 | static OsiClpSolverInterface * fixVubs(CbcModel & model, int skipZero2, |
---|
1157 |                     int & doAction, CoinMessageHandler * generalMessageHandler, |
---|
1158 |                     const double * lastSolution, double dextra[5]) |
---|
1159 | { |
---|
1160 |  if (doAction==11&&!lastSolution) |
---|
1161 | Â Â lastSolution =Â model.bestSolution(); |
---|
1162 | Â assert (((doAction==1||doAction==2)&&!lastSolution)||(doAction==11&&lastSolution)); |
---|
1163 |  double fractionIntFixed = dextra[3]; |
---|
1164 |  double fractionFixed = dextra[4]; |
---|
1165 |  double time1 = CoinCpuTime(); |
---|
1166 | Â OsiSolverInterface *Â originalSolver =Â model.solver(); |
---|
1167 | Â OsiClpSolverInterface *Â originalClpSolver =Â dynamic_cast<Â OsiClpSolverInterface*>Â (originalSolver); |
---|
1168 | Â ClpSimplex *Â originalLpSolver =Â originalClpSolver->getModelPtr(); |
---|
1169 |  int * originalColumns=NULL; |
---|
1170 | Â OsiClpSolverInterface *Â clpSolver; |
---|
1171 | Â ClpSimplex *Â lpSolver; |
---|
1172 | Â ClpPresolve pinfo; |
---|
1173 |  if (doAction==2) { |
---|
1174 | Â Â doAction=1; |
---|
1175 | Â Â lpSolver =Â pinfo.presolvedModel(*originalLpSolver,1.0e-8,true,10); |
---|
1176 | Â Â assert (lpSolver); |
---|
1177 |   clpSolver = new OsiClpSolverInterface(lpSolver,true); |
---|
1178 | Â Â assert(lpSolver ==Â clpSolver->getModelPtr()); |
---|
1179 | Â Â //int numberColumns = lpSolver->numberColumns(); |
---|
1180 |   int numberColumns = lpSolver->numberColumns(); |
---|
1181 | Â Â originalColumns =Â CoinCopyOfArray(pinfo.originalColumns(),numberColumns); |
---|
1182 |  } else { |
---|
1183 | Â Â OsiSolverInterface *Â solver =Â originalSolver->clone(); |
---|
1184 | Â Â clpSolver =Â dynamic_cast<Â OsiClpSolverInterface*>Â (solver); |
---|
1185 | Â Â lpSolver =Â clpSolver->getModelPtr(); |
---|
1186 | Â } |
---|
1187 | Â // Tighten bounds |
---|
1188 | Â lpSolver->tightenPrimalBounds(0.0,11,true); |
---|
1189 |  int numberColumns = clpSolver->getNumCols() ; |
---|
1190 |  double * saveColumnLower = CoinCopyOfArray(lpSolver->columnLower(),numberColumns); |
---|
1191 |  double * saveColumnUpper = CoinCopyOfArray(lpSolver->columnUpper(),numberColumns); |
---|
1192 | Â //char generalPrint[200]; |
---|
1193 |  const double *objective = lpSolver->getObjCoefficients() ; |
---|
1194 |  double *columnLower = lpSolver->columnLower() ; |
---|
1195 |  double *columnUpper = lpSolver->columnUpper() ; |
---|
1196 |  int numberRows = clpSolver->getNumRows(); |
---|
1197 |  int iRow,iColumn; |
---|
1198 | |
---|
1199 | Â // Row copy |
---|
1200 | Â CoinPackedMatrix matrixByRow(*clpSolver->getMatrixByRow()); |
---|
1201 |  const double * elementByRow = matrixByRow.getElements(); |
---|
1202 |  const int * column = matrixByRow.getIndices(); |
---|
1203 |  const CoinBigIndex * rowStart = matrixByRow.getVectorStarts(); |
---|
1204 |  const int * rowLength = matrixByRow.getVectorLengths(); |
---|
1205 | |
---|
1206 | Â // Column copy |
---|
1207 |  CoinPackedMatrix matrixByCol(*clpSolver->getMatrixByCol()); |
---|
1208 | Â //const double * element = matrixByCol.getElements(); |
---|
1209 |  const int * row = matrixByCol.getIndices(); |
---|
1210 |  const CoinBigIndex * columnStart = matrixByCol.getVectorStarts(); |
---|
1211 |  const int * columnLength = matrixByCol.getVectorLengths(); |
---|
1212 | |
---|
1213 |  const double * rowLower = clpSolver->getRowLower(); |
---|
1214 |  const double * rowUpper = clpSolver->getRowUpper(); |
---|
1215 | |
---|
1216 | Â // Get maximum size of VUB tree |
---|
1217 | Â // otherColumn is one fixed to 0 if this one zero |
---|
1218 |  int nEl = matrixByCol.getNumElements(); |
---|
1219 |  CoinBigIndex * fixColumn = new CoinBigIndex [numberColumns+1]; |
---|
1220 |  int * otherColumn = new int [nEl]; |
---|
1221 |  int * fix = new int[numberColumns]; |
---|
1222 |  char * mark = new char [numberColumns]; |
---|
1223 | Â memset(mark,0,numberColumns); |
---|
1224 |  int numberInteger=0; |
---|
1225 |  int numberOther=0; |
---|
1226 | Â fixColumn[0]=0; |
---|
1227 |  double large = lpSolver->largeValue(); // treat bounds > this as infinite |
---|
1228 | #ifndef NDEBUG |
---|
1229 |  double large2= 1.0e10*large; |
---|
1230 | #endif |
---|
1231 |  double tolerance = lpSolver->primalTolerance(); |
---|
1232 |  int * check = new int[numberRows]; |
---|
1233 |  for (iRow=0;iRow<numberRows;iRow++) { |
---|
1234 | Â Â check[iRow]=-2;Â // don't check |
---|
1235 |   if (rowLower[iRow]<-1.0e6&&rowUpper[iRow]>1.0e6) |
---|
1236 | Â Â Â continue;// unlikely |
---|
1237 | Â Â // possible row |
---|
1238 |   int numberPositive=0; |
---|
1239 |   int iPositive=-1; |
---|
1240 |   int numberNegative=0; |
---|
1241 |   int iNegative=-1; |
---|
1242 | Â Â CoinBigIndex rStart =Â rowStart[iRow]; |
---|
1243 | Â Â CoinBigIndex rEnd =Â rowStart[iRow]+rowLength[iRow]; |
---|
1244 | Â Â CoinBigIndex j; |
---|
1245 |   int kColumn; |
---|
1246 |   for (j = rStart; j < rEnd; ++j) { |
---|
1247 |    double value=elementByRow[j]; |
---|
1248 | Â Â Â kColumn =Â column[j]; |
---|
1249 |    if (columnUpper[kColumn]>columnLower[kColumn]) { |
---|
1250 |     if (value > 0.0) { |
---|
1251 | Â Â Â Â Â numberPositive++; |
---|
1252 | Â Â Â Â Â iPositive=kColumn; |
---|
1253 |     } else { |
---|
1254 | Â Â Â Â Â numberNegative++; |
---|
1255 | Â Â Â Â Â iNegative=kColumn; |
---|
1256 | Â Â Â Â } |
---|
1257 | Â Â Â } |
---|
1258 | Â Â } |
---|
1259 |   if (numberPositive==1&&numberNegative==1) |
---|
1260 | Â Â Â check[iRow]=-1;Â // try both |
---|
1261 |   if (numberPositive==1&&rowLower[iRow]>-1.0e20) |
---|
1262 | Â Â Â check[iRow]=iPositive; |
---|
1263 |   else if (numberNegative==1&&rowUpper[iRow]<1.0e20) |
---|
1264 | Â Â Â check[iRow]=iNegative; |
---|
1265 | Â } |
---|
1266 |  for (iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
1267 | Â Â fix[iColumn]=-1; |
---|
1268 |   if (columnUpper[iColumn] > columnLower[iColumn]+1.0e-8) { |
---|
1269 |    if (clpSolver->isInteger(iColumn)) |
---|
1270 | Â Â Â Â numberInteger++; |
---|
1271 |    if (columnLower[iColumn]==0.0) { |
---|
1272 |     bool infeasible=false; |
---|
1273 | Â Â Â Â fix[iColumn]=0; |
---|
1274 | Â Â Â Â // fake upper bound |
---|
1275 |     double saveUpper = columnUpper[iColumn]; |
---|
1276 | Â Â Â Â columnUpper[iColumn]=0.0; |
---|
1277 |     for (CoinBigIndex i=columnStart[iColumn]; |
---|
1278 | Â Â Â Â Â Â Â i<columnStart[iColumn]+columnLength[iColumn];i++)Â { |
---|
1279 | Â Â Â Â Â iRow =Â row[i]; |
---|
1280 |      if (check[iRow]!=-1&&check[iRow]!=iColumn) |
---|
1281 | Â Â Â Â Â Â continue;Â // unlikely |
---|
1282 | Â Â Â Â Â // possible row |
---|
1283 |      int infiniteUpper = 0; |
---|
1284 |      int infiniteLower = 0; |
---|
1285 |      double maximumUp = 0.0; |
---|
1286 |      double maximumDown = 0.0; |
---|
1287 |      double newBound; |
---|
1288 | Â Â Â Â Â CoinBigIndex rStart =Â rowStart[iRow]; |
---|
1289 | Â Â Â Â Â CoinBigIndex rEnd =Â rowStart[iRow]+rowLength[iRow]; |
---|
1290 | Â Â Â Â Â CoinBigIndex j; |
---|
1291 |      int kColumn; |
---|
1292 | Â Â Â Â Â // Compute possible lower and upper ranges |
---|
1293 |      for (j = rStart; j < rEnd; ++j) { |
---|
1294 |       double value=elementByRow[j]; |
---|
1295 | Â Â Â Â Â Â kColumn =Â column[j]; |
---|
1296 |       if (value > 0.0) { |
---|
1297 |        if (columnUpper[kColumn] >= large) { |
---|
1298 | Â Â Â Â Â Â Â Â ++infiniteUpper; |
---|
1299 |        } else { |
---|
1300 | Â Â Â Â Â Â Â Â maximumUp +=Â columnUpper[kColumn]Â *Â value; |
---|
1301 | Â Â Â Â Â Â Â } |
---|
1302 |        if (columnLower[kColumn] <= -large) { |
---|
1303 | Â Â Â Â Â Â Â Â ++infiniteLower; |
---|
1304 |        } else { |
---|
1305 | Â Â Â Â Â Â Â Â maximumDown +=Â columnLower[kColumn]Â *Â value; |
---|
1306 | Â Â Â Â Â Â Â } |
---|
1307 |       } else if (value<0.0) { |
---|
1308 |        if (columnUpper[kColumn] >= large) { |
---|
1309 | Â Â Â Â Â Â Â Â ++infiniteLower; |
---|
1310 |        } else { |
---|
1311 | Â Â Â Â Â Â Â Â maximumDown +=Â columnUpper[kColumn]Â *Â value; |
---|
1312 | Â Â Â Â Â Â Â } |
---|
1313 |        if (columnLower[kColumn] <= -large) { |
---|
1314 | Â Â Â Â Â Â Â Â ++infiniteUpper; |
---|
1315 |        } else { |
---|
1316 | Â Â Â Â Â Â Â Â maximumUp +=Â columnLower[kColumn]Â *Â value; |
---|
1317 | Â Â Â Â Â Â Â } |
---|
1318 | Â Â Â Â Â Â } |
---|
1319 | Â Â Â Â Â } |
---|
1320 | Â Â Â Â Â // Build in a margin of error |
---|
1321 | Â Â Â Â Â maximumUp +=Â 1.0e-8*fabs(maximumUp); |
---|
1322 | Â Â Â Â Â maximumDown -=Â 1.0e-8*fabs(maximumDown); |
---|
1323 |      double maxUp = maximumUp+infiniteUpper*1.0e31; |
---|
1324 |      double maxDown = maximumDown-infiniteLower*1.0e31; |
---|
1325 |      if (maxUp <= rowUpper[iRow] + tolerance && |
---|
1326 | Â Â Â Â Â Â Â maxDown >=Â rowLower[iRow]Â -Â tolerance)Â { |
---|
1327 | Â Â Â Â Â Â //printf("Redundant row in vubs %d\n",iRow); |
---|
1328 |      } else { |
---|
1329 |       if (maxUp < rowLower[iRow] -100.0*tolerance || |
---|
1330 | Â Â Â Â Â Â Â Â maxDown >Â rowUpper[iRow]+100.0*tolerance)Â { |
---|
1331 | Â Â Â Â Â Â Â infeasible=true; |
---|
1332 | Â Â Â Â Â Â Â break; |
---|
1333 | Â Â Â Â Â Â } |
---|
1334 |       double lower = rowLower[iRow]; |
---|
1335 |       double upper = rowUpper[iRow]; |
---|
1336 |       for (j = rStart; j < rEnd; ++j) { |
---|
1337 |        double value=elementByRow[j]; |
---|
1338 | Â Â Â Â Â Â Â kColumn =Â column[j]; |
---|
1339 |        double nowLower = columnLower[kColumn]; |
---|
1340 |        double nowUpper = columnUpper[kColumn]; |
---|
1341 |        if (value > 0.0) { |
---|
1342 | Â Â Â Â Â Â Â Â // positive value |
---|
1343 |         if (lower>-large) { |
---|
1344 |          if (!infiniteUpper) { |
---|
1345 | Â Â Â Â Â Â Â Â Â Â assert(nowUpper <Â large2); |
---|
1346 | Â Â Â Â Â Â Â Â Â Â newBound =Â nowUpper +Â |
---|
1347 | Â Â Â Â Â Â Â Â Â Â Â (lower -Â maximumUp)Â /Â value; |
---|
1348 | Â Â Â Â Â Â Â Â Â Â // relax if original was large |
---|
1349 |           if (fabs(maximumUp)>1.0e8) |
---|
1350 | Â Â Â Â Â Â Â Â Â Â Â newBound -=Â 1.0e-12*fabs(maximumUp); |
---|
1351 |          } else if (infiniteUpper==1&&nowUpper>large) { |
---|
1352 | Â Â Â Â Â Â Â Â Â Â newBound =Â (lower -maximumUp)Â /Â value; |
---|
1353 | Â Â Â Â Â Â Â Â Â Â // relax if original was large |
---|
1354 |           if (fabs(maximumUp)>1.0e8) |
---|
1355 | Â Â Â Â Â Â Â Â Â Â Â newBound -=Â 1.0e-12*fabs(maximumUp); |
---|
1356 |          } else { |
---|
1357 | Â Â Â Â Â Â Â Â Â Â newBound =Â -COIN_DBL_MAX; |
---|
1358 | Â Â Â Â Â Â Â Â Â } |
---|
1359 |          if (newBound > nowLower + 1.0e-12&&newBound>-large) { |
---|
1360 | Â Â Â Â Â Â Â Â Â Â // Tighten the lower bound |
---|
1361 | Â Â Â Â Â Â Â Â Â Â // check infeasible (relaxed) |
---|
1362 |           if (nowUpper < newBound) { |
---|
1363 |            if (nowUpper - newBound < |
---|
1364 | Â Â Â Â Â Â Â Â Â Â Â Â Â -100.0*tolerance)Â {Â |
---|
1365 | Â Â Â Â Â Â Â Â Â Â Â Â infeasible=true; |
---|
1366 | Â Â Â Â Â Â Â Â Â Â Â Â break; |
---|
1367 | Â Â Â Â Â Â Â Â Â Â Â } |
---|
1368 | Â Â Â Â Â Â Â Â Â Â } |
---|
1369 | Â Â Â Â Â Â Â Â Â } |
---|
1370 | Â Â Â Â Â Â Â Â }Â |
---|
1371 |         if (upper <large) { |
---|
1372 |          if (!infiniteLower) { |
---|
1373 | Â Â Â Â Â Â Â Â Â Â assert(nowLower >-Â large2); |
---|
1374 | Â Â Â Â Â Â Â Â Â Â newBound =Â nowLower +Â |
---|
1375 | Â Â Â Â Â Â Â Â Â Â Â (upper -Â maximumDown)Â /Â value; |
---|
1376 | Â Â Â Â Â Â Â Â Â Â // relax if original was large |
---|
1377 |           if (fabs(maximumDown)>1.0e8) |
---|
1378 | Â Â Â Â Â Â Â Â Â Â newBound +=Â 1.0e-12*fabs(maximumDown); |
---|
1379 |          } else if (infiniteLower==1&&nowLower<-large) { |
---|
1380 | Â Â Â Â Â Â Â Â Â Â newBound =Â Â (upper -Â maximumDown)Â /Â value; |
---|
1381 | Â Â Â Â Â Â Â Â Â Â // relax if original was large |
---|
1382 |           if (fabs(maximumDown)>1.0e8) |
---|
1383 | Â Â Â Â Â Â Â Â Â Â Â newBound +=Â 1.0e-12*fabs(maximumDown); |
---|
1384 |          } else { |
---|
1385 | Â Â Â Â Â Â Â Â Â Â newBound =Â COIN_DBL_MAX; |
---|
1386 | Â Â Â Â Â Â Â Â Â } |
---|
1387 |          if (newBound < nowUpper - 1.0e-12&&newBound<large) { |
---|
1388 | Â Â Â Â Â Â Â Â Â Â // Tighten the upper bound |
---|
1389 | Â Â Â Â Â Â Â Â Â Â // check infeasible (relaxed) |
---|
1390 |           if (nowLower > newBound) { |
---|
1391 |            if (newBound - nowLower < |
---|
1392 | Â Â Â Â Â Â Â Â Â Â Â Â Â -100.0*tolerance)Â { |
---|
1393 | Â Â Â Â Â Â Â Â Â Â Â Â infeasible=true; |
---|
1394 | Â Â Â Â Â Â Â Â Â Â Â Â break; |
---|
1395 |            } else { |
---|
1396 | Â Â Â Â Â Â Â Â Â Â Â Â newBound=nowLower; |
---|
1397 | Â Â Â Â Â Â Â Â Â Â Â } |
---|
1398 | Â Â Â Â Â Â Â Â Â Â } |
---|
1399 |           if (!newBound||(clpSolver->isInteger(kColumn)&&newBound<0.999)) { |
---|
1400 | Â Â Â Â Â Â Â Â Â Â Â // fix to zero |
---|
1401 |            if (!mark[kColumn]) { |
---|
1402 | Â Â Â Â Â Â Â Â Â Â Â Â otherColumn[numberOther++]=kColumn; |
---|
1403 | Â Â Â Â Â Â Â Â Â Â Â Â mark[kColumn]=1; |
---|
1404 |             if (check[iRow]==-1) |
---|
1405 | Â Â Â Â Â Â Â Â Â Â Â Â Â check[iRow]=iColumn; |
---|
1406 | Â Â Â Â Â Â Â Â Â Â Â Â else |
---|
1407 | Â Â Â Â Â Â Â Â Â Â Â Â Â assert(check[iRow]==iColumn); |
---|
1408 | Â Â Â Â Â Â Â Â Â Â Â } |
---|
1409 | Â Â Â Â Â Â Â Â Â Â } |
---|
1410 | Â Â Â Â Â Â Â Â Â } |
---|
1411 | Â Â Â Â Â Â Â Â } |
---|
1412 |        } else { |
---|
1413 | Â Â Â Â Â Â Â Â // negative value |
---|
1414 |         if (lower>-large) { |
---|
1415 |          if (!infiniteUpper) { |
---|
1416 | Â Â Â Â Â Â Â Â Â Â assert(nowLower <Â large2); |
---|
1417 | Â Â Â Â Â Â Â Â Â Â newBound =Â nowLower +Â |
---|
1418 | Â Â Â Â Â Â Â Â Â Â Â (lower -Â maximumUp)Â /Â value; |
---|
1419 | Â Â Â Â Â Â Â Â Â Â // relax if original was large |
---|
1420 |           if (fabs(maximumUp)>1.0e8) |
---|
1421 | Â Â Â Â Â Â Â Â Â Â Â newBound +=Â 1.0e-12*fabs(maximumUp); |
---|
1422 |          } else if (infiniteUpper==1&&nowLower<-large) { |
---|
1423 | Â Â Â Â Â Â Â Â Â Â newBound =Â (lower -maximumUp)Â /Â value; |
---|
1424 | Â Â Â Â Â Â Â Â Â Â // relax if original was large |
---|
1425 |           if (fabs(maximumUp)>1.0e8) |
---|
1426 | Â Â Â Â Â Â Â Â Â Â Â newBound +=Â 1.0e-12*fabs(maximumUp); |
---|
1427 |          } else { |
---|
1428 | Â Â Â Â Â Â Â Â Â Â newBound =Â COIN_DBL_MAX; |
---|
1429 | Â Â Â Â Â Â Â Â Â } |
---|
1430 |          if (newBound < nowUpper - 1.0e-12&&newBound<large) { |
---|
1431 | Â Â Â Â Â Â Â Â Â Â // Tighten the upper bound |
---|
1432 | Â Â Â Â Â Â Â Â Â Â // check infeasible (relaxed) |
---|
1433 |           if (nowLower > newBound) { |
---|
1434 |            if (newBound - nowLower < |
---|
1435 | Â Â Â Â Â Â Â Â Â Â Â Â Â -100.0*tolerance)Â { |
---|
1436 | Â Â Â Â Â Â Â Â Â Â Â Â infeasible=true; |
---|
1437 | Â Â Â Â Â Â Â Â Â Â Â Â break; |
---|
1438 |            } else { |
---|
1439 | Â Â Â Â Â Â Â Â Â Â Â Â newBound=nowLower; |
---|
1440 | Â Â Â Â Â Â Â Â Â Â Â } |
---|
1441 | Â Â Â Â Â Â Â Â Â Â } |
---|
1442 |           if (!newBound||(clpSolver->isInteger(kColumn)&&newBound<0.999)) { |
---|
1443 | Â Â Â Â Â Â Â Â Â Â Â // fix to zero |
---|
1444 |            if (!mark[kColumn]) { |
---|
1445 | Â Â Â Â Â Â Â Â Â Â Â Â otherColumn[numberOther++]=kColumn; |
---|
1446 | Â Â Â Â Â Â Â Â Â Â Â Â mark[kColumn]=1; |
---|
1447 |             if (check[iRow]==-1) |
---|
1448 | Â Â Â Â Â Â Â Â Â Â Â Â Â check[iRow]=iColumn; |
---|
1449 | Â Â Â Â Â Â Â Â Â Â Â Â else |
---|
1450 | Â Â Â Â Â Â Â Â Â Â Â Â Â assert(check[iRow]==iColumn); |
---|
1451 | Â Â Â Â Â Â Â Â Â Â Â } |
---|
1452 | Â Â Â Â Â Â Â Â Â Â } |
---|
1453 | Â Â Â Â Â Â Â Â Â } |
---|
1454 | Â Â Â Â Â Â Â Â } |
---|
1455 |         if (upper <large) { |
---|
1456 |          if (!infiniteLower) { |
---|
1457 | Â Â Â Â Â Â Â Â Â Â assert(nowUpper <Â large2); |
---|
1458 | Â Â Â Â Â Â Â Â Â Â newBound =Â nowUpper +Â |
---|
1459 | Â Â Â Â Â Â Â Â Â Â Â (upper -Â maximumDown)Â /Â value; |
---|
1460 | Â Â Â Â Â Â Â Â Â Â // relax if original was large |
---|
1461 |           if (fabs(maximumDown)>1.0e8) |
---|
1462 | Â Â Â Â Â Â Â Â Â Â Â newBound -=Â 1.0e-12*fabs(maximumDown); |
---|
1463 |          } else if (infiniteLower==1&&nowUpper>large) { |
---|
1464 | Â Â Â Â Â Â Â Â Â Â newBound =Â Â (upper -Â maximumDown)Â /Â value; |
---|
1465 | Â Â Â Â Â Â Â Â Â Â // relax if original was large |
---|
1466 |           if (fabs(maximumDown)>1.0e8) |
---|
1467 | Â Â Â Â Â Â Â Â Â Â Â newBound -=Â 1.0e-12*fabs(maximumDown); |
---|
1468 |          } else { |
---|
1469 | Â Â Â Â Â Â Â Â Â Â newBound =Â -COIN_DBL_MAX; |
---|
1470 | Â Â Â Â Â Â Â Â Â } |
---|
1471 |          if (newBound > nowLower + 1.0e-12&&newBound>-large) { |
---|
1472 | Â Â Â Â Â Â Â Â Â Â // Tighten the lower bound |
---|
1473 | Â Â Â Â Â Â Â Â Â Â // check infeasible (relaxed) |
---|
1474 |           if (nowUpper < newBound) { |
---|
1475 |            if (nowUpper - newBound < |
---|
1476 | Â Â Â Â Â Â Â Â Â Â Â Â Â -100.0*tolerance)Â { |
---|
1477 | Â Â Â Â Â Â Â Â Â Â Â Â infeasible=true; |
---|
1478 | Â Â Â Â Â Â Â Â Â Â Â Â break; |
---|
1479 | Â Â Â Â Â Â Â Â Â Â Â } |
---|
1480 | Â Â Â Â Â Â Â Â Â Â } |
---|
1481 | Â Â Â Â Â Â Â Â Â } |
---|
1482 | Â Â Â Â Â Â Â Â } |
---|
1483 | Â Â Â Â Â Â Â } |
---|
1484 | Â Â Â Â Â Â } |
---|
1485 | Â Â Â Â Â } |
---|
1486 | Â Â Â Â } |
---|
1487 |     for (int i=fixColumn[iColumn];i<numberOther;i++) |
---|
1488 | Â Â Â Â Â mark[otherColumn[i]]=0; |
---|
1489 | Â Â Â Â // reset bound unless infeasible |
---|
1490 |     if (!infeasible||!clpSolver->isInteger(iColumn)) |
---|
1491 | Â Â Â Â Â columnUpper[iColumn]=saveUpper; |
---|
1492 |     else if (clpSolver->isInteger(iColumn)) |
---|
1493 | Â Â Â Â Â columnLower[iColumn]=1.0; |
---|
1494 | Â Â Â } |
---|
1495 | Â Â } |
---|
1496 | Â Â fixColumn[iColumn+1]=numberOther; |
---|
1497 | Â } |
---|
1498 |  delete [] check; |
---|
1499 |  delete [] mark; |
---|
1500 | Â // Now do reverse way |
---|
1501 |  int * counts = new int [numberColumns]; |
---|
1502 | Â CoinZeroN(counts,numberColumns); |
---|
1503 |  for (iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
1504 |   for (int i=fixColumn[iColumn];i<fixColumn[iColumn+1];i++) |
---|
1505 | Â Â Â counts[otherColumn[i]]++; |
---|
1506 | Â } |
---|
1507 | Â numberOther=0; |
---|
1508 |  CoinBigIndex * fixColumn2 = new CoinBigIndex [numberColumns+1]; |
---|
1509 |  int * otherColumn2 = new int [fixColumn[numberColumns]]; |
---|
1510 | Â fixColumn2[0]=0; |
---|
1511 |  for ( iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
1512 | Â Â numberOther +=Â counts[iColumn]; |
---|
1513 | Â Â counts[iColumn]=0; |
---|
1514 | Â Â fixColumn2[iColumn+1]=numberOther; |
---|
1515 | Â } |
---|
1516 | Â // Create other way |
---|
1517 |  for ( iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
1518 |   for (int i=fixColumn[iColumn];i<fixColumn[iColumn+1];i++) { |
---|
1519 |    int jColumn=otherColumn[i]; |
---|
1520 | Â Â Â CoinBigIndex put =Â fixColumn2[jColumn]Â +Â counts[jColumn]; |
---|
1521 | Â Â Â counts[jColumn]++; |
---|
1522 | Â Â Â otherColumn2[put]=iColumn; |
---|
1523 | Â Â } |
---|
1524 | Â } |
---|
1525 | Â // get top layer i.e. those which are not fixed by any other |
---|
1526 |  int kLayer=0; |
---|
1527 |  while (true) { |
---|
1528 |   int numberLayered=0; |
---|
1529 |   for ( iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
1530 |    if (fix[iColumn]==kLayer) { |
---|
1531 |     for (int i=fixColumn2[iColumn];i<fixColumn2[iColumn+1];i++) { |
---|
1532 |      int jColumn=otherColumn2[i]; |
---|
1533 |      if (fix[jColumn]==kLayer) { |
---|
1534 | Â Â Â Â Â Â fix[iColumn]=kLayer+100; |
---|
1535 | Â Â Â Â Â } |
---|
1536 | Â Â Â Â } |
---|
1537 | Â Â Â } |
---|
1538 |    if (fix[iColumn]==kLayer) { |
---|
1539 | Â Â Â Â numberLayered++; |
---|
1540 | Â Â Â } |
---|
1541 | Â Â } |
---|
1542 |   if (numberLayered) { |
---|
1543 | Â Â Â kLayer+=100; |
---|
1544 |   } else { |
---|
1545 | Â Â Â break; |
---|
1546 | Â Â } |
---|
1547 | Â } |
---|
1548 |  for (int iPass=0;iPass<2;iPass++) { |
---|
1549 |   for (int jLayer=0;jLayer<kLayer;jLayer++) { |
---|
1550 |    int check[]={-1,0,1,2,3,4,5,10,50,100,500,1000,5000,10000,COIN_INT_MAX}; |
---|
1551 |    int nCheck = (int) (sizeof(check)/sizeof(int)); |
---|
1552 |    int countsI[20]; |
---|
1553 |    int countsC[20]; |
---|
1554 | Â Â Â assert (nCheck<=20); |
---|
1555 | Â Â Â memset(countsI,0,nCheck*sizeof(int)); |
---|
1556 | Â Â Â memset(countsC,0,nCheck*sizeof(int)); |
---|
1557 | Â Â Â check[nCheck-1]=numberColumns; |
---|
1558 |    int numberLayered=0; |
---|
1559 |    int numberInteger=0; |
---|
1560 |    for ( iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
1561 |     if (fix[iColumn]==jLayer) { |
---|
1562 | Â Â Â Â Â numberLayered++; |
---|
1563 |      int nFix = fixColumn[iColumn+1]-fixColumn[iColumn]; |
---|
1564 |      if (iPass) { |
---|
1565 | Â Â Â Â Â Â // just integers |
---|
1566 | Â Â Â Â Â Â nFix=0; |
---|
1567 |       for (int i=fixColumn[iColumn];i<fixColumn[iColumn+1];i++) { |
---|
1568 |        int jColumn=otherColumn[i]; |
---|
1569 |        if (clpSolver->isInteger(jColumn)) |
---|
1570 | Â Â Â Â Â Â Â Â nFix++; |
---|
1571 | Â Â Â Â Â Â } |
---|
1572 | Â Â Â Â Â } |
---|
1573 |      int iFix; |
---|
1574 |      for (iFix=0;iFix<nCheck;iFix++) { |
---|
1575 |       if (nFix<=check[iFix]) |
---|
1576 | Â Â Â Â Â Â Â break; |
---|
1577 | Â Â Â Â Â } |
---|
1578 | Â Â Â Â Â assert (iFix<nCheck); |
---|
1579 |      if (clpSolver->isInteger(iColumn)) { |
---|
1580 | Â Â Â Â Â Â numberInteger++; |
---|
1581 | Â Â Â Â Â Â countsI[iFix]++; |
---|
1582 |      } else { |
---|
1583 | Â Â Â Â Â Â countsC[iFix]++; |
---|
1584 | Â Â Â Â Â } |
---|
1585 | Â Â Â Â } |
---|
1586 | Â Â Â } |
---|
1587 |    if (numberLayered) { |
---|
1588 | Â Â Â Â printf("%d (%d integer) at priority %d\n",numberLayered,numberInteger,1+(jLayer/100)); |
---|
1589 |     char buffer[50]; |
---|
1590 |     for (int i=1;i<nCheck;i++) { |
---|
1591 |      if (countsI[i]||countsC[i]) { |
---|
1592 |       if (i==1) |
---|
1593 |        sprintf(buffer," ==  zero      "); |
---|
1594 |       else if (i<nCheck-1) |
---|
1595 | Â Â Â Â Â Â Â sprintf(buffer,"> %6d and <= %6d ",check[i-1],check[i]); |
---|
1596 | Â Â Â Â Â Â else |
---|
1597 |        sprintf(buffer,"> %6d        ",check[i-1]); |
---|
1598 | Â Â Â Â Â Â printf("%s %8d integers and %8d continuous\n",buffer,countsI[i],countsC[i]); |
---|
1599 | Â Â Â Â Â } |
---|
1600 | Â Â Â Â } |
---|
1601 | Â Â Â } |
---|
1602 | Â Â } |
---|
1603 | Â } |
---|
1604 |  delete [] counts; |
---|
1605 | Â // Now do fixing |
---|
1606 | Â { |
---|
1607 | Â Â // switch off presolve and up weight |
---|
1608 | Â Â ClpSolve solveOptions; |
---|
1609 | Â Â //solveOptions.setPresolveType(ClpSolve::presolveOff,0); |
---|
1610 | Â Â solveOptions.setSolveType(ClpSolve::usePrimalorSprint); |
---|
1611 | Â Â //solveOptions.setSpecialOption(1,3,30); // sprint |
---|
1612 |   int numberColumns = lpSolver->numberColumns(); |
---|
1613 |   int iColumn; |
---|
1614 |   bool allSlack=true; |
---|
1615 |   for (iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
1616 |    if (lpSolver->getColumnStatus(iColumn)==ClpSimplex::basic) { |
---|
1617 | Â Â Â Â allSlack=false; |
---|
1618 | Â Â Â Â break; |
---|
1619 | Â Â Â }Â |
---|
1620 | Â Â } |
---|
1621 |   if (allSlack) |
---|
1622 | Â Â Â solveOptions.setSpecialOption(1,2,50);Â // idiot |
---|
1623 | Â Â lpSolver->setInfeasibilityCost(1.0e11); |
---|
1624 | Â Â lpSolver->defaultFactorizationFrequency(); |
---|
1625 |   if (doAction!=11) |
---|
1626 | Â Â Â lpSolver->initialSolve(solveOptions); |
---|
1627 |   double * columnLower = lpSolver->columnLower(); |
---|
1628 |   double * columnUpper = lpSolver->columnUpper(); |
---|
1629 |   double * fullSolution = lpSolver->primalColumnSolution(); |
---|
1630 |   const double * dj = lpSolver->dualColumnSolution(); |
---|
1631 |   int iPass=0; |
---|
1632 | #define MAXPROB 2 |
---|
1633 | Â Â ClpSimplex models[MAXPROB]; |
---|
1634 |   int pass[MAXPROB]; |
---|
1635 |   int kPass=-1; |
---|
1636 |   int kLayer=0; |
---|
1637 |   int skipZero=0; |
---|
1638 |   if (skipZero2==-1) |
---|
1639 | Â Â Â skipZero2=40;Â //-1; |
---|
1640 | Â Â /* 0 fixed to 0 by choice |
---|
1641 | Â Â Â Â 1 lb of 1 by choice |
---|
1642 | Â Â Â Â 2 fixed to 0 by another |
---|
1643 | Â Â Â Â 3 as 2 but this go |
---|
1644 | Â Â Â Â -1 free |
---|
1645 | Â Â */ |
---|
1646 |   char * state = new char [numberColumns]; |
---|
1647 |   for (iColumn=0;iColumn<numberColumns;iColumn++) |
---|
1648 | Â Â Â state[iColumn]=-1; |
---|
1649 |   while (true) { |
---|
1650 |    double largest=-0.1; |
---|
1651 |    double smallest=1.1; |
---|
1652 |    int iLargest=-1; |
---|
1653 |    int iSmallest=-1; |
---|
1654 |    int atZero=0; |
---|
1655 |    int atOne=0; |
---|
1656 |    int toZero=0; |
---|
1657 |    int toOne=0; |
---|
1658 |    int numberFree=0; |
---|
1659 |    int numberGreater=0; |
---|
1660 | Â Â Â columnLower =Â lpSolver->columnLower(); |
---|
1661 | Â Â Â columnUpper =Â lpSolver->columnUpper(); |
---|
1662 | Â Â Â fullSolution =Â lpSolver->primalColumnSolution(); |
---|
1663 |    if (doAction==11) { |
---|
1664 | Â Â Â Â { |
---|
1665 |      double * columnLower = lpSolver->columnLower(); |
---|
1666 |      double * columnUpper = lpSolver->columnUpper(); |
---|
1667 | Â Â Â Â Â //Â Â Â lpSolver->dual(); |
---|
1668 | Â Â Â Â Â memcpy(columnLower,saveColumnLower,numberColumns*sizeof(double)); |
---|
1669 | Â Â Â Â Â memcpy(columnUpper,saveColumnUpper,numberColumns*sizeof(double)); |
---|
1670 | Â Â Â Â Â //Â Â Â lpSolver->dual(); |
---|
1671 |      int iColumn; |
---|
1672 |      for (iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
1673 |       if (columnUpper[iColumn] > columnLower[iColumn]+1.0e-8) { |
---|
1674 |        if (clpSolver->isInteger(iColumn)) { |
---|
1675 |         double value = lastSolution[iColumn]; |
---|
1676 |         int iValue = (int) (value+0.5); |
---|
1677 | Â Â Â Â Â Â Â Â assert (fabs(value-((double)Â iValue))<1.0e-3); |
---|
1678 | Â Â Â Â Â Â Â Â assert (iValue>=columnLower[iColumn]&& |
---|
1679 | Â Â Â Â Â Â Â Â Â Â Â Â iValue<=columnUpper[iColumn]); |
---|
1680 | Â Â Â Â Â Â Â Â columnLower[iColumn]=iValue; |
---|
1681 | Â Â Â Â Â Â Â Â columnUpper[iColumn]=iValue; |
---|
1682 | Â Â Â Â Â Â Â } |
---|
1683 | Â Â Â Â Â Â } |
---|
1684 | Â Â Â Â Â } |
---|
1685 | Â Â Â Â Â lpSolver->initialSolve(solveOptions); |
---|
1686 | Â Â Â Â Â memcpy(columnLower,saveColumnLower,numberColumns*sizeof(double)); |
---|
1687 | Â Â Â Â Â memcpy(columnUpper,saveColumnUpper,numberColumns*sizeof(double)); |
---|
1688 | Â Â Â Â } |
---|
1689 |     for (iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
1690 |      if (columnUpper[iColumn] > columnLower[iColumn]+1.0e-8) { |
---|
1691 |       if (clpSolver->isInteger(iColumn)) { |
---|
1692 |        double value = lastSolution[iColumn]; |
---|
1693 |        int iValue = (int) (value+0.5); |
---|
1694 | Â Â Â Â Â Â Â assert (fabs(value-((double)Â iValue))<1.0e-3); |
---|
1695 | Â Â Â Â Â Â Â assert (iValue>=columnLower[iColumn]&& |
---|
1696 | Â Â Â Â Â Â Â Â Â Â Â iValue<=columnUpper[iColumn]); |
---|
1697 |        if (!fix[iColumn]) { |
---|
1698 |         if (iValue==0) { |
---|
1699 | Â Â Â Â Â Â Â Â Â state[iColumn]=0; |
---|
1700 | Â Â Â Â Â Â Â Â Â assert (!columnLower[iColumn]); |
---|
1701 | Â Â Â Â Â Â Â Â Â columnUpper[iColumn]=0.0; |
---|
1702 |         } else if (iValue==1) { |
---|
1703 | Â Â Â Â Â Â Â Â Â state[iColumn]=1; |
---|
1704 | Â Â Â Â Â Â Â Â Â columnLower[iColumn]=1.0; |
---|
1705 |         } else { |
---|
1706 | Â Â Â Â Â Â Â Â Â // leave fixed |
---|
1707 | Â Â Â Â Â Â Â Â Â columnLower[iColumn]=iValue; |
---|
1708 | Â Â Â Â Â Â Â Â Â columnUpper[iColumn]=iValue; |
---|
1709 | Â Â Â Â Â Â Â Â } |
---|
1710 |        } else if (iValue==0) { |
---|
1711 | Â Â Â Â Â Â Â Â state[iColumn]=10; |
---|
1712 | Â Â Â Â Â Â Â Â columnUpper[iColumn]=0.0; |
---|
1713 |        } else { |
---|
1714 | Â Â Â Â Â Â Â Â // leave fixed |
---|
1715 | Â Â Â Â Â Â Â Â columnLower[iColumn]=iValue; |
---|
1716 | Â Â Â Â Â Â Â Â columnUpper[iColumn]=iValue; |
---|
1717 | Â Â Â Â Â Â Â } |
---|
1718 | Â Â Â Â Â Â } |
---|
1719 | Â Â Â Â Â } |
---|
1720 | Â Â Â Â } |
---|
1721 |     int jLayer=0; |
---|
1722 |     int nFixed=-1; |
---|
1723 |     int nTotalFixed=0; |
---|
1724 |     while (nFixed) { |
---|
1725 | Â Â Â Â Â nFixed=0; |
---|
1726 |      for ( iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
1727 |       if (columnUpper[iColumn]==0.0&&fix[iColumn]==jLayer) { |
---|
1728 |        for (int i=fixColumn[iColumn];i<fixColumn[iColumn+1];i++) { |
---|
1729 |         int jColumn=otherColumn[i]; |
---|
1730 |         if (columnUpper[jColumn]) { |
---|
1731 |          bool canFix=true; |
---|
1732 |          for (int k=fixColumn2[jColumn];k<fixColumn2[jColumn+1];k++) { |
---|
1733 |           int kColumn=otherColumn2[k]; |
---|
1734 |           if (state[kColumn]==1) { |
---|
1735 | Â Â Â Â Â Â Â Â Â Â Â canFix=false; |
---|
1736 | Â Â Â Â Â Â Â Â Â Â Â break; |
---|
1737 | Â Â Â Â Â Â Â Â Â Â } |
---|
1738 | Â Â Â Â Â Â Â Â Â } |
---|
1739 |          if (canFix) { |
---|
1740 | Â Â Â Â Â Â Â Â Â Â columnUpper[jColumn]=0.0; |
---|
1741 | Â Â Â Â Â Â Â Â Â Â nFixed++; |
---|
1742 | Â Â Â Â Â Â Â Â Â } |
---|
1743 | Â Â Â Â Â Â Â Â } |
---|
1744 | Â Â Â Â Â Â Â } |
---|
1745 | Â Â Â Â Â Â } |
---|
1746 | Â Â Â Â Â } |
---|
1747 | Â Â Â Â Â nTotalFixed +=Â nFixed; |
---|
1748 | Â Â Â Â Â jLayer +=Â 100; |
---|
1749 | Â Â Â Â } |
---|
1750 | Â Â Â Â printf("This fixes %d variables in lower priorities\n",nTotalFixed); |
---|
1751 | Â Â Â Â break; |
---|
1752 | Â Â Â } |
---|
1753 |    for ( iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
1754 |     if (!clpSolver->isInteger(iColumn)||fix[iColumn]>kLayer) |
---|
1755 | Â Â Â Â Â continue; |
---|
1756 | Â Â Â Â // skip if fixes nothing |
---|
1757 |     if (fixColumn[iColumn+1]-fixColumn[iColumn]<=skipZero2) |
---|
1758 | Â Â Â Â Â continue; |
---|
1759 |     double value = fullSolution[iColumn]; |
---|
1760 |     if (value>1.00001) { |
---|
1761 | Â Â Â Â Â numberGreater++; |
---|
1762 | Â Â Â Â Â continue; |
---|
1763 | Â Â Â Â } |
---|
1764 |     double lower = columnLower[iColumn]; |
---|
1765 |     double upper = columnUpper[iColumn]; |
---|
1766 |     if (lower==upper) { |
---|
1767 |      if (lower) |
---|
1768 | Â Â Â Â Â Â atOne++; |
---|
1769 | Â Â Â Â Â else |
---|
1770 | Â Â Â Â Â Â atZero++; |
---|
1771 | Â Â Â Â Â continue; |
---|
1772 | Â Â Â Â } |
---|
1773 |     if (value<1.0e-7) { |
---|
1774 | Â Â Â Â Â toZero++; |
---|
1775 | Â Â Â Â Â columnUpper[iColumn]=0.0; |
---|
1776 | Â Â Â Â Â state[iColumn]=10; |
---|
1777 | Â Â Â Â Â continue; |
---|
1778 | Â Â Â Â } |
---|
1779 |     if (value>1.0-1.0e-7) { |
---|
1780 | Â Â Â Â Â toOne++; |
---|
1781 | Â Â Â Â Â columnLower[iColumn]=1.0; |
---|
1782 | Â Â Â Â Â state[iColumn]=1; |
---|
1783 | Â Â Â Â Â continue; |
---|
1784 | Â Â Â Â } |
---|
1785 | Â Â Â Â numberFree++; |
---|
1786 | Â Â Â Â // skip if fixes nothing |
---|
1787 |     if (fixColumn[iColumn+1]-fixColumn[iColumn]<=skipZero) |
---|
1788 | Â Â Â Â Â continue; |
---|
1789 |     if (value<smallest) { |
---|
1790 | Â Â Â Â Â smallest=value; |
---|
1791 | Â Â Â Â Â iSmallest=iColumn; |
---|
1792 | Â Â Â Â } |
---|
1793 |     if (value>largest) { |
---|
1794 | Â Â Â Â Â largest=value; |
---|
1795 | Â Â Â Â Â iLargest=iColumn; |
---|
1796 | Â Â Â Â } |
---|
1797 | Â Â Â } |
---|
1798 |    if (toZero||toOne) |
---|
1799 | Â Â Â Â printf("%d at 0 fixed and %d at one fixed\n",toZero,toOne); |
---|
1800 | Â Â Â printf("%d variables free, %d fixed to 0, %d to 1 - smallest %g, largest %g\n", |
---|
1801 | Â Â Â Â Â Â Â numberFree,atZero,atOne,smallest,largest); |
---|
1802 |    if (numberGreater&&!iPass) |
---|
1803 | Â Â Â Â printf("%d variables have value > 1.0\n",numberGreater); |
---|
1804 | Â Â Â //skipZero2=0; // leave 0 fixing |
---|
1805 |    int jLayer=0; |
---|
1806 |    int nFixed=-1; |
---|
1807 |    int nTotalFixed=0; |
---|
1808 |    while (nFixed) { |
---|
1809 | Â Â Â Â nFixed=0; |
---|
1810 |     for ( iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
1811 |      if (columnUpper[iColumn]==0.0&&fix[iColumn]==jLayer) { |
---|
1812 |       for (int i=fixColumn[iColumn];i<fixColumn[iColumn+1];i++) { |
---|
1813 |        int jColumn=otherColumn[i]; |
---|
1814 |        if (columnUpper[jColumn]) { |
---|
1815 |         bool canFix=true; |
---|
1816 |         for (int k=fixColumn2[jColumn];k<fixColumn2[jColumn+1];k++) { |
---|
1817 |          int kColumn=otherColumn2[k]; |
---|
1818 |          if (state[kColumn]==1) { |
---|
1819 | Â Â Â Â Â Â Â Â Â Â canFix=false; |
---|
1820 | Â Â Â Â Â Â Â Â Â Â break; |
---|
1821 | Â Â Â Â Â Â Â Â Â } |
---|
1822 | Â Â Â Â Â Â Â Â } |
---|
1823 |         if (canFix) { |
---|
1824 | Â Â Â Â Â Â Â Â Â columnUpper[jColumn]=0.0; |
---|
1825 | Â Â Â Â Â Â Â Â Â nFixed++; |
---|
1826 | Â Â Â Â Â Â Â Â } |
---|
1827 | Â Â Â Â Â Â Â } |
---|
1828 | Â Â Â Â Â Â } |
---|
1829 | Â Â Â Â Â } |
---|
1830 | Â Â Â Â } |
---|
1831 | Â Â Â Â nTotalFixed +=Â nFixed; |
---|
1832 | Â Â Â Â jLayer +=Â 100; |
---|
1833 | Â Â Â } |
---|
1834 | Â Â Â printf("This fixes %d variables in lower priorities\n",nTotalFixed); |
---|
1835 |    if (iLargest<0) |
---|
1836 | Â Â Â Â break; |
---|
1837 |    double movement; |
---|
1838 |    int way; |
---|
1839 |    if (smallest<=1.0-largest&&smallest<0.2) { |
---|
1840 | Â Â Â Â columnUpper[iSmallest]=0.0; |
---|
1841 | Â Â Â Â state[iSmallest]=0; |
---|
1842 | Â Â Â Â movement=smallest; |
---|
1843 | Â Â Â Â way=-1; |
---|
1844 |    } else { |
---|
1845 | Â Â Â Â columnLower[iLargest]=1.0; |
---|
1846 | Â Â Â Â state[iLargest]=1; |
---|
1847 | Â Â Â Â movement=1.0-largest; |
---|
1848 | Â Â Â Â way=1; |
---|
1849 | Â Â Â } |
---|
1850 |    double saveObj = lpSolver->objectiveValue(); |
---|
1851 | Â Â Â iPass++; |
---|
1852 | Â Â Â kPass =Â iPass%MAXPROB; |
---|
1853 | Â Â Â models[kPass]=*lpSolver; |
---|
1854 |    if (way==-1) { |
---|
1855 | Â Â Â Â // fix others |
---|
1856 |     for (int i=fixColumn[iSmallest];i<fixColumn[iSmallest+1];i++) { |
---|
1857 |      int jColumn=otherColumn[i]; |
---|
1858 |      if (state[jColumn]==-1) { |
---|
1859 | Â Â Â Â Â Â columnUpper[jColumn]=0.0; |
---|
1860 | Â Â Â Â Â Â state[jColumn]=3; |
---|
1861 | Â Â Â Â Â } |
---|
1862 | Â Â Â Â } |
---|
1863 | Â Â Â } |
---|
1864 | Â Â Â pass[kPass]=iPass; |
---|
1865 |    double maxCostUp = COIN_DBL_MAX; |
---|
1866 | Â Â Â objective =Â lpSolver->getObjCoefficients()Â ; |
---|
1867 |    if (way==-1) |
---|
1868 | Â Â Â Â maxCostUp=Â (1.0-movement)*objective[iSmallest]; |
---|
1869 | Â Â Â lpSolver->setDualObjectiveLimit(saveObj+maxCostUp); |
---|
1870 | Â Â Â crunchIt(lpSolver); |
---|
1871 |    double moveObj = lpSolver->objectiveValue()-saveObj; |
---|
1872 | Â Â Â printf("movement %s was %g costing %g\n", |
---|
1873 |        (smallest<=1.0-largest) ? "down" : "up",movement,moveObj); |
---|
1874 |    if (way==-1&&(moveObj>=(1.0-movement)*objective[iSmallest]||lpSolver->status())) { |
---|
1875 | Â Â Â Â // go up |
---|
1876 | Â Â Â Â columnLower =Â models[kPass].columnLower(); |
---|
1877 | Â Â Â Â columnUpper =Â models[kPass].columnUpper(); |
---|
1878 | Â Â Â Â columnLower[iSmallest]=1.0; |
---|
1879 | Â Â Â Â columnUpper[iSmallest]=saveColumnUpper[iSmallest]; |
---|
1880 | Â Â Â Â *lpSolver=models[kPass]; |
---|
1881 | Â Â Â Â columnLower =Â lpSolver->columnLower(); |
---|
1882 | Â Â Â Â columnUpper =Â lpSolver->columnUpper(); |
---|
1883 | Â Â Â Â fullSolution =Â lpSolver->primalColumnSolution(); |
---|
1884 | Â Â Â Â dj =Â lpSolver->dualColumnSolution(); |
---|
1885 | Â Â Â Â columnLower[iSmallest]=1.0; |
---|
1886 | Â Â Â Â columnUpper[iSmallest]=saveColumnUpper[iSmallest]; |
---|
1887 | Â Â Â Â state[iSmallest]=1; |
---|
1888 | Â Â Â Â // unfix others |
---|
1889 |     for (int i=fixColumn[iSmallest];i<fixColumn[iSmallest+1];i++) { |
---|
1890 |      int jColumn=otherColumn[i]; |
---|
1891 |      if (state[jColumn]==3) { |
---|
1892 | Â Â Â Â Â Â columnUpper[jColumn]=saveColumnUpper[jColumn]; |
---|
1893 | Â Â Â Â Â Â state[jColumn]=-1; |
---|
1894 | Â Â Â Â Â } |
---|
1895 | Â Â Â Â } |
---|
1896 | Â Â Â Â crunchIt(lpSolver); |
---|
1897 | Â Â Â } |
---|
1898 | Â Â Â models[kPass]=*lpSolver; |
---|
1899 | Â Â } |
---|
1900 | Â Â lpSolver->dual(); |
---|
1901 | Â Â printf("Fixing took %g seconds\n",CoinCpuTime()-time1); |
---|
1902 | Â Â columnLower =Â lpSolver->columnLower(); |
---|
1903 | Â Â columnUpper =Â lpSolver->columnUpper(); |
---|
1904 | Â Â fullSolution =Â lpSolver->primalColumnSolution(); |
---|
1905 | Â Â dj =Â lpSolver->dualColumnSolution(); |
---|
1906 |   int * sort = new int[numberColumns]; |
---|
1907 |   double * dsort = new double[numberColumns]; |
---|
1908 |   int chunk=20; |
---|
1909 |   int iRelax=0; |
---|
1910 | Â Â //double fractionFixed=6.0/8.0; |
---|
1911 | Â Â // relax while lots fixed |
---|
1912 |   while (true) { |
---|
1913 |    if (skipZero2>10&&doAction<10) |
---|
1914 | Â Â Â Â break; |
---|
1915 | Â Â Â iRelax++; |
---|
1916 |    int n=0; |
---|
1917 |    double sum0=0.0; |
---|
1918 |    double sum00=0.0; |
---|
1919 |    double sum1=0.0; |
---|
1920 |    for ( iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
1921 |     if (!clpSolver->isInteger(iColumn)||fix[iColumn]>kLayer) |
---|
1922 | Â Â Â Â Â continue; |
---|
1923 | Â Â Â Â // skip if fixes nothing |
---|
1924 |     if (fixColumn[iColumn+1]-fixColumn[iColumn]==0&&doAction<10) |
---|
1925 | Â Â Â Â Â continue; |
---|
1926 |     double djValue = dj[iColumn]; |
---|
1927 |     if (state[iColumn]==1) { |
---|
1928 | Â Â Â Â Â assert (columnLower[iColumn]); |
---|
1929 | Â Â Â Â Â assert (fullSolution[iColumn]>0.1); |
---|
1930 |      if (djValue>0.0) { |
---|
1931 | Â Â Â Â Â Â //printf("YY dj of %d at %g is %g\n",iColumn,value,djValue); |
---|
1932 | Â Â Â Â Â Â sum1 +=Â djValue; |
---|
1933 | Â Â Â Â Â Â sort[n]=iColumn; |
---|
1934 | Â Â Â Â Â Â dsort[n++]=-djValue; |
---|
1935 |      } else { |
---|
1936 | Â Â Â Â Â Â //printf("dj of %d at %g is %g\n",iColumn,value,djValue); |
---|
1937 | Â Â Â Â Â } |
---|
1938 |     } else if (state[iColumn]==0||state[iColumn]==10) { |
---|
1939 | Â Â Â Â Â assert (fullSolution[iColumn]<0.1); |
---|
1940 | Â Â Â Â Â assert (!columnUpper[iColumn]); |
---|
1941 |      double otherValue=0.0; |
---|
1942 |      int nn=0; |
---|
1943 |      for (int i=fixColumn[iColumn];i<fixColumn[iColumn+1];i++) { |
---|
1944 |       int jColumn=otherColumn[i]; |
---|
1945 |       if (columnUpper[jColumn]==0.0) { |
---|
1946 |        if (dj[jColumn]<-1.0e-5) { |
---|
1947 | Â Â Â Â Â Â Â Â nn++; |
---|
1948 | Â Â Â Â Â Â Â Â otherValue +=Â dj[jColumn];Â // really need to look at rest |
---|
1949 | Â Â Â Â Â Â Â } |
---|
1950 | Â Â Â Â Â Â } |
---|
1951 | Â Â Â Â Â } |
---|
1952 |      if (djValue<-1.0e-2||otherValue<-1.0e-2) { |
---|
1953 | Â Â Â Â Â Â //printf("XX dj of %d at %g is %g - %d out of %d contribute %g\n",iColumn,value,djValue, |
---|
1954 | Â Â Â Â Â Â // nn,fixColumn[iColumn+1]-fixColumn[iColumn],otherValue); |
---|
1955 |       if (djValue<1.0e-8) { |
---|
1956 | Â Â Â Â Â Â Â sum0 -=Â djValue; |
---|
1957 | Â Â Â Â Â Â Â sum00 -=Â otherValue; |
---|
1958 | Â Â Â Â Â Â Â sort[n]=iColumn; |
---|
1959 |        if (djValue<-1.0e-2) |
---|
1960 | Â Â Â Â Â Â Â Â dsort[n++]=djValue+otherValue; |
---|
1961 | Â Â Â Â Â Â Â else |
---|
1962 | Â Â Â Â Â Â Â Â dsort[n++]=djValue+0.001*otherValue; |
---|
1963 | Â Â Â Â Â Â } |
---|
1964 |      } else { |
---|
1965 | Â Â Â Â Â Â //printf("dj of %d at %g is %g - no contribution from %d\n",iColumn,value,djValue, |
---|
1966 | Â Â Â Â Â Â //Â Â fixColumn[iColumn+1]-fixColumn[iColumn]); |
---|
1967 | Â Â Â Â Â } |
---|
1968 | Â Â Â Â } |
---|
1969 | Â Â Â } |
---|
1970 | Â Â Â CoinSort_2(dsort,dsort+n,sort); |
---|
1971 |    double * originalColumnLower = saveColumnLower; |
---|
1972 |    double * originalColumnUpper = saveColumnUpper; |
---|
1973 |    double * lo = CoinCopyOfArray(columnLower,numberColumns); |
---|
1974 |    double * up = CoinCopyOfArray(columnUpper,numberColumns); |
---|
1975 |    for (int k=0;k<CoinMin(chunk,n);k++) { |
---|
1976 | Â Â Â Â iColumn =Â sort[k]; |
---|
1977 | Â Â Â Â state[iColumn]=-2; |
---|
1978 | Â Â Â } |
---|
1979 | Â Â Â memcpy(columnLower,originalColumnLower,numberColumns*sizeof(double)); |
---|
1980 | Â Â Â memcpy(columnUpper,originalColumnUpper,numberColumns*sizeof(double)); |
---|
1981 |    int nFixed=0; |
---|
1982 |    int nFixed0=0; |
---|
1983 |    int nFixed1=0; |
---|
1984 |    for ( iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
1985 |     if (state[iColumn]==0||state[iColumn]==10) { |
---|
1986 | Â Â Â Â Â columnUpper[iColumn]=0.0; |
---|
1987 | Â Â Â Â Â assert (lo[iColumn]==0.0); |
---|
1988 | Â Â Â Â Â nFixed++; |
---|
1989 | Â Â Â Â Â nFixed0++; |
---|
1990 |      for (int i=fixColumn[iColumn];i<fixColumn[iColumn+1];i++) { |
---|
1991 |       int jColumn=otherColumn[i]; |
---|
1992 |       if (columnUpper[jColumn]) { |
---|
1993 |        bool canFix=true; |
---|
1994 |        for (int k=fixColumn2[jColumn];k<fixColumn2[jColumn+1];k++) { |
---|
1995 |         int kColumn=otherColumn2[k]; |
---|
1996 |         if (state[kColumn]==1||state[kColumn]==-2) { |
---|
1997 | Â Â Â Â Â Â Â Â Â canFix=false; |
---|
1998 | Â Â Â Â Â Â Â Â Â break; |
---|
1999 | Â Â Â Â Â Â Â Â } |
---|
2000 | Â Â Â Â Â Â Â } |
---|
2001 |        if (canFix) { |
---|
2002 | Â Â Â Â Â Â Â Â columnUpper[jColumn]=0.0; |
---|
2003 | Â Â Â Â Â Â Â Â assert (lo[jColumn]==0.0); |
---|
2004 | Â Â Â Â Â Â Â Â nFixed++; |
---|
2005 | Â Â Â Â Â Â Â } |
---|
2006 | Â Â Â Â Â Â } |
---|
2007 | Â Â Â Â Â } |
---|
2008 |     } else if (state[iColumn]==1) { |
---|
2009 | Â Â Â Â Â columnLower[iColumn]=1.0; |
---|
2010 | Â Â Â Â Â nFixed1++; |
---|
2011 | Â Â Â Â } |
---|
2012 | Â Â Â } |
---|
2013 | Â Â Â printf("%d fixed %d orig 0 %d 1\n",nFixed,nFixed0,nFixed1); |
---|
2014 |    int jLayer=0; |
---|
2015 | Â Â Â nFixed=-1; |
---|
2016 |    int nTotalFixed=0; |
---|
2017 |    while (nFixed) { |
---|
2018 | Â Â Â Â nFixed=0; |
---|
2019 |     for ( iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
2020 |      if (columnUpper[iColumn]==0.0&&fix[iColumn]==jLayer) { |
---|
2021 |       for (int i=fixColumn[iColumn];i<fixColumn[iColumn+1];i++) { |
---|
2022 |        int jColumn=otherColumn[i]; |
---|
2023 |        if (columnUpper[jColumn]) { |
---|
2024 |         bool canFix=true; |
---|
2025 |         for (int k=fixColumn2[jColumn];k<fixColumn2[jColumn+1];k++) { |
---|
2026 |          int kColumn=otherColumn2[k]; |
---|
2027 |          if (state[kColumn]==1||state[kColumn]==-2) { |
---|
2028 | Â Â Â Â Â Â Â Â Â Â canFix=false; |
---|
2029 | Â Â Â Â Â Â Â Â Â Â break; |
---|
2030 | Â Â Â Â Â Â Â Â Â } |
---|
2031 | Â Â Â Â Â Â Â Â } |
---|
2032 |         if (canFix) { |
---|
2033 | Â Â Â Â Â Â Â Â Â columnUpper[jColumn]=0.0; |
---|
2034 | Â Â Â Â Â Â Â Â Â assert (lo[jColumn]==0.0); |
---|
2035 | Â Â Â Â Â Â Â Â Â nFixed++; |
---|
2036 | Â Â Â Â Â Â Â Â } |
---|
2037 | Â Â Â Â Â Â Â } |
---|
2038 | Â Â Â Â Â Â } |
---|
2039 | Â Â Â Â Â } |
---|
2040 | Â Â Â Â } |
---|
2041 | Â Â Â Â nTotalFixed +=Â nFixed; |
---|
2042 | Â Â Â Â jLayer +=Â 100; |
---|
2043 | Â Â Â } |
---|
2044 | Â Â Â nFixed=0; |
---|
2045 |    int nFixedI=0; |
---|
2046 |    for ( iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
2047 |     if (columnLower[iColumn]==columnUpper[iColumn]) { |
---|
2048 |      if (clpSolver->isInteger(iColumn)) |
---|
2049 | Â Â Â Â Â Â nFixedI++; |
---|
2050 | Â Â Â Â Â nFixed++; |
---|
2051 | Â Â Â Â } |
---|
2052 | Â Â Â } |
---|
2053 | Â Â Â printf("This fixes %d variables in lower priorities - total %d (%d integer) - all target %d, int target %d\n", |
---|
2054 | Â Â Â Â Â Â Â nTotalFixed,nFixed,nFixedI,(int)(fractionFixed*numberColumns),(int)Â (fractionIntFixed*numberInteger)); |
---|
2055 |    int nBad=0; |
---|
2056 |    int nRelax=0; |
---|
2057 |    for ( iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
2058 |     if (lo[iColumn]<columnLower[iColumn]|| |
---|
2059 | Â Â Â Â Â Â up[iColumn]>columnUpper[iColumn])Â { |
---|
2060 | Â Â Â Â Â printf("bad %d old %g %g, new %g %g\n",iColumn,lo[iColumn],up[iColumn], |
---|
2061 | Â Â Â Â Â Â Â Â Â columnLower[iColumn],columnUpper[iColumn]); |
---|
2062 | Â Â Â Â Â nBad++; |
---|
2063 | Â Â Â Â } |
---|
2064 |     if (lo[iColumn]>columnLower[iColumn]|| |
---|
2065 | Â Â Â Â Â Â up[iColumn]<columnUpper[iColumn])Â { |
---|
2066 | Â Â Â Â Â nRelax++; |
---|
2067 | Â Â Â Â } |
---|
2068 | Â Â Â } |
---|
2069 | Â Â Â printf("%d relaxed\n",nRelax); |
---|
2070 |    if (iRelax>20&&nRelax==chunk) |
---|
2071 | Â Â Â Â nRelax=0; |
---|
2072 |    if (iRelax>50) |
---|
2073 | Â Â Â Â nRelax=0; |
---|
2074 | Â Â Â assert (!nBad); |
---|
2075 |    delete [] lo; |
---|
2076 |    delete [] up; |
---|
2077 | Â Â Â lpSolver->primal(1); |
---|
2078 |    if (nFixed<fractionFixed*numberColumns||nFixedI<fractionIntFixed*numberInteger||!nRelax) |
---|
2079 | Â Â Â Â break; |
---|
2080 | Â Â } |
---|
2081 |   delete [] state; |
---|
2082 |   delete [] sort; |
---|
2083 |   delete [] dsort; |
---|
2084 | Â } |
---|
2085 |  delete [] fix; |
---|
2086 |  delete [] fixColumn; |
---|
2087 |  delete [] otherColumn; |
---|
2088 |  delete [] otherColumn2; |
---|
2089 |  delete [] fixColumn2; |
---|
2090 | Â // See if was presolved |
---|
2091 |  if (originalColumns) { |
---|
2092 | Â Â columnLower =Â lpSolver->columnLower(); |
---|
2093 | Â Â columnUpper =Â lpSolver->columnUpper(); |
---|
2094 |   for ( iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
2095 | Â Â Â saveColumnLower[iColumn]Â =Â columnLower[iColumn]; |
---|
2096 | Â Â Â saveColumnUpper[iColumn]Â =Â columnUpper[iColumn]; |
---|
2097 | Â Â } |
---|
2098 | Â Â pinfo.postsolve(true); |
---|
2099 | Â Â columnLower =Â originalLpSolver->columnLower(); |
---|
2100 | Â Â columnUpper =Â originalLpSolver->columnUpper(); |
---|
2101 |   double * newColumnLower = lpSolver->columnLower(); |
---|
2102 |   double * newColumnUpper = lpSolver->columnUpper(); |
---|
2103 |   for (iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
2104 |    int jColumn = originalColumns[iColumn]; |
---|
2105 | Â Â Â columnLower[jColumn]Â =Â CoinMax(columnLower[jColumn],newColumnLower[iColumn]); |
---|
2106 | Â Â Â columnUpper[jColumn]Â =Â CoinMin(columnUpper[jColumn],newColumnUpper[iColumn]); |
---|
2107 | Â Â } |
---|
2108 | Â Â numberColumns =Â originalLpSolver->numberColumns(); |
---|
2109 |   delete [] originalColumns; |
---|
2110 | Â } |
---|
2111 |  delete [] saveColumnLower; |
---|
2112 |  delete [] saveColumnUpper; |
---|
2113 |  if (!originalColumns) { |
---|
2114 | Â Â // Basis |
---|
2115 | Â Â memcpy(originalLpSolver->statusArray(),lpSolver->statusArray(),numberRows+numberColumns); |
---|
2116 | Â Â memcpy(originalLpSolver->primalColumnSolution(),lpSolver->primalColumnSolution(),numberColumns*sizeof(double)); |
---|
2117 | Â Â memcpy(originalLpSolver->primalRowSolution(),lpSolver->primalRowSolution(),numberRows*sizeof(double)); |
---|
2118 | Â Â // Fix in solver |
---|
2119 | Â Â columnLower =Â lpSolver->columnLower(); |
---|
2120 | Â Â columnUpper =Â lpSolver->columnUpper(); |
---|
2121 | Â } |
---|
2122 |  double * originalColumnLower = originalLpSolver->columnLower(); |
---|
2123 |  double * originalColumnUpper = originalLpSolver->columnUpper(); |
---|
2124 | Â // number fixed |
---|
2125 | Â doAction=0; |
---|
2126 |  for ( iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
2127 | Â Â originalColumnLower[iColumn]Â =Â columnLower[iColumn]; |
---|
2128 | Â Â originalColumnUpper[iColumn]Â =Â columnUpper[iColumn]; |
---|
2129 |   if (columnLower[iColumn]==columnUpper[iColumn]) |
---|
2130 | Â Â Â doAction++; |
---|
2131 | Â } |
---|
2132 | Â printf("%d fixed by vub preprocessing\n",doAction); |
---|
2133 |  if (originalColumns) { |
---|
2134 | Â Â originalLpSolver->initialSolve(); |
---|
2135 | Â } |
---|
2136 |  delete clpSolver; |
---|
2137 |  return NULL; |
---|
2138 | } |
---|
2139 | #endif |
---|
2140 | #ifdef COIN_HAS_LINK |
---|
2141 | /*Â Returns OsiSolverInterface (User should delete) |
---|
2142 | Â Â On entry numberKnapsack is maximum number of Total entries |
---|
2143 | */ |
---|
2144 | static OsiSolverInterface * |
---|
2145 | expandKnapsack(CoinModel & model, int * whichColumn, int * knapsackStart, |
---|
2146 |         int * knapsackRow, int &numberKnapsack, |
---|
2147 |         CglStored & stored, int logLevel, |
---|
2148 |         int fixedPriority, int SOSPriority,CoinModel & tightenedModel) |
---|
2149 | { |
---|
2150 |  int maxTotal = numberKnapsack; |
---|
2151 | Â // load from coin model |
---|
2152 |  OsiSolverLink *si = new OsiSolverLink(); |
---|
2153 | Â OsiSolverInterface *Â finalModel=NULL; |
---|
2154 | Â si->setDefaultMeshSize(0.001); |
---|
2155 | Â // need some relative granularity |
---|
2156 | Â si->setDefaultBound(100.0); |
---|
2157 | Â si->setDefaultMeshSize(0.01); |
---|
2158 | Â si->setDefaultBound(100000.0); |
---|
2159 | Â si->setIntegerPriority(1000); |
---|
2160 | Â si->setBiLinearPriority(10000); |
---|
2161 | Â si->load(model,true,logLevel); |
---|
2162 | Â // get priorities |
---|
2163 |  const int * priorities=model.priorities(); |
---|
2164 |  int numberColumns = model.numberColumns(); |
---|
2165 |  if (priorities) { |
---|
2166 | Â Â OsiObject **Â objects =Â si->objects(); |
---|
2167 |   int numberObjects = si->numberObjects(); |
---|
2168 |   for (int iObj = 0;iObj<numberObjects;iObj++) { |
---|
2169 |    int iColumn = objects[iObj]->columnNumber(); |
---|
2170 |    if (iColumn>=0&&iColumn<numberColumns) { |
---|
2171 | #ifndef NDEBUG |
---|
2172 | Â Â Â Â OsiSimpleInteger *Â obj = |
---|
2173 |      dynamic_cast <OsiSimpleInteger *>(objects[iObj]) ; |
---|
2174 | #endif |
---|
2175 | Â Â Â Â assert (obj); |
---|
2176 |     int iPriority = priorities[iColumn]; |
---|
2177 |     if (iPriority>0) |
---|
2178 | Â Â Â Â Â objects[iObj]->setPriority(iPriority); |
---|
2179 | Â Â Â } |
---|
2180 | Â Â } |
---|
2181 |   if (fixedPriority>0) { |
---|
2182 | Â Â Â si->setFixedPriority(fixedPriority); |
---|
2183 | Â Â } |
---|
2184 |   if (SOSPriority<0) |
---|
2185 | Â Â Â SOSPriority=100000; |
---|
2186 | Â }Â |
---|
2187 | Â CoinModel coinModel=*si->coinModel(); |
---|
2188 | Â assert(coinModel.numberRows()>0); |
---|
2189 | Â tightenedModel =Â coinModel; |
---|
2190 |  int numberRows = coinModel.numberRows(); |
---|
2191 | Â // Mark variables |
---|
2192 |  int * whichKnapsack = new int [numberColumns]; |
---|
2193 |  int iRow,iColumn; |
---|
2194 |  for (iColumn=0;iColumn<numberColumns;iColumn++) |
---|
2195 | Â Â whichKnapsack[iColumn]=-1; |
---|
2196 |  int kRow; |
---|
2197 |  bool badModel=false; |
---|
2198 | Â // analyze |
---|
2199 |  if (logLevel>1) { |
---|
2200 |   for (iRow=0;iRow<numberRows;iRow++) { |
---|
2201 | Â Â Â /* Just obvious one at first |
---|
2202 | Â Â Â Â Â positive non unit coefficients |
---|
2203 | Â Â Â Â Â all integer |
---|
2204 | Â Â Â Â Â positive rowUpper |
---|
2205 | Â Â Â Â Â for now - linear (but further down in code may use nonlinear) |
---|
2206 | Â Â Â Â Â column bounds should be tight |
---|
2207 | Â Â Â */ |
---|
2208 | Â Â Â //double lower = coinModel.getRowLower(iRow); |
---|
2209 |    double upper = coinModel.getRowUpper(iRow); |
---|
2210 |    if (upper<1.0e10) { |
---|
2211 | Â Â Â Â CoinModelLink triple=coinModel.firstInRow(iRow); |
---|
2212 |     bool possible=true; |
---|
2213 |     int n=0; |
---|
2214 |     int n1=0; |
---|
2215 |     while (triple.column()>=0) { |
---|
2216 |      int iColumn = triple.column(); |
---|
2217 |      const char * el = coinModel.getElementAsString(iRow,iColumn); |
---|
2218 |      if (!strcmp("Numeric",el)) { |
---|
2219 |       if (coinModel.columnLower(iColumn)==coinModel.columnUpper(iColumn)) { |
---|
2220 | Â Â Â Â Â Â Â triple=coinModel.next(triple); |
---|
2221 | Â Â Â Â Â Â Â continue;Â // fixed |
---|
2222 | Â Â Â Â Â Â } |
---|
2223 |       double value=coinModel.getElement(iRow,iColumn); |
---|
2224 |       if (value<0.0) { |
---|
2225 | Â Â Â Â Â Â Â possible=false; |
---|
2226 |       } else { |
---|
2227 | Â Â Â Â Â Â Â n++; |
---|
2228 |        if (value==1.0) |
---|
2229 | Â Â Â Â Â Â Â Â n1++; |
---|
2230 |        if (coinModel.columnLower(iColumn)<0.0) |
---|
2231 | Â Â Â Â Â Â Â Â possible=false; |
---|
2232 |        if (!coinModel.isInteger(iColumn)) |
---|
2233 | Â Â Â Â Â Â Â Â possible=false; |
---|
2234 |        if (whichKnapsack[iColumn]>=0) |
---|
2235 | Â Â Â Â Â Â Â Â possible=false; |
---|
2236 | Â Â Â Â Â Â } |
---|
2237 |      } else { |
---|
2238 | Â Â Â Â Â Â possible=false;Â // non linear |
---|
2239 | Â Â Â Â Â }Â |
---|
2240 | Â Â Â Â Â triple=coinModel.next(triple); |
---|
2241 | Â Â Â Â } |
---|
2242 |     if (n-n1>1&&possible) { |
---|
2243 |      double lower = coinModel.getRowLower(iRow); |
---|
2244 |      double upper = coinModel.getRowUpper(iRow); |
---|
2245 | Â Â Â Â Â CoinModelLink triple=coinModel.firstInRow(iRow); |
---|
2246 |      while (triple.column()>=0) { |
---|
2247 |       int iColumn = triple.column(); |
---|
2248 | Â Â Â Â Â Â lower -=Â coinModel.columnLower(iColumn)*triple.value(); |
---|
2249 | Â Â Â Â Â Â upper -=Â coinModel.columnLower(iColumn)*triple.value(); |
---|
2250 | Â Â Â Â Â Â triple=coinModel.next(triple); |
---|
2251 | Â Â Â Â Â } |
---|
2252 | Â Â Â Â Â printf("%d is possible %g <=",iRow,lower); |
---|
2253 | Â Â Â Â Â // print |
---|
2254 | Â Â Â Â Â triple=coinModel.firstInRow(iRow); |
---|
2255 |      while (triple.column()>=0) { |
---|
2256 |       int iColumn = triple.column(); |
---|
2257 |       if (coinModel.columnLower(iColumn)!=coinModel.columnUpper(iColumn)) |
---|
2258 | Â Â Â Â Â Â Â printf(" (%d,el %g up %g)",iColumn,triple.value(), |
---|
2259 | Â Â Â Â Â Â Â Â Â Â Â coinModel.columnUpper(iColumn)-coinModel.columnLower(iColumn)); |
---|
2260 | Â Â Â Â Â Â triple=coinModel.next(triple); |
---|
2261 | Â Â Â Â Â } |
---|
2262 | Â Â Â Â Â printf(" <= %g\n",upper); |
---|
2263 | Â Â Â Â } |
---|
2264 | Â Â Â } |
---|
2265 | Â Â } |
---|
2266 | Â } |
---|
2267 | Â numberKnapsack=0; |
---|
2268 |  for (kRow=0;kRow<numberRows;kRow++) { |
---|
2269 | Â Â iRow=kRow; |
---|
2270 | Â Â /* Just obvious one at first |
---|
2271 | Â Â Â Â positive non unit coefficients |
---|
2272 | Â Â Â Â all integer |
---|
2273 | Â Â Â Â positive rowUpper |
---|
2274 | Â Â Â Â for now - linear (but further down in code may use nonlinear) |
---|
2275 | Â Â Â Â column bounds should be tight |
---|
2276 | Â Â */ |
---|
2277 | Â Â //double lower = coinModel.getRowLower(iRow); |
---|
2278 |   double upper = coinModel.getRowUpper(iRow); |
---|
2279 |   if (upper<1.0e10) { |
---|
2280 | Â Â Â CoinModelLink triple=coinModel.firstInRow(iRow); |
---|
2281 |    bool possible=true; |
---|
2282 |    int n=0; |
---|
2283 |    int n1=0; |
---|
2284 |    while (triple.column()>=0) { |
---|
2285 |     int iColumn = triple.column(); |
---|
2286 |     const char * el = coinModel.getElementAsString(iRow,iColumn); |
---|
2287 |     if (!strcmp("Numeric",el)) { |
---|
2288 |      if (coinModel.columnLower(iColumn)==coinModel.columnUpper(iColumn)) { |
---|
2289 | Â Â Â Â Â Â triple=coinModel.next(triple); |
---|
2290 | Â Â Â Â Â Â continue;Â // fixed |
---|
2291 | Â Â Â Â Â } |
---|
2292 |      double value=coinModel.getElement(iRow,iColumn); |
---|
2293 |      if (value<0.0) { |
---|
2294 | Â Â Â Â Â Â possible=false; |
---|
2295 |      } else { |
---|
2296 | Â Â Â Â Â Â n++; |
---|
2297 |       if (value==1.0) |
---|
2298 | Â Â Â Â Â Â Â n1++; |
---|
2299 |       if (coinModel.columnLower(iColumn)<0.0) |
---|
2300 | Â Â Â Â Â Â Â possible=false; |
---|
2301 |       if (!coinModel.isInteger(iColumn)) |
---|
2302 | Â Â Â Â Â Â Â possible=false; |
---|
2303 |       if (whichKnapsack[iColumn]>=0) |
---|
2304 | Â Â Â Â Â Â Â possible=false; |
---|
2305 | Â Â Â Â Â } |
---|
2306 |     } else { |
---|
2307 | Â Â Â Â Â possible=false;Â // non linear |
---|
2308 | Â Â Â Â }Â |
---|
2309 | Â Â Â Â triple=coinModel.next(triple); |
---|
2310 | Â Â Â } |
---|
2311 |    if (n-n1>1&&possible) { |
---|
2312 | Â Â Â Â // try |
---|
2313 | Â Â Â Â CoinModelLink triple=coinModel.firstInRow(iRow); |
---|
2314 |     while (triple.column()>=0) { |
---|
2315 |      int iColumn = triple.column(); |
---|
2316 |      if (coinModel.columnLower(iColumn)!=coinModel.columnUpper(iColumn)) |
---|
2317 | Â Â Â Â Â Â whichKnapsack[iColumn]=numberKnapsack; |
---|
2318 | Â Â Â Â Â triple=coinModel.next(triple); |
---|
2319 | Â Â Â Â } |
---|
2320 | Â Â Â Â knapsackRow[numberKnapsack++]=iRow; |
---|
2321 | Â Â Â } |
---|
2322 | Â Â } |
---|
2323 | Â } |
---|
2324 |  if (logLevel>0) |
---|
2325 | Â Â printf("%d out of %d candidate rows are possible\n",numberKnapsack,numberRows); |
---|
2326 | Â // Check whether we can get rid of nonlinearities |
---|
2327 | Â /* mark rows |
---|
2328 | Â Â Â -2 in knapsack and other variables |
---|
2329 | Â Â Â -1 not involved |
---|
2330 | Â Â Â n only in knapsack n |
---|
2331 | Â */ |
---|
2332 |  int * markRow = new int [numberRows]; |
---|
2333 |  for (iRow=0;iRow<numberRows;iRow++) |
---|
2334 | Â Â markRow[iRow]=-1; |
---|
2335 |  int canDo=1; // OK and linear |
---|
2336 |  for (iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
2337 | Â Â CoinModelLink triple=coinModel.firstInColumn(iColumn); |
---|
2338 |   int iKnapsack = whichKnapsack[iColumn]; |
---|
2339 |   bool linear=true; |
---|
2340 | Â Â // See if quadratic objective |
---|
2341 |   const char * expr = coinModel.getColumnObjectiveAsString(iColumn); |
---|
2342 |   if (strcmp(expr,"Numeric")) { |
---|
2343 | Â Â Â linear=false; |
---|
2344 | Â Â } |
---|
2345 |   while (triple.row()>=0) { |
---|
2346 |    int iRow = triple.row(); |
---|
2347 |    if (iKnapsack>=0) { |
---|
2348 |     if (markRow[iRow]==-1) { |
---|
2349 | Â Â Â Â Â markRow[iRow]=iKnapsack; |
---|
2350 |     } else if (markRow[iRow]!=iKnapsack) { |
---|
2351 | Â Â Â Â Â markRow[iRow]=-2; |
---|
2352 | Â Â Â Â } |
---|
2353 | Â Â Â } |
---|
2354 |    const char * expr = coinModel.getElementAsString(iRow,iColumn); |
---|
2355 |    if (strcmp(expr,"Numeric")) { |
---|
2356 | Â Â Â Â linear=false; |
---|
2357 | Â Â Â } |
---|
2358 | Â Â Â triple=coinModel.next(triple); |
---|
2359 | Â Â } |
---|
2360 |   if (!linear) { |
---|
2361 |    if (whichKnapsack[iColumn]<0) { |
---|
2362 | Â Â Â Â canDo=0; |
---|
2363 | Â Â Â Â break; |
---|
2364 |    } else { |
---|
2365 | Â Â Â Â canDo=2; |
---|
2366 | Â Â Â } |
---|
2367 | Â Â } |
---|
2368 | Â } |
---|
2369 |  int * markKnapsack = NULL; |
---|
2370 |  double * coefficient = NULL; |
---|
2371 |  double * linear = NULL; |
---|
2372 |  int * whichRow = NULL; |
---|
2373 |  int * lookupRow = NULL; |
---|
2374 | Â badModel=(canDo==0); |
---|
2375 |  if (numberKnapsack&&canDo) { |
---|
2376 | Â Â /* double check - OK if |
---|
2377 | Â Â Â Â no nonlinear |
---|
2378 | Â Â Â Â nonlinear only on columns in knapsack |
---|
2379 | Â Â Â Â nonlinear only on columns in knapsack * ONE other - same for all in knapsack |
---|
2380 | Â Â Â Â AND that is only row connected to knapsack |
---|
2381 | Â Â Â Â (theoretically could split knapsack if two other and small numbers) |
---|
2382 | Â Â Â Â also ONE could be ONE expression - not just a variable |
---|
2383 | Â Â */ |
---|
2384 |   int iKnapsack; |
---|
2385 |   markKnapsack = new int [numberKnapsack]; |
---|
2386 |   coefficient = new double [numberKnapsack]; |
---|
2387 |   linear = new double [numberColumns]; |
---|
2388 |   for (iKnapsack=0;iKnapsack<numberKnapsack;iKnapsack++) |
---|
2389 | Â Â Â markKnapsack[iKnapsack]=-1; |
---|
2390 |   if (canDo==2) { |
---|
2391 |    for (iRow=-1;iRow<numberRows;iRow++) { |
---|
2392 |     int numberOdd; |
---|
2393 | Â Â Â Â CoinPackedMatrix *Â row =Â coinModel.quadraticRow(iRow,linear,numberOdd); |
---|
2394 |     if (row) { |
---|
2395 | Â Â Â Â Â // see if valid |
---|
2396 |      const double * element = row->getElements(); |
---|
2397 |      const int * column = row->getIndices(); |
---|
2398 |      const CoinBigIndex * columnStart = row->getVectorStarts(); |
---|
2399 |      const int * columnLength = row->getVectorLengths(); |
---|
2400 |      int numberLook = row->getNumCols(); |
---|
2401 |      for (int i=0;i<numberLook;i++) { |
---|
2402 |       int iKnapsack=whichKnapsack[i]; |
---|
2403 |       if (iKnapsack<0) { |
---|
2404 | Â Â Â Â Â Â Â // might be able to swap - but for now can't have knapsack in |
---|
2405 |        for (int j=columnStart[i];j<columnStart[i]+columnLength[i];j++) { |
---|
2406 |         int iColumn = column[j]; |
---|
2407 |         if (whichKnapsack[iColumn]>=0) { |
---|
2408 | Â Â Â Â Â Â Â Â Â canDo=0;Â // no good |
---|
2409 | Â Â Â Â Â Â Â Â Â badModel=true; |
---|
2410 | Â Â Â Â Â Â Â Â Â break; |
---|
2411 | Â Â Â Â Â Â Â Â } |
---|
2412 | Â Â Â Â Â Â Â } |
---|
2413 |       } else { |
---|
2414 | Â Â Â Â Â Â Â // OK if in same knapsack - or maybe just one |
---|
2415 |        int marked=markKnapsack[iKnapsack]; |
---|
2416 |        for (int j=columnStart[i];j<columnStart[i]+columnLength[i];j++) { |
---|
2417 |         int iColumn = column[j]; |
---|
2418 |         if (whichKnapsack[iColumn]!=iKnapsack&&whichKnapsack[iColumn]>=0) { |
---|
2419 | Â Â Â Â Â Â Â Â Â canDo=0;Â // no good |
---|
2420 | Â Â Â Â Â Â Â Â Â badModel=true; |
---|
2421 | Â Â Â Â Â Â Â Â Â break; |
---|
2422 |         } else if (marked==-1) { |
---|
2423 | Â Â Â Â Â Â Â Â Â markKnapsack[iKnapsack]=iColumn; |
---|
2424 | Â Â Â Â Â Â Â Â Â marked=iColumn; |
---|
2425 | Â Â Â Â Â Â Â Â Â coefficient[iKnapsack]=element[j]; |
---|
2426 | Â Â Â Â Â Â Â Â Â coinModel.associateElement(coinModel.columnName(iColumn),1.0); |
---|
2427 |         } else if (marked!=iColumn) { |
---|
2428 | Â Â Â Â Â Â Â Â Â badModel=true; |
---|
2429 | Â Â Â Â Â Â Â Â Â canDo=0;Â // no good |
---|
2430 | Â Â Â Â Â Â Â Â Â break; |
---|
2431 |         } else { |
---|
2432 | Â Â Â Â Â Â Â Â Â // could manage with different coefficients - but for now ... |
---|
2433 | Â Â Â Â Â Â Â Â Â assert(coefficient[iKnapsack]==element[j]); |
---|
2434 | Â Â Â Â Â Â Â Â } |
---|
2435 | Â Â Â Â Â Â Â } |
---|
2436 | Â Â Â Â Â Â } |
---|
2437 | Â Â Â Â Â } |
---|
2438 |      delete row; |
---|
2439 | Â Â Â Â } |
---|
2440 | Â Â Â } |
---|
2441 | Â Â } |
---|
2442 |   if (canDo) { |
---|
2443 | Â Â Â // for any rows which are cuts |
---|
2444 |    whichRow = new int [numberRows]; |
---|
2445 |    lookupRow = new int [numberRows]; |
---|
2446 |    bool someNonlinear=false; |
---|
2447 |    double maxCoefficient=1.0; |
---|
2448 |    for (iKnapsack=0;iKnapsack<numberKnapsack;iKnapsack++) { |
---|
2449 |     if (markKnapsack[iKnapsack]>=0) { |
---|
2450 | Â Â Â Â Â someNonlinear=true; |
---|
2451 |      int iColumn = markKnapsack[iKnapsack]; |
---|
2452 | Â Â Â Â Â maxCoefficient =Â CoinMax(maxCoefficient,fabs(coefficient[iKnapsack]*coinModel.columnUpper(iColumn))); |
---|
2453 | Â Â Â Â } |
---|
2454 | Â Â Â } |
---|
2455 |    if (someNonlinear) { |
---|
2456 | Â Â Â Â // associate all columns to stop possible error messages |
---|
2457 |     for (iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
2458 | Â Â Â Â Â coinModel.associateElement(coinModel.columnName(iColumn),1.0); |
---|
2459 | Â Â Â Â } |
---|
2460 | Â Â Â } |
---|
2461 | Â Â Â ClpSimplex tempModel; |
---|
2462 | Â Â Â tempModel.loadProblem(coinModel); |
---|
2463 | Â Â Â // Create final model - first without knapsacks |
---|
2464 |    int nCol=0; |
---|
2465 |    int nRow=0; |
---|
2466 |    for (iRow=0;iRow<numberRows;iRow++) { |
---|
2467 |     if (markRow[iRow]<0) { |
---|
2468 | Â Â Â Â Â lookupRow[iRow]=nRow; |
---|
2469 | Â Â Â Â Â whichRow[nRow++]=iRow; |
---|
2470 |     } else { |
---|
2471 | Â Â Â Â Â lookupRow[iRow]=-1; |
---|
2472 | Â Â Â Â } |
---|
2473 | Â Â Â } |
---|
2474 |    for (iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
2475 |     if (whichKnapsack[iColumn]<0) |
---|
2476 | Â Â Â Â Â whichColumn[nCol++]=iColumn; |
---|
2477 | Â Â Â } |
---|
2478 | Â Â Â ClpSimplex finalModelX(&tempModel,nRow,whichRow,nCol,whichColumn,false,false,false); |
---|
2479 | Â Â Â OsiClpSolverInterface finalModelY(&finalModelX,true); |
---|
2480 | Â Â Â finalModel =Â finalModelY.clone(); |
---|
2481 | Â Â Â finalModelY.releaseClp(); |
---|
2482 | Â Â Â // Put back priorities |
---|
2483 |    const int * priorities=model.priorities(); |
---|
2484 |    if (priorities) { |
---|
2485 | Â Â Â Â finalModel->findIntegers(false); |
---|
2486 | Â Â Â Â OsiObject **Â objects =Â finalModel->objects(); |
---|
2487 |     int numberObjects = finalModel->numberObjects(); |
---|
2488 |     for (int iObj = 0;iObj<numberObjects;iObj++) { |
---|
2489 |      int iColumn = objects[iObj]->columnNumber(); |
---|
2490 |      if (iColumn>=0&&iColumn<nCol) { |
---|
2491 | #ifndef NDEBUG |
---|
2492 | Â Â Â Â Â Â OsiSimpleInteger *Â obj = |
---|
2493 |        dynamic_cast <OsiSimpleInteger *>(objects[iObj]) ; |
---|
2494 | #endif |
---|
2495 | Â Â Â Â Â Â assert (obj); |
---|
2496 |       int iPriority = priorities[whichColumn[iColumn]]; |
---|
2497 |       if (iPriority>0) |
---|
2498 | Â Â Â Â Â Â Â objects[iObj]->setPriority(iPriority); |
---|
2499 | Â Â Â Â Â } |
---|
2500 | Â Â Â Â } |
---|
2501 | Â Â Â } |
---|
2502 |    for (iRow=0;iRow<numberRows;iRow++) { |
---|
2503 | Â Â Â Â whichRow[iRow]=iRow; |
---|
2504 | Â Â Â } |
---|
2505 |    int numberOther=finalModel->getNumCols(); |
---|
2506 |    int nLargest=0; |
---|
2507 |    int nelLargest=0; |
---|
2508 |    int nTotal=0; |
---|
2509 |    for (iKnapsack=0;iKnapsack<numberKnapsack;iKnapsack++) { |
---|
2510 | Â Â Â Â iRow =Â knapsackRow[iKnapsack]; |
---|
2511 |     int nCreate = maxTotal; |
---|
2512 |     int nelCreate=coinModel.expandKnapsack(iRow,nCreate,NULL,NULL,NULL,NULL); |
---|
2513 |     if (nelCreate<0) |
---|
2514 | Â Â Â Â Â badModel=true; |
---|
2515 | Â Â Â Â nTotal+=nCreate; |
---|
2516 | Â Â Â Â nLargest =Â CoinMax(nLargest,nCreate); |
---|
2517 | Â Â Â Â nelLargest =Â CoinMax(nelLargest,nelCreate); |
---|
2518 | Â Â Â } |
---|
2519 |    if (nTotal>maxTotal) |
---|
2520 | Â Â Â Â badModel=true; |
---|
2521 |    if (!badModel) { |
---|
2522 | Â Â Â Â // Now arrays for building |
---|
2523 | Â Â Â Â nelLargest =Â CoinMax(nelLargest,nLargest)+1; |
---|
2524 |     double * buildObj = new double [nLargest]; |
---|
2525 |     double * buildElement = new double [nelLargest]; |
---|
2526 |     int * buildStart = new int[nLargest+1]; |
---|
2527 |     int * buildRow = new int[nelLargest]; |
---|
2528 | Â Â Â Â // alow for integers in knapsacks |
---|
2529 |     OsiObject ** object = new OsiObject * [numberKnapsack+nTotal]; |
---|
2530 |     int nSOS=0; |
---|
2531 |     int nObj=numberKnapsack; |
---|
2532 |     for (iKnapsack=0;iKnapsack<numberKnapsack;iKnapsack++) { |
---|
2533 | Â Â Â Â Â knapsackStart[iKnapsack]=finalModel->getNumCols(); |
---|
2534 | Â Â Â Â Â iRow =Â knapsackRow[iKnapsack]; |
---|
2535 |      int nCreate = 10000; |
---|
2536 | Â Â Â Â Â coinModel.expandKnapsack(iRow,nCreate,buildObj,buildStart,buildRow,buildElement); |
---|
2537 | Â Â Â Â Â // Redo row numbers |
---|
2538 |      for (iColumn=0;iColumn<nCreate;iColumn++) { |
---|
2539 |       for (int j=buildStart[iColumn];j<buildStart[iColumn+1];j++) { |
---|
2540 |        int jRow=buildRow[j]; |
---|
2541 | Â Â Â Â Â Â Â jRow=lookupRow[jRow]; |
---|
2542 | Â Â Â Â Â Â Â assert (jRow>=0&&jRow<nRow); |
---|
2543 | Â Â Â Â Â Â Â buildRow[j]=jRow; |
---|
2544 | Â Â Â Â Â Â } |
---|
2545 | Â Â Â Â Â } |
---|
2546 | Â Â Â Â Â finalModel->addCols(nCreate,buildStart,buildRow,buildElement,NULL,NULL,buildObj); |
---|
2547 |      int numberFinal=finalModel->getNumCols(); |
---|
2548 |      for (iColumn=numberOther;iColumn<numberFinal;iColumn++) { |
---|
2549 |       if (markKnapsack[iKnapsack]<0) { |
---|
2550 | Â Â Â Â Â Â Â finalModel->setColUpper(iColumn,maxCoefficient); |
---|
2551 | Â Â Â Â Â Â Â finalModel->setInteger(iColumn); |
---|
2552 |       } else { |
---|
2553 | Â Â Â Â Â Â Â finalModel->setColUpper(iColumn,maxCoefficient+1.0); |
---|
2554 | Â Â Â Â Â Â Â finalModel->setInteger(iColumn); |
---|
2555 | Â Â Â Â Â Â } |
---|
2556 |       OsiSimpleInteger * sosObject = new OsiSimpleInteger(finalModel,iColumn); |
---|
2557 | Â Â Â Â Â Â sosObject->setPriority(1000000); |
---|
2558 | Â Â Â Â Â Â object[nObj++]=sosObject; |
---|
2559 | Â Â Â Â Â Â buildRow[iColumn-numberOther]=iColumn; |
---|
2560 | Â Â Â Â Â Â buildElement[iColumn-numberOther]=1.0; |
---|
2561 | Â Â Â Â Â } |
---|
2562 |      if (markKnapsack[iKnapsack]<0) { |
---|
2563 | Â Â Â Â Â Â // convexity row |
---|
2564 | Â Â Â Â Â Â finalModel->addRow(numberFinal-numberOther,buildRow,buildElement,1.0,1.0); |
---|
2565 |      } else { |
---|
2566 |       int iColumn = markKnapsack[iKnapsack]; |
---|
2567 |       int n=numberFinal-numberOther; |
---|
2568 | Â Â Â Â Â Â buildRow[n]=iColumn; |
---|
2569 | Â Â Â Â Â Â buildElement[n++]=-fabs(coefficient[iKnapsack]); |
---|
2570 | Â Â Â Â Â Â // convexity row (sort of) |
---|
2571 | Â Â Â Â Â Â finalModel->addRow(n,buildRow,buildElement,0.0,0.0); |
---|
2572 |       OsiSOS * sosObject = new OsiSOS(finalModel,n-1,buildRow,NULL,1); |
---|
2573 | Â Â Â Â Â Â sosObject->setPriority(iKnapsack+SOSPriority); |
---|
2574 | Â Â Â Â Â Â // Say not integral even if is (switch off heuristics) |
---|
2575 | Â Â Â Â Â Â sosObject->setIntegerValued(false); |
---|
2576 | Â Â Â Â Â Â object[nSOS++]=sosObject; |
---|
2577 | Â Â Â Â Â } |
---|
2578 | Â Â Â Â Â numberOther=numberFinal; |
---|
2579 | Â Â Â Â } |
---|
2580 | Â Â Â Â finalModel->addObjects(nObj,object); |
---|
2581 |     for (iKnapsack=0;iKnapsack<nObj;iKnapsack++) |
---|
2582 |      delete object[iKnapsack]; |
---|
2583 |     delete [] object; |
---|
2584 | Â Â Â Â // Can we move any rows to cuts |
---|
2585 |     const int * cutMarker = coinModel.cutMarker(); |
---|
2586 |     if (cutMarker&&0) { |
---|
2587 | Â Â Â Â Â printf("AMPL CUTS OFF until global cuts fixed\n"); |
---|
2588 | Â Â Â Â Â cutMarker=NULL; |
---|
2589 | Â Â Â Â } |
---|
2590 |     if (cutMarker) { |
---|
2591 | Â Â Â Â Â // Row copy |
---|
2592 |      const CoinPackedMatrix * matrixByRow = finalModel->getMatrixByRow(); |
---|
2593 |      const double * elementByRow = matrixByRow->getElements(); |
---|
2594 |      const int * column = matrixByRow->getIndices(); |
---|
2595 |      const CoinBigIndex * rowStart = matrixByRow->getVectorStarts(); |
---|
2596 |      const int * rowLength = matrixByRow->getVectorLengths(); |
---|
2597 | Â Â Â Â Â |
---|
2598 |      const double * rowLower = finalModel->getRowLower(); |
---|
2599 |      const double * rowUpper = finalModel->getRowUpper(); |
---|
2600 |      int nDelete=0; |
---|
2601 |      for (iRow=0;iRow<numberRows;iRow++) { |
---|
2602 |       if (cutMarker[iRow]&&lookupRow[iRow]>=0) { |
---|
2603 |        int jRow=lookupRow[iRow]; |
---|
2604 | Â Â Â Â Â Â Â whichRow[nDelete++]=jRow; |
---|
2605 |        int start = rowStart[jRow]; |
---|
2606 | Â Â Â Â Â Â Â stored.addCut(rowLower[jRow],rowUpper[jRow], |
---|
2607 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â rowLength[jRow],column+start,elementByRow+start); |
---|
2608 | Â Â Â Â Â Â } |
---|
2609 | Â Â Â Â Â } |
---|
2610 | Â Â Â Â Â finalModel->deleteRows(nDelete,whichRow); |
---|
2611 | Â Â Â Â } |
---|
2612 | Â Â Â Â knapsackStart[numberKnapsack]=finalModel->getNumCols(); |
---|
2613 |     delete [] buildObj; |
---|
2614 |     delete [] buildElement; |
---|
2615 |     delete [] buildStart; |
---|
2616 |     delete [] buildRow; |
---|
2617 | Â Â Â Â finalModel->writeMps("full"); |
---|
2618 | Â Â Â } |
---|
2619 | Â Â } |
---|
2620 | Â } |
---|
2621 |  delete [] whichKnapsack; |
---|
2622 |  delete [] markRow; |
---|
2623 |  delete [] markKnapsack; |
---|
2624 |  delete [] coefficient; |
---|
2625 |  delete [] linear; |
---|
2626 |  delete [] whichRow; |
---|
2627 |  delete [] lookupRow; |
---|
2628 |  delete si; |
---|
2629 | Â si=NULL; |
---|
2630 |  if (!badModel&&finalModel) { |
---|
2631 | Â Â finalModel->setDblParam(OsiObjOffset,coinModel.objectiveOffset()); |
---|
2632 |   return finalModel; |
---|
2633 |  } else { |
---|
2634 |   delete finalModel; |
---|
2635 | Â Â printf("can't make knapsacks - did you set fixedPriority (extra1)\n"); |
---|
2636 |   return NULL; |
---|
2637 | Â } |
---|
2638 | } |
---|
2639 | // Fills in original solution (coinModel length) |
---|
2640 | static void |
---|
2641 | afterKnapsack(const CoinModel & coinModel2, const int * whichColumn, const int * knapsackStart, |
---|
2642 |           const int * knapsackRow, int numberKnapsack, |
---|
2643 |           const double * knapsackSolution, double * solution, int logLevel) |
---|
2644 | { |
---|
2645 | Â CoinModel coinModel =Â coinModel2; |
---|
2646 |  int numberColumns = coinModel.numberColumns(); |
---|
2647 |  int iColumn; |
---|
2648 | Â // associate all columns to stop possible error messages |
---|
2649 |  for (iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
2650 | Â Â coinModel.associateElement(coinModel.columnName(iColumn),1.0); |
---|
2651 | Â } |
---|
2652 | Â CoinZeroN(solution,numberColumns); |
---|
2653 |  int nCol=knapsackStart[0]; |
---|
2654 |  for (iColumn=0;iColumn<nCol;iColumn++) { |
---|
2655 |   int jColumn = whichColumn[iColumn]; |
---|
2656 | Â Â solution[jColumn]=knapsackSolution[iColumn]; |
---|
2657 | Â } |
---|
2658 |  int * buildRow = new int [numberColumns]; // wild overkill |
---|
2659 |  double * buildElement = new double [numberColumns]; |
---|
2660 |  int iKnapsack; |
---|
2661 |  for (iKnapsack=0;iKnapsack<numberKnapsack;iKnapsack++) { |
---|
2662 |   int k=-1; |
---|
2663 |   double value=0.0; |
---|
2664 |   for (iColumn=knapsackStart[iKnapsack];iColumn<knapsackStart[iKnapsack+1];iColumn++) { |
---|
2665 |    if (knapsackSolution[iColumn]>1.0e-5) { |
---|
2666 |     if (k>=0) { |
---|
2667 | Â Â Â Â Â printf("Two nonzero values for knapsack %d at (%d,%g) and (%d,%g)\n",iKnapsack, |
---|
2668 | Â Â Â Â Â Â Â Â Â k,knapsackSolution[k],iColumn,knapsackSolution[iColumn]); |
---|
2669 | Â Â Â Â Â abort(); |
---|
2670 | Â Â Â Â } |
---|
2671 | Â Â Â Â k=iColumn; |
---|
2672 | Â Â Â Â value=floor(knapsackSolution[iColumn]+0.5); |
---|
2673 | Â Â Â Â assert (fabs(value-knapsackSolution[iColumn])<1.0e-5); |
---|
2674 | Â Â Â } |
---|
2675 | Â Â } |
---|
2676 |   if (k>=0) { |
---|
2677 |    int iRow = knapsackRow[iKnapsack]; |
---|
2678 |    int nCreate = 10000; |
---|
2679 |    int nel=coinModel.expandKnapsack(iRow,nCreate,NULL,NULL,buildRow,buildElement,k-knapsackStart[iKnapsack]); |
---|
2680 | Â Â Â assert (nel); |
---|
2681 |    if (logLevel>0) |
---|
2682 | Â Â Â Â printf("expanded column %d in knapsack %d has %d nonzero entries:\n", |
---|
2683 | Â Â Â Â Â Â Â Â k-knapsackStart[iKnapsack],iKnapsack,nel); |
---|
2684 |    for (int i=0;i<nel;i++) { |
---|
2685 |     int jColumn = buildRow[i]; |
---|
2686 |     double value = buildElement[i]; |
---|
2687 |     if (logLevel>0) |
---|
2688 | Â Â Â Â Â printf("%d - original %d has value %g\n",i,jColumn,value); |
---|
2689 | Â Â Â Â solution[jColumn]=value; |
---|
2690 | Â Â Â } |
---|
2691 | Â Â } |
---|
2692 | Â } |
---|
2693 |  delete [] buildRow; |
---|
2694 |  delete [] buildElement; |
---|
2695 | #if 0 |
---|
2696 | Â for (iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
2697 | Â Â if (solution[iColumn]>1.0e-5&&coinModel.isInteger(iColumn)) |
---|
2698 | Â Â Â printf("%d %g\n",iColumn,solution[iColumn]); |
---|
2699 | Â } |
---|
2700 | #endif |
---|
2701 | } |
---|
2702 | #endif |
---|
2703 | #if 0 |
---|
2704 | static int outDupRow(OsiSolverInterface * solver) |
---|
2705 | { |
---|
2706 | Â CglDuplicateRow dupCuts(solver); |
---|
2707 | Â CglTreeInfo info; |
---|
2708 | Â info.level = 0; |
---|
2709 | Â info.pass = 0; |
---|
2710 | Â int numberRows = solver->getNumRows(); |
---|
2711 | Â info.formulation_rows = numberRows; |
---|
2712 | Â info.inTree = false; |
---|
2713 | Â info.strengthenRow= NULL; |
---|
2714 | Â info.pass = 0; |
---|
2715 | Â OsiCuts cs; |
---|
2716 | Â dupCuts.generateCuts(*solver,cs,info); |
---|
2717 | Â const int * duplicate = dupCuts.duplicate(); |
---|
2718 | Â // Get rid of duplicate rows |
---|
2719 | Â int * which = new int[numberRows]; |
---|
2720 | Â int numberDrop=0; |
---|
2721 | Â for (int iRow=0;iRow<numberRows;iRow++) { |
---|
2722 | Â Â if (duplicate[iRow]==-2||duplicate[iRow]>=0) |
---|
2723 | Â Â Â which[numberDrop++]=iRow; |
---|
2724 | Â } |
---|
2725 | Â if (numberDrop) { |
---|
2726 | Â Â solver->deleteRows(numberDrop,which); |
---|
2727 | Â } |
---|
2728 | Â delete [] which; |
---|
2729 | Â // see if we have any column cuts |
---|
2730 | Â int numberColumnCuts = cs.sizeColCuts() ; |
---|
2731 | Â const double * columnLower = solver->getColLower(); |
---|
2732 | Â const double * columnUpper = solver->getColUpper(); |
---|
2733 | Â for (int k = 0;k<numberColumnCuts;k++) { |
---|
2734 | Â Â OsiColCut * thisCut = cs.colCutPtr(k) ; |
---|
2735 | Â Â const CoinPackedVector & lbs = thisCut->lbs() ; |
---|
2736 | Â Â const CoinPackedVector & ubs = thisCut->ubs() ; |
---|
2737 | Â Â int j ; |
---|
2738 | Â Â int n ; |
---|
2739 | Â Â const int * which ; |
---|
2740 | Â Â const double * values ; |
---|
2741 | Â Â n = lbs.getNumElements() ; |
---|
2742 | Â Â which = lbs.getIndices() ; |
---|
2743 | Â Â values = lbs.getElements() ; |
---|
2744 | Â Â for (j = 0;j<n;j++) { |
---|
2745 | Â Â Â int iColumn = which[j] ; |
---|
2746 | Â Â Â if (values[j]>columnLower[iColumn]) |
---|
2747 | Â Â Â Â solver->setColLower(iColumn,values[j]) ; |
---|
2748 | Â Â } |
---|
2749 | Â Â n = ubs.getNumElements() ; |
---|
2750 | Â Â which = ubs.getIndices() ; |
---|
2751 | Â Â values = ubs.getElements() ; |
---|
2752 | Â Â for (j = 0;j<n;j++) { |
---|
2753 | Â Â Â int iColumn = which[j] ; |
---|
2754 | Â Â Â if (values[j]<columnUpper[iColumn]) |
---|
2755 | Â Â Â Â solver->setColUpper(iColumn,values[j]) ; |
---|
2756 | Â Â } |
---|
2757 | Â } |
---|
2758 | Â return numberDrop; |
---|
2759 | } |
---|
2760 | #endif |
---|
2761 | void checkSOS(CbcModel * babModel, const OsiSolverInterface * solver) |
---|
2762 | { |
---|
2763 | #ifdef COIN_DEVELOP |
---|
2764 |  if (!babModel->ownObjects()) |
---|
2765 | Â Â return; |
---|
2766 | Â //const double *objective = solver->getObjCoefficients() ; |
---|
2767 |  const double *columnLower = solver->getColLower() ; |
---|
2768 |  const double * columnUpper = solver->getColUpper() ; |
---|
2769 |  const double * solution = solver->getColSolution(); |
---|
2770 | Â //int numberColumns = solver->getNumCols() ; |
---|
2771 | Â //int numberRows = solver->getNumRows(); |
---|
2772 | Â //double direction = solver->getObjSense(); |
---|
2773 | Â //int iRow,iColumn; |
---|
2774 | |
---|
2775 | Â // Row copy |
---|
2776 | Â CoinPackedMatrix matrixByRow(*solver->getMatrixByRow()); |
---|
2777 | Â //const double * elementByRow = matrixByRow.getElements(); |
---|
2778 | Â //const int * column = matrixByRow.getIndices(); |
---|
2779 | Â //const CoinBigIndex * rowStart = matrixByRow.getVectorStarts(); |
---|
2780 |  const int * rowLength = matrixByRow.getVectorLengths(); |
---|
2781 | |
---|
2782 | Â // Column copy |
---|
2783 |  CoinPackedMatrix matrixByCol(*solver->getMatrixByCol()); |
---|
2784 |  const double * element = matrixByCol.getElements(); |
---|
2785 |  const int * row = matrixByCol.getIndices(); |
---|
2786 |  const CoinBigIndex * columnStart = matrixByCol.getVectorStarts(); |
---|
2787 |  const int * columnLength = matrixByCol.getVectorLengths(); |
---|
2788 | |
---|
2789 |  const double * rowLower = solver->getRowLower(); |
---|
2790 |  const double * rowUpper = solver->getRowUpper(); |
---|
2791 | Â OsiObject **Â objects =Â babModel->objects(); |
---|
2792 |  int numberObjects = babModel->numberObjects(); |
---|
2793 |  for (int iObj = 0;iObj<numberObjects;iObj++) { |
---|
2794 | Â Â CbcSOS *Â objSOS = |
---|
2795 |    dynamic_cast <CbcSOS *>(objects[iObj]) ; |
---|
2796 |   if (objSOS) { |
---|
2797 |    int n=objSOS->numberMembers(); |
---|
2798 |    const int * which = objSOS->members(); |
---|
2799 |    const double * weight = objSOS->weights(); |
---|
2800 |    int type = objSOS->sosType(); |
---|
2801 | Â Â Â // convexity row? |
---|
2802 |    int iColumn; |
---|
2803 | Â Â Â iColumn=which[0]; |
---|
2804 |    int j; |
---|
2805 |    int convex=-1; |
---|
2806 |    for (j=columnStart[iColumn];j<columnStart[iColumn]+columnLength[iColumn];j++) { |
---|
2807 |     int iRow = row[j]; |
---|
2808 |     double value = element[j]; |
---|
2809 |     if (rowLower[iRow]==1.0&&rowUpper[iRow]==1.0&& |
---|
2810 | Â Â Â Â Â Â value==1.0)Â { |
---|
2811 | Â Â Â Â Â // possible |
---|
2812 |      if (rowLength[iRow]==n) { |
---|
2813 |       if (convex==-1) |
---|
2814 | Â Â Â Â Â Â Â convex=iRow; |
---|
2815 | Â Â Â Â Â Â else |
---|
2816 | Â Â Â Â Â Â Â convex=-2; |
---|
2817 | Â Â Â Â Â } |
---|
2818 | Â Â Â Â } |
---|
2819 | Â Â Â } |
---|
2820 | Â Â Â printf ("set %d of type %d has %d members - possible convexity row %d\n", |
---|
2821 | Â Â Â Â Â Â Â iObj,type,n,convex); |
---|
2822 |    for (int i=0;i<n;i++) { |
---|
2823 | Â Â Â Â iColumn =Â which[i]; |
---|
2824 |     int convex2=-1; |
---|
2825 |     for (j=columnStart[iColumn];j<columnStart[iColumn]+columnLength[iColumn];j++) { |
---|
2826 |      int iRow = row[j]; |
---|
2827 |      if (iRow==convex) { |
---|
2828 |       double value = element[j]; |
---|
2829 |       if (value==1.0) { |
---|
2830 | Â Â Â Â Â Â Â convex2=iRow; |
---|
2831 | Â Â Â Â Â Â } |
---|
2832 | Â Â Â Â Â } |
---|
2833 | Â Â Â Â } |
---|
2834 |     if (convex2<0&&convex>=0) { |
---|
2835 | Â Â Â Â Â printf("odd convexity row\n"); |
---|
2836 | Â Â Â Â Â convex=-2; |
---|
2837 | Â Â Â Â } |
---|
2838 | Â Â Â Â printf("col %d has weight %g and value %g, bounds %g %g\n", |
---|
2839 | Â Â Â Â Â Â Â Â iColumn,weight[i],solution[iColumn],columnLower[iColumn], |
---|
2840 | Â Â Â Â Â Â Â Â columnUpper[iColumn]); |
---|
2841 | Â Â Â } |
---|
2842 | Â Â } |
---|
2843 | Â } |
---|
2844 | #endif |
---|
2845 | } |
---|
2846 | #ifndef NEW_STYLE_SOLVER |
---|
2847 | int callCbc1(const char * input2, CbcModel & model, int callBack(CbcModel * currentSolver, int whereFrom)) |
---|
2848 | { |
---|
2849 |  char * input = strdup(input2); |
---|
2850 |  int length = strlen(input); |
---|
2851 |  bool blank = input[0]=='0'; |
---|
2852 |  int n=blank ? 0 : 1; |
---|
2853 |  for (int i=0;i<length;i++) { |
---|
2854 |   if (blank) { |
---|
2855 | Â Â Â // look for next non blank |
---|
2856 |    if (input[i]==' ') { |
---|
2857 | Â Â Â Â continue; |
---|
2858 |    } else { |
---|
2859 | Â Â Â Â n++; |
---|
2860 | Â Â Â Â blank=false; |
---|
2861 | Â Â Â } |
---|
2862 |   } else { |
---|
2863 | Â Â Â // look for next blank |
---|
2864 |    if (input[i]!=' ') { |
---|
2865 | Â Â Â Â continue; |
---|
2866 |    } else { |
---|
2867 | Â Â Â Â blank=true; |
---|
2868 | Â Â Â } |
---|
2869 | Â Â } |
---|
2870 | Â } |
---|
2871 |  char ** argv = new char * [n+2]; |
---|
2872 | Â argv[0]=strdup("cbc"); |
---|
2873 |  int i=0; |
---|
2874 | Â while(input[i]==' ') |
---|
2875 | Â Â i++; |
---|
2876 |  for (int j=0;j<n;j++) { |
---|
2877 |   int saveI=i; |
---|
2878 |   for (;i<length;i++) { |
---|
2879 | Â Â Â // look for next blank |
---|
2880 |    if (input[i]!=' ') { |
---|
2881 | Â Â Â Â continue; |
---|
2882 |    } else { |
---|
2883 | Â Â Â Â break; |
---|
2884 | Â Â Â } |
---|
2885 | Â Â } |
---|
2886 | Â Â input[i]='\0'; |
---|
2887 | Â Â argv[j+1]=strdup(input+saveI); |
---|
2888 | Â Â while(input[i]==' ') |
---|
2889 | Â Â Â i++; |
---|
2890 | Â } |
---|
2891 | Â argv[n+1]=strdup("-quit"); |
---|
2892 | Â free(input); |
---|
2893 | Â totalTime=0.0; |
---|
2894 | Â currentBranchModel =Â NULL; |
---|
2895 | Â CbcOrClpRead_mode=1; |
---|
2896 | Â CbcOrClpReadCommand=stdin; |
---|
2897 | Â noPrinting=false; |
---|
2898 |  int returnCode = CbcMain1(n+2,const_cast<const char **>(argv),model,callBack); |
---|
2899 |  for (int k=0;k<n+2;k++) |
---|
2900 | Â Â free(argv[k]); |
---|
2901 |  delete [] argv; |
---|
2902 |  return returnCode; |
---|
2903 | } |
---|
2904 | int callCbc1(const std::string input2, CbcModel & babSolver) |
---|
2905 | { |
---|
2906 |  char * input3 = strdup(input2.c_str()); |
---|
2907 |  int returnCode=callCbc1(input3,babSolver); |
---|
2908 | Â free(input3); |
---|
2909 |  return returnCode; |
---|
2910 | } |
---|
2911 | int callCbc(const char * input2, CbcModel & babSolver) |
---|
2912 | { |
---|
2913 | Â CbcMain0(babSolver); |
---|
2914 |  return callCbc1(input2,babSolver); |
---|
2915 | } |
---|
2916 | int callCbc(const std::string input2, CbcModel & babSolver) |
---|
2917 | { |
---|
2918 |  char * input3 = strdup(input2.c_str()); |
---|
2919 | Â CbcMain0(babSolver); |
---|
2920 |  int returnCode=callCbc1(input3,babSolver); |
---|
2921 | Â free(input3); |
---|
2922 |  return returnCode; |
---|
2923 | } |
---|
2924 | int callCbc(const char * input2, OsiClpSolverInterface& solver1) |
---|
2925 | { |
---|
2926 | Â CbcModel model(solver1); |
---|
2927 |  return callCbc(input2,model); |
---|
2928 | } |
---|
2929 | int callCbc(const char * input2) |
---|
2930 | { |
---|
2931 | Â { |
---|
2932 | Â Â OsiClpSolverInterface solver1; |
---|
2933 |   return callCbc(input2,solver1); |
---|
2934 | Â } |
---|
2935 | } |
---|
2936 | int callCbc(const std::string input2, OsiClpSolverInterface& solver1) |
---|
2937 | { |
---|
2938 |  char * input3 = strdup(input2.c_str()); |
---|
2939 |  int returnCode=callCbc(input3,solver1); |
---|
2940 | Â free(input3); |
---|
2941 |  return returnCode; |
---|
2942 | } |
---|
2943 | int callCbc(const std::string input2) |
---|
2944 | { |
---|
2945 |  char * input3 = strdup(input2.c_str()); |
---|
2946 | Â OsiClpSolverInterface solver1; |
---|
2947 |  int returnCode=callCbc(input3,solver1); |
---|
2948 | Â free(input3); |
---|
2949 |  return returnCode; |
---|
2950 | } |
---|
2951 | static int dummyCallBack(CbcModel * model, int whereFrom) |
---|
2952 | { |
---|
2953 |  return 0; |
---|
2954 | } |
---|
2955 | int CbcMain1 (int argc, const char *argv[], |
---|
2956 |        CbcModel & model) |
---|
2957 | { |
---|
2958 |  return CbcMain1(argc,argv,model,dummyCallBack); |
---|
2959 | } |
---|
2960 | int callCbc1(const std::string input2, CbcModel & babSolver, int callBack(CbcModel * currentSolver, int whereFrom)) |
---|
2961 | { |
---|
2962 |  char * input3 = strdup(input2.c_str()); |
---|
2963 |  int returnCode=callCbc1(input3,babSolver,callBack); |
---|
2964 | Â free(input3); |
---|
2965 |  return returnCode; |
---|
2966 | } |
---|
2967 | int callCbc1(const char * input2, CbcModel & model) |
---|
2968 | { |
---|
2969 |  return callCbc1(input2,model,dummyCallBack); |
---|
2970 | } |
---|
2971 | int CbcMain (int argc, const char *argv[], |
---|
2972 |        CbcModel & model) |
---|
2973 | { |
---|
2974 | Â CbcMain0(model); |
---|
2975 |  return CbcMain1(argc,argv,model); |
---|
2976 | } |
---|
2977 | #define CBCMAXPARAMETERS 200 |
---|
2978 | static CbcOrClpParam parameters[CBCMAXPARAMETERS]; |
---|
2979 | static int numberParameters=0 ; |
---|
2980 | void CbcMain0 (CbcModel & model) |
---|
2981 | { |
---|
2982 | Â OsiClpSolverInterface *Â originalSolver =Â dynamic_cast<OsiClpSolverInterface *>Â (model.solver()); |
---|
2983 | Â assert (originalSolver); |
---|
2984 | Â CoinMessageHandler *Â generalMessageHandler =Â originalSolver->messageHandler(); |
---|
2985 | Â generalMessageHandler->setPrefix(true); |
---|
2986 | Â OsiSolverInterface *Â solver =Â model.solver(); |
---|
2987 | Â OsiClpSolverInterface *Â clpSolver =Â dynamic_cast<Â OsiClpSolverInterface*>Â (solver); |
---|
2988 | Â ClpSimplex *Â lpSolver =Â clpSolver->getModelPtr(); |
---|
2989 | Â lpSolver->setPerturbation(50); |
---|
2990 | Â lpSolver->messageHandler()->setPrefix(false); |
---|
2991 | Â establishParams(numberParameters,parameters)Â ; |
---|
2992 |  const char dirsep = CoinFindDirSeparator(); |
---|
2993 | Â std::string directory; |
---|
2994 | Â std::string dirSample; |
---|
2995 | Â std::string dirNetlib; |
---|
2996 | Â std::string dirMiplib; |
---|
2997 |  if (dirsep == '/') { |
---|
2998 | Â Â directory =Â "./"; |
---|
2999 | Â Â dirSample =Â "../../Data/Sample/"; |
---|
3000 | Â Â dirNetlib =Â "../../Data/Netlib/"; |
---|
3001 | Â Â dirMiplib =Â "../../Data/miplib3/"; |
---|
3002 |  } else { |
---|
3003 | Â Â directory =Â ".\\"; |
---|
3004 | Â Â dirSample =Â "..\\..\\Data\\Sample\\"; |
---|
3005 | Â Â dirNetlib =Â "..\\..\\Data\\Netlib\\"; |
---|
3006 | Â Â dirMiplib =Â "..\\..\\Data\\miplib3\\"; |
---|
3007 | Â } |
---|
3008 | Â std::string defaultDirectory =Â directory; |
---|
3009 | Â std::string importFile =""; |
---|
3010 | Â std::string exportFile ="default.mps"; |
---|
3011 | Â std::string importBasisFile =""; |
---|
3012 | Â std::string importPriorityFile =""; |
---|
3013 | Â std::string debugFile=""; |
---|
3014 | Â std::string printMask=""; |
---|
3015 | Â std::string exportBasisFile ="default.bas"; |
---|
3016 | Â std::string saveFile ="default.prob"; |
---|
3017 | Â std::string restoreFile ="default.prob"; |
---|
3018 | Â std::string solutionFile ="stdout"; |
---|
3019 | Â std::string solutionSaveFile ="solution.file"; |
---|
3020 |  int doIdiot=-1; |
---|
3021 |  int outputFormat=2; |
---|
3022 |  int substitution=3; |
---|
3023 |  int dualize=3; |
---|
3024 |  int preSolve=5; |
---|
3025 |  int doSprint=-1; |
---|
3026 |  int testOsiParameters=-1; |
---|
3027 | Â parameters[whichParam(BASISIN,numberParameters,parameters)].setStringValue(importBasisFile); |
---|
3028 | Â parameters[whichParam(PRIORITYIN,numberParameters,parameters)].setStringValue(importPriorityFile); |
---|
3029 | Â parameters[whichParam(BASISOUT,numberParameters,parameters)].setStringValue(exportBasisFile); |
---|
3030 | Â parameters[whichParam(DEBUG,numberParameters,parameters)].setStringValue(debugFile); |
---|
3031 | Â parameters[whichParam(PRINTMASK,numberParameters,parameters)].setStringValue(printMask); |
---|
3032 | Â parameters[whichParam(DIRECTORY,numberParameters,parameters)].setStringValue(directory); |
---|
3033 | Â parameters[whichParam(DIRSAMPLE,numberParameters,parameters)].setStringValue(dirSample); |
---|
3034 | Â parameters[whichParam(DIRNETLIB,numberParameters,parameters)].setStringValue(dirNetlib); |
---|
3035 | Â parameters[whichParam(DIRMIPLIB,numberParameters,parameters)].setStringValue(dirMiplib); |
---|
3036 | Â parameters[whichParam(DUALBOUND,numberParameters,parameters)].setDoubleValue(lpSolver->dualBound()); |
---|
3037 | Â parameters[whichParam(DUALTOLERANCE,numberParameters,parameters)].setDoubleValue(lpSolver->dualTolerance()); |
---|
3038 | Â parameters[whichParam(EXPORT,numberParameters,parameters)].setStringValue(exportFile); |
---|
3039 | Â parameters[whichParam(IDIOT,numberParameters,parameters)].setIntValue(doIdiot); |
---|
3040 | Â parameters[whichParam(IMPORT,numberParameters,parameters)].setStringValue(importFile); |
---|
3041 | Â parameters[whichParam(PRESOLVETOLERANCE,numberParameters,parameters)].setDoubleValue(1.0e-8); |
---|
3042 |  int slog = whichParam(SOLVERLOGLEVEL,numberParameters,parameters); |
---|
3043 |  int log = whichParam(LOGLEVEL,numberParameters,parameters); |
---|
3044 | Â parameters[slog].setIntValue(1); |
---|
3045 | Â clpSolver->messageHandler()->setLogLevel(1)Â ; |
---|
3046 | Â model.messageHandler()->setLogLevel(1); |
---|
3047 | Â lpSolver->setLogLevel(1); |
---|
3048 | Â parameters[log].setIntValue(1); |
---|
3049 | Â parameters[whichParam(MAXFACTOR,numberParameters,parameters)].setIntValue(lpSolver->factorizationFrequency()); |
---|
3050 | Â parameters[whichParam(MAXITERATION,numberParameters,parameters)].setIntValue(lpSolver->maximumIterations()); |
---|
3051 | Â parameters[whichParam(OUTPUTFORMAT,numberParameters,parameters)].setIntValue(outputFormat); |
---|
3052 | Â parameters[whichParam(PRESOLVEPASS,numberParameters,parameters)].setIntValue(preSolve); |
---|
3053 | Â parameters[whichParam(PERTVALUE,numberParameters,parameters)].setIntValue(lpSolver->perturbation()); |
---|
3054 | Â parameters[whichParam(PRIMALTOLERANCE,numberParameters,parameters)].setDoubleValue(lpSolver->primalTolerance()); |
---|
3055 | Â parameters[whichParam(PRIMALWEIGHT,numberParameters,parameters)].setDoubleValue(lpSolver->infeasibilityCost()); |
---|
3056 | Â parameters[whichParam(RESTORE,numberParameters,parameters)].setStringValue(restoreFile); |
---|
3057 | Â parameters[whichParam(SAVE,numberParameters,parameters)].setStringValue(saveFile); |
---|
3058 | Â //parameters[whichParam(TIMELIMIT,numberParameters,parameters)].setDoubleValue(1.0e8); |
---|
3059 | Â parameters[whichParam(TIMELIMIT_BAB,numberParameters,parameters)].setDoubleValue(1.0e8); |
---|
3060 | Â parameters[whichParam(SOLUTION,numberParameters,parameters)].setStringValue(solutionFile); |
---|
3061 | Â parameters[whichParam(SAVESOL,numberParameters,parameters)].setStringValue(solutionSaveFile); |
---|
3062 | Â parameters[whichParam(SPRINT,numberParameters,parameters)].setIntValue(doSprint); |
---|
3063 | Â parameters[whichParam(SUBSTITUTION,numberParameters,parameters)].setIntValue(substitution); |
---|
3064 | Â parameters[whichParam(DUALIZE,numberParameters,parameters)].setIntValue(dualize); |
---|
3065 | Â model.setNumberBeforeTrust(10); |
---|
3066 | Â parameters[whichParam(NUMBERBEFORE,numberParameters,parameters)].setIntValue(5); |
---|
3067 | Â parameters[whichParam(MAXNODES,numberParameters,parameters)].setIntValue(model.getMaximumNodes()); |
---|
3068 | Â model.setNumberStrong(5); |
---|
3069 | Â parameters[whichParam(STRONGBRANCHING,numberParameters,parameters)].setIntValue(model.numberStrong()); |
---|
3070 | Â parameters[whichParam(INFEASIBILITYWEIGHT,numberParameters,parameters)].setDoubleValue(model.getDblParam(CbcModel::CbcInfeasibilityWeight)); |
---|
3071 | Â parameters[whichParam(INTEGERTOLERANCE,numberParameters,parameters)].setDoubleValue(model.getDblParam(CbcModel::CbcIntegerTolerance)); |
---|
3072 | Â parameters[whichParam(INCREMENT,numberParameters,parameters)].setDoubleValue(model.getDblParam(CbcModel::CbcCutoffIncrement)); |
---|
3073 | Â parameters[whichParam(TESTOSI,numberParameters,parameters)].setIntValue(testOsiParameters); |
---|
3074 | Â parameters[whichParam(FPUMPTUNE,numberParameters,parameters)].setIntValue(1003); |
---|
3075 | #ifdef CBC_THREAD |
---|
3076 | Â parameters[whichParam(THREADS,numberParameters,parameters)].setIntValue(0); |
---|
3077 | #endif |
---|
3078 | Â // Set up likely cut generators and defaults |
---|
3079 | Â parameters[whichParam(PREPROCESS,numberParameters,parameters)].setCurrentOption("sos"); |
---|
3080 | Â parameters[whichParam(MIPOPTIONS,numberParameters,parameters)].setIntValue(128|64|1); |
---|
3081 | Â parameters[whichParam(MIPOPTIONS,numberParameters,parameters)].setIntValue(1); |
---|
3082 | Â parameters[whichParam(CUTPASSINTREE,numberParameters,parameters)].setIntValue(1); |
---|
3083 | Â parameters[whichParam(MOREMIPOPTIONS,numberParameters,parameters)].setIntValue(-1); |
---|
3084 | Â parameters[whichParam(MAXHOTITS,numberParameters,parameters)].setIntValue(100); |
---|
3085 | Â parameters[whichParam(CUTSSTRATEGY,numberParameters,parameters)].setCurrentOption("on"); |
---|
3086 | Â parameters[whichParam(HEURISTICSTRATEGY,numberParameters,parameters)].setCurrentOption("on"); |
---|
3087 | Â parameters[whichParam(NODESTRATEGY,numberParameters,parameters)].setCurrentOption("fewest"); |
---|
3088 | Â parameters[whichParam(GOMORYCUTS,numberParameters,parameters)].setCurrentOption("ifmove"); |
---|
3089 | Â parameters[whichParam(PROBINGCUTS,numberParameters,parameters)].setCurrentOption("ifmove"); |
---|
3090 | Â parameters[whichParam(KNAPSACKCUTS,numberParameters,parameters)].setCurrentOption("ifmove"); |
---|
3091 | Â parameters[whichParam(REDSPLITCUTS,numberParameters,parameters)].setCurrentOption("off"); |
---|
3092 | Â parameters[whichParam(CLIQUECUTS,numberParameters,parameters)].setCurrentOption("ifmove"); |
---|
3093 | Â parameters[whichParam(MIXEDCUTS,numberParameters,parameters)].setCurrentOption("ifmove"); |
---|
3094 | Â parameters[whichParam(FLOWCUTS,numberParameters,parameters)].setCurrentOption("ifmove"); |
---|
3095 | Â parameters[whichParam(TWOMIRCUTS,numberParameters,parameters)].setCurrentOption("root"); |
---|
3096 | Â parameters[whichParam(LANDPCUTS,numberParameters,parameters)].setCurrentOption("off"); |
---|
3097 | Â parameters[whichParam(RESIDCUTS,numberParameters,parameters)].setCurrentOption("off"); |
---|
3098 | Â parameters[whichParam(ROUNDING,numberParameters,parameters)].setCurrentOption("on"); |
---|
3099 | Â parameters[whichParam(FPUMP,numberParameters,parameters)].setCurrentOption("on"); |
---|
3100 | Â parameters[whichParam(GREEDY,numberParameters,parameters)].setCurrentOption("on"); |
---|
3101 | Â parameters[whichParam(COMBINE,numberParameters,parameters)].setCurrentOption("on"); |
---|
3102 | Â parameters[whichParam(RINS,numberParameters,parameters)].setCurrentOption("off"); |
---|
3103 | Â parameters[whichParam(LOCALTREE,numberParameters,parameters)].setCurrentOption("off"); |
---|
3104 | Â parameters[whichParam(COSTSTRATEGY,numberParameters,parameters)].setCurrentOption("off"); |
---|
3105 | } |
---|
3106 | #endif |
---|
3107 | /* 1 - add heuristics to model |
---|
3108 | Â Â 2 - do heuristics (and set cutoff and best solution) |
---|
3109 | Â Â 3 - for miplib test so skip some |
---|
3110 | */ |
---|
3111 | #ifndef NEW_STYLE_SOLVER |
---|
3112 | static int doHeuristics(CbcModel * model,int type) |
---|
3113 | #else |
---|
3114 | int |
---|
3115 |  CbcSolver::doHeuristics(CbcModel * model,int type) |
---|
3116 | #endif |
---|
3117 | { |
---|
3118 | #ifndef NEW_STYLE_SOLVER |
---|
3119 | Â CbcOrClpParam *Â parameters_ =Â parameters; |
---|
3120 |  int numberParameters_ = numberParameters; |
---|
3121 | #endif |
---|
3122 |  bool anyToDo=false; |
---|
3123 |  int logLevel = parameters_[whichParam(LOGLEVEL,numberParameters_,parameters_)].intValue(); |
---|
3124 |  int useFpump = parameters_[whichParam(FPUMP,numberParameters_,parameters_)].currentOptionAsInteger(); |
---|
3125 |  int useRounding = parameters_[whichParam(ROUNDING,numberParameters_,parameters_)].currentOptionAsInteger(); |
---|
3126 |  int useGreedy = parameters_[whichParam(GREEDY,numberParameters_,parameters_)].currentOptionAsInteger(); |
---|
3127 |  int useCombine = parameters_[whichParam(COMBINE,numberParameters_,parameters_)].currentOptionAsInteger(); |
---|
3128 |  int useRINS = parameters_[whichParam(RINS,numberParameters_,parameters_)].currentOptionAsInteger(); |
---|
3129 | Â // FPump done first as it only works if no solution |
---|
3130 |  int kType = (type<3) ? type : 1; |
---|
3131 |  if (useFpump>=kType) { |
---|
3132 | Â Â anyToDo=true; |
---|
3133 | Â Â CbcHeuristicFPump heuristic4(*model); |
---|
3134 | Â Â heuristic4.setFractionSmall(0.5); |
---|
3135 |   double dextra3 = parameters_[whichParam(DEXTRA3,numberParameters_,parameters_)].doubleValue(); |
---|
3136 |   if (dextra3) |
---|
3137 | Â Â Â heuristic4.setFractionSmall(dextra3); |
---|
3138 | Â Â heuristic4.setMaximumPasses(parameters_[whichParam(FPUMPITS,numberParameters_,parameters_)].intValue()); |
---|
3139 |   int pumpTune=parameters_[whichParam(FPUMPTUNE,numberParameters_,parameters_)].intValue(); |
---|
3140 |   if (pumpTune>0) { |
---|
3141 | Â Â Â /* |
---|
3142 | Â Â Â Â >=10000000 for using obj |
---|
3143 | Â Â Â Â >=1000000 use as accumulate switch |
---|
3144 | Â Â Â Â >=1000 use index+1 as number of large loops |
---|
3145 | Â Â Â Â >=100 use 0.05 objvalue as increment |
---|
3146 | Â Â Â Â >=10 use +0.1 objvalue for cutoff (add) |
---|
3147 | Â Â Â Â 1 == fix ints at bounds, 2 fix all integral ints, 3 and continuous at bounds |
---|
3148 | Â Â Â Â 4 and static continuous, 5 as 3 but no internal integers |
---|
3149 | Â Â Â Â 6 as 3 but all slack basis! |
---|
3150 | Â Â Â */ |
---|
3151 |    double value = model->solver()->getObjSense()*model->solver()->getObjValue(); |
---|
3152 |    int w = pumpTune/10; |
---|
3153 |    int c = w % 10; |
---|
3154 | Â Â Â w /=Â 10; |
---|
3155 |    int i = w % 10; |
---|
3156 | Â Â Â w /=Â 10; |
---|
3157 |    int r = w; |
---|
3158 |    int accumulate = r/1000; |
---|
3159 | Â Â Â r -=Â 1000*accumulate; |
---|
3160 |    if (accumulate>=10) { |
---|
3161 |     int which = accumulate/10; |
---|
3162 | Â Â Â Â accumulate -=Â 10*which; |
---|
3163 | Â Â Â Â which--; |
---|
3164 | Â Â Â Â // weights and factors |
---|
3165 |     double weight[]={0.1,0.1,0.5,0.5,1.0,1.0,5.0,5.0}; |
---|
3166 |     double factor[] = {0.1,0.5,0.1,0.5,0.1,0.5,0.1,0.5}; |
---|
3167 | Â Â Â Â heuristic4.setInitialWeight(weight[which]); |
---|
3168 | Â Â Â Â heuristic4.setWeightFactor(factor[which]); |
---|
3169 | Â Â Â } |
---|
3170 | Â Â Â // fake cutoff |
---|
3171 |    if (logLevel>1) |
---|
3172 | Â Â Â Â printf("Setting "); |
---|
3173 |    if (c) { |
---|
3174 |     double cutoff; |
---|
3175 | Â Â Â Â model->solver()->getDblParam(OsiDualObjectiveLimit,cutoff); |
---|
3176 | Â Â Â Â cutoff =Â CoinMin(cutoff,value +Â 0.1*fabs(value)*c); |
---|
3177 |     double dextra1 = parameters_[whichParam(DEXTRA1,numberParameters_,parameters_)].doubleValue(); |
---|
3178 |     if (dextra1) |
---|
3179 | Â Â Â Â Â cutoff=dextra1; |
---|
3180 | Â Â Â Â heuristic4.setFakeCutoff(cutoff); |
---|
3181 |     if (logLevel>1) |
---|
3182 | Â Â Â Â Â printf("fake cutoff of %g ",cutoff); |
---|
3183 | Â Â Â } |
---|
3184 |    if (i||r) { |
---|
3185 | Â Â Â Â // also set increment |
---|
3186 | Â Â Â Â //double increment = (0.01*i+0.005)*(fabs(value)+1.0e-12); |
---|
3187 |     double increment = 0.0; |
---|
3188 |     double dextra2 = parameters_[whichParam(DEXTRA2,numberParameters_,parameters_)].doubleValue(); |
---|
3189 |     if (dextra2) |
---|
3190 | Â Â Â Â Â increment =Â dextra2; |
---|
3191 | Â Â Â Â heuristic4.setAbsoluteIncrement(increment); |
---|
3192 | Â Â Â Â heuristic4.setAccumulate(accumulate); |
---|
3193 | Â Â Â Â heuristic4.setMaximumRetries(r+1); |
---|
3194 |     if (logLevel>1) { |
---|
3195 |      if (i) |
---|
3196 | Â Â Â Â Â Â printf("increment of %g ",heuristic4.absoluteIncrement()); |
---|
3197 |      if (accumulate) |
---|
3198 | Â Â Â Â Â Â printf("accumulate of %d ",accumulate); |
---|
3199 | Â Â Â Â Â printf("%d retries ",r+2); |
---|
3200 | Â Â Â Â } |
---|
3201 | Â Â Â } |
---|
3202 | Â Â Â pumpTune =Â pumpTune%100; |
---|
3203 |    if (logLevel>1) |
---|
3204 | Â Â Â Â printf("and setting when to %d\n",pumpTune+10); |
---|
3205 |    if (pumpTune==6) |
---|
3206 | Â Â Â Â pumpTune =13; |
---|
3207 | Â Â Â heuristic4.setWhen(pumpTune+10); |
---|
3208 | Â Â } |
---|
3209 | Â Â heuristic4.setHeuristicName("feasibility pump"); |
---|
3210 | Â Â //#define ROLF |
---|
3211 | #ifdef ROLFÂ Â |
---|
3212 | Â Â CbcHeuristicFPump pump(*model); |
---|
3213 | Â Â pump.setMaximumTime(60); |
---|
3214 | Â Â pump.setMaximumPasses(100); |
---|
3215 | Â Â pump.setMaximumRetries(1); |
---|
3216 | Â Â pump.setFixOnReducedCosts(0); |
---|
3217 | Â Â pump.setHeuristicName("Feasibility pump"); |
---|
3218 | Â Â pump.setFractionSmall(1.0); |
---|
3219 | Â Â pump.setWhen(13); |
---|
3220 | Â Â model->addHeuristic(&pump); |
---|
3221 | #else |
---|
3222 | Â Â model->addHeuristic(&heuristic4); |
---|
3223 | #endif |
---|
3224 | Â } |
---|
3225 |  if (useRounding>=type) { |
---|
3226 | Â Â CbcRounding heuristic1(*model); |
---|
3227 | Â Â heuristic1.setHeuristicName("rounding"); |
---|
3228 | Â Â model->addHeuristic(&heuristic1)Â ; |
---|
3229 | Â Â anyToDo=true; |
---|
3230 | Â } |
---|
3231 |  if (useCombine>=type) { |
---|
3232 | Â Â CbcHeuristicLocal heuristic2(*model); |
---|
3233 | Â Â heuristic2.setHeuristicName("combine solutions"); |
---|
3234 | Â Â heuristic2.setFractionSmall(0.6); |
---|
3235 | Â Â heuristic2.setSearchType(1); |
---|
3236 | Â Â model->addHeuristic(&heuristic2); |
---|
3237 | Â Â anyToDo=true; |
---|
3238 | Â } |
---|
3239 |  if (useGreedy>=type) { |
---|
3240 | Â Â CbcHeuristicGreedyCover heuristic3(*model); |
---|
3241 | Â Â heuristic3.setHeuristicName("greedy cover"); |
---|
3242 | Â Â CbcHeuristicGreedyEquality heuristic3a(*model); |
---|
3243 | Â Â heuristic3a.setHeuristicName("greedy equality"); |
---|
3244 | Â Â model->addHeuristic(&heuristic3); |
---|
3245 | Â Â model->addHeuristic(&heuristic3a); |
---|
3246 | Â Â anyToDo=true; |
---|
3247 | Â } |
---|
3248 |  if (useRINS>=kType) { |
---|
3249 | Â Â CbcHeuristicRINS heuristic5(*model); |
---|
3250 | Â Â heuristic5.setHeuristicName("RINS"); |
---|
3251 | Â Â heuristic5.setFractionSmall(0.6); |
---|
3252 | Â Â model->addHeuristic(&heuristic5)Â ; |
---|
3253 | Â Â anyToDo=true; |
---|
3254 | Â } |
---|
3255 |  if (type==2&&anyToDo) { |
---|
3256 | Â Â // Do heuristics |
---|
3257 | #if 1 |
---|
3258 | Â Â // clean copy |
---|
3259 | Â Â CbcModel model2(*model); |
---|
3260 | Â Â // But get rid of heuristics in model |
---|
3261 | Â Â model->doHeuristicsAtRoot(2); |
---|
3262 |   if (logLevel<=1) |
---|
3263 | Â Â Â model2.solver()->setHintParam(OsiDoReducePrint,true,OsiHintTry); |
---|
3264 | Â Â OsiBabSolver defaultC; |
---|
3265 | Â Â //solver_->setAuxiliaryInfo(&defaultC); |
---|
3266 | Â Â model2.passInSolverCharacteristics(&defaultC); |
---|
3267 | Â Â // Save bounds |
---|
3268 |   int numberColumns = model2.solver()->getNumCols(); |
---|
3269 | Â Â model2.createContinuousSolver(); |
---|
3270 |   bool cleanModel = !model2.numberIntegers()&&!model2.numberObjects(); |
---|
3271 | Â Â model2.findIntegers(false); |
---|
3272 | Â Â model2.doHeuristicsAtRoot(1); |
---|
3273 |   if (cleanModel) |
---|
3274 | Â Â Â model2.zapIntegerInformation(false); |
---|
3275 |   if (model2.bestSolution()) { |
---|
3276 |    double value = model2.getMinimizationObjValue(); |
---|
3277 | Â Â Â model->setCutoff(value); |
---|
3278 | Â Â Â model->setBestSolution(model2.bestSolution(),numberColumns,value); |
---|
3279 | Â Â Â model->setSolutionCount(1); |
---|
3280 | Â Â Â model->setNumberHeuristicSolutions(1); |
---|
3281 | Â Â } |
---|
3282 | #else |
---|
3283 |   if (logLevel<=1) |
---|
3284 | Â Â Â model->solver()->setHintParam(OsiDoReducePrint,true,OsiHintTry); |
---|
3285 | Â Â OsiBabSolver defaultC; |
---|
3286 | Â Â //solver_->setAuxiliaryInfo(&defaultC); |
---|
3287 | Â Â model->passInSolverCharacteristics(&defaultC); |
---|
3288 | Â Â // Save bounds |
---|
3289 |   int numberColumns = model->solver()->getNumCols(); |
---|
3290 | Â Â model->createContinuousSolver(); |
---|
3291 |   bool cleanModel = !model->numberIntegers()&&!model->numberObjects(); |
---|
3292 | Â Â model->findIntegers(false); |
---|
3293 | Â Â model->doHeuristicsAtRoot(1); |
---|
3294 |   if (cleanModel) |
---|
3295 | Â Â Â model->zapIntegerInformation(false); |
---|
3296 | #endif |
---|
3297 |   return 0; |
---|
3298 |  } else { |
---|
3299 |   return 0; |
---|
3300 | Â } |
---|
3301 | }Â |
---|
3302 | |
---|
3303 | int CbcClpUnitTest (const CbcModel & saveModel, |
---|
3304 |            std::string& dirMiplib, bool unitTestOnly); |
---|
3305 | #ifdef NEW_STYLE_SOLVER |
---|
3306 | /* This takes a list of commands, does "stuff" and returns |
---|
3307 | Â Â returnMode - |
---|
3308 | Â Â 0 model and solver untouched - babModel updated |
---|
3309 | Â Â 1 model updated - just with solution basis etc |
---|
3310 | Â Â 2 model updated i.e. as babModel (babModel NULL) (only use without preprocessing) |
---|
3311 | */ |
---|
3312 | int |
---|
3313 | CbcSolver::solve(const char * input2, int returnMode) |
---|
3314 | { |
---|
3315 |  char * input = strdup(input2); |
---|
3316 |  int length = strlen(input); |
---|
3317 |  bool blank = input[0]=='0'; |
---|
3318 |  int n=blank ? 0 : 1; |
---|
3319 |  for (int i=0;i<length;i++) { |
---|
3320 |   if (blank) { |
---|
3321 | Â Â Â // look for next non blank |
---|
3322 |    if (input[i]==' ') { |
---|
3323 | Â Â Â Â continue; |
---|
3324 |    } else { |
---|
3325 | Â Â Â Â n++; |
---|
3326 | Â Â Â Â blank=false; |
---|
3327 | Â Â Â } |
---|
3328 |   } else { |
---|
3329 | Â Â Â // look for next blank |
---|
3330 |    if (input[i]!=' ') { |
---|
3331 | Â Â Â Â continue; |
---|
3332 |    } else { |
---|
3333 | Â Â Â Â blank=true; |
---|
3334 | Â Â Â } |
---|
3335 | Â Â } |
---|
3336 | Â } |
---|
3337 |  char ** argv = new char * [n+2]; |
---|
3338 | Â argv[0]=strdup("cbc"); |
---|
3339 |  int i=0; |
---|
3340 | Â while(input[i]==' ') |
---|
3341 | Â Â i++; |
---|
3342 |  for (int j=0;j<n;j++) { |
---|
3343 |   int saveI=i; |
---|
3344 |   for (;i<length;i++) { |
---|
3345 | Â Â Â // look for next blank |
---|
3346 |    if (input[i]!=' ') { |
---|
3347 | Â Â Â Â continue; |
---|
3348 |    } else { |
---|
3349 | Â Â Â Â break; |
---|
3350 | Â Â Â } |
---|
3351 | Â Â } |
---|
3352 |   char save = input[i]; |
---|
3353 | Â Â input[i]='\0'; |
---|
3354 | Â Â argv[j+1]=strdup(input+saveI); |
---|
3355 | Â Â input[i]=save; |
---|
3356 | Â Â while(input[i]==' ') |
---|
3357 | Â Â Â i++; |
---|
3358 | Â } |
---|
3359 | Â argv[n+1]=strdup("-quit"); |
---|
3360 | Â free(input); |
---|
3361 |  int returnCode = solve(n+2,const_cast<const char **>(argv),returnMode); |
---|
3362 |  for (int k=0;k<n+2;k++) |
---|
3363 | Â Â free(argv[k]); |
---|
3364 |  delete [] argv; |
---|
3365 |  return returnCode; |
---|
3366 | } |
---|
3367 | #endif |
---|
3368 | /* Meaning of whereFrom: |
---|
3369 | Â Â 1 after initial solve by dualsimplex etc |
---|
3370 | Â Â 2 after preprocessing |
---|
3371 | Â Â 3 just before branchAndBound (so user can override) |
---|
3372 | Â Â 4 just after branchAndBound (before postprocessing) |
---|
3373 | Â Â 5 after postprocessing |
---|
3374 | Â Â 6 after a user called heuristic phase |
---|
3375 | */ |
---|
3376 | |
---|
3377 | #ifndef NEW_STYLE_SOLVER |
---|
3378 | int CbcMain1 (int argc, const char *argv[], |
---|
3379 |        CbcModel & model, |
---|
3380 |        int callBack(CbcModel * currentSolver, int whereFrom)) |
---|
3381 | #else |
---|
3382 | /* This takes a list of commands, does "stuff" and returns |
---|
3383 | Â Â returnMode - |
---|
3384 | Â Â 0 model and solver untouched - babModel updated |
---|
3385 | Â Â 1 model updated - just with solution basis etc |
---|
3386 | Â Â 2 model updated i.e. as babModel (babModel NULL) |
---|
3387 | */ |
---|
3388 | int |
---|
3389 |  CbcSolver::solve (int argc, const char *argv[], int returnMode) |
---|
3390 | #endif |
---|
3391 | { |
---|
3392 | #ifndef NEW_STYLE_SOLVER |
---|
3393 | Â CbcOrClpParam *Â parameters_ =Â parameters; |
---|
3394 |  int numberParameters_ = numberParameters; |
---|
3395 | Â CbcModel &Â model_ =Â model; |
---|
3396 | Â CbcModel *Â babModel_ =Â NULL; |
---|
3397 |  int returnMode=1; |
---|
3398 |  int statusUserFunction_[1]; |
---|
3399 |  int numberUserFunctions_=1; // to allow for ampl |
---|
3400 | #else |
---|
3401 |  delete babModel_; |
---|
3402 | Â babModel_ =Â NULL; |
---|
3403 | Â CbcOrClpRead_mode=1; |
---|
3404 |  delete [] statusUserFunction_; |
---|
3405 |  statusUserFunction_ = new int [numberUserFunctions_]; |
---|
3406 |  int iUser; |
---|
3407 | #endif |
---|
3408 | Â memset(statusUserFunction_,0,numberUserFunctions_*sizeof(int)); |
---|
3409 | Â /* Note |
---|
3410 | Â Â Â This is meant as a stand-alone executable to do as much of coin as possible. |
---|
3411 | Â Â Â It should only have one solver known to it. |
---|
3412 | Â */ |
---|
3413 | Â OsiClpSolverInterface *Â originalSolver =Â dynamic_cast<OsiClpSolverInterface *>Â (model_.solver()); |
---|
3414 | Â assert (originalSolver); |
---|
3415 | Â CoinMessageHandler *Â generalMessageHandler =Â model_.messageHandler(); |
---|
3416 | Â generalMessageHandler->setPrefix(false); |
---|
3417 | Â // Move handler across if not default |
---|
3418 |  if (!originalSolver->defaultHandler()&&originalSolver->getModelPtr()->defaultHandler()) |
---|
3419 | Â Â originalSolver->getModelPtr()->passInMessageHandler(originalSolver->messageHandler()); |
---|
3420 | Â CoinMessages generalMessages =Â originalSolver->getModelPtr()->messages(); |
---|
3421 |  char generalPrint[10000]; |
---|
3422 |  if (originalSolver->getModelPtr()->logLevel()==0) |
---|
3423 | Â Â noPrinting=true; |
---|
3424 | #ifndef NEW_STYLE_SOLVER |
---|
3425 |  bool noPrinting_=noPrinting; |
---|
3426 | #endif |
---|
3427 | Â // see if log in list |
---|
3428 |  for (int i=1;i<argc;i++) { |
---|
3429 |   if (!strncmp(argv[i],"log",3)) { |
---|
3430 |    const char * equals = strchr(argv[i],'='); |
---|
3431 |    if (equals&&atoi(equals+1)>0) |
---|
3432 | Â Â Â Â noPrinting_=false; |
---|
3433 | Â Â Â else |
---|
3434 | Â Â Â Â noPrinting_=true; |
---|
3435 | Â Â Â break; |
---|
3436 |   } else if (!strncmp(argv[i],"-log",4)&&i<argc-1) { |
---|
3437 |    if (atoi(argv[i+1])>0) |
---|
3438 | Â Â Â Â noPrinting_=false; |
---|
3439 | Â Â Â else |
---|
3440 | Â Â Â Â noPrinting_=true; |
---|
3441 | Â Â Â break; |
---|
3442 | Â Â } |
---|
3443 | Â } |
---|
3444 |  double time0; |
---|
3445 | Â { |
---|
3446 |   double time1 = CoinCpuTime(),time2; |
---|
3447 | Â Â time0=time1; |
---|
3448 |   bool goodModel=(originalSolver->getNumCols()) ? true : false; |
---|
3449 | |
---|
3450 | Â Â CoinSighandler_t saveSignal=SIG_DFL; |
---|
3451 | Â Â // register signal handler |
---|
3452 | Â Â saveSignal =Â signal(SIGINT,signal_handler); |
---|
3453 | Â Â // Set up all non-standard stuff |
---|
3454 |   int cutPass=-1234567; |
---|
3455 |   int cutPassInTree=-1234567; |
---|
3456 |   int tunePreProcess=5; |
---|
3457 |   int testOsiParameters=-1; |
---|
3458 | Â Â // 0 normal, 1 from ampl or MIQP etc (2 allows cuts) |
---|
3459 |   int complicatedInteger=0; |
---|
3460 | Â Â OsiSolverInterface *Â solver =Â model_.solver(); |
---|
3461 | Â Â OsiClpSolverInterface *Â clpSolver =Â dynamic_cast<Â OsiClpSolverInterface*>Â (solver); |
---|
3462 | Â Â ClpSimplex *Â lpSolver =Â clpSolver->getModelPtr(); |
---|
3463 |   if (noPrinting_) { |
---|
3464 | Â Â Â setCbcOrClpPrinting(false); |
---|
3465 | Â Â Â lpSolver->setLogLevel(0); |
---|
3466 | Â Â } |
---|
3467 | Â Â // For priorities etc |
---|
3468 |   int * priorities=NULL; |
---|
3469 |   int * branchDirection=NULL; |
---|
3470 |   double * pseudoDown=NULL; |
---|
3471 |   double * pseudoUp=NULL; |
---|
3472 |   double * solutionIn = NULL; |
---|
3473 |   int * prioritiesIn = NULL; |
---|
3474 |   int numberSOS = 0; |
---|
3475 |   int * sosStart = NULL; |
---|
3476 |   int * sosIndices = NULL; |
---|
3477 |   char * sosType = NULL; |
---|
3478 |   double * sosReference = NULL; |
---|
3479 |   int * cut=NULL; |
---|
3480 |   int * sosPriority=NULL; |
---|
3481 | Â Â CglStored storedAmpl; |
---|
3482 | Â Â CoinModel *Â coinModel =Â NULL; |
---|
3483 | Â Â CoinModel saveCoinModel; |
---|
3484 | Â Â CoinModel saveTightenedModel; |
---|
3485 |   int * whichColumn = NULL; |
---|
3486 |   int * knapsackStart=NULL; |
---|
3487 |   int * knapsackRow=NULL; |
---|
3488 |   int numberKnapsack=0; |
---|
3489 | #ifdef NEW_STYLE_SOLVER |
---|
3490 |   int numberInputs=0; |
---|
3491 | Â Â readMode_=CbcOrClpRead_mode; |
---|
3492 |   for (iUser=0;iUser<numberUserFunctions_;iUser++) { |
---|
3493 |    int status = userFunction_[iUser]->importData(this,argc,const_cast<char **>(argv)); |
---|
3494 |    if (status>=0) { |
---|
3495 |     if (!status) { |
---|
3496 | Â Â Â Â Â numberInputs++; |
---|
3497 | Â Â Â Â Â statusUserFunction_[iUser]=1; |
---|
3498 | Â Â Â Â Â goodModel=true; |
---|
3499 | Â Â Â Â Â solver =Â model_.solver(); |
---|
3500 | Â Â Â Â Â clpSolver =Â dynamic_cast<Â OsiClpSolverInterface*>Â (solver); |
---|
3501 | Â Â Â Â Â lpSolver =Â clpSolver->getModelPtr(); |
---|
3502 |     } else { |
---|
3503 | Â Â Â Â Â printf("Bad input from user function %s\n",userFunction_[iUser]->name().c_str()); |
---|
3504 | Â Â Â Â Â abort(); |
---|
3505 | Â Â Â Â } |
---|
3506 | Â Â Â } |
---|
3507 | Â Â } |
---|
3508 |   if (numberInputs>1) { |
---|
3509 | Â Â Â printf("Two or more user inputs!\n"); |
---|
3510 | Â Â Â abort(); |
---|
3511 | Â Â } |
---|
3512 |   if (originalCoinModel_) |
---|
3513 | Â Â Â complicatedInteger=1; |
---|
3514 | Â Â testOsiParameters =Â intValue(TESTOSI); |
---|
3515 |   if (noPrinting_) { |
---|
3516 | Â Â Â model_.messageHandler()->setLogLevel(0); |
---|
3517 | Â Â Â setCbcOrClpPrinting(false); |
---|
3518 | Â Â } |
---|
3519 | Â Â CbcOrClpRead_mode=readMode_; |
---|
3520 | #endif |
---|
3521 | #ifdef COIN_HAS_ASL |
---|
3522 | Â Â ampl_info info; |
---|
3523 | Â Â { |
---|
3524 | Â Â memset(&info,0,sizeof(info)); |
---|
3525 |   if (argc>2&&!strcmp(argv[2],"-AMPL")) { |
---|
3526 | Â Â Â statusUserFunction_[0]=1; |
---|
3527 | Â Â Â // see if log in list |
---|
3528 | Â Â Â noPrinting_=true; |
---|
3529 |    for (int i=1;i<argc;i++) { |
---|
3530 |     if (!strncmp(argv[i],"log",3)) { |
---|
3531 |      const char * equals = strchr(argv[i],'='); |
---|
3532 |      if (equals&&atoi(equals+1)>0) { |
---|
3533 | Â Â Â Â Â Â noPrinting_=false; |
---|
3534 | Â Â Â Â Â Â info.logLevel=atoi(equals+1); |
---|
3535 |       int log = whichParam(LOGLEVEL,numberParameters_,parameters_); |
---|
3536 | Â Â Â Â Â Â parameters_[log].setIntValue(info.logLevel); |
---|
3537 | Â Â Â Â Â Â // mark so won't be overWritten |
---|
3538 | Â Â Â Â Â Â info.numberRows=-1234567; |
---|
3539 | Â Â Â Â Â Â break; |
---|
3540 | Â Â Â Â Â } |
---|
3541 | Â Â Â Â } |
---|
3542 | Â Â Â } |
---|
3543 | |
---|
3544 |    union { void * voidModel; CoinModel * model; } coinModelStart; |
---|
3545 | Â Â Â coinModelStart.model=NULL; |
---|
3546 |    int returnCode = readAmpl(&info,argc, const_cast<char **>(argv),& coinModelStart.voidModel); |
---|
3547 | Â Â Â coinModel=coinModelStart.model; |
---|
3548 |    if (returnCode) |
---|
3549 |     return returnCode; |
---|
3550 | Â Â Â CbcOrClpRead_mode=2;Â // so will start with parameters |
---|
3551 | Â Â Â // see if log in list (including environment) |
---|
3552 |    for (int i=1;i<info.numberArguments;i++) { |
---|
3553 |     if (!strcmp(info.arguments[i],"log")) { |
---|
3554 |      if (i<info.numberArguments-1&&atoi(info.arguments[i+1])>0) |
---|
3555 | Â Â Â Â Â Â noPrinting_=false; |
---|
3556 | Â Â Â Â Â break; |
---|
3557 | Â Â Â Â } |
---|
3558 | Â Â Â } |
---|
3559 |    if (noPrinting_) { |
---|
3560 | Â Â Â Â model_.messageHandler()->setLogLevel(0); |
---|
3561 | Â Â Â Â setCbcOrClpPrinting(false); |
---|
3562 | Â Â Â } |
---|
3563 |    if (!noPrinting_) |
---|
3564 | Â Â Â Â printf("%d rows, %d columns and %d elements\n", |
---|
3565 | Â Â Â Â Â Â Â Â info.numberRows,info.numberColumns,info.numberElements); |
---|
3566 | #ifdef COIN_HAS_LINK |
---|
3567 |    if (!coinModel) { |
---|
3568 | #endif |
---|
3569 | Â Â Â solver->loadProblem(info.numberColumns,info.numberRows,info.starts, |
---|
3570 | Â Â Â Â Â Â Â Â Â Â Â Â Â info.rows,info.elements, |
---|
3571 | Â Â Â Â Â Â Â Â Â Â Â Â Â info.columnLower,info.columnUpper,info.objective, |
---|
3572 | Â Â Â Â Â Â Â Â Â Â Â Â Â info.rowLower,info.rowUpper); |
---|
3573 | Â Â Â // take off cuts if ampl wants that |
---|
3574 |    if (info.cut&&0) { |
---|
3575 | Â Â Â Â printf("AMPL CUTS OFF until global cuts fixed\n"); |
---|
3576 | Â Â Â Â info.cut=NULL; |
---|
3577 | Â Â Â } |
---|
3578 |    if (info.cut) { |
---|
3579 |     int numberRows = info.numberRows; |
---|
3580 |     int * whichRow = new int [numberRows]; |
---|
3581 | Â Â Â Â // Row copy |
---|
3582 |     const CoinPackedMatrix * matrixByRow = solver->getMatrixByRow(); |
---|
3583 |     const double * elementByRow = matrixByRow->getElements(); |
---|
3584 |     const int * column = matrixByRow->getIndices(); |
---|
3585 |     const CoinBigIndex * rowStart = matrixByRow->getVectorStarts(); |
---|
3586 |     const int * rowLength = matrixByRow->getVectorLengths(); |
---|
3587 | Â Â Â Â |
---|
3588 |     const double * rowLower = solver->getRowLower(); |
---|
3589 |     const double * rowUpper = solver->getRowUpper(); |
---|
3590 |     int nDelete=0; |
---|
3591 |     for (int iRow=0;iRow<numberRows;iRow++) { |
---|
3592 |      if (info.cut[iRow]) { |
---|
3593 | Â Â Â Â Â Â whichRow[nDelete++]=iRow; |
---|
3594 |       int start = rowStart[iRow]; |
---|
3595 | Â Â Â Â Â Â storedAmpl.addCut(rowLower[iRow],rowUpper[iRow], |
---|
3596 | Â Â Â Â Â Â Â Â Â Â Â Â Â rowLength[iRow],column+start,elementByRow+start); |
---|
3597 | Â Â Â Â Â } |
---|
3598 | Â Â Â Â } |
---|
3599 | Â Â Â Â solver->deleteRows(nDelete,whichRow); |
---|
3600 |     delete [] whichRow; |
---|
3601 | Â Â Â } |
---|
3602 | #ifdef COIN_HAS_LINK |
---|
3603 |    } else { |
---|
3604 | Â Â Â Â // save |
---|
3605 | Â Â Â Â saveCoinModel =Â *coinModel; |
---|
3606 | Â Â Â Â // load from coin model |
---|
3607 | Â Â Â Â OsiSolverLink solver1; |
---|
3608 | Â Â Â Â OsiSolverInterface *Â solver2 =Â solver1.clone(); |
---|
3609 | Â Â Â Â model_.assignSolver(solver2,false); |
---|
3610 | Â Â Â Â OsiSolverLink *Â si = |
---|
3611 | Â Â Â Â Â dynamic_cast<OsiSolverLink *>(model_.solver())Â ; |
---|
3612 | Â Â Â Â assert (si !=Â NULL); |
---|
3613 | Â Â Â Â si->setDefaultMeshSize(0.001); |
---|
3614 | Â Â Â Â // need some relative granularity |
---|
3615 | Â Â Â Â si->setDefaultBound(100.0); |
---|
3616 |     double dextra3 = parameters_[whichParam(DEXTRA3,numberParameters_,parameters_)].doubleValue(); |
---|
3617 |     if (dextra3) |
---|
3618 | Â Â Â Â Â si->setDefaultMeshSize(dextra3); |
---|
3619 | Â Â Â Â si->setDefaultBound(100000.0); |
---|
3620 | Â Â Â Â si->setIntegerPriority(1000); |
---|
3621 | Â Â Â Â si->setBiLinearPriority(10000); |
---|
3622 | Â Â Â Â CoinModel *Â model2 =Â (CoinModel *)Â coinModel; |
---|
3623 |     int logLevel = parameters_[whichParam(LOGLEVEL,numberParameters_,parameters_)].intValue(); |
---|
3624 | Â Â Â Â si->load(*model2,true,logLevel); |
---|
3625 | Â Â Â Â // redo |
---|
3626 | Â Â Â Â solver =Â model_.solver(); |
---|
3627 | Â Â Â Â clpSolver =Â dynamic_cast<Â OsiClpSolverInterface*>Â (solver); |
---|
3628 | Â Â Â Â lpSolver =Â clpSolver->getModelPtr(); |
---|
3629 | Â Â Â Â clpSolver->messageHandler()->setLogLevel(0)Â ; |
---|
3630 | Â Â Â Â testOsiParameters=0; |
---|
3631 | Â Â Â Â parameters_[whichParam(TESTOSI,numberParameters_,parameters_)].setIntValue(0); |
---|
3632 | Â Â Â Â complicatedInteger=1; |
---|
3633 |     if (info.cut) { |
---|
3634 | Â Â Â Â Â printf("Sorry - can't do cuts with LOS as ruins delicate row order\n"); |
---|
3635 | Â Â Â Â Â abort(); |
---|
3636 |      int numberRows = info.numberRows; |
---|
3637 |      int * whichRow = new int [numberRows]; |
---|
3638 | Â Â Â Â Â // Row copy |
---|
3639 |      const CoinPackedMatrix * matrixByRow = solver->getMatrixByRow(); |
---|
3640 |      const double * elementByRow = matrixByRow->getElements(); |
---|
3641 |      const int * column = matrixByRow->getIndices(); |
---|
3642 |      const CoinBigIndex * rowStart = matrixByRow->getVectorStarts(); |
---|
3643 |      const int * rowLength = matrixByRow->getVectorLengths(); |
---|
3644 | Â Â Â Â Â |
---|
3645 |      const double * rowLower = solver->getRowLower(); |
---|
3646 |      const double * rowUpper = solver->getRowUpper(); |
---|
3647 |      int nDelete=0; |
---|
3648 |      for (int iRow=0;iRow<numberRows;iRow++) { |
---|
3649 |       if (info.cut[iRow]) { |
---|
3650 | Â Â Â Â Â Â Â whichRow[nDelete++]=iRow; |
---|
3651 |        int start = rowStart[iRow]; |
---|
3652 | Â Â Â Â Â Â Â storedAmpl.addCut(rowLower[iRow],rowUpper[iRow], |
---|
3653 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â rowLength[iRow],column+start,elementByRow+start); |
---|
3654 | Â Â Â Â Â Â } |
---|
3655 | Â Â Â Â Â } |
---|
3656 | Â Â Â Â Â solver->deleteRows(nDelete,whichRow); |
---|
3657 | Â Â Â Â Â // and special matrix |
---|
3658 | Â Â Â Â Â si->cleanMatrix()->deleteRows(nDelete,whichRow); |
---|
3659 |      delete [] whichRow; |
---|
3660 | Â Â Â Â } |
---|
3661 | Â Â Â } |
---|
3662 | #endif |
---|
3663 | Â Â Â // If we had a solution use it |
---|
3664 |    if (info.primalSolution) { |
---|
3665 | Â Â Â Â solver->setColSolution(info.primalSolution); |
---|
3666 | Â Â Â } |
---|
3667 | Â Â Â // status |
---|
3668 |    if (info.rowStatus) { |
---|
3669 |     unsigned char * statusArray = lpSolver->statusArray(); |
---|
3670 |     int i; |
---|
3671 |     for (i=0;i<info.numberColumns;i++) |
---|
3672 | Â Â Â Â Â statusArray[i]=(char)info.columnStatus[i]; |
---|
3673 | Â Â Â Â statusArray+=info.numberColumns; |
---|
3674 |     for (i=0;i<info.numberRows;i++) |
---|
3675 | Â Â Â Â Â statusArray[i]=(char)info.rowStatus[i]; |
---|
3676 | Â Â Â Â CoinWarmStartBasis *Â basis =Â lpSolver->getBasis(); |
---|
3677 | Â Â Â Â solver->setWarmStart(basis); |
---|
3678 |     delete basis; |
---|
3679 | Â Â Â } |
---|
3680 | Â Â Â freeArrays1(&info); |
---|
3681 | Â Â Â // modify objective if necessary |
---|
3682 | Â Â Â solver->setObjSense(info.direction); |
---|
3683 | Â Â Â solver->setDblParam(OsiObjOffset,info.offset); |
---|
3684 |    if (info.offset) { |
---|
3685 | Â Â Â Â sprintf(generalPrint,"Ampl objective offset is %g", |
---|
3686 | Â Â Â Â Â Â Â Â info.offset); |
---|
3687 | Â Â Â Â generalMessageHandler->message(CLP_GENERAL,generalMessages) |
---|
3688 | Â Â Â Â Â <<Â generalPrint |
---|
3689 | Â Â Â Â Â <<CoinMessageEol; |
---|
3690 | Â Â Â } |
---|
3691 | Â Â Â // Set integer variables (unless nonlinear when set) |
---|
3692 |    if (!info.nonLinear) { |
---|
3693 |     for (int i=info.numberColumns-info.numberIntegers; |
---|
3694 | Â Â Â Â Â Â Â i<info.numberColumns;i++) |
---|
3695 | Â Â Â Â Â solver->setInteger(i); |
---|
3696 | Â Â Â } |
---|
3697 | Â Â Â goodModel=true; |
---|
3698 | Â Â Â // change argc etc |
---|
3699 | Â Â Â argc =Â info.numberArguments; |
---|
3700 |    argv = const_cast<const char **>(info.arguments); |
---|
3701 | Â Â } |
---|
3702 | Â Â } |
---|
3703 | #endif  |
---|
3704 | Â Â // default action on import |
---|
3705 |   int allowImportErrors=0; |
---|
3706 |   int keepImportNames=1; |
---|
3707 |   int doIdiot=-1; |
---|
3708 |   int outputFormat=2; |
---|
3709 |   int slpValue=-1; |
---|
3710 |   int cppValue=-1; |
---|
3711 |   int printOptions=0; |
---|
3712 |   int printMode=0; |
---|
3713 |   int presolveOptions=0; |
---|
3714 |   int substitution=3; |
---|
3715 |   int dualize=3; |
---|
3716 |   int doCrash=0; |
---|
3717 |   int doVector=0; |
---|
3718 |   int doSprint=-1; |
---|
3719 |   int doScaling=4; |
---|
3720 | Â Â // set reasonable defaults |
---|
3721 |   int preSolve=5; |
---|
3722 |   int preProcess=4; |
---|
3723 |   bool useStrategy=false; |
---|
3724 |   bool preSolveFile=false; |
---|
3725 |   bool strongChanged=false; |
---|
3726 | Â Â |
---|
3727 |   double djFix=1.0e100; |
---|
3728 |   double gapRatio=1.0e100; |
---|
3729 |   double tightenFactor=0.0; |
---|
3730 |   const char dirsep = CoinFindDirSeparator(); |
---|
3731 | Â Â std::string directory; |
---|
3732 | Â Â std::string dirSample; |
---|
3733 | Â Â std::string dirNetlib; |
---|
3734 | Â Â std::string dirMiplib; |
---|
3735 |   if (dirsep == '/') { |
---|
3736 | Â Â Â directory =Â "./"; |
---|
3737 | Â Â Â dirSample =Â "../../Data/Sample/"; |
---|
3738 | Â Â Â dirNetlib =Â "../../Data/Netlib/"; |
---|
3739 | Â Â Â dirMiplib =Â "../../Data/miplib3/"; |
---|
3740 |   } else { |
---|
3741 | Â Â Â directory =Â ".\\"; |
---|
3742 | Â Â Â dirSample =Â "..\\..\\Data\\Sample\\"; |
---|
3743 | Â Â Â dirNetlib =Â "..\\..\\Data\\Netlib\\"; |
---|
3744 | Â Â Â dirMiplib =Â "..\\..\\Data\\miplib3\\"; |
---|
3745 | Â Â } |
---|
3746 | Â Â std::string defaultDirectory =Â directory; |
---|
3747 | Â Â std::string importFile =""; |
---|
3748 | Â Â std::string exportFile ="default.mps"; |
---|
3749 | Â Â std::string importBasisFile =""; |
---|
3750 | Â Â std::string importPriorityFile =""; |
---|
3751 | Â Â std::string debugFile=""; |
---|
3752 | Â Â std::string printMask=""; |
---|
3753 |   double * debugValues = NULL; |
---|
3754 |   int numberDebugValues = -1; |
---|
3755 |   int basisHasValues=0; |
---|
3756 | Â Â std::string exportBasisFile ="default.bas"; |
---|
3757 | Â Â std::string saveFile ="default.prob"; |
---|
3758 | Â Â std::string restoreFile ="default.prob"; |
---|
3759 | Â Â std::string solutionFile ="stdout"; |
---|
3760 | Â Â std::string solutionSaveFile ="solution.file"; |
---|
3761 |   int slog = whichParam(SOLVERLOGLEVEL,numberParameters_,parameters_); |
---|
3762 |   int log = whichParam(LOGLEVEL,numberParameters_,parameters_); |
---|
3763 |   double normalIncrement=model_.getCutoffIncrement();; |
---|
3764 |   if (testOsiParameters>=0) { |
---|
3765 | Â Â Â // trying nonlinear - switch off some stuff |
---|
3766 | Â Â Â preProcess=0; |
---|
3767 | Â Â } |
---|
3768 | Â Â // Set up likely cut generators and defaults |
---|
3769 |   int nodeStrategy=0; |
---|
3770 |   int doSOS=1; |
---|
3771 |   int verbose=0; |
---|
3772 | Â Â CglGomory gomoryGen; |
---|
3773 | Â Â // try larger limit |
---|
3774 | Â Â gomoryGen.setLimitAtRoot(512); |
---|
3775 | Â Â gomoryGen.setLimit(50); |
---|
3776 | Â Â // set default action (0=off,1=on,2=root) |
---|
3777 |   int gomoryAction=3; |
---|
3778 | |
---|
3779 | Â Â CglProbing probingGen; |
---|
3780 | Â Â probingGen.setUsingObjective(1); |
---|
3781 | Â Â probingGen.setMaxPass(1); |
---|
3782 | Â Â probingGen.setMaxPassRoot(1); |
---|
3783 | Â Â // Number of unsatisfied variables to look at |
---|
3784 | Â Â probingGen.setMaxProbe(10); |
---|
3785 | Â Â probingGen.setMaxProbeRoot(50); |
---|
3786 | Â Â // How far to follow the consequences |
---|
3787 | Â Â probingGen.setMaxLook(10); |
---|
3788 | Â Â probingGen.setMaxLookRoot(50); |
---|
3789 | Â Â probingGen.setMaxLookRoot(10); |
---|
3790 | Â Â // Only look at rows with fewer than this number of elements |
---|
3791 | Â Â probingGen.setMaxElements(200); |
---|
3792 | Â Â probingGen.setRowCuts(3); |
---|
3793 | Â Â // set default action (0=off,1=on,2=root) |
---|
3794 |   int probingAction=1; |
---|
3795 | |
---|
3796 | Â Â CglKnapsackCover knapsackGen; |
---|
3797 | Â Â //knapsackGen.switchOnExpensive(); |
---|
3798 | Â Â // set default action (0=off,1=on,2=root) |
---|
3799 |   int knapsackAction=3; |
---|
3800 | |
---|
3801 | Â Â CglRedSplit redsplitGen; |
---|
3802 | Â Â //redsplitGen.setLimit(100); |
---|
3803 | Â Â // set default action (0=off,1=on,2=root) |
---|
3804 | Â Â // Off as seems to give some bad cuts |
---|
3805 |   int redsplitAction=0; |
---|
3806 | |
---|
3807 | Â Â CglClique cliqueGen(false,true); |
---|
3808 | Â Â cliqueGen.setStarCliqueReport(false); |
---|
3809 | Â Â cliqueGen.setRowCliqueReport(false); |
---|
3810 | Â Â cliqueGen.setMinViolation(0.1); |
---|
3811 | Â Â // set default action (0=off,1=on,2=root) |
---|
3812 |   int cliqueAction=3; |
---|
3813 | |
---|
3814 | Â Â CglMixedIntegerRounding2 mixedGen; |
---|
3815 | Â Â // set default action (0=off,1=on,2=root) |
---|
3816 |   int mixedAction=3; |
---|
3817 | |
---|
3818 | Â Â CglFlowCover flowGen; |
---|
3819 | Â Â // set default action (0=off,1=on,2=root) |
---|
3820 |   int flowAction=3; |
---|
3821 | |
---|
3822 | Â Â CglTwomir twomirGen; |
---|
3823 | Â Â twomirGen.setMaxElements(250); |
---|
3824 | Â Â // set default action (0=off,1=on,2=root) |
---|
3825 |   int twomirAction=2; |
---|
3826 | Â Â CglLandP landpGen; |
---|
3827 | Â Â // set default action (0=off,1=on,2=root) |
---|
3828 |   int landpAction=0; |
---|
3829 | Â Â CglResidualCapacity residualCapacityGen; |
---|
3830 | Â Â // set default action (0=off,1=on,2=root) |
---|
3831 |   int residualCapacityAction=0; |
---|
3832 | Â Â // Stored cuts |
---|
3833 |   bool storedCuts = false; |
---|
3834 | |
---|
3835 |   int useCosts=0; |
---|
3836 | Â Â // don't use input solution |
---|
3837 |   int useSolution=0; |
---|
3838 | Â Â |
---|
3839 | Â Â // total number of commands read |
---|
3840 |   int numberGoodCommands=0; |
---|
3841 | Â Â // Set false if user does anything advanced |
---|
3842 |   bool defaultSettings=true; |
---|
3843 | |
---|
3844 | Â Â // Hidden stuff for barrier |
---|
3845 |   int choleskyType = 0; |
---|
3846 |   int gamma=0; |
---|
3847 |   int scaleBarrier=0; |
---|
3848 |   int doKKT=0; |
---|
3849 |   int crossover=2; // do crossover unless quadratic |
---|
3850 | Â Â // For names |
---|
3851 |   int lengthName = 0; |
---|
3852 | Â Â std::vector<std::string>Â rowNames; |
---|
3853 | Â Â std::vector<std::string>Â columnNames; |
---|
3854 | Â Â |
---|
3855 | Â Â std::string field; |
---|
3856 |   if (!noPrinting_) { |
---|
3857 | Â Â Â sprintf(generalPrint,"Coin Cbc and Clp Solver version %s, build %s", |
---|
3858 | Â Â Â Â Â Â Â CBCVERSION,__DATE__); |
---|
3859 | Â Â Â generalMessageHandler->message(CLP_GENERAL,generalMessages) |
---|
3860 | Â Â Â Â <<Â generalPrint |
---|
3861 | Â Â Â Â <<CoinMessageEol; |
---|
3862 | Â Â Â // Print command line |
---|
3863 |    if (argc>1) { |
---|
3864 | Â Â Â Â sprintf(generalPrint,"command line - "); |
---|
3865 |     for (int i=0;i<argc;i++) { |
---|
3866 |      if (!argv[i]) |
---|
3867 | Â Â Â Â Â Â break; |
---|
3868 | Â Â Â Â Â sprintf(generalPrint+strlen(generalPrint),"%s ",argv[i]); |
---|
3869 | Â Â Â Â } |
---|
3870 | Â Â Â Â generalMessageHandler->message(CLP_GENERAL,generalMessages) |
---|
3871 | Â Â Â Â Â <<Â generalPrint |
---|
3872 | Â Â Â Â Â <<CoinMessageEol; |
---|
3873 | Â Â Â } |
---|
3874 | Â Â } |
---|
3875 |   while (1) { |
---|
3876 | Â Â Â // next command |
---|
3877 | Â Â Â field=CoinReadGetCommand(argc,argv); |
---|
3878 | Â Â Â // Reset time |
---|
3879 | Â Â Â time1 =Â CoinCpuTime(); |
---|
3880 | Â Â Â // adjust field if has odd trailing characters |
---|
3881 |    char temp [200]; |
---|
3882 | Â Â Â strcpy(temp,field.c_str()); |
---|
3883 |    int length = strlen(temp); |
---|
3884 |    for (int k=length-1;k>=0;k--) { |
---|
3885 |     if (temp[k]<' ') |
---|
3886 | Â Â Â Â Â length--; |
---|
3887 | Â Â Â Â else |
---|
3888 | Â Â Â Â Â break; |
---|
3889 | Â Â Â } |
---|
3890 | Â Â Â temp[length]='\0'; |
---|
3891 | Â Â Â field=temp; |
---|
3892 | Â Â Â // exit if null or similar |
---|
3893 |    if (!field.length()) { |
---|
3894 |     if (numberGoodCommands==1&&goodModel) { |
---|
3895 | Â Â Â Â Â // we just had file name - do branch and bound |
---|
3896 | Â Â Â Â Â field="branch"; |
---|
3897 |     } else if (!numberGoodCommands) { |
---|
3898 | Â Â Â Â Â // let's give the sucker a hint |
---|
3899 | Â Â Â Â Â std::cout |
---|
3900 | Â Â Â Â Â Â <<"CoinSolver takes input from arguments ( - switches to stdin)" |
---|
3901 | Â Â Â Â Â Â <<std::endl |
---|
3902 | Â Â Â Â Â Â <<"Enter ? for list of commands or help"<<std::endl; |
---|
3903 | Â Â Â Â Â field="-"; |
---|
3904 |     } else { |
---|
3905 | Â Â Â Â Â break; |
---|
3906 | Â Â Â Â } |
---|
3907 | Â Â Â } |
---|
3908 | Â Â Â |
---|
3909 | Â Â Â // see if ? at end |
---|
3910 |    int numberQuery=0; |
---|
3911 |    if (field!="?"&&field!="???") { |
---|
3912 |     int length = field.length(); |
---|
3913 |     int i; |
---|
3914 |     for (i=length-1;i>0;i--) { |
---|
3915 |      if (field[i]=='?') |
---|
3916 | Â Â Â Â Â Â numberQuery++; |
---|
3917 | Â Â Â Â Â else |
---|
3918 | Â Â Â Â Â Â break; |
---|
3919 | Â Â Â Â } |
---|
3920 | Â Â Â Â field=field.substr(0,length-numberQuery); |
---|
3921 | Â Â Â } |
---|
3922 | Â Â Â // find out if valid command |
---|
3923 |    int iParam; |
---|
3924 |    int numberMatches=0; |
---|
3925 |    int firstMatch=-1; |
---|
3926 |    for ( iParam=0; iParam<numberParameters_; iParam++ ) { |
---|
3927 |     int match = parameters_[iParam].matches(field); |
---|
3928 |     if (match==1) { |
---|
3929 | Â Â Â Â Â numberMatches =Â 1; |
---|
3930 | Â Â Â Â Â firstMatch=iParam; |
---|
3931 | Â Â Â Â Â break; |
---|
3932 |     } else { |
---|
3933 |      if (match&&firstMatch<0) |
---|
3934 | Â Â Â Â Â Â firstMatch=iParam; |
---|
3935 | Â Â Â Â Â numberMatches +=Â match>>1; |
---|
3936 | Â Â Â Â } |
---|
3937 | Â Â Â } |
---|
3938 |    if (iParam<numberParameters_&&!numberQuery) { |
---|
3939 | Â Â Â Â // found |
---|
3940 | Â Â Â Â CbcOrClpParam found =Â parameters_[iParam]; |
---|
3941 | Â Â Â Â CbcOrClpParameterType type =Â found.type(); |
---|
3942 |     int valid; |
---|
3943 | Â Â Â Â numberGoodCommands++; |
---|
3944 |     if (type==BAB&&goodModel) { |
---|
3945 | Â Â Â Â Â // check if any integers |
---|
3946 | #ifdef COIN_HAS_ASL |
---|
3947 |      if (info.numberSos&&doSOS&&statusUserFunction_[0]) { |
---|
3948 | Â Â Â Â Â Â // SOS |
---|
3949 | Â Â Â Â Â Â numberSOS =Â info.numberSos; |
---|
3950 | Â Â Â Â Â } |
---|
3951 | #endif |
---|
3952 | Â Â Â Â Â lpSolver =Â clpSolver->getModelPtr(); |
---|
3953 |      if (!lpSolver->integerInformation()&&!numberSOS&& |
---|
3954 | Â Â Â Â Â Â Â !clpSolver->numberSOS()&&!model_.numberObjects()&&!clpSolver->numberObjects()) |
---|
3955 | Â Â Â Â Â Â type=DUALSIMPLEX; |
---|
3956 | Â Â Â Â } |
---|
3957 |     if (type==GENERALQUERY) { |
---|
3958 |      bool evenHidden=false; |
---|
3959 |      if ((verbose&8)!=0) { |
---|
3960 | Â Â Â Â Â Â // even hidden |
---|
3961 | Â Â Â Â Â Â evenHidden =Â true; |
---|
3962 | Â Â Â Â Â Â verbose &=Â ~8; |
---|
3963 | Â Â Â Â Â } |
---|
3964 | #ifdef COIN_HAS_ASL |
---|
3965 |      if (verbose<4&&statusUserFunction_[0]) |
---|
3966 | Â Â Â Â Â Â verbose +=4; |
---|
3967 | #endif |
---|
3968 |      if (verbose<4) { |
---|
3969 | Â Â Â Â Â Â std::cout<<"In argument list keywords have leading - " |
---|
3970 | Â Â Â Â Â Â Â ", -stdin or just - switches to stdin"<<std::endl; |
---|
3971 | Â Â Â Â Â Â std::cout<<"One command per line (and no -)"<<std::endl; |
---|
3972 | Â Â Â Â Â Â std::cout<<"abcd? gives list of possibilities, if only one + explanation"<<std::endl; |
---|
3973 | Â Â Â Â Â Â std::cout<<"abcd?? adds explanation, if only one fuller help"<<std::endl; |
---|
3974 | Â Â Â Â Â Â std::cout<<"abcd without value (where expected) gives current value"<<std::endl; |
---|
3975 | Â Â Â Â Â Â std::cout<<"abcd value sets value"<<std::endl; |
---|
3976 | Â Â Â Â Â Â std::cout<<"Commands are:"<<std::endl; |
---|
3977 |      } else { |
---|
3978 | Â Â Â Â Â Â std::cout<<"Cbc options are set within AMPL with commands like:"<<std::endl<<std::endl; |
---|
3979 | Â Â Â Â Â Â std::cout<<"Â Â Â Â Â option cbc_options \"cuts=root log=2 feas=on slog=1\""<<std::endl<<std::endl; |
---|
3980 | Â Â Â Â Â Â std::cout<<"only maximize, dual, primal, help and quit are recognized without ="<<std::endl; |
---|
3981 | Â Â Â Â Â } |
---|
3982 |      int maxAcross=5; |
---|
3983 |      if ((verbose%4)!=0) |
---|
3984 | Â Â Â Â Â Â maxAcross=1; |
---|
3985 |      int limits[]={1,51,101,151,201,251,301,351,401}; |
---|
3986 | Â Â Â Â Â std::vector<std::string>Â types; |
---|
3987 | Â Â Â Â Â types.push_back("Double parameters:"); |
---|
3988 | Â Â Â Â Â types.push_back("Branch and Cut double parameters:"); |
---|
3989 | Â Â Â Â Â types.push_back("Integer parameters:"); |
---|
3990 | Â Â Â Â Â types.push_back("Branch and Cut integer parameters:"); |
---|
3991 | Â Â Â Â Â types.push_back("Keyword parameters:"); |
---|
3992 | Â Â Â Â Â types.push_back("Branch and Cut keyword parameters:"); |
---|
3993 | Â Â Â Â Â types.push_back("Actions or string parameters:"); |
---|
3994 | Â Â Â Â Â types.push_back("Branch and Cut actions:"); |
---|
3995 |      int iType; |
---|
3996 |      for (iType=0;iType<8;iType++) { |
---|
3997 |       int across=0; |
---|
3998 |       if ((verbose%4)!=0) |
---|
3999 | Â Â Â Â Â Â Â std::cout<<std::endl; |
---|
4000 | Â Â Â Â Â Â std::cout<<types[iType]<<std::endl; |
---|
4001 |       if ((verbose&2)!=0) |
---|
4002 | Â Â Â Â Â Â Â std::cout<<std::endl; |
---|
4003 |       for ( iParam=0; iParam<numberParameters_; iParam++ ) { |
---|
4004 |        int type = parameters_[iParam].type(); |
---|
4005 |        if ((parameters_[iParam].displayThis()||evenHidden)&& |
---|
4006 | Â Â Â Â Â Â Â Â Â type>=limits[iType] |
---|
4007 | Â Â Â Â Â Â Â Â Â &&type<limits[iType+1])Â { |
---|
4008 | Â Â Â Â Â Â Â Â // but skip if not useful for ampl (and in ampl mode) |
---|
4009 |         if (verbose>=4&&(parameters_[iParam].whereUsed()&4)==0) |
---|
4010 | Â Â Â Â Â Â Â Â Â continue; |
---|
4011 |         if (!across) { |
---|
4012 |          if ((verbose&2)==0) |
---|
4013 | Â Â Â Â Â Â Â Â Â Â std::cout<<"Â "; |
---|
4014 | Â Â Â Â Â Â Â Â Â else |
---|
4015 | Â Â Â Â Â Â Â Â Â Â std::cout<<"Command "; |
---|
4016 | Â Â Â Â Â Â Â Â } |
---|
4017 | Â Â Â Â Â Â Â Â std::cout<<parameters_[iParam].matchName()<<"Â "; |
---|
4018 | Â Â Â Â Â Â Â Â across++; |
---|
4019 |         if (across==maxAcross) { |
---|
4020 | Â Â Â Â Â Â Â Â Â across=0; |
---|
4021 |          if ((verbose%4)!=0) { |
---|
4022 | Â Â Â Â Â Â Â Â Â Â // put out description as well |
---|
4023 |           if ((verbose&1)!=0) |
---|
4024 | Â Â Â Â Â Â Â Â Â Â Â std::cout<<parameters_[iParam].shortHelp(); |
---|
4025 | Â Â Â Â Â Â Â Â Â Â std::cout<<std::endl; |
---|
4026 |           if ((verbose&2)!=0) { |
---|
4027 | Â Â Â Â Â Â Â Â Â Â Â std::cout<<"---- description"<<std::endl; |
---|
4028 | Â Â Â Â Â Â Â Â Â Â Â parameters_[iParam].printLongHelp(); |
---|
4029 | Â Â Â Â Â Â Â Â Â Â Â std::cout<<"----"<<std::endl<<std::endl; |
---|
4030 | Â Â Â Â Â Â Â Â Â Â } |
---|
4031 |          } else { |
---|
4032 | Â Â Â Â Â Â Â Â Â Â std::cout<<std::endl; |
---|
4033 | Â Â Â Â Â Â Â Â Â } |
---|
4034 | Â Â Â Â Â Â Â Â } |
---|
4035 | Â Â Â Â Â Â Â } |
---|
4036 | Â Â Â Â Â Â } |
---|
4037 |       if (across) |
---|
4038 | Â Â Â Â Â Â Â std::cout<<std::endl; |
---|
4039 | Â Â Â Â Â } |
---|
4040 |     } else if (type==FULLGENERALQUERY) { |
---|
4041 | Â Â Â Â Â std::cout<<"Full list of commands is:"<<std::endl; |
---|
4042 |      int maxAcross=5; |
---|
4043 |      int limits[]={1,51,101,151,201,251,301,351,401}; |
---|
4044 | Â Â Â Â Â std::vector<std::string>Â types; |
---|
4045 | Â Â Â Â Â types.push_back("Double parameters:"); |
---|
4046 | Â Â Â Â Â types.push_back("Branch and Cut double parameters:"); |
---|
4047 | Â Â Â Â Â types.push_back("Integer parameters:"); |
---|
4048 | Â Â Â Â Â types.push_back("Branch and Cut integer parameters:"); |
---|
4049 | Â Â Â Â Â types.push_back("Keyword parameters:"); |
---|
4050 | Â Â Â Â Â types.push_back("Branch and Cut keyword parameters:"); |
---|
4051 | Â Â Â Â Â types.push_back("Actions or string parameters:"); |
---|
4052 | Â Â Â Â Â types.push_back("Branch and Cut actions:"); |
---|
4053 |      int iType; |
---|
4054 |      for (iType=0;iType<8;iType++) { |
---|
4055 |       int across=0; |
---|
4056 | Â Â Â Â Â Â std::cout<<types[iType]<<"Â "; |
---|
4057 |       for ( iParam=0; iParam<numberParameters_; iParam++ ) { |
---|
4058 |        int type = parameters_[iParam].type(); |
---|
4059 |        if (type>=limits[iType] |
---|
4060 | Â Â Â Â Â Â Â Â Â &&type<limits[iType+1])Â { |
---|
4061 |         if (!across) |
---|
4062 | Â Â Â Â Â Â Â Â Â std::cout<<"Â "; |
---|
4063 | Â Â Â Â Â Â Â Â std::cout<<parameters_[iParam].matchName()<<"Â "; |
---|
4064 | Â Â Â Â Â Â Â Â across++; |
---|
4065 |         if (across==maxAcross) { |
---|
4066 | Â Â Â Â Â Â Â Â Â std::cout<<std::endl; |
---|
4067 | Â Â Â Â Â Â Â Â Â across=0; |
---|
4068 | Â Â Â Â Â Â Â Â } |
---|
4069 | Â Â Â Â Â Â Â } |
---|
4070 | Â Â Â Â Â Â } |
---|
4071 |       if (across) |
---|
4072 | Â Â Â Â Â Â Â std::cout<<std::endl; |
---|
4073 | Â Â Â Â Â } |
---|
4074 |     } else if (type<101) { |
---|
4075 | Â Â Â Â Â // get next field as double |
---|
4076 |      double value = CoinReadGetDoubleField(argc,argv,&valid); |
---|
4077 |      if (!valid) { |
---|
4078 |       if (type<51) { |
---|
4079 | Â Â Â Â Â Â Â parameters_[iParam].setDoubleParameter(lpSolver,value); |
---|
4080 |       } else if (type<81) { |
---|
4081 | Â Â Â Â Â Â Â parameters_[iParam].setDoubleParameter(model_,value); |
---|
4082 |       } else { |
---|
4083 | Â Â Â Â Â Â Â parameters_[iParam].setDoubleParameter(lpSolver,value); |
---|
4084 | Â Â Â Â Â Â Â switch(type)Â { |
---|
4085 |        case DJFIX: |
---|
4086 | Â Â Â Â Â Â Â Â djFix=value; |
---|
4087 |         if (goodModel&&djFix<1.0e20) { |
---|
4088 | Â Â Â Â Â Â Â Â Â // do some fixing |
---|
4089 | Â Â Â Â Â Â Â Â Â clpSolver =Â dynamic_cast<Â OsiClpSolverInterface*>Â (model_.solver()); |
---|
4090 | Â Â Â Â Â Â Â Â Â clpSolver->initialSolve(); |
---|
4091 | Â Â Â Â Â Â Â Â Â lpSolver =Â clpSolver->getModelPtr(); |
---|
4092 |          int numberColumns = lpSolver->numberColumns(); |
---|
4093 |          int i; |
---|
4094 |          const char * type = lpSolver->integerInformation(); |
---|
4095 |          double * lower = lpSolver->columnLower(); |
---|
4096 |          double * upper = lpSolver->columnUpper(); |
---|
4097 |          double * solution = lpSolver->primalColumnSolution(); |
---|
4098 |          double * dj = lpSolver->dualColumnSolution(); |
---|
4099 |          int numberFixed=0; |
---|
4100 |          double dextra4 = parameters_[whichParam(DEXTRA4,numberParameters_,parameters_)].doubleValue(); |
---|
4101 |          if (dextra4) |
---|
4102 | Â Â Â Â Â Â Â Â Â Â printf("Multiple for continuous dj fixing is %g\n",dextra4); |
---|
4103 |          for (i=0;i<numberColumns;i++) { |
---|
4104 |           double djValue = dj[i]; |
---|
4105 |           if (!type[i]) |
---|
4106 | Â Â Â Â Â Â Â Â Â Â Â djValue *=Â dextra4; |
---|
4107 |           if (type[i]||dextra4) { |
---|
4108 |            double value = solution[i]; |
---|
4109 |            if (value<lower[i]+1.0e-5&&djValue>djFix) { |
---|
4110 | Â Â Â Â Â Â Â Â Â Â Â Â solution[i]=lower[i]; |
---|
4111 | Â Â Â Â Â Â Â Â Â Â Â Â upper[i]=lower[i]; |
---|
4112 | Â Â Â Â Â Â Â Â Â Â Â Â numberFixed++; |
---|
4113 |            } else if (value>upper[i]-1.0e-5&&djValue<-djFix) { |
---|
4114 | Â Â Â Â Â Â Â Â Â Â Â Â solution[i]=upper[i]; |
---|
4115 | Â Â Â Â Â Â Â Â Â Â Â Â lower[i]=upper[i]; |
---|
4116 | Â Â Â Â Â Â Â Â Â Â Â Â numberFixed++; |
---|
4117 | Â Â Â Â Â Â Â Â Â Â Â } |
---|
4118 | Â Â Â Â Â Â Â Â Â Â } |
---|
4119 | Â Â Â Â Â Â Â Â Â } |
---|
4120 | Â Â Â Â Â Â Â Â Â sprintf(generalPrint,"%d columns fixed\n",numberFixed); |
---|
4121 | Â Â Â Â Â Â Â Â Â generalMessageHandler->message(CLP_GENERAL,generalMessages) |
---|
4122 | Â Â Â Â Â Â Â Â Â Â <<Â generalPrint |
---|
4123 | Â Â Â Â Â Â Â Â Â Â <<CoinMessageEol; |
---|
4124 | Â Â Â Â Â Â Â Â } |
---|
4125 | Â Â Â Â Â Â Â Â break; |
---|
4126 |        case GAPRATIO: |
---|
4127 | Â Â Â Â Â Â Â Â gapRatio=value; |
---|
4128 | Â Â Â Â Â Â Â Â break; |
---|
4129 |        case TIGHTENFACTOR: |
---|
4130 | Â Â Â Â Â Â Â Â tightenFactor=value; |
---|
4131 | Â Â Â Â Â Â Â Â if(!complicatedInteger) |
---|
4132 | Â Â Â Â Â Â Â Â Â defaultSettings=false;Â // user knows what she is doing |
---|
4133 | Â Â Â Â Â Â Â Â break; |
---|
4134 | Â Â Â Â Â Â Â default: |
---|
4135 | Â Â Â Â Â Â Â Â break; |
---|
4136 | Â Â Â Â Â Â Â } |
---|
4137 | Â Â Â Â Â Â } |
---|
4138 |      } else if (valid==1) { |
---|
4139 | Â Â Â Â Â Â std::cout<<" is illegal for double parameter "<<parameters_[iParam].name()<<" value remains "<< |
---|
4140 | Â Â Â Â Â Â Â parameters_[iParam].doubleValue()<<std::endl; |
---|
4141 |      } else { |
---|
4142 | Â Â Â Â Â Â std::cout<<parameters_[iParam].name()<<" has value "<< |
---|
4143 | Â Â Â Â Â Â Â parameters_[iParam].doubleValue()<<std::endl; |
---|
4144 | Â Â Â Â Â } |
---|
4145 |     } else if (type<201) { |
---|
4146 | Â Â Â Â Â // get next field as int |
---|
4147 |      int value = CoinReadGetIntField(argc,argv,&valid); |
---|
4148 |      if (!valid) { |
---|
4149 |       if (type<151) { |
---|
4150 |        if (parameters_[iParam].type()==PRESOLVEPASS) |
---|
4151 | Â Â Â Â Â Â Â Â preSolve =Â value; |
---|
4152 |        else if (parameters_[iParam].type()==IDIOT) |
---|
4153 | Â Â Â Â Â Â Â Â doIdiot =Â value; |
---|
4154 |        else if (parameters_[iParam].type()==SPRINT) |
---|
4155 | Â Â Â Â Â Â Â Â doSprint =Â value; |
---|
4156 |        else if (parameters_[iParam].type()==OUTPUTFORMAT) |
---|
4157 | Â Â Â Â Â Â Â Â outputFormat =Â value; |
---|
4158 |        else if (parameters_[iParam].type()==SLPVALUE) |
---|
4159 | Â Â Â Â Â Â Â Â slpValue =Â value; |
---|
4160 |        else if (parameters_[iParam].type()==CPP) |
---|
4161 | Â Â Â Â Â Â Â Â cppValue =Â value; |
---|
4162 |        else if (parameters_[iParam].type()==PRESOLVEOPTIONS) |
---|
4163 | Â Â Â Â Â Â Â Â presolveOptions =Â value; |
---|
4164 |        else if (parameters_[iParam].type()==PRINTOPTIONS) |
---|
4165 | Â Â Â Â Â Â Â Â printOptions =Â value; |
---|
4166 |        else if (parameters_[iParam].type()==SUBSTITUTION) |
---|
4167 | Â Â Â Â Â Â Â Â substitution =Â value; |
---|
4168 |        else if (parameters_[iParam].type()==DUALIZE) |
---|
4169 | Â Â Â Â Â Â Â Â dualize =Â value; |
---|
4170 |        else if (parameters_[iParam].type()==PROCESSTUNE) |
---|
4171 | Â Â Â Â Â Â Â Â tunePreProcess =Â value; |
---|
4172 |        else if (parameters_[iParam].type()==VERBOSE) |
---|
4173 | Â Â Â Â Â Â Â Â verbose =Â value; |
---|
4174 | Â Â Â Â Â Â Â parameters_[iParam].setIntParameter(lpSolver,value); |
---|
4175 |       } else { |
---|
4176 |        if (parameters_[iParam].type()==CUTPASS) |
---|
4177 | Â Â Â Â Â Â Â Â cutPass =Â value; |
---|
4178 |        else if (parameters_[iParam].type()==CUTPASSINTREE) |
---|
4179 | Â Â Â Â Â Â Â Â cutPassInTree =Â value; |
---|
4180 |        else if (parameters_[iParam].type()==STRONGBRANCHING|| |
---|
4181 | Â Â Â Â Â Â Â Â Â Â Â Â parameters_[iParam].type()==NUMBERBEFORE) |
---|
4182 | Â Â Â Â Â Â Â Â strongChanged=true; |
---|
4183 | Â Â Â Â Â Â Â parameters_[iParam].setIntParameter(model_,value); |
---|
4184 | Â Â Â Â Â Â } |
---|
4185 |      } else if (valid==1) { |
---|
4186 | Â Â Â Â Â Â std::cout<<" is illegal for integer parameter "<<parameters_[iParam].name()<<" value remains "<< |
---|
4187 | Â Â Â Â Â Â Â parameters_[iParam].intValue()<<std::endl; |
---|
4188 |      } else { |
---|
4189 | Â Â Â Â Â Â std::cout<<parameters_[iParam].name()<<" has value "<< |
---|
4190 | Â Â Â Â Â Â Â parameters_[iParam].intValue()<<std::endl; |
---|
4191 | Â Â Â Â Â } |
---|
4192 |     } else if (type<301) { |
---|
4193 | Â Â Â Â Â // one of several strings |
---|
4194 | Â Â Â Â Â std::string value =Â CoinReadGetString(argc,argv); |
---|
4195 |      int action = parameters_[iParam].parameterOption(value); |
---|
4196 |      if (action<0) { |
---|
4197 |       if (value!="EOL") { |
---|
4198 | Â Â Â Â Â Â Â // no match |
---|
4199 | Â Â Â Â Â Â Â parameters_[iParam].printOptions(); |
---|
4200 |       } else { |
---|
4201 | Â Â Â Â Â Â Â // print current value |
---|
4202 | Â Â Â Â Â Â Â std::cout<<parameters_[iParam].name()<<" has value "<< |
---|
4203 | Â Â Â Â Â Â Â Â parameters_[iParam].currentOption()<<std::endl; |
---|
4204 | Â Â Â Â Â Â } |
---|
4205 |      } else { |
---|
4206 | Â Â Â Â Â Â parameters_[iParam].setCurrentOption(action,!noPrinting_); |
---|
4207 | Â Â Â Â Â Â // for now hard wired |
---|
4208 |       switch (type) { |
---|
4209 |       case DIRECTION: |
---|
4210 |        if (action==0) |
---|
4211 | Â Â Â Â Â Â Â Â lpSolver->setOptimizationDirection(1); |
---|
4212 |        else if (action==1) |
---|
4213 | Â Â Â Â Â Â Â Â lpSolver->setOptimizationDirection(-1); |
---|
4214 | Â Â Â Â Â Â Â else |
---|
4215 | Â Â Â Â Â Â Â Â lpSolver->setOptimizationDirection(0); |
---|
4216 | Â Â Â Â Â Â Â break; |
---|
4217 |       case DUALPIVOT: |
---|
4218 |        if (action==0) { |
---|
4219 | Â Â Â Â Â Â Â Â ClpDualRowSteepest steep(3); |
---|
4220 | Â Â Â Â Â Â Â Â lpSolver->setDualRowPivotAlgorithm(steep); |
---|
4221 |        } else if (action==1) { |
---|
4222 | Â Â Â Â Â Â Â Â //ClpDualRowDantzig dantzig; |
---|
4223 | Â Â Â Â Â Â Â Â ClpDualRowSteepest dantzig(5); |
---|
4224 | Â Â Â Â Â Â Â Â lpSolver->setDualRowPivotAlgorithm(dantzig); |
---|
4225 |        } else if (action==2) { |
---|
4226 | Â Â Â Â Â Â Â Â // partial steep |
---|
4227 | Â Â Â Â Â Â Â Â ClpDualRowSteepest steep(2); |
---|
4228 | Â Â Â Â Â Â Â Â lpSolver->setDualRowPivotAlgorithm(steep); |
---|
4229 |        } else { |
---|
4230 | Â Â Â Â Â Â Â Â ClpDualRowSteepest steep; |
---|
4231 | Â Â Â Â Â Â Â Â lpSolver->setDualRowPivotAlgorithm(steep); |
---|
4232 | Â Â Â Â Â Â Â } |
---|
4233 | Â Â Â Â Â Â Â break; |
---|
4234 |       case PRIMALPIVOT: |
---|
4235 |        if (action==0) { |
---|
4236 | Â Â Â Â Â Â Â Â ClpPrimalColumnSteepest steep(3); |
---|
4237 | Â Â Â Â Â Â Â Â lpSolver->setPrimalColumnPivotAlgorithm(steep); |
---|
4238 |        } else if (action==1) { |
---|
4239 | Â Â Â Â Â Â Â Â ClpPrimalColumnSteepest steep(0); |
---|
4240 | Â Â Â Â Â Â Â Â lpSolver->setPrimalColumnPivotAlgorithm(steep); |
---|
4241 |        } else if (action==2) { |
---|
4242 | Â Â Â Â Â Â Â Â ClpPrimalColumnDantzig dantzig; |
---|
4243 | Â Â Â Â Â Â Â Â lpSolver->setPrimalColumnPivotAlgorithm(dantzig); |
---|
4244 |        } else if (action==3) { |
---|
4245 | Â Â Â Â Â Â Â Â ClpPrimalColumnSteepest steep(4); |
---|
4246 | Â Â Â Â Â Â Â Â lpSolver->setPrimalColumnPivotAlgorithm(steep); |
---|
4247 |        } else if (action==4) { |
---|
4248 | Â Â Â Â Â Â Â Â ClpPrimalColumnSteepest steep(1); |
---|
4249 | Â Â Â Â Â Â Â Â lpSolver->setPrimalColumnPivotAlgorithm(steep); |
---|
4250 |        } else if (action==5) { |
---|
4251 | Â Â Â Â Â Â Â Â ClpPrimalColumnSteepest steep(2); |
---|
4252 | Â Â Â Â Â Â Â Â lpSolver->setPrimalColumnPivotAlgorithm(steep); |
---|
4253 |        } else if (action==6) { |
---|
4254 | Â Â Â Â Â Â Â Â ClpPrimalColumnSteepest steep(10); |
---|
4255 | Â Â Â Â Â Â Â Â lpSolver->setPrimalColumnPivotAlgorithm(steep); |
---|
4256 | Â Â Â Â Â Â Â } |
---|
4257 | Â Â Â Â Â Â Â break; |
---|
4258 |       case SCALING: |
---|
4259 | Â Â Â Â Â Â Â lpSolver->scaling(action); |
---|
4260 | Â Â Â Â Â Â Â solver->setHintParam(OsiDoScale,action!=0,OsiHintTry); |
---|
4261 | Â Â Â Â Â Â Â doScaling =Â action; |
---|
4262 | Â Â Â Â Â Â Â break; |
---|
4263 |       case AUTOSCALE: |
---|
4264 | Â Â Â Â Â Â Â lpSolver->setAutomaticScaling(action!=0); |
---|
4265 | Â Â Â Â Â Â Â break; |
---|
4266 |       case SPARSEFACTOR: |
---|
4267 | Â Â Â Â Â Â Â lpSolver->setSparseFactorization((1-action)!=0); |
---|
4268 | Â Â Â Â Â Â Â break; |
---|
4269 |       case BIASLU: |
---|
4270 | Â Â Â Â Â Â Â lpSolver->factorization()->setBiasLU(action); |
---|
4271 | Â Â Â Â Â Â Â break; |
---|
4272 |       case PERTURBATION: |
---|
4273 |        if (action==0) |
---|
4274 | Â Â Â Â Â Â Â Â lpSolver->setPerturbation(50); |
---|
4275 | Â Â Â Â Â Â Â else |
---|
4276 | Â Â Â Â Â Â Â Â lpSolver->setPerturbation(100); |
---|
4277 | Â Â Â Â Â Â Â break; |
---|
4278 |       case ERRORSALLOWED: |
---|
4279 | Â Â Â Â Â Â Â allowImportErrors =Â action; |
---|
4280 | Â Â Â Â Â Â Â break; |
---|
4281 |       case INTPRINT: |
---|
4282 | Â Â Â Â Â Â Â printMode=action; |
---|
4283 | Â Â Â Â Â Â Â break; |
---|
4284 | Â Â Â Â Â Â Â //case ALGORITHM: |
---|
4285 |        //algorithm = action; |
---|
4286 | Â Â Â Â Â Â Â //defaultSettings=false; // user knows what she is doing |
---|
4287 | Â Â Â Â Â Â Â //abort(); |
---|
4288 | Â Â Â Â Â Â Â //break; |
---|
4289 |       case KEEPNAMES: |
---|
4290 | Â Â Â Â Â Â Â keepImportNames =Â 1-action; |
---|
4291 | Â Â Â Â Â Â Â break; |
---|
4292 |       case PRESOLVE: |
---|
4293 |        if (action==0) |
---|
4294 | Â Â Â Â Â Â Â Â preSolve =Â 5; |
---|
4295 |        else if (action==1) |
---|
4296 | Â Â Â Â Â Â Â Â preSolve=0; |
---|
4297 |        else if (action==2) |
---|
4298 | Â Â Â Â Â Â Â Â preSolve=10; |
---|
4299 | Â Â Â Â Â Â Â else |
---|
4300 | Â Â Â Â Â Â Â Â preSolveFile=true; |
---|
4301 | Â Â Â Â Â Â Â break; |
---|
4302 |       case PFI: |
---|
4303 | Â Â Â Â Â Â Â lpSolver->factorization()->setForrestTomlin(action==0); |
---|
4304 | Â Â Â Â Â Â Â break; |
---|
4305 |       case CRASH: |
---|
4306 | Â Â Â Â Â Â Â doCrash=action; |
---|
4307 | Â Â Â Â Â Â Â break; |
---|
4308 |       case VECTOR: |
---|
4309 | Â Â Â Â Â Â Â doVector=action; |
---|
4310 | Â Â Â Â Â Â Â break; |
---|
4311 |       case MESSAGES: |
---|
4312 | Â Â Â Â Â Â Â lpSolver->messageHandler()->setPrefix(action!=0); |
---|
4313 | Â Â Â Â Â Â Â break; |
---|
4314 |       case CHOLESKY: |
---|
4315 | Â Â Â Â Â Â Â choleskyType =Â action; |
---|
4316 | Â Â Â Â Â Â Â break; |
---|
4317 |       case GAMMA: |
---|
4318 | Â Â Â Â Â Â Â gamma=action; |
---|
4319 | Â Â Â Â Â Â Â break; |
---|
4320 |       case BARRIERSCALE: |
---|
4321 | Â Â Â Â Â Â Â scaleBarrier=action; |
---|
4322 | Â Â Â Â Â Â Â break; |
---|
4323 |       case KKT: |
---|
4324 | Â Â Â Â Â Â Â doKKT=action; |
---|
4325 | Â Â Â Â Â Â Â break; |
---|
4326 |       case CROSSOVER: |
---|
4327 | Â Â Â Â Â Â Â crossover=action; |
---|
4328 | Â Â Â Â Â Â Â break; |
---|
4329 |       case SOS: |
---|
4330 | Â Â Â Â Â Â Â doSOS=action; |
---|
4331 | Â Â Â Â Â Â Â break; |
---|
4332 |       case GOMORYCUTS: |
---|
4333 | Â Â Â Â Â Â Â defaultSettings=false;Â // user knows what she is doing |
---|
4334 | Â Â Â Â Â Â Â gomoryAction =Â action; |
---|
4335 | Â Â Â Â Â Â Â break; |
---|
4336 |       case PROBINGCUTS: |
---|
4337 | Â Â Â Â Â Â Â defaultSettings=false;Â // user knows what she is doing |
---|
4338 | Â Â Â Â Â Â Â probingAction =Â action; |
---|
4339 | Â Â Â Â Â Â Â break; |
---|
4340 |       case KNAPSACKCUTS: |
---|
4341 | Â Â Â Â Â Â Â defaultSettings=false;Â // user knows what she is doing |
---|
4342 | Â Â Â Â Â Â Â knapsackAction =Â action; |
---|
4343 | Â Â Â Â Â Â Â break; |
---|
4344 |       case REDSPLITCUTS: |
---|
4345 | Â Â Â Â Â Â Â defaultSettings=false;Â // user knows what she is doing |
---|
4346 | Â Â Â Â Â Â Â redsplitAction =Â action; |
---|
4347 | Â Â Â Â Â Â Â break; |
---|
4348 |       case CLIQUECUTS: |
---|
4349 | Â Â Â Â Â Â Â defaultSettings=false;Â // user knows what she is doing |
---|
4350 | Â Â Â Â Â Â Â cliqueAction =Â action; |
---|
4351 | Â Â Â Â Â Â Â break; |
---|
4352 |       case FLOWCUTS: |
---|
4353 | Â Â Â Â Â Â Â defaultSettings=false;Â // user knows what she is doing |
---|
4354 | Â Â Â Â Â Â Â flowAction =Â action; |
---|
4355 | Â Â Â Â Â Â Â break; |
---|
4356 |       case MIXEDCUTS: |
---|
4357 | Â Â Â Â Â Â Â defaultSettings=false;Â // user knows what she is doing |
---|
4358 | Â Â Â Â Â Â Â mixedAction =Â action; |
---|
4359 | Â Â Â Â Â Â Â break; |
---|
4360 |       case TWOMIRCUTS: |
---|
4361 | Â Â Â Â Â Â Â defaultSettings=false;Â // user knows what she is doing |
---|
4362 | Â Â Â Â Â Â Â twomirAction =Â action; |
---|
4363 | Â Â Â Â Â Â Â break; |
---|
4364 |       case LANDPCUTS: |
---|
4365 | Â Â Â Â Â Â Â defaultSettings=false;Â // user knows what she is doing |
---|
4366 | Â Â Â Â Â Â Â landpAction =Â action; |
---|
4367 | Â Â Â Â Â Â Â break; |
---|
4368 |       case RESIDCUTS: |
---|
4369 | Â Â Â Â Â Â Â defaultSettings=false;Â // user knows what she is doing |
---|
4370 | Â Â Â Â Â Â Â residualCapacityAction =Â action; |
---|
4371 | Â Â Â Â Â Â Â break; |
---|
4372 |       case ROUNDING: |
---|
4373 | Â Â Â Â Â Â Â defaultSettings=false;Â // user knows what she is doing |
---|
4374 | Â Â Â Â Â Â Â break; |
---|
4375 |       case FPUMP: |
---|
4376 | Â Â Â Â Â Â Â defaultSettings=false;Â // user knows what she is doing |
---|
4377 | Â Â Â Â Â Â Â break; |
---|
4378 |       case RINS: |
---|
4379 | Â Â Â Â Â Â Â break; |
---|
4380 |       case CUTSSTRATEGY: |
---|
4381 | Â Â Â Â Â Â Â gomoryAction =Â action; |
---|
4382 | Â Â Â Â Â Â Â probingAction =Â action; |
---|
4383 | Â Â Â Â Â Â Â knapsackAction =Â action; |
---|
4384 | Â Â Â Â Â Â Â cliqueAction =Â action; |
---|
4385 | Â Â Â Â Â Â Â flowAction =Â action; |
---|
4386 | Â Â Â Â Â Â Â mixedAction =Â action; |
---|
4387 | Â Â Â Â Â Â Â twomirAction =Â action; |
---|
4388 | Â Â Â Â Â Â Â //landpAction = action; |
---|
4389 | Â Â Â Â Â Â Â parameters_[whichParam(GOMORYCUTS,numberParameters_,parameters_)].setCurrentOption(action); |
---|
4390 | Â Â Â Â Â Â Â parameters_[whichParam(PROBINGCUTS,numberParameters_,parameters_)].setCurrentOption(action); |
---|
4391 | Â Â Â Â Â Â Â parameters_[whichParam(KNAPSACKCUTS,numberParameters_,parameters_)].setCurrentOption(action); |
---|
4392 | Â Â Â Â Â Â Â parameters_[whichParam(CLIQUECUTS,numberParameters_,parameters_)].setCurrentOption(action); |
---|
4393 | Â Â Â Â Â Â Â parameters_[whichParam(FLOWCUTS,numberParameters_,parameters_)].setCurrentOption(action); |
---|
4394 | Â Â Â Â Â Â Â parameters_[whichParam(MIXEDCUTS,numberParameters_,parameters_)].setCurrentOption(action); |
---|
4395 | Â Â Â Â Â Â Â parameters_[whichParam(TWOMIRCUTS,numberParameters_,parameters_)].setCurrentOption(action); |
---|
4396 |        if (!action) { |
---|
4397 | Â Â Â Â Â Â Â Â redsplitAction =Â action; |
---|
4398 | Â Â Â Â Â Â Â Â parameters_[whichParam(REDSPLITCUTS,numberParameters_,parameters_)].setCurrentOption(action); |
---|
4399 | Â Â Â Â Â Â Â Â landpAction =Â action; |
---|
4400 | Â Â Â Â Â Â Â Â parameters_[whichParam(LANDPCUTS,numberParameters_,parameters_)].setCurrentOption(action); |
---|
4401 | Â Â Â Â Â Â Â Â residualCapacityAction =Â action; |
---|
4402 | Â Â Â Â Â Â Â Â parameters_[whichParam(RESIDCUTS,numberParameters_,parameters_)].setCurrentOption(action); |
---|
4403 | Â Â Â Â Â Â Â } |
---|
4404 | Â Â Â Â Â Â Â break; |
---|
4405 |       case HEURISTICSTRATEGY: |
---|
4406 | Â Â Â Â Â Â Â parameters_[whichParam(ROUNDING,numberParameters_,parameters_)].setCurrentOption(action); |
---|
4407 | Â Â Â Â Â Â Â parameters_[whichParam(GREEDY,numberParameters_,parameters_)].setCurrentOption(action); |
---|
4408 | Â Â Â Â Â Â Â parameters_[whichParam(COMBINE,numberParameters_,parameters_)].setCurrentOption(action); |
---|
4409 | Â Â Â Â Â Â Â //parameters_[whichParam(LOCALTREE,numberParameters_,parameters_)].setCurrentOption(action); |
---|
4410 | Â Â Â Â Â Â Â parameters_[whichParam(FPUMP,numberParameters_,parameters_)].setCurrentOption(action); |
---|
4411 | Â Â Â Â Â Â Â break; |
---|
4412 |       case GREEDY: |
---|
4413 | Â Â Â Â Â Â Â defaultSettings=false;Â // user knows what she is doing |
---|
4414 | Â Â Â Â Â Â Â break; |
---|
4415 |       case COMBINE: |
---|
4416 | Â Â Â Â Â Â Â defaultSettings=false;Â // user knows what she is doing |
---|
4417 | Â Â Â Â Â Â Â break; |
---|
4418 |       case LOCALTREE: |
---|
4419 | Â Â Â Â Â Â Â defaultSettings=false;Â // user knows what she is doing |
---|
4420 | Â Â Â Â Â Â Â break; |
---|
4421 |       case COSTSTRATEGY: |
---|
4422 | Â Â Â Â Â Â Â useCosts=action; |
---|
4423 | Â Â Â Â Â Â Â break; |
---|
4424 |       case NODESTRATEGY: |
---|
4425 | Â Â Â Â Â Â Â nodeStrategy=action; |
---|
4426 | Â Â Â Â Â Â Â break; |
---|
4427 |       case PREPROCESS: |
---|
4428 | Â Â Â Â Â Â Â preProcess =Â action; |
---|
4429 | Â Â Â Â Â Â Â break; |
---|
4430 |       case USESOLUTION: |
---|
4431 | Â Â Â Â Â Â Â useSolution =Â action; |
---|
4432 | Â Â Â Â Â Â Â break; |
---|
4433 | Â Â Â Â Â Â default: |
---|
4434 | Â Â Â Â Â Â Â abort(); |
---|
4435 | Â Â Â Â Â Â } |
---|
4436 | Â Â Â Â Â } |
---|
4437 |     } else { |
---|
4438 | Â Â Â Â Â // action |
---|
4439 |      if (type==EXIT) { |
---|
4440 | #ifdef COIN_HAS_ASL |
---|
4441 | Â Â Â Â Â Â if(statusUserFunction_[0])Â { |
---|
4442 |        if (info.numberIntegers||info.numberBinary) { |
---|
4443 | Â Â Â Â Â Â Â Â // integer |
---|
4444 |        } else { |
---|
4445 | Â Â Â Â Â Â Â Â // linear |
---|
4446 | Â Â Â Â Â Â Â } |
---|
4447 | Â Â Â Â Â Â Â writeAmpl(&info); |
---|
4448 | Â Â Â Â Â Â Â freeArrays2(&info); |
---|
4449 | Â Â Â Â Â Â Â freeArgs(&info); |
---|
4450 | Â Â Â Â Â Â } |
---|
4451 | #endif |
---|
4452 | Â Â Â Â Â Â break;Â // stop all |
---|
4453 | Â Â Â Â Â } |
---|
4454 |      switch (type) { |
---|
4455 |      case DUALSIMPLEX: |
---|
4456 |      case PRIMALSIMPLEX: |
---|
4457 |      case SOLVECONTINUOUS: |
---|
4458 |      case BARRIER: |
---|
4459 |       if (goodModel) { |
---|
4460 |        double objScale = |
---|
4461 | Â Â Â Â Â Â Â Â parameters_[whichParam(OBJSCALE2,numberParameters_,parameters_)].doubleValue(); |
---|
4462 |        if (objScale!=1.0) { |
---|
4463 |         int iColumn; |
---|
4464 |         int numberColumns=lpSolver->numberColumns(); |
---|
4465 |         double * dualColumnSolution = |
---|
4466 | Â Â Â Â Â Â Â Â Â lpSolver->dualColumnSolution(); |
---|
4467 | Â Â Â Â Â Â Â Â ClpObjective *Â obj =Â lpSolver->objectiveAsObject(); |
---|
4468 | Â Â Â Â Â Â Â Â assert(dynamic_cast<ClpLinearObjective *>Â (obj)); |
---|
4469 |         double offset; |
---|
4470 |         double * objective = obj->gradient(NULL,NULL,offset,true); |
---|
4471 |         for (iColumn=0;iColumn<numberColumns;iColumn++) { |
---|
4472 | Â Â Â Â Â Â Â Â Â dualColumnSolution[iColumn]Â *=Â objScale; |
---|
4473 | Â Â Â Â Â Â Â Â Â objective[iColumn]Â *=Â objScale;; |
---|
4474 | Â Â Â Â Â Â Â Â } |
---|
4475 |         int iRow; |
---|
4476 |         int numberRows=lpSolver->numberRows(); |
---|
4477 |         double * dualRowSolution = |
---|
4478 | Â Â Â Â Â Â Â Â Â lpSolver->dualRowSolution(); |
---|
4479 |         for (iRow=0;iRow<numberRows;iRow++) |
---|
4480 | Â Â Â Â Â Â Â Â Â dualRowSolution[iRow]Â *=Â objScale; |
---|
4481 | Â Â Â Â Â Â Â Â lpSolver->setObjectiveOffset(objScale*lpSolver->objectiveOffset()); |
---|
4482 | Â Â Â Â Â Â Â } |
---|
4483 | Â Â Â Â Â Â Â ClpSolve::SolveType method; |
---|
4484 | Â Â Â Â Â Â Â ClpSolve::PresolveType presolveType; |
---|
4485 | Â Â Â Â Â Â Â ClpSimplex *Â model2 =Â lpSolver; |
---|
4486 |        if (dualize) { |
---|
4487 |         bool tryIt=true; |
---|
4488 |         double fractionColumn=1.0; |
---|
4489 |         double fractionRow=1.0; |
---|
4490 |         if (dualize==3) { |
---|
4491 | Â Â Â Â Â Â Â Â Â dualize=1; |
---|
4492 |          int numberColumns=lpSolver->numberColumns(); |
---|
4493 |          int numberRows=lpSolver->numberRows(); |
---|
4494 |          if (numberRows<50000||5*numberColumns>numberRows) { |
---|
4495 | Â Â Â Â Â Â Â Â Â Â tryIt=false; |
---|
4496 |          } else { |
---|
4497 | Â Â Â Â Â Â Â Â Â Â fractionColumn=0.1; |
---|
4498 | Â Â Â Â Â Â Â Â Â Â fractionRow=0.1; |
---|
4499 | Â Â Â Â Â Â Â Â Â } |
---|
4500 | Â Â Â Â Â Â Â Â } |
---|
4501 |         if (tryIt) { |
---|
4502 | Â Â Â Â Â Â Â Â Â model2 =Â ((ClpSimplexOther *)Â model2)->dualOfModel(fractionRow,fractionColumn); |
---|
4503 |          if (model2) { |
---|
4504 | Â Â Â Â Â Â Â Â Â Â sprintf(generalPrint,"Dual of model has %d rows and %d columns", |
---|
4505 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â model2->numberRows(),model2->numberColumns()); |
---|
4506 | Â Â Â Â Â Â Â Â Â Â generalMessageHandler->message(CLP_GENERAL,generalMessages) |
---|
4507 | Â Â Â Â Â Â Â Â Â Â Â <<Â generalPrint |
---|
4508 | Â Â Â Â Â Â Â Â Â Â Â <<CoinMessageEol; |
---|
4509 | Â Â Â Â Â Â Â Â Â Â model2->setOptimizationDirection(1.0); |
---|
4510 |          } else { |
---|
4511 | Â Â Â Â Â Â Â Â Â Â model2 =Â lpSolver; |
---|
4512 | Â Â Â Â Â Â Â Â Â Â dualize=0; |
---|
4513 | Â Â Â Â Â Â Â Â Â } |
---|
4514 |         } else { |
---|
4515 | Â Â Â Â Â Â Â Â Â dualize=0; |
---|
4516 | Â Â Â Â Â Â Â Â } |
---|
4517 | Â Â Â Â Â Â Â } |
---|
4518 |        if (noPrinting_) |
---|
4519 | Â Â Â Â Â Â Â Â lpSolver->setLogLevel(0); |
---|
4520 | Â Â Â Â Â Â Â ClpSolve solveOptions; |
---|
4521 | Â Â Â Â Â Â Â solveOptions.setPresolveActions(presolveOptions); |
---|
4522 | Â Â Â Â Â Â Â solveOptions.setSubstitution(substitution); |
---|
4523 |        if (preSolve!=5&&preSolve) { |
---|
4524 | Â Â Â Â Â Â Â Â presolveType=ClpSolve::presolveNumber; |
---|
4525 |         if (preSolve<0) { |
---|
4526 | Â Â Â Â Â Â Â Â Â preSolve =Â -Â preSolve; |
---|
4527 |          if (preSolve<=100) { |
---|
4528 | Â Â Â Â Â Â Â Â Â Â presolveType=ClpSolve::presolveNumber; |
---|
4529 | Â Â Â Â Â Â Â Â Â Â sprintf(generalPrint,"Doing %d presolve passes - picking up non-costed slacks", |
---|
4530 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â preSolve); |
---|
4531 | Â Â Â Â Â Â Â Â Â Â generalMessageHandler->message(CLP_GENERAL,generalMessages) |
---|
4532 | Â Â Â Â Â Â Â Â Â Â Â <<Â generalPrint |
---|
4533 | Â Â Â Â Â Â Â Â Â Â Â <<CoinMessageEol; |
---|
4534 | Â Â Â Â Â Â Â Â Â Â solveOptions.setDoSingletonColumn(true); |
---|
4535 |          } else { |
---|
4536 | Â Â Â Â Â Â Â Â Â Â preSolve -=100; |
---|
4537 | Â Â Â Â Â Â Â Â Â Â presolveType=ClpSolve::presolveNumberCost; |
---|
4538 | Â Â Â Â Â Â Â Â Â Â sprintf(generalPrint,"Doing %d presolve passes - picking up costed slacks", |
---|
4539 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â preSolve); |
---|
4540 | Â Â Â Â Â Â Â Â Â Â generalMessageHandler->message(CLP_GENERAL,generalMessages) |
---|
4541 | Â Â Â Â Â Â Â Â Â Â Â <<Â generalPrint |
---|
4542 | Â Â Â Â Â Â Â Â Â Â Â <<CoinMessageEol; |
---|
4543 | Â Â Â Â Â Â Â Â Â } |
---|
4544 | Â Â Â Â Â Â Â Â }Â |
---|
4545 |        } else if (preSolve) { |
---|
4546 | Â Â Â Â Â Â Â Â presolveType=ClpSolve::presolveOn; |
---|
4547 |        } else { |
---|
4548 | Â Â Â Â Â Â Â Â presolveType=ClpSolve::presolveOff; |
---|
4549 | Â Â Â Â Â Â Â } |
---|
4550 | Â Â Â Â Â Â Â solveOptions.setPresolveType(presolveType,preSolve); |
---|
4551 |        if (type==DUALSIMPLEX||type==SOLVECONTINUOUS) { |
---|
4552 | Â Â Â Â Â Â Â Â method=ClpSolve::useDual; |
---|
4553 |        } else if (type==PRIMALSIMPLEX) { |
---|
4554 | Â Â Â Â Â Â Â Â method=ClpSolve::usePrimalorSprint; |
---|
4555 |        } else { |
---|
4556 | Â Â Â Â Â Â Â Â method =Â ClpSolve::useBarrier; |
---|
4557 |         if (crossover==1) { |
---|
4558 | Â Â Â Â Â Â Â Â Â method=ClpSolve::useBarrierNoCross; |
---|
4559 |         } else if (crossover==2) { |
---|
4560 | Â Â Â Â Â Â Â Â Â ClpObjective *Â obj =Â lpSolver->objectiveAsObject(); |
---|
4561 |          if (obj->type()>1) { |
---|
4562 | Â Â Â Â Â Â Â Â Â Â method=ClpSolve::useBarrierNoCross; |
---|
4563 | Â Â Â Â Â Â Â Â Â Â presolveType=ClpSolve::presolveOff; |
---|
4564 | Â Â Â Â Â Â Â Â Â Â solveOptions.setPresolveType(presolveType,preSolve); |
---|
4565 | Â Â Â Â Â Â Â Â Â }Â |
---|
4566 | Â Â Â Â Â Â Â Â } |
---|
4567 | Â Â Â Â Â Â Â } |
---|
4568 | Â Â Â Â Â Â Â solveOptions.setSolveType(method); |
---|
4569 | Â Â Â Â Â Â Â if(preSolveFile) |
---|
4570 | Â Â Â Â Â Â Â Â presolveOptions |=Â 0x40000000; |
---|
4571 | Â Â Â Â Â Â Â solveOptions.setSpecialOption(4,presolveOptions); |
---|
4572 | Â Â Â Â Â Â Â solveOptions.setSpecialOption(5,printOptions); |
---|
4573 |        if (doVector) { |
---|
4574 | Â Â Â Â Â Â Â Â ClpMatrixBase *Â matrix =Â lpSolver->clpMatrix(); |
---|
4575 |         if (dynamic_cast< ClpPackedMatrix*>(matrix)) { |
---|
4576 | Â Â Â Â Â Â Â Â Â ClpPackedMatrix *Â clpMatrix =Â dynamic_cast<Â ClpPackedMatrix*>(matrix); |
---|
4577 | Â Â Â Â Â Â Â Â Â clpMatrix->makeSpecialColumnCopy(); |
---|
4578 | Â Â Â Â Â Â Â Â } |
---|
4579 | Â Â Â Â Â Â Â } |
---|
4580 |        if (method==ClpSolve::useDual) { |
---|
4581 | Â Â Â Â Â Â Â Â // dual |
---|
4582 |         if (doCrash) |
---|
4583 | Â Â Â Â Â Â Â Â Â solveOptions.setSpecialOption(0,1,doCrash);Â // crash |
---|
4584 |         else if (doIdiot) |
---|
4585 | Â Â Â Â Â Â Â Â Â solveOptions.setSpecialOption(0,2,doIdiot);Â // possible idiot |
---|
4586 |        } else if (method==ClpSolve::usePrimalorSprint) { |
---|
4587 | Â Â Â Â Â Â Â Â // primal |
---|
4588 | Â Â Â Â Â Â Â Â // if slp turn everything off |
---|
4589 |         if (slpValue>0) { |
---|
4590 | Â Â Â Â Â Â Â Â Â doCrash=false; |
---|
4591 | Â Â Â Â Â Â Â Â Â doSprint=0; |
---|
4592 | Â Â Â Â Â Â Â Â Â doIdiot=-1; |
---|
4593 | Â Â Â Â Â Â Â Â Â solveOptions.setSpecialOption(1,10,slpValue);Â // slp |
---|
4594 | Â Â Â Â Â Â Â Â Â method=ClpSolve::usePrimal; |
---|
4595 | Â Â Â Â Â Â Â Â } |
---|
4596 |         if (doCrash) { |
---|
4597 | Â Â Â Â Â Â Â Â Â solveOptions.setSpecialOption(1,1,doCrash);Â // crash |
---|
4598 |         } else if (doSprint>0) { |
---|
4599 | Â Â Â Â Â Â Â Â Â // sprint overrides idiot |
---|
4600 | Â Â Â Â Â Â Â Â Â solveOptions.setSpecialOption(1,3,doSprint);Â // sprint |
---|
4601 |         } else if (doIdiot>0) { |
---|
4602 | Â Â Â Â Â Â Â Â Â solveOptions.setSpecialOption(1,2,doIdiot);Â // idiot |
---|
4603 |         } else if (slpValue<=0) { |
---|
4604 |          if (doIdiot==0) { |
---|
4605 |           if (doSprint==0) |
---|
4606 | Â Â Â Â Â Â Â Â Â Â Â solveOptions.setSpecialOption(1,4);Â // all slack |
---|
4607 | Â Â Â Â Â Â Â Â Â Â else |
---|
4608 | Â Â Â Â Â Â Â Â Â Â Â solveOptions.setSpecialOption(1,9);Â // all slack or sprint |
---|
4609 |          } else { |
---|
4610 |           if (doSprint==0) |
---|
4611 | Â Â Â Â Â Â Â Â Â Â Â solveOptions.setSpecialOption(1,8);Â // all slack or idiot |
---|
4612 | Â Â Â Â Â Â Â Â Â Â else |
---|
4613 | Â Â Â Â Â Â Â Â Â Â Â solveOptions.setSpecialOption(1,7);Â // initiative |
---|
4614 | Â Â Â Â Â Â Â Â Â } |
---|
4615 | Â Â Â Â Â Â Â Â } |
---|
4616 |         if (basisHasValues==-1) |
---|
4617 | Â Â Â Â Â Â Â Â Â solveOptions.setSpecialOption(1,11);Â // switch off values |
---|
4618 |        } else if (method==ClpSolve::useBarrier||method==ClpSolve::useBarrierNoCross) { |
---|
4619 |         int barrierOptions = choleskyType; |
---|
4620 |         if (scaleBarrier) |
---|
4621 | Â Â Â Â Â Â Â Â Â barrierOptions |=Â 8; |
---|
4622 |         if (doKKT) |
---|
4623 | Â Â Â Â Â Â Â Â Â barrierOptions |=Â 16; |
---|
4624 |         if (gamma) |
---|
4625 | Â Â Â Â Â Â Â Â Â barrierOptions |=Â 32*gamma; |
---|
4626 |         if (crossover==3) |
---|
4627 | Â Â Â Â Â Â Â Â Â barrierOptions |=Â 256;Â // try presolve in crossover |
---|
4628 | Â Â Â Â Â Â Â Â solveOptions.setSpecialOption(4,barrierOptions); |
---|
4629 | Â Â Â Â Â Â Â } |
---|
4630 | Â Â Â Â Â Â Â model2->setMaximumSeconds(model_.getMaximumSeconds()); |
---|
4631 | #ifdef COIN_HAS_LINK |
---|
4632 | Â Â Â Â Â Â Â OsiSolverInterface *Â coinSolver =Â model_.solver(); |
---|
4633 | Â Â Â Â Â Â Â OsiSolverLink *Â linkSolver =Â dynamic_cast<Â OsiSolverLink*>Â (coinSolver); |
---|
4634 |        if (!linkSolver) { |
---|
4635 | Â Â Â Â Â Â Â Â model2->initialSolve(solveOptions); |
---|
4636 |        } else { |
---|
4637 | Â Â Â Â Â Â Â Â // special solver |
---|
4638 |         int testOsiOptions = parameters_[whichParam(TESTOSI,numberParameters_,parameters_)].intValue(); |
---|
4639 |         double * solution = NULL; |
---|
4640 |         if (testOsiOptions<10) { |
---|
4641 |          solution = linkSolver->nonlinearSLP(slpValue>0 ? slpValue : 20 ,1.0e-5); |
---|
4642 |         } else if (testOsiOptions>=10) { |
---|
4643 | Â Â Â Â Â Â Â Â Â CoinModel coinModel =Â *linkSolver->coinModel(); |
---|
4644 |          ClpSimplex * tempModel = approximateSolution(coinModel,slpValue>0 ? slpValue : 50 ,1.0e-5,0); |
---|
4645 | Â Â Â Â Â Â Â Â Â assert (tempModel); |
---|
4646 | Â Â Â Â Â Â Â Â Â solution =Â CoinCopyOfArray(tempModel->primalColumnSolution(),coinModel.numberColumns()); |
---|
4647 | Â Â Â Â Â Â Â Â Â model2->setObjectiveValue(tempModel->objectiveValue()); |
---|
4648 | Â Â Â Â Â Â Â Â Â model2->setProblemStatus(tempModel->problemStatus()); |
---|
4649 | Â Â Â Â Â Â Â Â Â model2->setSecondaryStatus(tempModel->secondaryStatus()); |
---|
4650 |          delete tempModel; |
---|
4651 | Â Â Â Â Â Â Â Â } |
---|
4652 |         if (solution) { |
---|
4653 | Â Â Â Â Â Â Â Â Â memcpy(model2->primalColumnSolution(),solution, |
---|
4654 | Â Â Â Â Â Â Â Â Â Â Â Â Â CoinMin(model2->numberColumns(),linkSolver->coinModel()->numberColumns())*sizeof(double)); |
---|
4655 |          delete [] solution; |
---|
4656 |         } else { |
---|
4657 | Â Â Â Â Â Â Â Â Â printf("No nonlinear solution\n"); |
---|
4658 | Â Â Â Â Â Â Â Â } |
---|
4659 | Â Â Â Â Â Â Â } |
---|
4660 | #else |
---|
4661 | Â Â Â Â Â Â Â model2->initialSolve(solveOptions); |
---|
4662 | #endif |
---|
4663 | Â Â Â Â Â Â Â { |
---|
4664 | Â Â Â Â Â Â Â Â // map states |
---|
4665 | Â Â Â Â Â Â Â Â /* clp status |
---|
4666 | Â Â Â Â Â Â Â Â Â Â -1 - unknown e.g. before solve or if postSolve says not optimal |
---|
4667 | Â Â Â Â Â Â Â Â Â Â 0 - optimal |
---|
4668 | Â Â Â Â Â Â Â Â Â Â 1 - primal infeasible |
---|
4669 | Â Â Â Â Â Â Â Â Â Â 2 - dual infeasible |
---|
4670 | Â Â Â Â Â Â Â Â Â Â 3 - stopped on iterations or time |
---|
4671 | Â Â Â Â Â Â Â Â Â Â 4 - stopped due to errors |
---|
4672 | Â Â Â Â Â Â Â Â Â Â 5 - stopped by event handler (virtual int ClpEventHandler::event()) */ |
---|
4673 | Â Â Â Â Â Â Â Â /* cbc status |
---|
4674 | Â Â Â Â Â Â Â Â Â Â -1 before branchAndBound |
---|
4675 | Â Â Â Â Â Â Â Â Â Â 0 finished - check isProvenOptimal or isProvenInfeasible to see if solution found |
---|
4676 | Â Â Â Â Â Â Â Â Â Â (or check value of best solution) |
---|
4677 | Â Â Â Â Â Â Â Â Â Â 1 stopped - on maxnodes, maxsols, maxtime |
---|
4678 | Â Â Â Â Â Â Â Â Â Â 2 difficulties so run was abandoned |
---|
4679 | Â Â Â Â Â Â Â Â Â Â (5 event user programmed event occurred) */ |
---|
4680 | Â Â Â Â Â Â Â Â /* clp secondary status of problem - may get extended |
---|
4681 | Â Â Â Â Â Â Â Â Â Â 0 - none |
---|
4682 | Â Â Â Â Â Â Â Â Â Â 1 - primal infeasible because dual limit reached OR probably primal |
---|
4683 | Â Â Â Â Â Â Â Â Â Â infeasible but can't prove it (main status 4) |
---|
4684 | Â Â Â Â Â Â Â Â Â Â 2 - scaled problem optimal - unscaled problem has primal infeasibilities |
---|
4685 | Â Â Â Â Â Â Â Â Â Â 3 - scaled problem optimal - unscaled problem has dual infeasibilities |
---|
4686 | Â Â Â Â Â Â Â Â Â Â 4 - scaled problem optimal - unscaled problem has primal and dual infeasibilities |
---|
4687 | Â Â Â Â Â Â Â Â Â Â 5 - giving up in primal with flagged variables |
---|
4688 | Â Â Â Â Â Â Â Â Â Â 6 - failed due to empty problem check |
---|
4689 | Â Â Â Â Â Â Â Â Â Â 7 - postSolve says not optimal |
---|
4690 | Â Â Â Â Â Â Â Â Â Â 8 - failed due to bad element check |
---|
4691 | Â Â Â Â Â Â Â Â Â Â 9 - status was 3 and stopped on time |
---|
4692 | Â Â Â Â Â Â Â Â Â Â 100 up - translation of enum from ClpEventHandler |
---|
4693 | Â Â Â Â Â Â Â Â */ |
---|
4694 | Â Â Â Â Â Â Â Â /* cbc secondary status of problem |
---|
4695 | Â Â Â Â Â Â Â Â Â Â -1 unset (status_ will also be -1) |
---|
4696 | Â Â Â Â Â Â Â Â Â Â 0 search completed with solution |
---|
4697 | Â Â Â Â Â Â Â Â Â Â 1 linear relaxation not feasible (or worse than cutoff) |
---|
4698 | Â Â Â Â Â Â Â Â Â Â 2 stopped on gap |
---|
4699 | Â Â Â Â Â Â Â Â Â Â 3 stopped on nodes |
---|
4700 | Â Â Â Â Â Â Â Â Â Â 4 stopped on time |
---|
4701 | Â Â Â Â Â Â Â Â Â Â 5 stopped on user event |
---|
4702 | Â Â Â Â Â Â Â Â Â Â 6 stopped on solutions |
---|
4703 | Â Â Â Â Â Â Â Â Â Â 7 linear relaxation unbounded |
---|
4704 | Â Â Â Â Â Â Â Â */ |
---|
4705 |         int iStatus = model2->status(); |
---|
4706 |         int iStatus2 = model2->secondaryStatus(); |
---|
4707 |         if (iStatus==0) { |
---|
4708 | Â Â Â Â Â Â Â Â Â iStatus2=0; |
---|
4709 |         } else if (iStatus==1) { |
---|
4710 | Â Â Â Â Â Â Â Â Â iStatus=0; |
---|
4711 | Â Â Â Â Â Â Â Â Â iStatus2=1;Â // say infeasible |
---|
4712 |         } else if (iStatus==2) { |
---|
4713 | Â Â Â Â Â Â Â Â Â iStatus=0; |
---|
4714 | Â Â Â Â Â Â Â Â Â iStatus2=7;Â // say unbounded |
---|
4715 |         } else if (iStatus==3) { |
---|
4716 | Â Â Â Â Â Â Â Â Â iStatus=1; |
---|
4717 |          if (iStatus2==9) |
---|
4718 | Â Â Â Â Â Â Â Â Â Â iStatus2=4; |
---|
4719 | Â Â Â Â Â Â Â Â Â else |
---|
4720 | Â Â Â Â Â Â Â Â Â Â iStatus2=3;Â // Use nodes - as closer than solutions |
---|
4721 |         } else if (iStatus==4) { |
---|
4722 | Â Â Â Â Â Â Â Â Â iStatus=2;Â // difficulties |
---|
4723 | Â Â Â Â Â Â Â Â Â iStatus2=0;Â |
---|
4724 | Â Â Â Â Â Â Â Â } |
---|
4725 | Â Â Â Â Â Â Â Â model_.setProblemStatus(iStatus); |
---|
4726 | Â Â Â Â Â Â Â Â model_.setSecondaryStatus(iStatus2); |
---|
4727 | Â Â Â Â Â Â Â Â assert (lpSolver==clpSolver->getModelPtr()); |
---|
4728 | Â Â Â Â Â Â Â Â assert (clpSolver==model_.solver()); |
---|
4729 | Â Â Â Â Â Â Â Â clpSolver->setWarmStart(NULL); |
---|
4730 | Â Â Â Â Â Â Â Â // and in babModel if exists |
---|
4731 |         if (babModel_) { |
---|
4732 | Â Â Â Â Â Â Â Â Â babModel_->setProblemStatus(iStatus); |
---|
4733 | Â Â Â Â Â Â Â Â Â babModel_->setSecondaryStatus(iStatus2); |
---|
4734 | Â Â Â Â Â Â Â Â }Â |
---|
4735 | #ifdef NEW_STYLE_SOLVER |
---|
4736 |         int returnCode = callBack_->callBack(&model_,1); |
---|
4737 | #else |
---|
4738 |         int returnCode=callBack(&model,1); |
---|
4739 | #endif |
---|
4740 |         if (returnCode) { |
---|
4741 | Â Â Â Â Â Â Â Â Â // exit if user wants |
---|
4742 | #ifdef NEW_STYLE_SOLVER |
---|
4743 | Â Â Â Â Â Â Â Â Â updateModel(model2,returnMode); |
---|
4744 | #else |
---|
4745 |          delete babModel_; |
---|
4746 | Â Â Â Â Â Â Â Â Â babModel_ =Â NULL; |
---|
4747 | #endif |
---|
4748 |          return returnCode; |
---|
4749 | Â Â Â Â Â Â Â Â } |
---|
4750 | Â Â Â Â Â Â Â } |
---|
4751 | Â Â Â Â Â Â Â basisHasValues=1; |
---|
4752 |        if (dualize) { |
---|
4753 |         int returnCode=((ClpSimplexOther *) lpSolver)->restoreFromDual(model2); |
---|
4754 |         if (model2->status()==3) |
---|
4755 | Â Â Â Â Â Â Â Â Â returnCode=0; |
---|
4756 |         delete model2; |
---|
4757 |         if (returnCode&&dualize!=2) |
---|
4758 | Â Â Â Â Â Â Â Â Â lpSolver->primal(1); |
---|
4759 | Â Â Â Â Â Â Â Â model2=lpSolver; |
---|
4760 | Â Â Â Â Â Â Â } |
---|
4761 | #ifdef NEW_STYLE_SOLVER |
---|
4762 | Â Â Â Â Â Â Â updateModel(model2,returnMode); |
---|
4763 |        for (iUser=0;iUser<numberUserFunctions_;iUser++) { |
---|
4764 |         if (statusUserFunction_[iUser]) |
---|
4765 | Â Â Â Â Â Â Â Â Â userFunction_[iUser]->exportSolution(this,1); |
---|
4766 | Â Â Â Â Â Â Â } |
---|
4767 | #endif |
---|
4768 | #ifdef COIN_HAS_ASL |
---|
4769 |        if (statusUserFunction_[0]) { |
---|
4770 |         double value = model2->getObjValue()*model2->getObjSense(); |
---|
4771 |         char buf[300]; |
---|
4772 |         int pos=0; |
---|
4773 |         int iStat = model2->status(); |
---|
4774 |         if (iStat==0) { |
---|
4775 | Â Â Â Â Â Â Â Â Â pos +=Â sprintf(buf+pos,"optimal,"Â ); |
---|
4776 |         } else if (iStat==1) { |
---|
4777 | Â Â Â Â Â Â Â Â Â // infeasible |
---|
4778 | Â Â Â Â Â Â Â Â Â pos +=Â sprintf(buf+pos,"infeasible,"); |
---|
4779 |         } else if (iStat==2) { |
---|
4780 | Â Â Â Â Â Â Â Â Â // unbounded |
---|
4781 | Â Â Â Â Â Â Â Â Â pos +=Â sprintf(buf+pos,"unbounded,"); |
---|
4782 |         } else if (iStat==3) { |
---|
4783 | Â Â Â Â Â Â Â Â Â pos +=Â sprintf(buf+pos,"stopped on iterations or time,"); |
---|
4784 |         } else if (iStat==4) { |
---|
4785 | Â Â Â Â Â Â Â Â Â iStat =Â 7; |
---|
4786 | Â Â Â Â Â Â Â Â Â pos +=Â sprintf(buf+pos,"stopped on difficulties,"); |
---|
4787 |         } else if (iStat==5) { |
---|
4788 | Â Â Â Â Â Â Â Â Â iStat =Â 3; |
---|
4789 | Â Â Â Â Â Â Â Â Â pos +=Â sprintf(buf+pos,"stopped on ctrl-c,"); |
---|
4790 |         } else { |
---|
4791 | Â Â Â Â Â Â Â Â Â pos +=Â sprintf(buf+pos,"status unknown,"); |
---|
4792 | Â Â Â Â Â Â Â Â Â iStat=6; |
---|
4793 | Â Â Â Â Â Â Â Â } |
---|
4794 | Â Â Â Â Â Â Â Â info.problemStatus=iStat; |
---|
4795 | Â Â Â Â Â Â Â Â info.objValue =Â value; |
---|
4796 | Â Â Â Â Â Â Â Â pos +=Â sprintf(buf+pos," objective %.*g",ampl_obj_prec(), |
---|
4797 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â value); |
---|
4798 | Â Â Â Â Â Â Â Â sprintf(buf+pos,"\n%d iterations", |
---|
4799 | Â Â Â Â Â Â Â Â Â Â Â Â model2->getIterationCount()); |
---|
4800 | Â Â Â Â Â Â Â Â free(info.primalSolution); |
---|
4801 |         int numberColumns=model2->numberColumns(); |
---|
4802 |         info.primalSolution = (double *) malloc(numberColumns*sizeof(double)); |
---|
4803 | Â Â Â Â Â Â Â Â CoinCopyN(model2->primalColumnSolution(),numberColumns,info.primalSolution); |
---|
4804 |         int numberRows = model2->numberRows(); |
---|
4805 | Â Â Â Â Â Â Â Â free(info.dualSolution); |
---|
4806 |         info.dualSolution = (double *) malloc(numberRows*sizeof(double)); |
---|
4807 | Â Â Â Â Â Â Â Â CoinCopyN(model2->dualRowSolution(),numberRows,info.dualSolution); |
---|
4808 | Â Â Â Â Â Â Â Â CoinWarmStartBasis *Â basis =Â model2->getBasis(); |
---|
4809 | Â Â Â Â Â Â Â Â free(info.rowStatus); |
---|
4810 |         info.rowStatus = (int *) malloc(numberRows*sizeof(int)); |
---|
4811 | Â Â Â Â Â Â Â Â free(info.columnStatus); |
---|
4812 |         info.columnStatus = (int *) malloc(numberColumns*sizeof(int)); |
---|
4813 | Â Â Â Â Â Â Â Â // Put basis in |
---|
4814 |         int i; |
---|
4815 | Â Â Â Â Â Â Â Â // free,basic,ub,lb are 0,1,2,3 |
---|
4816 |         for (i=0;i<numberRows;i++) { |
---|
4817 | Â Â Â Â Â Â Â Â Â CoinWarmStartBasis::Status status =Â basis->getArtifStatus(i); |
---|
4818 | Â Â Â Â Â Â Â Â Â info.rowStatus[i]=status; |
---|
4819 | Â Â Â Â Â Â Â Â } |
---|
4820 |         for (i=0;i<numberColumns;i++) { |
---|
4821 | Â Â Â Â Â Â Â Â Â CoinWarmStartBasis::Status status =Â basis->getStructStatus(i); |
---|
4822 | Â Â Â Â Â Â Â Â Â info.columnStatus[i]=status; |
---|
4823 | Â Â Â Â Â Â Â Â } |
---|
4824 | Â Â Â Â Â Â Â Â // put buffer into info |
---|
4825 | Â Â Â Â Â Â Â Â strcpy(info.buffer,buf); |
---|
4826 |         delete basis; |
---|
4827 | Â Â Â Â Â Â Â } |
---|
4828 | #endif |
---|
4829 |       } else { |
---|
4830 | #ifndef DISALLOW_PRINTING |
---|
4831 | Â Â Â Â Â Â Â std::cout<<"** Current model not valid"<<std::endl; |
---|
4832 | #endif |
---|
4833 | Â Â Â Â Â Â } |
---|
4834 | Â Â Â Â Â Â break; |
---|
4835 |      case STATISTICS: |
---|
4836 |       if (goodModel) { |
---|
4837 | Â Â Â Â Â Â Â // If presolve on look at presolved |
---|
4838 |        bool deleteModel2=false; |
---|
4839 | Â Â Â Â Â Â Â ClpSimplex *Â model2 =Â lpSolver; |
---|
4840 |        if (preSolve) { |
---|
4841 | Â Â Â Â Â Â Â Â ClpPresolve pinfo; |
---|
4842 |         int presolveOptions2 = presolveOptions&~0x40000000; |
---|
4843 |         if ((presolveOptions2&0xffff)!=0) |
---|
4844 | Â Â Â Â Â Â Â Â Â pinfo.setPresolveActions(presolveOptions2); |
---|
4845 | Â Â Â Â Â Â Â Â pinfo.setSubstitution(substitution); |
---|
4846 |         if ((printOptions&1)!=0) |
---|
4847 | Â Â Â Â Â Â Â Â Â pinfo.statistics(); |
---|
4848 |         double presolveTolerance = |
---|
4849 | Â Â Â Â Â Â Â Â Â parameters_[whichParam(PRESOLVETOLERANCE,numberParameters_,parameters_)].doubleValue(); |
---|
4850 | Â Â Â Â Â Â Â Â model2 =Â |
---|
4851 | Â Â Â Â Â Â Â Â Â pinfo.presolvedModel(*lpSolver,presolveTolerance, |
---|
4852 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â true,preSolve); |
---|
4853 |         if (model2) { |
---|
4854 | Â Â Â Â Â Â Â Â Â printf("Statistics for presolved model\n"); |
---|
4855 | Â Â Â Â Â Â Â Â Â deleteModel2=true; |
---|
4856 |         } else { |
---|
4857 | Â Â Â Â Â Â Â Â Â printf("Presolved model looks infeasible - will use unpresolved\n"); |
---|
4858 | Â Â Â Â Â Â Â Â Â model2 =Â lpSolver; |
---|
4859 | Â Â Â Â Â Â Â Â } |
---|
4860 |        } else { |
---|
4861 | Â Â Â Â Â Â Â Â printf("Statistics for unpresolved model\n"); |
---|
4862 | Â Â Â Â Â Â Â Â model2 =Â lpSolver; |
---|
4863 | Â Â Â Â Â Â Â } |
---|
4864 | Â Â Â Â Â Â Â statistics(lpSolver,model2); |
---|
4865 |        if (deleteModel2) |
---|
4866 |         delete model2; |
---|
4867 |       } else { |
---|
4868 | #ifndef DISALLOW_PRINTING |
---|
4869 | Â Â Â Â Â Â Â std::cout<<"** Current model not valid"<<std::endl; |
---|
4870 | #endif |
---|
4871 | Â Â Â Â Â Â } |
---|
4872 | Â Â Â Â Â Â break; |
---|
4873 |      case TIGHTEN: |
---|
4874 |       if (goodModel) { |
---|
4875 |        int numberInfeasibilities = lpSolver->tightenPrimalBounds(); |
---|
4876 |        if (numberInfeasibilities) |
---|
4877 | Â Â Â Â Â Â Â Â std::cout<<"** Analysis indicates model infeasible"<<std::endl; |
---|
4878 |       } else { |
---|
4879 | #ifndef DISALLOW_PRINTING |
---|
4880 | Â Â Â Â Â Â Â std::cout<<"** Current model not valid"<<std::endl; |
---|
4881 | #endif |
---|
4882 | Â Â Â Â Â Â } |
---|
4883 | Â Â Â Â Â Â break; |
---|
4884 |      case PLUSMINUS: |
---|
4885 |       if (goodModel) { |
---|
4886 | Â Â Â Â Â Â Â ClpMatrixBase *Â saveMatrix =Â lpSolver->clpMatrix(); |
---|
4887 | Â Â Â Â Â Â Â ClpPackedMatrix*Â clpMatrix = |
---|
4888 | Â Â Â Â Â Â Â Â dynamic_cast<Â ClpPackedMatrix*>(saveMatrix); |
---|
4889 |        if (clpMatrix) { |
---|
4890 |         ClpPlusMinusOneMatrix * newMatrix = new ClpPlusMinusOneMatrix(*(clpMatrix->matrix())); |
---|
4891 |         if (newMatrix->getIndices()) { |
---|
4892 | Â Â Â Â Â Â Â Â Â lpSolver->replaceMatrix(newMatrix); |
---|
4893 |          delete saveMatrix; |
---|
4894 | Â Â Â Â Â Â Â Â Â std::cout<<"Matrix converted to +- one matrix"<<std::endl; |
---|
4895 |         } else { |
---|
4896 | Â Â Â Â Â Â Â Â Â std::cout<<"Matrix can not be converted to +- 1 matrix"<<std::endl; |
---|
4897 | Â Â Â Â Â Â Â Â } |
---|
4898 |        } else { |
---|
4899 | Â Â Â Â Â Â Â Â std::cout<<"Matrix not a ClpPackedMatrix"<<std::endl; |
---|
4900 | Â Â Â Â Â Â Â } |
---|
4901 |       } else { |
---|
4902 | #ifndef DISALLOW_PRINTING |
---|
4903 | Â Â Â Â Â Â Â std::cout<<"** Current model not valid"<<std::endl; |
---|
4904 | #endif |
---|
4905 | Â Â Â Â Â Â } |
---|
4906 | Â Â Â Â Â Â break; |
---|
4907 |      case OUTDUPROWS: |
---|
4908 |       if (goodModel) { |
---|
4909 |        int numberRows = clpSolver->getNumRows(); |
---|
4910 | Â Â Â Â Â Â Â //int nOut = outDupRow(clpSolver); |
---|
4911 | Â Â Â Â Â Â Â CglDuplicateRow dupcuts(clpSolver); |
---|
4912 | Â Â Â Â Â Â Â storedCuts =Â dupcuts.outDuplicates(clpSolver)!=0; |
---|
4913 |        int nOut = numberRows-clpSolver->getNumRows(); |
---|
4914 |        if (nOut&&!noPrinting_) |
---|
4915 | Â Â Â Â Â Â Â Â sprintf(generalPrint,"%d rows eliminated",nOut); |
---|
4916 | Â Â Â Â Â Â Â generalMessageHandler->message(CLP_GENERAL,generalMessages) |
---|
4917 | Â Â Â Â Â Â Â Â <<Â generalPrint |
---|
4918 | Â Â Â Â Â Â Â Â <<CoinMessageEol; |
---|
4919 |       } else { |
---|
4920 | #ifndef DISALLOW_PRINTING |
---|
4921 | Â Â Â Â Â Â Â std::cout<<"** Current model not valid"<<std::endl; |
---|
4922 | #endif |
---|
4923 | Â Â Â Â Â Â } |
---|
4924 | Â Â Â Â Â Â break; |
---|
4925 |      case NETWORK: |
---|
4926 |       if (goodModel) { |
---|
4927 | Â Â Â Â Â Â Â ClpMatrixBase *Â saveMatrix =Â lpSolver->clpMatrix(); |
---|
4928 | Â Â Â Â Â Â Â ClpPackedMatrix*Â clpMatrix = |
---|
4929 | Â Â Â Â Â Â Â Â dynamic_cast<Â ClpPackedMatrix*>(saveMatrix); |
---|
4930 |        if (clpMatrix) { |
---|
4931 |         ClpNetworkMatrix * newMatrix = new ClpNetworkMatrix(*(clpMatrix->matrix())); |
---|
4932 |         if (newMatrix->getIndices()) { |
---|
4933 | Â Â Â Â Â Â Â Â Â lpSolver->replaceMatrix(newMatrix); |
---|
4934 |          delete saveMatrix; |
---|
4935 | Â Â Â Â Â Â Â Â Â std::cout<<"Matrix converted to network matrix"<<std::endl; |
---|
4936 |         } else { |
---|
4937 | Â Â Â Â Â Â Â Â Â std::cout<<"Matrix can not be converted to network matrix"<<std::endl; |
---|
4938 | Â Â Â Â Â Â Â Â } |
---|
4939 |        } else { |
---|
4940 | Â Â Â Â Â Â Â Â std::cout<<"Matrix not a ClpPackedMatrix"<<std::endl; |
---|
4941 | Â Â Â Â Â Â Â } |
---|
4942 |       } else { |
---|
4943 | #ifndef DISALLOW_PRINTING |
---|
4944 | Â Â Â Â Â Â Â std::cout<<"** Current model not valid"<<std::endl; |
---|
4945 | #endif |
---|
4946 | Â Â Â Â Â Â } |
---|
4947 | Â Â Â Â Â Â break; |
---|
4948 |      case DOHEURISTIC: |
---|
4949 |       if (goodModel) { |
---|
4950 |        int vubAction = parameters_[whichParam(VUBTRY,numberParameters_,parameters_)].intValue(); |
---|
4951 |        if (vubAction!=-1) { |
---|
4952 | Â Â Â Â Â Â Â Â // look at vubs |
---|
4953 | Â Â Â Â Â Â Â Â // Just ones which affect >= extra3 |
---|
4954 |         int extra3 = parameters_[whichParam(EXTRA3,numberParameters_,parameters_)].intValue(); |
---|
4955 | Â Â Â Â Â Â Â Â /* 3 is fraction of integer variables fixed (0.97) |
---|
4956 | Â Â Â Â Â Â Â Â Â Â 4 is fraction of all variables fixed (0.0) |
---|
4957 | Â Â Â Â Â Â Â Â */ |
---|
4958 |         double dextra[5]; |
---|
4959 | Â Â Â Â Â Â Â Â dextra[1]Â =Â parameters_[whichParam(DEXTRA1,numberParameters_,parameters_)].doubleValue(); |
---|
4960 | Â Â Â Â Â Â Â Â dextra[2]Â =Â parameters_[whichParam(DEXTRA2,numberParameters_,parameters_)].doubleValue(); |
---|
4961 | Â Â Â Â Â Â Â Â dextra[3]Â =Â parameters_[whichParam(DEXTRA3,numberParameters_,parameters_)].doubleValue(); |
---|
4962 | Â Â Â Â Â Â Â Â dextra[4]Â =Â parameters_[whichParam(DEXTRA4,numberParameters_,parameters_)].doubleValue(); |
---|
4963 |         if (!dextra[3]) |
---|
4964 | Â Â Â Â Â Â Â Â Â dextra[3]Â =Â 0.97; |
---|
4965 | Â Â Â Â Â Â Â Â //OsiClpSolverInterface * newSolver = |
---|
4966 | Â Â Â Â Â Â Â Â fixVubs(model_,extra3,vubAction,generalMessageHandler, |
---|
4967 | Â Â Â Â Â Â Â Â Â Â Â Â debugValues,dextra); |
---|
4968 | Â Â Â Â Â Â Â Â //assert (!newSolver); |
---|
4969 | Â Â Â Â Â Â Â } |
---|
4970 | Â Â Â Â Â Â Â // Actually do heuristics |
---|
4971 | Â Â Â Â Â Â Â doHeuristics(&model_,2); |
---|
4972 |        if (model_.bestSolution()) { |
---|
4973 | Â Â Â Â Â Â Â Â model_.setProblemStatus(1); |
---|
4974 | Â Â Â Â Â Â Â Â model_.setSecondaryStatus(6); |
---|
4975 | #ifdef COIN_HAS_ASL |
---|
4976 |         if (statusUserFunction_[0]) { |
---|
4977 |          double value = model_.getObjValue(); |
---|
4978 |          char buf[300]; |
---|
4979 |          int pos=0; |
---|
4980 | Â Â Â Â Â Â Â Â Â pos +=Â sprintf(buf+pos,"feasible,"); |
---|
4981 | Â Â Â Â Â Â Â Â Â info.problemStatus=0; |
---|
4982 | Â Â Â Â Â Â Â Â Â info.objValue =Â value; |
---|
4983 | Â Â Â Â Â Â Â Â Â pos +=Â sprintf(buf+pos," objective %.*g",ampl_obj_prec(), |
---|
4984 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â value); |
---|
4985 | Â Â Â Â Â Â Â Â Â sprintf(buf+pos,"\n0 iterations"); |
---|
4986 | Â Â Â Â Â Â Â Â Â free(info.primalSolution); |
---|
4987 |          int numberColumns=lpSolver->numberColumns(); |
---|
4988 |          info.primalSolution = (double *) malloc(numberColumns*sizeof(double)); |
---|
4989 | Â Â Â Â Â Â Â Â Â CoinCopyN(model_.bestSolution(),numberColumns,info.primalSolution); |
---|
4990 |          int numberRows = lpSolver->numberRows(); |
---|
4991 | Â Â Â Â Â Â Â Â Â free(info.dualSolution); |
---|
4992 |          info.dualSolution = (double *) malloc(numberRows*sizeof(double)); |
---|
4993 | Â Â Â Â Â Â Â Â Â CoinZeroN(info.dualSolution,numberRows); |
---|
4994 | Â Â Â Â Â Â Â Â Â CoinWarmStartBasis *Â basis =Â lpSolver->getBasis(); |
---|
4995 | Â Â Â Â Â Â Â Â Â free(info.rowStatus); |
---|
4996 |          info.rowStatus = (int *) malloc(numberRows*sizeof(int)); |
---|
4997 | Â Â Â Â Â Â Â Â Â free(info.columnStatus); |
---|
4998 |          info.columnStatus = (int *) malloc(numberColumns*sizeof(int)); |
---|
4999 | Â Â Â Â Â Â Â Â Â // Put basis in |
---|
5000 |          int i; |
---|
5001 | Â Â Â Â Â Â Â Â Â // free,basic,ub,lb are 0,1,2,3 |
---|
5002 |          for (i=0;i<numberRows;i++) { |
---|
5003 | Â Â Â Â Â Â Â Â Â Â CoinWarmStartBasis::Status status =Â basis->getArtifStatus(i); |
---|
5004 | Â Â Â Â Â Â Â Â Â Â info.rowStatus[i]=status; |
---|
5005 | Â Â Â Â Â Â Â Â Â } |
---|
5006 |          for (i=0;i<numberColumns;i++) { |
---|
5007 | Â Â Â Â Â Â Â Â Â Â CoinWarmStartBasis::Status status =Â basis->getStructStatus(i); |
---|
5008 | Â Â Â Â Â Â Â Â Â Â info.columnStatus[i]=status; |
---|
5009 | Â Â Â Â Â Â Â Â Â } |
---|
5010 | Â Â Â Â Â Â Â Â Â // put buffer into info |
---|
5011 | Â Â Â Â Â Â Â Â Â strcpy(info.buffer,buf); |
---|
5012 |          delete basis; |
---|
5013 | Â Â Â Â Â Â Â Â } |
---|
5014 | #endif |
---|
5015 | Â Â Â Â Â Â Â } |
---|
5016 | #ifdef NEW_STYLE_SOLVER |
---|
5017 |        int returnCode = callBack_->callBack(&model_,6); |
---|
5018 | #else |
---|
5019 |        int returnCode=callBack(&model,6); |
---|
5020 | #endif |
---|
5021 |        if (returnCode) { |
---|
5022 | Â Â Â Â Â Â Â Â // exit if user wants |
---|
5023 | #ifdef NEW_STYLE_SOLVER |
---|
5024 | Â Â Â Â Â Â Â Â updateModel(NULL,returnMode); |
---|
5025 | #else |
---|
5026 |         delete babModel_; |
---|
5027 | Â Â Â Â Â Â Â Â babModel_ =Â NULL; |
---|
5028 | #endif |
---|
5029 |         return returnCode; |
---|
5030 | Â Â Â Â Â Â Â } |
---|
5031 | Â Â Â Â Â Â } |
---|
5032 | Â Â Â Â Â Â break; |
---|
5033 |      case MIPLIB: |
---|
5034 | Â Â Â Â Â Â // User can set options - main difference is lack of model and CglPreProcess |
---|
5035 | Â Â Â Â Â Â goodModel=true; |
---|
5036 | /* |
---|
5037 | Â Run branch-and-cut. First set a few options -- node comparison, scaling. |
---|
5038 | Â Print elapsed time at the end. |
---|
5039 | */ |
---|
5040 |      case BAB: // branchAndBound |
---|
5041 |      case STRENGTHEN: |
---|
5042 |       if (goodModel) { |
---|
5043 |        bool miplib = type==MIPLIB; |
---|
5044 |        int logLevel = parameters_[slog].intValue(); |
---|
5045 | Â Â Â Â Â Â Â // Reduce printout |
---|
5046 |        if (logLevel<=1) |
---|
5047 | Â Â Â Â Â Â Â Â model_.solver()->setHintParam(OsiDoReducePrint,true,OsiHintTry); |
---|
5048 | Â Â Â Â Â Â Â { |
---|
5049 | Â Â Â Â Â Â Â Â OsiSolverInterface *Â solver =Â model_.solver(); |
---|
5050 | Â Â Â Â Â Â Â Â OsiClpSolverInterface *Â si = |
---|
5051 | Â Â Â Â Â Â Â Â Â dynamic_cast<OsiClpSolverInterface *>(solver)Â ; |
---|
5052 | Â Â Â Â Â Â Â Â assert (si !=Â NULL); |
---|
5053 | Â Â Â Â Â Â Â Â si->getModelPtr()->scaling(doScaling); |
---|
5054 | Â Â Â Â Â Â Â Â // See if quadratic |
---|
5055 | #ifdef COIN_HAS_LINK |
---|
5056 |         if (!complicatedInteger) { |
---|
5057 | Â Â Â Â Â Â Â Â Â ClpSimplex *Â lpSolver =Â si->getModelPtr(); |
---|
5058 | Â Â Â Â Â Â Â Â Â ClpQuadraticObjective *Â obj =Â (dynamic_cast<Â ClpQuadraticObjective*>(lpSolver->objectiveAsObject())); |
---|
5059 |          if (obj) { |
---|
5060 | Â Â Â Â Â Â Â Â Â Â preProcess=0; |
---|
5061 |           int testOsiOptions = parameters_[whichParam(TESTOSI,numberParameters_,parameters_)].intValue(); |
---|
5062 | Â Â Â Â Â Â Â Â Â Â parameters_[whichParam(TESTOSI,numberParameters_,parameters_)].setIntValue(CoinMax(0,testOsiOptions)); |
---|
5063 | Â Â Â Â Â Â Â Â Â Â // create coin model |
---|
5064 | Â Â Â Â Â Â Â Â Â Â coinModel =Â lpSolver->createCoinModel(); |
---|
5065 | Â Â Â Â Â Â Â Â Â Â assert (coinModel); |
---|
5066 | Â Â Â Â Â Â Â Â Â Â // load from coin model |
---|
5067 | Â Â Â Â Â Â Â Â Â Â OsiSolverLink solver1; |
---|
5068 | Â Â Â Â Â Â Â Â Â Â OsiSolverInterface *Â solver2 =Â solver1.clone(); |
---|
5069 | Â Â Â Â Â Â Â Â Â Â model_.assignSolver(solver2,false); |
---|
5070 | Â Â Â Â Â Â Â Â Â Â OsiSolverLink *Â si = |
---|
5071 | Â Â Â Â Â Â Â Â Â Â Â dynamic_cast<OsiSolverLink *>(model_.solver())Â ; |
---|
5072 | Â Â Â Â Â Â Â Â Â Â assert (si !=Â NULL); |
---|
5073 | Â Â Â Â Â Â Â Â Â Â si->setDefaultMeshSize(0.001); |
---|
5074 | Â Â Â Â Â Â Â Â Â Â // need some relative granularity |
---|
5075 | Â Â Â Â Â Â Â Â Â Â si->setDefaultBound(100.0); |
---|
5076 |           double dextra3 = parameters_[whichParam(DEXTRA3,numberParameters_,parameters_)].doubleValue(); |
---|
5077 |           if (dextra3) |
---|
5078 | Â Â Â Â Â Â Â Â Â Â Â si->setDefaultMeshSize(dextra3); |
---|
5079 | Â Â Â Â Â Â Â Â Â Â si->setDefaultBound(1000.0); |
---|
5080 | Â Â Â Â Â Â Â Â Â Â si->setIntegerPriority(1000); |
---|
5081 | Â Â Â Â Â Â Â Â Â Â si->setBiLinearPriority(10000); |
---|
5082 | Â Â Â Â Â Â Â Â Â Â si->setSpecialOptions2(2+4+8); |
---|
5083 | Â Â Â Â Â Â Â Â Â Â CoinModel *Â model2 =Â (CoinModel *)Â coinModel; |
---|
5084 |           si->load(*model2,true, parameters_[log].intValue()); |
---|
5085 | Â Â Â Â Â Â Â Â Â Â // redo |
---|
5086 | Â Â Â Â Â Â Â Â Â Â solver =Â model_.solver(); |
---|
5087 | Â Â Â Â Â Â Â Â Â Â clpSolver =Â dynamic_cast<Â OsiClpSolverInterface*>Â (solver); |
---|
5088 | Â Â Â Â Â Â Â Â Â Â lpSolver =Â clpSolver->getModelPtr(); |
---|
5089 | Â Â Â Â Â Â Â Â Â Â clpSolver->messageHandler()->setLogLevel(0)Â ; |
---|
5090 | Â Â Â Â Â Â Â Â Â Â testOsiParameters=0; |
---|
5091 | Â Â Â Â Â Â Â Â Â Â complicatedInteger=2;Â // allow cuts |
---|
5092 | Â Â Â Â Â Â Â Â Â Â OsiSolverInterface *Â coinSolver =Â model_.solver(); |
---|
5093 | Â Â Â Â Â Â Â Â Â Â OsiSolverLink *Â linkSolver =Â dynamic_cast<Â OsiSolverLink*>Â (coinSolver); |
---|
5094 |           if (linkSolver->quadraticModel()) { |
---|
5095 | Â Â Â Â Â Â Â Â Â Â Â ClpSimplex *Â qp =Â linkSolver->quadraticModel(); |
---|
5096 | Â Â Â Â Â Â Â Â Â Â Â //linkSolver->nonlinearSLP(CoinMax(slpValue,10),1.0e-5); |
---|
5097 | Â Â Â Â Â Â Â Â Â Â Â qp->nonlinearSLP(CoinMax(slpValue,40),1.0e-5); |
---|
5098 | Â Â Â Â Â Â Â Â Â Â Â qp->primal(1); |
---|
5099 | Â Â Â Â Â Â Â Â Â Â Â OsiSolverLinearizedQuadratic solver2(qp); |
---|
5100 |            const double * solution=NULL; |
---|
5101 | Â Â Â Â Â Â Â Â Â Â Â // Reduce printout |
---|
5102 | Â Â Â Â Â Â Â Â Â Â Â solver2.setHintParam(OsiDoReducePrint,true,OsiHintTry); |
---|
5103 | Â Â Â Â Â Â Â Â Â Â Â CbcModel model2(solver2); |
---|
5104 | Â Â Â Â Â Â Â Â Â Â Â // Now do requested saves and modifications |
---|
5105 | Â Â Â Â Â Â Â Â Â Â Â CbcModel *Â cbcModel =Â &Â model2; |
---|
5106 | Â Â Â Â Â Â Â Â Â Â Â OsiSolverInterface *Â osiModel =Â model2.solver(); |
---|
5107 | Â Â Â Â Â Â Â Â Â Â Â OsiClpSolverInterface *Â osiclpModel =Â dynamic_cast<Â OsiClpSolverInterface*>Â (osiModel); |
---|
5108 | Â Â Â Â Â Â Â Â Â Â Â ClpSimplex *Â clpModel =Â osiclpModel->getModelPtr(); |
---|
5109 | Â Â Â Â Â Â Â Â Â Â Â |
---|
5110 | Â Â Â Â Â Â Â Â Â Â Â // Set changed values |
---|
5111 | Â Â Â Â Â Â Â Â Â Â Â |
---|
5112 | Â Â Â Â Â Â Â Â Â Â Â CglProbing probing; |
---|
5113 | Â Â Â Â Â Â Â Â Â Â Â probing.setMaxProbe(10); |
---|
5114 | Â Â Â Â Â Â Â Â Â Â Â probing.setMaxLook(10); |
---|
5115 | Â Â Â Â Â Â Â Â Â Â Â probing.setMaxElements(200); |
---|
5116 | Â Â Â Â Â Â Â Â Â Â Â probing.setMaxProbeRoot(50); |
---|
5117 | Â Â Â Â Â Â Â Â Â Â Â probing.setMaxLookRoot(10); |
---|
5118 | Â Â Â Â Â Â Â Â Â Â Â probing.setRowCuts(3); |
---|
5119 | Â Â Â Â Â Â Â Â Â Â Â probing.setUsingObjective(true); |
---|
5120 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->addCutGenerator(&probing,-1,"Probing",true,false,false,-100,-1,-1); |
---|
5121 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->cutGenerator(0)->setTiming(true); |
---|
5122 | Â Â Â Â Â Â Â Â Â Â Â |
---|
5123 | Â Â Â Â Â Â Â Â Â Â Â CglGomory gomory; |
---|
5124 | Â Â Â Â Â Â Â Â Â Â Â gomory.setLimitAtRoot(512); |
---|
5125 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->addCutGenerator(&gomory,-98,"Gomory",true,false,false,-100,-1,-1); |
---|
5126 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->cutGenerator(1)->setTiming(true); |
---|
5127 | Â Â Â Â Â Â Â Â Â Â Â |
---|
5128 | Â Â Â Â Â Â Â Â Â Â Â CglKnapsackCover knapsackCover; |
---|
5129 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->addCutGenerator(&knapsackCover,-98,"KnapsackCover",true,false,false,-100,-1,-1); |
---|
5130 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->cutGenerator(2)->setTiming(true); |
---|
5131 | Â Â Â Â Â Â Â Â Â Â Â |
---|
5132 | Â Â Â Â Â Â Â Â Â Â Â CglRedSplit redSplit; |
---|
5133 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->addCutGenerator(&redSplit,-99,"RedSplit",true,false,false,-100,-1,-1); |
---|
5134 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->cutGenerator(3)->setTiming(true); |
---|
5135 | Â Â Â Â Â Â Â Â Â Â Â |
---|
5136 | Â Â Â Â Â Â Â Â Â Â Â CglClique clique; |
---|
5137 | Â Â Â Â Â Â Â Â Â Â Â clique.setStarCliqueReport(false); |
---|
5138 | Â Â Â Â Â Â Â Â Â Â Â clique.setRowCliqueReport(false); |
---|
5139 | Â Â Â Â Â Â Â Â Â Â Â clique.setMinViolation(0.1); |
---|
5140 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->addCutGenerator(&clique,-98,"Clique",true,false,false,-100,-1,-1); |
---|
5141 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->cutGenerator(4)->setTiming(true); |
---|
5142 | Â Â Â Â Â Â Â Â Â Â Â |
---|
5143 | Â Â Â Â Â Â Â Â Â Â Â CglMixedIntegerRounding2 mixedIntegerRounding2; |
---|
5144 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->addCutGenerator(&mixedIntegerRounding2,-98,"MixedIntegerRounding2",true,false,false,-100,-1,-1); |
---|
5145 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->cutGenerator(5)->setTiming(true); |
---|
5146 | Â Â Â Â Â Â Â Â Â Â Â |
---|
5147 | Â Â Â Â Â Â Â Â Â Â Â CglFlowCover flowCover; |
---|
5148 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->addCutGenerator(&flowCover,-98,"FlowCover",true,false,false,-100,-1,-1); |
---|
5149 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->cutGenerator(6)->setTiming(true); |
---|
5150 | Â Â Â Â Â Â Â Â Â Â Â |
---|
5151 | Â Â Â Â Â Â Â Â Â Â Â CglTwomir twomir; |
---|
5152 | Â Â Â Â Â Â Â Â Â Â Â twomir.setMaxElements(250); |
---|
5153 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->addCutGenerator(&twomir,-99,"Twomir",true,false,false,-100,-1,-1); |
---|
5154 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->cutGenerator(7)->setTiming(true); |
---|
5155 | Â Â Â Â Â Â Â Â Â Â Â |
---|
5156 | Â Â Â Â Â Â Â Â Â Â Â CbcHeuristicFPump heuristicFPump(*cbcModel); |
---|
5157 | Â Â Â Â Â Â Â Â Â Â Â heuristicFPump.setWhen(13); |
---|
5158 | Â Â Â Â Â Â Â Â Â Â Â heuristicFPump.setMaximumPasses(20); |
---|
5159 | Â Â Â Â Â Â Â Â Â Â Â heuristicFPump.setMaximumRetries(7); |
---|
5160 | Â Â Â Â Â Â Â Â Â Â Â heuristicFPump.setHeuristicName("feasibility pump"); |
---|
5161 | Â Â Â Â Â Â Â Â Â Â Â heuristicFPump.setInitialWeight(1); |
---|
5162 | Â Â Â Â Â Â Â Â Â Â Â heuristicFPump.setFractionSmall(0.6); |
---|
5163 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->addHeuristic(&heuristicFPump); |
---|
5164 | Â Â Â Â Â Â Â Â Â Â Â |
---|
5165 | Â Â Â Â Â Â Â Â Â Â Â CbcRounding rounding(*cbcModel); |
---|
5166 | Â Â Â Â Â Â Â Â Â Â Â rounding.setHeuristicName("rounding"); |
---|
5167 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->addHeuristic(&rounding); |
---|
5168 | Â Â Â Â Â Â Â Â Â Â Â |
---|
5169 | Â Â Â Â Â Â Â Â Â Â Â CbcHeuristicLocal heuristicLocal(*cbcModel); |
---|
5170 | Â Â Â Â Â Â Â Â Â Â Â heuristicLocal.setHeuristicName("combine solutions"); |
---|
5171 | Â Â Â Â Â Â Â Â Â Â Â heuristicLocal.setSearchType(1); |
---|
5172 | Â Â Â Â Â Â Â Â Â Â Â heuristicLocal.setFractionSmall(0.6); |
---|
5173 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->addHeuristic(&heuristicLocal); |
---|
5174 | Â Â Â Â Â Â Â Â Â Â Â |
---|
5175 | Â Â Â Â Â Â Â Â Â Â Â CbcHeuristicGreedyCover heuristicGreedyCover(*cbcModel); |
---|
5176 | Â Â Â Â Â Â Â Â Â Â Â heuristicGreedyCover.setHeuristicName("greedy cover"); |
---|
5177 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->addHeuristic(&heuristicGreedyCover); |
---|
5178 | Â Â Â Â Â Â Â Â Â Â Â |
---|
5179 | Â Â Â Â Â Â Â Â Â Â Â CbcHeuristicGreedyEquality heuristicGreedyEquality(*cbcModel); |
---|
5180 | Â Â Â Â Â Â Â Â Â Â Â heuristicGreedyEquality.setHeuristicName("greedy equality"); |
---|
5181 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->addHeuristic(&heuristicGreedyEquality); |
---|
5182 | Â Â Â Â Â Â Â Â Â Â Â |
---|
5183 | Â Â Â Â Â Â Â Â Â Â Â CbcCompareDefault compare; |
---|
5184 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->setNodeComparison(compare); |
---|
5185 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->setNumberBeforeTrust(5); |
---|
5186 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->setSpecialOptions(2); |
---|
5187 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->messageHandler()->setLogLevel(1); |
---|
5188 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->setMaximumCutPassesAtRoot(-100); |
---|
5189 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->setMaximumCutPasses(1); |
---|
5190 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->setMinimumDrop(0.05); |
---|
5191 | Â Â Â Â Â Â Â Â Â Â Â // For branchAndBound this may help |
---|
5192 | Â Â Â Â Â Â Â Â Â Â Â clpModel->defaultFactorizationFrequency(); |
---|
5193 | Â Â Â Â Â Â Â Â Â Â Â clpModel->setDualBound(1.0001e+08); |
---|
5194 | Â Â Â Â Â Â Â Â Â Â Â clpModel->setPerturbation(50); |
---|
5195 | Â Â Â Â Â Â Â Â Â Â Â osiclpModel->setSpecialOptions(193); |
---|
5196 | Â Â Â Â Â Â Â Â Â Â Â osiclpModel->messageHandler()->setLogLevel(0); |
---|
5197 | Â Â Â Â Â Â Â Â Â Â Â osiclpModel->setIntParam(OsiMaxNumIterationHotStart,100); |
---|
5198 | Â Â Â Â Â Â Â Â Â Â Â osiclpModel->setHintParam(OsiDoReducePrint,true,OsiHintTry); |
---|
5199 | Â Â Â Â Â Â Â Â Â Â Â // You can save some time by switching off message building |
---|
5200 | Â Â Â Â Â Â Â Â Â Â Â // clpModel->messagesPointer()->setDetailMessages(100,10000,(int *) NULL); |
---|
5201 | Â Â Â Â Â Â Â Â Â Â Â |
---|
5202 | Â Â Â Â Â Â Â Â Â Â Â // Solve |
---|
5203 | Â Â Â Â Â Â Â Â Â Â Â |
---|
5204 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->initialSolve(); |
---|
5205 |            if (clpModel->tightenPrimalBounds()!=0) { |
---|
5206 | #ifndef DISALLOW_PRINTING |
---|
5207 | Â Â Â Â Â Â Â Â Â Â Â Â std::cout<<"Problem is infeasible - tightenPrimalBounds!"<<std::endl; |
---|
5208 | #endif |
---|
5209 | Â Â Â Â Â Â Â Â Â Â Â Â break; |
---|
5210 | Â Â Â Â Â Â Â Â Â Â Â } |
---|
5211 | Â Â Â Â Â Â Â Â Â Â Â clpModel->dual();Â // clean up |
---|
5212 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->initialSolve(); |
---|
5213 | #ifdef CBC_THREAD |
---|
5214 |            int numberThreads =parameters_[whichParam(THREADS,numberParameters_,parameters_)].intValue(); |
---|
5215 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->setNumberThreads(numberThreads%100); |
---|
5216 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->setThreadMode(numberThreads/100); |
---|
5217 | #endif |
---|
5218 | Â Â Â Â Â Â Â Â Â Â Â cbcModel->branchAndBound(); |
---|
5219 | Â Â Â Â Â Â Â Â Â Â Â OsiSolverLinearizedQuadratic *Â solver3 =Â dynamic_cast<OsiSolverLinearizedQuadratic *>Â (model2.solver()); |
---|
5220 | Â Â Â Â Â Â Â Â Â Â Â assert (solver3); |
---|
5221 | Â Â Â Â Â Â Â Â Â Â Â solution =Â solver3->bestSolution(); |
---|
5222 |            double bestObjectiveValue = solver3->bestObjectiveValue(); |
---|
5223 | Â Â Â Â Â Â Â Â Â Â Â linkSolver->setBestObjectiveValue(bestObjectiveValue); |
---|
5224 | Â Â Â Â Â Â Â Â Â Â Â linkSolver->setBestSolution(solution,solver3->getNumCols()); |
---|
5225 | Â Â Â Â Â Â Â Â Â Â Â CbcHeuristicDynamic3 dynamic(model_); |
---|
5226 | Â Â Â Â Â Â Â Â Â Â Â dynamic.setHeuristicName("dynamic pass thru"); |
---|
5227 | Â Â Â Â Â Â Â Â Â Â Â model_.addHeuristic(&dynamic); |
---|
5228 | Â Â Â Â Â Â Â Â Â Â Â // if convex |
---|
5229 |            if ((linkSolver->specialOptions2()&4)!=0) { |
---|
5230 |             int numberColumns = coinModel->numberColumns(); |
---|
5231 | Â Â Â Â Â Â Â Â Â Â Â Â assert (linkSolver->objectiveVariable()==numberColumns); |
---|
5232 | Â Â Â Â Â Â Â Â Â Â Â Â // add OA cut |
---|
5233 |             double offset; |
---|
5234 |             double * gradient = new double [numberColumns+1]; |
---|
5235 | Â Â Â Â Â Â Â Â Â Â Â Â memcpy(gradient,qp->objectiveAsObject()->gradient(qp,solution,offset,true,2), |
---|
5236 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â numberColumns*sizeof(double)); |
---|
5237 |             double rhs = 0.0; |
---|
5238 |             int * column = new int[numberColumns+1]; |
---|
5239 |             int n=0; |
---|
5240 |             for (int i=0;i<numberColumns;i++) { |
---|
5241 |              double value = gradient[i]; |
---|
5242 |              if (fabs(value)>1.0e-12) { |
---|
5243 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â gradient[n]=value; |
---|
5244 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â rhs +=Â value*solution[i]; |
---|
5245 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â column[n++]=i; |
---|
5246 | Â Â Â Â Â Â Â Â Â Â Â Â Â } |
---|
5247 | Â Â Â Â Â Â Â Â Â Â Â Â } |
---|
5248 | Â Â Â Â Â Â Â Â Â Â Â Â gradient[n]=-1.0; |
---|
5249 | Â Â Â Â Â Â Â Â Â Â Â Â column[n++]=numberColumns; |
---|
5250 | Â Â Â Â Â Â Â Â Â Â Â Â storedAmpl.addCut(-COIN_DBL_MAX,offset+1.0e-7,n,column,gradient); |
---|
5251 |             delete [] gradient; |
---|
5252 |             delete [] column; |
---|
5253 | Â Â Â Â Â Â Â Â Â Â Â } |
---|
5254 | Â Â Â Â Â Â Â Â Â Â Â // could do three way branching round a) continuous b) best solution |
---|
5255 | Â Â Â Â Â Â Â Â Â Â Â printf("obj %g\n",bestObjectiveValue); |
---|
5256 | Â Â Â Â Â Â Â Â Â Â Â linkSolver->initialSolve(); |
---|
5257 | Â Â Â Â Â Â Â |
---|