Commit cffefd9c by jonasseidel

### computational models bulk commit

parent 5b3c57cc
 use application "polytope"; use application "polytope"; my \$import = lp2poly(".data/Maintenance_Problem/mp.lp"); declare \$import = lp2poly(".data/Maintenance_Problem/mp.lp"); #print "\n\n---------------------------------------------------------------------------------------------------------\n"; #print "\n\n---------------------------------------------------------------------------------------------------------\n"; #print "Extreme points relaxed polyeder:\n\n"; #print "Extreme points relaxed polyeder:\n\n"; ... @@ -64,13 +64,14 @@ for (@\$integral_indexes) { ... @@ -64,13 +64,14 @@ for (@\$integral_indexes) { #print "@\$restr_labels\n"; #print "@\$restr_labels\n"; # calculating the wanted data: # calculating the wanted data: #print "Mixed Integer Convex Hull:\n"; #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; #\$mint_hull->COORDINATE_LABELS = \$import->COORDINATE_LABELS; #print_constraints(\$mint_hull); #print_constraints(\$mint_hull); print "Integral Coordinate Projection Convex Hull\n"; print "Integral Coordinate Projection Convex Hull\n"; my \$proj = projection(\$import, \$integral_indexes); declare \$proj = projection(\$import, \$integral_indexes); my \$proj_hull = integer_hull(\$proj); \$proj->COORDINATE_LABELS = \$restr_labels; declare \$proj_hull = integer_hull(\$proj); \$proj_hull->COORDINATE_LABELS = \$restr_labels; \$proj_hull->COORDINATE_LABELS = \$restr_labels; print_constraints(\$proj_hull); 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
 class Generic_Tester{
 ... @@ -7,7 +7,7 @@ random_attribute_generator::random_attribute_generator( ... @@ -7,7 +7,7 @@ random_attribute_generator::random_attribute_generator( > data > data ){ ){ for(std::pair > pair : data){ for(std::pair > 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 constr_data = {std::get<0>(pair.second), std::get<1>(pair.second)}; std::pair constr_data = {std::get<0>(pair.second), std::get<1>(pair.second)}; this->_constr_data.insert({pair.first, constr_data}); this->_constr_data.insert({pair.first, constr_data}); ... ...
 ... @@ -220,7 +220,7 @@ std::pair, std::vector>> random_graph_ ... @@ -220,7 +220,7 @@ std::pair, std::vector>> random_graph_ Node* n1; Node* n1; Node* n2; 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 for(size_t i = 0; i < edges_to_be_added; ++i){ // the last step does not get any edges size_t attempt = 0; size_t attempt = 0; redo: redo: ... ...
 ... @@ -74,8 +74,10 @@ void Graph::conditional_bfs_all_components( ... @@ -74,8 +74,10 @@ void Graph::conditional_bfs_all_components( node_exec will be called with nullptr for via for start node 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 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 uncharted = this->nodes(); std::set uncharted = this->nodes(); std::deque> active; std::deque> active; for(Node* node : starting_nodes){ for(Node* node : starting_nodes){ ... @@ -92,7 +94,6 @@ void Graph::conditional_bfs_all_components( ... @@ -92,7 +94,6 @@ void Graph::conditional_bfs_all_components( bool local_all_paths = node_exec(next.first, next.second); bool local_all_paths = node_exec(next.first, next.second); Node* n = next.second; Node* n = next.second; uncharted.erase(n); for(Edge* e : n->incident()){ for(Edge* e : n->incident()){ bool used_in_traversal = false; bool used_in_traversal = false; ... @@ -102,6 +103,7 @@ void Graph::conditional_bfs_all_components( ... @@ -102,6 +103,7 @@ void Graph::conditional_bfs_all_components( used_in_traversal = true; used_in_traversal = true; active.push_back({e, e->to(n)}); active.push_back({e, e->to(n)}); uncharted.erase(e->to(n)); } } edge_exec(n, e, used_in_traversal); edge_exec(n, e, used_in_traversal); ... ...
 ... @@ -33,6 +33,16 @@ bool Coefficient::is_unity(){ ... @@ -33,6 +33,16 @@ bool Coefficient::is_unity(){ return true; return true; } } double Coefficient::value(){ double curr = 0; for(std::pair pair : this->_coeff){ curr += pair.second*pair.first.value(); } return curr; } // Coefficient operator+(double val, Coefficient coeff){ // Coefficient operator+(double val, Coefficient coeff){ // Coefficient tmp (coeff); // Coefficient tmp (coeff); // // ... ...
 #include "Constraint.h" #include "Constraint.h" Constraint::Constraint(std::string description, relation relation_type, std::map lhs, Coefficient rhs) Constraint::Constraint(std::string description, relation relation_type, std::unordered_map lhs, Coefficient rhs) : _description(description), _relation(relation_type), _lhs(lhs), _rhs(rhs){} : _description(description), _relation(relation_type), _lhs(lhs), _rhs(rhs){} Constraint::Constraint(relation relation_type, std::map lhs, Coefficient rhs) Constraint::Constraint(relation relation_type, std::unordered_map lhs, Coefficient rhs) : _relation(relation_type), _lhs(lhs), _rhs(rhs){} : _relation(relation_type), _lhs(lhs), _rhs(rhs){} std::string Constraint::description(){ std::string Constraint::description(){ ... @@ -14,7 +14,7 @@ relation Constraint::is_equality(){ ... @@ -14,7 +14,7 @@ relation Constraint::is_equality(){ return this->_relation; return this->_relation; } } std::map Constraint::lhs(){ std::unordered_map Constraint::lhs(){ return this->_lhs; return this->_lhs; } } ... @@ -30,6 +30,20 @@ Coefficient Constraint::rhs(){ ... @@ -30,6 +30,20 @@ Coefficient Constraint::rhs(){ return this->_rhs; return this->_rhs; } } SCIP_CONS* Constraint::computational_con(SCIP* scip, std::unordered_map& 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 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){ std::ostream& operator<<(std::ostream& os, Constraint& constraint){ os << constraint.description() << ":\t"; os << constraint.description() << ":\t"; bool empty = true; bool empty = true; ... ...
 ... @@ -3,29 +3,34 @@ ... @@ -3,29 +3,34 @@ #include #include #include #include #include #include #include #include #include #include #include #include "Variable.h" #include "Variable.h" #include "Coefficient.h" #include "Coefficient.h" #include enum relation : bool {Inequality = false, Equality = true}; enum relation : bool {Inequality = false, Equality = true}; class Constraint{ class Constraint{ std::string _description; std::string _description; relation _relation; relation _relation; std::map _lhs; std::unordered_map _lhs; Coefficient _rhs; Coefficient _rhs; public: public: Constraint(std::string description, relation relation_type, std::map lhs, Coefficient rhs); Constraint(std::string description, relation relation_type, std::unordered_map lhs, Coefficient rhs); Constraint(relation relation_type, std::map lhs, Coefficient rhs); Constraint(relation relation_type, std::unordered_map lhs, Coefficient rhs); std::string description(); std::string description(); relation is_equality(); relation is_equality(); std::map lhs(); std::unordered_map lhs(); Coefficient lhs_coefficient(Variable* var); Coefficient lhs_coefficient(Variable* var); Coefficient rhs(); Coefficient rhs(); SCIP_CONS* computational_con(SCIP* scip, std::unordered_map& variable_lookup); }; }; std::ostream& operator<<(std::ostream& os, Constraint& constraint); std::ostream& operator<<(std::ostream& os, Constraint& constraint); ... ...
 ... @@ -10,14 +10,19 @@ Linear_Program::Linear_Program(Linear_Program&& lp){ ... @@ -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) : _maximum(maximum) {} Linear_Program::Linear_Program(bool maximum, std::map direction, Polyeder polyeder) Linear_Program::Linear_Program(bool maximum, std::unordered_map direction, Polyeder polyeder) : _maximum(std::move(maximum)), _direction(std::move(direction)), _polyeder(std::move(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(){ bool Linear_Program::is_maximum(){ return this->_maximum; return this->_maximum; } } std::map Linear_Program::direction(){ std::unordered_map Linear_Program::direction(){ return this->_direction; return this->_direction; } } ... @@ -35,15 +40,35 @@ Polyeder& Linear_Program::polyeder(){ ... @@ -35,15 +40,35 @@ Polyeder& Linear_Program::polyeder(){ return this->_polyeder; return this->_polyeder; } } void Linear_Program::solve(){ SCIP* Linear_Program::computational_model(){ std::stringstream path; SCIP* scip; path << "./.data/.cache/" << this << ".lp"; SCIPcreate(&scip); std::ofstream ofs(path.str()); SCIPincludeDefaultPlugins(scip); ofs << "solving:\n" << *this << std::endl; 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_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; return scip; command << "scip -c \"read " << path.str() << " optimize quit \""; system(command.str().c_str()); } } void Linear_Program::operator=(Linear_Program& lp){ void Linear_Program::operator=(Linear_Program& lp){ ... @@ -76,7 +101,7 @@ Linear_Program Linear_Program::relaxation_dual(){ ... @@ -76,7 +101,7 @@ Linear_Program Linear_Program::relaxation_dual(){ } } } variables; } variables; std::map direction; std::unordered_map direction; for(size_t index = 0; index < this->polyeder().number_of_constraints(); ++index){ for(size_t index = 0; index < this->polyeder().number_of_constraints(); ++index){ std::stringstream name; std::stringstream name; ... @@ -93,7 +118,7 @@ Linear_Program Linear_Program::relaxation_dual(){ ... @@ -93,7 +118,7 @@ Linear_Program Linear_Program::relaxation_dual(){ // we introduce one constraint per primal variable // we introduce one constraint per primal variable for(auto curr_variable : this->polyeder().variables()){ for(auto curr_variable : this->polyeder().variables()){ // gather lhs_coefficient // gather lhs_coefficient std::map lhs; std::unordered_map lhs; for(size_t index = 0; index < this->polyeder().number_of_constraints(); ++index){ 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)}}); lhs.insert({variables.unwrap().right.find(index)->second, {-this->polyeder().constraint(index).lhs_coefficient(curr_variable.left)}}); } } ... ...
 ... @@ -2,7 +2,7 @@ ... @@ -2,7 +2,7 @@ #define LINEAR_PROGRAM_H #define LINEAR_PROGRAM_H #include #include #include #include #include #include #include #include #include #include ... @@ -11,27 +11,31 @@ ... @@ -11,27 +11,31 @@ #include #include #include #include #include #include #include "Polyeder.h" #include "Polyeder.h" #include "../Common/integrality.h" #include "../Common/integrality.h" class Linear_Program{ class Linear_Program{ bool _maximum; bool _maximum; std::map _direction; std::unordered_map _direction; Polyeder _polyeder; Polyeder _polyeder; public: public: Linear_Program(Linear_Program& lp); Linear_Program(Linear_Program& lp); Linear_Program(Linear_Program&& lp); Linear_Program(Linear_Program&& lp); Linear_Program(bool maximum); Linear_Program(bool maximum); Linear_Program(bool maximum, std::map direction, Polyeder polyeder); Linear_Program(bool maximum, std::unordered_map direction, Polyeder polyeder); std::string description(); bool is_maximum(); bool is_maximum(); std::map direction(); std::unordered_map direction(); void add_direction_coefficient(std::pair summand); void add_direction_coefficient(std::pair summand); Coefficient direction_coefficient(Variable* index); Coefficient direction_coefficient(Variable* index); Polyeder& polyeder(); Polyeder& polyeder(); void solve(); SCIP* computational_model(); void operator=(Linear_Program& lp); void operator=(Linear_Program& lp); void operator=(Linear_Program&& lp); void operator=(Linear_Program&& lp); ... ...
 ... @@ -4,6 +4,14 @@ Monomial::Monomial(const Monomial& other) : _vars(other._vars) {} ... @@ -4,6 +4,14 @@ Monomial::Monomial(const Monomial& other) : _vars(other._vars) {} Monomial::Monomial(std::set vars) : _vars(vars) {} Monomial::Monomial(std::set 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 { bool Monomial::less::operator()(const Monomial a, const Monomial b) const { std::stringstream key_a; std::stringstream key_a; for(auto var_ptr : a._vars){ for(auto var_ptr : a._vars){ ... ...
 ... @@ -12,6 +12,9 @@ public: ... @@ -12,6 +12,9 @@ public: Monomial(const Monomial& other); Monomial(const Monomial& other); Monomial(std::set vars = {}); Monomial(std::set vars = {}); double value(); class less{ class less{ public: public: bool operator()(const Monomial a, const Monomial b) const; bool operator()(const Monomial a, const Monomial b) const; ... ...
 ... @@ -99,9 +99,9 @@ std::ostream& operator<<(std::ostream& os, Polyeder& polyeder){ ... @@ -99,9 +99,9 @@ std::ostream& operator<<(std::ostream& os, Polyeder& polyeder){ } } } } os << "General\n"; os << "General\n"; for(size_t index = 0; index < polyeder.vs_dim(); ++index){ for(auto var : polyeder._variables){ if(polyeder.variable(index).is_integral() == Integral){ if(var.left->is_integral() == Integral){ os << polyeder.variable_identifier(index) << " "; os << var.left->description() << " "; } } } } return os; return os; ... ...
 ... @@ -28,6 +28,22 @@ std::pair Variable::upper_bound(){ ... @@ -28,6 +28,22 @@ std::pair Variable::upper_bound(){ return this->_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(){ bool Variable::is_fixed(){ return this->_fixed;