src/work/athos/lp/lp_cplex.h
author athos
Thu, 07 Apr 2005 09:42:31 +0000
changeset 1314 9269c76551cf
parent 1299 e2545ef5d7d8
child 1319 6e277ba3fc76
permissions -rw-r--r--
New functions in lp_glpk.cc. Sample file: lp_sample.cc.
athos@1299
     1
/* -*- C++ -*-
athos@1299
     2
 * src/lemon/lp_cplex.h - Part of LEMON, a generic C++ optimization library
athos@1299
     3
 *
athos@1299
     4
 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
athos@1299
     5
 * (Egervary Combinatorial Optimization Research Group, EGRES).
athos@1299
     6
 *
athos@1299
     7
 * Permission to use, modify and distribute this software is granted
athos@1299
     8
 * provided that this copyright notice appears in all copies. For
athos@1299
     9
 * precise terms see the accompanying LICENSE file.
athos@1299
    10
 *
athos@1299
    11
 * This software is provided "AS IS" with no warranty of any kind,
athos@1299
    12
 * express or implied, and with no claim as to its suitability for any
athos@1299
    13
 * purpose.
athos@1299
    14
 *
athos@1299
    15
 */
athos@1299
    16
athos@1299
    17
#ifndef LEMON_LP_CPLEX_H
athos@1299
    18
#define LEMON_LP_CPLEX_H
athos@1299
    19
athos@1299
    20
///\file
athos@1299
    21
///\brief Header of the LEMON-CPLEX lp solver interface.
athos@1299
    22
athos@1299
    23
#include "lp_base.h"
athos@1299
    24
extern "C" {
athos@1299
    25
#include "ilcplex/cplex.h"
athos@1299
    26
}
athos@1299
    27
athos@1299
    28
namespace lemon {
athos@1299
    29
athos@1299
    30
athos@1299
    31
  /// \brief Wrapper for GLPK solver
athos@1299
    32
  /// 
athos@1299
    33
  /// This class implements a lemon wrapper for GLPK.
athos@1299
    34
  class LpCplex : public LpSolverBase {
athos@1299
    35
athos@1299
    36
  public:
athos@1299
    37
athos@1299
    38
    typedef LpSolverBase Parent;
athos@1299
    39
    
athos@1299
    40
    /// \e
athos@1299
    41
    int status;
athos@1299
    42
    CPXENVptr env;
athos@1299
    43
    CPXLPptr lp;
athos@1299
    44
athos@1299
    45
athos@1299
    46
    /// \e
athos@1299
    47
    LpCplex() : Parent() {
athos@1299
    48
      env = NULL;
athos@1299
    49
      lp = NULL;
athos@1299
    50
      env = CPXopenCPLEXdevelop(&status);     
athos@1299
    51
//     if (Env == NULL)
athos@1299
    52
//     {
athos@1299
    53
//          fprintf(stderr,"A CPLEX környezet megnyitása sikertelen.\n");
athos@1299
    54
// 	 CPXgeterrorstring(Env, Status, ErrorMsg);
athos@1299
    55
// 	 fprintf(stderr,"%s",ErrorMsg);
athos@1299
    56
// 	 goto Terminate;
athos@1299
    57
//     }
athos@1299
    58
athos@1299
    59
    // *** A problema létrehozása ***
athos@1299
    60
    lp = CPXcreateprob(env, &status, "LP problem");
athos@1299
    61
 
athos@1299
    62
//    if (Problem == NULL)
athos@1299
    63
//     {
athos@1299
    64
// 	fprintf(stderr,"Az LP létrehozása sikertelen");
athos@1299
    65
// 	goto Terminate;
athos@1299
    66
//     }
athos@1299
    67
 
athos@1299
    68
    }
athos@1299
    69
    /// \e
athos@1299
    70
    ~LpCplex() {
athos@1299
    71
      status = CPXfreeprob(env,&lp); 
athos@1299
    72
//       if (Status != 0)
athos@1299
    73
// 	{
athos@1299
    74
// 	  fprintf(stderr,"A CPLEX feladat törlése sikertelen.\n");
athos@1299
    75
// 	  CPXgeterrorstring(Env, Status, ErrorMsg);
athos@1299
    76
// 	  fprintf(stderr,"%s",ErrorMsg);
athos@1299
    77
// 	  goto Terminate;
athos@1299
    78
// 	}
athos@1299
    79
       
athos@1299
    80
      status = CPXcloseCPLEX(&env); 
athos@1299
    81
//       if (Status != 0)
athos@1299
    82
// 	{
athos@1299
    83
// 	  fprintf(stderr,"A CPLEX környezet bezárása sikertelen.\n");
athos@1299
    84
// 	  CPXgeterrorstring(Env, Status, ErrorMsg);
athos@1299
    85
// 	  fprintf(stderr,"%s",ErrorMsg);
athos@1299
    86
// 	  goto Terminate;
athos@1299
    87
// 	}
athos@1299
    88
      
athos@1299
    89
    }
athos@1299
    90
athos@1299
    91
  protected:
athos@1299
    92
    virtual int _addCol();
athos@1299
    93
    virtual int _addRow();
athos@1299
    94
    virtual void _setRowCoeffs(int i, 
athos@1299
    95
			       int length,
athos@1299
    96
                               const int   * indices, 
athos@1299
    97
                               const Value   * values );
athos@1299
    98
    virtual void _setColCoeffs(int i, 
athos@1299
    99
			       int length,
athos@1299
   100
                               const int   * indices, 
athos@1299
   101
                               const Value   * values);
athos@1299
   102
    virtual void _setColLowerBound(int i, Value value);
athos@1299
   103
    virtual void _setColUpperBound(int i, Value value);
athos@1299
   104
    virtual void _setRowLowerBound(int i, Value value);
athos@1299
   105
    virtual void _setRowUpperBound(int i, Value value);
athos@1299
   106
    virtual void _setObjCoeff(int i, Value obj_coef);
athos@1299
   107
    ///\e
athos@1299
   108
    
athos@1299
   109
    ///\bug Unimplemented
athos@1299
   110
    ///
alpar@1303
   111
    virtual SolutionStatus _solve();
athos@1299
   112
    ///\e
athos@1299
   113
    
athos@1299
   114
    ///\bug Unimplemented
athos@1299
   115
    ///
athos@1299
   116
    virtual Value _getSolution(int i);
athos@1299
   117
athos@1299
   118
  };
athos@1299
   119
} //END OF NAMESPACE LEMON
athos@1299
   120
athos@1299
   121
#endif //LEMON_LP_CPLEX_H
athos@1299
   122