Crevice  0.1
 All Classes Functions Variables Pages
TermVariable.cc
1 /*
2  * File: TermVariable.cc
3  *
4  * Copyright 2012 Heinrich Schuchardt <xypron.glpk@gmx.de>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #include "TermVariable.h"
20 #include "TermConstant.h"
21 #include "Problem.h"
22 #include <limits>
23 
29 TermVariable::TermVariable(Problem* problem, const std::string &name) :
30 Term::Term(problem) {
31  name_ = std::string(name);
32  lowerBound_ = std::numeric_limits<double>::min();
33  upperBound_ = std::numeric_limits<double>::max();
34 }
35 
40 }
41 
47 bool TermVariable::less(const Term* term) const {
48  bool ret;
49  if (this->Term::less(term)) {
50  return true;
51  } else if (term->Term::less(this)) {
52  return false;
53  } else {
54  const TermVariable* term_variable;
55  term_variable = static_cast<const TermVariable *> (term);
56  ret = this->name_.compare(term_variable->name_) < 0;
57  }
58  return ret;
59 }
60 
67 TermVariable* TermVariable::create(Problem* problem, const std::string &name) {
68  TermVariable* variable = new TermVariable(problem, name);
69  variable = static_cast<TermVariable *> (problem->addVariable(variable));
70  return variable;
71 }
72 
80  if (this->getProblem() != variable->getProblem()) {
81  ProblemMismatchException problem_mismatch_exception;
82  throw problem_mismatch_exception;
83  }
84  if (this->name_ == variable->name_) {
85  return TermConstant::create(this->getProblem(), 1.);
86  } else {
87  return TermConstant::create(this->getProblem(), 0.);
88  }
89 }
90 
92  const DoubleVector* variableValues,
93  TermValueSet* termValues) {
94  return (*variableValues)[this->variableIndex_];
95 }
96 
102  return variableIndex_;
103 }
104 
109 void TermVariable::setVariableIndex(const int variableIndex) {
110  variableIndex_ = variableIndex;
111 }
112 
118  return lowerBound_;
119 }
120 
125 void TermVariable::setLowerBound(const double lowerBound) {
126  lowerBound_ = lowerBound;
127 }
128 
133 const std::string TermVariable::getName() {
134  return name_;
135 }
136 
142  return upperBound_;
143 }
144 
149 void TermVariable::setUpperBound(const double upperBound) {
150  upperBound_ = upperBound;
151 }
152 
153 std::string TermVariable::toString() const {
154  return name_;
155 };