Variable.cpp 2.42 KB
Newer Older
1
2
#include "Variable.h"

3
4
5
bool Variable::VERBOSE_IDENT = true;


6
Variable::Variable(const Variable& var) : _description(var._description), _integrality(var._integrality), _lower_bound(var._lower_bound), _upper_bound(var._upper_bound), _fixed(false), _value(var._value) {}
7

8
Variable::Variable(Variable&& var) : _description(std::move(var._description)), _integrality(std::move(var._integrality)), _lower_bound(std::move(var._lower_bound)), _upper_bound(std::move(var._upper_bound)), _fixed(false), _value(std::move(var._value)) {}
Jonas Seidel's avatar
Jonas Seidel committed
9

Jonas Seidel's avatar
Jonas Seidel committed
10
//Variable::Variable(integrality integrality, std::pair<bool, double> lower_bound, std::pair<bool, double> upper_bound, double value) : _integrality(integrality), _lower_bound(lower_bound), _upper_bound(upper_bound), _value(value) {}
Jonas Seidel's avatar
Jonas Seidel committed
11

12
Variable::Variable(std::string description, integrality integrality, std::pair<bool, double> lower_bound, std::pair<bool, double> upper_bound, double value) : _description(description), _integrality(integrality), _lower_bound(lower_bound), _upper_bound(upper_bound), _fixed(false), _value(value) {}
Jonas Seidel's avatar
Jonas Seidel committed
13
14
15
16
17


std::string Variable::description(){
  return this->_description;
}
18
19
20
21
22

integrality Variable::is_integral(){
  return this->_integrality;
}

Jonas Seidel's avatar
Jonas Seidel committed
23
24
25
26
27
28
29
30
std::pair<bool, double> Variable::lower_bound(){
  return this->_lower_bound;
}

std::pair<bool, double> Variable::upper_bound(){
  return this->_upper_bound;
}

jonasseidel's avatar
jonasseidel committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
SCIP_Real Variable::computational_lower_bound(SCIP* scip){
  auto lower = this->lower_bound();
  if(!lower.first){
    return -SCIPinfinity(scip);
  }
  return lower.second;
}

SCIP_Real Variable::computational_upper_bound(SCIP* scip){
  auto upper = this->upper_bound();
  if(!upper.first){
    return SCIPinfinity(scip);
  }
  return upper.second;
}

Jonas Seidel's avatar
Jonas Seidel committed
47

48
49
50
51
bool Variable::is_fixed(){
  return this->_fixed;
}

52
double& Variable::value(){
53
  assert(this->is_fixed());
54
55
  return this->_value;
}
56

jonasseidel's avatar
jonasseidel committed
57
58
59
60
61
62
63
64
SCIP_VAR* Variable::computational_var(SCIP* scip, double direction_coefficient){
  SCIP_VAR* var;
  char* name = new char[this->description().size()+1];
  SCIP_CALL_ABORT( SCIPcreateVarBasic(scip, &var, strcpy(name, this->description().c_str()), this->computational_lower_bound(scip), this->computational_upper_bound(scip), direction_coefficient,
                          (this->is_integral() ? SCIP_VARTYPE_INTEGER : SCIP_VARTYPE_CONTINUOUS)));
  return var;
}

65
66
67
68
69
70
71
72
std::ostream& operator<<(std::ostream& os, Variable& var){
  if(var.is_fixed()){
    os << var.value();
  }else{
    os << var.description();
  }
  return os;
}