COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/athos/lp/lp_cplex.cc @ 1319:6e277ba3fc76

Last change on this file since 1319:6e277ba3fc76 was 1319:6e277ba3fc76, checked in by athos, 19 years ago

Cplex interface has improved a lot.

File size: 4.0 KB
Line 
1/* -*- C++ -*-
2 * src/lemon/lp_cplex.cc
3 * - Part of LEMON, a generic C++ optimization library
4 *
5 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
6 * (Egervary Combinatorial Optimization Research Group, EGRES).
7 *
8 * Permission to use, modify and distribute this software is granted
9 * provided that this copyright notice appears in all copies. For
10 * precise terms see the accompanying LICENSE file.
11 *
12 * This software is provided "AS IS" with no warranty of any kind,
13 * express or implied, and with no claim as to its suitability for any
14 * purpose.
15 *
16 */
17
18#include"lp_cplex.h"
19
20///\file
21///\brief Implementation of the LEMON-CPLEX lp solver interface.
22namespace lemon {
23 
24  int LpCplex::_addCol()
25  {
26    int i = CPXgetnumcols (env, lp);
27    Value lb[1],ub[1];
28    lb[0]=-INF;//-CPX_INFBOUND;
29    ub[0]=INF;//CPX_INFBOUND;
30    status = CPXnewcols (env, lp, 1, NULL, lb, ub, NULL, NULL);
31    return i;
32  }
33 
34  int LpCplex::_addRow()
35  {
36    //We want a ranged row
37    char sense[1];
38    sense[0]='R';
39
40    int i = CPXgetnumrows (env, lp);
41    status = CPXnewrows (env, lp, 1, NULL, sense, NULL, NULL);
42    return i;
43  }
44 
45  ///\warning Data at index 0 is ignored iin the arrays.
46  void LpCplex::_setRowCoeffs(int i,
47                              int length,
48                              int  const * indices,
49                              Value  const * values )
50  {
51    int rowlist[length+1];
52    int* p=rowlist;
53    for (int k=1;k<=length;++k){
54      rowlist[k]=i;
55    }
56    status = CPXchgcoeflist(env, lp,
57                            length,
58                            p++,
59                            const_cast<int * >(indices++),
60                            const_cast<Value * >(values++));
61  }
62 
63  void LpCplex::_setColCoeffs(int i,
64                              int length,
65                              int  const * indices,
66                              Value  const * values)
67  {
68    int collist[length+1];
69    int* p=collist;
70    for (int k=1;k<=length;++k){
71      collist[k]=i;
72    }
73    status = CPXchgcoeflist(env, lp,
74                            length,
75                            const_cast<int * >(indices++),
76                            p++,
77                            const_cast<Value * >(values++));
78  }
79 
80  void LpCplex::_setColLowerBound(int i, Value value)
81  {
82    int indices[1];
83    indices[0]=i;
84    char lu[1];
85    lu[0]='L';
86    Value bd[1];
87    bd[0]=value;
88    status = CPXchgbds (env, lp, 1, indices, lu, bd);
89 
90  }
91 
92  void LpCplex::_setColUpperBound(int i, Value value)
93  {
94    int indices[1];
95    indices[0]=i;
96    char lu[1];
97    lu[0]='U';
98    Value bd[1];
99    bd[0]=value;
100    status = CPXchgbds (env, lp, 1, indices, lu, bd);
101  }
102 
103  void LpCplex::_setRowLowerBound(int i, Value value)
104  {
105    status = CPXchgcoef (env, lp, i, -1, value);
106
107  }
108 
109  void LpCplex::_setRowUpperBound(int i, Value value)
110  {
111    //TODO Ezt kell meg megirni
112    //    Value lo=CPX
113  }
114 
115  void LpCplex::_setObjCoeff(int i, Value obj_coef)
116  {
117    status = CPXchgcoef (env, lp, -1, i, obj_coef);
118   }
119
120  LpCplex::SolveExitStatus LpCplex::_solve()
121  {
122    return SOLVED;
123//     int i=  lpx_simplex(lp);
124//     switch (i) {
125//     case LPX_E_OK:
126//       return SOLVED;
127//       break;
128//     default:
129//       return UNSOLVED;
130//     }
131  }
132
133  LpCplex::Value LpCplex::_getPrimal(int i)
134  {
135    return 0;
136  }
137 
138  LpCplex::Value LpCplex::_getPrimalValue()
139  {
140    return 0;
141  }
142 
143 
144  LpCplex::SolutionStatus LpCplex::_getPrimalStatus()
145  {
146    return OPTIMAL;
147//     int stat=  lpx_get_status(lp);
148//     switch (stat) {
149//     case LPX_UNDEF://Undefined (no solve has been run yet)
150//       return UNDEFINED;
151//       break;
152//     case LPX_NOFEAS://There is no feasible solution (primal, I guess)
153//     case LPX_INFEAS://Infeasible
154//       return INFEASIBLE;
155//       break;
156//     case LPX_UNBND://Unbounded
157//       return INFINITE;
158//       break;
159//     case LPX_FEAS://Feasible
160//       return FEASIBLE;
161//       break;
162//     case LPX_OPT://Feasible
163//       return OPTIMAL;
164//       break;
165//     default:
166//       return UNDEFINED; //to avoid gcc warning
167//       //FIXME error
168//     }
169  }
170
171
172  void LpCplex::_setMax()
173  {
174    CPXchgobjsen (env, lp, CPX_MAX);
175   }
176  void LpCplex::_setMin()
177  {
178    CPXchgobjsen (env, lp, CPX_MIN);
179   }
180 
181} //namespace lemon
182
Note: See TracBrowser for help on using the repository browser.