[Lemon-commits] [lemon_svn] deba: r2674 - in hugo/trunk/lemon: . bits

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:54:23 CET 2006


Author: deba
Date: Mon Apr  3 21:47:37 2006
New Revision: 2674

Added:
   hugo/trunk/lemon/bits/mingw32_rand.cc
   hugo/trunk/lemon/bits/mingw32_rand.h
   hugo/trunk/lemon/bits/mingw32_time.cc
Modified:
   hugo/trunk/lemon/Makefile.am
   hugo/trunk/lemon/bits/mingw32_time.h
   hugo/trunk/lemon/simann.h

Log:
More mingw compatibility

Implementation of the drand48 functions




Modified: hugo/trunk/lemon/Makefile.am
==============================================================================
--- hugo/trunk/lemon/Makefile.am	(original)
+++ hugo/trunk/lemon/Makefile.am	Mon Apr  3 21:47:37 2006
@@ -9,7 +9,10 @@
 	lp_base.cc \
 	lp_skeleton.cc \
 	base.cc \
-	eps.cc 
+	eps.cc \
+	bits/mingw32_rand.cc \
+	bits/mingw32_time.cc
+
 libemon_la_CXXFLAGS = $(GLPK_CFLAGS) $(CPLEX_CFLAGS)
 libemon_la_LDFLAGS = $(GLPK_LIBS) $(CPLEX_LIBS)
 
@@ -99,6 +102,8 @@
 	bits/item_writer.h \
 	bits/traits.h \
 	bits/utility.h \
+	bits/mingw32_rand.h \
+	bits/mingw32_time.h \
 	concept/bpugraph.h \
 	concept/graph.h \
 	concept/graph_component.h \

Added: hugo/trunk/lemon/bits/mingw32_rand.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/lemon/bits/mingw32_rand.cc	Mon Apr  3 21:47:37 2006
@@ -0,0 +1,83 @@
+#ifdef WIN32
+
+#include <lemon/bits/mingw32_rand.h>
+
+
+static unsigned short _mingw_rand_state[10];
+
+void _mingw_rand_next_state(unsigned short xsubi[3]) {
+  _mingw_rand_state[8] = _mingw_rand_state[9] = 0;
+  _mingw_rand_state[7] =  _mingw_rand_state[6];
+  for (int i = 0; i < 3; ++i) {
+    unsigned long val = 0;
+    for (int j = 0; i + j < 3; ++j) {
+      val += (unsigned long)_mingw_rand_state[7 + i + j]
+        + (unsigned long)xsubi[i] * (unsigned long)_mingw_rand_state[3 + j];
+      _mingw_rand_state[7 + i + j] = val;
+      val >>= 16;
+    }
+  }
+  xsubi[0] = _mingw_rand_state[6];
+  xsubi[1] = _mingw_rand_state[7];
+  xsubi[2] = _mingw_rand_state[8];
+}
+
+long int lrand48(void) {
+  return nrand48(_mingw_rand_state);
+}
+
+long int nrand48(unsigned short xsubi[3]) {
+  _mingw_rand_next_state(xsubi);
+  return ((long)(xsubi[2] & ( (1 << 15) - 1) ) << 16) | (long)xsubi[1];
+}
+
+double drand48(void) {
+  return erand48(_mingw_rand_state);
+}
+
+double erand48(unsigned short xsubi[3]) {
+  return (double)nrand48(xsubi) / (1 << 31);
+}
+
+
+long int mrand48(void) {
+  return jrand48(_mingw_rand_state);
+}
+
+long int jrand48(unsigned short xsubi[3]) {
+  _mingw_rand_next_state(xsubi);
+  return ((long)xsubi[2] << 16) | (long)xsubi[1];
+}
+
+void srand48(long int seedval) {
+  _mingw_rand_state[0] = 0x330E;
+  _mingw_rand_state[1] = seedval & ( (1 << 16) - 1);
+  _mingw_rand_state[2] = seedval >> 16;
+  _mingw_rand_state[3] = 0xE66D;
+  _mingw_rand_state[4] = 0xDEEC;
+  _mingw_rand_state[5] = 0x0005;
+  _mingw_rand_state[6] = 0x000B;
+}
+
+unsigned short *seed48(unsigned short seed16v[3]) {
+  _mingw_rand_state[7] = _mingw_rand_state[0];
+  _mingw_rand_state[8] = _mingw_rand_state[1];
+  _mingw_rand_state[9] = _mingw_rand_state[2];
+  _mingw_rand_state[0] = seed16v[0];
+  _mingw_rand_state[1] = seed16v[1];
+  _mingw_rand_state[2] = seed16v[2];
+  return _mingw_rand_state + 7;
+}
+
+void lcong48(unsigned short param[7]) {
+  _mingw_rand_state[0] = param[0];
+  _mingw_rand_state[1] = param[1];
+  _mingw_rand_state[2] = param[2];
+  _mingw_rand_state[3] = param[3];
+  _mingw_rand_state[4] = param[4];
+  _mingw_rand_state[5] = param[5];
+  _mingw_rand_state[6] = param[6];
+}
+
+
+#endif

