0
5
0
1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
4 | 4 |
* |
5 |
* Copyright (C) 2003- |
|
5 |
* Copyright (C) 2003-2009 |
|
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
... | ... |
@@ -432,31 +432,31 @@ |
432 | 432 |
|
433 | 433 |
void CplexBase::_clear() { |
434 | 434 |
CPXfreeprob(cplexEnv(),&_prob); |
435 | 435 |
int status; |
436 | 436 |
_prob = CPXcreateprob(cplexEnv(), &status, "Cplex problem"); |
437 | 437 |
rows.clear(); |
438 | 438 |
cols.clear(); |
439 | 439 |
} |
440 | 440 |
|
441 | 441 |
// CplexLp members |
442 | 442 |
|
443 | 443 |
CplexLp::CplexLp() |
444 |
: LpBase(), |
|
444 |
: LpBase(), LpSolver(), CplexBase() {} |
|
445 | 445 |
|
446 | 446 |
CplexLp::CplexLp(const CplexEnv& env) |
447 |
: LpBase(), |
|
447 |
: LpBase(), LpSolver(), CplexBase(env) {} |
|
448 | 448 |
|
449 | 449 |
CplexLp::CplexLp(const CplexLp& other) |
450 |
: LpBase(), |
|
450 |
: LpBase(), LpSolver(), CplexBase(other) {} |
|
451 | 451 |
|
452 | 452 |
CplexLp::~CplexLp() {} |
453 | 453 |
|
454 | 454 |
CplexLp* CplexLp::newSolver() const { return new CplexLp; } |
455 | 455 |
CplexLp* CplexLp::cloneSolver() const {return new CplexLp(*this); } |
456 | 456 |
|
457 | 457 |
const char* CplexLp::_solverName() const { return "CplexLp"; } |
458 | 458 |
|
459 | 459 |
void CplexLp::_clear_temporals() { |
460 | 460 |
_col_status.clear(); |
461 | 461 |
_row_status.clear(); |
462 | 462 |
_primal_ray.clear(); |
... | ... |
@@ -789,46 +789,46 @@ |
789 | 789 |
case CPX_UNBOUNDED: |
790 | 790 |
return INFEASIBLE; |
791 | 791 |
default: |
792 | 792 |
return UNDEFINED; //Everything else comes here |
793 | 793 |
//FIXME error |
794 | 794 |
} |
795 | 795 |
#endif |
796 | 796 |
} |
797 | 797 |
|
798 | 798 |
// CplexMip members |
799 | 799 |
|
800 | 800 |
CplexMip::CplexMip() |
801 |
: LpBase(), |
|
801 |
: LpBase(), MipSolver(), CplexBase() { |
|
802 | 802 |
|
803 | 803 |
#if CPX_VERSION < 800 |
804 | 804 |
CPXchgprobtype(cplexEnv(), _prob, CPXPROB_MIP); |
805 | 805 |
#else |
806 | 806 |
CPXchgprobtype(cplexEnv(), _prob, CPXPROB_MILP); |
807 | 807 |
#endif |
808 | 808 |
} |
809 | 809 |
|
810 | 810 |
CplexMip::CplexMip(const CplexEnv& env) |
811 |
: LpBase(), |
|
811 |
: LpBase(), MipSolver(), CplexBase(env) { |
|
812 | 812 |
|
813 | 813 |
#if CPX_VERSION < 800 |
814 | 814 |
CPXchgprobtype(cplexEnv(), _prob, CPXPROB_MIP); |
815 | 815 |
#else |
816 | 816 |
CPXchgprobtype(cplexEnv(), _prob, CPXPROB_MILP); |
817 | 817 |
#endif |
818 | 818 |
|
819 | 819 |
} |
820 | 820 |
|
821 | 821 |
CplexMip::CplexMip(const CplexMip& other) |
822 |
: LpBase(), |
|
822 |
: LpBase(), MipSolver(), CplexBase(other) {} |
|
823 | 823 |
|
824 | 824 |
CplexMip::~CplexMip() {} |
825 | 825 |
|
826 | 826 |
CplexMip* CplexMip::newSolver() const { return new CplexMip; } |
827 | 827 |
CplexMip* CplexMip::cloneSolver() const {return new CplexMip(*this); } |
828 | 828 |
|
829 | 829 |
const char* CplexMip::_solverName() const { return "CplexMip"; } |
830 | 830 |
|
831 | 831 |
void CplexMip::_setColType(int i, CplexMip::ColTypes col_type) { |
832 | 832 |
|
833 | 833 |
// Note If a variable is to be changed to binary, a call to CPXchgbds |
834 | 834 |
// should also be made to change the bounds to 0 and 1. |
1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
4 | 4 |
* |
5 |
* Copyright (C) 2003- |
|
5 |
* Copyright (C) 2003-2009 |
|
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
... | ... |
@@ -69,25 +69,25 @@ |
69 | 69 |
/// Destructor |
70 | 70 |
virtual ~CplexEnv(); |
71 | 71 |
|
72 | 72 |
protected: |
73 | 73 |
|
74 | 74 |
cpxenv* cplexEnv() { return _env; } |
75 | 75 |
const cpxenv* cplexEnv() const { return _env; } |
76 | 76 |
}; |
77 | 77 |
|
78 | 78 |
/// \brief Base interface for the CPLEX LP and MIP solver |
79 | 79 |
/// |
80 | 80 |
/// This class implements the common interface of the CPLEX LP and |
81 |
/// MIP solvers. |
|
81 |
/// MIP solvers. |
|
82 | 82 |
/// \ingroup lp_group |
83 | 83 |
class CplexBase : virtual public LpBase { |
84 | 84 |
protected: |
85 | 85 |
|
86 | 86 |
CplexEnv _env; |
87 | 87 |
cpxlp* _prob; |
88 | 88 |
|
89 | 89 |
CplexBase(); |
90 | 90 |
CplexBase(const CplexEnv&); |
91 | 91 |
CplexBase(const CplexBase &); |
92 | 92 |
virtual ~CplexBase(); |
93 | 93 |
|
... | ... |
@@ -226,28 +226,31 @@ |
226 | 226 |
///\ingroup lp_group |
227 | 227 |
class CplexMip : public MipSolver, public CplexBase { |
228 | 228 |
public: |
229 | 229 |
/// \e |
230 | 230 |
CplexMip(); |
231 | 231 |
/// \e |
232 | 232 |
CplexMip(const CplexEnv&); |
233 | 233 |
/// \e |
234 | 234 |
CplexMip(const CplexMip&); |
235 | 235 |
/// \e |
236 | 236 |
virtual ~CplexMip(); |
237 | 237 |
|
238 |
/// \e |
|
239 |
virtual CplexMip* cloneSolver() const; |
|
240 |
/// \e |
|
241 |
virtual CplexMip* newSolver() const; |
|
242 |
|
|
238 | 243 |
protected: |
239 | 244 |
|
240 |
virtual CplexMip* _cloneSolver() const; |
|
241 |
virtual CplexMip* _newSolver() const; |
|
242 | 245 |
|
243 | 246 |
virtual const char* _solverName() const; |
244 | 247 |
|
245 | 248 |
virtual ColTypes _getColType(int col) const; |
246 | 249 |
virtual void _setColType(int col, ColTypes col_type); |
247 | 250 |
|
248 | 251 |
virtual SolveExitStatus _solve(); |
249 | 252 |
virtual ProblemType _getType() const; |
250 | 253 |
virtual Value _getSol(int i) const; |
251 | 254 |
virtual Value _getSolValue() const; |
252 | 255 |
|
253 | 256 |
}; |
1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
4 | 4 |
* |
5 |
* Copyright (C) 2003- |
|
5 |
* Copyright (C) 2003-2009 |
|
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
... | ... |
@@ -522,30 +522,30 @@ |
522 | 522 |
cols.clear(); |
523 | 523 |
} |
524 | 524 |
|
525 | 525 |
void GlpkBase::freeEnv() { |
526 | 526 |
glp_free_env(); |
527 | 527 |
} |
528 | 528 |
|
529 | 529 |
GlpkBase::FreeEnvHelper GlpkBase::freeEnvHelper; |
530 | 530 |
|
531 | 531 |
// GlpkLp members |
532 | 532 |
|
533 | 533 |
GlpkLp::GlpkLp() |
534 |
: LpBase(), |
|
534 |
: LpBase(), LpSolver(), GlpkBase() { |
|
535 | 535 |
messageLevel(MESSAGE_NO_OUTPUT); |
536 | 536 |
} |
537 | 537 |
|
538 | 538 |
GlpkLp::GlpkLp(const GlpkLp& other) |
539 |
: LpBase(other), |
|
539 |
: LpBase(other), LpSolver(other), GlpkBase(other) { |
|
540 | 540 |
messageLevel(MESSAGE_NO_OUTPUT); |
541 | 541 |
} |
542 | 542 |
|
543 | 543 |
GlpkLp* GlpkLp::newSolver() const { return new GlpkLp; } |
544 | 544 |
GlpkLp* GlpkLp::cloneSolver() const { return new GlpkLp(*this); } |
545 | 545 |
|
546 | 546 |
const char* GlpkLp::_solverName() const { return "GlpkLp"; } |
547 | 547 |
|
548 | 548 |
void GlpkLp::_clear_temporals() { |
549 | 549 |
_primal_ray.clear(); |
550 | 550 |
_dual_ray.clear(); |
551 | 551 |
} |
... | ... |
@@ -821,30 +821,30 @@ |
821 | 821 |
|
822 | 822 |
void GlpkLp::presolver(bool b) { |
823 | 823 |
lpx_set_int_parm(lp, LPX_K_PRESOL, b ? 1 : 0); |
824 | 824 |
} |
825 | 825 |
|
826 | 826 |
void GlpkLp::messageLevel(MessageLevel m) { |
827 | 827 |
_message_level = m; |
828 | 828 |
} |
829 | 829 |
|
830 | 830 |
// GlpkMip members |
831 | 831 |
|
832 | 832 |
GlpkMip::GlpkMip() |
833 |
: LpBase(), |
|
833 |
: LpBase(), MipSolver(), GlpkBase() { |
|
834 | 834 |
messageLevel(MESSAGE_NO_OUTPUT); |
835 | 835 |
} |
836 | 836 |
|
837 | 837 |
GlpkMip::GlpkMip(const GlpkMip& other) |
838 |
: LpBase(), |
|
838 |
: LpBase(), MipSolver(), GlpkBase(other) { |
|
839 | 839 |
messageLevel(MESSAGE_NO_OUTPUT); |
840 | 840 |
} |
841 | 841 |
|
842 | 842 |
void GlpkMip::_setColType(int i, GlpkMip::ColTypes col_type) { |
843 | 843 |
switch (col_type) { |
844 | 844 |
case INTEGER: |
845 | 845 |
glp_set_col_kind(lp, i, GLP_IV); |
846 | 846 |
break; |
847 | 847 |
case REAL: |
848 | 848 |
glp_set_col_kind(lp, i, GLP_CV); |
849 | 849 |
break; |
850 | 850 |
} |
1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
4 | 4 |
* |
5 |
* Copyright (C) 2003- |
|
5 |
* Copyright (C) 2003-2009 |
|
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
... | ... |
@@ -356,25 +356,25 @@ |
356 | 356 |
solveAndCheck(lp, LpSolver::UNBOUNDED, expected_opt); |
357 | 357 |
|
358 | 358 |
//Infeasibilty |
359 | 359 |
lp.addRow(x1+x2 <=-2); |
360 | 360 |
solveAndCheck(lp, LpSolver::INFEASIBLE, expected_opt); |
361 | 361 |
|
362 | 362 |
} |
363 | 363 |
|
364 | 364 |
template<class LP> |
365 | 365 |
void cloneTest() |
366 | 366 |
{ |
367 | 367 |
//Test for clone/new |
368 |
|
|
368 |
|
|
369 | 369 |
LP* lp = new LP(); |
370 | 370 |
LP* lpnew = lp->newSolver(); |
371 | 371 |
LP* lpclone = lp->cloneSolver(); |
372 | 372 |
delete lp; |
373 | 373 |
delete lpnew; |
374 | 374 |
delete lpclone; |
375 | 375 |
} |
376 | 376 |
|
377 | 377 |
int main() |
378 | 378 |
{ |
379 | 379 |
LpSkeleton lp_skel; |
380 | 380 |
lpTest(lp_skel); |
... | ... |
@@ -384,33 +384,33 @@ |
384 | 384 |
GlpkLp lp_glpk1,lp_glpk2; |
385 | 385 |
lpTest(lp_glpk1); |
386 | 386 |
aTest(lp_glpk2); |
387 | 387 |
cloneTest<GlpkLp>(); |
388 | 388 |
} |
389 | 389 |
#endif |
390 | 390 |
|
391 | 391 |
#ifdef HAVE_CPLEX |
392 | 392 |
try { |
393 | 393 |
CplexLp lp_cplex1,lp_cplex2; |
394 | 394 |
lpTest(lp_cplex1); |
395 | 395 |
aTest(lp_cplex2); |
396 |
cloneTest<CplexLp>(); |
|
396 | 397 |
} catch (CplexEnv::LicenseError& error) { |
397 | 398 |
#ifdef LEMON_FORCE_CPLEX_CHECK |
398 | 399 |
check(false, error.what()); |
399 | 400 |
#else |
400 | 401 |
std::cerr << error.what() << std::endl; |
401 | 402 |
std::cerr << "Cplex license check failed, lp check skipped" << std::endl; |
402 | 403 |
#endif |
403 | 404 |
} |
404 |
cloneTest<CplexLp>(); |
|
405 | 405 |
#endif |
406 | 406 |
|
407 | 407 |
#ifdef HAVE_SOPLEX |
408 | 408 |
{ |
409 | 409 |
SoplexLp lp_soplex1,lp_soplex2; |
410 | 410 |
lpTest(lp_soplex1); |
411 | 411 |
aTest(lp_soplex2); |
412 | 412 |
cloneTest<SoplexLp>(); |
413 | 413 |
} |
414 | 414 |
#endif |
415 | 415 |
|
416 | 416 |
#ifdef HAVE_CLP |
1 | 1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*- |
2 | 2 |
* |
3 | 3 |
* This file is a part of LEMON, a generic C++ optimization library. |
4 | 4 |
* |
5 |
* Copyright (C) 2003- |
|
5 |
* Copyright (C) 2003-2009 |
|
6 | 6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
7 | 7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES). |
8 | 8 |
* |
9 | 9 |
* Permission to use, modify and distribute this software is granted |
10 | 10 |
* provided that this copyright notice appears in all copies. For |
11 | 11 |
* precise terms see the accompanying LICENSE file. |
12 | 12 |
* |
13 | 13 |
* This software is provided "AS IS" with no warranty of any kind, |
14 | 14 |
* express or implied, and with no claim as to its suitability for any |
15 | 15 |
* purpose. |
16 | 16 |
* |
17 | 17 |
*/ |
... | ... |
@@ -100,50 +100,50 @@ |
100 | 100 |
//Restrict both to integer |
101 | 101 |
mip.colType(x1,MipSolver::INTEGER); |
102 | 102 |
expected_opt=0; |
103 | 103 |
solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt); |
104 | 104 |
|
105 | 105 |
|
106 | 106 |
|
107 | 107 |
} |
108 | 108 |
|
109 | 109 |
template<class MIP> |
110 | 110 |
void cloneTest() |
111 | 111 |
{ |
112 |
|
|
112 |
|
|
113 | 113 |
MIP* mip = new MIP(); |
114 | 114 |
MIP* mipnew = mip->newSolver(); |
115 | 115 |
MIP* mipclone = mip->cloneSolver(); |
116 | 116 |
delete mip; |
117 | 117 |
delete mipnew; |
118 | 118 |
delete mipclone; |
119 | 119 |
} |
120 | 120 |
|
121 | 121 |
int main() |
122 | 122 |
{ |
123 | 123 |
|
124 | 124 |
#ifdef HAVE_GLPK |
125 | 125 |
{ |
126 | 126 |
GlpkMip mip1; |
127 | 127 |
aTest(mip1); |
128 | 128 |
cloneTest<GlpkMip>(); |
129 | 129 |
} |
130 | 130 |
#endif |
131 | 131 |
|
132 | 132 |
#ifdef HAVE_CPLEX |
133 | 133 |
try { |
134 | 134 |
CplexMip mip2; |
135 | 135 |
aTest(mip2); |
136 |
cloneTest<CplexMip>(); |
|
136 | 137 |
} catch (CplexEnv::LicenseError& error) { |
137 | 138 |
#ifdef LEMON_FORCE_CPLEX_CHECK |
138 | 139 |
check(false, error.what()); |
139 | 140 |
#else |
140 | 141 |
std::cerr << error.what() << std::endl; |
141 | 142 |
std::cerr << "Cplex license check failed, lp check skipped" << std::endl; |
142 | 143 |
#endif |
143 | 144 |
} |
144 |
cloneTest<CplexMip>(); |
|
145 | 145 |
#endif |
146 | 146 |
|
147 | 147 |
return 0; |
148 | 148 |
|
149 | 149 |
} |
0 comments (0 inline)