From ef2d3a56c533a615ee9fb38d3771a56918f5ed62 Mon Sep 17 00:00:00 2001 From: "A380-N-9025E0\\Tilk" <christian.tilk@univie.ac.at> Date: Thu, 27 Jul 2023 16:21:27 +0200 Subject: [PATCH] changes for new cplex version + code compatible to current c++ standard (what a mess...) --- ColumnGeneration/base.h | 6 +- ColumnGeneration/cplexcpp.cpp | 1976 +++++++++++++++------------------ ColumnGeneration/cplexcpp.h | 594 +++++----- bcp_cvrptw.cpp | 214 ++-- cvrptw_instance.cpp | 54 +- cvrptw_ref.cpp | 26 +- data.h | 4 +- espprc/solver.h | 3 +- main.cpp | 2 +- 9 files changed, 1332 insertions(+), 1547 deletions(-) diff --git a/ColumnGeneration/base.h b/ColumnGeneration/base.h index c386cbf..29dbfb9 100644 --- a/ColumnGeneration/base.h +++ b/ColumnGeneration/base.h @@ -365,9 +365,9 @@ public: int GetMinPricingStartLevel(){ int minPricingLevel = pricing_levels_in_hierarchies[0]; - for each( int l in pricing_levels_in_hierarchies ){ - if( l < minPricingLevel ){ - minPricingLevel = l; + for (auto l= pricing_levels_in_hierarchies.begin();l!= pricing_levels_in_hierarchies.end();l++){ + if( *l < minPricingLevel ){ + minPricingLevel = *l; } } return minPricingLevel; diff --git a/ColumnGeneration/cplexcpp.cpp b/ColumnGeneration/cplexcpp.cpp index bce3f88..08f5de4 100644 --- a/ColumnGeneration/cplexcpp.cpp +++ b/ColumnGeneration/cplexcpp.cpp @@ -1,14 +1,9 @@ // Implementation of an example C++ class library for CPLEX -#define _CPLEX_12dot6_x64 1 - -#pragma warning( disable: 4786 ) - #include "cplexcpp.h" #include <sstream> #include <ostream> #include <set> -#include <iostream> namespace CGBase { @@ -20,1266 +15,1043 @@ namespace CGBase if (env_ == NULL) throw CPLEXException(env_, status, (char*)"CPXopenCPLEX"); } -CPLEXEnvironment::~CPLEXEnvironment () -{ -int status = 0; - - status = CPXcloseCPLEX (&env_); - if ( status ) { - throw CPLEXException (env_, status, "CPXcloseCPLEX"); - } -} - -void -CPLEXEnvironment::setparam (int paramnum, int value) -{ -int status = CPXsetintparam (env_, paramnum, value); - - if ( status ) { - throw CPLEXException (env_, status, "CPXsetintparam"); - } -} - -void -CPLEXEnvironment::setparam (int paramnum, double value) -{ -int status = CPXsetdblparam (env_, paramnum, value); - - if ( status ) { - throw CPLEXException (env_, status, "CPXsetdblparam"); - } -} - -void -CPLEXEnvironment::setdefaults () -{ - int status = CPXsetdefaults (env_); - - if ( status ) - throw CPLEXException (env_, status, "CPXsetdefaults"); -} - -void -CPLEXEnvironment::getParam (int paramnum, int& rvalue) const -{ -int value; -int status = CPXgetintparam (env_, paramnum, &value); - - if ( status ) { - throw CPLEXException (env_, status, "CPXgetintparam"); - } - rvalue = value; -} - -void -CPLEXEnvironment::getParam (int paramnum, double& rvalue) const -{ -double value; -int status = CPXgetdblparam (env_, paramnum, &value); - - if ( status ) { - throw CPLEXException (env_, status, "CPXsetdblparam"); - } - rvalue = value; -} - - -typedef int(*callback_func_p)(CPXENVptr, void*, int, void*); - + void + CPLEXEnvironment::terminate() + { + if (env_ != NULL) + { + int status = CPXcloseCPLEX(&env_); + if (status) throw CPLEXException(env_, status, (char*)"CPXcloseCPLEX"); + env_ = NULL; + } + } + CPLEXEnvironment::~CPLEXEnvironment() + { + terminate(); + } + void + CPLEXEnvironment::setparam(int paramnum, int value) + { + int status = CPXsetintparam(env_, paramnum, value); + if (status) throw CPLEXException(env_, status, (char*)"CPXsetintparam"); + } -CPLEXException::CPLEXException (CPXENVptr env, int status, - char *funcname) : - env_ (env), - status_ (status), - funcname_ (funcname) -{} + void + CPLEXEnvironment::setparam(int paramnum, double value) + { + int status = CPXsetdblparam(env_, paramnum, value); + if (status) throw CPLEXException(env_, status, (char*)"CPXsetdblparam"); + } -const char * -CPLEXException::what () const -{ - return (CPXgeterrorstring (NULL, status_, (char *)buffer)); -} + void + CPLEXEnvironment::setdefaults() + { + int status = CPXsetdefaults(env_); + if (status) throw CPLEXException(env_, status, (char*)"CPXsetdefaults"); + } -const char * -CPLEXException::funcname () const -{ - return (funcname_); -} + void + CPLEXEnvironment::getParam(int paramnum, int& rvalue) const + { + int value; + int status = CPXgetintparam(env_, paramnum, &value); -int -CPLEXException::errcode () const -{ - return (status_); -} + if (status) throw CPLEXException(env_, status, (char*)"CPXgetintparam"); + rvalue = value; + } -CPLEXProblem::CPLEXProblem (CPLEXEnvironment& renv, - char *probname) -{ - int status = 0; + void + CPLEXEnvironment::getParam(int paramnum, double& rvalue) const + { + double value; + int status = CPXgetdblparam(env_, paramnum, &value); - env_ = renv.env_; + if (status) throw CPLEXException(env_, status, (char*)"CPXsetdblparam"); - lp_ = CPXcreateprob (env_, &status, probname); - if ( status != 0 ) { - throw CPLEXException (renv.env_, status, "CPXcreateprob"); - } + rvalue = value; + } -} + typedef int(*callback_func_p)(CPXENVptr, void*, int, void*); -CPLEXProblem::~CPLEXProblem () -{ - CPXfreeprob (env_, &lp_); -} + CPLEXException::CPLEXException(CPXENVptr env, int status, char *funcname) + : env_(env), status_(status), funcname_(funcname) + {} + const char * + CPLEXException::what() const + { + return (CPXgeterrorstring(NULL, status_, (char *)buffer)); + } -void -CPLEXProblem::read (const char *fname, const char *filetype) -{ -int status = CPXreadcopyprob (env_, lp_, (char *) fname, - (char *) filetype); + const char * + CPLEXException::funcname() const + { + return (funcname_); + } - if ( status ) throw CPLEXException (env_, status, "CPXreadcopyprob"); + int + CPLEXException::errcode() const + { + return (status_); + } -} + CPLEXProblem::CPLEXProblem(CPLEXEnvironment& renv, const char *probname) + { + int status = 0; + env_ = renv.env_; + lp_ = CPXcreateprob(env_, &status, probname); + if (status != 0) throw CPLEXException(renv.env_, status, (char*)"CPXcreateprob"); + } -void -CPLEXProblem::write (const char *fname, const char *filetype) const -{ -int status = CPXwriteprob (env_, lp_, (char *) fname, (char *) filetype); + CPLEXProblem::~CPLEXProblem() + { + CPXfreeprob(env_, &lp_); + } - if ( status ) throw CPLEXException (env_, status, "CPXwriteprob"); -} + void + CPLEXProblem::read(const char *fname, const char *filetype) + { + int status = CPXreadcopyprob(env_, lp_, (char *)fname, (char *)filetype); + if (status) throw CPLEXException(env_, status, (char*)"CPXreadcopyprob"); + } + void + CPLEXProblem::write(const char *fname, const char *filetype) const + { + int status = CPXwriteprob(env_, lp_, (char *)fname, (char *)filetype); + if (status) throw CPLEXException(env_, status, (char*)"CPXwriteprob"); + } -void -CPLEXProblem::copylpdata (int numcols, int numrows, - ObjSense objsen, double obj[], - double rhs[], char sense[], - int matbeg[], int matcnt[], - int matind[], double matval[], - double lb[], double ub[], - double rngval[], char *colname[], - char *rowname[]) -{ + void + CPLEXProblem::copylpdata(int numcols, int numrows, + ObjSense objsen, double obj[], + double rhs[], char sense[], + int matbeg[], int matcnt[], + int matind[], double matval[], + double lb[], double ub[], + double rngval[], char *colname[], + char *rowname[]) + { #ifdef _DEBUG #if CPX_VERSION < 900 - int st = CPXcheckcopylpwnames (env_, lp_, numcols, numrows, (int)objsen, - obj, rhs, sense, matbeg, matcnt, - matind, matval, lb, ub, rngval, - colname, rowname); - if ( st >= 2 ) throw CPLEXException (env_, st, "CPXcopylpwnames"); + int st = CPXcheckcopylpwnames(env_, lp_, numcols, numrows, (int)objsen, + obj, rhs, sense, matbeg, matcnt, + matind, matval, lb, ub, rngval, + colname, rowname); + if (st >= 2) throw CPLEXException(env_, st, "CPXcopylpwnames"); #endif #endif -int status = CPXcopylpwnames (env_, lp_, numcols, numrows, (int)objsen, - obj, rhs, sense, matbeg, matcnt, - matind, matval, lb, ub, rngval, - colname, rowname); - if ( status ) throw CPLEXException (env_, status, "CPXcopylpwnames"); -} - - -void -CPLEXProblem::chgprobtype( CPLEXProblem::ProbType cpx_prob ) -{ - int status = CPXchgprobtype( env_, lp_, cpx_prob ); - if ( status ) throw CPLEXException (env_, status, "CPXchgprobtype"); -} + int status = CPXcopylpwnames(env_, lp_, numcols, numrows, (int)objsen, + obj, rhs, sense, matbeg, matcnt, + matind, matval, lb, ub, rngval, + colname, rowname); + if (status) throw CPLEXException(env_, status, (char*)"CPXcopylpwnames"); + } -void -CPLEXProblem::chgctype( int cnt, int indices[], char ctype[] ) -{ - int status = CPXchgctype( env_, lp_, cnt, indices, ctype ); - if ( status ) throw CPLEXException (env_, status, "CPXchgctype"); -} + void + CPLEXProblem::chgprobtype(CPLEXProblem::ProbType cpx_prob) + { + int status = CPXchgprobtype(env_, lp_, cpx_prob); + if (status) throw CPLEXException(env_, status, (char*)"CPXchgprobtype"); + } -void -CPLEXProblem::newrows (int rcnt, double rhs[], char sense[], - double rngval[], char *rowname[]) -{ -int status = CPXnewrows (env_, lp_, rcnt, rhs, sense, rngval, rowname); + void + CPLEXProblem::chgctype(int cnt, int indices[], char ctype[]) + { + int status = CPXchgctype(env_, lp_, cnt, indices, ctype); + if (status) throw CPLEXException(env_, status, (char*)"CPXchgctype"); + } - if ( status ) throw CPLEXException (env_, status, "CPXnewrows"); -} -void -CPLEXProblem::newcols (int ccnt, double obj[], double lb[], - double ub[], char ctype[], char *colname[]) -{ -int status = CPXnewcols (env_, lp_, ccnt, obj, lb, ub, ctype, colname); + void + CPLEXProblem::newrows(int rcnt, double rhs[], char sense[], + double rngval[], char *rowname[]) + { + int status = CPXnewrows(env_, lp_, rcnt, rhs, sense, rngval, rowname); + if (status) throw CPLEXException(env_, status, (char*)"CPXnewrows"); + } - if ( status ) throw CPLEXException (env_, status, "CPXnewcols"); -} + void + CPLEXProblem::newcols(int ccnt, double obj[], double lb[], + double ub[], char ctype[], char *colname[]) + { + int status = CPXnewcols(env_, lp_, ccnt, obj, lb, ub, ctype, colname); + if (status) throw CPLEXException(env_, status, (char*)"CPXnewcols"); + } -void -CPLEXProblem::addrows (int ccnt, int rcnt, int nzcnt, - double rhs[], char sense[], int rmatbeg[], - int rmatind[], double rmatval[], - char *colname[], char *rowname[]) -{ + void + CPLEXProblem::addrows(int ccnt, int rcnt, int nzcnt, + double rhs[], char sense[], int rmatbeg[], + int rmatind[], double rmatval[], + char *colname[], char *rowname[]) + { #ifdef _DEBUG #if CPX_VERSION < 900 - int st = CPXcheckaddrows (env_, lp_, ccnt, rcnt, nzcnt, rhs, sense, - rmatbeg, rmatind, rmatval, colname, rowname); - if ( st ) throw CPLEXException (env_, st, "CPXaddrows"); + int st = CPXcheckaddrows(env_, lp_, ccnt, rcnt, nzcnt, rhs, sense, + rmatbeg, rmatind, rmatval, colname, rowname); + if (st) throw CPLEXException(env_, st, "CPXaddrows"); #endif #endif -int status = CPXaddrows (env_, lp_, ccnt, rcnt, nzcnt, rhs, sense, - rmatbeg, rmatind, rmatval, colname, rowname); - - if ( status ) throw CPLEXException (env_, status, "CPXaddrows"); -} + int status = CPXaddrows(env_, lp_, ccnt, rcnt, nzcnt, rhs, sense, + rmatbeg, rmatind, rmatval, colname, rowname); + if (status) throw CPLEXException(env_, status, (char*)"CPXaddrows"); + } -void -CPLEXProblem::addcols (int ccnt, int nzcnt, double obj[], - int cmatbeg[], int cmatind[], - double cmatval[], double lb[], double ub[], - char *colname[]) -{ + void + CPLEXProblem::addcols(int ccnt, int nzcnt, double obj[], + int cmatbeg[], int cmatind[], + double cmatval[], double lb[], double ub[], + char *colname[]) + { #ifdef _DEBUG #if CPX_VERSION < 900 - int st = CPXcheckaddcols (env_, lp_, ccnt, nzcnt, obj, - cmatbeg, cmatind, cmatval, lb, ub, - colname); - if ( st ) throw CPLEXException (env_, st, "CPXaddcols"); + int st = CPXcheckaddcols(env_, lp_, ccnt, nzcnt, obj, + cmatbeg, cmatind, cmatval, lb, ub, + colname); + if (st) throw CPLEXException(env_, st, "CPXaddcols"); #endif #endif -int status = CPXaddcols (env_, lp_, ccnt, nzcnt, obj, - cmatbeg, cmatind, cmatval, lb, ub, - colname); - - if ( status ) throw CPLEXException (env_, status, "CPXaddcols"); -} + int status = CPXaddcols(env_, lp_, ccnt, nzcnt, obj, + cmatbeg, cmatind, cmatval, lb, ub, + colname); + if (status) throw CPLEXException(env_, status, (char*)"CPXaddcols"); + } -// NEW!!! -void -CPLEXProblem::chgbds (int cnt, int indices[], char lu[], double bd[] ) -{ + // NEW!!! + void + CPLEXProblem::chgbds(int cnt, int indices[], char lu[], double bd[]) + { #ifdef _DEBUG #if CPX_VERSION < 900 - int st = CPXcheckvals(env_, lp_, cnt, NULL, indices, bd ); - if ( st ) - throw CPLEXException( env_, st, "CPXchgbds"); + int st = CPXcheckvals(env_, lp_, cnt, NULL, indices, bd); + if (st) + throw CPLEXException(env_, st, "CPXchgbds"); #endif #endif - int status = CPXchgbds(env_, lp_, cnt, indices, lu, bd ); - if ( status ) - throw CPLEXException( env_, status, "CPXchgbds"); -} + int status = CPXchgbds(env_, lp_, cnt, indices, lu, bd); + if (status) throw CPLEXException(env_, status, (char*)"CPXchgbds"); + } -void -CPLEXProblem::chgobj (int cnt, int indices[], double values[] ) -{ + void + CPLEXProblem::chgobj(int cnt, int indices[], double values[]) + { #ifdef _DEBUG #if CPX_VERSION < 900 - int st = CPXcheckvals(env_, lp_, cnt, NULL, indices, values ); - if ( st ) - throw CPLEXException( env_, st, "CPXchgobj"); + int st = CPXcheckvals(env_, lp_, cnt, NULL, indices, values); + if (st) + throw CPLEXException(env_, st, "CPXchgobj"); #endif #endif - int status = CPXchgobj(env_, lp_, cnt, indices, values ); - if ( status ) - throw CPLEXException( env_, status, "CPXchgobj"); -} + int status = CPXchgobj(env_, lp_, cnt, indices, values); + if (status) throw CPLEXException(env_, status, (char*)"CPXchgobj"); + } -void -CPLEXProblem::chgrhs (int cnt, int indices[], double values[] ) -{ + void + CPLEXProblem::chgrhs(int cnt, int indices[], double values[]) + { #ifdef _DEBUG #if CPX_VERSION < 900 - int st = CPXcheckvals(env_, lp_, cnt, indices, NULL, values ); - if ( st ) - throw CPLEXException( env_, st, "CPXchgrhs"); + int st = CPXcheckvals(env_, lp_, cnt, indices, NULL, values); + if (st) + throw CPLEXException(env_, st, "CPXchgrhs"); #endif #endif - int status = CPXchgrhs(env_, lp_, cnt, indices, values ); - if ( status ) - throw CPLEXException( env_, status, "CPXchgrhs"); -} - - -void -CPLEXProblem::chgobjsen (ObjSense objsen) -{ - CPXchgobjsen (env_, lp_, (int) objsen); -} + int status = CPXchgrhs(env_, lp_, cnt, indices, values); + if (status) throw CPLEXException(env_, status, (char*)"CPXchgrhs"); + } -void -CPLEXProblem::chgcoef (int i, int j, double val) -{ -int status = CPXchgcoef (env_, lp_, i, j, val); + void + CPLEXProblem::chgobjsen(ObjSense objsen) + { + CPXchgobjsen(env_, lp_, (int)objsen); + } - if ( status ) throw CPLEXException (env_, status, "CPXchgcoef"); -} + void + CPLEXProblem::chgcoef(int i, int j, double val) + { + int status = CPXchgcoef(env_, lp_, i, j, val); + if (status) throw CPLEXException(env_, status, (char*)"CPXchgcoef"); + } -void -CPLEXProblem::chgcoeflist (int numcoefs, int rowlist[], int collist[], - double vallist[]) -{ + void + CPLEXProblem::chgcoeflist(int numcoefs, int rowlist[], int collist[], + double vallist[]) + { #ifdef _DEBUG #if CPX_VERSION < 900 - int st = CPXcheckchgcoeflist (env_, lp_, numcoefs, rowlist, - collist, vallist); + int st = CPXcheckchgcoeflist(env_, lp_, numcoefs, rowlist, + collist, vallist); - if ( st ) throw CPLEXException (env_, st, "CPXchgcoeflist"); + if (st) throw CPLEXException(env_, st, "CPXchgcoeflist"); #endif #endif - int status = CPXchgcoeflist (env_, lp_, numcoefs, rowlist, - collist, vallist); - - if ( status ) throw CPLEXException (env_, status, "CPXchgcoeflist"); -} - - -void -CPLEXProblem::primopt () -{ -int status = CPXprimopt (env_, lp_); - - if ( status ) throw CPLEXException (env_, status, "CPXprimopt"); -} - -void -CPLEXProblem::dualopt () -{ -int status = CPXdualopt (env_, lp_); - - if ( status ) throw CPLEXException (env_, status, "CPXdualopt"); -} - -void -CPLEXProblem::baropt () -{ -int status = CPXbaropt (env_, lp_); - - if ( status ) throw CPLEXException (env_, status, "CPXbaropt"); -} - - -void -CPLEXProblem::mipopt () -{ -int status = CPXmipopt (env_, lp_); - - if ( status ) throw CPLEXException (env_, status, "CPXmipopt"); -} - - - -void -CPLEXProblem::hybbaropt (OptMethod method) -{ -int status = CPXhybbaropt (env_, lp_, (char) method); - - if ( status ) throw CPLEXException (env_, status, "CPXhybbaropt"); -} - -void -CPLEXProblem::hybnetopt (OptMethod method) -{ -int status = CPXhybnetopt (env_, lp_, (char) method); - - if ( status ) throw CPLEXException (env_, status, "CPXhybnetopt"); -} - -int -CPLEXProblem::stat () const -{ - return (CPXgetstat (env_, lp_)); -} - -int -CPLEXProblem::getitcnt () -{ - int status = 0; - status = CPXgetitcnt ( env_, lp_ ); - if ( status == -1 ) - throw CPLEXException (env_, status, "CPXgetitcnt" ); - return status; -} - - -double -CPLEXProblem::objval () const -{ -double objval; -int status; - - status = CPXgetobjval (env_, lp_, &objval); - if ( !status ) return (objval); - - else throw CPLEXException (env_, status, "CPXgetobjval"); - - return (0.0); - -} - -CPLEXProblem::ProbType CPLEXProblem::probtype(void) const -{ - return ((CPLEXProblem::ProbType) CPXgetprobtype(env_, lp_) ); -} - - -double -CPLEXProblem::mipobjval () const -{ -double objval; -int status; - - status = CPXgetmipobjval (env_, lp_, &objval); - if ( !status ) return (objval); - - else throw CPLEXException (env_, status, "CPXgetmipobjval"); - - return (0.0); - -} - -void -CPLEXProblem::_getX (double x[], int begin, int end) const -{ -if ( probtype() == CPLEXProblem::MIP ) - getmipX( x, begin, end ); -else - getX( x, begin, end ); -} - - -void -CPLEXProblem::getX (double x[], int begin, int end) const -{ -int theend = end; -int status = 0; - - if ( end < 0 ) { - theend = numcols() - 1; - } - - status = CPXgetx (env_, lp_, x, begin, theend); - - if ( status ) throw CPLEXException (env_, status, "CPXgetx"); -} - - -void -CPLEXProblem::getmipX (double x[], int begin, int end) const -{ -int theend = end; -int status = 0; - - if ( end < 0 ) { - theend = numcols() - 1; - } - - status = CPXgetmipx (env_, lp_, x, begin, theend); - - if ( status ) throw CPLEXException (env_, status, "CPXgetmipx"); -} - - -void -CPLEXProblem::getobj (double val[], int begin, int end) const -{ -int theend = end; -int status = 0; + int status = CPXchgcoeflist(env_, lp_, numcoefs, rowlist, collist, vallist); + if (status) throw CPLEXException(env_, status, (char*)"CPXchgcoeflist"); + } - if ( end < 0 ) { - theend = numcols() - 1; - } - status = CPXgetobj (env_, lp_, val, begin, theend); + void + CPLEXProblem::primopt() + { + int status = CPXprimopt(env_, lp_); + if (status) throw CPLEXException(env_, status, (char*)"CPXprimopt"); + } - if ( status ) throw CPLEXException (env_, status, "CPXgetobj"); -} + void + CPLEXProblem::dualopt() + { + int status = CPXdualopt(env_, lp_); + if (status) throw CPLEXException(env_, status, (char*)"CPXdualopt"); + } + void + CPLEXProblem::baropt() + { + int status = CPXbaropt(env_, lp_); + if (status) throw CPLEXException(env_, status, (char*)"CPXbaropt"); + } -void -CPLEXProblem::getSlack (double slack[], int begin, int end) const -{ -int theend = end; -int status = 0; + void + CPLEXProblem::mipopt() + { + int status = CPXmipopt(env_, lp_); + if (status) throw CPLEXException(env_, status, (char*)"CPXmipopt"); + } - if ( end < 0 ) { - theend = numrows() - 1; - } + void + CPLEXProblem::hybbaropt(OptMethod method) + { + int status = CPXhybbaropt(env_, lp_, (char)method); + if (status) throw CPLEXException(env_, status, (char*)"CPXhybbaropt"); + } - status = CPXgetslack (env_, lp_, slack, begin, theend); + void + CPLEXProblem::hybnetopt(OptMethod method) + { + int status = CPXhybnetopt(env_, lp_, (char)method); + if (status) throw CPLEXException(env_, status, (char*)"CPXhybnetopt"); + } - if ( status ) throw CPLEXException (env_, status, "CPXgetslack"); -} + int + CPLEXProblem::stat() const + { + return (CPXgetstat(env_, lp_)); + } -void -CPLEXProblem::getPi (double pi[], int begin, int end) const -{ -int theend = end; -int status = 0; + int + CPLEXProblem::getitcnt() + { + int status = CPXgetitcnt(env_, lp_); + if (status == -1) throw CPLEXException(env_, status, (char*)"CPXgetitcnt"); + return status; + } - if ( end < 0 ) { - theend = numrows() - 1; - } + double + CPLEXProblem::objval() const + { + double objval; + int status = CPXgetobjval(env_, lp_, &objval); + if (status) throw CPLEXException(env_, status, (char*)"CPXgetobjval"); + return (objval); + } - status = CPXgetpi (env_, lp_, pi, begin, theend); + CPLEXProblem::ProbType CPLEXProblem::probtype(void) const + { + return ((CPLEXProblem::ProbType) CPXgetprobtype(env_, lp_)); + } - if ( status ) throw CPLEXException (env_, status, "CPXgetpi"); -} + double + CPLEXProblem::mipobjval() const + { + double objval; + int status = CPXgetmipobjval(env_, lp_, &objval); + if (status) throw CPLEXException(env_, status, (char*)"CPXgetmipobjval"); + return (objval); + } -void -CPLEXProblem::getDj (double dj[], int begin, int end) const -{ -int theend = end; -int status = 0; + void + CPLEXProblem::_getX(double x[], int begin, int end) const + { + if (probtype() == CPLEXProblem::MIP) + getmipX(x, begin, end); + else + getX(x, begin, end); + } - if ( end < 0 ) { - theend = numcols() - 1; - } + void + CPLEXProblem::getX(double x[], int begin, int end) const + { + int theend = (end < 0) ? numcols() - 1 : end; + int status = CPXgetx(env_, lp_, x, begin, theend); + if (status) throw CPLEXException(env_, status, (char*)"CPXgetx"); + } - status = CPXgetdj (env_, lp_, dj, begin, theend); + void + CPLEXProblem::getmipX(double x[], int begin, int end) const + { + int theend = (end < 0) ? numcols() - 1 : end; + int status = CPXgetmipx(env_, lp_, x, begin, theend); + if (status) throw CPLEXException(env_, status, (char*)"CPXgetmipx"); + } - if ( status ) throw CPLEXException (env_, status, "CPXgetdj"); -} + void + CPLEXProblem::getobj(double val[], int begin, int end) const + { + int theend = (end < 0) ? numcols() - 1 : end; + int status = CPXgetobj(env_, lp_, val, begin, theend); + if (status) throw CPLEXException(env_, status, (char*)"CPXgetobj"); + } -void -CPLEXProblem::getBase (int cstat[], int rstat[]) const -{ -int status = CPXgetbase (env_, lp_, cstat, rstat); + void + CPLEXProblem::getSlack(double slack[], int begin, int end) const + { + int theend = (end < 0) ? numrows() - 1 : end; + int status = CPXgetslack(env_, lp_, slack, begin, theend); + if (status) throw CPLEXException(env_, status, (char*)"CPXgetslack"); + } - if ( status ) throw CPLEXException (env_, status, "CPXgetbase"); -} + void + CPLEXProblem::getPi(double pi[], int begin, int end) const + { + int theend = (end < 0) ? numrows() - 1 : end; + int status = CPXgetpi(env_, lp_, pi, begin, theend); + if (status) throw CPLEXException(env_, status, (char*)"CPXgetpi"); + } -void + void + CPLEXProblem::getDj(double dj[], int begin, int end) const + { + int theend = (end < 0) ? numcols() - 1 : end; + int status = CPXgetdj(env_, lp_, dj, begin, theend); + if (status) throw CPLEXException(env_, status, (char*)"CPXgetdj"); + } -CPLEXProblem::getRHS(double rhs[], int begin, int end ) -{ -int theend = end; -int status = 0; + void + CPLEXProblem::getBase(int cstat[], int rstat[]) const + { + int status = CPXgetbase(env_, lp_, cstat, rstat); + if (status) throw CPLEXException(env_, status, (char*)"CPXgetbase"); + } - if ( end < 0 ) { - theend = numrows() - 1; - } + void + CPLEXProblem::getRHS(double rhs[], int begin, int end) + { + int theend = (end < 0) ? numrows() - 1 : end; + int status = CPXgetrhs(env_, lp_, rhs, begin, theend); + if (status) throw CPLEXException(env_, status, (char*)"CPXgetrhs"); + } - status = CPXgetrhs (env_, lp_, rhs, begin, theend); + int + CPLEXProblem::numcols() const + { + return (CPXgetnumcols(env_, lp_)); + } - if ( status ) throw CPLEXException (env_, status, "CPXgetrhs"); -} + int + CPLEXProblem::numrows() const + { + return (CPXgetnumrows(env_, lp_)); + } -int -CPLEXProblem::numcols () const -{ - return (CPXgetnumcols (env_, lp_)); -} + void + CPLEXProblem::delcols(int first, int last) + { + int status = CPXdelcols(env_, lp_, first, last); + if (status) throw CPLEXException(env_, status, (char*)"CPXdelcols"); + } -int -CPLEXProblem::numrows () const -{ - return (CPXgetnumrows (env_, lp_)); -} + void + CPLEXProblem::delrows(int first, int last) + { + int status = CPXdelrows(env_, lp_, first, last); + if (status) throw CPLEXException(env_, status, (char*)"CPXdelrows"); + } -void -CPLEXProblem::delcols ( int first, int last) -{ - int status = 0; - status = CPXdelcols(env_, lp_, first, last ); - if ( status ) throw CPLEXException (env_, status, "CPXdelcols"); -} + void + CPLEXProblem::copyStart(int cstat[], int rstat[], double cprim[], double rprim[], double cdual[], double rdual[]) + { + int status = CPXcopystart(env_, lp_, cstat, rstat, cprim, rprim, cdual, rdual); + if (status) throw CPLEXException(env_, status, (char*)"CPXcopystart"); + } -void -CPLEXProblem::delrows ( int first, int last) -{ - int status = 0; - status = CPXdelrows(env_, lp_, first, last ); - if ( status ) throw CPLEXException (env_, status, "CPXdelrows"); -} +#if(CPX_VERSION < 12060000) + void + CPLEXProblem::copymipstart(int cnt, int* indices, double* value) + { + int status = CPXcopymipstart(env_, lp_, cnt, indices, value); + if (status) throw CPLEXException(env_, status, "CPXcopymipstart"); + } +#endif -void -CPLEXProblem::copyStart( int cstat[], int rstat[], double cprim[], double rprim[], double cdual[], double rdual[] ) -{ - int status = 0; - status = CPXcopystart( env_, lp_, cstat, rstat, cprim, rprim, cdual, rdual ); - if ( status ) - throw CPLEXException( env_, status, "CPXcopystart" ); -} +#if(CPX_VERSION >= 12060000) + void + CPLEXProblem::copymipstart(int cnt, int* indices, double* value) + { + int mcnt = 1; + int nzcnt = cnt; + int* beg = new int[1]; beg[0] = 0; + int* varindices = indices; + //double* value = value; + int* effortlevel = NULL; + char** mipstartname = NULL; + + int status = CPXaddmipstarts(env_, lp_, mcnt, nzcnt, beg, varindices, value, effortlevel, mipstartname); + if (status) throw CPLEXException(env_, status, (char*)"CPXcopymipstart"); + delete[] beg; + } +#endif -#if(_CPLEX_12dot6_x64 == 0) -void -CPLEXProblem::copymipstart ( int cnt, int* indices, double* value ) -{ - int status = CPXcopymipstart (env_, lp_, cnt, indices, value ); + void + CPLEXProblem::copyctype(char ctype[]) + { + int status = CPXcopyctype(env_, lp_, ctype); + if (status) throw CPLEXException(env_, status, (char*)"CPXcopyctype"); + } - if ( status ) - throw CPLEXException (env_, status, "CPXcopymipstart"); -} -#endif + // Zum Testen der LP-Matrix eingefuehrt + // Rueckgabewert ist ein String, der alle Fehler enthaelt + // method is like CPXcopylp() + // except that numnzs (number of non-zeros is third parameter) + std::string CPLEXProblem::CheckMatrix(int numcols, int numrows, int numnzs, + ObjSense objsen, double obj[], + double rhs[], char sense[], char ctype[], + int matbeg[], int matcnt[], + int matind[], double matval[], + double lb[], double ub[], + double rngval[], char *colname[], + char *rowname[], + const double d_minvalue, + const double d_maxvalue) + { + std::ostringstream os; + + if (numcols < 1) + os << "Anzahl Variablen: " << numcols << std::endl; + if (numrows < 1) + os << "Anzahl Restriktionen " << numrows << std::endl; + if (obj == NULL) + os << "obj ist NULL-Pointer" << std::endl; + if (rhs == NULL) + os << "rhs ist NULL-Pointer" << std::endl; + if (sense == NULL) + os << "sense ist NULL-Pointer" << std::endl; + if (matbeg == NULL) + os << "matbeg ist NULL-Pointer" << std::endl; + if (matcnt == NULL) + os << "matcnt ist NULL-Pointer" << std::endl; + if (matind == NULL) + os << "matind ist NULL-Pointer" << std::endl; + if (matval == NULL) + os << "matval ist NULL-Pointer" << std::endl; + if (lb == NULL) + os << "lb ist NULL-Pointer" << std::endl; + if (ub == NULL) + os << "ub ist NULL-Pointer" << std::endl; + + for (int i = 0; i < numrows; ++i) + { + if ((rhs[i] < d_minvalue) || (rhs[i] > d_maxvalue)) + os << "Warnung: rhs[" << i << "] = " << rhs[i] << std::endl; + if ((sense[i] != 'L') && (sense[i] != 'E') && (sense[i] != 'G') && (sense[i] != 'R')) + os << "Warnung: sense[" << i << "] = " << sense[i] << std::endl; + } -#if(_CPLEX_12dot6_x64 == 1) -void -CPLEXProblem::copymipstart(int cnt, int* indices, double* value) -{ - int mcnt = 1; - int nzcnt = cnt; - int* beg = new int[1]; beg[0] = 0; - int* varindices = indices; - //double* value = value; - int* effortlevel = NULL; - char** mipstartname = NULL; + for (int i = 0; i < numcols; ++i) + { + if ((obj[i] < d_minvalue) || (obj[i] > d_maxvalue)) + os << "Warnung: obj[" << i << "] = " << obj[i] << std::endl; + if ((lb[i] < d_minvalue) || (lb[i] > d_maxvalue)) + os << "Warnung: lb[" << i << "] = " << lb[i] << std::endl; + if ((ub[i] < d_minvalue) || (ub[i] > d_maxvalue)) + os << "Warnung: ub[" << i << "] = " << ub[i] << std::endl; + if (lb[i] > ub[i]) + os << "Fehler: lb[" << i << "] = " << lb[i] << " > ub[" << i << "] = " << ub[i] << std::endl; + if (ctype != NULL && + ctype[i] != CPX_CONTINUOUS && + ctype[i] != CPX_BINARY && + ctype[i] != CPX_INTEGER // && + // ctype[i] != CPX_SEMICONT && // erst ab CPLEX 7.1 + // ctype[i] != CPX_SEMIINT + ) + os << "Fehler: ctype[" << i << "] = " << ctype[i] << std::endl; + if (matbeg[i] < 0) + os << "Fehler: matbeg[" << i << "] = " << matbeg[i] << std::endl; + if (matcnt[i] <= 0) + os << "Fehler: matcnt[" << i << "] = " << matcnt[i] << std::endl; + if (matbeg[i] + matcnt[i] > numnzs) + { + os << "Fehler: matbeg[" << i << "] + matcnt[" << i << "] > numnzs" << std::endl; + os << "matbeg[" << i << "] = " << matbeg[i] << ", matcnt[" << i << "] = " << matcnt[i] << ", numnzs = " << numnzs << std::endl; + } + if ((i > 0) && (matbeg[i] != matbeg[i - 1] + matcnt[i - 1])) + os << "Fehler: matbeg[" << i << "] = " << matbeg[i] << "!= matbeg[" << i - 1 << "] = " << matbeg[i - 1] << " + macnt[" << i - 1 << "] = " << matcnt[i - 1] << std::endl; + std::set< int > col_rows; + for (int k = matbeg[i]; k < matbeg[i] + matcnt[i]; ++k) + { + if (k < numnzs) + { + if (matind[k] < 0 || matind[k] >= numrows) + os << "Fehler: Spalte " << i << " Zeile: " << matind[k] << " ausserhalb des zulaessigen Bereichs[0," << numrows - 1 << "]" << std::endl; + if (col_rows.find(matind[k]) != col_rows.end()) + os << "Fehler: Spalte " << i << " Zeile: " << matind[k] << " mehrfach enthalten" << std::endl; + col_rows.insert(matind[k]); + } + else + os << "Fehler: Spalte " << i << " Eintrag: " << k << " ausserhalb des zulaessigen Bereichs[0," << numnzs - 1 << "]" << std::endl; + } + } - int status = CPXaddmipstarts(env_, lp_, mcnt, nzcnt, beg, varindices, value, effortlevel, mipstartname); + for (int i = 0; i < numnzs; ++i) + { + if ((matval[i] < d_minvalue) || (matval[i] > d_maxvalue)) + os << "Warnung: matval[" << i << "] = " << matval[i] << std::endl; + } - if (status) - throw CPLEXException(env_, status, "CPXcopymipstart"); + return os.str(); + } - delete[]beg; -} -#endif + // Gibt ein LP als Excel-Matrix im csv-Format aus + // method is like CPXcopylp(), + std::string CPLEXProblem::DumpExcelMatrix(int numcols, int numrows, + ObjSense objsen, double obj[], + double rhs[], char sense[], + int matbeg[], int matcnt[], + int matind[], double matval[], + double lb[], double ub[], + double rngval[], char *colname[], + char *rowname[]) + { + std::ostringstream os; + if (objsen == CPX_MAX) + os << "Maximierung;"; + else + os << "Minimierung;"; + os << "#Spalten;" << numcols << ";"; + os << "#Zeilen;" << numrows; + os << std::endl; -void -CPLEXProblem::copyctype ( char ctype[] ) -{ - int status = CPXcopyctype (env_, lp_, ctype ); - - if ( status ) - throw CPLEXException (env_, status, "CPXcopyctype"); -} - - -// Zum Testen der LP-Matrix eingefuehrt -// Rueckgabewert ist ein String, der alle Fehler enthaelt -// method is like CPXcopylp() -// except that numnzs (number of non-zeros is third parameter) -std::string CPLEXProblem::CheckMatrix (int numcols, int numrows, int numnzs, - ObjSense objsen, double obj[], - double rhs[], char sense[], char ctype[], - int matbeg[], int matcnt[], - int matind[], double matval[], - double lb[], double ub[], - double rngval[], char *colname[], - char *rowname[], - const double d_minvalue, - const double d_maxvalue ) -{ - std::ostringstream os; - - if ( numcols < 1 ) - os << "Anzahl Variablen: " << numcols << std::endl; - if ( numrows < 1 ) - os << "Anzahl Restriktionen " << numrows << std::endl; - if ( obj == NULL ) - os << "obj ist NULL-Pointer" << std::endl; - if ( rhs == NULL ) - os << "rhs ist NULL-Pointer" << std::endl; - if ( sense == NULL ) - os << "sense ist NULL-Pointer" << std::endl; - if ( matbeg == NULL ) - os << "matbeg ist NULL-Pointer" << std::endl; - if ( matcnt == NULL ) - os << "matcnt ist NULL-Pointer" << std::endl; - if ( matind == NULL ) - os << "matind ist NULL-Pointer" << std::endl; - if ( matval == NULL ) - os << "matval ist NULL-Pointer" << std::endl; - if ( lb == NULL ) - os << "lb ist NULL-Pointer" << std::endl; - if ( ub == NULL ) - os << "ub ist NULL-Pointer" << std::endl; - - for (int i = 0; i < numrows; i++ ) - { - if ( ( rhs[ i ] < d_minvalue ) || ( rhs[ i ] > d_maxvalue ) ) - os << "Warnung: rhs[" << i << "] = " << rhs[ i ] << std::endl; - if ( ( sense[ i ] != 'L' ) && ( sense[ i ] != 'E' ) && ( sense[ i ] != 'G' ) && ( sense[ i ] != 'R' ) ) - os << "Warnung: sense[" << i << "] = " << sense[ i ] << std::endl; - } - - for ( int i = 0; i < numcols; i++ ) - { - if ( ( obj[ i ] < d_minvalue ) || ( obj[ i ] > d_maxvalue ) ) - os << "Warnung: obj[" << i << "] = " << obj[i] << std::endl; - if ( ( lb[ i ] < d_minvalue ) || ( lb[ i ] > d_maxvalue ) ) - os << "Warnung: lb[" << i << "] = " << lb[i] << std::endl; - if ( ( ub[ i ] < d_minvalue ) || ( ub[ i ] > d_maxvalue ) ) - os << "Warnung: ub[" << i << "] = " << ub[i] << std::endl; - if ( lb[ i ] > ub [ i ] ) - os << "Fehler: lb[" << i << "] = " << lb[i] << " > ub[" << i << "] = " << ub[i] << std::endl; - if ( ctype != NULL && - ctype[i] != CPX_CONTINUOUS && - ctype[i] != CPX_BINARY && - ctype[i] != CPX_INTEGER // && -// ctype[i] != CPX_SEMICONT && // erst ab CPLEX 7.1 -// ctype[i] != CPX_SEMIINT - ) - os << "Fehler: ctype[" << i << "] = " << ctype[i] << std::endl; - if ( matbeg[ i ] < 0 ) - os << "Fehler: matbeg[" << i << "] = " << matbeg[i] << std::endl; - if ( matcnt[ i ] <= 0 ) - os << "Fehler: matcnt[" << i << "] = " << matcnt[i] << std::endl; - if ( matbeg[ i ] + matcnt[ i ] > numnzs ) + os << ";"; + for (int j = 0; j < numcols; ++j) { - os << "Fehler: matbeg[" << i << "] + matcnt[" << i << "] > numnzs"<< std::endl; - os << "matbeg[" << i << "] = " << matbeg[ i ] << ", matcnt[" << i << "] = " << matcnt[ i ] << ", numnzs = " << numnzs << std::endl; + if (colname != NULL) + os << colname[j] << ";"; + else + os << j << ";"; } - if ( ( i > 0 ) && ( matbeg[ i ] != matbeg[i-1] + matcnt[i-1] ) ) - os << "Fehler: matbeg[" << i << "] = " << matbeg[ i ] << "!= matbeg[" << i-1 << "] = " << matbeg[ i-1 ] << " + macnt[" << i-1 << "] = "<< matcnt[ i-1 ] << std::endl; - std::set< int > col_rows; - for ( int k = matbeg[ i ]; k < matbeg[ i ] + matcnt[ i ]; k++ ) + os << std::endl; + os << ";"; + for (int j = 0; j < numcols; ++j) + os << obj[j] << ";"; + os << std::endl; + for (int i = 0; i < numrows; ++i) { - if ( k < numnzs ) + if (rowname != NULL) + os << rowname[i] << ";"; + else + os << i << ";"; + for (int j = 0; j < numcols; ++j) { - if ( matind[ k ] < 0 || matind[ k ] >= numrows ) - os << "Fehler: Spalte " << i << " Zeile: " << matind[ k ] << " ausserhalb des zulaessigen Bereichs[0," << numrows-1 << "]" << std::endl; - if ( col_rows.find( matind[ k ] ) != col_rows.end() ) - os << "Fehler: Spalte " << i << " Zeile: " << matind[ k ] << " mehrfach enthalten" << std::endl; - col_rows.insert( matind[ k ] ); + int k = matbeg[j]; + bool found = false; + while (k < matbeg[j] + matcnt[j]) + { + if (matind[k] == i) + os << matval[k]; + ++k; + } + os << ";"; } + if (sense[i] == 'L') + os << "<=;"; + else if (sense[i] == 'E') + os << "=;"; + else if (sense[i] == 'G') + os << ">=;"; + else if (sense[i] == 'R') + os << "R;"; else - os << "Fehler: Spalte " << i << " Eintrag: " << k << " ausserhalb des zulaessigen Bereichs[0," << numnzs-1 << "]" << std::endl; + os << "Error;"; + os << rhs[i]; + os << std::endl; } + os << "LB;"; + for (int j = 0; j < numcols; ++j) + os << lb[j] << ";"; + os << std::endl; + os << "UB;"; + for (int j = 0; j < numcols; ++j) + os << ub[j] << ";"; + + return os.str(); } - for ( int i = 0; i < numnzs; i++ ) + CPLEX_NET_Problem::CPLEX_NET_Problem(CPLEXEnvironment& renv, const char *probname) { - if ( ( matval[ i ] < d_minvalue ) || ( matval[ i ] > d_maxvalue ) ) - os << "Warnung: matval[" << i << "] = " << matval[i] << std::endl; + int status = 0; + env_ = renv.env_; + net_ = CPXNETcreateprob(env_, &status, probname); + if (status != 0) throw CPLEXException(renv.env_, status, (char*)"CPXNETcreateprob"); } - return os.str(); -} - -// Gibt ein LP als Excel-Matrix im csv-Format aus -// method is like CPXcopylp(), -std::string CPLEXProblem::DumpExcelMatrix ( int numcols, int numrows, - ObjSense objsen, double obj[], - double rhs[], char sense[], - int matbeg[], int matcnt[], - int matind[], double matval[], - double lb[], double ub[], - double rngval[], char *colname[], - char *rowname[] ) -{ - std::ostringstream os; - - if ( objsen == CPX_MAX ) - os << "Maximierung;"; - else - os << "Minimierung;"; - os << "#Spalten;" << numcols << ";"; - os << "#Zeilen;" << numrows; - os << std::endl; + void + CPLEX_NET_Problem::terminate() + { + if (env_ != NULL) + { + int status = CPXNETfreeprob(env_, &net_); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETaddarcs"); + env_ = NULL; + } + } - os << ";"; - for( int j = 0; j < numcols; j++ ) + CPLEX_NET_Problem::~CPLEX_NET_Problem() { - if ( colname != NULL ) - os << colname[ j ] << ";"; - else - os << j << ";"; + terminate(); } - os << std::endl; - os << ";"; - for( int j = 0; j < numcols; j++ ) - os << obj[ j ] << ";"; - os << std::endl; - for( int i = 0; i < numrows; i++ ) + + void + CPLEX_NET_Problem::addarcs(int narcs, int *fromnode, int *tonode, double *low, double *up, double *obj, char **anames) { - if ( rowname != NULL ) - os << rowname[ i ] << ";"; - else - os << i << ";"; - for( int j = 0; j < numcols; j++ ) - { - int k = matbeg[ j ]; - bool found = false; - while ( k < matbeg[ j ] + matcnt[ j ] ) - { - if ( matind[ k ] == i ) - os << matval[ k ]; - k++; - } - os << ";"; - } - if ( sense[ i ] == 'L' ) - os << "<=;"; - else if ( sense[ i ] == 'E' ) - os << "=;"; - else if ( sense[ i ] == 'G' ) - os << ">=;"; - else if ( sense[ i ] == 'R' ) - os << "R;"; - else - os << "Error;"; - os << rhs[ i ]; - os << std::endl; + int status = CPXNETaddarcs(env_, net_, narcs, fromnode, tonode, low, up, obj, anames); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETaddarcs"); } - os << "LB;"; - for( int j = 0; j < numcols; j++ ) - os << lb[ j ] << ";"; - os << std::endl; - os << "UB;"; - for( int j = 0; j < numcols; j++ ) - os << ub[ j ] << ";"; - return os.str(); -} + void + CPLEX_NET_Problem::addnodes(int nnodes, double *supply, char **nnames) + { + int status = CPXNETaddnodes(env_, net_, nnodes, supply, nnames); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETaddnodes"); + } + void + CPLEX_NET_Problem::basewrite(char *filename) + { + int status = CPXNETbasewrite(env_, net_, filename); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETbasewrite"); + } -CPLEX_NET_Problem::CPLEX_NET_Problem (CPLEXEnvironment& renv, char *probname) -{ + /* + void + CPLEX_NET_Problem::checkcopynet ( int objsen, int nnodes, double *supply, char **nnames, + int narcs, int *fromnode, int *tonode, double *low, double *up, + double *obj, char **anames ) + { int status = 0; + status = CPXNETcheckcopynet ( env_, net_, objsen, nnodes, supply, nnames, narcs, fromnode, tonode, + low, up, obj, anames ); + if ( status ) + throw CPLEXException (env_, status, "CPXNETcheckcopynet"); + } + */ - env_ = renv.env_; - - net_ = CPXNETcreateprob (env_, &status, probname); - - if ( status != 0 ) { - throw CPLEXException (renv.env_, status, "CPXNETcreateprob"); + void + CPLEX_NET_Problem::chgarcname(int cnt, int *indices, char **anames) + { + int status = CPXNETchgarcname(env_, net_, cnt, indices, anames); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETchgarcname"); } -} -CPLEX_NET_Problem::~CPLEX_NET_Problem () -{ - int status = 0; - status = CPXNETfreeprob (env_, &net_); - if ( status ) - throw CPLEXException (env_, status, "CPXNETaddarcs"); -} + void + CPLEX_NET_Problem::chgarcnodes(int cnt, int *index, int *fromnode, int *tonode) + { + int status = CPXNETchgarcnodes(env_, net_, cnt, index, fromnode, tonode); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETchgarcnodes"); + } + void + CPLEX_NET_Problem::chgbds(int cnt, int *index, char *lu, double *bd) + { + int status = CPXNETchgbds(env_, net_, cnt, index, lu, bd); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETchgbds"); + } -void -CPLEX_NET_Problem::addarcs ( int narcs, int *fromnode, int *tonode, double *low, double *up, double *obj, char **anames) -{ - int status = 0; - status = CPXNETaddarcs ( env_, net_, narcs, fromnode, tonode, low, up, obj, anames); - if ( status ) - throw CPLEXException (env_, status, "CPXNETaddarcs"); -} + void + CPLEX_NET_Problem::chgname(int key, int index, char *name) + { + int status = CPXNETchgname(env_, net_, key, index, name); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETchgname"); + } -void -CPLEX_NET_Problem::addnodes( int nnodes, double *supply, char **nnames ) -{ - int status = 0; - status = CPXNETaddnodes ( env_, net_, nnodes, supply, nnames ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETaddnodes"); -} + void + CPLEX_NET_Problem::chgnodename(int cnt, int *indices, char **name) + { + int status = CPXNETchgnodename(env_, net_, cnt, indices, name); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETchgnodename"); + } -void -CPLEX_NET_Problem::basewrite ( char *filename ) -{ - int status = 0; - status = CPXNETbasewrite ( env_, net_, filename ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETbasewrite"); -} - -/* -void -CPLEX_NET_Problem::checkcopynet ( int objsen, int nnodes, double *supply, char **nnames, - int narcs, int *fromnode, int *tonode, double *low, double *up, - double *obj, char **anames ) -{ - int status = 0; - status = CPXNETcheckcopynet ( env_, net_, objsen, nnodes, supply, nnames, narcs, fromnode, tonode, - low, up, obj, anames ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETcheckcopynet"); -} -*/ - -void -CPLEX_NET_Problem::chgarcname ( int cnt, int *indices, char **anames) -{ - int status = 0; - status = CPXNETchgarcname ( env_, net_, cnt, indices, anames ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETchgarcname"); -} + void + CPLEX_NET_Problem::chgobj(int cnt, int *index, double *obj) + { + int status = CPXNETchgobj(env_, net_, cnt, index, obj); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETchgobj"); + } -void -CPLEX_NET_Problem::chgarcnodes ( int cnt, int *index, int *fromnode, int *tonode) -{ - int status = 0; - status = CPXNETchgarcnodes ( env_, net_, cnt, index, fromnode, tonode ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETchgarcnodes"); -} + void + CPLEX_NET_Problem::chgobjsen(int maxormin) + { + int status = CPXNETchgobjsen(env_, net_, maxormin); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETchgobjsen"); + } -void -CPLEX_NET_Problem::chgbds ( int cnt, int *index, char *lu, double *bd ) -{ - int status = 0; - status = CPXNETchgbds ( env_, net_, cnt, index, lu, bd ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETchgbds"); -} + void + CPLEX_NET_Problem::chgsupply(int cnt, int *index, double *supply) + { + int status = CPXNETchgsupply(env_, net_, cnt, index, supply); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETchgsupply"); + } -void -CPLEX_NET_Problem::chgname ( int key, int index, char *name ) -{ - int status = 0; - status = CPXNETchgname ( env_, net_, key, index, name ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETchgname"); -} + void + CPLEX_NET_Problem::copybase(int *astat, int *nstat) + { + int status = CPXNETcopybase(env_, net_, astat, nstat); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETcopybase"); + } -void -CPLEX_NET_Problem::chgnodename ( int cnt, int *indices, char **name) -{ - int status = 0; - status = CPXNETchgnodename ( env_, net_, cnt, indices, name ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETchgnodename"); -} + void + CPLEX_NET_Problem::copynet(int objsen, int nnodes, double *supply, char **nnames, + int narcs, int *fromnode, int *tonode, double *low, double *up, + double *obj, char **anames) + { + int status = CPXNETcopynet(env_, net_, objsen, nnodes, supply, nnames, narcs, fromnode, tonode, + low, up, obj, anames); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETcopynet"); + } + void + CPLEX_NET_Problem::delarcs(int begin, int end) + { + int status = CPXNETdelarcs(env_, net_, begin, end); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETdelarcs"); + } -void -CPLEX_NET_Problem::chgobj ( int cnt, int *index, double *obj) -{ - int status = 0; - status = CPXNETchgobj ( env_, net_, cnt, index, obj ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETchgobj"); -} + void + CPLEX_NET_Problem::delnodes(int begin, int end) + { + int status = CPXNETdelnodes(env_, net_, begin, end); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETdelnodes"); + } -void -CPLEX_NET_Problem::chgobjsen ( int maxormin ) -{ - int status = 0; - status = CPXNETchgobjsen ( env_, net_, maxormin ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETchgobjsen"); -} + void + CPLEX_NET_Problem::delset(int *whichnodes, int *whicharcs) + { + int status = CPXNETdelset(env_, net_, whichnodes, whicharcs); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETdelnset"); + } -void -CPLEX_NET_Problem::chgsupply ( int cnt, int *index, double *supply ) -{ - int status = 0; - status = CPXNETchgsupply ( env_, net_, cnt, index, supply ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETchgsupply"); -} + void + CPLEX_NET_Problem::extract(CPLEXProblem *lp, int *colmap, int *rowmap) + { + int status = CPXNETextract(env_, net_, lp->lp_, colmap, rowmap); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETextract"); + } -void -CPLEX_NET_Problem::copybase ( int *astat, int *nstat ) -{ - int status = 0; - status = CPXNETcopybase ( env_, net_, astat, nstat ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETcopybase"); -} - -void -CPLEX_NET_Problem::copynet ( int objsen, int nnodes, double *supply, char **nnames, - int narcs, int *fromnode, int *tonode, double *low, double *up, - double *obj, char **anames ) -{ - int status = 0; - status = CPXNETcopynet ( env_, net_, objsen, nnodes, supply, nnames, narcs, fromnode, tonode, - low, up, obj, anames ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETcopynet"); -} - -void -CPLEX_NET_Problem::delarcs ( int begin, int end ) -{ - int status = 0; - status = CPXNETdelarcs ( env_, net_, begin, end ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETdelarcs"); -} + void + CPLEX_NET_Problem::getarcindex(char *lname, int *index_p) + { + int status = CPXNETgetarcindex(env_, net_, lname, index_p); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETgetarcindex"); + } -void -CPLEX_NET_Problem::delnodes ( int begin, int end ) -{ - int status = 0; - status = CPXNETdelnodes ( env_, net_, begin, end ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETdelnodes"); -} + void + CPLEX_NET_Problem::getarcname(char **nnames, char *namestore, int namespc, int *surplus_p, int begin, int end) + { + int status = CPXNETgetarcname(env_, net_, nnames, namestore, namespc, surplus_p, begin, end); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETgetarcname"); + } -void -CPLEX_NET_Problem::delset ( int *whichnodes, int *whicharcs ) -{ - int status = 0; - status = CPXNETdelset ( env_, net_, whichnodes, whicharcs ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETdelnset"); -} + void + CPLEX_NET_Problem::getarcnodes(int *fromnode, int *tonode, int begin, int end) + { + int status = CPXNETgetarcnodes(env_, net_, fromnode, tonode, begin, end); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETgetarcnodes"); + } -void -CPLEX_NET_Problem::extract ( CPLEXProblem *lp, int *colmap, int *rowmap ) -{ - int status = 0; - status = CPXNETextract ( env_, net_, lp->lp_, colmap, rowmap ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETextract" ); -} + void + CPLEX_NET_Problem::getbase(int *astat, int *nstat) + { + int status = CPXNETgetbase(env_, net_, astat, nstat); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETgetbase"); + } -void -CPLEX_NET_Problem::getarcindex ( char *lname, int *index_p ) -{ - int status = 0; - status = CPXNETgetarcindex ( env_, net_, lname, index_p ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETgetarcindex" ); -} + void + CPLEX_NET_Problem::getdj(double *dj, int begin, int end) + { + int status = CPXNETgetdj(env_, net_, dj, begin, end); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETgetdj"); + } -void -CPLEX_NET_Problem::getarcname ( char **nnames, char *namestore, int namespc, int *surplus_p, int begin, int end ) -{ - int status = 0; - status = CPXNETgetarcname ( env_, net_, nnames, namestore, namespc, surplus_p, begin, end ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETgetarcname" ); -} + int + CPLEX_NET_Problem::getitcnt() + { + int status = CPXNETgetitcnt(env_, net_); + if (status == -1) throw CPLEXException(env_, status, (char*)"CPXNETgetitcnt"); + return status; + } -void -CPLEX_NET_Problem::getarcnodes ( int *fromnode, int *tonode, int begin, int end ) -{ - int status = 0; - status = CPXNETgetarcnodes ( env_, net_, fromnode, tonode, begin, end ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETgetarcnodes" ); -} + void + CPLEX_NET_Problem::getlb(double *low, int begin, int end) + { + int status = CPXNETgetlb(env_, net_, low, begin, end); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETgetlb"); + } -void -CPLEX_NET_Problem::getbase ( int *astat, int *nstat ) -{ - int status = 0; - status = CPXNETgetbase ( env_, net_, astat, nstat ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETgetbase" ); -} + void + CPLEX_NET_Problem::getnodearcs(int *arccnt_p, int *arcbeg, int *arc, int arcspace, int *surplus_p, int begin, int end) + { + int status = CPXNETgetnodearcs(env_, net_, arccnt_p, arcbeg, arc, arcspace, surplus_p, begin, end); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETgetnodearcs"); + } + void + CPLEX_NET_Problem::getnodeindex(char *lname, int *index_p) + { + int status = CPXNETgetnodeindex(env_, net_, lname, index_p); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETgetnodeindex"); + } -void -CPLEX_NET_Problem::getdj ( double *dj, int begin, int end ) -{ - int status = 0; - status = CPXNETgetdj ( env_, net_, dj, begin, end ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETgetdj" ); -} + void + CPLEX_NET_Problem::getnodename(char **nnames, char *namestore, int namespc, int *surplus_p, int begin, int end) + { + int status = CPXNETgetnodename(env_, net_, nnames, namestore, namespc, surplus_p, begin, end); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETgetnodename"); + } + int + CPLEX_NET_Problem::getnumarcs() + { + int status = CPXNETgetnumarcs(env_, net_); + if (status == 0) throw CPLEXException(env_, status, (char*)"CPXNETgetnumarcs"); + return status; + } -int -CPLEX_NET_Problem::getitcnt () -{ - int status = 0; - status = CPXNETgetitcnt ( env_, net_ ); - if ( status == -1 ) - throw CPLEXException (env_, status, "CPXNETgetitcnt" ); - - return status; -} - -void -CPLEX_NET_Problem::getlb ( double *low, int begin, int end ) -{ - int status = 0; - status = CPXNETgetlb ( env_, net_, low, begin, end ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETgetlb" ); -} + int + CPLEX_NET_Problem::getnumnodes() + { + int status = CPXNETgetnumnodes(env_, net_); + if (status == 0) throw CPLEXException(env_, status, (char*)"CPXNETgetnodes"); + return status; + } -void -CPLEX_NET_Problem::getnodearcs ( int *arccnt_p, int *arcbeg, int *arc, int arcspace, int *surplus_p, int begin, int end ) -{ - int status = 0; - status = CPXNETgetnodearcs ( env_, net_, arccnt_p, arcbeg, arc, arcspace, surplus_p, begin, end ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETgetnodearcs" ); -} + void + CPLEX_NET_Problem::getobj(double *obj, int begin, int end) + { + int status = CPXNETgetobj(env_, net_, obj, begin, end); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETgetobj"); + } -void -CPLEX_NET_Problem::getnodeindex ( char *lname, int *index_p ) -{ - int status = 0; - status = CPXNETgetnodeindex ( env_, net_, lname, index_p ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETgetnodeindex" ); -} + int + CPLEX_NET_Problem::getobjsen() + { + int status = CPXNETgetobjsen(env_, net_); + if (status == 0) throw CPLEXException(env_, status, (char*)"CPXNETgetobjsen"); + return status; + } -void -CPLEX_NET_Problem::getnodename ( char **nnames, char *namestore, int namespc, int *surplus_p, int begin, int end ) -{ - int status = 0; - status = CPXNETgetnodename ( env_, net_, nnames, namestore, namespc, surplus_p, begin, end ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETgetnodename" ); -} + double + CPLEX_NET_Problem::getobjval() + { + double objval; + int status = CPXNETgetobjval(env_, net_, &objval); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETgetobjval"); + return objval; + } -int -CPLEX_NET_Problem::getnumarcs ( ) -{ - int status = 0; - status = CPXNETgetnumarcs ( env_, net_ ); - if ( status == 0 ) - throw CPLEXException (env_, status, "CPXNETgetnumarcs" ); - - return status; -} - -int -CPLEX_NET_Problem::getnumnodes ( ) -{ - int status = 0; - status = CPXNETgetnumnodes ( env_, net_ ); - if ( status == 0 ) - throw CPLEXException (env_, status, "CPXNETgetnodes" ); - - return status; -} - -void -CPLEX_NET_Problem::getobj ( double *obj, int begin, int end ) -{ - int status = 0; - status = CPXNETgetobj ( env_, net_, obj, begin, end ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETgetobj" ); -} + int + CPLEX_NET_Problem::getphase1cnt() + { + int status = CPXNETgetphase1cnt(env_, net_); + if (status == -1) throw CPLEXException(env_, status, (char*)"CPXNETgetphase1cnt"); + return status; + } -int -CPLEX_NET_Problem::getobjsen ( ) -{ - int status = 0; - status = CPXNETgetobjsen ( env_, net_ ); - if ( status == 0 ) - throw CPLEXException (env_, status, "CPXNETgetobjsen" ); - - return status; -} - -double -CPLEX_NET_Problem::getobjval ( ) -{ - int status = 0; - double objval; - status = CPXNETgetobjval ( env_, net_, &objval ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETgetobjval" ); - - return objval; -} - -int -CPLEX_NET_Problem::getphase1cnt( ) -{ - int status = 0; - status = CPXNETgetphase1cnt ( env_, net_ ); - if ( status == -1 ) - throw CPLEXException (env_, status, "CPXNETgetphase1cnt" ); - - return status; -} - -void -CPLEX_NET_Problem::getpi ( double *pi, int begin, int end ) -{ - int status = 0; - status = CPXNETgetpi ( env_, net_, pi, begin, end ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETgetpi" ); -} + void + CPLEX_NET_Problem::getpi(double *pi, int begin, int end) + { + int status = CPXNETgetpi(env_, net_, pi, begin, end); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETgetpi"); + } -void -CPLEX_NET_Problem::getprobname ( char *buf, int bufspace, int *surplus_p ) -{ - int status = 0; - status = CPXNETgetprobname ( env_, net_, buf, bufspace, surplus_p ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETgetprobname" ); -} + void + CPLEX_NET_Problem::getprobname(char *buf, int bufspace, int *surplus_p) + { + int status = CPXNETgetprobname(env_, net_, buf, bufspace, surplus_p); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETgetprobname"); + } -void -CPLEX_NET_Problem::getslack ( double *slack, int begin, int end ) -{ - int status = 0; - status = CPXNETgetslack ( env_, net_, slack, begin ,end ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETgetslack" ); -} + void + CPLEX_NET_Problem::getslack(double *slack, int begin, int end) + { + int status = CPXNETgetslack(env_, net_, slack, begin, end); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETgetslack"); + } -int -CPLEX_NET_Problem::getstat( ) -{ - return CPXNETgetstat ( env_, net_ ); -} + int + CPLEX_NET_Problem::getstat() + { + return CPXNETgetstat(env_, net_); + } -void CPLEX_NET_Problem::getsupply ( double *supply, int begin, int end ) -{ - int status = 0; - status = CPXNETgetsupply ( env_, net_, supply, begin ,end ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETgetsupply" ); -} + void + CPLEX_NET_Problem::getsupply(double *supply, int begin, int end) + { + int status = CPXNETgetsupply(env_, net_, supply, begin, end); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETgetsupply"); + } -void -CPLEX_NET_Problem::getub ( double *up, int begin, int end ) -{ - int status = 0; - status = CPXNETgetub ( env_, net_, up, begin ,end ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETgetub" ); -} + void + CPLEX_NET_Problem::getub(double *up, int begin, int end) + { + int status = CPXNETgetub(env_, net_, up, begin, end); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETgetub"); + } -void -CPLEX_NET_Problem::getx ( double *x, int begin, int end ) -{ - int status = 0; - status = CPXNETgetx ( env_, net_, x, begin ,end ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETgetx" ); -} + void + CPLEX_NET_Problem::getx(double *x, int begin, int end) + { + int status = CPXNETgetx(env_, net_, x, begin, end); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETgetx"); + } -void -CPLEX_NET_Problem::primopt ( ) -{ - int status = 0; - status = CPXNETprimopt ( env_, net_ ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETprimopt" ); -} + void + CPLEX_NET_Problem::primopt() + { + int status = CPXNETprimopt(env_, net_); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETprimopt"); + } -void -CPLEX_NET_Problem::readcopybase ( char *filename ) -{ - int status = 0; - status = CPXNETreadcopybase ( env_, net_, filename ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETreadcopybase" ); -} + void + CPLEX_NET_Problem::readcopybase(char *filename) + { + int status = CPXNETreadcopybase(env_, net_, filename); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETreadcopybase"); + } -void -CPLEX_NET_Problem::readcopyprob ( char *filename ) -{ - int status = 0; - status = CPXNETreadcopyprob ( env_, net_, filename ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETreadcopyprob" ); -} + void + CPLEX_NET_Problem::readcopyprob(char *filename) + { + int status = CPXNETreadcopyprob(env_, net_, filename); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETreadcopyprob"); + } -void CPLEX_NET_Problem::solution ( int *netstat_p, double *objval_p , double *x , double *pi , - double *slack , double *dj ) -{ - int status = 0; - status = CPXNETsolution ( env_, net_, netstat_p, objval_p, x, pi, slack, dj ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETsolution" ); -} + void CPLEX_NET_Problem::solution(int *netstat_p, double *objval_p, double *x, double *pi, + double *slack, double *dj) + { + int status = CPXNETsolution(env_, net_, netstat_p, objval_p, x, pi, slack, dj); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETsolution"); + } -void -CPLEX_NET_Problem::writeprob ( char *filename, char *format ) -{ - int status = 0; - status = CPXNETwriteprob ( env_, net_, filename, format ); - if ( status ) - throw CPLEXException (env_, status, "CPXNETwriteprob" ); -} + void + CPLEX_NET_Problem::writeprob(char *filename, char *format) + { + int status = CPXNETwriteprob(env_, net_, filename, format); + if (status) throw CPLEXException(env_, status, (char*)"CPXNETwriteprob"); + } -} // end of namespace CGBase +} // end of namespace CGBase \ No newline at end of file diff --git a/ColumnGeneration/cplexcpp.h b/ColumnGeneration/cplexcpp.h index 0d43792..72557e5 100644 --- a/ColumnGeneration/cplexcpp.h +++ b/ColumnGeneration/cplexcpp.h @@ -2,7 +2,7 @@ #define _CPLEXCPP_H // Header file for C++ example class library -#include "ilcplex\cplex.h" +#include <ilcplex/cplex.h> #include <string> @@ -20,306 +20,316 @@ namespace CGBase { -class CPLEXEnvironment { - private: - CPXENVptr env_; - friend class CPLEXProblem; - friend class CPLEX_NET_Problem; - CPLEXEnvironment (const CPLEXEnvironment &rhs); - CPLEXEnvironment& operator= (const CPLEXEnvironment& rhs); - public: - CPLEXEnvironment (int ldwid = 0, char *licenvstring = NULL); - virtual ~CPLEXEnvironment (); - - // The setparam functions are the equivalent of CPXsetintparam() and - // CPXsetdblparam(), but we use the C++ overloading feature - // to define one function, and let the type of the argument - // determine which parameter function is used. This means - // that the user is responsible for making sure that the CPLEX - // parameters that require double arguments are given double - // values as the "value" parameter - - void setparam (int paramnum, int value); - void setparam (int paramnum, double value); - void setdefaults(); - - // The getParam functions are similar to the setparam functions - // in that the arguments determine whether CPXgetintparam() or - // CPXgetdblparam() are called. Note that if each of the parameter - // numbers became part of one of two enumerated types corresponding - // to parameters that require integer values and parameters that - // require double values, then the getParam() methods could return - // int or double, and the first parameter to the method would - // be the enumerated type. We leave this as an exercise for - // those who are so inclined! - - void getParam (int paramnum, int& rvalue) const; - void getParam (int paramnum, double& rvalue) const; - - // Quick and Dirty, to use the C-Funktions "setmipcallbackfunc" and "setlpcallbackfunc" - CPXENVptr getEnv() { return env_; } -}; - -// A class to handle exception handling. When a CPLEX function fails, -// the method that calls the CPLEX function will throw an exception -// of type CPLEXException (env_, status, funcname), -// and the function what() will return the corresponding string -// message. The parameter env_ is required for the exception so that -// CPLEX can quickly translate an error number to a string. If the -// parameter is NULL, then the string is still found, but the search -// is significantly slower. - -class CPLEXException { - private: - CPXENVptr env_; - int status_; - char *funcname_; - char buffer[512]; - public: - CPLEXException (CPXENVptr env, int status, - char *funcname = "unknown"); - const char *what () const; - const char *funcname () const; - int errcode () const; -}; - -class CPLEXProblem { - friend class CPLEX_NET_Problem; - private: - CPXLPptr lp_; - CPXENVptr env_; - CPLEXProblem (const CPLEXProblem &lp); - CPLEXProblem& operator= (const CPLEXProblem& rhs); - public: - CPLEXProblem (CPLEXEnvironment& renv, - char *probname = "problem"); - virtual ~CPLEXProblem (); - - void read (const char *filename, const char *filetype = 0); - void write (const char *filename, - const char *filetype = NULL) const; - - enum ObjSense { MAXIMIZE = CPX_MAX, MINIMIZE = CPX_MIN }; + class CPLEXEnvironment + { + private: + CPXENVptr env_; + friend class CPLEXProblem; + friend class CPLEX_NET_Problem; + CPLEXEnvironment(const CPLEXEnvironment &rhs); + CPLEXEnvironment& operator= (const CPLEXEnvironment& rhs); + public: + CPLEXEnvironment(int ldwid = 0, char *licenvstring = NULL); + void terminate(); + virtual ~CPLEXEnvironment(); + + // The setparam functions are the equivalent of CPXsetintparam() and + // CPXsetdblparam(), but we use the C++ overloading feature + // to define one function, and let the type of the argument + // determine which parameter function is used. This means + // that the user is responsible for making sure that the CPLEX + // parameters that require double arguments are given double + // values as the "value" parameter + + void setparam(int paramnum, int value); + void setparam(int paramnum, double value); + void setdefaults(); + + // The getParam functions are similar to the setparam functions + // in that the arguments determine whether CPXgetintparam() or + // CPXgetdblparam() are called. Note that if each of the parameter + // numbers became part of one of two enumerated types corresponding + // to parameters that require integer values and parameters that + // require double values, then the getParam() methods could return + // int or double, and the first parameter to the method would + // be the enumerated type. We leave this as an exercise for + // those who are so inclined! + + void getParam(int paramnum, int& rvalue) const; + void getParam(int paramnum, double& rvalue) const; + + // Quick and Dirty, to use the C-Funktions "setmipcallbackfunc" and "setlpcallbackfunc" + CPXENVptr getEnv() { return env_; } + }; + + // A class to handle exception handling. When a CPLEX function fails, + // the method that calls the CPLEX function will throw an exception + // of type CPLEXException (env_, status, funcname), + // and the function what() will return the corresponding string + // message. The parameter env_ is required for the exception so that + // CPLEX can quickly translate an error number to a string. If the + // parameter is NULL, then the string is still found, but the search + // is significantly slower. + + + class CPLEXException + { + private: + CPXENVptr env_; + int status_; + const char *funcname_; + char buffer[512]; + public: + CPLEXException(CPXENVptr env, int status, char *funcname = (char*)"unknown"); + const char *what() const; + const char *funcname() const; + int errcode() const; + }; + + class CPLEXProblem + { + friend class CPLEX_NET_Problem; + private: + CPXLPptr lp_; + CPXENVptr env_; + CPLEXProblem(const CPLEXProblem &lp); + CPLEXProblem& operator= (const CPLEXProblem& rhs); + public: + CPLEXProblem(CPLEXEnvironment& renv, const char *probname = "problem"); + virtual ~CPLEXProblem(); + + void read(const char *filename, const char *filetype = 0); + void write(const char *filename, const char *filetype = NULL) const; + + enum ObjSense { MAXIMIZE = CPX_MAX, MINIMIZE = CPX_MIN }; #if CPX_VERSION >= 900 - enum ProbType { LP = CPXPROB_LP, - MIP = CPXPROB_MILP, - RELAXED = CPXPROB_NODELP, - FIXED = CPXPROB_FIXEDMILP, - QP = CPXPROB_QP }; + enum ProbType + { + LP = CPXPROB_LP, + MIP = CPXPROB_MILP, + RELAXED = CPXPROB_NODELP, + FIXED = CPXPROB_FIXEDMILP, + QP = CPXPROB_QP + }; #else - enum ProbType { LP = CPXPROB_LP, - MIP = CPXPROB_MIP, - RELAXED = CPXPROB_RELAXED, - FIXED = CPXPROB_FIXED, - QP = CPXPROB_QP }; + enum ProbType + { + LP = CPXPROB_LP, + MIP = CPXPROB_MIP, + RELAXED = CPXPROB_RELAXED, + FIXED = CPXPROB_FIXED, + QP = CPXPROB_QP + }; #endif - enum ColumnType { CONTINUES = 'C', BIN = 'B', INT = 'I' }; - enum ConstrSense { LESS = 'L', EQUAL = 'E', GREATER = 'G', RANGED = 'R' }; - enum BoundType { UPPER = 'U', LOWER = 'L', LOWER_AND_UPPER = 'B' }; - - // copylpdata() method is like CPXcopylpwnames(), and CPXcopylp() - void copylpdata (int numcols, int numrows, - ObjSense objsen, double obj[], - double rhs[], char sense[], - int matbeg[], int matcnt[], - int matind[], double matval[], - double lb[], double ub[], - double rngval[] = 0, char *colname[] = 0, - char *rowname[] = 0); - - // copymipstart() method is like CPXcopymipstart() - void copymipstart ( int cnt, int* indices, double* value ); - - // copyctype() method is like CPXcopyctype() - void copyctype ( char ctype[] ); - - // newrows() method is like CPXnewrows() - void newrows (int rcnt, double rhs[], - char sense[], double rngval[] = 0, - char *rowname[] = 0); - - // newcols() method is like CPXnewcols() - void newcols (int ccnt, double obj[], - double lb[], double ub[], - char ctype[] = 0, char *colname[] = 0); - - // addrows() method is like CPXaddrows() - void addrows (int ccnt, int rcnt, int nzcnt, - double rhs[], char sense[], int rmatbeg[], - int rmatind[], double rmatval[], - char *colname[] = 0, char *rowname[] = 0); - - // addcols() method is like CPXaddcols() - void addcols (int ccnt, int nzcnt, double obj[], - int cmatbeg[], int cmatind[], - double cmatval[], double lb[], double ub[], - char *colname[] = 0); - - // delcols() method is like CPXdelCols() - void delcols( int first, int last ); - - // delrows() method is like CPXdelRows() - void delrows( int first, int last ); - - // chgctype is like CPXchgprobtype - void chgprobtype( ProbType cpx_prob ); - - // chgctype is like CPXchgctype - void chgctype( int cnt, int indices[], char ctype[] ); - - // chgobjsen() method is like CPXchgobjsen() - void chgobjsen (ObjSense objsen); - - // chgcoef() method is like CPXchgcoef() - void chgcoef (int i, int j, double val); - - // chgcoeflist() method is like CPXchgcoeflist() - void chgcoeflist (int numcoefs, int rowlist[], int collist[], - double vallist[]); - - // chgbds() method is like CPXchgbds - void chgbds (int cnt, int indices[], char lu[], double bd[] ); - // chgbds() method is like CPXchgobj - void chgobj (int cnt, int indices[], double values[] ); - // chgbds() method is like CPXchgrhs - void chgrhs (int cnt, int indices[], double values[] ); - - // primopt(), dualopt(), hybbaropt() are equivalents of - // CPXprimopt(), CPXdualopt(), CPXhybbaropt() respectively - void primopt (); - void dualopt (); - void baropt (); - void mipopt (); - - // No of iterations - int getitcnt(); - // For the hybrid methods, define an enumerated type to hold - // the possible simplex methods to be used after the initial - // optimization. - - enum OptMethod { PRIMOPT = 'p', DUALOPT = 'd' }; - - void hybbaropt (OptMethod = PRIMOPT); - void hybnetopt (OptMethod = DUALOPT); - - // Solution routines. stat() is CPXgetstat() - int stat () const; - - double objval () const; - double mipobjval() const; - - // The methods X, Slack, Pi, and Dj are like - // CPXgetx(), CPXgetslack(), CPXgetpi() and CPXgetdj(), respectively. - // Note that if the delimiters (begin,end) = (0,-1), we'll assume - // that means get the entire vector. This allows those arguments - // to not be required for the call. - - void getX (double x[], int begin = 0, int end = -1) const; - void getmipX (double x[], int begin = 0, int end = -1) const; - void _getX (double x[], int begin, int end) const; // both LP and MIP - - void getobj (double val[], int begin, int end) const; - void getSlack (double slack[], int begin = 0, int end = -1) const; - void getPi (double Pi[], int begin = 0, int end = -1) const; - void getDj (double Dj[], int begin = 0, int end = -1) const; - void getBase (int cstat[], int rstat[]) const; - void getRHS(double rhs[], int begin=0, int end=-1 ); - - // Some useful query functions - int numcols (void) const; - int numrows (void) const; - ProbType probtype(void) const; - - // Methods to restart optimization - void copyStart( int cstat[], int rstat[], double cprim[], double rprim[], double cdual[], double rdual[] ); + enum ColumnType { CONTINUES = 'C', BIN = 'B', INT = 'I' }; + enum ConstrSense { LESS = 'L', EQUAL = 'E', GREATER = 'G', RANGED = 'R' }; + enum BoundType { UPPER = 'U', LOWER = 'L', LOWER_AND_UPPER = 'B' }; + + // copylpdata() method is like CPXcopylpwnames(), and CPXcopylp() + void copylpdata(int numcols, int numrows, + ObjSense objsen, double obj[], + double rhs[], char sense[], + int matbeg[], int matcnt[], + int matind[], double matval[], + double lb[], double ub[], + double rngval[] = 0, char *colname[] = 0, + char *rowname[] = 0); + + // copymipstart() method is like CPXcopymipstart() + void copymipstart(int cnt, int* indices, double* value); + + // copyctype() method is like CPXcopyctype() + void copyctype(char ctype[]); + + // newrows() method is like CPXnewrows() + void newrows(int rcnt, double rhs[], + char sense[], double rngval[] = 0, + char *rowname[] = 0); + + // newcols() method is like CPXnewcols() + void newcols(int ccnt, double obj[], + double lb[], double ub[], + char ctype[] = 0, char *colname[] = 0); + + // addrows() method is like CPXaddrows() + void addrows(int ccnt, int rcnt, int nzcnt, + double rhs[], char sense[], int rmatbeg[], + int rmatind[], double rmatval[], + char *colname[] = 0, char *rowname[] = 0); + + // addcols() method is like CPXaddcols() + void addcols(int ccnt, int nzcnt, double obj[], + int cmatbeg[], int cmatind[], + double cmatval[], double lb[], double ub[], + char *colname[] = 0); + + // delcols() method is like CPXdelCols() + void delcols(int first, int last); + + // delrows() method is like CPXdelRows() + void delrows(int first, int last); + + // chgctype is like CPXchgprobtype + void chgprobtype(ProbType cpx_prob); + + // chgctype is like CPXchgctype + void chgctype(int cnt, int indices[], char ctype[]); + + // chgobjsen() method is like CPXchgobjsen() + void chgobjsen(ObjSense objsen); + + // chgcoef() method is like CPXchgcoef() + void chgcoef(int i, int j, double val); + + // chgcoeflist() method is like CPXchgcoeflist() + void chgcoeflist(int numcoefs, int rowlist[], int collist[], + double vallist[]); + + // chgbds() method is like CPXchgbds + void chgbds(int cnt, int indices[], char lu[], double bd[]); + // chgbds() method is like CPXchgobj + void chgobj(int cnt, int indices[], double values[]); + // chgbds() method is like CPXchgrhs + void chgrhs(int cnt, int indices[], double values[]); + + // primopt(), dualopt(), hybbaropt() are equivalents of + // CPXprimopt(), CPXdualopt(), CPXhybbaropt() respectively + void primopt(); + void dualopt(); + void baropt(); + void mipopt(); + + // No of iterations + int getitcnt(); + // For the hybrid methods, define an enumerated type to hold + // the possible simplex methods to be used after the initial + // optimization. + + enum OptMethod { PRIMOPT = 'p', DUALOPT = 'd' }; + + void hybbaropt(OptMethod = PRIMOPT); + void hybnetopt(OptMethod = DUALOPT); + + // Solution routines. stat() is CPXgetstat() + int stat() const; + + double objval() const; + double mipobjval() const; + + // The methods X, Slack, Pi, and Dj are like + // CPXgetx(), CPXgetslack(), CPXgetpi() and CPXgetdj(), respectively. + // Note that if the delimiters (begin,end) = (0,-1), we'll assume + // that means get the entire vector. This allows those arguments + // to not be required for the call. + + void getX(double x[], int begin = 0, int end = -1) const; + void getmipX(double x[], int begin = 0, int end = -1) const; + void _getX(double x[], int begin, int end) const; // both LP and MIP + + void getobj(double val[], int begin, int end) const; + void getSlack(double slack[], int begin = 0, int end = -1) const; + void getPi(double Pi[], int begin = 0, int end = -1) const; + void getDj(double Dj[], int begin = 0, int end = -1) const; + void getBase(int cstat[], int rstat[]) const; + void getRHS(double rhs[], int begin = 0, int end = -1); + + // Some useful query functions + int numcols(void) const; + int numrows(void) const; + ProbType probtype(void) const; + + // Methods to restart optimization + void copyStart(int cstat[], int rstat[], double cprim[], double rprim[], double cdual[], double rdual[]); // Zum Testen der LP-Matrix eingefuehrt // Rueckgabewert ist ein String, der alle Fehler enthaelt - std::string CheckMatrix (int numcols, int numrows, int numnzs, - ObjSense objsen, double obj[], - double rhs[], char sense[], char ctype[], - int matbeg[], int matcnt[], - int matind[], double matval[], - double lb[], double ub[], - double rngval[] = 0, char *colname[] = 0, - char *rowname[] = 0, - const double d_minvalue = -CPX_INFBOUND, - const double d_maxvalue = CPX_INFBOUND ); + std::string CheckMatrix(int numcols, int numrows, int numnzs, + ObjSense objsen, double obj[], + double rhs[], char sense[], char ctype[], + int matbeg[], int matcnt[], + int matind[], double matval[], + double lb[], double ub[], + double rngval[] = 0, char *colname[] = 0, + char *rowname[] = 0, + const double d_minvalue = -CPX_INFBOUND, + const double d_maxvalue = CPX_INFBOUND); // Gibt ein LP als Excel-Matrix im csv-Format aus // method is like CPXcopylp(), - std::string DumpExcelMatrix (int numcols, int numrows, - ObjSense objsen, double obj[], - double rhs[], char sense[], - int matbeg[], int matcnt[], - int matind[], double matval[], - double lb[], double ub[], - double rngval[] = 0, char *colname[] = 0, - char *rowname[] = 0); -}; - - -class CPLEX_NET_Problem { - private: - CPXNETptr net_; - CPXENVptr env_; - CPLEX_NET_Problem (const CPLEX_NET_Problem &lp ); - CPLEX_NET_Problem& operator= (const CPLEX_NET_Problem& rhs ); - public: - CPLEX_NET_Problem (CPLEXEnvironment& renv, char *probname = "network problem" ); - virtual ~CPLEX_NET_Problem (); - void addarcs ( int narcs, int *fromnode, int *tonode, double *low = NULL, double *up = NULL, double *obj = NULL, char **anames = NULL); - void addnodes ( int nnodes, double *supply = NULL, char **nnames = NULL); - void basewrite ( char *filename ); - void checkcopynet ( int objsen, int nnodes, double *supply, char **nnames, - int narcs, int *fromnode, int *tonode, double *low = NULL, double *up = NULL, - double *obj = NULL, char **anames = NULL ); - void chgarcname ( int cnt, int *indices, char **anames ); - void chgarcnodes ( int cnt, int *index, int *fromnode, int *tonode ); - void chgbds ( int cnt, int *index, char *lu, double *bd ); - void chgname ( int key, int index, char *name ); - void chgnodename ( int cnt, int *indices, char **name ); - void chgobj ( int cnt, int *index, double *obj ); - void chgobjsen ( int maxormin ); - void chgsupply ( int cnt, int *index, double *supply ); - void copybase ( int *astat, int *nstat ); - void copynet ( int objsen, int nnodes, double *supply, char **nnames, - int narcs, int *fromnode, int *tonode, double *low = NULL, double *up = NULL, - double *obj = NULL, char **anames = NULL ); - void delarcs ( int begin, int end ); - void delnodes ( int begin, int end ); - void delset ( int *whichnodes = NULL, int *whicharcs = NULL ); - void extract ( CPLEXProblem *lp, int *colmap = NULL, int *rowmap = NULL ); - void getarcindex ( char *lname, int *index_p ); - void getarcname ( char **nnames, char *namestore, int namespc, int *surplus_p, int begin, int end); - void getarcnodes ( int *fromnode, int *tonode, int begin, int end ); - void getbase ( int *astat, int *nstat ); - void getdj ( double *dj, int begin, int end ); - int getitcnt (); - void getlb ( double *low, int begin, int end ); - void getnodearcs ( int *arccnt_p, int *arcbeg, int *arc, int arcspace, int *surplus_p, int begin, int end ); - void getnodeindex ( char *lname, int *index_p ); - void getnodename ( char **nnames, char *namestore, int namespc, int *surplus_p, int begin, int end); - int getnumarcs ( ); - int getnumnodes ( ); - void getobj ( double *obj, int begin, int end ); - int getobjsen ( ); - double getobjval ( ); - int getphase1cnt( ); - void getpi ( double *pi, int begin, int end ); - void getprobname ( char *buf, int bufspace, int *surplus_p ); - void getslack ( double *slack, int begin, int end ); - int getstat( ); - void getsupply ( double *supply, int begin, int end ); - void getub ( double *up, int begin, int end ); - void getx ( double *x, int begin, int end ); - void primopt ( ); - void readcopybase ( char *filename ); - void readcopyprob ( char *filename ); - void solution ( int *netstat_p, double *objval_p = NULL, double *x = NULL, double *pi = NULL, - double *slack = NULL, double *dj = NULL); - void writeprob ( char *filename, char *format = NULL); -}; + std::string DumpExcelMatrix(int numcols, int numrows, + ObjSense objsen, double obj[], + double rhs[], char sense[], + int matbeg[], int matcnt[], + int matind[], double matval[], + double lb[], double ub[], + double rngval[] = 0, char *colname[] = 0, + char *rowname[] = 0); + }; + + + class CPLEX_NET_Problem + { + private: + CPXNETptr net_; + CPXENVptr env_; + CPLEX_NET_Problem(const CPLEX_NET_Problem &lp); + CPLEX_NET_Problem& operator= (const CPLEX_NET_Problem& rhs); + public: + CPLEX_NET_Problem(CPLEXEnvironment& renv, const char *probname = "network problem"); + virtual ~CPLEX_NET_Problem(); + void terminate(); + + void addarcs(int narcs, int *fromnode, int *tonode, double *low = NULL, double *up = NULL, double *obj = NULL, char **anames = NULL); + void addnodes(int nnodes, double *supply = NULL, char **nnames = NULL); + void basewrite(char *filename); + void checkcopynet(int objsen, int nnodes, double *supply, char **nnames, + int narcs, int *fromnode, int *tonode, double *low = NULL, double *up = NULL, + double *obj = NULL, char **anames = NULL); + void chgarcname(int cnt, int *indices, char **anames); + void chgarcnodes(int cnt, int *index, int *fromnode, int *tonode); + void chgbds(int cnt, int *index, char *lu, double *bd); + void chgname(int key, int index, char *name); + void chgnodename(int cnt, int *indices, char **name); + void chgobj(int cnt, int *index, double *obj); + void chgobjsen(int maxormin); + void chgsupply(int cnt, int *index, double *supply); + void copybase(int *astat, int *nstat); + void copynet(int objsen, int nnodes, double *supply, char **nnames, + int narcs, int *fromnode, int *tonode, double *low = NULL, double *up = NULL, + double *obj = NULL, char **anames = NULL); + void delarcs(int begin, int end); + void delnodes(int begin, int end); + void delset(int *whichnodes = NULL, int *whicharcs = NULL); + void extract(CPLEXProblem *lp, int *colmap = NULL, int *rowmap = NULL); + void getarcindex(char *lname, int *index_p); + void getarcname(char **nnames, char *namestore, int namespc, int *surplus_p, int begin, int end); + void getarcnodes(int *fromnode, int *tonode, int begin, int end); + void getbase(int *astat, int *nstat); + void getdj(double *dj, int begin, int end); + int getitcnt(); + void getlb(double *low, int begin, int end); + void getnodearcs(int *arccnt_p, int *arcbeg, int *arc, int arcspace, int *surplus_p, int begin, int end); + void getnodeindex(char *lname, int *index_p); + void getnodename(char **nnames, char *namestore, int namespc, int *surplus_p, int begin, int end); + int getnumarcs(); + int getnumnodes(); + void getobj(double *obj, int begin, int end); + int getobjsen(); + double getobjval(); + int getphase1cnt(); + void getpi(double *pi, int begin, int end); + void getprobname(char *buf, int bufspace, int *surplus_p); + void getslack(double *slack, int begin, int end); + int getstat(); + void getsupply(double *supply, int begin, int end); + void getub(double *up, int begin, int end); + void getx(double *x, int begin, int end); + void primopt(); + void readcopybase(char *filename); + void readcopyprob(char *filename); + void solution(int *netstat_p, double *objval_p = NULL, double *x = NULL, double *pi = NULL, double *slack = NULL, double *dj = NULL); + void writeprob(char *filename, char *format = NULL); + }; } // end of namespace CGBase diff --git a/bcp_cvrptw.cpp b/bcp_cvrptw.cpp index 4b33ae7..7ed0ac8 100644 --- a/bcp_cvrptw.cpp +++ b/bcp_cvrptw.cpp @@ -196,8 +196,8 @@ void c_ControllerCVRPTW::WriteSolutionInFile( string FileName ) c_StringField network( 610, "Network|Settings", this->NetworkOfTasks()? "tasks": "scheduleParts"); stringstream network_sizes; - for each( int nwSize in this->HeuristicPricersNetworkSizes() ) - network_sizes << nwSize << "_"; + for ( auto nwSize= HeuristicPricersNetworkSizes().begin(); nwSize != HeuristicPricersNetworkSizes().end(); nwSize++ ) + network_sizes << *nwSize << "_"; c_StringField networkSizes( 611, "networkSizes|Settings", network_sizes.str() ); c_BoolField regularVisits ( 614, "RegularVisits|Settings", this->RegularVisits() ); @@ -345,31 +345,31 @@ void c_ControllerCVRPTW::AddPricingProblems() if (UseHeuristicDominance()){ //Add pricers with every second network size with heuristic dominance int cnt = 0; - for each( int i in HeuristicPricersNetworkSizes() ) { + for (auto i = HeuristicPricersNetworkSizes().begin(); i != HeuristicPricersNetworkSizes().end();i++ ) { if( cnt%2 == 0 ){ - hierarchies[d]->Add( new c_PricingSolverCVRPTW( this, i, d, false ) ); - if ( i > NumNodes() ){ + hierarchies[d]->Add( new c_PricingSolverCVRPTW( this, *i, d, false ) ); + if ( *i > NumNodes() ){ break; } } cnt++; } //Add pricers with all network sizes with exact dominance - for each( int i in HeuristicPricersNetworkSizes() ) { - if ( i > 0.5 * NumNodes() ){ //Add only reduced networks with at most half of all nodes + for (auto i = HeuristicPricersNetworkSizes().begin(); i != HeuristicPricersNetworkSizes().end(); i++) { + if ( *i > 0.5 * NumNodes() ){ //Add only reduced networks with at most half of all nodes break; } - hierarchies[d]->Add( new c_PricingSolverCVRPTW( this, i, d, true ) ); + hierarchies[d]->Add( new c_PricingSolverCVRPTW( this, *i, d, true ) ); } //Finally add an exact dominance PricingSolver with all nodes hierarchies[d]->Add( new c_PricingSolverCVRPTW( this, 10000, d, true ) ); } else{ - for each( int i in HeuristicPricersNetworkSizes() ) { - if ( i > 0.5 * NumNodes() ){ //Add only reduced networks with at most half of all nodes + for (auto i = HeuristicPricersNetworkSizes().begin(); i != HeuristicPricersNetworkSizes().end();i++ ) { + if ( *i > 0.5 * NumNodes() ){ //Add only reduced networks with at most half of all nodes break; } - hierarchies[d]->Add( new c_PricingSolverCVRPTW( this, i, d, true ) ); + hierarchies[d]->Add( new c_PricingSolverCVRPTW( this, *i, d, true ) ); } //Finally add an exact dominance PricingSolver with all nodes hierarchies[d]->Add( new c_PricingSolverCVRPTW( this, 10000, d, true ) ); @@ -590,10 +590,10 @@ bool c_ControllerCVRPTW::Disaggregate() //Delete Aggregated SR Cuts list<c_Constraint*> cut_list_toRemove; - for each(c_Constraint* con in rmp->Constraints()){ - c_Constraint_PVRPTW* con_pvrptw = (c_Constraint_PVRPTW*) con; + for (int i = 0; i < rmp->Constraints().size(); i++) { + c_Constraint_PVRPTW* con_pvrptw = (c_Constraint_PVRPTW*) (rmp->Constraints()[i]); if( con_pvrptw->Type() == c_RMP_CVRPTW::eAggregatedSubsetRowCut ) - cut_list_toRemove.push_back(con); + cut_list_toRemove.push_back(con_pvrptw); } rmp->RemoveConstraints( cut_list_toRemove ); int oldNumSRCuts = NumSubsetRowCuts(); @@ -603,10 +603,10 @@ bool c_ControllerCVRPTW::Disaggregate() if( RegularVisits() ){ //Remove aggegrated constraints list<c_Constraint*> con_list_toRemove; - for each(c_Constraint* con in rmp->Constraints()){ - c_Constraint_PVRPTW* con_pvrptw = (c_Constraint_PVRPTW*) con; + for (int i = 0; i < rmp->Constraints().size(); i++) { + c_Constraint_PVRPTW* con_pvrptw = (c_Constraint_PVRPTW*)(rmp->Constraints()[i]); if( con_pvrptw->Type() == c_RMP_CVRPTW::eVisitFrequency ) - con_list_toRemove.push_back(con); + con_list_toRemove.push_back(con_pvrptw); } rmp->RemoveConstraints( con_list_toRemove ); @@ -619,8 +619,8 @@ bool c_ControllerCVRPTW::Disaggregate() con_list_toAdd.push_back( new c_GlobalValidConstraint_PVRPTW( this, 'G', 1.0, 0.0, c_RMP_CVRPTW::eCOVERING, i ) ); for ( int i=0; i<NumNodes(); i++ ) if ( IsCustomerNode(i) ) - for each ( int sPart in GetAllowedScheduleParts(i) ) - con_list_toAdd.push_back( new c_GlobalValidConstraint_PVRPTW( this, 'G', 0.0, 0.0, c_RMP_CVRPTW::eLINKING, sPart) ); + for ( auto sPart=GetAllowedScheduleParts(i).begin();sPart!= GetAllowedScheduleParts(i).end();sPart++) + con_list_toAdd.push_back( new c_GlobalValidConstraint_PVRPTW( this, 'G', 0.0, 0.0, c_RMP_CVRPTW::eLINKING, *sPart) ); rmp->AddConstraints(con_list_toAdd); @@ -638,8 +638,8 @@ bool c_ControllerCVRPTW::Disaggregate() for ( int i=0; i<NumNodes(); i++ ){ if ( IsCustomerNode(i) ){ int scheduleId = 0; - for each( vector<bool> schedule in GetAllowedSchedules(i) ){ - col_list_toAdd.push_back( new c_ScheduleColumnCVRPTW( this, i, scheduleId, schedule) ); + for (auto schedule = GetAllowedSchedules(i).begin(); schedule != GetAllowedSchedules(i).end(); schedule++) { + col_list_toAdd.push_back( new c_ScheduleColumnCVRPTW( this, i, scheduleId, *schedule) ); scheduleId++; } } @@ -724,9 +724,9 @@ bool c_ControllerCVRPTW::SolveMIPWithOriginalMP() //delete branch-and-bound constraints (SumNumTrains & BranchOnEdge-Enforced) int cntAlreadyDeleted = 0; - for each(c_Constraint* con in rmp->Constraints()){ - int index = con->Index(); - if(!con->IsGloballyValid()){ + for (auto con = rmp->Constraints().begin(); con != rmp->Constraints().end();con++) { + int index = (*con)->Index(); + if(!(*con)->IsGloballyValid()){ rmp->delrows(index-cntAlreadyDeleted, index-cntAlreadyDeleted); cntAlreadyDeleted++; } @@ -828,9 +828,9 @@ bool c_ControllerCVRPTW::GreedyRepair() double cost = 0.0; - for each( vector<int> route in routes ){ - dayOfRoutes.push_back( GetSchedulePart(route[0])->getStartDay() ); - cost += calculateCostOfRoute( route ); + for (auto route = routes.begin(); route != routes.end();route++) { + dayOfRoutes.push_back( GetSchedulePart((*route)[0])->getStartDay() ); + cost += calculateCostOfRoute( *route ); } cout << "Actual routing costs: " << cost << endl; @@ -862,8 +862,8 @@ bool c_ControllerCVRPTW::GreedyRepair() } cost = 0.0; - for each( vector<int> route in routes ){ - cost += calculateCostOfRoute( route ); + for (auto route = routes.begin(); route != routes.end();route++ ) { + cost += calculateCostOfRoute( *route ); } cout << "Routing costs after removal of duplicates: " << cost << endl; @@ -875,14 +875,14 @@ bool c_ControllerCVRPTW::GreedyRepair() for ( int i=0; i< NumNodes(); i++ ){ if ( IsCustomerNode(i) ){ int scheduleId = 0; - for each( vector<bool> schedule in GetAllowedSchedules(i) ){ + for (auto schedule = GetAllowedSchedules(i).begin(); schedule != GetAllowedSchedules(i).end();schedule++) { if( v_contains(dummies, i) ){ bool schedulePartInserted; //try every possible schedule - for each (int spId in GetScheduleParts(i, scheduleId) ){ + for (auto spId = GetScheduleParts(i, scheduleId).begin(); spId != GetScheduleParts(i, scheduleId).end();spId++) { schedulePartInserted = false; for (int r = 0; r < routes.size(); r++ ){ - if( dayOfRoutes[r] == GetSchedulePart(spId)->getStartDay() ){ + if( dayOfRoutes[r] == GetSchedulePart(*spId)->getStartDay() ){ //try insertion at every place for( int p = 0; p < routes[r].size(); p++ ){ new_route.clear(); @@ -890,7 +890,7 @@ bool c_ControllerCVRPTW::GreedyRepair() for( int p1 = 0; p1 < p; p1++ ){ new_route.push_back( routes[r][p1] ); } - new_route.push_back(spId); + new_route.push_back(*spId); for( int p2 = p; p2 < routes[r].size(); p2++ ){ new_route.push_back( routes[r][p2] ); } @@ -924,8 +924,8 @@ bool c_ControllerCVRPTW::GreedyRepair() } cost = 0.0; - for each( vector<int> route in routes ){ - cost += calculateCostOfRoute( route ); + for (auto route = routes.begin();route!=routes.end();route++){ + cost += calculateCostOfRoute( *route ); } if( successfullyInserted == dummies.size() ){ @@ -1063,11 +1063,11 @@ c_TourColumnCVRPTW::c_TourColumnCVRPTW(c_Controller* controller, const vector<in //for ( int t=0; t<(int)v_route.size(); t++ ){ v_routeOfSchedulePartIds.push_back( v_route[t] ); } - for each( int spId in v_route ){ - int cust = ctlr->GetSchedulePart( spId )->getCustomer(); - int d = ctlr->GetSchedulePart( spId )->getStartDay(); + for (auto spId = v_route.begin(); spId != route.end();spId++ ) { + int cust = ctlr->GetSchedulePart( *spId )->getCustomer(); + int d = ctlr->GetSchedulePart( *spId )->getStartDay(); v_routeOfTasks.push_back( ctlr->GetTask(cust, d) ); - int endDay = ctlr->GetSchedulePart( spId )->getEndDay(); + int endDay = ctlr->GetSchedulePart( *spId )->getEndDay(); while ( d != endDay) { d = (d+1)%ctlr->PlanningHorizon(); v_routeOfTasks.push_back( ctlr->GetTask(cust, d) ); @@ -1108,8 +1108,8 @@ int c_TourColumnCVRPTW::GetCPXColumn( double& cost, int* ind, double* val, doubl //create map based on customers instead of schedule parts because with NG, a customer can for non-standard instances be visited several times with different schedule parts //and cplex does not allow two coefficients for the same row map<int,int> cnt_visits; //customer is key, number of visits is value - for each( int SPId in v_routeOfSchedulePartIds){ - cnt_visits[ctlr->GetSchedulePart(SPId)->getCustomer()] += ctlr->GetNumTasksCoveredBySP(SPId); + for (auto SPId = v_routeOfSchedulePartIds.begin(); SPId != v_routeOfSchedulePartIds.end();SPId++) { + cnt_visits[ctlr->GetSchedulePart(*SPId)->getCustomer()] += ctlr->GetNumTasksCoveredBySP(*SPId); } for ( auto ii=cnt_visits.begin(); ii!=cnt_visits.end(); ++ii ){ //consider this tour for visit frequency requirement @@ -1120,8 +1120,8 @@ int c_TourColumnCVRPTW::GetCPXColumn( double& cost, int* ind, double* val, doubl //If the model is aggregated, only routes for day 0 exists, so only schedule parts starting at day 0 are active. The schedule columns have to accept schedule parts that cover the correct number of tasks // determine entries for covering constraints map<int,int> cnt_visits; //schedulePartId is key, number of visits is value - for each( int SPId in v_routeOfSchedulePartIds){ - cnt_visits[SPId]++; + for (auto SPId = v_routeOfSchedulePartIds.begin(); SPId != v_routeOfSchedulePartIds.end(); SPId++) { + cnt_visits[*SPId]++; } for ( auto ii=cnt_visits.begin(); ii!=cnt_visits.end(); ++ii ){ ////link tour columns with scheduleParts. @@ -1145,8 +1145,8 @@ int c_TourColumnCVRPTW::GetCPXColumn( double& cost, int* ind, double* val, doubl int coef = 0; for( int d = 0; d <ctlr->PlanningHorizon(); d++){ alphasum[d] = 0; - for each(int cust in cut->GetSubset(d)){ - alphasum[d] += countVisits(cust); + for (auto cust = cut->GetSubset(d).begin(); cust != cut->GetSubset(d).end();cust++) { + alphasum[d] += countVisits(*cust); } coef += floor(alphasum[d]/2); } @@ -1163,8 +1163,8 @@ int c_TourColumnCVRPTW::GetCPXColumn( double& cost, int* ind, double* val, doubl c_SubsetRowCutConstraintCVRPTW* cut = (c_SubsetRowCutConstraintCVRPTW*) ctlr->RMP()->Constraint( c_RMP_CVRPTW::eSubsetRowCut, cutId ); //count visits of this tour column of customer-vertices in cut subset double alphasum = 0; - for each(int cust in cut->GetSubset()) - alphasum += countVisits(cust); + for (auto cust = cut->GetSubset().begin(); cust != cut->GetSubset().end();cust++) + alphasum += countVisits(*cust); if( alphasum >= 2 ){ ind[idx] = ctlr->RMP()->ConstraintIndex( c_RMP_CVRPTW::eSubsetRowCut, cutId ); @@ -1366,17 +1366,17 @@ int c_ScheduleColumnCVRPTW::GetCPXColumn(double& cost, int* ind, double* val, do val[idx++] = 1.0; if( !ctlr->IsAggregated() ){ - for each( int sPart in ctlr->GetScheduleParts(customer, sId) ){ + for (auto sPart = ctlr->GetScheduleParts(customer, sId).begin(); sPart != ctlr->GetScheduleParts(customer, sId).end();sPart++) { /*ind[idx] = ctlr->RMP()->ConstraintIndex( c_RMP_CVRPTW::eLINKING, customer, ctlr->GetSchedulePart(sPart)->getStartDay(), ctlr->GetSchedulePart(sPart)->getEndDay() );*/ - ind[idx] = ctlr->RMP()->ConstraintIndex( c_RMP_CVRPTW::eLINKING, sPart ); + ind[idx] = ctlr->RMP()->ConstraintIndex( c_RMP_CVRPTW::eLINKING, *sPart ); val[idx++] = -1.0; } } else{ //in case of regular schedules, the schedule columns are not necessary (not existing) while the model is aggregated (thus no error occurs) //every schedule part is shifted to its aquivalent on day 0 map<int,int> cnt_visits; //schedulePartId is key, number of schedule parts with this length in the schedule is its value - for each( int sPart in ctlr->GetScheduleParts(customer, sId) ){ - int sPartShiftedToFirstPeriod = ctlr->GetSchedulePartShiftedToFirstPeriod(sPart); + for (auto sPart = ctlr->GetScheduleParts(customer, sId).begin(); sPart != ctlr->GetScheduleParts(customer, sId).end();sPart++) { + int sPartShiftedToFirstPeriod = ctlr->GetSchedulePartShiftedToFirstPeriod(*sPart); cnt_visits[sPartShiftedToFirstPeriod]++; } @@ -1407,8 +1407,8 @@ int c_ScheduleColumnCVRPTW::GetCPXColumn(double& cost, int* ind, double* val, do void c_ScheduleColumnCVRPTW::OutputInOStream(ostream& s) const { s << "Cust: " << customer << " Schedule: ["; - for each (int d in v_days ){ - s << d << ", "; + for (auto d = v_days.begin(); d != v_days.end();d++ ) { + s << *d << ", "; } s << "]"; } @@ -1492,11 +1492,11 @@ void c_DualVariablesCVRPTW::OutputInOStream( ostream& s ) const if ( ctlr->IsCustomerNode(i) ) s << "Pi( " << i << ")=" << pi(i) << endl; - for ( int i = 0; i<ctlr->NumNodes(); i++ ) - if ( ctlr->IsCustomerNode(i) ) - for each (int sPart in ctlr->GetAllowedScheduleParts(i) ){ - s << "Rho( " << sPart << "=["<< i << "," << ctlr->GetSchedulePart(sPart)->getStartDay() << "," << ctlr->GetSchedulePart(sPart)->getEndDay() << "])="; - s << rho(sPart) << endl; + for (int i = 0; i < ctlr->NumNodes(); i++) + if (ctlr->IsCustomerNode(i)) + for (auto sPart = ctlr->GetAllowedScheduleParts(i).begin(); sPart != ctlr->GetAllowedScheduleParts(i).end();sPart++) { + s << "Rho( " << *sPart << "=["<< i << "," << ctlr->GetSchedulePart(*sPart)->getStartDay() << "," << ctlr->GetSchedulePart(*sPart)->getEndDay() << "])="; + s << rho(*sPart) << endl; } } @@ -1558,8 +1558,8 @@ void c_RMP_CVRPTW::InitializeFirstRMP() // Startmodell wird hier erstellt for ( int i=0; i<ctlr->NumNodes(); i++ ) if ( ctlr->IsCustomerNode(i) ) - for each ( int sPart in ctlr->GetAllowedScheduleParts(i) ) - AddConstraint( new c_GlobalValidConstraint_PVRPTW( ctlr, 'G', 0.0, 0.0, c_RMP_CVRPTW::eLINKING, sPart)); //i, ctlr->GetSchedulePart(sPart)->getStartDay() , ctlr->GetSchedulePart(sPart)->getEndDay() ) ); + for ( auto sPart = ctlr->GetAllowedScheduleParts(i).begin(); sPart != ctlr->GetAllowedScheduleParts(i).end();sPart++) + AddConstraint( new c_GlobalValidConstraint_PVRPTW( ctlr, 'G', 0.0, 0.0, c_RMP_CVRPTW::eLINKING, *sPart)); //i, ctlr->GetSchedulePart(sPart)->getStartDay() , ctlr->GetSchedulePart(sPart)->getEndDay() ) ); } for ( int d = 0; d < ctlr->PlanningHorizon(); d++ ){ @@ -1593,8 +1593,8 @@ void c_RMP_CVRPTW::InitializeFirstRMP() // Startmodell wird hier erstellt for ( int i=0; i<ctlr->NumNodes(); i++ ){ if ( ctlr->IsCustomerNode(i) ){ int scheduleId = 0; - for each( vector<bool> schedule in ctlr->GetAllowedSchedules(i) ){ - col_list.push_back( new c_ScheduleColumnCVRPTW( ctlr, i, scheduleId, schedule) ); + for (auto schedule = ctlr->GetAllowedSchedules(i).begin(); schedule != ctlr->GetAllowedSchedules(i).end();schedule++) { + col_list.push_back( new c_ScheduleColumnCVRPTW( ctlr, i, scheduleId, *schedule) ); scheduleId++; } } @@ -1713,22 +1713,22 @@ bool c_RMP_CVRPTW::IsFeasible() const void c_RMP_CVRPTW::RemoveAggregatedConstraints(list<c_BranchAndBoundConstraint*>& constraint_list) { list<c_BranchAndBoundConstraint*> con_list_to_delete; - for each( c_BranchAndBoundConstraint* con in constraint_list ){ + for (auto con = constraint_list.begin(); con != constraint_list.end();con++) { bool isAggregatedCut = false; - if (dynamic_cast<c_BranchAndBoundConstraintCVRPTW*>(con) == 0){ - for each( c_Constraint* cut in (con)->RMPConstraints()){ - c_Constraint_PVRPTW* pvrptw_cut = (c_Constraint_PVRPTW*) cut; + if (dynamic_cast<c_BranchAndBoundConstraintCVRPTW*>(*con) == 0){ + for (auto cut = (*con)->RMPConstraints().begin(); cut != (*con)->RMPConstraints().end();cut++) { + c_Constraint_PVRPTW* pvrptw_cut = (c_Constraint_PVRPTW*) *cut; if( pvrptw_cut->Type() == c_RMP_CVRPTW::eAggregatedSubsetRowCut ){ isAggregatedCut = true; break; } } if( isAggregatedCut ) - con_list_to_delete.push_back(con); + con_list_to_delete.push_back(*con); } } - for each( c_BranchAndBoundConstraint* con in con_list_to_delete ){ - constraint_list.remove(con); + for (auto con = con_list_to_delete.begin(); con != con_list_to_delete.end();con++) { + constraint_list.remove(*con); } //throw std::logic_error("The method or operation is not implemented."); } @@ -2649,8 +2649,8 @@ void c_BranchAndBoundNodeCVRPTW::GetConstraints(list<c_BranchAndBoundConstraint* bool addBaBConstraint = true; //SR-Cuts are globally valid, don't add them again if( ctlr->StartWithAggregation() && !ctlr->IsAggregated() ){ //Aggregated SR Cuts no longer valid, don't add them - for each( c_Constraint* cut in (*iter)->RMPConstraints()){ - if( cut->IsGloballyValid() ){ + for (auto cut = (*iter)->RMPConstraints().begin(); cut != (*iter)->RMPConstraints().end();cut++) { + if( (*cut)->IsGloballyValid() ){ addBaBConstraint = false; break; } @@ -2669,8 +2669,8 @@ void c_BranchAndBoundNodeCVRPTW::GetConstraints(list<c_BranchAndBoundConstraint* bool addBaBConstraint = true; //SR-Cuts are globally valid, don't add them again if( ctlr->StartWithAggregation() && !ctlr->IsAggregated() ){ //Aggregated SR Cuts no longer valid, don't add them - for each( c_Constraint* cut in (*iter)->RMPConstraints()){ - if( cut->IsGloballyValid() ){ + for (auto cut = (*iter)->RMPConstraints().begin(); cut != (*iter)->RMPConstraints().end();cut++) { + if( (*cut)->IsGloballyValid() ){ /*c_Constraint_PVRPTW* pvrptw_cut = (c_Constraint_PVRPTW*) cut; if( pvrptw_cut->Type() == c_RMP_CVRPTW::eAggregatedSubsetRowCut ){*/ addBaBConstraint = false; @@ -3081,10 +3081,10 @@ c_PricingSolverCVRPTW::c_PricingSolverCVRPTW( c_Controller* controller, int netw } } else if ( ctlr->NetworkOfScheduleParts() ){ for ( int j=0; j<min(networkSize, (int)sorter.size()); j++ ){ - for each( int spID_i in ctlr->GetAllowedScheduleParts(i) ){ - for each( int spID_j in ctlr->GetAllowedScheduleParts(sorter[j].second) ){ - if( ctlr->ArcExistsOnDay(spID_i, spID_j, i_day)) //especially if both scheduleParts belong to i_day - o_esppc_solver.Add( ctlr->REF(spID_i, spID_j, i_day) ); + for (auto spID_i = ctlr->GetAllowedScheduleParts(i).begin(); spID_i != ctlr->GetAllowedScheduleParts(i).end();spID_i++) { + for (auto spID_j = ctlr->GetAllowedScheduleParts(sorter[j].second).begin(); spID_j != ctlr->GetAllowedScheduleParts(sorter[j].second).end();spID_j) { + if( ctlr->ArcExistsOnDay(*spID_i, *spID_j, i_day)) //especially if both scheduleParts belong to i_day + o_esppc_solver.Add( ctlr->REF(*spID_i, *spID_j, i_day) ); } } } @@ -3105,12 +3105,12 @@ c_PricingSolverCVRPTW::c_PricingSolverCVRPTW( c_Controller* controller, int netw } } else if ( ctlr->NetworkOfScheduleParts() ){ for ( int j=0; j<n; j++ ){ - for each( int spID in ctlr->GetAllowedScheduleParts(j) ){ - if ( ctlr->ArcExistsOnDay( ctlr->OrigDepotVertex(i_day), spID, i_day) ){ - o_esppc_solver.Add( ctlr->REF(ctlr->OrigDepotVertex(i_day), spID, i_day) ); + for (auto spID = ctlr->GetAllowedScheduleParts(j).begin(); spID != ctlr->GetAllowedScheduleParts(j).end();spID++) { + if ( ctlr->ArcExistsOnDay( ctlr->OrigDepotVertex(i_day), *spID, i_day) ){ + o_esppc_solver.Add( ctlr->REF(ctlr->OrigDepotVertex(i_day), *spID, i_day) ); } - if ( ctlr->ArcExistsOnDay( spID, ctlr->DestDepotVertex(i_day), i_day) ){ - o_esppc_solver.Add( ctlr->REF(spID, ctlr->DestDepotVertex(i_day), i_day) ); + if ( ctlr->ArcExistsOnDay( *spID, ctlr->DestDepotVertex(i_day), i_day) ){ + o_esppc_solver.Add( ctlr->REF(*spID, ctlr->DestDepotVertex(i_day), i_day) ); } } } @@ -3818,33 +3818,33 @@ bool c_MergeManagerCVRPTW::Mergeable( const LabelFW& label_fw, const LabelBW& la rdc = 0.0; rdc = label_fw.Cost() + label_bw.Cost(); - for each( int cutId in _controller->getActiveCutIds()){ - bool singleSRCutExists = !_controller->IsAggregated() && _controller->RMP()->ConstraintIndexExists(c_RMP_CVRPTW::eSubsetRowCut,cutId); - bool aggregatedSRCutExists = _controller->IsAggregated() && _controller->RMP()->ConstraintIndexExists(c_RMP_CVRPTW::eAggregatedSubsetRowCut, (cutId%_controller->NumSubsetRowCuts()) ); + for (auto cutId = _controller->getActiveCutIds().begin(); cutId != _controller->getActiveCutIds().end();cutId++) { + bool singleSRCutExists = !_controller->IsAggregated() && _controller->RMP()->ConstraintIndexExists(c_RMP_CVRPTW::eSubsetRowCut,*cutId); + bool aggregatedSRCutExists = _controller->IsAggregated() && _controller->RMP()->ConstraintIndexExists(c_RMP_CVRPTW::eAggregatedSubsetRowCut, ((*cutId)%_controller->NumSubsetRowCuts()) ); if(singleSRCutExists || aggregatedSRCutExists ){ //if mergeVertex is not in cut subset, but cut is active forward and backward: punish one more time by this cut if( taskNetwork ){ - if (!v_contains(_controller->getSRIs()[cutId], mergeVertex)){ - if (label_fw.Bs_SRI(cutId) && label_bw.Bs_SRI(cutId) ){ - rdc -= _controller->getSRIDual(cutId); //increase rdc (sigma is negative) + if (!v_contains(_controller->getSRIs()[*cutId], mergeVertex)){ + if (label_fw.Bs_SRI(*cutId) && label_bw.Bs_SRI(*cutId) ){ + rdc -= _controller->getSRIDual(*cutId); //increase rdc (sigma is negative) } } //if mergeVertex is in cut subset and cut is not-active forward and backward: redo one punishment - if (v_contains(_controller->getSRIs()[cutId], mergeVertex)){ - if ( !label_fw.Bs_SRI(cutId) && !label_bw.Bs_SRI(cutId) ){ - rdc += _controller->getSRIDual(cutId); + if (v_contains(_controller->getSRIs()[*cutId], mergeVertex)){ + if ( !label_fw.Bs_SRI(*cutId) && !label_bw.Bs_SRI(*cutId) ){ + rdc += _controller->getSRIDual(*cutId); } } } else if( schedulePartNetwork ){ - if ( !_controller->TaskOfSubsetContainedInSP( _controller->getSRIs()[cutId], mergeVertex) ){ - if (label_fw.Bs_SRI(cutId) && label_bw.Bs_SRI(cutId) ){ - rdc -= _controller->getSRIDual(cutId); //increase rdc (sigma is negative) + if ( !_controller->TaskOfSubsetContainedInSP( _controller->getSRIs()[*cutId], mergeVertex) ){ + if (label_fw.Bs_SRI(*cutId) && label_bw.Bs_SRI(*cutId) ){ + rdc -= _controller->getSRIDual(*cutId); //increase rdc (sigma is negative) } } //if mergeVertex is in cut subset and cut is not-active forward and backward: redo one punishment - if ( _controller->TaskOfSubsetContainedInSP( _controller->getSRIs()[cutId], mergeVertex) ){ - if ( !label_fw.Bs_SRI(cutId) && !label_bw.Bs_SRI(cutId) ){ - rdc += _controller->getSRIDual(cutId); + if ( _controller->TaskOfSubsetContainedInSP( _controller->getSRIs()[*cutId], mergeVertex) ){ + if ( !label_fw.Bs_SRI(*cutId) && !label_bw.Bs_SRI(*cutId) ){ + rdc += _controller->getSRIDual(*cutId); } } } @@ -4208,9 +4208,9 @@ int c_SeparationProblemCVRPTW::EliminateCyclesByExtendingNeighborhood( list<c_Co if( cycleWithThisNode ){ locationsWithChange.push_back(*it_n); if( nodesInBetween.size() < ctlr->DynamicNgNeighborhoodUB() ){ - for each( int v in nodesInBetween){ + for (auto v = nodesInBetween.begin(); v != nodesInBetween.end();v++) { //the neighborhood of the nodes in between must be extended (not the other way around!) - if( ctlr->AddToNeighborhood(v, *it_n, ctlr->DynamicNgNeighborhoodUB()) ){ // of course some of the locations can be inserted already before, but not all + if( ctlr->AddToNeighborhood(*v, *it_n, ctlr->DynamicNgNeighborhoodUB()) ){ // of course some of the locations can be inserted already before, but not all numIncreasedNeighborhoods++; } } @@ -4356,8 +4356,8 @@ c_SubsetRowCutConstraintCVRPTW::c_SubsetRowCutConstraintCVRPTW(c_Controller* con void c_SubsetRowCutConstraintCVRPTW::OutputInOStream(ostream& s) const { s << "Subset("; - for each( int c in v_Subset){ - s << c << ","; + for (auto c = v_Subset.begin(); c != v_Subset.end();c++) { + s << *c << ","; } s << ")"; } @@ -4386,8 +4386,8 @@ c_AggregatedSubsetRowCutConstraintCVRPTW::c_AggregatedSubsetRowCutConstraintCVRP void c_AggregatedSubsetRowCutConstraintCVRPTW::OutputInOStream(ostream& s) const { s << "Agg-Subset("; - for each( int c in v_Subset){ - s << c << ","; + for (auto c = v_Subset.begin(); c != v_Subset.end(); c++) { + s << *c << ","; } s << ")"; } @@ -4408,8 +4408,8 @@ c_NgIncreasementCVRPTW::c_NgIncreasementCVRPTW(c_Controller* controller, vector< void c_NgIncreasementCVRPTW::OutputInOStream(ostream& s) const { s << "Locations("; - for each( int c in v_changedLocations){ - s << c << ","; + for (auto c = v_changedLocations.begin(); c != v_changedLocations.end();c++) { + s << *c << ","; } s << ")"; } @@ -4431,8 +4431,8 @@ c_CapacityCutConstraintCVRPTW::c_CapacityCutConstraintCVRPTW(c_Controller* contr void c_CapacityCutConstraintCVRPTW::OutputInOStream(ostream& s) const { s << "Subset("; - for each( int c in v_customerSubset){ - s << c << ","; + for (auto c = v_customerSubset.begin(); c != v_customerSubset.end();c++) { + s << *c << ","; } s << ")"; } diff --git a/cvrptw_instance.cpp b/cvrptw_instance.cpp index bc26d18..9865cb4 100644 --- a/cvrptw_instance.cpp +++ b/cvrptw_instance.cpp @@ -455,12 +455,12 @@ const int c_CVRPTW_Instance::GetVertex(int cust, int day, int endDay/*=-1*/) } else if( cust == DestDepot() ){ return DestDepotVertex(day); } else{ //customer - for each( int spId in GetAllowedScheduleParts(cust) ){ - if( GetSchedulePart(spId)->getStartDay() == day ) + for (auto spId = GetAllowedScheduleParts(cust).begin(); spId != GetAllowedScheduleParts(cust).end();spId) { + if( GetSchedulePart(*spId)->getStartDay() == day ) if( endDay == -1 ) - return spId; - else if( GetSchedulePart(spId)->getEndDay() == endDay ) - return spId; + return *spId; + else if( GetSchedulePart(*spId)->getEndDay() == endDay ) + return *spId; } //return cust * PlanningHorizon() + day; } @@ -556,9 +556,9 @@ const int c_CVRPTW_Instance::GetTask(int cust, int day) const{ const bool c_CVRPTW_Instance::TaskOfSubsetContainedInSP(const vector<int>& subset, int SPId) const { - for each( int task in subset ){ - if( GetSchedulePart(SPId)->getCustomer() == GetNodeOfTask(task) ){ - if( SPContainsDay( SPId, GetDayOfTask(task) ) ){ + for (auto task = subset.begin(); task!=subset.end();task++ ) { + if( GetSchedulePart(SPId)->getCustomer() == GetNodeOfTask(*task) ){ + if( SPContainsDay( SPId, GetDayOfTask(*task) ) ){ return true; } } @@ -687,22 +687,22 @@ void c_CVRPTW_Instance::createScheduleParts() //if( IsCustomerNode(i) ){ //also depot has schedule v_schedulePartsPerCustomerAndScheduleId[i] = vector<vector<int>>( (int)GetAllowedSchedules(i).size() ); int scheduleId = 0; - for each( vector<bool> schedule in GetAllowedSchedules(i) ){ + for (auto schedule = GetAllowedSchedules(i).begin(); schedule != GetAllowedSchedules(i).end();schedule++) { for( int d = 0; d < PlanningHorizon(); d++ ){ - if( schedule[d] == true ){ + if( (*schedule)[d] == true ){ //check how many following days can be delivered at this visit int dBeforeNextVisit = d; int dEnd = (d + 1)%PlanningHorizon(); - while( schedule[dEnd] == false ){ + while((*schedule)[dEnd] == false ){ dBeforeNextVisit = dEnd; dEnd = (dEnd+ 1)%PlanningHorizon(); } //don't create same schedulePart (defined by customer, start and endPeriod) twice int sp_id = -1; - for each ( int SPId in v_schedulePartsPerCustomer[i] ){ - if( GetSchedulePart(SPId)->getStartDay() == d && GetSchedulePart(SPId)->getEndDay() == dBeforeNextVisit ){ - sp_id = SPId; + for (auto SPId = v_schedulePartsPerCustomer[i].begin(); SPId != v_schedulePartsPerCustomer[i].end();SPId++) { + if( GetSchedulePart(*SPId)->getStartDay() == d && GetSchedulePart(*SPId)->getEndDay() == dBeforeNextVisit ){ + sp_id = *SPId; break; } } @@ -780,9 +780,9 @@ const bool c_CVRPTW_Instance::SPContainsDay(int SPId, int day) const //-1 as endDay as wildcard, useful for non-overlapping schedules such that the starting vertex suffices const int c_CVRPTW_Instance::GetSchedulePartId(int customer, int startDay, int endDay) const { - for each ( int SPId in GetAllowedScheduleParts(customer) ){ - if( GetSchedulePart(SPId)->getStartDay() == startDay && (GetSchedulePart(SPId)->getEndDay() == endDay || endDay == -1) ){ - return SPId; + for (auto SPId = GetAllowedScheduleParts(customer).begin(); SPId != GetAllowedScheduleParts(customer).end();SPId++) { + if( GetSchedulePart(*SPId)->getStartDay() == startDay && (GetSchedulePart(*SPId)->getEndDay() == endDay || endDay == -1) ){ + return *SPId; } } cerr << "Error. No schedule part id found for customer " << customer << ", startPeriod " << startDay << " and endPeriod " << endDay << endl; @@ -898,8 +898,8 @@ bool c_CVRPTW_Instance::ArcExistsOnDay(int v1, int v2, int day) const return false; // start of customer visit has to be the vertex belonging to the day of the current network, depot belongs always to day 0 per definition bool node2VisitableAtThisDay = false; - for each( const vector<bool>& schedule in GetAllowedSchedules( node2 )){ - if( schedule[day] ){ + for (auto schedule = GetAllowedSchedules(node2).begin(); schedule != GetAllowedSchedules(node2).end();schedule++) { + if( (*schedule)[day] ){ node2VisitableAtThisDay = true; break; } @@ -910,21 +910,21 @@ bool c_CVRPTW_Instance::ArcExistsOnDay(int v1, int v2, int day) const if( !node2VisitableAtThisDay && !destDepot ) return false; //node2 has to be visitable at this day - for each( const vector<bool>& schedule in GetAllowedSchedules( node1 )){ + for (auto schedule = GetAllowedSchedules(node1).begin(); schedule != GetAllowedSchedules(node1).end();schedule++) { //if at least one schedule, that is active at the network-day, allows visit at the day after day2, - if( schedule[day%PlanningHorizon()] ){ //check all schedules that allow visit at the network day + if( (*schedule)[day%PlanningHorizon()] ){ //check all schedules that allow visit at the network day //if node1 belongs to network day and schedule allows new visit at next day, visitation of this customer can stop here int day1 = GetDay(v1); if( day1 == day ){ - if( schedule[(day+1)%PlanningHorizon()] ) + if( (*schedule)[(day+1)%PlanningHorizon()] ) return true; } else { //if node1 does not belong to network day, but there is a schedule that allows visit at day1+1 - if ( schedule[(day1+1)%PlanningHorizon()] ){ + if ( (*schedule)[(day1+1)%PlanningHorizon()] ){ //and does not include visits at all days in (network day; day1], int d_between = (day + 1) % PlanningHorizon(); bool allBetweenNotVisitable = true; do{ - if( schedule[d_between] ) + if( (*schedule)[d_between] ) allBetweenNotVisitable = false; d_between = (d_between + 1) % PlanningHorizon(); } while (d_between != (day1+1)%PlanningHorizon() ) ; @@ -935,12 +935,12 @@ bool c_CVRPTW_Instance::ArcExistsOnDay(int v1, int v2, int day) const } } } else if ( node1 == node2 ){ //same node, but other days - for each( const vector<bool>& schedule in GetAllowedSchedules( node1 )){ + for (auto schedule = GetAllowedSchedules(node1).begin(); schedule != GetAllowedSchedules(node1).end();schedule++) { //if at least one schedule that is active at the network-day - if( schedule[day] ){ + if( (*schedule)[day] ){ //forbids visit at the day after d1 and d1+1 = d2 int day1 = GetDay(v1); - if( !schedule[(day1+1)%PlanningHorizon()] && ((day1+1)%PlanningHorizon() == GetDay(v2)) ){ + if( !(*schedule)[(day1+1)%PlanningHorizon()] && ((day1+1)%PlanningHorizon() == GetDay(v2)) ){ return true; //if at least one schedule, that is active at this day, forbids visit at the following day, further demand fulfillment has to be allowed } } diff --git a/cvrptw_ref.cpp b/cvrptw_ref.cpp index 82444de..7e0710e 100644 --- a/cvrptw_ref.cpp +++ b/cvrptw_ref.cpp @@ -83,9 +83,9 @@ bool c_REF_CVRPTW::PropagateFw( const c_ResVectorCVRPTW_Fw& old_res, c_ResVector //wenn Wechsel von true auf false, addiere sigma (dual-variable des betrachteten cuts) mit getSRIDual(cutId), denn Instanz kennt die Werte new_res.bs_SubsetRowCutactive = old_res.bs_SubsetRowCutactive ^ bs_IncrementCutCounter_Fw ; - for each( int cutId in o_instance.getActiveCutIds()){ - if( bs_IncrementCutCounter_Fw[cutId] && !new_res.bs_SubsetRowCutactive[cutId] ){ //Wenn Wechsel und Wert nun false - new_res.d_cost -= o_instance.getSRIDual(cutId); + for (auto cutId = o_instance.getActiveCutIds().begin(); cutId != o_instance.getActiveCutIds().end();cutId++) { + if( bs_IncrementCutCounter_Fw[*cutId] && !new_res.bs_SubsetRowCutactive[*cutId] ){ //Wenn Wechsel und Wert nun false + new_res.d_cost -= o_instance.getSRIDual(*cutId); } } @@ -174,9 +174,9 @@ bool c_REF_CVRPTW::PropagateBw(const c_ResVectorCVRPTW_Bw& old_res, c_ResVectorC // entspricht exakt dem Verfahren von Forward, nur ist nun tail zu betrachten, daher bs_IncrementCutCounter_Bw new_res.bs_SubsetRowCutactive = old_res.bs_SubsetRowCutactive ^ bs_IncrementCutCounter_Bw ; - for each( int cutId in o_instance.getActiveCutIds()){ - if( bs_IncrementCutCounter_Bw[cutId] && !new_res.bs_SubsetRowCutactive[cutId] ){ - new_res.d_cost -= o_instance.getSRIDual(cutId); + for (auto cutId = o_instance.getActiveCutIds().begin(); cutId != o_instance.getActiveCutIds().end(); cutId++) { + if( bs_IncrementCutCounter_Bw[*cutId] && !new_res.bs_SubsetRowCutactive[*cutId] ){ + new_res.d_cost -= o_instance.getSRIDual(*cutId); } } @@ -250,9 +250,10 @@ bool c_LabelCVRPTW_Fw::operator<=(const c_LabelCVRPTW_Fw& second) // return false; //} - for each( int cutId in p_REF->o_instance.getActiveCutIds()) - if ( bs_SubsetRowCutactive[cutId] && !second.bs_SubsetRowCutactive[cutId] ) - costForComparison -= p_REF->o_instance.getSRIDual(cutId); + for (auto cutId = p_REF->o_instance.getActiveCutIds().begin(); cutId != p_REF->o_instance.getActiveCutIds().end(); cutId++) { + if (bs_SubsetRowCutactive[*cutId] && !second.bs_SubsetRowCutactive[*cutId]) + costForComparison -= p_REF->o_instance.getSRIDual(*cutId); + } return ( costForComparison <= second.Cost() ); // Label 1 ist besser als Label 2 trotz Bestrafung } @@ -278,9 +279,10 @@ bool c_LabelCVRPTW_Bw::operator<=(const c_LabelCVRPTW_Bw& second) // return false; //} - for each( int cutId in p_REF->o_instance.getActiveCutIds() ) - if ( bs_SubsetRowCutactive[cutId] && !second.bs_SubsetRowCutactive[cutId] ) - costForComparison -= p_REF->o_instance.getSRIDual(cutId); + for (auto cutId = p_REF->o_instance.getActiveCutIds().begin(); cutId != p_REF->o_instance.getActiveCutIds().end(); cutId++) { + if (bs_SubsetRowCutactive[*cutId] && !second.bs_SubsetRowCutactive[*cutId]) + costForComparison -= p_REF->o_instance.getSRIDual(*cutId); + } return ( costForComparison <= second.Cost() ); } diff --git a/data.h b/data.h index 3f54994..f6c88c2 100644 --- a/data.h +++ b/data.h @@ -23,7 +23,7 @@ public: const int getAdditionalServiceTime() const { return i_additionalServiceTime;} //customer, start and end period define a schedule part uniquely - bool c_SchedulePart::operator==(const c_SchedulePart &other) const { + bool operator==(const c_SchedulePart &other) const { if( i_customer == other.getCustomer() && i_startDay == other.getStartDay() && i_endDay == other.getEndDay() ){ return true; } else{ @@ -31,7 +31,7 @@ public: } } - bool c_SchedulePart::operator!=(const c_SchedulePart &other) const { + bool operator!=(const c_SchedulePart &other) const { return !(*this == other); } }; diff --git a/espprc/solver.h b/espprc/solver.h index 9315458..8e7b70a 100644 --- a/espprc/solver.h +++ b/espprc/solver.h @@ -6,6 +6,7 @@ #include "../Graphml/graphml.h" #include "../SharedFiles/timeinfo.h" +#include "../SharedFiles/output_formatter.h" #define DebugAnka @@ -71,7 +72,7 @@ namespace espprc bool SolveBidir( MManager& merger, int source, int sink, ResVectFW&& init_res_FW, ResVectBW&& init_res_bw, int maxnumpaths = -1, int maxTime = numeric_limits<int>::max() ); bool SolveBidir_DynamicHalfway( MManager& merger, int source, int sink, ResVectFW&& init_res_FW, ResVectBW&& init_res_bw, int maxnumpaths = -1, int maxTime = numeric_limits<int>::max() ); bool GetPathsBidir( const int sink, std::vector<std::pair<double, std::pair<t_labelFW*,t_labelBW*> > >& paths, std::function<bool (std::pair<double,std::pair<t_labelFW*,t_labelBW*> >, std::pair<double,std::pair<t_labelFW*,t_labelBW*> > )>* pointer_sorter = nullptr, int maxnumpaths = -1 ); - double InfoTimeMerging(){ return d_mergeSeconds; } + //double InfoTimeMerging(){ return d_mergeSeconds; } // IO void OutputInStream( std::ostream& s ) const; // output all labels grouped by node void OutputGraphML(const char* filename); diff --git a/main.cpp b/main.cpp index ff1df82..f4e3805 100644 --- a/main.cpp +++ b/main.cpp @@ -33,7 +33,7 @@ int main(int argc, char** argv ) } cout << "... " << endl; - c_ControllerCVRPTW ctlr( ssInstance.str().c_str(), ssSchedule.str().c_str() ); + c_ControllerCVRPTW ctlr( ssInstance.str().c_str(), ssSchedule.str().c_str(),"../settings/settings.txt"); ctlr.ReadSettings(); /*stringstream tikzName; -- GitLab