0
5
2
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 |
* |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 |
* |
|
5 |
* Copyright (C) 2003-2009 |
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
|
8 |
* |
|
9 |
* Permission to use, modify and distribute this software is granted |
|
10 |
* provided that this copyright notice appears in all copies. For |
|
11 |
* precise terms see the accompanying LICENSE file. |
|
12 |
* |
|
13 |
* This software is provided "AS IS" with no warranty of any kind, |
|
14 |
* express or implied, and with no claim as to its suitability for any |
|
15 |
* purpose. |
|
16 |
* |
|
17 |
*/ |
|
18 |
|
|
19 |
///\file |
|
20 |
///\brief Some basic non-inline functions and static global data. |
|
21 |
|
|
22 |
#include<lemon/bits/windows.h> |
|
23 |
|
|
24 |
#ifdef WIN32 |
|
25 |
#ifndef WIN32_LEAN_AND_MEAN |
|
26 |
#define WIN32_LEAN_AND_MEAN |
|
27 |
#endif |
|
28 |
#ifndef NOMINMAX |
|
29 |
#define NOMINMAX |
|
30 |
#endif |
|
31 |
#include <windows.h> |
|
32 |
#else |
|
33 |
#include <unistd.h> |
|
34 |
#include <ctime> |
|
35 |
#include <sys/times.h> |
|
36 |
#include <sys/time.h> |
|
37 |
#endif |
|
38 |
|
|
39 |
#include <cmath> |
|
40 |
#include <sstream> |
|
41 |
|
|
42 |
namespace lemon { |
|
43 |
namespace bits { |
|
44 |
void getWinProcTimes(double &rtime, |
|
45 |
double &utime, double &stime, |
|
46 |
double &cutime, double &cstime) |
|
47 |
{ |
|
48 |
#ifdef WIN32 |
|
49 |
static const double ch = 4294967296.0e-7; |
|
50 |
static const double cl = 1.0e-7; |
|
51 |
|
|
52 |
FILETIME system; |
|
53 |
GetSystemTimeAsFileTime(&system); |
|
54 |
rtime = ch * system.dwHighDateTime + cl * system.dwLowDateTime; |
|
55 |
|
|
56 |
FILETIME create, exit, kernel, user; |
|
57 |
if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) { |
|
58 |
utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime; |
|
59 |
stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime; |
|
60 |
cutime = 0; |
|
61 |
cstime = 0; |
|
62 |
} else { |
|
63 |
rtime = 0; |
|
64 |
utime = 0; |
|
65 |
stime = 0; |
|
66 |
cutime = 0; |
|
67 |
cstime = 0; |
|
68 |
} |
|
69 |
#else |
|
70 |
timeval tv; |
|
71 |
gettimeofday(&tv, 0); |
|
72 |
rtime=tv.tv_sec+double(tv.tv_usec)/1e6; |
|
73 |
|
|
74 |
tms ts; |
|
75 |
double tck=sysconf(_SC_CLK_TCK); |
|
76 |
times(&ts); |
|
77 |
utime=ts.tms_utime/tck; |
|
78 |
stime=ts.tms_stime/tck; |
|
79 |
cutime=ts.tms_cutime/tck; |
|
80 |
cstime=ts.tms_cstime/tck; |
|
81 |
#endif |
|
82 |
} |
|
83 |
|
|
84 |
std::string getWinFormattedDate() |
|
85 |
{ |
|
86 |
std::ostringstream os; |
|
87 |
#ifdef WIN32 |
|
88 |
SYSTEMTIME time; |
|
89 |
GetSystemTime(&time); |
|
90 |
#if defined(_MSC_VER) && (_MSC_VER < 1500) |
|
91 |
LPWSTR buf1, buf2, buf3; |
|
92 |
if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, |
|
93 |
L"ddd MMM dd", buf1, 11) && |
|
94 |
GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time, |
|
95 |
L"HH':'mm':'ss", buf2, 9) && |
|
96 |
GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, |
|
97 |
L"yyyy", buf3, 5)) { |
|
98 |
os << buf1 << ' ' << buf2 << ' ' << buf3; |
|
99 |
} |
|
100 |
#else |
|
101 |
char buf1[11], buf2[9], buf3[5]; |
|
102 |
if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, |
|
103 |
"ddd MMM dd", buf1, 11) && |
|
104 |
GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time, |
|
105 |
"HH':'mm':'ss", buf2, 9) && |
|
106 |
GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, |
|
107 |
"yyyy", buf3, 5)) { |
|
108 |
os << buf1 << ' ' << buf2 << ' ' << buf3; |
|
109 |
} |
|
110 |
#endif |
|
111 |
else os << "unknown"; |
|
112 |
#else |
|
113 |
timeval tv; |
|
114 |
gettimeofday(&tv, 0); |
|
115 |
|
|
116 |
char cbuf[26]; |
|
117 |
ctime_r(&tv.tv_sec,cbuf); |
|
118 |
os << cbuf; |
|
119 |
#endif |
|
120 |
return os.str(); |
|
121 |
} |
|
122 |
|
|
123 |
int getWinRndSeed() |
|
124 |
{ |
|
125 |
#ifdef WIN32 |
|
126 |
FILETIME time; |
|
127 |
GetSystemTimeAsFileTime(&time); |
|
128 |
return GetCurrentProcessId() + time.dwHighDateTime + time.dwLowDateTime; |
|
129 |
#else |
|
130 |
timeval tv; |
|
131 |
gettimeofday(&tv, 0); |
|
132 |
return getpid() + tv.tv_sec + tv.tv_usec; |
|
133 |
#endif |
|
134 |
} |
|
135 |
} |
|
136 |
} |
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
|
2 |
* |
|
3 |
* This file is a part of LEMON, a generic C++ optimization library. |
|
4 |
* |
|
5 |
* Copyright (C) 2003-2009 |
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
|
8 |
* |
|
9 |
* Permission to use, modify and distribute this software is granted |
|
10 |
* provided that this copyright notice appears in all copies. For |
|
11 |
* precise terms see the accompanying LICENSE file. |
|
12 |
* |
|
13 |
* This software is provided "AS IS" with no warranty of any kind, |
|
14 |
* express or implied, and with no claim as to its suitability for any |
|
15 |
* purpose. |
|
16 |
* |
|
17 |
*/ |
|
18 |
|
|
19 |
#ifndef LEMON_WINDOWS_H |
|
20 |
#define LEMON_WINDOWS_H |
|
21 |
|
|
22 |
#include <string> |
|
23 |
|
|
24 |
namespace lemon { |
|
25 |
namespace bits { |
|
26 |
void getWinProcTimes(double &rtime, |
|
27 |
double &utime, double &stime, |
|
28 |
double &cutime, double &cstime); |
|
29 |
std::string getWinFormattedDate(); |
|
30 |
int getWinRndSeed(); |
|
31 |
} |
|
32 |
} |
|
33 |
|
|
34 |
#endif |
... | ... |
@@ -10,7 +10,8 @@ |
10 | 10 |
lemon/arg_parser.cc \ |
11 | 11 |
lemon/base.cc \ |
12 | 12 |
lemon/color.cc \ |
13 |
lemon/random.cc |
|
13 |
lemon/random.cc \ |
|
14 |
lemon/bits/windows.cc |
|
14 | 15 |
|
15 | 16 |
#lemon_libemon_la_CXXFLAGS = $(GLPK_CFLAGS) $(CPLEX_CFLAGS) $(SOPLEX_CXXFLAGS) |
16 | 17 |
#lemon_libemon_la_LDFLAGS = $(GLPK_LIBS) $(CPLEX_LIBS) $(SOPLEX_LIBS) |
... | ... |
@@ -40,7 +41,8 @@ |
40 | 41 |
lemon/smart_graph.h \ |
41 | 42 |
lemon/time_measure.h \ |
42 | 43 |
lemon/tolerance.h \ |
43 |
lemon/unionfind.h |
|
44 |
lemon/unionfind.h \ |
|
45 |
lemon/bits/windows.h |
|
44 | 46 |
|
45 | 47 |
bits_HEADERS += \ |
46 | 48 |
lemon/bits/alteration_notifier.h \ |
... | ... |
@@ -29,13 +29,7 @@ |
29 | 29 |
#include<sys/time.h> |
30 | 30 |
#include<ctime> |
31 | 31 |
#else |
32 |
#ifndef WIN32_LEAN_AND_MEAN |
|
33 |
#define WIN32_LEAN_AND_MEAN |
|
34 |
#endif |
|
35 |
#ifndef NOMINMAX |
|
36 |
#define NOMINMAX |
|
37 |
#endif |
|
38 |
#include<windows.h> |
|
32 |
#include<lemon/bits/windows.h> |
|
39 | 33 |
#endif |
40 | 34 |
|
41 | 35 |
#include<lemon/math.h> |
... | ... |
@@ -683,41 +677,19 @@ |
683 | 677 |
os << "%%Creator: LEMON, graphToEps()\n"; |
684 | 678 |
|
685 | 679 |
{ |
680 |
os << "%%CreationDate: "; |
|
686 | 681 |
#ifndef WIN32 |
687 | 682 |
timeval tv; |
688 | 683 |
gettimeofday(&tv, 0); |
689 | 684 |
|
690 | 685 |
char cbuf[26]; |
691 | 686 |
ctime_r(&tv.tv_sec,cbuf); |
692 |
os << |
|
687 |
os << cbuf; |
|
693 | 688 |
#else |
694 |
SYSTEMTIME time; |
|
695 |
GetSystemTime(&time); |
|
696 |
#if defined(_MSC_VER) && (_MSC_VER < 1500) |
|
697 |
LPWSTR buf1, buf2, buf3; |
|
698 |
if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, |
|
699 |
L"ddd MMM dd", buf1, 11) && |
|
700 |
GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time, |
|
701 |
L"HH':'mm':'ss", buf2, 9) && |
|
702 |
GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, |
|
703 |
L"yyyy", buf3, 5)) { |
|
704 |
os << "%%CreationDate: " << buf1 << ' ' |
|
705 |
<< buf2 << ' ' << buf3 << std::endl; |
|
706 |
} |
|
707 |
#else |
|
708 |
char buf1[11], buf2[9], buf3[5]; |
|
709 |
if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, |
|
710 |
"ddd MMM dd", buf1, 11) && |
|
711 |
GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time, |
|
712 |
"HH':'mm':'ss", buf2, 9) && |
|
713 |
GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, |
|
714 |
"yyyy", buf3, 5)) { |
|
715 |
os << "%%CreationDate: " << buf1 << ' ' |
|
716 |
<< buf2 << ' ' << buf3 << std::endl; |
|
717 |
} |
|
718 |
|
|
689 |
os << bits::getWinFormattedDate(); |
|
719 | 690 |
#endif |
720 | 691 |
} |
692 |
os << std::endl; |
|
721 | 693 |
|
722 | 694 |
if (_autoArcWidthScale) { |
723 | 695 |
double max_w=0; |
... | ... |
@@ -77,7 +77,7 @@ |
77 | 77 |
#include <sys/types.h> |
78 | 78 |
#include <unistd.h> |
79 | 79 |
#else |
80 |
#include <windows.h> |
|
80 |
#include <lemon/bits/windows.h> |
|
81 | 81 |
#endif |
82 | 82 |
|
83 | 83 |
///\ingroup misc |
... | ... |
@@ -666,9 +666,7 @@ |
666 | 666 |
gettimeofday(&tv, 0); |
667 | 667 |
seed(getpid() + tv.tv_sec + tv.tv_usec); |
668 | 668 |
#else |
669 |
FILETIME time; |
|
670 |
GetSystemTimeAsFileTime(&time); |
|
671 |
seed( |
|
669 |
seed(bits::getWinRndSeed()); |
|
672 | 670 |
#endif |
673 | 671 |
return true; |
674 | 672 |
} |
... | ... |
@@ -24,14 +24,7 @@ |
24 | 24 |
///\brief Tools for measuring cpu usage |
25 | 25 |
|
26 | 26 |
#ifdef WIN32 |
27 |
#ifndef WIN32_LEAN_AND_MEAN |
|
28 |
#define WIN32_LEAN_AND_MEAN |
|
29 |
#endif |
|
30 |
#ifndef NOMINMAX |
|
31 |
#define NOMINMAX |
|
32 |
#endif |
|
33 |
#include <windows.h> |
|
34 |
#include <cmath> |
|
27 |
#include <lemon/bits/windows.h> |
|
35 | 28 |
#else |
36 | 29 |
#include <unistd.h> |
37 | 30 |
#include <sys/times.h> |
... | ... |
@@ -92,26 +85,7 @@ |
92 | 85 |
cutime=ts.tms_cutime/tck; |
93 | 86 |
cstime=ts.tms_cstime/tck; |
94 | 87 |
#else |
95 |
static const double ch = 4294967296.0e-7; |
|
96 |
static const double cl = 1.0e-7; |
|
97 |
|
|
98 |
FILETIME system; |
|
99 |
GetSystemTimeAsFileTime(&system); |
|
100 |
rtime = ch * system.dwHighDateTime + cl * system.dwLowDateTime; |
|
101 |
|
|
102 |
FILETIME create, exit, kernel, user; |
|
103 |
if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) { |
|
104 |
utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime; |
|
105 |
stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime; |
|
106 |
cutime = 0; |
|
107 |
cstime = 0; |
|
108 |
} else { |
|
109 |
rtime = 0; |
|
110 |
utime = 0; |
|
111 |
stime = 0; |
|
112 |
cutime = 0; |
|
113 |
cstime = 0; |
|
114 |
} |
|
88 |
bits::getWinProcTimes(rtime, utime, stime, cutime, cstime); |
|
115 | 89 |
#endif |
116 | 90 |
} |
117 | 91 |
|
0 comments (0 inline)