void ILPSolverSCIP::set_log_level(int p_level)
 {
     p_level = std::clamp(p_level, 0, 5); // Minimum level is 0 (no output), maximum level is 5.
     call_scip(SCIPsetIntParam, d_scip, "display/verblevel", p_level);
     if (p_level == 0)
     {
         SCIPsetMessagehdlrQuiet(d_scip, true);
         SCIPmessageSetErrorPrinting(nullptr, nullptr); // suppress error printing.
     }
     else
     {
         SCIPsetMessagehdlrQuiet(d_scip, false);
         SCIPmessageSetErrorPrintingDefault(); // print errors to cerr.
     }
 }
Beispiel #2
0
int GamsScip::callSolver()
{
   assert(gmo  != NULL);
   assert(gev  != NULL);
   assert(scip != NULL);

   /* set interface type so we see =B= and =X= equations */
   gmoInterfaceSet(gmo, gmoIFace_Raw);

   if( gmoGetEquTypeCnt(gmo, gmoequ_C) || gmoGetEquTypeCnt(gmo, gmoequ_B) || gmoGetEquTypeCnt(gmo, gmoequ_X) )
   {
      gevLogStat(gev, "ERROR: Conic and logic constraints and external functions not supported by SCIP interface.\n");
      gmoSolveStatSet(gmo, gmoSolveStat_Capability);
      gmoModelStatSet(gmo, gmoModelStat_NoSolutionReturned);
      return 1;
   }

   // set number of threads for linear algebra routines used in Ipopt
   setNumThreads(gev, gevThreads(gev));

   // update error printing callback in SCIP to use current gev
   SCIPmessageSetErrorPrinting(printErrorGev, (void*)gev);

   SCIP_RETCODE scipret;

   // let GMO reader setup SCIP parameters and read options file
   // do this here already so we know how to assemble dialog
   scipret = SCIPreadParamsReaderGmo(scip);
   if( scipret != SCIP_OKAY )
   {
      char buffer[256];
      sprintf(buffer, "Error %d in call of SCIP function\n", scipret);
      gevLogStatPChar(gev, buffer);
      gmoSolveStatSet(gmo, gmoSolveStat_SystemErr);
      gmoModelStatSet(gmo, gmoModelStat_ErrorNoSolution);
      return 1;
   }
   SCIPinfoMessage(scip, NULL, "non-default parameter settings:\n");
   SCIPwriteParams(scip, NULL, FALSE, TRUE);

   char* interactive = NULL;
   SCIP_CALL_ABORT( SCIPgetStringParam(scip, "gams/interactive", &interactive) );
   assert(interactive != NULL);
#ifdef GAMS_BUILD
   if( interactive[0] != '\0' && !palLicenseIsAcademic(pal) )
   {
      gevLogStat(gev, "SCIP interactive shell not available in demo mode.\n");
      interactive[0] = '\0';
   }
#endif

   SCIP_Bool printstat;
   SCIP_CALL_ABORT( SCIPgetBoolParam(scip, "display/statistics", &printstat) );

   char* attrfile = NULL;
#if 0
   SCIP_CALL( SCIPgetStringParam(scip, "constraints/attrfile", &attrfile) );
#endif

   // setup commands to be executed by SCIP
   SCIP_CALL_ABORT( SCIPaddDialogInputLine(scip, "readgams") );              // setup model

   if( attrfile != NULL && *attrfile != '\0' )
   {
      char buffer[SCIP_MAXSTRLEN + 10];
      size_t len;

      len = strlen(attrfile);
      if( len >= 3 && strcmp(&attrfile[len-3], ".ca") == 0 )
         (void) SCIPsnprintf(buffer, sizeof(buffer), "read %g", attrfile);
      else
         (void) SCIPsnprintf(buffer, sizeof(buffer), "read %g ca", attrfile);
      SCIP_CALL_ABORT( SCIPaddDialogInputLine(scip, buffer) );               // process constraints attribute file
   }

   if( interactive[0] == '\0' )
   {
      SCIP_CALL_ABORT( SCIPaddDialogInputLine(scip, "optimize") );           // solve model

      if( printstat )
      {
         SCIP_CALL_ABORT( SCIPaddDialogInputLine(scip, "disp statistics") ); // display solution statistics
      }
      SCIP_CALL_ABORT( SCIPaddDialogInputLine(scip, "write gamssol") );      // pass solution to GMO

      SCIP_CALL_ABORT( SCIPaddDialogInputLine(scip, "quit") );               // quit shell
   }
   else
   {
      // pass user commands to shell
      SCIP_CALL_ABORT( SCIPaddDialogInputLine(scip, interactive) );
   }


   // run SCIP
   scipret = SCIPstartInteraction(scip);

   // evaluate SCIP return code
   switch( scipret )
   {
      case SCIP_OKAY:
         break;

      case SCIP_READERROR:
         /* if it's readerror, then we guess that it comes from encountering an unsupported gams instruction in the gmo readers makeExprtree method
          * we still return with zero then
          */
         gmoModelStatSet(gmo, gmoModelStat_NoSolutionReturned);
         gmoSolveStatSet(gmo, gmoSolveStat_Capability);
         break;

      case SCIP_LPERROR:
      case SCIP_MAXDEPTHLEVEL:
         /* if SCIP failed due to internal error (forced LP solve failed, max depth level reached), also return zero */
         gmoModelStatSet(gmo, gmoModelStat_ErrorNoSolution);
         gmoSolveStatSet(gmo, gmoSolveStat_SolverErr);
         break;

      case SCIP_NOMEMORY:
         /* there is no extra solver status for running out of memory, but memory is a resource, so return this */
         gmoModelStatSet(gmo, gmoModelStat_ErrorNoSolution);
         gmoSolveStatSet(gmo, gmoSolveStat_Resource);
         break;

      default:
      {
         char buffer[256];
         sprintf(buffer, "Error %d in call of SCIP function\n", scipret);
         gevLogStatPChar(gev, buffer);

         gmoModelStatSet(gmo, gmoModelStat_ErrorNoSolution);
         gmoSolveStatSet(gmo, gmoSolveStat_SystemErr);
         return 1;
      }
   }

   return 0;
}
Beispiel #3
0
int GamsScip::readyAPI(
   struct gmoRec*     gmo_,               /**< GAMS modeling object */
   struct optRec*     opt_                /**< GAMS options object */
)
{
   char buffer[512];

   gmo = gmo_;
   assert(gmo != NULL);

   if( getGmoReady() || getGevReady() )
      return 1;

   gev = (gevRec*)gmoEnvironment(gmo);
   assert(gev != NULL);

   ipoptlicensed = false;
#ifdef GAMS_BUILD
   if( pal == NULL && !palCreate(&pal, buffer, sizeof(buffer)) )
      return 1;

#define PALPTR pal
#include "coinlibdCL5svn.h" 
   palGetAuditLine(pal, buffer);
   gevLogStat(gev, "");
   gevLogStat(gev, buffer);
   gevStatAudit(gev, buffer);

   initLicensing(gmo, pal);

#ifdef COIN_HAS_OSIXPR
   /* Xpress license setup - don't say anything if failing, since Xpress is not used by default */
   XPlicenseInit_t initType;
   gevxpresslice(gev, pal, gmoM(gmo), gmoN(gmo), gmoNZ(gmo), gmoNLNZ(gmo), gmoNDisc(gmo), 0, &initType, buffer, sizeof(buffer));
#endif
#endif

   // check for academic license, or if we run in demo mode
   if( !checkScipLicense(gmo, pal) )
   {
      gevLogStat(gev, "*** Use of SCIP is limited to academic users.");
      gevLogStat(gev, "*** Please contact [email protected] to arrange for a license.");
      gmoSolveStatSet(gmo, gmoSolveStat_License);
      gmoModelStatSet(gmo, gmoModelStat_LicenseError);
      return 1;
   }

   ipoptlicensed = HSLInit(gmo, pal);

   // print version info and copyright
   if( SCIPsubversion() > 0 )
      sprintf(buffer, "SCIP version %d.%d.%d.%d (" SCIP_GITHASH ")\n", SCIPmajorVersion(), SCIPminorVersion(), SCIPtechVersion(), SCIPsubversion());
   else
      sprintf(buffer, "SCIP version %d.%d.%d (" SCIP_GITHASH ")\n", SCIPmajorVersion(), SCIPminorVersion(), SCIPtechVersion());
   gevLogStatPChar(gev, buffer);
   gevLogStatPChar(gev, SCIP_COPYRIGHT"\n\n");

   // install or update error printing callback in SCIP to use current gev
   SCIPmessageSetErrorPrinting(printErrorGev, (void*)gev);

   // setup (or reset) SCIP instance
   SCIP_RETCODE scipret;
   scipret = setupSCIP();

   if( scipret != SCIP_OKAY )
   {
      snprintf(buffer, sizeof(buffer), "Error %d in call of SCIP function\n", scipret);
      gevLogStatPChar(gev, buffer);
      gmoSolveStatSet(gmo, gmoSolveStat_SystemErr);
      gmoModelStatSet(gmo, gmoModelStat_ErrorNoSolution);
      return 1;
   }

   assert(scip != NULL);

   // print info on used external codes
   SCIPprintExternalCodes(scip, NULL);

   return 0;
}