- examples cleaned up; now all examples are referred to from the ref_manual

This commit is contained in:
Bernd Gärtner 2007-04-14 15:48:12 +00:00
parent ce80f2f8db
commit d987c81bd6
12 changed files with 19 additions and 261 deletions

View File

@ -68,7 +68,8 @@ The following example for the simpler model
should give you a flavor of the use of this
model in practice.
\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp.h}
\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp.h}\\
\ccReferToExampleCode{QP_solver/convex_hull_containment.cpp}
\ccSeeAlso
\ccc{LinearProgramInterface}

View File

@ -56,7 +56,8 @@ linear program is described in \ccc{NonnegativeLinearProgramInterface}.}
\ccExample
\ccReferToExampleCode{QP_solver/first_nonnegative_lp_from_iterators.cpp}\\
\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp.h}
\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp.h}\\
\ccReferToExampleCode{QP_solver/convex_hull_containment.cpp}
\ccSeeAlso
\ccc{NonnegativeLinearProgramInterface}

View File

@ -63,7 +63,9 @@ The following example for the simpler model
should give you a flavor of the use of this
model in practice.
\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp.h}
\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp.h}\\
\ccReferToExampleCode{QP_solver/convex_hull_containment.cpp}
\ccSeeAlso
\ccc{NonnegativeQuadraticProgramInterface}
\ccc{Quadratic_program<NT>}\\

View File

@ -71,8 +71,8 @@ The following example for the simpler model
should give you a flavor of the use of this
model in practice.
\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp.h}
\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp.h}\\
\ccReferToExampleCode{QP_solver/convex_hull_containment.cpp}
\ccSeeAlso
\ccc{QuadraticProgramInterface}
\ccc{Quadratic_program<NT>}\\

View File

@ -35,7 +35,8 @@ make_linear_program_from_iterators (
The following example demonstrates the typical usage of makers
with the simpler function \ccc{make_nonnegative_linear_program_from_iterators}.
\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp2.h}
\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp2.h}\\
\ccReferToExampleCode{QP_solver/convex_hull_containment2.cpp}
\ccSeeAlso
\ccc{Linear_program_from_iterators<A_it, B_it, R_it, FL_it, L_it, FU_it, U_it, C_it>}

View File

@ -26,7 +26,8 @@ make_nonnegative_linear_program_from_iterators (
{returns an instance of \ccc{Nonnegative_linear_program_from_iterators<A_it, B_it, R_it, C_it>}, constructed from the given iterators.}
\ccExample
\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp2.h}
\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp2.h}\\
\ccReferToExampleCode{QP_solver/convex_hull_containment2.cpp}
\ccSeeAlso
\ccc{Nonnegative_linear_program_from_iterators<A_it, B_it, R_it, C_it>}

View File

@ -30,7 +30,9 @@ make_nonnegative_quadratic_program_from_iterators (
The following example demonstrates the typical usage of makers
with the simpler function \ccc{make_nonnegative_linear_program_from_iterators}.
\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp2.h}
\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp2.h}\\
\ccReferToExampleCode{QP_solver/convex_hull_containment2.cpp}
\ccSeeAlso
\ccc{Nonnegative_quadratic_program_from_iterators<A_it, B_it, R_it, D_it, C_it>}
\end{ccRefFunction}

View File

@ -37,8 +37,8 @@ make_quadratic_program_from_iterators (
The following example demonstrates the typical usage of makers
with the simpler function \ccc{make_nonnegative_linear_program_from_iterators}.
\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp2.h}
\ccReferToExampleCode{QP_solver/solve_convex_hull_containment_lp2.h}\\
\ccReferToExampleCode{QP_solver/convex_hull_containment2.cpp}
\ccSeeAlso
\ccc{Quadratic_program_from_iterators<A_it, B_it, R_it, FL_it, L_it, FU_it, U_it, D_it, C_it>}

View File

