Ejemplo n.º 1
0
int
sl_seed()
{
    HCRYPTPROV hCryptProv;
    int seed;

    if(CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
        CryptGenRandom(hCryptProv, sizeof(int), (void*)&seed);
        CryptReleaseContext(hCryptProv, 0);
    } else {
        long tv_sec, tv_usec;
        get_timeval(&tv_sec, &tv_usec);
        seed = (int)(tv_usec ^ tv_sec);
    }

    return seed;
}
Ejemplo n.º 2
0
static lpret_enum do_lp (struct timeval *elapsed, int printlvl)

/*
  This routine is a wrapper which makes up the difference between the setup
  completed in the main program and the setup expected by dylp.  Structures
  are created for the lp problem, options, tolerances, and statistics, and
  passed to dylp. Once the lp completes, the stats are printed and the
  statistics structure is released. Other cleanup is handled in main.

  Returns: lp status code; lpINV is used in the event of a fatal error that's
	   not really dylp's fault.
*/

{ int ndx,i,flips ;
  bool *flipped ;

  lpret_enum lpret ;
  lpopts_struct *initial_lpopts ;
  lpstats_struct *initial_lpstats ;
  basis_struct *basis ;

  struct timeval diff,before,after ;

  const char *rtnnme = "do_lp" ;

  lpret = lpINV ;

/*
  Create and initialise the main_lp structure to pass the problem in to dylp.
*/
  main_lp = (lpprob_struct *) CALLOC(1,sizeof(lpprob_struct)) ;
  main_lp->phase = dyINV ;
  main_lp->consys = main_sys ;
  main_lp->rowsze = main_sys->rowsze ;
  main_lp->colsze = main_sys->colsze ;
/*
  Set up options, statistics, and solve the lp. After we're done, dump the
  statistics and free the dylp statistics structure. The options specified in
  the main routine (cold start using a logical basis and the full constraint
  system) are appropriate for the initial solution of an LP.

  In particular, if you're modifying this driver to do more than just solve
  the LP (for example, if you want access to tableau information after dylp
  returns with an answer) you really want to set the lpctlNOFREE flag in
  main_lp->ctlopts. See the comments in dylp.h for the available flags.
*/
  initial_lpopts = (lpopts_struct *) MALLOC(sizeof(lpopts_struct)) ;
  memcpy(initial_lpopts,main_lpopts,sizeof(lpopts_struct)) ;

  dy_setprintopts(printlvl,initial_lpopts) ;

# ifdef DYLP_STATISTICS
  initial_lpstats = NULL ;
  dy_initstats(&initial_lpstats,main_sys) ;
# else
  initial_lpstats = NULL ;
# endif

  get_timeval(&before) ;
  lpret = dylp(main_lp,initial_lpopts,main_lptols,initial_lpstats) ;
  get_timeval(&after) ;
  sub_timevals(&diff,&after,&before) ;
  if (elapsed != NULL) (*elapsed) = diff ;

  stats_lp(outpath,FALSE,main_lp,&diff,initial_lpstats) ;
# ifdef DYLP_STATISTICS
  dy_freestats(&initial_lpstats) ;
# endif

  if (initial_lpopts != NULL) FREE(initial_lpopts) ;

  return (lpret) ;
}