00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "solver.h"
00022
00023 #include "loader.h"
00024 #include "conflicts.h"
00025 #include "model.h"
00026 #include "cuts.h"
00027 #include "strategy.h"
00028 #include "saver_bound.h"
00029
00030 using namespace Udine;
00031
00032 Solver::Solver(IloEnv &env, Config &config) {
00033 try {
00034 env.out() << "<?xml version='1.0' encoding='UTF-8'?>" << std::endl;
00035 env.out() << "<log";
00036 env.out() << " data='" << config.path << "' ";
00037 env.out() << " config='" << config.configId << "' ";
00038 env.out() << ">" << std::endl;
00039 env.out() << "<cplex>";
00040
00041 IloModel model(env);
00042 IloCplex cplex(model);
00043 config.apply(cplex, Surface);
00044
00045 Instance instance;
00046 instance.load(config.path);
00047 Graph conflictGraph;
00048 conflictGraph.generateConflictGraph(instance);
00049 conflictGraph.generateCliques();
00050 Neighbourhood definition;
00051 definition.type = Surface;
00052 definition.cost = 0;
00053 Model surface(model, config, instance, conflictGraph, definition);
00054
00055 if (config.getParam(UseLpFilesExport)) {
00056 env.out() << std::endl << "Exporting the surface model ..." << std::endl;
00057 std::stringstream filename;
00058 filename << config.path << ".surface.lp";
00059 cplex.exportModel(filename.str().c_str());
00060 }
00061
00062 StrategyI *strategy = NULL;
00063 switch (config.strategy) {
00064 case ContractAlgorithm:
00065 strategy = new (env) ContractStrategyI(env, surface, config);
00066 break;
00067 case AnytimeAlgorithm:
00068 default:
00069 strategy = new (env) AnytimeStrategyI(env, surface, config);
00070 break;
00071 }
00072 cplex.use(IloCplex::Callback(strategy));
00073
00074 if (config.getParam(UseLowerBoundLogging))
00075 cplex.use(BoundSaver(env, config, "globalLB"));
00076
00077 if (config.getParam(UseDynamicCutsAtSurface))
00078 cplex.use(CutManager(env, surface, config));
00079
00080 env.out() << std::endl << "Solver: Running ..." << std::endl;
00081
00082 #if CPX_VERSION >= 1100
00083 cplex.populate();
00084 #else
00085 cplex.solve();
00086 #endif
00087
00088 if (cplex.getStatus() != IloAlgorithm::Feasible &&
00089 cplex.getStatus() != IloAlgorithm::Optimal) {
00090 env.out() << "Solver: Not a single neighbourhood has been found. Please check the time limit and feasibility of the instance." << std::endl;
00091 }
00092
00093 env.out() << "</cplex>";
00094 env.out() << "<timestamp end='" << config.elapsed() << "'/>";
00095
00096 strategy->finishOff();
00097
00098 env.out() << "</log>" << std::endl;
00099 }
00100 catch (IloException& e) { env.error() << "Solver: Concert exception caught: " << e << std::endl; }
00101 catch (...) { env.error() << "Solver: Unknown exception caught" << std::endl; }
00102 }