Added: hugo/trunk/lemon/bits/mingw32_rand.h
==============================================================================
--- (empty file)
+++ hugo/trunk/lemon/bits/mingw32_rand.h	Mon Apr  3 21:47:37 2006
@@ -0,0 +1,37 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2006
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+#ifndef LEMON_BITS_MINGW32_RAND_H
+#define LEMON_BITS_MINGW32_RAND_H
+
+
+#ifdef WIN32
+
+double drand48(void);
+double erand48(unsigned short xsubi[3]);
+long int lrand48(void);
+long int nrand48(unsigned short xsubi[3]);
+long int mrand48(void);
+long int jrand48(unsigned short xsubi[3]);
+void srand48(long int seedval);
+unsigned short *seed48(unsigned short seed16v[3]);
+void lcong48(unsigned short param[7]);
+
+#endif
+
+#endif

Added: hugo/trunk/lemon/bits/mingw32_time.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/lemon/bits/mingw32_time.cc	Mon Apr  3 21:47:37 2006
@@ -0,0 +1,104 @@
+#ifdef WIN32
+
+#include <lemon/bits/mingw32_time.h>
+
+#include <windows.h>
+#include <ctime>
+#include "dos.h"
+
+static const char days[] = 
+"Sun Mon Tue Wed Thu Fri Sat ";
+static const char months[] = 
+"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ";
+
+void num2str(char *c,int i) {
+  c[0]=i/10+'0';
+  c[1]=i%10+'0';
+}
+
+char *asctime_r(const struct tm *t, char *buf) {
+  *(int*)buf=*(int*)(days+(t->tm_wday<<2));
+  *(int*)(buf+4)=*(int*)(months+(t->tm_mon<<2));
+  num2str(buf+8,t->tm_mday);
+  if (buf[8]=='0') buf[8]=' ';
+  buf[10]=' ';
+  num2str(buf+11,t->tm_hour);
+  buf[13]=':';
+  num2str(buf+14,t->tm_min);
+  buf[16]=':';
+  num2str(buf+17,t->tm_sec);
+  buf[19]=' ';
+  num2str(buf+20,(t->tm_year+1900)/100);
+  num2str(buf+22,(t->tm_year+1900)%100);
+  buf[24]='\n'; buf[25]='\0';
+  return buf;
+}
+
+struct tm * localtime_r (const time_t *t, struct tm *tm) {
+  struct tm *tmp;
+  
+  if ((tmp = localtime(t)) && tm)
+    *tm = *tmp;
+  else
+    return 0;
+  
+  return tm;
+}
+
+char *ctime_r(const time_t * tim_p , char * result) {
+  struct tm tm;
+  return asctime_r (localtime_r (tim_p, &tm), result);
+}
+
+
+int gettimeofday(struct timeval * tp, struct timezone *) {
+  SYSTEMTIME systime;
+
+  if (tp) {
+    struct tm tmrec;
+    time_t theTime = time(NULL);
+    
+    
+    tmrec = *localtime(&theTime);
+    tp->tv_sec = mktime(&tmrec);
+    GetLocalTime(&systime); /* system time */
+
+    tp->tv_usec = systime.wMilliseconds * 1000;
+  }
+  return 0;
+}
+
+long filetime_to_clock(FILETIME *ft)
+{
+  __int64 qw = ft->dwHighDateTime;
+  qw <<= 32;
+  qw |= ft->dwLowDateTime;
+  qw /= 10000;  
+  return (long) qw;
+
+}
+
+int times(struct tms *tmbuf)
+{
+  FILETIME create, exit, kernel, user;
+  if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
+    tmbuf->tms_utime = filetime_to_clock(&user);
+    tmbuf->tms_stime = filetime_to_clock(&kernel);
+    tmbuf->tms_cutime = 0;
+    tmbuf->tms_cstime = 0;
+  }
+  else {
+    tmbuf->tms_utime = clock();
+    tmbuf->tms_stime = 0;
+    tmbuf->tms_cutime = 0;
+    tmbuf->tms_cstime = 0;
+  }
+  return 0;
+}
+
+int sysconf(int)
+{
+  return 1;
+}
+
+#endif

