From d0ff8af5918190101f020a15cd928c06ad7249e1 Mon Sep 17 00:00:00 2001 From: Aszarsha Date: Tue, 16 Dec 2014 14:51:46 +0100 Subject: [PATCH] upper bound output and gap objective --- src/Solver.cpp | 6 ++++++ src/Solver/Config.cpp | 3 ++- src/Solver/Config.hpp | 5 ++++- src/Solver/Solution.cpp | 1 + src/Solver/Solution.hpp | 1 + src/xHeinz.cpp | 10 +++++++++- 6 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Solver.cpp b/src/Solver.cpp index aa6a899..9dc2a2b 100644 --- a/src/Solver.cpp +++ b/src/Solver.cpp @@ -85,6 +85,7 @@ namespace xHeinz { ); OutputSolution sol; + sol.upperBound = cplex.getBestObjValue(); sol.weight = score1 + score2; sol.alpha = get< 0 >( alphas ); sol.graphsSolutions.emplace_back( move( sol1 ), score1, get< 1 >( alphas ) ); @@ -654,6 +655,11 @@ namespace xHeinz { cplex.setParam( IloCplex::Threads, config.numThreads ); } + if ( config.gapObjective >= 0 ) { + cplex.setParam( IloCplex::EpGap, config.gapObjective ); + cplex.setParam( IloCplex::MIPEmphasis, 1 ); + } + cplex.setParam( IloCplex::HeurFreq , -1 ); cplex.setParam( IloCplex::Cliques , -1 ); cplex.setParam( IloCplex::Covers , -1 ); diff --git a/src/Solver/Config.cpp b/src/Solver/Config.cpp index 4880acb..6c22fd5 100644 --- a/src/Solver/Config.cpp +++ b/src/Solver/Config.cpp @@ -22,7 +22,8 @@ namespace solver { out << "\n-- size = " << config.size << "\n-- time limit = " << config.timeLimit << "\n-- root time limit = " << config.rootTimeLimit - << "\n-- # threads = " << config.numThreads; + << "\n-- # threads = " << config.numThreads + << "\n-- gap objective = " << config.gapObjective; return out; } diff --git a/src/Solver/Config.hpp b/src/Solver/Config.hpp index de91471..7c0b5a4 100644 --- a/src/Solver/Config.hpp +++ b/src/Solver/Config.hpp @@ -23,6 +23,7 @@ namespace solver { int maxCutIterations; double timeLimit; double rootTimeLimit; + double gapObjective; Config( double cp = 0.6 , std::array< double, 2 > pp = std::array< double, 2 >{ 0.0, 0.0 } @@ -32,6 +33,7 @@ namespace solver { , int mi = 20 , double tl = std::numeric_limits< double >::infinity() , double rtl = std::numeric_limits< double >::infinity() + , double go = -1 ) : connectivityPercentage{ cp } , positivePercentage( pp ) @@ -40,7 +42,8 @@ namespace solver { , size{ s } , maxCutIterations{ mi } , timeLimit{ tl } - , rootTimeLimit{ rtl } { + , rootTimeLimit{ rtl } + , gapObjective{ go } { } friend std::ostream & operator<<( std::ostream & out, Config const & conf ); diff --git a/src/Solver/Solution.cpp b/src/Solver/Solution.cpp index eab1efe..db0fd3d 100644 --- a/src/Solver/Solution.cpp +++ b/src/Solver/Solution.cpp @@ -33,6 +33,7 @@ namespace solver { out << get< 1 >( gs ); }); out << ")"; + out << "\n-- Objective UpperBound = " << sol.upperBound; for ( int i = 0, e = sol.graphsSolutions.size(); i != e; ++i ) { auto const & graphSol = sol.graphsSolutions[i]; diff --git a/src/Solver/Solution.hpp b/src/Solver/Solution.hpp index a551d4b..2128ea0 100644 --- a/src/Solver/Solution.hpp +++ b/src/Solver/Solution.hpp @@ -16,6 +16,7 @@ namespace solver { using SolutionSet = std::vector< NodeBoolPair >; using GraphSolution = std::tuple< SolutionSet, WeightScore, AlphaScore >; + WeightScore upperBound; WeightScore weight; AlphaScore alpha; std::vector< GraphSolution > graphsSolutions; diff --git a/src/xHeinz.cpp b/src/xHeinz.cpp index 039d9de..5ba1f52 100644 --- a/src/xHeinz.cpp +++ b/src/xHeinz.cpp @@ -36,7 +36,7 @@ int main( int argc, char * argv[] ) { .refOption( "a", "Conservation ratio threshold (default: 0.6)" , config.connectivityPercentage, false ) - .synonym("alpha", "a" ) + .synonym( "alpha", "a" ) #if 0 .refOption( "b1", "Graph 1: positive node ratio threshold (default: 0.0) TODO" , config.positivePercentage[0], false @@ -47,6 +47,9 @@ int main( int argc, char * argv[] ) { ) .synonym("beta2", "b2" ) #endif + .refOption( "gap", "Specifies the target gap (in [0, 1] or < 0 for disabled, default: -1)" + , config.gapObjective, false + ) .refOption( "w", "Specifies the type of mapping weighting:\n" " 0 - Sum mapped nodes (default)\n" " 1 - Sum mapped node weights\n" @@ -113,6 +116,11 @@ int main( int argc, char * argv[] ) { config.connectivityType = static_cast< solver::Config::ConnectivityType >(connectivityType); + if ( config.gapObjective > 1 ) { + cerr << "Invalid omega (mapping weighting)" << endl; + return 1; + } + if ( ap.given( "version" ) ) { cout << "Version number: " << XHEINZ_VERSION << endl; return 0;