Example #1
0
/** starts user interactive mode */
static
SCIP_RETCODE interactive(
   SCIP*                      scip                /**< SCIP data structure */
   )
{
   SCIP_CALL( SCIPstartInteraction(scip) );

   return SCIP_OKAY;
}
Example #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;
}
Example #3
0
/** evaluates command line parameters and runs GCG appropriately in the given SCIP instance */
static
SCIP_RETCODE SCIPprocessGCGShellArguments(
   SCIP*                 scip,               /**< SCIP data structure */
   int                   argc,               /**< number of shell parameters */
   char**                argv,               /**< array with shell parameters */
   const char*           defaultsetname      /**< name of default settings file */
   )
{  /*lint --e{850}*/
   char* probname = NULL;
   char* decname = NULL;
   char* settingsname = NULL;
   char* mastersetname = NULL;
   char* logname = NULL;
   SCIP_Bool quiet;
   SCIP_Bool paramerror;
   SCIP_Bool interactive;
   int i;

   /********************
    * Parse parameters *
    ********************/

   quiet = FALSE;
   paramerror = FALSE;
   interactive = FALSE;
   for( i = 1; i < argc; ++i )
   {
      if( strcmp(argv[i], "-l") == 0 )
      {
         i++;
         if( i < argc )
            logname = argv[i];
         else
         {
            SCIPinfoMessage(scip, NULL, "missing log filename after parameter '-l'\n");
            paramerror = TRUE;
         }
      }
      else if( strcmp(argv[i], "-q") == 0 )
         quiet = TRUE;
      else if( strcmp(argv[i], "-s") == 0 )
      {
         i++;
         if( i < argc )
            settingsname = argv[i];
         else
         {
            SCIPinfoMessage(scip, NULL, "missing settings filename after parameter '-s'\n");
            paramerror = TRUE;
         }
      }
      else if( strcmp(argv[i], "-m") == 0 )
      {
         i++;
         if( i < argc )
            mastersetname = argv[i];
         else
         {
            SCIPinfoMessage(scip, NULL, "missing master settings filename after parameter '-m'\n");
            paramerror = TRUE;
         }
      }
      else if( strcmp(argv[i], "-f") == 0 )
      {
         i++;
         if( i < argc )
            probname = argv[i];
         else
         {
            SCIPinfoMessage(scip, NULL, "missing problem filename after parameter '-f'\n");
            paramerror = TRUE;
         }
      }
      else if( strcmp(argv[i], "-d") == 0 )
      {
         i++;
         if( i < argc )
            decname = argv[i];
         else
         {
            SCIPinfoMessage(scip, NULL, "missing decomposition filename after parameter '-d'\n");
            paramerror = TRUE;
         }
      }
      else if( strcmp(argv[i], "-c") == 0 )
      {
         i++;
         if( i < argc )
         {
            SCIP_CALL( SCIPaddDialogInputLine(scip, argv[i]) );
            interactive = TRUE;
         }
         else
         {
            SCIPinfoMessage(scip, NULL, "missing command line after parameter '-c'\n");
            paramerror = TRUE;
         }
      }
      else if( strcmp(argv[i], "-b") == 0 )
      {
         i++;
         if( i < argc )
         {
            SCIP_FILE* file;

            file = SCIPfopen(argv[i], "r");
            if( file == NULL )
            {
               SCIPinfoMessage(scip, NULL, "cannot read command batch file <%s>\n", argv[i]);
               SCIPprintSysError(argv[i]);
               paramerror = TRUE;
            }
            else
            {
               while( !SCIPfeof(file) )
               {
                  char buffer[SCIP_MAXSTRLEN];

                  (void)SCIPfgets(buffer, sizeof(buffer), file);
                  if( buffer[0] != '\0' )
                  {
                     SCIP_CALL( SCIPaddDialogInputLine(scip, buffer) );
                  }
               }
               SCIPfclose(file);
               interactive = TRUE;
            }
         }
         else
         {
            SCIPinfoMessage(scip, NULL, "missing command batch filename after parameter '-b'\n");
            paramerror = TRUE;
         }
      }
      else
      {
         SCIPinfoMessage(scip, NULL, "invalid parameter <%s>\n", argv[i]);
         paramerror = TRUE;
      }
   }
   if( interactive && probname != NULL )
   {
      SCIPinfoMessage(scip, NULL, "cannot mix batch mode '-c' and '-b' with file mode '-f'\n");
      paramerror = TRUE;
   }
   if( probname == NULL && decname != NULL )
   {
      SCIPinfoMessage(scip, NULL, "cannot read decomposition file without given problem\n");
      paramerror = TRUE;
   }

   if( !paramerror )
   {

      /***********************************
       * create log file message handler *
       ***********************************/

      if( quiet )
      {
         SCIPsetMessagehdlrQuiet(scip, quiet);
      }

      if( logname != NULL )
      {
         SCIPsetMessagehdlrLogfile(scip, logname);
      }


      /***********************************
       * Version and library information *
       ***********************************/

      SCIPprintVersion(scip, NULL);
      SCIPinfoMessage(scip, NULL, "\n");

      SCIPprintExternalCodes(scip, NULL);
      SCIPinfoMessage(scip, NULL, "\n");

      /*****************
       * Load settings *
       *****************/

      if( settingsname != NULL )
      {
         SCIP_CALL( readParams(scip, settingsname) );
      }
      else if( defaultsetname != NULL )
      {
         SCIP_CALL( readParams(scip, defaultsetname) );
      }

      if( mastersetname != NULL )
      {
         SCIP_CALL( readParams(GCGrelaxGetMasterprob(scip), mastersetname) );
      }

      /**************
       * Start SCIP *
       **************/

      if( probname != NULL )
      {
         SCIP_CALL( fromCommandLine(scip, probname, decname) );
      }
      else
      {
         SCIPinfoMessage(scip, NULL, "\n");
         SCIP_CALL( SCIPstartInteraction(scip) );
      }
   }
   else
   {
      SCIPinfoMessage(scip, NULL, "\nsyntax: %s [-l <logfile>] [-q] [-s <settings>] [-f <problem>] [-m <mastersettings>] [-d <decomposition>] [-b <batchfile>] [-c \"command\"]\n"
         "  -l <logfile>        : copy output into log file\n"
         "  -q                  : suppress screen messages\n"
         "  -s <settings>       : load parameter settings (.set) file\n"
         "  -m <mastersettings> : load master parameter settings (.set) file\n"
         "  -f <problem>        : load and solve problem file\n"
         "  -d <decomposition>  : load decomposition file\n"
         "  -b <batchfile>      : load and execute dialog command batch file (can be used multiple times)\n"
         "  -c \"command\"        : execute single line of dialog commands (can be used multiple times)\n\n",
         argv[0]);
   }

   return SCIP_OKAY;
}
Example #4
0
static
SCIP_RETCODE run(
   const char*                nlfile,        /**< name of AMPL .nl file */
   const char*                setfile,       /**< SCIP settings file, or NULL to try default scip.set */
   SCIP_Bool                  interactive    /**< whether to start SCIP interactive shell instead of solving command */
)
{
   SCIP* scip;
   char buffer[SCIP_MAXSTRLEN];
   SCIP_Bool printstat;

   assert(nlfile != NULL);

   /* setup SCIP and print version information */
   SCIP_CALL( SCIPcreate(&scip) );

   SCIPprintVersion(scip, NULL);
   SCIPinfoMessage(scip, NULL, "\n");

   SCIP_CALL( SCIPincludeDefaultPlugins(scip) );
   SCIP_CALL( SCIPincludeReaderNl(scip) );

   SCIP_CALL( SCIPaddBoolParam(scip, "display/statistics",
      "whether to print statistics on a solve",
      NULL, FALSE, FALSE, NULL, NULL) );

   SCIPprintExternalCodes(scip, NULL);
   SCIPinfoMessage(scip, NULL, "\n");

   /* read setting file */
   if( setfile != NULL )
   {
      SCIP_CALL( SCIPreadParams(scip, setfile) );
   }

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

   /* setup commands to be executed by SCIP */

   SCIP_CALL( SCIPaddDialogInputLine(scip, "display param") );

   /* add .nl extension, if not given */
   (void) SCIPsnprintf(buffer, SCIP_MAXSTRLEN, "read %s%s", nlfile, (strlen(nlfile) < 3 || strcmp(nlfile+(strlen(nlfile)-3), ".nl") != 0) ? ".nl" : "");
   SCIP_CALL( SCIPaddDialogInputLine(scip, buffer) );

   if( !interactive )
   {
      /* SCIP_CALL( SCIPaddDialogInputLine(scip, "display problem") ); */

      SCIP_CALL( SCIPaddDialogInputLine(scip, "optimize") );

      SCIP_CALL( SCIPaddDialogInputLine(scip, "write amplsol") );

      if( printstat )
      {
         SCIP_CALL( SCIPaddDialogInputLine(scip, "display statistics") );
      }

      SCIP_CALL( SCIPaddDialogInputLine(scip, "quit") );
   }

   /* run SCIP */
   SCIP_CALL( SCIPstartInteraction(scip) );

   SCIP_CALL( SCIPfree(&scip) );

   return SCIP_OKAY;
}