Commit cffefd9c authored by jonasseidel's avatar jonasseidel

computational models bulk commit

parent 5b3c57cc
use application "polytope";
my $import = lp2poly(".data/Maintenance_Problem/mp.lp");
declare $import = lp2poly(".data/Maintenance_Problem/mp.lp");
#print "\n\n---------------------------------------------------------------------------------------------------------\n";
#print "Extreme points relaxed polyeder:\n\n";
......@@ -64,13 +64,14 @@ for (@$integral_indexes) {
#print "@$restr_labels\n";
# calculating the wanted data:
#print "Mixed Integer Convex Hull:\n";
#my $mint_hull = mixed_integer_hull($import, $integral_indexes);
#declare $mint_hull = mixed_integer_hull($import, $integral_indexes);
#$mint_hull->COORDINATE_LABELS = $import->COORDINATE_LABELS;
#print_constraints($mint_hull);
print "Integral Coordinate Projection Convex Hull\n";
my $proj = projection($import, $integral_indexes);
my $proj_hull = integer_hull($proj);
declare $proj = projection($import, $integral_indexes);
$proj->COORDINATE_LABELS = $restr_labels;
declare $proj_hull = integer_hull($proj);
$proj_hull->COORDINATE_LABELS = $restr_labels;
print_constraints($proj_hull);
......
0: -edge_1_0_Selected_epoch_0 >= -1
1: -edge_2_3_Selected_epoch_0 >= -1
2: -edge_2_1_Selected_epoch_0 >= -1
3: -edge_2_3_Selected_epoch_0 - 3 edge_2_1_Selected_epoch_0 - 2 edge_2_0_Selected_epoch_0 - target_variable >= -6
4: -3 edge_1_0_Selected_epoch_0 - edge_2_3_Selected_epoch_0 - 2 edge_2_0_Selected_epoch_0 - target_variable >= -6
5: target_variable >= 0
6: -edge_2_0_Selected_epoch_0 >= -1
7: -3 edge_1_0_Selected_epoch_0 - 2 edge_2_0_Selected_epoch_0 - edge_3_0_Selected_epoch_0 - target_variable >= -6
8: -edge_1_0_Selected_epoch_0 - 2 edge_2_1_Selected_epoch_0 - 2 edge_2_0_Selected_epoch_0 - edge_3_0_Selected_epoch_0 - target_variable >= -6
9: -edge_3_0_Selected_epoch_0 >= -1
10: -edge_3_1_Selected_epoch_0 >= -1
11: -3 edge_2_1_Selected_epoch_0 - 2 edge_2_0_Selected_epoch_0 - edge_3_0_Selected_epoch_0 - edge_3_1_Selected_epoch_0 - target_variable >= -7
12: edge_3_0_Selected_epoch_0 >= 0
13: -edge_2_3_Selected_epoch_0 + edge_2_1_Selected_epoch_0 + 2 edge_2_0_Selected_epoch_0 - target_variable >= -2
14: edge_1_0_Selected_epoch_0 - edge_2_3_Selected_epoch_0 + 2 edge_2_0_Selected_epoch_0 - target_variable >= -2
15: -3 edge_1_0_Selected_epoch_0 - edge_2_3_Selected_epoch_0 + edge_2_1_Selected_epoch_0 - edge_2_0_Selected_epoch_0 - target_variable >= -5
16: edge_1_0_Selected_epoch_0 - 3 edge_2_1_Selected_epoch_0 - edge_2_0_Selected_epoch_0 - edge_3_0_Selected_epoch_0 - edge_3_1_Selected_epoch_0 - target_variable >= -6
17: edge_3_1_Selected_epoch_0 >= 0
18: -edge_2_3_Selected_epoch_0 - 2 edge_2_1_Selected_epoch_0 - 2 edge_2_0_Selected_epoch_0 + edge_3_0_Selected_epoch_0 - target_variable >= -5
19: edge_2_3_Selected_epoch_0 - 2 edge_2_1_Selected_epoch_0 - 2 edge_2_0_Selected_epoch_0 - edge_3_0_Selected_epoch_0 - edge_3_1_Selected_epoch_0 - target_variable >= -6
20: edge_1_0_Selected_epoch_0 - edge_2_3_Selected_epoch_0 + edge_2_1_Selected_epoch_0 + 2 edge_2_0_Selected_epoch_0 + edge_3_0_Selected_epoch_0 - target_variable >= -1
21: edge_1_0_Selected_epoch_0 + 2 edge_2_0_Selected_epoch_0 - edge_3_0_Selected_epoch_0 - target_variable >= -2
22: edge_1_0_Selected_epoch_0 - 2 edge_2_1_Selected_epoch_0 - edge_3_0_Selected_epoch_0 - target_variable >= -4
23: edge_2_1_Selected_epoch_0 + 2 edge_2_0_Selected_epoch_0 - edge_3_0_Selected_epoch_0 - target_variable >= -2
24: -2 edge_1_0_Selected_epoch_0 - edge_2_3_Selected_epoch_0 - 2 edge_2_0_Selected_epoch_0 + edge_3_0_Selected_epoch_0 - target_variable >= -5
25: 2 edge_1_0_Selected_epoch_0 - edge_2_3_Selected_epoch_0 - 2 edge_2_1_Selected_epoch_0 + edge_3_0_Selected_epoch_0 - target_variable >= -3
26: edge_1_0_Selected_epoch_0 - edge_2_3_Selected_epoch_0 - 3 edge_2_1_Selected_epoch_0 - edge_2_0_Selected_epoch_0 - target_variable >= -5
27: 2 edge_1_0_Selected_epoch_0 - edge_2_3_Selected_epoch_0 + 2 edge_2_0_Selected_epoch_0 + edge_3_0_Selected_epoch_0 - target_variable >= -1
28: -2 edge_1_0_Selected_epoch_0 - edge_2_3_Selected_epoch_0 + edge_2_1_Selected_epoch_0 - edge_2_0_Selected_epoch_0 + edge_3_0_Selected_epoch_0 - target_variable >= -4
29: edge_2_0_Selected_epoch_0 >= 0
30: -edge_1_0_Selected_epoch_0 + edge_2_3_Selected_epoch_0 + 3 edge_2_1_Selected_epoch_0 + edge_2_0_Selected_epoch_0 - target_variable >= -1
31: edge_2_3_Selected_epoch_0 - edge_2_1_Selected_epoch_0 - 2 edge_2_0_Selected_epoch_0 - target_variable >= -4
32: 2 edge_1_0_Selected_epoch_0 + edge_2_3_Selected_epoch_0 - 2 edge_2_1_Selected_epoch_0 - edge_3_0_Selected_epoch_0 - edge_3_1_Selected_epoch_0 - target_variable >= -4
33: 2 edge_1_0_Selected_epoch_0 + edge_2_3_Selected_epoch_0 + 2 edge_2_0_Selected_epoch_0 - edge_3_0_Selected_epoch_0 - target_variable >= -1
34: edge_2_3_Selected_epoch_0 + 2 edge_2_1_Selected_epoch_0 + 2 edge_2_0_Selected_epoch_0 - edge_3_0_Selected_epoch_0 - target_variable >= -1
35: 2 edge_1_0_Selected_epoch_0 + edge_2_3_Selected_epoch_0 - edge_2_1_Selected_epoch_0 + edge_2_0_Selected_epoch_0 - edge_3_0_Selected_epoch_0 - target_variable >= -2
36: -2 edge_1_0_Selected_epoch_0 + edge_2_3_Selected_epoch_0 - 2 edge_2_0_Selected_epoch_0 - edge_3_0_Selected_epoch_0 - target_variable >= -5
37: -edge_1_0_Selected_epoch_0 + 3 edge_2_1_Selected_epoch_0 + edge_2_0_Selected_epoch_0 + edge_3_0_Selected_epoch_0 + edge_3_1_Selected_epoch_0 - target_variable >= -1
38: edge_2_3_Selected_epoch_0 + 3 edge_2_1_Selected_epoch_0 + 2 edge_2_0_Selected_epoch_0 - target_variable >= 0
39: 3 edge_1_0_Selected_epoch_0 - edge_2_1_Selected_epoch_0 + edge_2_0_Selected_epoch_0 + edge_3_0_Selected_epoch_0 - target_variable >= -1
40: -edge_1_0_Selected_epoch_0 + 2 edge_2_1_Selected_epoch_0 + edge_3_0_Selected_epoch_0 - target_variable >= -2
41: 3 edge_1_0_Selected_epoch_0 + edge_2_3_Selected_epoch_0 - edge_2_1_Selected_epoch_0 + edge_2_0_Selected_epoch_0 - target_variable >= -1
42: -edge_1_0_Selected_epoch_0 - 2 edge_2_0_Selected_epoch_0 + edge_3_0_Selected_epoch_0 - target_variable >= -4
43: edge_1_0_Selected_epoch_0 + 2 edge_2_1_Selected_epoch_0 + 2 edge_2_0_Selected_epoch_0 + edge_3_0_Selected_epoch_0 - target_variable >= 0
44: edge_1_0_Selected_epoch_0 >= 0
45: -3 edge_1_0_Selected_epoch_0 + edge_2_1_Selected_epoch_0 - edge_2_0_Selected_epoch_0 - edge_3_0_Selected_epoch_0 - target_variable >= -5
46: edge_2_1_Selected_epoch_0 >= 0
47: -2 edge_1_0_Selected_epoch_0 + edge_2_3_Selected_epoch_0 + 2 edge_2_1_Selected_epoch_0 - edge_3_0_Selected_epoch_0 - target_variable >= -3
48: 3 edge_1_0_Selected_epoch_0 + 2 edge_2_0_Selected_epoch_0 + edge_3_0_Selected_epoch_0 - target_variable >= 0
49: 3 edge_1_0_Selected_epoch_0 + edge_2_3_Selected_epoch_0 + 2 edge_2_0_Selected_epoch_0 - target_variable >= 0
50: 3 edge_2_1_Selected_epoch_0 + 2 edge_2_0_Selected_epoch_0 + edge_3_0_Selected_epoch_0 + edge_3_1_Selected_epoch_0 - target_variable >= 0
51: -edge_2_1_Selected_epoch_0 - 2 edge_2_0_Selected_epoch_0 + edge_3_0_Selected_epoch_0 - target_variable >= -4
52: -edge_1_0_Selected_epoch_0 + edge_2_3_Selected_epoch_0 - edge_2_1_Selected_epoch_0 - 2 edge_2_0_Selected_epoch_0 - edge_3_0_Selected_epoch_0 - target_variable >= -5
53: edge_2_3_Selected_epoch_0 >= 0
54: -edge_2_3_Selected_epoch_0 + 2 edge_2_1_Selected_epoch_0 + 2 edge_2_0_Selected_epoch_0 + edge_3_0_Selected_epoch_0 + edge_3_1_Selected_epoch_0 - target_variable >= -1
55: -2 edge_1_0_Selected_epoch_0 - edge_2_3_Selected_epoch_0 + 2 edge_2_1_Selected_epoch_0 + edge_3_0_Selected_epoch_0 + edge_3_1_Selected_epoch_0 - target_variable >= -3
56: -edge_1_0_Selected_epoch_0 + edge_2_3_Selected_epoch_0 - 2 edge_2_0_Selected_epoch_0 - target_variable >= -4
0: -edge_1_Selected_epoch_0 - edge_1_Selected_epoch_1 >= -1
1: edge_1_Selected_epoch_1 >= 0
2: -edge_2_Selected_epoch_0 - edge_2_Selected_epoch_1 >= -1
3: edge_2_Selected_epoch_1 >= 0
4: edge_3_Selected_epoch_2 >= 0
5: edge_3_Selected_epoch_1 >= 0
6: target_variable >= 0
7: -edge_1_Selected_epoch_0 - 2 edge_2_Selected_epoch_0 + 3 edge_3_Selected_epoch_1 + 3 edge_3_Selected_epoch_2 - target_variable >= -3
9: -2 edge_2_Selected_epoch_0 + 2 edge_3_Selected_epoch_1 + 2 edge_3_Selected_epoch_2 - target_variable >= -3
10: -edge_1_Selected_epoch_1 - edge_3_Selected_epoch_1 - target_variable >= -4
11: -target_variable >= -3
12: -edge_1_Selected_epoch_1 - 2 edge_2_Selected_epoch_1 - 3 edge_3_Selected_epoch_1 - target_variable >= -6
13: edge_1_Selected_epoch_0 + edge_1_Selected_epoch_1 - 2 edge_2_Selected_epoch_0 + 2 edge_3_Selected_epoch_1 + edge_3_Selected_epoch_2 - target_variable >= -3
14: edge_1_Selected_epoch_0 + edge_1_Selected_epoch_1 - 2 edge_2_Selected_epoch_1 - 2 edge_3_Selected_epoch_1 - edge_3_Selected_epoch_2 - target_variable >= -5
15: edge_2_Selected_epoch_0 >= 0
16: -edge_3_Selected_epoch_1 - edge_3_Selected_epoch_2 >= -1
17: edge_1_Selected_epoch_0 + edge_1_Selected_epoch_1 - edge_3_Selected_epoch_2 - target_variable >= -3
18: 2 edge_2_Selected_epoch_0 + 2 edge_2_Selected_epoch_1 - 2 edge_3_Selected_epoch_2 - target_variable >= -3
19: -edge_1_Selected_epoch_0 - 2 edge_2_Selected_epoch_1 - edge_3_Selected_epoch_1 + edge_3_Selected_epoch_2 - target_variable >= -5
20: -edge_1_Selected_epoch_0 + 2 edge_2_Selected_epoch_0 + 2 edge_2_Selected_epoch_1 + edge_3_Selected_epoch_1 - edge_3_Selected_epoch_2 - target_variable >= -3
21: -edge_1_Selected_epoch_1 + 2 edge_2_Selected_epoch_0 + 2 edge_2_Selected_epoch_1 - edge_3_Selected_epoch_1 - 2 edge_3_Selected_epoch_2 - target_variable >= -4
22: edge_1_Selected_epoch_0 >= 0
23: edge_1_Selected_epoch_0 + edge_1_Selected_epoch_1 + 2 edge_2_Selected_epoch_0 + 2 edge_2_Selected_epoch_1 - 3 edge_3_Selected_epoch_2 - target_variable >= -3
24: -edge_1_Selected_epoch_1 - 2 edge_2_Selected_epoch_0 + edge_3_Selected_epoch_1 + 2 edge_3_Selected_epoch_2 - target_variable >= -4
25: -2 edge_2_Selected_epoch_1 - 2 edge_3_Selected_epoch_1 - target_variable >= -5
......@@ -7,7 +7,7 @@ random_attribute_generator::random_attribute_generator(
> data
){
for(std::pair<std::string, std::tuple<opt_dir, integrality, double, double> > pair : data){
assert(std::get<2>(pair.second) < std::get<3>(pair.second) );
assert(std::get<2>(pair.second) <= std::get<3>(pair.second) );
std::pair<opt_dir, integrality> constr_data = {std::get<0>(pair.second), std::get<1>(pair.second)};
this->_constr_data.insert({pair.first, constr_data});
......
......@@ -220,7 +220,7 @@ std::pair<bool, std::pair<std::vector<Node*>, std::vector<Edge*>>> random_graph_
Node* n1;
Node* n2;
size_t edges_to_be_added = curr_step == number_of_steps-1 ? number_of_edges_per_step/step_fading : number_of_edges_per_step;
size_t edges_to_be_added = curr_step == number_of_steps-1 ? number_of_edges_per_step/(step_fading+1) : number_of_edges_per_step;
for(size_t i = 0; i < edges_to_be_added; ++i){ // the last step does not get any edges
size_t attempt = 0;
redo:
......
......@@ -74,8 +74,10 @@ void Graph::conditional_bfs_all_components(
node_exec will be called with nullptr for via for start node
node_exec might be called with nullptr for via if the graph is not strongly connected
node_exec need to return true in order to continue traversal over its incident edges
if node_exec returns true traversal over its incident edges will be forced no matter their visitation status
*/
std::set<Node*> uncharted = this->nodes();
std::deque<std::pair<Edge*, Node*>> active;
for(Node* node : starting_nodes){
......@@ -92,7 +94,6 @@ void Graph::conditional_bfs_all_components(
bool local_all_paths = node_exec(next.first, next.second);
Node* n = next.second;
uncharted.erase(n);
for(Edge* e : n->incident()){
bool used_in_traversal = false;
......@@ -102,6 +103,7 @@ void Graph::conditional_bfs_all_components(
used_in_traversal = true;
active.push_back({e, e->to(n)});
uncharted.erase(e->to(n));
}
edge_exec(n, e, used_in_traversal);
......
......@@ -33,6 +33,16 @@ bool Coefficient::is_unity(){
return true;
}
double Coefficient::value(){
double curr = 0;
for(std::pair<Monomial, double> pair : this->_coeff){
curr += pair.second*pair.first.value();
}
return curr;
}
// Coefficient operator+(double val, Coefficient coeff){
// Coefficient tmp (coeff);
//
......
#include "Constraint.h"
Constraint::Constraint(std::string description, relation relation_type, std::map<Variable*, Coefficient> lhs, Coefficient rhs)
Constraint::Constraint(std::string description, relation relation_type, std::unordered_map<Variable*, Coefficient> lhs, Coefficient rhs)
: _description(description), _relation(relation_type), _lhs(lhs), _rhs(rhs){}
Constraint::Constraint(relation relation_type, std::map<Variable*, Coefficient> lhs, Coefficient rhs)
Constraint::Constraint(relation relation_type, std::unordered_map<Variable*, Coefficient> lhs, Coefficient rhs)
: _relation(relation_type), _lhs(lhs), _rhs(rhs){}
std::string Constraint::description(){
......@@ -14,7 +14,7 @@ relation Constraint::is_equality(){
return this->_relation;
}
std::map<Variable*, Coefficient> Constraint::lhs(){
std::unordered_map<Variable*, Coefficient> Constraint::lhs(){
return this->_lhs;
}
......@@ -30,6 +30,20 @@ Coefficient Constraint::rhs(){
return this->_rhs;
}
SCIP_CONS* Constraint::computational_con(SCIP* scip, std::unordered_map<Variable*, SCIP_VAR*>& variable_lookup){
SCIP_CONS* cons;
SCIP_Real right_inequality = this->_rhs.value();
SCIP_Real left_inequality = (this->is_equality() ? right_inequality : -SCIPinfinity(scip));
char* name = new char[this->description().size()+1];
SCIP_CALL_ABORT( SCIPcreateConsBasicLinear(scip, &cons, strcpy(name, this->description().c_str()),
0, NULL, NULL, left_inequality, right_inequality));
for(std::pair<Variable*, Coefficient> pair : this->_lhs){
SCIP_CALL_ABORT( SCIPaddCoefLinear(scip, cons, variable_lookup.find(pair.first)->second, pair.second.value()));
}
return cons;
}
std::ostream& operator<<(std::ostream& os, Constraint& constraint){
os << constraint.description() << ":\t";
bool empty = true;
......
......@@ -3,29 +3,34 @@
#include <cstddef>
#include <string>
#include <map>
#include <cstring>
#include <unordered_map>
#include <iostream>
#include <cmath>
#include "Variable.h"
#include "Coefficient.h"
#include <scip/cons_linear.h>
enum relation : bool {Inequality = false, Equality = true};
class Constraint{
std::string _description;
relation _relation;
std::map<Variable*, Coefficient> _lhs;
std::unordered_map<Variable*, Coefficient> _lhs;
Coefficient _rhs;
public:
Constraint(std::string description, relation relation_type, std::map<Variable*, Coefficient> lhs, Coefficient rhs);
Constraint(relation relation_type, std::map<Variable*, Coefficient> lhs, Coefficient rhs);
Constraint(std::string description, relation relation_type, std::unordered_map<Variable*, Coefficient> lhs, Coefficient rhs);
Constraint(relation relation_type, std::unordered_map<Variable*, Coefficient> lhs, Coefficient rhs);
std::string description();
relation is_equality();
std::map<Variable*, Coefficient> lhs();
std::unordered_map<Variable*, Coefficient> lhs();
Coefficient lhs_coefficient(Variable* var);
Coefficient rhs();
SCIP_CONS* computational_con(SCIP* scip, std::unordered_map<Variable*, SCIP_VAR*>& variable_lookup);
};
std::ostream& operator<<(std::ostream& os, Constraint& constraint);
......
......@@ -10,14 +10,19 @@ Linear_Program::Linear_Program(Linear_Program&& lp){
Linear_Program::Linear_Program(bool maximum) : _maximum(maximum) {}
Linear_Program::Linear_Program(bool maximum, std::map<Variable*, Coefficient> direction, Polyeder polyeder)
Linear_Program::Linear_Program(bool maximum, std::unordered_map<Variable*, Coefficient> direction, Polyeder polyeder)
: _maximum(std::move(maximum)), _direction(std::move(direction)), _polyeder(std::move(polyeder)) {}
std::string Linear_Program::description(){
// TODO: implement names
return "";
}
bool Linear_Program::is_maximum(){
return this->_maximum;
}
std::map<Variable*, Coefficient> Linear_Program::direction(){
std::unordered_map<Variable*, Coefficient> Linear_Program::direction(){
return this->_direction;
}
......@@ -35,15 +40,35 @@ Polyeder& Linear_Program::polyeder(){
return this->_polyeder;
}
void Linear_Program::solve(){
std::stringstream path;
path << "./.data/.cache/" << this << ".lp";
std::ofstream ofs(path.str());
ofs << "solving:\n" << *this << std::endl;
SCIP* Linear_Program::computational_model(){
SCIP* scip;
SCIPcreate(&scip);
SCIPincludeDefaultPlugins(scip);
SCIPcreateProb(scip, this->description().c_str(), NULL, NULL,
NULL, NULL, NULL, NULL, NULL);
if(this->is_maximum()){
SCIPsetObjsense(scip, SCIP_OBJSENSE_MAXIMIZE);
}else{
SCIPsetObjsense(scip, SCIP_OBJSENSE_MINIMIZE);
}
std::cout << "generating variables" << std::endl;
std::unordered_map<Variable*, SCIP_VAR*> variable_lookup;
for(auto pair : this->_polyeder.variables()){
auto search = this->_direction.find(pair.left);
SCIP_VAR* computational_var = pair.left->computational_var(scip, (search != this->_direction.end() ? search->second.value() : 0));
variable_lookup.insert({pair.left, computational_var});
SCIPaddVar(scip, computational_var);
}
std::cout << "generating constraints" << std::endl;
for(Constraint con : this->_polyeder.constraints()){
SCIP_CONS* computational_con = con.computational_con(scip, variable_lookup);
SCIPaddCons(scip, computational_con);
}
std::stringstream command;
command << "scip -c \"read " << path.str() << " optimize quit \"";
system(command.str().c_str());
return scip;
}
void Linear_Program::operator=(Linear_Program& lp){
......@@ -76,7 +101,7 @@ Linear_Program Linear_Program::relaxation_dual(){
}
} variables;
std::map<Variable*, Coefficient> direction;
std::unordered_map<Variable*, Coefficient> direction;
for(size_t index = 0; index < this->polyeder().number_of_constraints(); ++index){
std::stringstream name;
......@@ -93,7 +118,7 @@ Linear_Program Linear_Program::relaxation_dual(){
// we introduce one constraint per primal variable
for(auto curr_variable : this->polyeder().variables()){
// gather lhs_coefficient
std::map<Variable*, Coefficient> lhs;
std::unordered_map<Variable*, Coefficient> lhs;
for(size_t index = 0; index < this->polyeder().number_of_constraints(); ++index){
lhs.insert({variables.unwrap().right.find(index)->second, {-this->polyeder().constraint(index).lhs_coefficient(curr_variable.left)}});
}
......
......@@ -2,7 +2,7 @@
#define LINEAR_PROGRAM_H
#include <cstddef>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
#include <sstream>
......@@ -11,27 +11,31 @@
#include <cstdlib>
#include <boost/bimap.hpp>
#include <scip/scip.h>
#include <scip/scipdefplugins.h>
#include "Polyeder.h"
#include "../Common/integrality.h"
class Linear_Program{
bool _maximum;
std::map<Variable*, Coefficient> _direction;
std::unordered_map<Variable*, Coefficient> _direction;
Polyeder _polyeder;
public:
Linear_Program(Linear_Program& lp);
Linear_Program(Linear_Program&& lp);
Linear_Program(bool maximum);
Linear_Program(bool maximum, std::map<Variable*, Coefficient> direction, Polyeder polyeder);
Linear_Program(bool maximum, std::unordered_map<Variable*, Coefficient> direction, Polyeder polyeder);
std::string description();
bool is_maximum();
std::map<Variable*, Coefficient> direction();
std::unordered_map<Variable*, Coefficient> direction();
void add_direction_coefficient(std::pair<Variable*, Coefficient> summand);
Coefficient direction_coefficient(Variable* index);
Polyeder& polyeder();
void solve();
SCIP* computational_model();
void operator=(Linear_Program& lp);
void operator=(Linear_Program&& lp);
......
......@@ -4,6 +4,14 @@ Monomial::Monomial(const Monomial& other) : _vars(other._vars) {}
Monomial::Monomial(std::set<Variable*> vars) : _vars(vars) {}
double Monomial::value(){
double curr = 1;
for(Variable* var : this->_vars){
curr *= var->value();
}
return curr;
}
bool Monomial::less::operator()(const Monomial a, const Monomial b) const {
std::stringstream key_a;
for(auto var_ptr : a._vars){
......
......@@ -12,6 +12,9 @@ public:
Monomial(const Monomial& other);
Monomial(std::set<Variable*> vars = {});
double value();
class less{
public:
bool operator()(const Monomial a, const Monomial b) const;
......
......@@ -99,9 +99,9 @@ std::ostream& operator<<(std::ostream& os, Polyeder& polyeder){
}
}
os << "General\n";
for(size_t index = 0; index < polyeder.vs_dim(); ++index){
if(polyeder.variable(index).is_integral() == Integral){
os << polyeder.variable_identifier(index) << " ";
for(auto var : polyeder._variables){
if(var.left->is_integral() == Integral){
os << var.left->description() << " ";
}
}
return os;
......
......@@ -28,6 +28,22 @@ std::pair<bool, double> Variable::upper_bound(){
return this->_upper_bound;
}
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;
}
bool Variable::is_fixed(){
return this->_fixed;
......@@ -38,6 +54,14 @@ double& Variable::value(){
return this->_value;
}
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;
}
std::ostream& operator<<(std::ostream& os, Variable& var){
if(var.is_fixed()){
os << var.value();
......
......@@ -2,9 +2,12 @@
#define VARIABLE_H
#include <string>
#include <cstring>
#include <iostream>
#include <cassert>
#include <scip/scip.h>
#include "../Common/integrality.h"
......@@ -27,9 +30,14 @@ public:
std::pair<bool, double> lower_bound();
std::pair<bool, double> upper_bound();
SCIP_Real computational_lower_bound(SCIP* scip);
SCIP_Real computational_upper_bound(SCIP* scip);
bool is_fixed();
double& value();
SCIP_VAR* computational_var(SCIP* scip, double direction_coefficient = 0);
static bool VERBOSE_IDENT;
};
......
#include "lp_generator.h"
std::map<Variable*, Coefficient> lp_generator::lhs_from_data(
std::unordered_map<Variable*, Coefficient> lp_generator::lhs_from_data(
lhs_constraint_data& data,
const std::map<
......@@ -13,7 +13,7 @@ std::map<Variable*, Coefficient> lp_generator::lhs_from_data(
std::pair<Variable*, size_t>
>& node_variable_lookup
){
std::map<Variable*, Coefficient> lhs;
std::unordered_map<Variable*, Coefficient> lhs;
for(std::pair<std::pair<Node*, std::string>, double> w : data.first){
auto search_result = node_variable_lookup.find(w.first);
......
......@@ -6,6 +6,7 @@
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <functional>
#include "../Linear_Programming/Linear_Program.h"
......@@ -47,7 +48,7 @@ std::function<
>;
class lp_generator{
static std::map<Variable*, Coefficient> lhs_from_data(
static std::unordered_map<Variable*, Coefficient> lhs_from_data(
lhs_constraint_data& data,
const std::map<
......
......@@ -13,7 +13,7 @@ LP_PROBLEMS_OUT := $(patsubst %.cpp,%.o,$(shell find -wholename "./Specializatio
COMMON_OUT := $(patsubst %.cpp,%.o,$(shell find -wholename "./Common_Types/*.cpp"))
all: graph_test ass_test linear_program_test maintenance_problem_test
all: graph_test ass_test linear_program_test maintenance_problem_test benders_test
OUTS :=
......@@ -37,17 +37,24 @@ ass_test.o: assertion_test.cpp $(GRAPH_DEP) $(COMMON_DEP)
# Linear Program Test
linear_program_test: linear_program_test.o $(LP_OUT)
linear_program_test: linear_program_test.o $(LP_OUT) /usr/local/lib/libscip.so.7.0.2.0
$(CXX) $(CXXFLAGS) $^ -o $@
linear_program_test.o: linear_programming_test.cpp ./Linear_Programming/Linear_Program.o
$(CXX) $(CXXFLAGS) -c $< -o $@
maintenance_problem_test: maintenance_problem_test.o $(LP_PROBLEMS_OUT) $(LP_OUT) $(GRAPH_OUT) Linear_Programming/lp_generator.o
maintenance_problem_test: maintenance_problem_test.o $(LP_PROBLEMS_OUT) $(LP_OUT) $(GRAPH_OUT) Linear_Programming/lp_generator.o /usr/local/lib/libscip.so.7.0.2.0
$(CXX) $(CXXFLAGS) $^ -o $@
maintenance_problem_test.o: maintenance_problem_test.cpp ./Specialization/LP_Problems/maintenance_problem_generator.o $(GRAPH_DEP) $(COMMON_DEP) $(LP_DEP) $(LP_PROBLEMS_DEP)
maintenance_problem_test.o: maintenance_problem_test.cpp ./Specialization/LP_Problems/Maintenance_Problem/maintenance_problem_generator.o $(GRAPH_DEP) $(COMMON_DEP) $(LP_DEP) $(LP_PROBLEMS_DEP)
$(CXX) $(CXXFLAGS) -c $< -o $@
benders_test: benders_test.o /usr/local/lib/libscip.so.7.0.2.0
$(CXX) $(CXXFLAGS) $^ -o $@
benders_test.o: benders_test.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
# Linear Programming Folder Object Files
......
#include "Maintenance_Problem.h"
Maintenance_Problem::Maintenance_Problem() : Linear_Program(true), _g({{"Flow", Attribute(max, 0)},{"Upper", Attribute(fix, 1)}, {"Selected", Attribute(fix, 0)}}) {
Maintenance_Problem::Maintenance_Problem() : Linear_Program(true), _number_of_epochs(0), _g({{"Flow", Attribute(max, 0)},{"Upper", Attribute(fix, 1)}, {"Selected", Attribute(fix, 0)}}) {
}
Maintenance_Problem::Maintenance_Problem(Maintenance_Problem& mp) : Linear_Program(mp), _g(mp._g) {
Maintenance_Problem::Maintenance_Problem(Maintenance_Problem& mp) : Linear_Program(mp), _number_of_epochs(mp._number_of_epochs), _g(mp._g) {
mp._g = Graph();
}
Maintenance_Problem::Maintenance_Problem(Maintenance_Problem&& mp) : Linear_Program(std::move(mp)), _g(std::move(mp._g)) {
Maintenance_Problem::Maintenance_Problem(Maintenance_Problem&& mp) : Linear_Program(std::move(mp)), _number_of_epochs(std::move(mp._number_of_epochs)), _g(std::move(mp._g)) {
mp._g = Graph();
}
Maintenance_Problem::Maintenance_Problem(