Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add qc feature to dw #243

Merged
merged 3 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ set(DSP_SRC
Solver/DualDecomp/DdWorkerCG.cpp
Solver/DualDecomp/DdWorkerLB.cpp
Solver/DualDecomp/DdWorkerUB.cpp
Solver/DualDecomp/DdWorkerUB2.cpp
Solver/DualDecomp/DdWorkerUBQcp.cpp
Solver/DualDecomp/DdDroWorkerUB.cpp
Solver/DantzigWolfe/DwBranchInt.cpp
Solver/DantzigWolfe/DwBranchNonant.cpp
Expand Down
35 changes: 35 additions & 0 deletions src/Solver/DantzigWolfe/DwWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ DSP_RTN_CODE DwWorker::createSubproblems() {
char* ctype = NULL;
double* rlbd = NULL;
double* rubd = NULL;
QuadRowData *qc_row_core = NULL;
QuadRowData *qc_row_scen = NULL;

BGN_TRY_CATCH

Expand All @@ -142,6 +144,29 @@ DSP_RTN_CODE DwWorker::createSubproblems() {
mat, sub_clbd_[s], sub_cubd_[s], ctype, sub_objs_[s], rlbd, rubd));
for (int j = 0; j < tss->getNumCols(0); ++j)
sub_objs_[s][j] *= tss->getProbability()[parProcIdx_[s]];

/** get quadratic rows data */
if (tss->hasQuadraticRowCore())
{
qc_row_core = tss->getQuaraticsRowCore();

#ifdef DSP_DEBUG
/* print qcrowdata to test whether it is successfully received or not */
cout << "DwSub's quadratic constraints in core: " << endl;
tss->printQuadRows(-1);
tss->printQuadRows(qc_row_core);
#endif
}
if (tss->hasQuadraticRowScenario()) {
qc_row_scen = tss->getQuaraticsRowScenario(s);

#ifdef DSP_DEBUG
/* print qcrowdata to test whether it is successfully received or not */
cout << "DwSub's quadratic constraints in scen: " << endl;
tss->printQuadRows(s);
tss->printQuadRows(qc_row_scen);
#endif
}
} else {
DSP_RTN_CHECK_RTN_CODE(
model_->copySubprob(parProcIdx_[s], mat, sub_clbd_[s], sub_cubd_[s], ctype, sub_objs_[s], rlbd, rubd));
Expand All @@ -162,6 +187,10 @@ DSP_RTN_CODE DwWorker::createSubproblems() {
/** load problem to si */
osi_[s]->si_->loadProblem(*mat, sub_clbd_[s], sub_cubd_[s], sub_objs_[s], rlbd, rubd);

/* add quadratic rows */
if (qc_row_core) osi_[s]->addQuadraticRows(qc_row_core->nqrows, qc_row_core->linnzcnt, qc_row_core->quadnzcnt, qc_row_core->rhs, qc_row_core->sense, qc_row_core->linind, qc_row_core->linval, qc_row_core->quadrow, qc_row_core->quadcol, qc_row_core->quadval);
if (qc_row_scen) osi_[s]->addQuadraticRows(qc_row_scen->nqrows, qc_row_scen->linnzcnt, qc_row_scen->quadnzcnt, qc_row_scen->rhs, qc_row_scen->sense, qc_row_scen->linind, qc_row_scen->linval, qc_row_scen->quadrow, qc_row_scen->quadcol, qc_row_scen->quadval);

/** set integers */
int nintegers = 0;
for (int j = 0; j < osi_[s]->si_->getNumCols(); ++j) {
Expand Down Expand Up @@ -191,6 +220,12 @@ DSP_RTN_CODE DwWorker::createSubproblems() {
sprintf(ofname, "sub%d.mps", parProcIdx_[s]);
DSPdebugMessage("Writing MPS file: %s\n", ofname);
osi_[s]->si_->writeMps(ofname);

/** write lp */
char filename[128];
sprintf(filename, "sub%d.lp", parProcIdx_[s]);
DSPdebugMessage("Writing lp file: %s\n", filename);
osi_[s]->writeProb(filename, "lp");
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/Solver/DantzigWolfe/DwWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DwWorker {
/** generate variables */
virtual DSP_RTN_CODE generateCols(
int phase, /**< [in] phase of the master */
const double* piA, /**< [in] piA */
const double* piA, /**< [in] dual variable times the constraint matrix */
std::vector<int>& indices, /**< [out] subproblem indices */
std::vector<int>& statuses, /**< [out] solution status */
std::vector<double>& cxs, /**< [out] solution times original objective coefficients */
Expand Down
2 changes: 1 addition & 1 deletion src/Solver/DantzigWolfe/DwWorkerMpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DwWorkerMpi: public DwWorker {
/** generate variables */
virtual DSP_RTN_CODE generateCols(
int phase, /**< [in] phase of the master */
const double* piA, /**< [in] piA */
const double* piA, /**< [in] dual variable times the constraint matrix (see DwWorker.h) */
std::vector<int>& indices, /**< [out] subproblem indices */
std::vector<int>& statuses, /**< [out] solution status */
std::vector<double>& cxs, /**< [out] solution times original objective coefficients */
Expand Down
2 changes: 1 addition & 1 deletion src/Solver/DualDecomp/DdMW.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "Solver/DualDecomp/DdWorker.h"
#include "Solver/DualDecomp/DdWorkerLB.h"
#include "Solver/DualDecomp/DdWorkerUB.h"
#include "Solver/DualDecomp/DdWorkerUB2.h"
#include "Solver/DualDecomp/DdWorkerUBQcp.h"
#include "Solver/DualDecomp/DdDroWorkerUB.h"

#ifdef DSP_HAS_SCIP
Expand Down
8 changes: 4 additions & 4 deletions src/Solver/DualDecomp/DdMWSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ DSP_RTN_CODE DdMWSerial::init()
if (model_->isDro())
worker_.push_back(new DdDroWorkerUB(model_, par_, message_));
else if (model_->isQcp())
worker_.push_back(new DdWorkerUB2(model_, par_, message_));
worker_.push_back(new DdWorkerUBQcp(model_, par_, message_));
else
worker_.push_back(new DdWorkerUB(model_, par_, message_));
}
Expand Down Expand Up @@ -196,7 +196,7 @@ DSP_RTN_CODE DdMWSerial::run()
break;
case DdWorker::UB:
if (model_->isQcp())
workerub = dynamic_cast<DdWorkerUB2 *>(worker_[i]);
workerub = dynamic_cast<DdWorkerUBQcp *>(worker_[i]);
else
workerub = dynamic_cast<DdWorkerUB *>(worker_[i]);
break;
Expand Down Expand Up @@ -422,13 +422,13 @@ DSP_RTN_CODE DdMWSerial::run()

if (parEvalUb_ >= 0 && model_->isStochastic())
{
// DdWorkerUB2 *workerub = NULL;
// DdWorkerUBQcp *workerub = NULL;
DdWorkerUB *workerub = NULL;
for (unsigned i = 0; i < worker_.size(); ++i)
if (worker_[i]->getType() == DdWorker::UB)
{
if (model_->isQcp())
workerub = dynamic_cast<DdWorkerUB2 *>(worker_[i]);
workerub = dynamic_cast<DdWorkerUBQcp *>(worker_[i]);
else
workerub = dynamic_cast<DdWorkerUB *>(worker_[i]);
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
* DdWorkerUB.cpp
* DdWorkerUBQcp.cpp
*
* Created on: Mar 28, 2016
* Author: kibaekkim
* Created on: Mar 18, 2022
* Author: geunyeongbyeon
*/

// #define DSP_DEBUG
// #define DSP_DEBUG_WRITE
#include "Model/DecTssModel.h"
#include "Solver/DualDecomp/DdWorkerUB2.h"
#include "Solver/DualDecomp/DdWorkerUBQcp.h"
#include "SolverInterface/DspOsiCpx.h"
#include "SolverInterface/DspOsiGrb.h"
#include "SolverInterface/DspOsiScip.h"
Expand All @@ -17,24 +17,24 @@
#include "Solver/DualDecomp/SCIPconshdlrBendersDd.h"
#endif

DdWorkerUB2::DdWorkerUB2(
DdWorkerUBQcp::DdWorkerUBQcp(
DecModel *model, /**< model pointer */
DspParams *par, /**< parameter pointer */
DspMessage *message /**< message pointer */) : DdWorkerUB(model, par, message)
{
}

DdWorkerUB2::DdWorkerUB2(const DdWorkerUB2 &rhs) : DdWorkerUB(rhs)
DdWorkerUBQcp::DdWorkerUBQcp(const DdWorkerUBQcp &rhs) : DdWorkerUB(rhs)
{}

DdWorkerUB2::~DdWorkerUB2()
DdWorkerUBQcp::~DdWorkerUBQcp()
{
// check whether subprobs_[s] is being deleted
}

DSP_RTN_CODE DdWorkerUB2::init()
DSP_RTN_CODE DdWorkerUBQcp::init()
{
DSPdebugMessage("initiating DdWorkerUB2\n");
DSPdebugMessage("initiating DdWorkerUBQcp\n");
BGN_TRY_CATCH
/** status */
status_ = DSP_STAT_MW_CONTINUE;
Expand Down Expand Up @@ -85,7 +85,7 @@ DSP_RTN_CODE DdWorkerUB2::init()
{
/* write in lp file */
char filename[128];
sprintf(filename, "DdWorkerUB2_scen%d", s);
sprintf(filename, "DdWorkerUBQcp_scen%d", s);
DSPdebugMessage("writing initial upper bound subproblem for scenario %d in %s.lp\n", s, filename);
subprobs_[s]->getDspOsiPtr()->writeProb(filename, "lp");
}
Expand All @@ -94,7 +94,7 @@ DSP_RTN_CODE DdWorkerUB2::init()
return DSP_RTN_OK;
}

DSP_RTN_CODE DdWorkerUB2::createProblem(int nsubprobs, int* subindex)
DSP_RTN_CODE DdWorkerUBQcp::createProblem(int nsubprobs, int* subindex)
{
BGN_TRY_CATCH

Expand All @@ -121,7 +121,7 @@ BGN_TRY_CATCH
}


double DdWorkerUB2::evaluate(int n, double *solution)
double DdWorkerUBQcp::evaluate(int n, double *solution)
{
std::vector<int> indices;
std::vector<double> elements;
Expand All @@ -140,7 +140,7 @@ double DdWorkerUB2::evaluate(int n, double *solution)
return ub;
}

double DdWorkerUB2::evaluate(CoinPackedVector *solution)
double DdWorkerUBQcp::evaluate(CoinPackedVector *solution)
{
#define FREE_MEMORY \
FREE_ARRAY_PTR(indices) \
Expand Down Expand Up @@ -213,7 +213,7 @@ double DdWorkerUB2::evaluate(CoinPackedVector *solution)
}


DSP_RTN_CODE DdWorkerUB2::solve()
DSP_RTN_CODE DdWorkerUBQcp::solve()
{
double cputime;
double walltime;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*
* DdWorkerUB2.h
* DdWorkerUBQcp.h
*
* Created on: Mar 18, 2022
* Author: geunyeongbyeon
*/

#ifndef SRC_SOLVER_DUALDECOMP_DDWORKERUB2_H_
#define SRC_SOLVER_DUALDECOMP_DDWORKERUB2_H_
#ifndef SRC_SOLVER_DUALDECOMP_DDWORKERUBQCP_H_
#define SRC_SOLVER_DUALDECOMP_DDWORKERUBQCP_H_

// #include "Solver/DualDecomp/DdWorker.h"
#include "Solver/DualDecomp/DdWorkerUB.h"
#include "Solver/DualDecomp/DdSub.h"

/** A worker class for solving upper bounding subproblems. */
class DdWorkerUB2: public DdWorkerUB {
class DdWorkerUBQcp: public DdWorkerUB {

friend class DdMWSerial;
friend class DdMWSync;
Expand All @@ -22,20 +22,20 @@ class DdWorkerUB2: public DdWorkerUB {
public:

/** A default constructor. */
DdWorkerUB2(
DdWorkerUBQcp(
DecModel * model, /**< model pointer */
DspParams * par, /**< parameter pointer */
DspMessage * message /**< message pointer */);

/** A copy constructor. */
DdWorkerUB2(const DdWorkerUB2& rhs);
DdWorkerUBQcp(const DdWorkerUBQcp& rhs);

/** A default destructor. */
virtual ~DdWorkerUB2();
virtual ~DdWorkerUBQcp();

/** A clone function */
virtual DdWorkerUB2* clone() const {
return new DdWorkerUB2(*this);
virtual DdWorkerUBQcp* clone() const {
return new DdWorkerUBQcp(*this);
}

/** A virtual member for initializing solver. */
Expand All @@ -62,4 +62,4 @@ class DdWorkerUB2: public DdWorkerUB {
vector<DdSub*> subprobs_; /**< set of subproblems */
};

#endif /* SRC_SOLVER_DUALDECOMP_DDWORKERUB2_H_ */
#endif /* SRC_SOLVER_DUALDECOMP_DDWORKERUBQCP_H_ */
2 changes: 1 addition & 1 deletion src/dsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ int runDsp(char *algotype, char *smpsfile, char *mpsfile, char *decfile, char *s

if (quadfile != NULL)
{
if (string(algotype) != "de" && string(algotype) != "dd" && string(algotype) != "drdd")
if (string(algotype) != "de" && string(algotype) != "dd" && string(algotype) != "drdd" && string(algotype) != "dw")
{
cout << "Quadratic constrained problem is not supported for " << string(algotype) << "." << endl;
return 1;
Expand Down