@ -14,7 +14,7 @@ bool is_in_convex_hull (const Point_d& p,
{
CGAL::Quadratic_program_solution<CGAL::MP_Float> s =
solve_convex_hull_containment_lp (p, begin, end, CGAL::MP_Float());
return s.status() != CGAL::QP_INFEASIBLE;
return !s.is_infeasible();
}
int main()

View File

@ -1,109 +0,0 @@
// Copyright (c) 1997-2001 ETH Zurich (Switzerland).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
//
// Author(s) : Kaspar Fischer <fischerk@inf.ethz.ch>
// Bernd Gaertner <gaertner@inf.ethz.ch>
#include <CGAL/basic.h>
#include <iostream>
#include <sstream>
#include <cstdlib>
#ifndef CGAL_USE_GMP
#include <CGAL/MP_Float.h>
#else
#include <CGAL/Gmpzf.h>
#endif
#include <CGAL/QP_solver.h>
#include <CGAL/QP_solver/QP_full_exact_pricing.h>
#include <CGAL/QP_solver/QP_partial_exact_pricing.h>
#include <CGAL/QP_solver/QP_full_filtered_pricing.h>
#include <CGAL/QP_solver/QP_partial_filtered_pricing.h>
#include <CGAL/QP_models.h>
#include <CGAL/QP_functions.h>
int main(const int argNr,const char **args) {
using std::cout;
using std::endl;
// get desired level of additional logging output:
//const int verbosity = argNr < 2? 1 : std::atoi(args[1]);
// construct QP instance:
typedef double IT;
#ifndef CGAL_USE_GMP
typedef CGAL::MP_Float ET;
#else
typedef CGAL::Gmpzf ET;
#endif
typedef CGAL::Quadratic_program_from_mps<IT> QP;
QP qp(std::cin);
// check for format errors in MPS f\ile:
if (!qp.is_valid()) {
cout << "Input is not a valid MPS file." << endl
<< "Error: " << qp.get_error() << endl;
std::exit(2);
}
typedef CGAL::Quadratic_program_solution<ET> Solution;
Solution s = CGAL::solve_quadratic_program (qp, ET(0));
// get solution:
if (s.is_optimal()) {
// output solution:
cout << "Objective function value: " <<
CGAL::to_double(s.objective_value()) << endl;
cout << "Variable values:" << endl;
Solution::Variable_value_iterator vit =
s.variable_values_begin() ;
for (int i=0; i < qp.get_n(); ++vit, ++i)
cout << " " << qp.get_name_of_variable(i) << " = "
<< CGAL::to_double(*vit) << endl;
cout << "Basic variables (index, value):" << endl;
Solution::Index_iterator iit =
s.basic_variable_indices_begin();
vit = s.variable_values_begin();
for ( ; iit < s.basic_variable_indices_end(); ++iit)
cout << " (" << *iit << ", "
<< CGAL::to_double(vit[*iit]) << ")" << endl;
cout << " There are " << s.number_of_basic_variables()
<< " basic variables. " << endl;
cout << "Basic constraints: " << endl;
Solution::Index_iterator cit =
s.basic_constraint_indices_begin();
for ( ; cit < s.basic_constraint_indices_end(); ++cit)
cout << *cit << " ";
cout << endl;
cout << " There are " << s.number_of_basic_constraints()
<< " basic constraints. " << endl;
return 0;
}
if (s.status() == CGAL::QP_INFEASIBLE)
cout << "Problem is infeasible." << endl;
else // unbounded
cout << "Problem is unbounded." << endl;
return 0;
}

View File

@ -1,71 +0,0 @@
// This example program solves the quadratic program
// minimize x^T D x + c^T x + c0
// subject to A x <rel> b
// L <= x <= u
// where <rel> stands for a vector of relations from {<=, ==, >=}
//
// In the concrete example below, we have the following data:
// D c A b L U c0
// ---------------------------------------------------------------------
// 1 0 0 3 1 2 1 0 0 infinity 1 1
// 0 0
//
// In other words, we minimize x^2 + 3y + 1 subject to x + 2y = 1
// and x >= 0, 0 <= y <= 1. Let's see what this gives: if we
// substitute x with 1 - 2y in the objective function, we get
// 4y^2 - y + 1. The derivative is 8y-1, so this is minimzed
// for y = 1/8. This value (as well as x = 1 - 2(1/8) = 3/4)
// are within the bounds, so the solution should be x = 3/4
// and y = 1/8. The objective function value should be
// 9/16 + 3/8 + 1 = 31/16
#include <CGAL/basic.h>
#include <CGAL/QP_models.h>
#include <CGAL/QP_functions.h>
#ifndef CGAL_USE_GMP
#include <CGAL/MP_Float.h>
typedef CGAL::MP_Float ET;
#else
#include <CGAL/Gmpz.h>
typedef CGAL::Gmpz ET;
#endif
// program and solution types
typedef CGAL::Quadratic_program_from_pointers<int> Program;
typedef CGAL::Quadratic_program_solution<ET> Solution;
int main() {
int A_col_0[] = {1};
int A_col_1[] = {2};
int *cols_of_A[] = {A_col_0, A_col_1};
int b[] = {1};
CGAL::Comparison_result rt[] = {CGAL::EQUAL};
bool fl[] = {true, true};
int l[] = {0, 0};
bool fu[] = {false, true}; // x has upper bound infinity...
int u[] = {0, 1}; // ... and it's u-entry is ignored
int D_row_0[] = {2, 0};
int D_row_1[] = {0, 0};
int *rows_of_D[] = {D_row_0, D_row_1};
int c[] = {0, 3};
int c0 = 1;
// now construct the quadratic program; the first two parameters are
// the number of variables and the number of constraints (rows of A)
Program qp (2, 1, cols_of_A, b, rt, fl, l, fu, u, rows_of_D, c, c0);
// solve the program
Solution s = CGAL::solve_quadratic_program(qp, ET());
// output solution
if (s.status() == CGAL::QP_OPTIMAL) { // we know that, don't we?
std::cout << "Optimal feasible solution: ";
for (Solution::Variable_value_iterator it = s.variable_values_begin();
it != s.variable_values_end(); ++it)
std::cout << *it << " ";
std::cout << "\nOptimal value: " << s.objective_value() << std::endl;
}
return 0;
}

View File

@ -1,70 +0,0 @@
// This example program solves the quadratic program
// minimize x^T D x + c^T x + c0
// subject to A x <rel> b
// L <= x <= u
// where <rel> stands for a vector of relations from {<=, ==, >=}
//
// In the concrete example below, we have the following data:
// D c A b L U c0
// -----------------------------------------------------------------------
// 1.0 0.0 0.0 3.0 0.5 1.0 0.5 0.0 0.0 inf, inf 1
// 0.0 0.0
//
// In other words, we minimize x^2 + 3y subject to x/2 + y >= 1/2
// and x,y >= 0. Let's see what this gives: it is clear that in an
// optimal solution, the constraint is satisfied with equality,
// otherwise, we could decrease the objective function value. Let's
// substitute x with 1 - 2y in the objective function; we get
// 4y^2 - y + 1. The derivative is 8y-1, so this is minimzed
// for y = 1/8. This value (as well as x = 1 - 2(1/8) = 3/4)
// are within the bounds, so the solution should be x = 3/4
// and y = 1/8. The objective function value should be
// 9/16 + 3/8 + 1 = 31/16
#include <CGAL/basic.h>
#include <CGAL/QP_models.h>
#include <CGAL/QP_functions.h>
#ifndef CGAL_USE_GMP
#include <CGAL/MP_Float.h>
typedef CGAL::MP_Float ET;
#else
#include <CGAL/Gmpzf.h>
typedef CGAL::Gmpzf ET;
#endif
// program and solution types
typedef CGAL::Nonnegative_quadratic_program_from_pointers<double> Program;
typedef CGAL::Quadratic_program_solution<ET> Solution;
int main() {
// program data
double A_col_0[] = {0.5};
double A_col_1[] = {1.0};
double *cols_of_A[] = {A_col_0, A_col_1};
double b[] = {0.5};
CGAL::Comparison_result rt[] = {CGAL::LARGER};
double D_row_0[] = {2.0, 0.0};
double D_row_1[] = {0.0, 0.0};
double *rows_of_D[] = {D_row_0, D_row_1};
double c[] = {0.0, 3.0};
double c0 = 1.0;
// now construct the quadratic program; the first two parameters are
// the number of variables and the number of constraints (rows of A)
Program qp (2, 1, cols_of_A, b, rt, rows_of_D, c, c0);
// solve the program
Solution s = CGAL::solve_nonnegative_quadratic_program(qp, ET());
// output solution
if (s.status() == CGAL::QP_OPTIMAL) { // we know that, don't we?
std::cout << "Optimal feasible solution: ";
for (Solution::Variable_value_iterator it = s.variable_values_begin();
it != s.variable_values_end(); ++it)
std::cout << CGAL::to_double(*it) << " ";
std::cout << "\nOptimal value: " << CGAL::to_double(s.objective_value())
<< std::endl;
}
return 0;
}