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