Modified: hugo/trunk/lemon/bits/mingw32_time.h
==============================================================================
--- hugo/trunk/lemon/bits/mingw32_time.h	(original)
+++ hugo/trunk/lemon/bits/mingw32_time.h	Mon Apr  3 21:47:37 2006
@@ -22,72 +22,13 @@
 #ifdef WIN32
 
 #include <windows.h>
-#include <time.h>
+#include <ctime>
 #include "dos.h"
 
-static const char days[] = 
-"Sun Mon Tue Wed Thu Fri Sat ";
-static const char months[] = 
-"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ";
-
-inline void num2str(char *c,int i) {
-  c[0]=i/10+'0';
-  c[1]=i%10+'0';
-}
-
-inline char *asctime_r(const struct tm *t, char *buf) {
-  /* "Wed Jun 30 21:49:08 1993\n" */
-  *(int*)buf=*(int*)(days+(t->tm_wday<<2));
-  *(int*)(buf+4)=*(int*)(months+(t->tm_mon<<2));
-  num2str(buf+8,t->tm_mday);
-  if (buf[8]=='0') buf[8]=' ';
-  buf[10]=' ';
-  num2str(buf+11,t->tm_hour);
-  buf[13]=':';
-  num2str(buf+14,t->tm_min);
-  buf[16]=':';
-  num2str(buf+17,t->tm_sec);
-  buf[19]=' ';
-  num2str(buf+20,(t->tm_year+1900)/100);
-  num2str(buf+22,(t->tm_year+1900)%100);
-  buf[24]='\n'; buf[25]='\0';
-  return buf;
-}
-
-inline struct tm * localtime_r (const time_t *t, struct tm *tm) {
-  struct tm *tmp;
-  
-  if ((tmp = localtime(t)) && tm)
-    *tm = *tmp;
-  else
-    return 0;
-  
-  return tm;
-}
-
-inline char *ctime_r(const time_t * tim_p , char * result) {
-  struct tm tm;
-  return asctime_r (localtime_r (tim_p, &tm), result);
-}
-
-
-inline int gettimeofday(struct timeval * tp, struct timezone *) {
-  SYSTEMTIME systime;
-
-  if (tp) {
-    struct tm tmrec;
-    time_t theTime = time(NULL);
-    
-    
-    tmrec = *localtime(&theTime);
-    tp->tv_sec = mktime(&tmrec);
-    GetLocalTime(&systime); /* system time */
-
-    tp->tv_usec = systime.wMilliseconds * 1000;
-  }
-  return 0;
-}
-
+char *asctime_r(const struct tm *t, char *buf);
+struct tm * localtime_r (const time_t *t, struct tm *tm);
+char *ctime_r(const time_t * tim_p , char * result);
+int gettimeofday(struct timeval * tp, struct timezone *);
 
 struct tms {
   long	tms_utime;
@@ -96,42 +37,14 @@
   long	tms_cstime;
 };
 
-inline long filetime_to_clock(FILETIME *ft)
-{
-  __int64 qw = ft->dwHighDateTime;
-  qw <<= 32;
-  qw |= ft->dwLowDateTime;
-  qw /= 10000;  /* File time ticks at 0.1uS, clock at 1mS */
-  return (long) qw;
-
-}
-
-inline int times(struct tms *tmbuf)
-{
-  FILETIME create, exit, kernel, user;
-  if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
-    tmbuf->tms_utime = filetime_to_clock(&user);
-    tmbuf->tms_stime = filetime_to_clock(&kernel);
-    tmbuf->tms_cutime = 0;
-    tmbuf->tms_cstime = 0;
-  }
-  else {
-    tmbuf->tms_utime = clock();
-    tmbuf->tms_stime = 0;
-    tmbuf->tms_cutime = 0;
-    tmbuf->tms_cstime = 0;
-  }
-  return 0;
-}
+long filetime_to_clock(FILETIME *ft);
+
+int times(struct tms *tmbuf);
 
 #define _SC_CLK_TCK 1
 
-inline int sysconf(int)
-{
-  return 1;
-}
+int sysconf(int);
 
 #endif
 
-
 #endif

Modified: hugo/trunk/lemon/simann.h
==============================================================================
--- hugo/trunk/lemon/simann.h	(original)
+++ hugo/trunk/lemon/simann.h	Mon Apr  3 21:47:37 2006
@@ -32,6 +32,10 @@
 #include <limits>
 #include <lemon/time_measure.h>
 
+#ifdef WIN32
+#include <lemon/bits/mingw32_rand.h>
+#endif
+
 namespace lemon {
 
 /// \addtogroup experimental



More information about the Lemon-commits mailing list