source: pico/trunk/src/lp/pico/PicoCpxLP.h @ 5835

Revision 5835, 20.6 KB checked in by wehart, 5 years ago (diff)

Update of copyright assertions.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*  _________________________________________________________________________
2 *
3 *  Acro: A Common Repository for Optimizers
4 *  Copyright (c) 2008 Sandia Corporation.
5 *  This software is distributed under the BSD License.
6 *  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
7 *  the U.S. Government retains certain rights in this software.
8 *  For more information, see the README.txt file in the top Acro directory.
9 *  _________________________________________________________________________
10 */
11
12/**
13 * \file PicoCpxLP.h
14 *
15 * Defines CPLEX interface stuff.
16 */
17
18#ifndef pico_PicoCpxLP_h
19#define pico_PicoCpxLP_h
20
21#include <acro_config.h>
22#ifdef ACRO_HAVE_CPLEX
23
24#include <OsiCpxSolverInterface.hpp>
25#include <pico/PicoLPCutMngmnt.h>
26#include <pico/PicoLPSubclass.h>
27
28// Copied from the OsiCpxSolverInterface.cpp file.  This used to be in the corresponding
29// header file, but moved to the .cpp file and became inaccessible.  Check to see if we
30// can move it back to the header file.  In the meantime, see if this works.  If we cannot
31// get this moved back to the header, be careful to watch for any changes in this method.
32
33static inline void
34checkCPXerror( int err, std::string cpxfuncname, std::string osimethod )
35{
36  if( err != 0 )
37    {
38      char s[100];
39      sprintf( s, "%s returned error %d", cpxfuncname.c_str(), err );
40      std::cout << "ERROR: " << s << " (" << osimethod <<
41        " in OsiCpxSolverInterface)" << std::endl;
42      throw CoinError( s, osimethod.c_str(), "OsiCpxSolverInterface" );
43    }
44}
45
46
47namespace pico {
48
49
50template <>
51void PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::initialize()
52{
53  messageHandler()->setLogLevel(0);
54}
55
56//
57// TODO: is this right???
58// CAP response: probably not. Why are we using MIP stats when we are using the solver
59// as an LP?
60//
61template<>
62bool PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::isTimeLimitReached() const
63{
64  //int stat = CPXgetstat( const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(), getMutableLpPtr() );
65int stat = CPXgetstat( const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(), const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL) );
66#if (CPX_VERSION >= 800)
67return stat == CPXMIP_TIME_LIM_INFEAS || stat == CPXMIP_TIME_LIM_FEAS;
68#else
69return stat == CPX_TIME_LIM_INFEAS || stat == CPX_TIME_LIM_FEAS;
70#endif
71}
72
73
74template<>
75bool PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::isProvenPrimalUnbounded() const
76{
77int stat = CPXgetstat( const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(), const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL) );
78#if (CPX_VERSION >= 800)
79return stat == CPX_STAT_UNBOUNDED;
80#else
81int method = CPXgetmethod(const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(), const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL) );
82// stat for version < 8 is relative to solver. If running dual simplex and stat is
83// infeasible, we do not necessarily know the primal is unbounded (could be infeasible).
84 return ((method == CPX_ALG_PRIMAL && stat == CPX_UNBOUNDED));
85#endif
86}
87
88
89template<>
90bool PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::isProvenDualUnbounded() const
91{
92  // Version 8.0 and up returns status wrt the primal only.  There is no primal status that
93  // proves dual unboundedness.  CAP.
94#if (CPX_VERSION < 800)
95int stat =
96#endif
97CPXgetstat( const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(), const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL) );
98#if (CPX_VERSION >= 800)
99return false;
100#else
101int method = CPXgetmethod(const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(), const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL) );
102// stat for version < 8 is relative to solver. If running primal simplex and stat is
103// infeasible, we do not necessarily know the dual is unbounded (could be infeasible).
104 return ((method == CPX_ALG_DUAL && stat == CPX_UNBOUNDED));
105#endif
106}
107
108
109template<>
110double PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::getColLower(int whichVariable) const
111{
112double ans;
113CPXgetlb(const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(),const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL),&ans,whichVariable,whichVariable);
114return ans;
115}
116
117
118template<>
119double PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::getColUpper(int whichVariable) const
120{
121double ans;
122CPXgetub(const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(),const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL),&ans,whichVariable,whichVariable);
123return ans;
124}
125
126
127template<>
128double PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::getRowLower(int whichVariable) const
129{
130char sense;
131CPXgetsense(const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(),const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL),&sense,whichVariable,whichVariable);
132double rhs;
133CPXgetrhs(const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(),const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL),&rhs,whichVariable,whichVariable);
134double range;
135CPXgetrngval(const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(),const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL),&range,whichVariable,whichVariable);
136double lower, upper;
137convertSenseToBound(sense, rhs, range, lower, upper);
138return lower;
139}
140
141
142template<>
143double PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::getRowUpper(int whichVariable) const
144{
145char sense;
146CPXgetsense(const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(),const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL),&sense,whichVariable,whichVariable);
147double rhs;
148CPXgetrhs(const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(),const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL),&rhs,whichVariable,whichVariable);
149double range;
150CPXgetrngval(const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(),const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL),&range,whichVariable,whichVariable);
151double lower, upper;
152convertSenseToBound(sense, rhs, range, lower, upper);
153return upper;
154}
155
156
157template<>
158double PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::getRightHandSide(int whichConstraint) const
159{
160double rhs;
161CPXgetrhs(const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(),const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL),&rhs,whichConstraint,whichConstraint);
162return rhs;
163}
164
165template<>
166PicoLPInterface::constraintSense PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::getRowSense(int whichConstraint) const
167{
168char csense;
169CPXgetsense( const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(),const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL), &csense, whichConstraint, whichConstraint);
170
171PicoLPInterface::constraintSense sense = notRestricted;
172switch (csense) {
173  case 'L':     sense = lessOrEqual; break;
174  case 'G':     sense = greaterOrEqual; break;
175  case 'E':     sense = equal; break;
176  case 'R':     sense = ranged; break;
177  case 'N':     sense = notRestricted; break;
178  default:
179        EXCEPTION_MNGR(std::runtime_error,"PicoLPSubclass::getRowSense - bad sense type=" << csense);
180  };
181return sense;
182}
183
184
185template<>
186double PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::getObjCoefficient(int whichVariable) const
187{
188double ans;
189int err = CPXgetobj(const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(),const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL),&ans,whichVariable,whichVariable);
190checkCPXerror( err, "CPXgetobj", "getObjCoefficient" );
191return ans;
192}
193
194
195template<>
196double PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::getColSolution(const int whichCol) const
197{
198double ans = 0.0;
199int probType = CPXgetprobtype(const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(),const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL));
200#if (CPX_VERSION >= 800)
201if ( probType == CPXPROB_MILP ) {
202#else
203if ( probType == CPXPROB_MIP ) {
204#endif
205   int err = CPXgetmipx( (const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr()), (const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL)), &ans, whichCol, whichCol);
206   if ( err == CPXERR_NO_INT_SOLN )
207      ans = 0.0;
208   else
209      checkCPXerror( err, "CPXgetmipx", "getColSolution" );
210   }
211else {
212   int err = CPXgetx( const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(),const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL), &ans, whichCol, whichCol );
213   if ( err == CPXERR_NO_SOLN )
214      ans = 0.0;
215   else
216      checkCPXerror( err, "CPXgetx", "getColSolution" );
217   }
218return ans;
219}
220
221
222template<>
223double PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::getRowPrice(const int whichRow) const
224{
225double ans;
226int err = CPXgetpi(const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(),const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL),&ans,whichRow,whichRow);
227if (err == CPXERR_NO_SOLN)
228   ans = 0.0;
229else
230   checkCPXerror( err, "CPXgetpi", "getRowPrice" );
231return ans;
232}
233
234
235template<>
236double PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::getReducedCost(const int whichCol) const
237{
238double ans;
239int err = CPXgetdj(const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(),const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL),&ans,whichCol,whichCol);
240if (err == CPXERR_NO_SOLN)
241   ans = 0.0;
242else
243   checkCPXerror( err, "CPXgetdj", "getReducedCost" );
244return ans;
245}
246
247
248template <>
249void PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::getBasis(BasisArray& basisBuffer)
250{
251int numCols = getNumCols();
252int basisSize = numCols + getNumRows();
253utilib::IntVector tempBasis(basisSize);
254int tmp = CPXgetbase(const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(),const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL),(int*)(tempBasis.data()),(int*)(&tempBasis[numCols]));
255if (tmp)
256   EXCEPTION_MNGR(std::runtime_error,"CPLEX would not retreive basis");
257for (int i = 0; i < basisSize; i++) {
258  int val = tempBasis[i];
259  if (val == 0) basisBuffer.put(i, atLower);
260  else if (val == 3) basisBuffer.put(i, nonbasic);
261  else basisBuffer.put(i, (basisState)val);
262  }
263}
264
265template <>
266basisState PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::getBasis(int whichVariable)
267{
268int numCols = getNumCols();
269utilib::IntVector tempBasis(numCols + getNumRows());
270int tmp = CPXgetbase(const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(),const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL),
271                (int*)(tempBasis.data()),(int*)(&tempBasis[numCols]));
272if (tmp)
273  EXCEPTION_MNGR(std::runtime_error, "PicoLPSubclass<T,V>::getBasis -- "
274                 "Couldn't retreive basis");
275int val = tempBasis[whichVariable];
276//
277// Convert to Osi standard representation for the basis
278//
279if (val == 0) return atLower;
280if (val == 3) return nonbasic;
281return (basisState)val;
282}
283
284
285template <>
286void PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::setBasis(BasisArray& basisBuffer)
287{
288static BasicArray<int> tempBasis;
289
290int num_cols = getNumCols();
291int basisSize = getNumRows() + num_cols;
292tempBasis.resize(basisSize);
293for (int i = 0; i < basisSize; i++)
294  {
295  tempBasis[i] = (int)basisBuffer(i);
296  // translate differences between PICO values and cplex values
297  if (tempBasis[i] == atLower)
298    tempBasis[i] = 0;
299  else if (tempBasis[i] == nonbasic)
300    {
301  // If this is the slack variable for an added cut and the value is nonbasic, set it
302  // to atLower (this is the value a slack variable can be if it's not basic
303      if (i >= num_cols + num_core_rows)
304        tempBasis[i] = 0;
305      else tempBasis[i] = 3;
306    }
307  }
308
309status = CPXcopybase(const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(),const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL),(int*)(tempBasis.data()),
310                                        (int*)(&tempBasis[getNumCols() ]));
311if (status && lpWarnings)
312   ucout << "Warning: cplex would not load basis, status = " << status;
313  // Might want to set state to unsolved to indicate a possible mismatch between
314  // the solution and the basis, but for now, we won't do it here.
315//else
316//  {
317  //  myState= unsolved;
318//  }
319}
320
321
322template<>
323priceRule PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::getPricingRule() const
324{
325/// TODO
326return defaultPricing;
327}
328
329
330template<>
331void PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::setPricingRule(priceRule rule)
332{
333/// TODO
334}
335
336
337template<>
338double PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::getTimeLimit() const
339{
340double ans;
341int tmp = CPXgetdblparam(const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(),CPX_PARAM_TILIM,&ans);
342if (tmp != 0)
343  {
344    EXCEPTION_MNGR(std::runtime_error, "Unable to get time limit");
345  }
346return ans;
347}
348
349
350template<>
351void PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::setTimeLimit(double time)
352{
353int tmp = CPXsetdblparam(const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(),CPX_PARAM_TILIM,time);
354if (tmp)
355  EXCEPTION_MNGR(std::runtime_error,"Unable to set time limit");
356}
357
358
359template<>
360clockType PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::getClockType() const
361{
362int ans;
363int tmp = CPXgetintparam(const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(),CPX_PARAM_CLOCKTYPE,&ans);
364if (tmp != 0)
365  {
366    EXCEPTION_MNGR(std::runtime_error,"Unable to get clock type");
367  }
368if ((clockType) ans != cpuTime && (clockType)ans != wallTime)
369   EXCEPTION_MNGR(std::runtime_error, "Unknown clock type " <<  ans);
370return (clockType)ans;
371}
372
373
374template<>
375void PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::setClockType(clockType cType)
376{
377if (cType != cpuTime && cType != wallTime)
378   EXCEPTION_MNGR(std::runtime_error, "Improper clock type " << cType);
379int tmp = CPXsetintparam(const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(),CPX_PARAM_CLOCKTYPE, (int)cType);
380if (tmp)
381   EXCEPTION_MNGR(std::runtime_error, "Unable to set clock type");
382}
383
384
385
386template<>
387PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::PicoLPSubclass()
388{
389solverMethod = primalSimplex;
390// TODO
391// Turn cplex preprocessing off till we handle presolve infeasibility
392// errors more gracefully
393CPXsetintparam(const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getEnvironmentPtr(), CPX_PARAM_PREIND, 0);
394}
395
396/* Comment this out till I can figure out why the cplex call isn't working
397template<>
398void PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::setColUpper(double* upperBounds, int* indexList, int len)
399{
400  char c = 'U';
401  // Going to getting lp pointer with default values rather than
402  // OsiCpxSolverInterface::FREECACHED_COLUMN, for debugging
403  int err = CPXchgbds( getEnvironmentPtr(), const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL), len, indexList, &c, upperBounds);
404  checkCPXerror( err, "CPXchgbds", "setColUpper" );
405}
406
407template<>
408void PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::setColLower(double* lowerBounds, int* indexList, int len)
409{
410  char c = 'L';
411  int err = CPXchgbds( getEnvironmentPtr(), const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL), len, indexList, &c, lowerBounds);
412  checkCPXerror( err, "CPXchgbds", "setColLower" );
413}
414*/
415
416template<>
417  void PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::write(char *filename, ilp_format format, bool signalInts)
418{
419  // actually just use cplex mps and lp formats for now.
420  bool currSolveStatus;
421  if (signalInts)
422    {
423      currSolveStatus = solving;
424      setCutting();
425    }
426int writeStatus;
427if (format == mps_format)
428  {
429    // This will write with original names, but since PICO currently
430    // doesn't give the real variable names (etc) to the cplex solver,
431    // it will be equivalent to the "REW" filetype = generic names
432  writeStatus = CPXwriteprob(getEnvironmentPtr(), const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL), filename, "MPS");
433  if (writeStatus)
434    ucout << "Error writing lp to file\n";
435  solving = currSolveStatus;
436  return;
437  }
438if (format == lp_format)
439  {
440  writeStatus = CPXwriteprob(getEnvironmentPtr(), const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL), filename, "LP");
441  if (status)
442    ucout << "Error writing lp to file\n";
443  solving = currSolveStatus;
444  return;
445  }
446// default for the other formats.
447 solving = currSolveStatus;
448 PicoLPInterface::write(filename, format);
449}
450
451template<>
452void PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::printBrokenInfo()
453{
454    int stat = CPXgetstat( getEnvironmentPtr(), const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL) );
455    ucout << "Broken LP has cplex status " << stat << "\n";
456}
457
458template<>
459void PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>::setMatrixCoeff(int row, int col, double newValue)
460{
461    int stat = CPXchgcoef(getEnvironmentPtr(), const_cast<PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt>*>(this)->OsiCpxSolverInterface::getLpPtr(OsiCpxSolverInterface::KEEPCACHED_ALL), row, col, newValue);
462    if (stat != 0) EXCEPTION_MNGR(std::runtime_error, "Cplex error setting matrix coefficient for (" << row << ", " << col << ")");
463}
464
465typedef PicoLPSubclass<OsiCpxSolverInterface,PicoLPCutMngmnt> PicoCpxLP;
466
467} // namespace pico
468
469#endif
470
471#endif
Note: See TracBrowser for help on using the repository browser.