Commit 81e3a7cc authored by jonasseidel's avatar jonasseidel
Browse files

stock benders decomp now has proper reference counts set

parent 86abae54
......@@ -194,13 +194,13 @@ std::vector<SCIP*> Maintenance_Problem::all_computational_models(){
*/
// benders
//SCIP* benders_native = nmp_generate_benders(*this);
SCIP* benders_native = nmp_generate_benders(*this);
//SCIP* scip_benders = generate_nmp_bendersdecomp(*this, benders_native, SCIPgetBestSol(benders_native));
// return all models
return {scip_basic/*, scip_semiassign/*, scip_benders/*, benders_native*/};
return {scip_basic/*, scip_semiassign/*, scip_benders/**/, benders_native};
}
void Maintenance_Problem::operator=(const Maintenance_Problem& mp){
......
......@@ -6,12 +6,21 @@ struct SCIP_VarData{
SCIP_VAR** vars_of_repr_edge;
};
SCIP_RETCODE del_vardata_benders(SCIP* scip, SCIP_VAR* var, SCIP_VARDATA** vardata_unpec){
SCIP_VarData** vardata = (SCIP_VarData**) vardata_unpec;
SCIPfreeBlockMemory(scip, vardata);
return SCIP_OKAY;
}
SCIP* nmp_generate_benders(Maintenance_Problem& mp){
// Master Problem:
SCIP* master;
SCIP_CALL_ABORT( SCIPcreate(&master));
SCIP_CALL_ABORT( SCIPincludeDefaultPlugins(master));
SCIP_CALL_ABORT( SCIPcreateProbBasic(master, "-1"));
SCIP_CALL_ABORT( SCIPcreateProbBasic(master, "maintenance_problem_benders"));
SCIP_CALL_ABORT( SCIPsetObjsense(master, SCIP_OBJSENSE_MAXIMIZE));
......@@ -34,9 +43,12 @@ SCIP* nmp_generate_benders(Maintenance_Problem& mp){
SCIP_CALL_ABORT( SCIPaddVar(master, computational_var));
SCIP_CONS* remove;
SCIPcreateConsBasicLinear(master, &remove, "aritficial_bound", 0, NULL, NULL, 0, 5000);
SCIPcreateConsBasicLinear(master, &remove, "aritficial_bound", 0, NULL, NULL, 0, 500000);
SCIPaddCoefLinear(master, remove, computational_var, 1);
SCIPaddCons(master, remove);
SCIPreleaseVar(master, &computational_var);
SCIPreleaseCons(master, &remove);
}
}
......@@ -90,6 +102,9 @@ SCIP* nmp_generate_benders(Maintenance_Problem& mp){
SCIP_CALL_ABORT( SCIPallocBlockMemoryArray(master, &edge_vars, mp.number_of_epochs()));
SCIP_Bool result;
SCIP_CALL_ABORT( SCIPgetConsVars(master, computational_cons, edge_vars, mp.number_of_epochs(), &result));
/*for(int i = 0; i < mp.number_of_epochs(); i++){
SCIP_CALL_ABORT( SCIPcaptureVar(master, edge_vars[i]));
}*/ // We would ordinary capture these variables since they are saved in one anothers vardata, however doing so would create a circular dependence, meaning that non of them would be released ever. We trust that they will continue being valid for the lifetime of our scip instance
assert(result);
// sorting array by epoch
class epoch_relation_extractor{
......@@ -113,7 +128,10 @@ SCIP* nmp_generate_benders(Maintenance_Problem& mp){
curr_var_data->nepochs = mp.number_of_epochs();
curr_var_data->vars_of_repr_edge = edge_vars;
SCIPvarSetData(edge_vars[epoch], curr_var_data);
SCIPvarSetDelorigData(edge_vars[epoch], del_vardata_benders);
}
SCIPreleaseCons(master, &computational_cons);
/*}else if(cons.description().find("non_critical") != std::string::npos){
SCIP_CONS* computational_cons = cons.computational_con(master, mp_variable_lookup);
SCIP_CALL_ABORT( SCIPaddCons(master, computational_cons));*/
......@@ -123,6 +141,15 @@ SCIP* nmp_generate_benders(Maintenance_Problem& mp){
int epoch = std::atoi(cons.description().c_str() + (epoch_parse_index+6));
SCIP_CONS* computational_cons = cons.computational_con(subproblems[epoch], subproblem_variable_lookups[epoch]);
SCIP_CALL_ABORT( SCIPaddCons(subproblems[epoch], computational_cons));
SCIPreleaseCons(subproblems[epoch], &computational_cons);
}
}
for(auto& [var, comp_var] : mp_variable_lookup){
SCIPreleaseVar(master, &comp_var);
}
for(int epoch = 0; epoch < mp.number_of_epochs(); epoch++){
for(auto& [var, comp_var] : subproblem_variable_lookups[epoch]){
SCIPreleaseVar(subproblems[epoch], &comp_var);
}
}
......
......@@ -67,7 +67,7 @@ int main(int argc, char** argv){
ofs_netw.close();
//std::cout << mp << std::endl;
std::cout << "finished write" << std::endl;
system("cd ../display/graph_display/ && (./graph_display --file ../../discrete_optimization_library/.data/Maintenance_Problem/mp.netw &) && cd ../../discrete_optimization_library");
//system("cd ../display/graph_display/ && (./graph_display --file ../../discrete_optimization_library/.data/Maintenance_Problem/mp.netw &) && cd ../../discrete_optimization_library");
std::cout << "generating SCIP model" << std::endl;
std::vector<SCIP*> scips = mp.all_computational_models();
......@@ -77,7 +77,7 @@ int main(int argc, char** argv){
}
for(SCIP* scip : scips){
//SCIPfree(&scip);
SCIPfree(&scip);
//std::cin.ignore();
}
//system("polymake --script .data/Maintenance_Problem/pm_script_lp2facets");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment