Ejemplo n.º 1
0
DllExport int STDCALL C__hisCallSolver(void* Cptr)
{
   int rc = 1;
   char buffer[1024];
   gamshighs_t* gh;
   HighsStatus status;

   gh = (gamshighs_t*)Cptr;
   assert(gh->gmo != NULL);
   assert(gh->gev != NULL);

   gevLogStatPChar(gh->gev, "HiGHS " XQUOTE(HIGHS_VERSION_MAJOR) "." XQUOTE(HIGHS_VERSION_MINOR) "." XQUOTE(HIGHS_VERSION_PATCH) " [date: " HIGHS_COMPILATION_DATE ", git hash: " HIGHS_GITHASH "]\n");
   gevLogStatPChar(gh->gev, "Copyright (c) 2019 ERGO-Code under MIT licence terms.\n");

   gmoModelStatSet(gh->gmo, gmoModelStat_NoSolutionReturned);
   gmoSolveStatSet(gh->gmo, gmoSolveStat_SystemErr);

   /* get the problem into a normal form */
   gmoObjStyleSet(gh->gmo, gmoObjType_Fun);
   gmoObjReformSet(gh->gmo, 1);
   gmoIndexBaseSet(gh->gmo, 0);
   gmoSetNRowPerm(gh->gmo); /* hide =N= rows */
   gmoMinfSet(gh->gmo, -HIGHS_CONST_INF);
   gmoPinfSet(gh->gmo,  HIGHS_CONST_INF);

   if( setupOptions(gh) )
      goto TERMINATE;

   if( setupProblem(gh) )
      goto TERMINATE;

   gevTimeSetStart(gh->gev);

   /* solve the problem */
   status = gh->highs->run();

   /* pass solution, status, etc back to GMO */
   if( processSolve(gh, status) )
      goto TERMINATE;

   rc = 0;
TERMINATE:

   delete gh->lp;
   gh->lp = NULL;

   delete gh->highs;
   gh->highs= NULL;

   delete gh->options;
   gh->options = NULL;

   return rc;
}
Ejemplo n.º 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;
}
Ejemplo n.º 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;
}
Ejemplo n.º 4
0
static
int processSolve(
   gamshighs_t* gh,
   HighsStatus status
)
{
   assert(gh != NULL);
   assert(gh->highs != NULL);
   assert(gh->lp != NULL);

   gmoSetHeadnTail(gh->gmo, gmoHresused, gevTimeDiffStart(gh->gev));
   gmoSetHeadnTail(gh->gmo, gmoHiterused, 42 /* FIXME number of iterations */);

   HighsSolution sol = gh->highs->getSolution();
   bool havesol = sol.col_value.size() > 0;

   if( havesol )
   {
      /* TODO probably should use gmoSetSolution or gmoSetSolution8 */
      gmoSetSolution2(gh->gmo, &sol.col_value[0], &sol.row_dual[0]);
      gmoCompleteSolution(gh->gmo);
   }

   gmoSolveStatSet(gh->gmo, gmoSolveStat_Normal);

   switch( status )
   {
      case HighsStatus::NotSet:
      case HighsStatus::Init:
      case HighsStatus::LpError:
      case HighsStatus::OptionsError:
      case HighsStatus::PresolveError:
      case HighsStatus::SolutionError:
      case HighsStatus::PostsolveError:
      case HighsStatus::NotImplemented:
         gmoModelStatSet(gh->gmo, gmoModelStat_ErrorNoSolution);
         gmoSolveStatSet(gh->gmo, gmoSolveStat_SolverErr);
         break;

      case HighsStatus::ReachedDualObjectiveUpperBound:
         /* TODO is solution feasible? */
         gmoModelStatSet(gh->gmo, havesol ? gmoModelStat_InfeasibleIntermed : gmoModelStat_NoSolutionReturned);
         gmoSolveStatSet(gh->gmo, gmoSolveStat_Solver);
         break;

      case HighsStatus::Unbounded:
         gmoModelStatSet(gh->gmo, havesol ? gmoModelStat_Unbounded : gmoModelStat_UnboundedNoSolution);
         break;

      case HighsStatus::Infeasible:
         gmoModelStatSet(gh->gmo, havesol ? gmoModelStat_InfeasibleGlobal : gmoModelStat_InfeasibleNoSolution);
         break;

      case HighsStatus::Feasible:
         gmoModelStatSet(gh->gmo, havesol ? gmoModelStat_InfeasibleGlobal : gmoModelStat_InfeasibleNoSolution);
         break;

      case HighsStatus::OK:   /* ???? */
      case HighsStatus::Optimal:
         assert(havesol);
         gmoModelStatSet(gh->gmo, gmoModelStat_OptimalGlobal);
         break;

      case HighsStatus::Timeout:
         /* TODO is solution feasible? */
         gmoModelStatSet(gh->gmo, havesol ? gmoModelStat_InfeasibleIntermed : gmoModelStat_NoSolutionReturned);
         gmoSolveStatSet(gh->gmo, gmoSolveStat_Resource);
         break;

      case HighsStatus::ReachedIterationLimit:
         /* TODO is solution feasible? */
         gmoModelStatSet(gh->gmo, havesol ? gmoModelStat_InfeasibleIntermed : gmoModelStat_NoSolutionReturned);
         gmoSolveStatSet(gh->gmo, gmoSolveStat_Iteration);
         break;

      case HighsStatus::NumericalDifficulties:
         /* TODO is solution feasible? */
         gmoModelStatSet(gh->gmo, havesol ? gmoModelStat_InfeasibleIntermed : gmoModelStat_NoSolutionReturned);
         gmoSolveStatSet(gh->gmo, gmoSolveStat_Solver);
         break;
   }

   return 0;
}