/* -*- C++ -*-
 * src/lemon/lp_cplex.h - Part of LEMON, a generic C++ optimization library
 *
 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
 * (Egervary Combinatorial Optimization Research Group, EGRES).
 *
 * Permission to use, modify and distribute this software is granted
 * provided that this copyright notice appears in all copies. For
 * precise terms see the accompanying LICENSE file.
 *
 * This software is provided "AS IS" with no warranty of any kind,
 * express or implied, and with no claim as to its suitability for any
 * purpose.
 *
 */

#ifndef LEMON_LP_CPLEX_H
#define LEMON_LP_CPLEX_H

///\file
///\brief Header of the LEMON-CPLEX lp solver interface.

#include "lp_base.h"
extern "C" {
#include "ilcplex/cplex.h"
}

namespace lemon {


  /// \brief Wrapper for GLPK solver
  /// 
  /// This class implements a lemon wrapper for GLPK.
  class LpCplex : public LpSolverBase {

  public:

    typedef LpSolverBase Parent;
    
    /// \e
    int status;
    CPXENVptr env;
    CPXLPptr lp;


    /// \e
    LpCplex() : Parent() {
      env = NULL;
      lp = NULL;
      env = CPXopenCPLEXdevelop(&status);     
//     if (Env == NULL)
//     {
//          fprintf(stderr,"A CPLEX környezet megnyitása sikertelen.\n");
// 	 CPXgeterrorstring(Env, Status, ErrorMsg);
// 	 fprintf(stderr,"%s",ErrorMsg);
// 	 goto Terminate;
//     }

    // *** A problema létrehozása ***
    lp = CPXcreateprob(env, &status, "LP problem");
 
//    if (Problem == NULL)
//     {
// 	fprintf(stderr,"Az LP létrehozása sikertelen");
// 	goto Terminate;
//     }
 
    }
    /// \e
    ~LpCplex() {
      status = CPXfreeprob(env,&lp); 
//       if (Status != 0)
// 	{
// 	  fprintf(stderr,"A CPLEX feladat törlése sikertelen.\n");
// 	  CPXgeterrorstring(Env, Status, ErrorMsg);
// 	  fprintf(stderr,"%s",ErrorMsg);
// 	  goto Terminate;
// 	}
       
      status = CPXcloseCPLEX(&env); 
//       if (Status != 0)
// 	{
// 	  fprintf(stderr,"A CPLEX környezet bezárása sikertelen.\n");
// 	  CPXgeterrorstring(Env, Status, ErrorMsg);
// 	  fprintf(stderr,"%s",ErrorMsg);
// 	  goto Terminate;
// 	}
      
    }

  protected:
    virtual int _addCol();
    virtual int _addRow();
    virtual void _setRowCoeffs(int i, 
			       int length,
                               const int   * indices, 
                               const Value   * values );
    virtual void _setColCoeffs(int i, 
			       int length,
                               const int   * indices, 
                               const Value   * values);
    virtual void _setColLowerBound(int i, Value value);
    virtual void _setColUpperBound(int i, Value value);
    virtual void _setRowLowerBound(int i, Value value);
    virtual void _setRowUpperBound(int i, Value value);
    virtual void _setObjCoeff(int i, Value obj_coef);
    ///\e
    
    ///\bug Unimplemented
    ///
    virtual SolutionStatus _solve();
    ///\e
    
    ///\bug Unimplemented
    ///
    virtual Value _getSolution(int i);

  };
} //END OF NAMESPACE LEMON

#endif //LEMON_LP_CPLEX_H

