/* Copyright (c) 1997-2004
Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
http://www.math.tu-berlin.de/polymake, mailto:polymake@math.tu-berlin.de
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version: http://www.gnu.org/licenses/gpl.txt.
This program 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 General Public License for more details.
*/
#ifndef _POLYMAKE_LP_CLIENT_H
#define _POLYMAKE_LP_CLIENT_H "$Project: polymake $$Id: lp_client.h 4714 2004-06-22 16:23:15Z gawrilow $"
#include <Poly.h>
#include <Matrix.h>
#include <Vector.h>
#include <linalg_exceptions.h>
namespace polymake { namespace polytope {
template <typename Solver>
void valid_point(Poly& p, Solver& solver)
{
typedef typename Solver::coord_type coord_type;
const Matrix<coord_type> H=p.give("FACETS | INEQUALITIES"),
E=p.lookup("AFFINE_HULL | EQUATIONS");
const typename Solver::feasibility_solution F=solver.check_feasibility(H,E);
p.take("FEASIBLE") << F.first;
if (F.first)
p.take("VALID_POINT") << F.second;
else
p.take("VALID_POINT") << Poly::undefined();
}
template <typename Solver>
void solve_lp(Poly& p, Solver& solver, bool maximize)
{
typedef typename Solver::coord_type coord_type;
const Matrix<coord_type> H=p.give("FACETS | INEQUALITIES"),
E=p.lookup("AFFINE_HULL | EQUATIONS");
const Vector<coord_type> Obj=p.give("LINEAR_OBJECTIVE");
try {
typename Solver::lp_solution S=solver.solve_lp(H, E, Obj, maximize);
p.take(maximize ? "MAXIMAL_VALUE" : "MINIMAL_VALUE") << S.first;
p.take(maximize ? "MAXIMAL_VERTEX" : "MINIMAL_VERTEX") << S.second;
p.take("FEASIBLE") << true;
}
catch (const linalg_error& error) {
p.take(maximize ? "MAXIMAL_VALUE" : "MINIMAL_VALUE") << Poly::undefined();
p.take(maximize ? "MAXIMAL_VERTEX" : "MINIMAL_VERTEX") << Poly::undefined();
p.take("FEASIBLE") << bool(dynamic_cast<const unbounded*>(&error));
}
}
} }
#endif // _POLYMAKE_LP_CLIENT_H
// Local Variables:
// mode:C++
// c-basic-offset:3
// End:
syntax highlighted by Code2HTML, v. 0.9.1