gravatar
deba@inf.elte.hu
deba@inf.elte.hu
Fix GLPK tests (#213)
0 4 0
default
4 files changed with 14 insertions and 0 deletions:
↑ Collapse diff ↑
Show white space 48 line context
... ...
@@ -501,48 +501,52 @@
501 501
    case MAX:
502 502
      glp_set_obj_dir(lp, GLP_MAX);
503 503
      break;
504 504
    }
505 505
  }
506 506

	
507 507
  GlpkBase::Sense GlpkBase::_getSense() const {
508 508
    switch(glp_get_obj_dir(lp)) {
509 509
    case GLP_MIN:
510 510
      return MIN;
511 511
    case GLP_MAX:
512 512
      return MAX;
513 513
    default:
514 514
      LEMON_ASSERT(false, "Wrong sense");
515 515
      return GlpkBase::Sense();
516 516
    }
517 517
  }
518 518

	
519 519
  void GlpkBase::_clear() {
520 520
    glp_erase_prob(lp);
521 521
    rows.clear();
522 522
    cols.clear();
523 523
  }
524 524

	
525
  void GlpkBase::freeEnv() {
526
    glp_free_env();
527
  }
528

	
525 529
  // GlpkLp members
526 530

	
527 531
  GlpkLp::GlpkLp()
528 532
    : LpBase(), GlpkBase(), LpSolver() {
529 533
    messageLevel(MESSAGE_NO_OUTPUT);
530 534
  }
531 535

	
532 536
  GlpkLp::GlpkLp(const GlpkLp& other)
533 537
    : LpBase(other), GlpkBase(other), LpSolver(other) {
534 538
    messageLevel(MESSAGE_NO_OUTPUT);
535 539
  }
536 540

	
537 541
  GlpkLp* GlpkLp::_newSolver() const { return new GlpkLp; }
538 542
  GlpkLp* GlpkLp::_cloneSolver() const { return new GlpkLp(*this); }
539 543

	
540 544
  const char* GlpkLp::_solverName() const { return "GlpkLp"; }
541 545

	
542 546
  void GlpkLp::_clear_temporals() {
543 547
    _primal_ray.clear();
544 548
    _dual_ray.clear();
545 549
  }
546 550

	
547 551
  GlpkLp::SolveExitStatus GlpkLp::_solve() {
548 552
    return solvePrimal();
Show white space 48 line context
... ...
@@ -81,48 +81,56 @@
81 81
    virtual Value _getColLowerBound(int i) const;
82 82

	
83 83
    virtual void _setColUpperBound(int i, Value value);
84 84
    virtual Value _getColUpperBound(int i) const;
85 85

	
86 86
    virtual void _setRowLowerBound(int i, Value value);
87 87
    virtual Value _getRowLowerBound(int i) const;
88 88

	
89 89
    virtual void _setRowUpperBound(int i, Value value);
90 90
    virtual Value _getRowUpperBound(int i) const;
91 91

	
92 92
    virtual void _setObjCoeffs(ExprIterator b, ExprIterator e);
93 93
    virtual void _getObjCoeffs(InsertIterator b) const;
94 94

	
95 95
    virtual void _setObjCoeff(int i, Value obj_coef);
96 96
    virtual Value _getObjCoeff(int i) const;
97 97

	
98 98
    virtual void _setSense(Sense);
99 99
    virtual Sense _getSense() const;
100 100

	
101 101
    virtual void _clear();
102 102

	
103 103
  public:
104 104

	
105
    /// \brief Deallocates the globally allocated memory of GLPK.
106

	
107
    /// Deallocates the globally allocated memory of GLPK.  \note
108
    /// Usually, it do not have to be called, because the GLPK use
109
    /// only a small amount of global memory, and it is deallocated
110
    /// automatically at the end of program.
111
    static void freeEnv();
112

	
105 113
    ///Pointer to the underlying GLPK data structure.
106 114
    LPX *lpx() {return lp;}
107 115
    ///Const pointer to the underlying GLPK data structure.
108 116
    const LPX *lpx() const {return lp;}
109 117

	
110 118
    ///Returns the constraint identifier understood by GLPK.
111 119
    int lpxRow(Row r) const { return rows(id(r)); }
112 120

	
113 121
    ///Returns the variable identifier understood by GLPK.
114 122
    int lpxCol(Col c) const { return cols(id(c)); }
115 123

	
116 124
  };
