Skip to content

Commit

Permalink
Multi-obj: SCIP, GCG #239
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed May 28, 2024
1 parent 0569606 commit 085d8d0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
3 changes: 1 addition & 2 deletions solvers/gcgmp/gcgmpcommon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ SCIP_DECL_PROBDELORIG(probdataDelOrigNl)
int i;

assert((*probdata)->vars != NULL || (*probdata)->nvars == 0);
assert((*probdata)->linconss != NULL || (*probdata)->nlinconss == 0);
assert((*probdata)->linconss.size() || (*probdata)->nlinconss == 0);

for( i = 0; i < (*probdata)->nlinconss; ++i )
{
SCIP_CALL( SCIPreleaseCons(scip, &(*probdata)->linconss[i]) );
}
SCIPfreeBlockMemoryArray(scip, &(*probdata)->linconss, (*probdata)->nlinconss);

for( i = 0; i < (*probdata)->nvars; ++i )
{
Expand Down
7 changes: 4 additions & 3 deletions solvers/gcgmp/gcgmpcommon.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef GCGCOMMON_H
#define GCGCOMMON_H

#include <vector>
#include <string>

#include "mp/backend-to-model-api.h"
Expand All @@ -18,9 +19,9 @@ struct SCIP_ProbData
SCIP_VAR** vars; /**< variables in the order given by AMPL */
int nvars; /**< number of variables */

SCIP_CONS** linconss; /**< linear constraints in the order given by AMPL */
int i; /**< shows free slot of linear constraints */
int nlinconss; /**< number of linear constraints */
std::vector<SCIP_CONS*> linconss; /**< linear constraints in the order given by AMPL */
int i = 0; /**< shows free slot of linear constraints */
int nlinconss = 0; /**< number of linear constraints */

gcg::PARTIALDECOMP* decomp; /**< user partialdecomp */
};
Expand Down
8 changes: 6 additions & 2 deletions solvers/gcgmp/gcgmpmodelapi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ namespace mp {
void GcgModelAPI::InitProblemModificationPhase(const FlatModelInfo* flat_model_info) {
// Allocate storage if needed:
int n_linear_cons = flat_model_info->GetNumberOfConstraintsOfGroup(CG_Linear);
if (getPROBDATA()->nlinconss)
GCG_CCALL( SCIPfreeTransform(getSCIP()) ); // allow model update
getPROBDATA()->nlinconss = n_linear_cons;
getPROBDATA()->i = 0;
GCG_CCALL( SCIPallocBlockMemoryArray(getSCIP(), &getPROBDATA()->linconss, getPROBDATA()->nlinconss) );
getPROBDATA()->linconss.resize(n_linear_cons);
}

void GcgModelAPI::AddVariables(const VarArrayDef& v) {
Expand Down Expand Up @@ -43,6 +44,9 @@ void GcgModelAPI::SetLinearObjective( int iobj, const LinearObjective& lo ) {
GCG_CCALL( SCIPsetObjsense(getSCIP(),
obj::Type::MAX==lo.obj_sense() ? SCIP_OBJSENSE_MAXIMIZE : SCIP_OBJSENSE_MINIMIZE) );
SCIP_VAR** vars = getPROBDATA()->vars;
for (int i = 0; i < getPROBDATA()->nvars; i++) {
GCG_CCALL( SCIPchgVarObj(getSCIP(), vars[i], 0.0) ); // zero out
}
for (int i = 0; i < lo.num_terms(); i++) {
GCG_CCALL( SCIPchgVarObj(getSCIP(), vars[lo.vars()[i]], lo.coefs()[i]) );
}
Expand Down
3 changes: 1 addition & 2 deletions solvers/scipmp/scipmpcommon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ SCIP_DECL_PROBDELORIG(probdataDelOrigNl)
int i;

assert((*probdata)->vars != NULL || (*probdata)->nvars == 0);
assert((*probdata)->linconss != NULL || (*probdata)->nlinconss == 0);
assert((*probdata)->linconss.size() || (*probdata)->nlinconss == 0);

for( i = 0; i < (*probdata)->nlinconss; ++i )
{
SCIP_CALL( SCIPreleaseCons(scip, &(*probdata)->linconss[i]) );
}
SCIPfreeBlockMemoryArray(scip, &(*probdata)->linconss, (*probdata)->nlinconss);

for( i = 0; i < (*probdata)->nvars; ++i )
{
Expand Down
7 changes: 4 additions & 3 deletions solvers/scipmp/scipmpcommon.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef SCIPCOMMON_H
#define SCIPCOMMON_H

#include <vector>
#include <string>

#include "mp/backend-to-model-api.h"
Expand All @@ -16,9 +17,9 @@ struct SCIP_ProbData
SCIP_VAR** vars; /**< variables in the order given by AMPL */
int nvars; /**< number of variables */

SCIP_CONS** linconss; /**< linear constraints in the order given by AMPL */
int i; /**< shows free slot of linear constraints */
int nlinconss; /**< number of linear constraints */
std::vector<SCIP_CONS*> linconss; /**< linear constraints in the order given by AMPL */
int i = 0; /**< shows free slot of linear constraints */
int nlinconss = 0; /**< number of linear constraints */
};

namespace mp {
Expand Down
8 changes: 6 additions & 2 deletions solvers/scipmp/scipmpmodelapi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ namespace mp {
void ScipModelAPI::InitProblemModificationPhase(const FlatModelInfo* flat_model_info) {
// Allocate storage if needed:
int n_linear_cons = flat_model_info->GetNumberOfConstraintsOfGroup(CG_Linear);
if (getPROBDATA()->nlinconss)
SCIP_CCALL( SCIPfreeTransform(getSCIP()) ); // allow model update
getPROBDATA()->nlinconss = n_linear_cons;
getPROBDATA()->i = 0;
SCIP_CCALL( SCIPallocBlockMemoryArray(getSCIP(), &getPROBDATA()->linconss, getPROBDATA()->nlinconss) );
getPROBDATA()->linconss.resize(n_linear_cons);
}

void ScipModelAPI::AddVariables(const VarArrayDef& v) {
Expand Down Expand Up @@ -42,6 +43,9 @@ void ScipModelAPI::SetLinearObjective( int iobj, const LinearObjective& lo ) {
SCIP_CCALL( SCIPsetObjsense(getSCIP(),
obj::Type::MAX==lo.obj_sense() ? SCIP_OBJSENSE_MAXIMIZE : SCIP_OBJSENSE_MINIMIZE) );
SCIP_VAR** vars = getPROBDATA()->vars;
for (int i = 0; i < getPROBDATA()->nvars; i++) {
SCIP_CCALL( SCIPchgVarObj(getSCIP(), vars[i], 0.0) ); // zero out
}
for (int i = 0; i < lo.num_terms(); i++) {
SCIP_CCALL( SCIPchgVarObj(getSCIP(), vars[lo.vars()[i]], lo.coefs()[i]) );
}
Expand Down

0 comments on commit 085d8d0

Please sign in to comment.