Skip to content

Commit 085d8d0

Browse files
committed
Multi-obj: SCIP, GCG #239
1 parent 0569606 commit 085d8d0

File tree

6 files changed

+22
-14
lines changed

6 files changed

+22
-14
lines changed

solvers/gcgmp/gcgmpcommon.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ SCIP_DECL_PROBDELORIG(probdataDelOrigNl)
99
int i;
1010

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

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

2019
for( i = 0; i < (*probdata)->nvars; ++i )
2120
{

solvers/gcgmp/gcgmpcommon.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef GCGCOMMON_H
22
#define GCGCOMMON_H
33

4+
#include <vector>
45
#include <string>
56

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

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

2526
gcg::PARTIALDECOMP* decomp; /**< user partialdecomp */
2627
};

solvers/gcgmp/gcgmpmodelapi.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ namespace mp {
66
void GcgModelAPI::InitProblemModificationPhase(const FlatModelInfo* flat_model_info) {
77
// Allocate storage if needed:
88
int n_linear_cons = flat_model_info->GetNumberOfConstraintsOfGroup(CG_Linear);
9+
if (getPROBDATA()->nlinconss)
10+
GCG_CCALL( SCIPfreeTransform(getSCIP()) ); // allow model update
911
getPROBDATA()->nlinconss = n_linear_cons;
10-
getPROBDATA()->i = 0;
11-
GCG_CCALL( SCIPallocBlockMemoryArray(getSCIP(), &getPROBDATA()->linconss, getPROBDATA()->nlinconss) );
12+
getPROBDATA()->linconss.resize(n_linear_cons);
1213
}
1314

1415
void GcgModelAPI::AddVariables(const VarArrayDef& v) {
@@ -43,6 +44,9 @@ void GcgModelAPI::SetLinearObjective( int iobj, const LinearObjective& lo ) {
4344
GCG_CCALL( SCIPsetObjsense(getSCIP(),
4445
obj::Type::MAX==lo.obj_sense() ? SCIP_OBJSENSE_MAXIMIZE : SCIP_OBJSENSE_MINIMIZE) );
4546
SCIP_VAR** vars = getPROBDATA()->vars;
47+
for (int i = 0; i < getPROBDATA()->nvars; i++) {
48+
GCG_CCALL( SCIPchgVarObj(getSCIP(), vars[i], 0.0) ); // zero out
49+
}
4650
for (int i = 0; i < lo.num_terms(); i++) {
4751
GCG_CCALL( SCIPchgVarObj(getSCIP(), vars[lo.vars()[i]], lo.coefs()[i]) );
4852
}

solvers/scipmp/scipmpcommon.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ SCIP_DECL_PROBDELORIG(probdataDelOrigNl)
77
int i;
88

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

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

1817
for( i = 0; i < (*probdata)->nvars; ++i )
1918
{

solvers/scipmp/scipmpcommon.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef SCIPCOMMON_H
22
#define SCIPCOMMON_H
33

4+
#include <vector>
45
#include <string>
56

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

19-
SCIP_CONS** linconss; /**< linear constraints in the order given by AMPL */
20-
int i; /**< shows free slot of linear constraints */
21-
int nlinconss; /**< number of linear constraints */
20+
std::vector<SCIP_CONS*> linconss; /**< linear constraints in the order given by AMPL */
21+
int i = 0; /**< shows free slot of linear constraints */
22+
int nlinconss = 0; /**< number of linear constraints */
2223
};
2324

2425
namespace mp {

solvers/scipmp/scipmpmodelapi.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ namespace mp {
55
void ScipModelAPI::InitProblemModificationPhase(const FlatModelInfo* flat_model_info) {
66
// Allocate storage if needed:
77
int n_linear_cons = flat_model_info->GetNumberOfConstraintsOfGroup(CG_Linear);
8+
if (getPROBDATA()->nlinconss)
9+
SCIP_CCALL( SCIPfreeTransform(getSCIP()) ); // allow model update
810
getPROBDATA()->nlinconss = n_linear_cons;
9-
getPROBDATA()->i = 0;
10-
SCIP_CCALL( SCIPallocBlockMemoryArray(getSCIP(), &getPROBDATA()->linconss, getPROBDATA()->nlinconss) );
11+
getPROBDATA()->linconss.resize(n_linear_cons);
1112
}
1213

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

0 commit comments

Comments
 (0)