| 188 | } |
| 189 | |
| 190 | bool Engine::solve( double timeoutInSeconds ) |
| 191 | { |
| 192 | SignalHandler::getInstance()->initialize(); |
| 193 | SignalHandler::getInstance()->registerClient( this ); |
| 194 | |
| 195 | // Register the boundManager with all the PL constraints |
| 196 | for ( auto &plConstraint : _plConstraints ) |
| 197 | plConstraint->registerBoundManager( &_boundManager ); |
| 198 | for ( auto &nlConstraint : _nlConstraints ) |
| 199 | nlConstraint->registerBoundManager( &_boundManager ); |
| 200 | |
| 201 | // Before encoding, make sure all valid constraints are applied. |
| 202 | applyAllValidConstraintCaseSplits(); |
| 203 | |
| 204 | if ( _solveWithMILP ) |
| 205 | return solveWithMILPEncoding( timeoutInSeconds ); |
| 206 | |
| 207 | updateDirections(); |
| 208 | if ( _lpSolverType == LPSolverType::NATIVE ) |
| 209 | storeInitialEngineState(); |
| 210 | else if ( _lpSolverType == LPSolverType::GUROBI ) |
| 211 | { |
| 212 | ENGINE_LOG( "Encoding convex relaxation into Gurobi..." ); |
| 213 | _gurobi = std::unique_ptr<GurobiWrapper>( new GurobiWrapper() ); |
| 214 | _tableau->setGurobi( &( *_gurobi ) ); |
| 215 | _milpEncoder = std::unique_ptr<MILPEncoder>( new MILPEncoder( *_tableau ) ); |
| 216 | _milpEncoder->setStatistics( &_statistics ); |
| 217 | _milpEncoder->encodeInputQuery( *_gurobi, *_preprocessedQuery, true ); |
| 218 | ENGINE_LOG( "Encoding convex relaxation into Gurobi - done" ); |
| 219 | } |
| 220 | |
| 221 | mainLoopStatistics(); |
| 222 | if ( _verbosity > 0 ) |
| 223 | { |
| 224 | printf( "\nEngine::solve: Initial statistics\n" ); |
| 225 | _statistics.print(); |
| 226 | printf( "\n---\n" ); |
| 227 | } |
| 228 | |
| 229 | bool splitJustPerformed = true; |
| 230 | struct timespec mainLoopStart = TimeUtils::sampleMicro(); |
| 231 | while ( true ) |
| 232 | { |
| 233 | struct timespec mainLoopEnd = TimeUtils::sampleMicro(); |
| 234 | _statistics.incLongAttribute( Statistics::TIME_MAIN_LOOP_MICRO, |
| 235 | TimeUtils::timePassed( mainLoopStart, mainLoopEnd ) ); |
| 236 | mainLoopStart = mainLoopEnd; |
| 237 | |
| 238 | if ( shouldExitDueToTimeout( timeoutInSeconds ) ) |
| 239 | { |
| 240 | if ( _verbosity > 0 ) |
| 241 | { |
| 242 | printf( "\n\nEngine: quitting due to timeout...\n\n" ); |
| 243 | printf( "Final statistics:\n" ); |
| 244 | _statistics.print(); |
| 245 | } |
| 246 | |
| 247 | _exitCode = Engine::TIMEOUT; |