//==================================================================================================
// L i n e a r _ s y s t e m                                                              Interface
// D e f a u l t _s o l v e r
//                                                                                By Bruno Bachelet
//==================================================================================================
// Copyright (c) 1999-2016
// Bruno Bachelet - bruno@nawouak.net - http://www.nawouak.net
//
// This file is part of the B++ Library. This library is free software; you can redistribute it
// and/or modify it under the terms of the GNU Library General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your option) any later
// version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
// the GNU Library General Public License for more details (http://www.gnu.org).

/*DESCRIPTION*/
/* This module provides an implementation for the <CODE>defaultSolver</CODE> method of the
   <CODE>Solver</CODE> class that returns the default valid solver to use to solve linear
   programs. */

// File Name //-------------------------------------------------------------------------------------
#line __LINE__ "default_solver.hpp"

// Guardian //--------------------------------------------------------------------------------------
#ifndef guLinearSystemDefaultSolver
#define guLinearSystemDefaultSolver

// Headers //---------------------------------------------------------------------------------------
#include <bpp/linear_system/ampl.hpp> /*INCLUDE*/
#include <bpp/linear_system/cplex.hpp> /*INCLUDE*/
#include <bpp/linear_system/cplex_library.hpp> /*INCLUDE*/
#include <bpp/linear_system/glpk.hpp> /*INCLUDE*/

namespace bpp {

// Importation/Exportation //-----------------------------------------------------------------------
#ifdef LINEAR_SYSTEM_DLL
 #define dll_export DLL_EXPORT
#else
 #define dll_export DLL_IMPORT
#endif

// Namespaces //------------------------------------------------------------------------------------
#define public_area  linearSystemDefaultSolver
#define private_area linearSystemDefaultSolver_private

namespace public_area {
 /*NAMESPACE*/ using namespace linearSystemAmpl;
 /*NAMESPACE*/ using namespace linearSystemCplex;
 /*NAMESPACE*/ using namespace linearSystemCplexLibrary;
 /*NAMESPACE*/ using namespace linearSystemGlpk;
}

namespace private_area { using namespace public_area; }

extern_module_name;

// Initialization //--------------------------------------------------------------------------------

// Macrocommands //---------------------------------------------------------------------------------

// Types & Classes //-------------------------------------------------------------------------------
namespace public_area  {}
namespace private_area {}

// Functions Interface //---------------------------------------------------------------------------
namespace public_area  {}
namespace private_area {}

// Errors //----------------------------------------------------------------------------------------
namespace public_area {}

// Constants & Variables //-------------------------------------------------------------------------
namespace public_area  {}
namespace private_area {}

// X X X  Interface //------------------------------------------------------------------------------
namespace {}

// Functions Inline //------------------------------------------------------------------------------
namespace public_area  {}
namespace private_area {}

// X X X  Inline //---------------------------------------------------------------------------------
namespace {}

// S o l v e r  Implementation //-------------------------------------------------------------------
namespace linearSystemSolver {
 //---------------------------------------------------------------------------------------Attributes
 template <class prContent> clSolver<prContent> * clSolver<prContent>::atDefaultSolver;
 template <class prContent> clInitializerMutex    clSolver<prContent>::atMutex;
 //------------------------------------------------------------------------------------DefaultSolver
 /*METHOD clSolver */ /* Returns the default solver of linear programs. Static method. */
 template <class prContent> clSolver<prContent> & clSolver<prContent>::defaultSolver(void) {
  ampl_yes (
   typedef linearSystemAmpl::clAmplSolver<prContent> cpAmplSolver;
  )

  cplex_yes (
   typedef linearSystemCplex::clCplexSolver<prContent> cpCplexSolver;
  )

  cplex_library_yes (
   typedef linearSystemCplexLibrary::clCplexLibrarySolver<prContent> cpCplexLibrarySolver;
  )

  typedef linearSystemGlpk::clGlpkSolver<prContent> cpGlpkSolver;

  if (atMutex.tryLock()) {
   atDefaultSolver=nil;
   cplex_library_yes ( atDefaultSolver=new cpCplexLibrarySolver(); )

   cplex_yes (
    if (atDefaultSolver==nil and exchangeCplex::valid()) atDefaultSolver=new cpCplexSolver();
   )

   ampl_yes (
    if (atDefaultSolver==nil and exchangeAmpl::valid()) atDefaultSolver=new cpAmplSolver();
   )

   if (atDefaultSolver==nil) atDefaultSolver=new cpGlpkSolver();
   atMutex.release();
  }

  return (*atDefaultSolver);
 }
}

// End //-------------------------------------------------------------------------------------------
}
#undef dll_export
#undef public_area
#undef private_area
#endif
 
//==================================================================================================
// L i n e a r _ s y s t e m                                                         Implementation
// D e f a u l t _ s o l v e r
//                                                                                By Bruno Bachelet
//==================================================================================================
// Copyright (c) 1999-2016
// Bruno Bachelet - bruno@nawouak.net - http://www.nawouak.net
//
// This file is part of the B++ Library. This library is free software; you can redistribute it
// and/or modify it under the terms of the GNU Library General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your option) any later
// version.
//
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
// the GNU Library General Public License for more details (http://www.gnu.org).

// File Name //-------------------------------------------------------------------------------------
#line __LINE__ "linear_system/default_solver.cpp"

// DLL Belonging //---------------------------------------------------------------------------------
#define LINEAR_SYSTEM_DLL

// Headers //---------------------------------------------------------------------------------------
#include <bpp/linear_system/default_solver.hpp> /*INTERFACE*/

namespace bpp {

// Namespaces //------------------------------------------------------------------------------------
#define public_area  linearSystemDefaultSolver
#define private_area linearSystemDefaultSolver_private
#define dll_export   DLL_EXPORT

namespace public_area  {}
namespace private_area {}

static_module_name("Linear_system/Default_solver");

// Initialization //--------------------------------------------------------------------------------

// Errors //----------------------------------------------------------------------------------------
namespace public_area {}

// Constants & Variables //-------------------------------------------------------------------------
namespace public_area  {}
namespace private_area {}

// Static Members //--------------------------------------------------------------------------------
namespace public_area  {}
namespace private_area {}

// Functions Implementation //----------------------------------------------------------------------
namespace public_area  {}
namespace private_area {}

// X X X  Implementation //-------------------------------------------------------------------------
namespace {}

// End //-------------------------------------------------------------------------------------------
}