117 125

	
118 126
  /// \brief Interface for the GLPK LP solver
119 127
  ///
120 128
  /// This class implements an interface for the GLPK LP solver.
121 129
  ///\ingroup lp_group
122 130
  class GlpkLp : public GlpkBase, public LpSolver {
123 131
  public:
124 132

	
125 133
    ///\e
126 134
    GlpkLp();
127 135
    ///\e
128 136
    GlpkLp(const GlpkLp&);
Show white space 48 line context
... ...
@@ -345,48 +345,49 @@
345 345

	
346 346
  //Erase one constraint and return to maximization
347 347
  lp.erase(upright);
348 348
  lp.sense(lp.MAX);
349 349
  expected_opt=LpSolver::INF;
350 350
  solveAndCheck(lp, LpSolver::UNBOUNDED, expected_opt);
351 351

	
352 352
  //Infeasibilty
353 353
  lp.addRow(x1+x2 <=-2);
354 354
  solveAndCheck(lp, LpSolver::INFEASIBLE, expected_opt);
355 355

	
356 356
}
357 357

	
358 358
int main()
359 359
{
360 360
  LpSkeleton lp_skel;
361 361
  lpTest(lp_skel);
362 362

	
363 363
#ifdef HAVE_GLPK
364 364
  {
365 365
    GlpkLp lp_glpk1,lp_glpk2;
366 366
    lpTest(lp_glpk1);
367 367
    aTest(lp_glpk2);
368 368
  }
369
  GlpkLp::freeEnv();
369 370
#endif
370 371

	
371 372
#ifdef HAVE_CPLEX
372 373
  try {
373 374
    CplexLp lp_cplex1,lp_cplex2;
374 375
    lpTest(lp_cplex1);
375 376
    aTest(lp_cplex2);
376 377
  } catch (CplexEnv::LicenseError& error) {
377 378
#ifdef LEMON_FORCE_CPLEX_CHECK
378 379
    check(false, error.what());
379 380
#else
380 381
    std::cerr << error.what() << std::endl;
381 382
    std::cerr << "Cplex license check failed, lp check skipped" << std::endl;
382 383
#endif
383 384
  }
384 385
#endif
385 386

	
386 387
#ifdef HAVE_SOPLEX
387 388
  {
388 389
    SoplexLp lp_soplex1,lp_soplex2;
389 390
    lpTest(lp_soplex1);
390 391
    aTest(lp_soplex2);
391 392
  }
392 393
#endif
Show white space 48 line context
... ...
@@ -94,43 +94,44 @@
94 94
  //Restrict x2 to integer
95 95
  mip.colType(x2,MipSolver::INTEGER);
96 96
  expected_opt=1.0/2.0;
97 97
  solveAndCheck(mip, MipSolver::OPTIMAL, expected_opt);
98 98

	
99 99

	
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

	
110 110
int main()
111 111
{
112 112

	
113 113
#ifdef HAVE_GLPK
114 114
  {
115 115
    GlpkMip mip1;
116 116
    aTest(mip1);
117 117
  }
118
  GlpkLp::freeEnv();
118 119
#endif
119 120

	
120 121
#ifdef HAVE_CPLEX
121 122
  try {
122 123
    CplexMip mip2;
123 124
    aTest(mip2);
124 125
  } catch (CplexEnv::LicenseError& error) {
125 126
#ifdef LEMON_FORCE_CPLEX_CHECK
126 127
    check(false, error.what());
127 128
#else
128 129
    std::cerr << error.what() << std::endl;
129 130
    std::cerr << "Cplex license check failed, lp check skipped" << std::endl;
130 131
#endif
131 132
  }
132 133
#endif
133 134

	
134 135
  return 0;
135 136

	
136 137
}
0 comments (0 inline)