[Coin-discuss] couple of patches
Livio Bertacco
livio at bertacco.it
Mon Jan 26 06:06:40 EST 2004
Hello,
I've been working a bit on getting OsiCpx to compile and link with
cplex*.lib under cygwin/Windows. For this you have to use the mingw
compiler (or cygwin gcc with option -mno-cygwin). Here is a few patches
I needed to apply (tested only under cygwin):
A) For mingw compilation:
1)
diff -r1.13 CoinFinite.hpp
79a80,87
> #if defined(__MINGW32__)
> # include<float.h>
> # define CoinIsnan _isnan
> # define CoinFinite _finite
> #endif
>
>
//======================================================================
=======
>
2)
diff -r1.5 CoinSignal.hpp
16c16
< #if defined(_MSC_VER)
---
> #if defined(_MSC_VER) || defined(__MINGW32__)
B) For proper cpu time readings under WinNT/2k/xp (clock() under Win32
returns wall-clock time, not cpu time):
1) Added COIN/Coin/CoinTimeWin.cpp
#ifdef _WIN32
#include <windows.h>
#include <time.h>
double CoinCpuTime()
{
double cpu_temp;
__int64 cre, ext, ker, usr=0;
static HANDLE me=GetCurrentProcess();
if(GetProcessTimes(me,(LPFILETIME)&cre,(LPFILETIME)&ext,(LPFILETIME)&ker
,(LPFILETIME)&usr)) return usr*1.0e-7;
else return clock()/(double)CLOCKS_PER_SEC; // fallback to clock() for
Win9x/ME
}
#endif
2) modified COIN/Coin/include/CoinTime.hpp
diff -r1.8 CoinTime.hpp
9a10,11
> #ifdef _WIN32
> double CoinCpuTime();
12a15
> #endif
19,22d21
< #endif
<
<
//######################################################################
#######
<
26,32d24
< #if defined(_MSC_VER)
< unsigned int ticksnow; /* clock_t is same as int */
<
< ticksnow = (unsigned int)clock();
<
< cpu_temp = (double)((double)ticksnow/CLOCKS_PER_SEC);
< #else
37d28
< #endif
39a31
> #endif
C) For OsiCpx and OsiGlpk to honor the algorithm and presolve hints
(it's not always good to re-solve with dual algo, e.g. when you just
change the objective and not the constraints):
1) OsiCpx
diff -r1.25 OsiCpxSolverInterface.cpp
189c189,200
< int term = CPXprimopt( env_, lp );
---
> // sort out hints;
> bool takeHint;
> OsiHintStrength strength;
> // Hint: OsiDoDualInInitial
> int (CPXPUBLIC *algorithm)(CPXCENVptr, CPXLPptr) = CPXlpopt;
> bool gotHint = (getHintParam(OsiDoDualInInitial,takeHint,strength));
> assert (gotHint);
> if (strength!=OsiHintIgnore) algorithm = takeHint ? CPXdualopt :
CPXprimopt;
> // Hint: OsiDoPresolveInInitial
> gotHint = (getHintParam(OsiDoPresolveInInitial,takeHint,strength));
> assert (gotHint);
> if (strength!=OsiHintIgnore) CPXsetintparam( env_, CPX_PARAM_PREIND,
takeHint );
190a202,203
> int term = algorithm( env_, lp );
>
195c208
< CPXprimopt( env_, lp );
---
> algorithm( env_, lp );
208c221,234
< int term = CPXdualopt( env_, lp );
---
> // sort out hints;
> bool takeHint;
> OsiHintStrength strength;
> // Hint: OsiDoDualInInitial
> int (CPXPUBLIC *algorithm)(CPXCENVptr, CPXLPptr) = CPXlpopt;
> bool gotHint = (getHintParam(OsiDoDualInResolve,takeHint,strength));
> assert (gotHint);
> if (strength!=OsiHintIgnore) algorithm = takeHint ? CPXdualopt :
CPXprimopt;
> // Hint: OsiDoPresolveInResolve
> gotHint = (getHintParam(OsiDoPresolveInResolve,takeHint,strength));
> assert (gotHint);
> if (strength!=OsiHintIgnore) CPXsetintparam( env_, CPX_PARAM_PREIND,
takeHint );
>
> int term = algorithm( env_, lp );
214c240
< CPXdualopt( env_, lp );
---
> algorithm( env_, lp );
2) OsiGlpk
diff -r1.12 OsiGlpkSolverInterface.cpp
90a91,102
> // sort out hints;
> bool takeHint;
> OsiHintStrength strength;
> // Hint: OsiDoDualInInitial
> bool gotHint =
(getHintParam(OsiDoDualInInitial,takeHint,strength));
> assert (gotHint);
> if (strength!=OsiHintIgnore) lpx_set_int_parm(model, LPX_K_DUAL,
takeHint);
> // Hint: OsiDoPresolveInInitial
> gotHint = (getHintParam(OsiDoPresolveInInitial,takeHint,strength));
> assert (gotHint);
> if (strength!=OsiHintIgnore) lpx_set_int_parm(model, LPX_K_PRESOL,
takeHint);
>
129c141,153
< lpx_set_int_parm(model, LPX_K_DUAL, 1); // Use dual simplex if
dual feasible
---
>
> // sort out hints;
> bool takeHint;
> OsiHintStrength strength;
> // Hint: OsiDoDualInInitial
> bool gotHint =
(getHintParam(OsiDoDualInResolve,takeHint,strength));
> assert (gotHint);
> if (strength!=OsiHintIgnore) lpx_set_int_parm(model, LPX_K_DUAL,
takeHint); // Use dual simplex if dual feasible
> // Hint: OsiDoPresolveInResolve
> gotHint = (getHintParam(OsiDoPresolveInResolve,takeHint,strength));
> assert (gotHint);
> if (strength!=OsiHintIgnore) lpx_set_int_parm(model, LPX_K_PRESOL,
takeHint);
>
2027c2051
< return OsiSolverInterface::readMps(filename,extension);
---
> return OsiSolverInterface::readMps(filename,extension);
Livio
More information about the Coin-discuss
mailing list