#  Copyright (c) 1997-2010
#  Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Darmstadt, Germany)
#  http://www.polymake.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.
#-------------------------------------------------------------------------------
#  $Project: polymake $$Id: lp_float.rules 9535 2010-03-05 17:13:17Z benmuell $

object Polytope<Float> {

# @topic credits/cddlib

rule cdd.simplex: LP.MAXIMAL_VALUE, LP.MAXIMAL_VERTEX, FEASIBLE : LP.LINEAR_OBJECTIVE, FACETS | INEQUALITIES {
   cdd_solve_lp($this, $this->LP, 1);
}
weight 3.10;

rule cdd.simplex: LP.MINIMAL_VALUE, LP.MINIMAL_VERTEX, FEASIBLE : LP.LINEAR_OBJECTIVE, FACETS | INEQUALITIES {
   cdd_solve_lp($this, $this->LP, 0);
}
weight 3.10;

}


# @category Utilities
# Read a linear programming problem given in LP-Format (as used by cplex & Co.)
# and convert it to a [[Polytope<Float>]] object
# @param String file filename of a linear programming problem in LP-Format
# @return Polytope<Float>

user_function lp2poly($) {
   require LPparser;
   my $parser=new LPparser(shift);
   my $P=new Polytope<Float>;
   $P->description="Linear problem converted from file ".$parser->LPfile."\n";
   if ($parser->LPfile =~ /\.lp/i) {
      $P->name=$`;
   }
   $P->INEQUALITIES=new SparseMatrix<Float>($parser->Ineq);
   $P->EQUATIONS=new SparseMatrix<Float>($parser->Eq);

   my $lp=new LinearProgram<Float>;
   $lp->description="Objective sense was ".($parser->objsense eq "+" ? "MAXIMIZE" : "MINIMIZE")."\n";
   $lp->LINEAR_OBJECTIVE=new SparseVector<Float>($parser->Obj);
   $lp->attach("VARIABLE_NAMES", new Array<String>($parser->X));
   if (@{$parser->Int}) {
      $lp->attach("INTEGER_VARIABLES", new Array<Bool>($parser->Int));
   }
   $P->add("LP",$lp);
   $P->commit;
   $P;
}


# Local Variables:
# mode: perl
# c-basic-offset:3
# End:
