BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/QP_functions.h
Go to the documentation of this file.
00001 // Copyright (c) 1997-2007  ETH Zurich (Switzerland).
00002 // All rights reserved.
00003 //
00004 // This file is part of CGAL (www.cgal.org); you may redistribute it under
00005 // the terms of the Q Public License version 1.0.
00006 // See the file LICENSE.QPL distributed with CGAL.
00007 //
00008 // Licensees holding a valid commercial license may use this file in
00009 // accordance with the commercial license agreement provided with the software.
00010 //
00011 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 //
00014 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/QP_solver/include/CGAL/QP_functions.h $
00015 // $Id: QP_functions.h 38453 2007-04-27 00:34:44Z gaertner $
00016 // 
00017 //
00018 // Author(s)     : Bernd Gaertner <gaertner@inf.ethz.ch>
00019 
00020 #ifndef CGAL_QP_FUNCTIONS_H
00021 #define CGAL_QP_FUNCTIONS_H
00022 
00023 #include <iostream>
00024 #include <string>
00025 #include <CGAL/QP_options.h>
00026 #include <CGAL/QP_solution.h>
00027 
00028 CGAL_BEGIN_NAMESPACE
00029 
00030 namespace QP_functions_detail { 
00031   // internal routine; writes P to out in MPS format
00032   // Is_linear == Tag_true / Tag_false:
00033   //    p is treated as LinearProgram / QuadraticProgram
00034   // Is_nonnegative == Tag_true / Tag_false
00035   //    p is treated as Nonnegative / Arbitrary  
00036   // the dmatrix parameter specificies whether the quadratic matrix (if any)
00037   // is written in DMATRIX format (no multiplication by two, good for
00038   // cross-checking output, or in QMATRIX format (good for using other
00039   // solvers like CPLEX)
00040   template <typename P, typename Is_linear, typename Is_nonnegative>
00041   void print_program
00042   (std::ostream& out, 
00043    const P &p,
00044    const std::string& problem_name,
00045    Is_linear is_linear, 
00046    Is_nonnegative is_nonnegative); 
00047 
00048   // internal routine: solves a program, depending on the tags
00049   template <typename Program, typename ET, 
00050             typename Is_linear,typename Is_nonnegative >
00051   Quadratic_program_solution<ET> solve_program 
00052   (const Program &p, const ET&, 
00053    Is_linear is_linear, 
00054    Is_nonnegative is_nonnegative,
00055    const Quadratic_program_options& options = Quadratic_program_options()); 
00056 
00057   // internal routines: prints name of solution function
00058   void print_solution_function 
00059   (std::ostream& out, 
00060    Tag_true /*is_linear*/, Tag_true /*is_nonnegative*/)
00061   {
00062     out << "solve_nonnegative_linear_program"; 
00063   }
00064   void print_solution_function 
00065   (std::ostream& out, 
00066    Tag_false /*is_linear*/, Tag_true /*is_nonnegative*/)
00067   {
00068     out << "solve_nonnegative_quadratic_program"; 
00069   }
00070   void print_solution_function 
00071   (std::ostream& out, 
00072    Tag_true /*is_linear*/, Tag_false /*is_nonnegative*/)
00073   {
00074     out << "solve_linear_program"; 
00075   }
00076   void print_solution_function 
00077   (std::ostream& out, 
00078    Tag_false /*is_linear*/, Tag_false /*is_nonnegative*/)
00079   {
00080     out << "solve_quadratic_program"; 
00081   }
00082                                 
00083   // internal routine:
00084   // test whether the system is of the form A x == b (equations only)
00085   template <typename R>
00086   bool is_in_equational_form (const R& r);
00087 
00088   // internal routine:
00089   // test whether the row vectors of A that correpsond to equations 
00090   // are linearly independent; this is done using type ET. The value
00091   // type of LinearInequalitySystem must be convertible to ET
00092   template <class Ar, class ET>
00093   bool has_linearly_independent_equations 
00094   (const Ar& ar, const ET& dummy);
00095 }
00096 
00097 template <typename QuadraticProgram>
00098 void print_quadratic_program 
00099 (std::ostream& out, const QuadraticProgram &qp, 
00100  const std::string& problem_name = std::string("MY_MPS"))
00101 // writes qp to out in MPS format
00102 {
00103   QP_functions_detail::print_program 
00104     (out, qp, problem_name, CGAL::Tag_false(), CGAL::Tag_false());
00105 }
00106 
00107 template <typename LinearProgram>
00108 void print_linear_program 
00109 (std::ostream& out, const LinearProgram &lp, 
00110  const std::string& problem_name = std::string("MY_MPS"))
00111 // writes lp to out in MPS format
00112 {
00113   QP_functions_detail::print_program 
00114     (out, lp, problem_name, CGAL::Tag_true(), CGAL::Tag_false());
00115 }
00116 
00117 template <typename NonnegativeQuadraticProgram>
00118 void print_nonnegative_quadratic_program 
00119 (std::ostream& out, const NonnegativeQuadraticProgram &qp,
00120  const std::string& problem_name = std::string("MY_MPS"))
00121 // writes qp to out in MPS format
00122 {
00123   QP_functions_detail::print_program 
00124     (out, qp, problem_name, CGAL::Tag_false(), CGAL::Tag_true());
00125 }
00126 
00127 template <typename NonnegativeLinearProgram>
00128 void print_nonnegative_linear_program 
00129 (std::ostream& out, const NonnegativeLinearProgram &lp,
00130  const std::string& problem_name = std::string("MY_MPS"))
00131 // writes lp to out in MPS format
00132 {
00133   QP_functions_detail::print_program 
00134     (out, lp, problem_name, CGAL::Tag_true(), CGAL::Tag_true());
00135 }
00136 
00137 template <typename QuadraticProgram, typename ET>
00138 Quadratic_program_solution<ET> solve_quadratic_program 
00139 (const QuadraticProgram &qp, const ET&,
00140 const Quadratic_program_options& options = Quadratic_program_options());
00141 
00142 template <typename NonnegativeQuadraticProgram, typename ET>
00143 Quadratic_program_solution<ET> solve_nonnegative_quadratic_program 
00144 (const NonnegativeQuadraticProgram &qp, const ET&,
00145 const Quadratic_program_options& options = Quadratic_program_options());
00146 
00147 template <typename LinearProgram, typename ET>
00148 Quadratic_program_solution<ET> solve_linear_program 
00149 (const LinearProgram &lp, const ET&, 
00150 const Quadratic_program_options& options = Quadratic_program_options());
00151 
00152 template <typename NonnegativeLinearProgram, typename ET>
00153 Quadratic_program_solution<ET> solve_nonnegative_linear_program 
00154 (const NonnegativeLinearProgram &lp, const ET&,
00155 const Quadratic_program_options& options = Quadratic_program_options());
00156 
00157 CGAL_END_NAMESPACE
00158 
00159 #include <CGAL/QP_solver/QP_functions_impl.h>
00160 
00161 #endif // CGAL_QP_FUNCTIONS_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines