Commit f42ec0d2 authored by David Bommes's avatar David Bommes
Browse files

added cplex timelimit

git-svn-id: http://www.openflipper.org/svnrepo/CoMISo/trunk@134 1355f012-dd97-4b2f-ae87-10fa9f823a57
parent 9d11ce28
......@@ -150,6 +150,7 @@ solve(NProblemInterface* _problem,
//----------------------------------------------
IloCplex cplex(model);
cplex.setParam(IloCplex::TiLim, _time_limit);
cplex.solve();
......
......@@ -74,6 +74,7 @@ get_parameters()
noRoundingCB ->setChecked( misolver_.get_no_rounding());
multipleRoundingCB->setChecked( misolver_.get_multiple_rounding());
gurobiRoundingCB ->setChecked( misolver_.get_gurobi_rounding());
cplexRoundingCB ->setChecked( misolver_.get_cplex_rounding());
localItersSB ->setValue( misolver_.get_local_iters());
localErrorDSB->setValue( log(misolver_.get_local_error())/log(10.0f));
......@@ -105,6 +106,7 @@ set_parameters()
misolver_.set_no_rounding( noRoundingCB->isChecked());
misolver_.set_multiple_rounding( multipleRoundingCB->isChecked());
misolver_.set_gurobi_rounding( gurobiRoundingCB->isChecked());
misolver_.set_cplex_rounding ( cplexRoundingCB->isChecked());
misolver_.set_local_iters( localItersSB ->value());
misolver_.set_local_error( pow(10, localErrorDSB->value()));
......
......@@ -9,8 +9,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>368</width>
<height>259</height>
<width>385</width>
<height>273</height>
</rect>
</property>
<property name="windowTitle">
......@@ -19,6 +19,13 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="8" column="1">
<widget class="QCheckBox" name="cplexRoundingCB">
<property name="text">
<string>use cplex</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_4">
<property name="text">
......
......@@ -34,6 +34,11 @@
#include <gurobi_c++.h>
#endif
#if COMISO_CPLEX_AVAILABLE
#include <ilcplex/ilocplex.h>
#endif
#include <CoMISo/Utils/StopWatch.hh>
#include <gmm/gmm.h>
......@@ -61,6 +66,7 @@ MISolver::MISolver()
no_rounding_ = false;
multiple_rounding_ = true;
gurobi_rounding_ = false;
cplex_rounding_ = false;
max_local_iters_ = 100000;
max_local_error_ = 1e-3;
......@@ -96,16 +102,19 @@ MISolver::solve(
if( gurobi_rounding_)
solve_gurobi(_A, _x, _rhs, _to_round);
else
if( no_rounding_ || _to_round.size() == 0)
solve_no_rounding( _A, _x, _rhs);
if( cplex_rounding_)
solve_gurobi(_A, _x, _rhs, _to_round);
else
if( direct_rounding_)
solve_direct_rounding( _A, _x, _rhs, _to_round);
if( no_rounding_ || _to_round.size() == 0)
solve_no_rounding( _A, _x, _rhs);
else
if( multiple_rounding_)
solve_multiple_rounding( _A, _x, _rhs, _to_round);
if( direct_rounding_)
solve_direct_rounding( _A, _x, _rhs, _to_round);
else
solve_iterative( _A, _x, _rhs, _to_round, _fixed_order);
if( multiple_rounding_)
solve_multiple_rounding( _A, _x, _rhs, _to_round);
else
solve_iterative( _A, _x, _rhs, _to_round, _fixed_order);
}
......@@ -714,6 +723,93 @@ MISolver::solve_gurobi(
}
//-----------------------------------------------------------------------------
void
MISolver::solve_cplex(
CSCMatrix& _A,
Vecd& _x,
Vecd& _rhs,
Veci& _to_round)
{
#if COMISO_CPLEX_AVAILABLE
// get round-indices in set
std::set<int> to_round;
for(unsigned int i=0; i<_to_round.size();++i)
to_round.insert(_to_round[i]);
try {
IloEnv env_;
IloModel model(env_);
// set time limite
// model.getEnv().set(GRB_DoubleParam_TimeLimit, gurobi_max_time_);
unsigned int n = _rhs.size();
// 1. allocate variables
std::vector<IloNumVar> vars;
for( unsigned int i=0; i<n; ++i)
if( to_round.count(i))
vars.push_back( IloNumVar(env_, -IloIntMax, IloIntMax, IloNumVar::Int) );
else
vars.push_back( IloNumVar(env_,-IloInfinity, IloInfinity, IloNumVar::Float) );
// 2. setup_energy
// build objective function from linear system E = x^tAx - 2x^t*rhs
IloExpr objective(env_);
for(unsigned int i=0; i<_A.nc; ++i)
for(unsigned int j=_A.jc[i]; j<_A.jc[i+1]; ++j)
{
objective += _A.pr[j]*vars[_A.ir[j]]*vars[i];
}
for(unsigned int i=0; i<n; ++i)
objective -= 2*_rhs[i]*vars[i];
// _A.jc[c+1]
// _A.pr[write]
// _A.ir[write]
// _A.nc
// _A.nr
// minimize
model.add(IloMinimize(env_,objective));
// 4. solve
IloCplex cplex(model);
cplex.setParam(IloCplex::TiLim, gurobi_max_time_);
cplex.solve();
// 5. store result
_x.resize(n);
for(unsigned int i=0; i<n; ++i)
_x[i] = cplex.getValue(vars[i]);
std::cout << "CPLEX objective: " << cplex.getObjValue() << std::endl;
}
catch (IloException& e)
{
cerr << "CPLEX Concert exception caught: " << e << endl;
}
catch (...)
{
cerr << "CPLEX Unknown exception caught" << endl;
}
#else
std::cerr << "CPLEX solver is not available, please install it..." << std::endl;
#endif
}
//----------------------------------------------------------------------------
......
......@@ -166,6 +166,10 @@ public:
/// Will gurobi rounding be performed?
bool get_gurobi_rounding() { return gurobi_rounding_;}
/// Shall cplex solver be used?
void set_cplex_rounding( bool _b) { cplex_rounding_=_b;}
/// Will cplex rounding be performed?
bool get_cplex_rounding() { return cplex_rounding_;}
/// Set number of maximum Gauss-Seidel iterations
void set_local_iters( unsigned int _i) { max_local_iters_ = _i;}
......@@ -303,6 +307,12 @@ private:
Vecd& _rhs,
Veci& _to_round );
void solve_cplex(
CSCMatrix& _A,
Vecd& _x,
Vecd& _rhs,
Veci& _to_round );
void update_solution(
CSCMatrix& _A,
......@@ -327,6 +337,7 @@ private:
bool no_rounding_;
bool multiple_rounding_;
bool gurobi_rounding_;
bool cplex_rounding_;
double multiple_rounding_threshold_;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment