gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
Merge
0 4 0
merge default
4 files changed with 18 insertions and 0 deletions:
↑ Collapse diff ↑
Ignore white space 6 line context
... ...
@@ -501,48 +501,54 @@
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

	
529
  GlpkBase::FreeEnvHelper GlpkBase::freeEnvHelper;
530

	
525 531
  // GlpkLp members
526 532

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

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

	
537 543
  GlpkLp* GlpkLp::newSolver() const { return new GlpkLp; }
538 544
  GlpkLp* GlpkLp::cloneSolver() const { return new GlpkLp(*this); }
539 545

	
540 546
  const char* GlpkLp::_solverName() const { return "GlpkLp"; }
541 547

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

	
547 553
  GlpkLp::SolveExitStatus GlpkLp::_solve() {
548 554
    return solvePrimal();
Ignore white space 48 line context
... ...
@@ -79,48 +79,60 @@
79 79

	
80 80
    virtual void _setColLowerBound(int i, Value value);
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
  private:
104

	
105
    static void freeEnv();
106

	
107
    struct FreeEnvHelper {
108
      ~FreeEnvHelper() {
109
        freeEnv();
110
      }
111
    };
112
    
113
    static FreeEnvHelper freeEnvHelper;
114
    
103 115
  public:
104 116

	
105 117
    ///Pointer to the underlying GLPK data structure.
106 118
    LPX *lpx() {return lp;}
107 119
    ///Const pointer to the underlying GLPK data structure.
108 120
    const LPX *lpx() const {return lp;}
109 121

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

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

	
116 128
  };
117 129

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

	
125 137
    ///\e
126 138
    GlpkLp();
0 comments (0 inline)